@ -219,7 +219,7 @@ namespace MWSound
return sfx ;
}
DecoderPtr SoundManager : : loadVoice ( const std : : string & voicefile , Sound_Loudness * * lipdata )
DecoderPtr SoundManager : : loadVoice ( const std : : string & voicefile )
{
DecoderPtr decoder = getDecoder ( ) ;
// Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav.
@ -234,21 +234,6 @@ namespace MWSound
decoder - > open ( file ) ;
}
NameLoudnessRefMap : : iterator lipiter = mVoiceLipNameMap . find ( voicefile ) ;
if ( lipiter ! = mVoiceLipNameMap . end ( ) )
{
* lipdata = lipiter - > second ;
return decoder ;
}
mVoiceLipBuffers . insert ( mVoiceLipBuffers . end ( ) , Sound_Loudness ( ) ) ;
lipiter = mVoiceLipNameMap . insert (
std : : make_pair ( voicefile , & mVoiceLipBuffers . back ( ) )
) . first ;
mOutput - > loadLoudnessAsync ( decoder , lipiter - > second ) ;
* lipdata = lipiter - > second ;
return decoder ;
}
@ -400,28 +385,22 @@ namespace MWSound
{
std : : string voicefile = " Sound/ " + filename ;
Sound_Loudness * loudness ;
mVFS - > normalizeFilename ( voicefile ) ;
DecoderPtr decoder = loadVoice ( voicefile , & loudness );
DecoderPtr decoder = loadVoice ( voicefile );
if ( ! loudness - > isReady ( ) )
mPendingSaySounds [ ptr ] = std : : make_pair ( decoder , loudness ) ;
else
{
MWBase : : World * world = MWBase : : Environment : : get ( ) . getWorld ( ) ;
const osg : : Vec3f pos = world - > getActorHeadTransform ( ptr ) . getTrans ( ) ;
SaySoundMap : : iterator oldIt = mActiveSaySounds . find ( ptr ) ;
if ( oldIt ! = mActiveSaySounds . end ( ) )
{
mOutput - > finishStream ( oldIt - > second . first ) ;
mOutput - > finishStream ( oldIt - > second ) ;
mActiveSaySounds . erase ( oldIt ) ;
}
MWBase : : SoundStreamPtr sound = playVoice ( decoder , pos , ( ptr = = MWMechanics : : getPlayer ( ) ) ) ;
mActiveSaySounds . insert ( std : : make_pair ( ptr , std : : make_pair ( sound , loudness ) ) ) ;
}
mActiveSaySounds . insert ( std : : make_pair ( ptr , sound ) ) ;
}
catch ( std : : exception & e )
{
@ -434,10 +413,8 @@ namespace MWSound
SaySoundMap : : const_iterator snditer = mActiveSaySounds . find ( ptr ) ;
if ( snditer ! = mActiveSaySounds . end ( ) )
{
MWBase : : SoundStreamPtr sound = snditer - > second . first ;
Sound_Loudness * loudness = snditer - > second . second ;
float sec = mOutput - > getStreamOffset ( sound ) ;
return loudness - > getLoudnessAtTime ( sec ) ;
MWBase : : SoundStreamPtr sound = snditer - > second ;
return mOutput - > getStreamLoudness ( sound ) ;
}
return 0.0f ;
@ -451,24 +428,18 @@ namespace MWSound
{
std : : string voicefile = " Sound/ " + filename ;
Sound_Loudness * loudness ;
mVFS - > normalizeFilename ( voicefile ) ;
DecoderPtr decoder = loadVoice ( voicefile , & loudness );
DecoderPtr decoder = loadVoice ( voicefile );
if ( ! loudness - > isReady ( ) )
mPendingSaySounds [ MWWorld : : ConstPtr ( ) ] = std : : make_pair ( decoder , loudness ) ;
else
{
SaySoundMap : : iterator oldIt = mActiveSaySounds . find ( MWWorld : : ConstPtr ( ) ) ;
if ( oldIt ! = mActiveSaySounds . end ( ) )
{
mOutput - > finishStream ( oldIt - > second . first ) ;
mOutput - > finishStream ( oldIt - > second ) ;
mActiveSaySounds . erase ( oldIt ) ;
}
mActiveSaySounds . insert ( std : : make_pair ( MWWorld : : ConstPtr ( ) ,
std : : make_pair ( playVoice ( decoder , osg : : Vec3f ( ) , true ) , loudness ) ) ) ;
}
playVoice ( decoder , osg : : Vec3f ( ) , true ) ) ) ;
}
catch ( std : : exception & e )
{
@ -481,11 +452,11 @@ namespace MWSound
SaySoundMap : : const_iterator snditer = mActiveSaySounds . find ( ptr ) ;
if ( snditer ! = mActiveSaySounds . end ( ) )
{
if ( mOutput - > isStreamPlaying ( snditer - > second .first ))
if ( mOutput - > isStreamPlaying ( snditer - > second ))
return false ;
return true ;
}
return mPendingSaySounds . find ( ptr ) = = mPendingSaySounds . end ( ) ;
return true ;
}
void SoundManager : : stopSay ( const MWWorld : : ConstPtr & ptr )
@ -493,10 +464,9 @@ namespace MWSound
SaySoundMap : : iterator snditer = mActiveSaySounds . find ( ptr ) ;
if ( snditer ! = mActiveSaySounds . end ( ) )
{
mOutput - > finishStream ( snditer - > second .first );
mOutput - > finishStream ( snditer - > second );
mActiveSaySounds . erase ( snditer ) ;
}
mPendingSaySounds . erase ( ptr ) ;
}
@ -691,7 +661,7 @@ namespace MWSound
sayiter - > first ! = MWMechanics : : getPlayer ( ) & &
sayiter - > first . getCell ( ) = = cell )
{
mOutput - > finishStream ( sayiter - > second .first );
mOutput - > finishStream ( sayiter - > second );
}
+ + sayiter ;
}
@ -901,51 +871,11 @@ namespace MWSound
+ + snditer ;
}
SayDecoderMap : : iterator penditer = mPendingSaySounds . begin ( ) ;
while ( penditer ! = mPendingSaySounds . end ( ) )
{
Sound_Loudness * loudness = penditer - > second . second ;
if ( loudness - > isReady ( ) )
{
try {
DecoderPtr decoder = penditer - > second . first ;
decoder - > rewind ( ) ;
MWBase : : SoundStreamPtr sound ;
MWWorld : : ConstPtr ptr = penditer - > first ;
SaySoundMap : : iterator old = mActiveSaySounds . find ( ptr ) ;
if ( old ! = mActiveSaySounds . end ( ) )
{
mOutput - > finishStream ( old - > second . first ) ;
mActiveSaySounds . erase ( old ) ;
}
if ( ptr = = MWWorld : : ConstPtr ( ) )
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 . insert ( std : : make_pair ( ptr , std : : make_pair ( sound , loudness ) ) ) ;
}
catch ( std : : exception & e ) {
std : : cerr < < " Sound Error: " < < e . what ( ) < < std : : endl ;
}
mPendingSaySounds . erase ( penditer + + ) ;
}
else
+ + penditer ;
}
SaySoundMap : : iterator sayiter = mActiveSaySounds . begin ( ) ;
while ( sayiter ! = mActiveSaySounds . end ( ) )
{
MWWorld : : ConstPtr ptr = sayiter - > first ;
MWBase : : SoundStreamPtr sound = sayiter - > second .first ;
MWBase : : SoundStreamPtr sound = sayiter - > second ;
if ( ! ptr . isEmpty ( ) & & sound - > getIs3D ( ) )
{
MWBase : : World * world = MWBase : : Environment : : get ( ) . getWorld ( ) ;
@ -1040,7 +970,7 @@ namespace MWSound
SaySoundMap : : iterator sayiter = mActiveSaySounds . begin ( ) ;
for ( ; sayiter ! = mActiveSaySounds . end ( ) ; + + sayiter )
{
MWBase : : SoundStreamPtr sound = sayiter - > second .first ;
MWBase : : SoundStreamPtr sound = sayiter - > second ;
sound - > setBaseVolume ( volumeFromType ( sound - > getPlayType ( ) ) ) ;
mOutput - > updateStream ( sound ) ;
}
@ -1080,16 +1010,9 @@ namespace MWSound
SaySoundMap : : iterator sayiter = mActiveSaySounds . find ( old ) ;
if ( sayiter ! = mActiveSaySounds . end ( ) )
{
SoundLoudnessPair sndlist = sayiter - > second ;
MWBase: : SoundStreamPtr stream = sayiter - > second ;
mActiveSaySounds . erase ( sayiter ) ;
mActiveSaySounds [ updated ] = sndlist ;
}
SayDecoderMap : : iterator penditer = mPendingSaySounds . find ( old ) ;
if ( penditer ! = mPendingSaySounds . end ( ) )
{
DecoderLoudnessPair dl = penditer - > second ;
mPendingSaySounds . erase ( penditer ) ;
mPendingSaySounds [ updated ] = dl ;
mActiveSaySounds [ updated ] = stream ;
}
}
@ -1175,13 +1098,12 @@ namespace MWSound
mActiveSounds . clear ( ) ;
SaySoundMap : : iterator sayiter = mActiveSaySounds . begin ( ) ;
for ( ; sayiter ! = mActiveSaySounds . end ( ) ; + + sayiter )
mOutput - > finishStream ( sayiter - > second .first );
mOutput - > finishStream ( sayiter - > second );
mActiveSaySounds . clear ( ) ;
TrackList : : iterator trkiter = mActiveTracks . begin ( ) ;
for ( ; trkiter ! = mActiveTracks . end ( ) ; + + trkiter )
mOutput - > finishStream ( * trkiter ) ;
mActiveTracks . clear ( ) ;
mPendingSaySounds . clear ( ) ;
mUnderwaterSound . reset ( ) ;
stopMusic ( ) ;
}