diff --git a/src/AudioManager.cpp b/src/AudioManager.cpp index 081670e6c..4b1a8e463 100644 --- a/src/AudioManager.cpp +++ b/src/AudioManager.cpp @@ -28,17 +28,13 @@ void AudioManager::mixAudio(void *unused, Uint8 *stream, int len) } //mix sample into stream SDL_MixAudio(stream, &(sound->getData()[sound->getPosition()]), restLength, SDL_MIX_MAXVOLUME); - if (sound->getPosition() + restLength >= sound->getLength()) - { - //if the position is beyond the end of the buffer, stop playing the sample - sound->stop(); - } - else + if (sound->getPosition() + restLength < sound->getLength()) { //sample hasn't ended yet - sound->setPosition(sound->getPosition() + restLength); stillPlaying = true; } + //set new sound position. if this is at or beyond the end of the sample, it will stop automatically + sound->setPosition(sound->getPosition() + restLength); } //advance to next sound ++soundIt; diff --git a/src/Sound.cpp b/src/Sound.cpp index e908a7716..000d7dc65 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -82,18 +82,19 @@ void Sound::play() if(mSampleData == NULL) return; + SDL_LockAudio(); if (playing) { //replay from start. rewind the sample to the beginning - SDL_LockAudio(); mSamplePos = 0; - SDL_UnlockAudio(); + } else { //flag our sample as playing playing = true; } + SDL_UnlockAudio(); //tell the AudioManager to start playing samples AudioManager::getInstance()->play(); } @@ -126,6 +127,8 @@ void Sound::setPosition(Uint32 newPosition) { mSamplePos = newPosition; if (mSamplePos >= mSampleLength) { + //got to or beyond the end of the sample. stop playing + playing = false; mSamplePos = 0; } } diff --git a/src/VolumeControl.cpp b/src/VolumeControl.cpp index 95ac7535a..1097ae2e1 100644 --- a/src/VolumeControl.cpp +++ b/src/VolumeControl.cpp @@ -215,6 +215,8 @@ void VolumeControl::deinit() #error TODO: Not implemented for MacOS yet!!! #elif defined(__linux__) if (mixerHandle != nullptr) { + snd_mixer_detach(mixerHandle, mixerCard); + snd_mixer_free(mixerHandle); snd_mixer_close(mixerHandle); mixerHandle = nullptr; mixerElem = nullptr;