mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
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));
|
return lookup(lookupId(soundId));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::loadVoice(const std::string &voicefile)
|
DecoderPtr SoundManager::loadVoice(const std::string &voicefile)
|
||||||
{
|
{
|
||||||
NameLoudnessMap::iterator lipiter = mVoiceLipBuffers.find(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();
|
DecoderPtr decoder = getDecoder();
|
||||||
// Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav.
|
// 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;
|
std::vector<char> data;
|
||||||
decoder->readAll(data);
|
decoder->readAll(data);
|
||||||
decoder->close();
|
|
||||||
|
|
||||||
Sound_Loudness loudness;
|
Sound_Loudness loudness;
|
||||||
loudness.analyzeLoudness(data, srate, chans, type, static_cast<float>(sLoudnessFPS));
|
loudness.analyzeLoudness(data, srate, chans, type, static_cast<float>(sLoudnessFPS));
|
||||||
|
|
||||||
mVoiceLipBuffers.insert(std::make_pair(voicefile, loudness));
|
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 ESM::Position &pos = ptr.getRefData().getPosition();
|
||||||
const osg::Vec3f objpos(pos.asVec3());
|
const osg::Vec3f objpos(pos.asVec3());
|
||||||
|
|
||||||
loadVoice(voicefile);
|
DecoderPtr decoder = loadVoice(voicefile);
|
||||||
DecoderPtr decoder = getDecoder();
|
|
||||||
decoder->open(voicefile);
|
|
||||||
|
|
||||||
MWBase::SoundPtr sound = mOutput->streamSound3D(decoder,
|
MWBase::SoundPtr sound = mOutput->streamSound3D(decoder,
|
||||||
objpos, 1.0f, basevol, 1.0f, minDistance, maxDistance, Play_Normal|Play_TypeVoice
|
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);
|
std::string voicefile = "sound/"+Misc::StringUtils::lowerCase(filename);
|
||||||
float basevol = volumeFromType(Play_TypeVoice);
|
float basevol = volumeFromType(Play_TypeVoice);
|
||||||
|
|
||||||
loadVoice(voicefile);
|
DecoderPtr decoder = loadVoice(voicefile);
|
||||||
DecoderPtr decoder = getDecoder();
|
|
||||||
decoder->open(voicefile);
|
|
||||||
|
|
||||||
MWBase::SoundPtr sound = mOutput->streamSound(decoder,
|
MWBase::SoundPtr sound = mOutput->streamSound(decoder,
|
||||||
basevol, 1.0f, Play_Normal|Play_TypeVoice
|
basevol, 1.0f, Play_Normal|Play_TypeVoice
|
||||||
|
|
|
@ -93,8 +93,9 @@ namespace MWSound
|
||||||
Sound_Buffer *lookup(size_t sfxid);
|
Sound_Buffer *lookup(size_t sfxid);
|
||||||
Sound_Buffer *lookup(const std::string &soundId);
|
Sound_Buffer *lookup(const std::string &soundId);
|
||||||
|
|
||||||
// Ensure the loudness/"lip" data is loaded
|
// Ensures the loudness/"lip" data is loaded, and returns a decoder to
|
||||||
void loadVoice(const std::string &voicefile);
|
// start streaming
|
||||||
|
DecoderPtr loadVoice(const std::string &voicefile);
|
||||||
|
|
||||||
void streamMusicFull(const std::string& filename);
|
void streamMusicFull(const std::string& filename);
|
||||||
bool updateSound(MWBase::SoundPtr sound, const MWWorld::Ptr &ptr, float duration);
|
bool updateSound(MWBase::SoundPtr sound, const MWWorld::Ptr &ptr, float duration);
|
||||||
|
|
Loading…
Reference in a new issue