forked from mirror/openmw-tes3mp
Return a decoder from the loadVoice function
This commit is contained in:
parent
24f8c78fca
commit
3ce6aee98b
2 changed files with 25 additions and 11 deletions
|
@ -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<char> data;
|
||||
decoder->readAll(data);
|
||||
decoder->close();
|
||||
|
||||
Sound_Loudness loudness;
|
||||
loudness.analyzeLoudness(data, srate, chans, type, static_cast<float>(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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue