From 3ce6aee98babc135b95c77b749f509549855e81f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 24 Nov 2015 04:00:17 -0800 Subject: [PATCH] Return a decoder from the loadVoice function --- apps/openmw/mwsound/soundmanagerimp.cpp | 31 ++++++++++++++++++------- apps/openmw/mwsound/soundmanagerimp.hpp | 5 ++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index bb767cf41..fca879e8f 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -241,10 +241,25 @@ namespace MWSound return lookup(lookupId(soundId)); } - void SoundManager::loadVoice(const std::string &voicefile) + DecoderPtr SoundManager::loadVoice(const std::string &voicefile) { NameLoudnessMap::iterator lipiter = mVoiceLipBuffers.find(voicefile); - if(lipiter != mVoiceLipBuffers.end()) return; + if(lipiter != mVoiceLipBuffers.end()) + { + DecoderPtr decoder = getDecoder(); + // Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav. + if(decoder->mResourceMgr->exists(voicefile)) + decoder->open(voicefile); + else + { + std::string file = voicefile; + std::string::size_type pos = file.rfind('.'); + if(pos != std::string::npos) + file = file.substr(0, pos)+".mp3"; + decoder->open(file); + } + return decoder; + } DecoderPtr decoder = getDecoder(); // Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav. @@ -266,12 +281,14 @@ namespace MWSound std::vector data; decoder->readAll(data); - decoder->close(); Sound_Loudness loudness; loudness.analyzeLoudness(data, srate, chans, type, static_cast(sLoudnessFPS)); mVoiceLipBuffers.insert(std::make_pair(voicefile, loudness)); + + decoder->rewind(); + return decoder; } @@ -407,9 +424,7 @@ namespace MWSound const ESM::Position &pos = ptr.getRefData().getPosition(); const osg::Vec3f objpos(pos.asVec3()); - loadVoice(voicefile); - DecoderPtr decoder = getDecoder(); - decoder->open(voicefile); + DecoderPtr decoder = loadVoice(voicefile); MWBase::SoundPtr sound = mOutput->streamSound3D(decoder, objpos, 1.0f, basevol, 1.0f, minDistance, maxDistance, Play_Normal|Play_TypeVoice @@ -449,9 +464,7 @@ namespace MWSound std::string voicefile = "sound/"+Misc::StringUtils::lowerCase(filename); float basevol = volumeFromType(Play_TypeVoice); - loadVoice(voicefile); - DecoderPtr decoder = getDecoder(); - decoder->open(voicefile); + DecoderPtr decoder = loadVoice(voicefile); MWBase::SoundPtr sound = mOutput->streamSound(decoder, basevol, 1.0f, Play_Normal|Play_TypeVoice diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 25ba9ce05..9fc9084ee 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -93,8 +93,9 @@ namespace MWSound Sound_Buffer *lookup(size_t sfxid); Sound_Buffer *lookup(const std::string &soundId); - // Ensure the loudness/"lip" data is loaded - void loadVoice(const std::string &voicefile); + // Ensures the loudness/"lip" data is loaded, and returns a decoder to + // start streaming + DecoderPtr loadVoice(const std::string &voicefile); void streamMusicFull(const std::string& filename); bool updateSound(MWBase::SoundPtr sound, const MWWorld::Ptr &ptr, float duration);