From 7fc2df153a42ae5545d1129a31d610ea1b143f19 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 11 Dec 2015 15:13:14 -0800 Subject: [PATCH 1/2] Rename stopSound/stopStream to finishSound/finishStream Since they're also used to clean up output resources, not just stopping. --- apps/openmw/mwsound/openal_output.cpp | 4 +-- apps/openmw/mwsound/openal_output.hpp | 4 +-- apps/openmw/mwsound/sound_output.hpp | 4 +-- apps/openmw/mwsound/soundmanagerimp.cpp | 36 ++++++++++++------------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 02a9f33f90..d440206329 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -915,7 +915,7 @@ void OpenAL_Output::playSound3D(MWBase::SoundPtr sound, Sound_Handle data, float sound->mHandle = MAKE_PTRID(source); } -void OpenAL_Output::stopSound(MWBase::SoundPtr sound) +void OpenAL_Output::finishSound(MWBase::SoundPtr sound) { if(!sound->mHandle) return; ALuint source = GET_PTRID(sound->mHandle); @@ -1012,7 +1012,7 @@ void OpenAL_Output::streamSound3D(DecoderPtr decoder, MWBase::SoundStreamPtr sou sound->mHandle = stream; } -void OpenAL_Output::stopStream(MWBase::SoundStreamPtr sound) +void OpenAL_Output::finishStream(MWBase::SoundStreamPtr sound) { if(!sound->mHandle) return; OpenAL_SoundStream *stream = reinterpret_cast(sound->mHandle); diff --git a/apps/openmw/mwsound/openal_output.hpp b/apps/openmw/mwsound/openal_output.hpp index 28f30bec9f..4986cd3a03 100644 --- a/apps/openmw/mwsound/openal_output.hpp +++ b/apps/openmw/mwsound/openal_output.hpp @@ -58,13 +58,13 @@ namespace MWSound virtual void playSound(MWBase::SoundPtr sound, Sound_Handle data, float offset); virtual void playSound3D(MWBase::SoundPtr sound, Sound_Handle data, float offset); - virtual void stopSound(MWBase::SoundPtr sound); + virtual void finishSound(MWBase::SoundPtr sound); virtual bool isSoundPlaying(MWBase::SoundPtr sound); virtual void updateSound(MWBase::SoundPtr sound); virtual void streamSound(DecoderPtr decoder, MWBase::SoundStreamPtr sound); virtual void streamSound3D(DecoderPtr decoder, MWBase::SoundStreamPtr sound); - virtual void stopStream(MWBase::SoundStreamPtr sound); + virtual void finishStream(MWBase::SoundStreamPtr sound); virtual double getStreamDelay(MWBase::SoundStreamPtr sound); virtual double getStreamOffset(MWBase::SoundStreamPtr sound); virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound); diff --git a/apps/openmw/mwsound/sound_output.hpp b/apps/openmw/mwsound/sound_output.hpp index 79025abb00..98eba8466c 100644 --- a/apps/openmw/mwsound/sound_output.hpp +++ b/apps/openmw/mwsound/sound_output.hpp @@ -37,13 +37,13 @@ namespace MWSound virtual void playSound(MWBase::SoundPtr sound, Sound_Handle data, float offset) = 0; virtual void playSound3D(MWBase::SoundPtr sound, Sound_Handle data, float offset) = 0; - virtual void stopSound(MWBase::SoundPtr sound) = 0; + virtual void finishSound(MWBase::SoundPtr sound) = 0; virtual bool isSoundPlaying(MWBase::SoundPtr sound) = 0; virtual void updateSound(MWBase::SoundPtr sound) = 0; virtual void streamSound(DecoderPtr decoder, MWBase::SoundStreamPtr sound) = 0; virtual void streamSound3D(DecoderPtr decoder, MWBase::SoundStreamPtr sound) = 0; - virtual void stopStream(MWBase::SoundStreamPtr sound) = 0; + virtual void finishStream(MWBase::SoundStreamPtr sound) = 0; virtual double getStreamDelay(MWBase::SoundStreamPtr sound) = 0; virtual double getStreamOffset(MWBase::SoundStreamPtr sound) = 0; virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound) = 0; diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 801a262d84..a36c21da12 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -309,7 +309,7 @@ namespace MWSound void SoundManager::stopMusic() { if(mMusic) - mOutput->stopStream(mMusic); + mOutput->finishStream(mMusic); mMusic.reset(); } @@ -477,7 +477,7 @@ namespace MWSound SaySoundMap::iterator snditer = mActiveSaySounds.find(ptr); if(snditer != mActiveSaySounds.end()) { - mOutput->stopStream(snditer->second.first); + mOutput->finishStream(snditer->second.first); mActiveSaySounds.erase(snditer); } mPendingSaySounds.erase(ptr); @@ -506,7 +506,7 @@ namespace MWSound void SoundManager::stopTrack(MWBase::SoundStreamPtr stream) { - mOutput->stopStream(stream); + mOutput->finishStream(stream); TrackList::iterator iter = std::lower_bound(mActiveTracks.begin(), mActiveTracks.end(), stream); if(iter != mActiveTracks.end() && *iter == stream) mActiveTracks.erase(iter); @@ -624,7 +624,7 @@ namespace MWSound void SoundManager::stopSound(MWBase::SoundPtr sound) { if (sound.get()) - mOutput->stopSound(sound); + mOutput->finishSound(sound); } void SoundManager::stopSound3D(const MWWorld::Ptr &ptr, const std::string& soundId) @@ -637,7 +637,7 @@ namespace MWSound for(;sndidx != snditer->second.end();++sndidx) { if(sndidx->second == sfx) - mOutput->stopSound(sndidx->first); + mOutput->finishSound(sndidx->first); } } } @@ -649,7 +649,7 @@ namespace MWSound { SoundBufferRefPairList::iterator sndidx = snditer->second.begin(); for(;sndidx != snditer->second.end();++sndidx) - mOutput->stopSound(sndidx->first); + mOutput->finishSound(sndidx->first); } } @@ -664,7 +664,7 @@ namespace MWSound { SoundBufferRefPairList::iterator sndidx = snditer->second.begin(); for(;sndidx != snditer->second.end();++sndidx) - mOutput->stopSound(sndidx->first); + mOutput->finishSound(sndidx->first); } ++snditer; } @@ -675,7 +675,7 @@ namespace MWSound sayiter->first != MWMechanics::getPlayer() && sayiter->first.getCell() == cell) { - mOutput->stopStream(sayiter->second.first); + mOutput->finishStream(sayiter->second.first); } ++sayiter; } @@ -691,7 +691,7 @@ namespace MWSound for(;sndidx != snditer->second.end();++sndidx) { if(sndidx->second == sfx) - mOutput->stopSound(sndidx->first); + mOutput->finishSound(sndidx->first); } } } @@ -829,7 +829,7 @@ namespace MWSound env = Env_Underwater; else if(mUnderwaterSound) { - mOutput->stopSound(mUnderwaterSound); + mOutput->finishSound(mUnderwaterSound); mUnderwaterSound.reset(); } @@ -866,13 +866,13 @@ namespace MWSound if(sound->getDistanceCull()) { if((mListenerPos - objpos).length2() > 2000*2000) - mOutput->stopSound(sound); + mOutput->finishSound(sound); } } if(!mOutput->isSoundPlaying(sound)) { - mOutput->stopSound(sound); + mOutput->finishSound(sound); Sound_Buffer *sfx = sndidx->second; if(sfx->mUses-- == 1) mUnusedBuffers.push_front(sfx); @@ -939,13 +939,13 @@ namespace MWSound if(sound->getDistanceCull()) { if((mListenerPos - pos).length2() > 2000*2000) - mOutput->stopStream(sound); + mOutput->finishStream(sound); } } if(!mOutput->isStreamPlaying(sound)) { - mOutput->stopStream(sound); + mOutput->finishStream(sound); mActiveSaySounds.erase(sayiter++); } else @@ -963,7 +963,7 @@ namespace MWSound MWBase::SoundStreamPtr sound = *trkiter; if(!mOutput->isStreamPlaying(sound)) { - mOutput->stopStream(sound); + mOutput->finishStream(sound); trkiter = mActiveTracks.erase(trkiter); } else @@ -1143,7 +1143,7 @@ namespace MWSound SoundBufferRefPairList::iterator sndidx = snditer->second.begin(); for(;sndidx != snditer->second.end();++sndidx) { - mOutput->stopSound(sndidx->first); + mOutput->finishSound(sndidx->first); Sound_Buffer *sfx = sndidx->second; if(sfx->mUses-- == 1) mUnusedBuffers.push_front(sfx); @@ -1152,11 +1152,11 @@ namespace MWSound mActiveSounds.clear(); SaySoundMap::iterator sayiter = mActiveSaySounds.begin(); for(;sayiter != mActiveSaySounds.end();++sayiter) - mOutput->stopStream(sayiter->second.first); + mOutput->finishStream(sayiter->second.first); mActiveSaySounds.clear(); TrackList::iterator trkiter = mActiveTracks.begin(); for(;trkiter != mActiveTracks.end();++trkiter) - mOutput->stopStream(*trkiter); + mOutput->finishStream(*trkiter); mActiveTracks.clear(); mPendingSaySounds.clear(); mUnderwaterSound.reset(); From f47f0a996f096d7e0ce3cd4d89eb660b814b29b9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 11 Dec 2015 15:49:45 -0800 Subject: [PATCH 2/2] Stop the object's old say sound before playing the new one --- apps/openmw/mwsound/soundmanagerimp.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index a36c21da12..d1a90759b1 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -410,8 +410,10 @@ namespace MWSound { MWBase::World *world = MWBase::Environment::get().getWorld(); const osg::Vec3f pos = world->getActorHeadTransform(ptr).getTrans(); - MWBase::SoundStreamPtr sound = playVoice(decoder, pos, (ptr == MWMechanics::getPlayer())); - mActiveSaySounds[ptr] = std::make_pair(sound, loudness); + SoundLoudnessPair &old = mActiveSaySounds[ptr]; + if(old.first.get()) mOutput->finishStream(old.first); + old = std::make_pair(playVoice(decoder, pos, (ptr == MWMechanics::getPlayer())), + loudness); } } catch(std::exception &e) @@ -450,8 +452,9 @@ namespace MWSound mPendingSaySounds[MWWorld::Ptr()] = std::make_pair(decoder, loudness); else { - MWBase::SoundStreamPtr sound = playVoice(decoder, osg::Vec3f(), true); - mActiveSaySounds[MWWorld::Ptr()] = std::make_pair(sound, loudness); + SoundLoudnessPair &old = mActiveSaySounds[MWWorld::Ptr()]; + if(old.first.get()) mOutput->finishStream(old.first); + old = std::make_pair(playVoice(decoder, osg::Vec3f(), true), loudness); } } catch(std::exception &e) @@ -904,16 +907,18 @@ namespace MWSound MWBase::SoundStreamPtr sound; MWWorld::Ptr ptr = penditer->first; + + SoundLoudnessPair &old = mActiveSaySounds[ptr]; + if(old.first.get()) mOutput->finishStream(old.first); if(ptr == MWWorld::Ptr()) sound = playVoice(decoder, osg::Vec3f(), true); else { MWBase::World *world = MWBase::Environment::get().getWorld(); const osg::Vec3f pos = world->getActorHeadTransform(ptr).getTrans(); - sound = playVoice(decoder, pos, (ptr == MWMechanics::getPlayer())); } - mActiveSaySounds[ptr] = std::make_pair(sound, loudness); + old = std::make_pair(sound, loudness); } catch(std::exception &e) { std::cerr<< "Sound Error: "<