~openmw/openmw/openmw-packaging2

« back to all changes in this revision

Viewing changes to apps/openmw/mwsound/soundmanagerimp.cpp

  • Committer: Scott Howard
  • Date: 2016-09-15 20:56:29 UTC
  • Revision ID: showard@debian.org-20160915205629-3tvfxe47zrb41a91
Cron update. Git hash: 37278b5

Show diffs side-by-side

added added

removed removed

Lines of Context:
219
219
        return sfx;
220
220
    }
221
221
 
222
 
    DecoderPtr SoundManager::loadVoice(const std::string &voicefile, Sound_Loudness **lipdata)
 
222
    DecoderPtr SoundManager::loadVoice(const std::string &voicefile)
223
223
    {
224
224
        DecoderPtr decoder = getDecoder();
225
225
        // Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav.
234
234
            decoder->open(file);
235
235
        }
236
236
 
237
 
        NameLoudnessRefMap::iterator lipiter = mVoiceLipNameMap.find(voicefile);
238
 
        if(lipiter != mVoiceLipNameMap.end())
239
 
        {
240
 
            *lipdata = lipiter->second;
241
 
            return decoder;
242
 
        }
243
 
 
244
 
        mVoiceLipBuffers.insert(mVoiceLipBuffers.end(), Sound_Loudness());
245
 
        lipiter = mVoiceLipNameMap.insert(
246
 
            std::make_pair(voicefile, &mVoiceLipBuffers.back())
247
 
        ).first;
248
 
 
249
 
        mOutput->loadLoudnessAsync(decoder, lipiter->second);
250
 
 
251
 
        *lipdata = lipiter->second;
252
237
        return decoder;
253
238
    }
254
239
 
273
258
        {
274
259
            sound.reset(new Stream(pos, 1.0f, basevol, 1.0f, minDistance, maxDistance,
275
260
                                   Play_Normal|Play_TypeVoice|Play_3D));
276
 
            mOutput->streamSound3D(decoder, sound);
 
261
            mOutput->streamSound3D(decoder, sound, true);
277
262
        }
278
263
        return sound;
279
264
    }
400
385
        {
401
386
            std::string voicefile = "Sound/"+filename;
402
387
 
403
 
            Sound_Loudness *loudness;
404
388
            mVFS->normalizeFilename(voicefile);
405
 
            DecoderPtr decoder = loadVoice(voicefile, &loudness);
406
 
 
407
 
            if(!loudness->isReady())
408
 
                mPendingSaySounds[ptr] = std::make_pair(decoder, loudness);
409
 
            else
 
389
            DecoderPtr decoder = loadVoice(voicefile);
 
390
 
 
391
            MWBase::World *world = MWBase::Environment::get().getWorld();
 
392
            const osg::Vec3f pos = world->getActorHeadTransform(ptr).getTrans();
 
393
 
 
394
            SaySoundMap::iterator oldIt = mActiveSaySounds.find(ptr);
 
395
            if (oldIt != mActiveSaySounds.end())
410
396
            {
411
 
                MWBase::World *world = MWBase::Environment::get().getWorld();
412
 
                const osg::Vec3f pos = world->getActorHeadTransform(ptr).getTrans();
413
 
 
414
 
                SaySoundMap::iterator oldIt = mActiveSaySounds.find(ptr);
415
 
                if (oldIt != mActiveSaySounds.end())
416
 
                {
417
 
                    mOutput->finishStream(oldIt->second.first);
418
 
                    mActiveSaySounds.erase(oldIt);
419
 
                }
420
 
 
421
 
                MWBase::SoundStreamPtr sound = playVoice(decoder, pos, (ptr == MWMechanics::getPlayer()));
422
 
 
423
 
                mActiveSaySounds.insert(std::make_pair(ptr, std::make_pair(sound, loudness)));
 
397
                mOutput->finishStream(oldIt->second);
 
398
                mActiveSaySounds.erase(oldIt);
424
399
            }
 
400
 
 
401
            MWBase::SoundStreamPtr sound = playVoice(decoder, pos, (ptr == MWMechanics::getPlayer()));
 
402
 
 
403
            mActiveSaySounds.insert(std::make_pair(ptr, sound));
425
404
        }
426
405
        catch(std::exception &e)
427
406
        {
434
413
        SaySoundMap::const_iterator snditer = mActiveSaySounds.find(ptr);
435
414
        if(snditer != mActiveSaySounds.end())
436
415
        {
437
 
            MWBase::SoundStreamPtr sound = snditer->second.first;
438
 
            Sound_Loudness *loudness = snditer->second.second;
439
 
            float sec = mOutput->getStreamOffset(sound);
440
 
            return loudness->getLoudnessAtTime(sec);
 
416
            MWBase::SoundStreamPtr sound = snditer->second;
 
417
            return mOutput->getStreamLoudness(sound);
441
418
        }
442
419
 
443
420
        return 0.0f;
451
428
        {
452
429
            std::string voicefile = "Sound/"+filename;
453
430
 
454
 
            Sound_Loudness *loudness;
455
431
            mVFS->normalizeFilename(voicefile);
456
 
            DecoderPtr decoder = loadVoice(voicefile, &loudness);
 
432
            DecoderPtr decoder = loadVoice(voicefile);
457
433
 
458
 
            if(!loudness->isReady())
459
 
                mPendingSaySounds[MWWorld::ConstPtr()] = std::make_pair(decoder, loudness);
460
 
            else
 
434
            SaySoundMap::iterator oldIt = mActiveSaySounds.find(MWWorld::ConstPtr());
 
435
            if (oldIt != mActiveSaySounds.end())
461
436
            {
462
 
                SaySoundMap::iterator oldIt = mActiveSaySounds.find(MWWorld::ConstPtr());
463
 
                if (oldIt != mActiveSaySounds.end())
464
 
                {
465
 
                    mOutput->finishStream(oldIt->second.first);
466
 
                    mActiveSaySounds.erase(oldIt);
467
 
                }
468
 
 
469
 
                mActiveSaySounds.insert(std::make_pair(MWWorld::ConstPtr(),
470
 
                                                       std::make_pair(playVoice(decoder, osg::Vec3f(), true), loudness)));
 
437
                mOutput->finishStream(oldIt->second);
 
438
                mActiveSaySounds.erase(oldIt);
471
439
            }
 
440
 
 
441
            mActiveSaySounds.insert(std::make_pair(MWWorld::ConstPtr(),
 
442
                                                   playVoice(decoder, osg::Vec3f(), true)));
472
443
        }
473
444
        catch(std::exception &e)
474
445
        {
481
452
        SaySoundMap::const_iterator snditer = mActiveSaySounds.find(ptr);
482
453
        if(snditer != mActiveSaySounds.end())
483
454
        {
484
 
            if(mOutput->isStreamPlaying(snditer->second.first))
 
455
            if(mOutput->isStreamPlaying(snditer->second))
485
456
                return false;
486
457
            return true;
487
458
        }
488
 
        return mPendingSaySounds.find(ptr) == mPendingSaySounds.end();
 
459
        return true;
489
460
    }
490
461
 
491
462
    void SoundManager::stopSay(const MWWorld::ConstPtr &ptr)
493
464
        SaySoundMap::iterator snditer = mActiveSaySounds.find(ptr);
494
465
        if(snditer != mActiveSaySounds.end())
495
466
        {
496
 
            mOutput->finishStream(snditer->second.first);
 
467
            mOutput->finishStream(snditer->second);
497
468
            mActiveSaySounds.erase(snditer);
498
469
        }
499
 
        mPendingSaySounds.erase(ptr);
500
470
    }
501
471
 
502
472
 
691
661
               sayiter->first != MWMechanics::getPlayer() &&
692
662
               sayiter->first.getCell() == cell)
693
663
            {
694
 
                mOutput->finishStream(sayiter->second.first);
 
664
                mOutput->finishStream(sayiter->second);
695
665
            }
696
666
            ++sayiter;
697
667
        }
837
807
        timePassed = 0.0f;
838
808
 
839
809
        // Make sure music is still playing
840
 
        if(!isMusicPlaying())
 
810
        if(!isMusicPlaying() && !mCurrentPlaylist.empty())
841
811
            startRandomTitle();
842
812
 
843
813
        Environment env = Env_Normal;
901
871
                ++snditer;
902
872
        }
903
873
 
904
 
        SayDecoderMap::iterator penditer = mPendingSaySounds.begin();
905
 
        while(penditer != mPendingSaySounds.end())
906
 
        {
907
 
            Sound_Loudness *loudness = penditer->second.second;
908
 
            if(loudness->isReady())
909
 
            {
910
 
                try {
911
 
                    DecoderPtr decoder = penditer->second.first;
912
 
                    decoder->rewind();
913
 
 
914
 
                    MWBase::SoundStreamPtr sound;
915
 
                    MWWorld::ConstPtr ptr = penditer->first;
916
 
 
917
 
                    SaySoundMap::iterator old = mActiveSaySounds.find(ptr);
918
 
                    if (old != mActiveSaySounds.end())
919
 
                    {
920
 
                        mOutput->finishStream(old->second.first);
921
 
                        mActiveSaySounds.erase(old);
922
 
                    }
923
 
 
924
 
                    if(ptr == MWWorld::ConstPtr())
925
 
                        sound = playVoice(decoder, osg::Vec3f(), true);
926
 
                    else
927
 
                    {
928
 
                        MWBase::World *world = MWBase::Environment::get().getWorld();
929
 
                        const osg::Vec3f pos = world->getActorHeadTransform(ptr).getTrans();
930
 
                        sound = playVoice(decoder, pos, (ptr == MWMechanics::getPlayer()));
931
 
                    }
932
 
                    mActiveSaySounds.insert(std::make_pair(ptr, std::make_pair(sound, loudness)));
933
 
                }
934
 
                catch(std::exception &e) {
935
 
                    std::cerr<< "Sound Error: "<<e.what() <<std::endl;
936
 
                }
937
 
 
938
 
                mPendingSaySounds.erase(penditer++);
939
 
            }
940
 
            else
941
 
                ++penditer;
942
 
        }
943
 
 
944
874
        SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
945
875
        while(sayiter != mActiveSaySounds.end())
946
876
        {
947
877
            MWWorld::ConstPtr ptr = sayiter->first;
948
 
            MWBase::SoundStreamPtr sound = sayiter->second.first;
 
878
            MWBase::SoundStreamPtr sound = sayiter->second;
949
879
            if(!ptr.isEmpty() && sound->getIs3D())
950
880
            {
951
881
                MWBase::World *world = MWBase::Environment::get().getWorld();
1040
970
        SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
1041
971
        for(;sayiter != mActiveSaySounds.end();++sayiter)
1042
972
        {
1043
 
            MWBase::SoundStreamPtr sound = sayiter->second.first;
 
973
            MWBase::SoundStreamPtr sound = sayiter->second;
1044
974
            sound->setBaseVolume(volumeFromType(sound->getPlayType()));
1045
975
            mOutput->updateStream(sound);
1046
976
        }
1080
1010
        SaySoundMap::iterator sayiter = mActiveSaySounds.find(old);
1081
1011
        if(sayiter != mActiveSaySounds.end())
1082
1012
        {
1083
 
            SoundLoudnessPair sndlist = sayiter->second;
 
1013
            MWBase::SoundStreamPtr stream = sayiter->second;
1084
1014
            mActiveSaySounds.erase(sayiter);
1085
 
            mActiveSaySounds[updated] = sndlist;
1086
 
        }
1087
 
        SayDecoderMap::iterator penditer = mPendingSaySounds.find(old);
1088
 
        if(penditer != mPendingSaySounds.end())
1089
 
        {
1090
 
            DecoderLoudnessPair dl = penditer->second;
1091
 
            mPendingSaySounds.erase(penditer);
1092
 
            mPendingSaySounds[updated] = dl;
 
1015
            mActiveSaySounds[updated] = stream;
1093
1016
        }
1094
1017
    }
1095
1018
 
1175
1098
        mActiveSounds.clear();
1176
1099
        SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
1177
1100
        for(;sayiter != mActiveSaySounds.end();++sayiter)
1178
 
            mOutput->finishStream(sayiter->second.first);
 
1101
            mOutput->finishStream(sayiter->second);
1179
1102
        mActiveSaySounds.clear();
1180
1103
        TrackList::iterator trkiter = mActiveTracks.begin();
1181
1104
        for(;trkiter != mActiveTracks.end();++trkiter)
1182
1105
            mOutput->finishStream(*trkiter);
1183
1106
        mActiveTracks.clear();
1184
 
        mPendingSaySounds.clear();
1185
1107
        mUnderwaterSound.reset();
1186
1108
        stopMusic();
1187
1109
    }