Keep track of audio tracks

openmw-38
Chris Robinson 9 years ago
parent 2883cdba5c
commit 3a39a92b93

@ -474,6 +474,8 @@ namespace MWSound
try
{
track = mOutput->streamSound(decoder, volumeFromType(type), 1.0f, Play_NoEnv|type);
TrackList::iterator iter = std::lower_bound(mActiveTracks.begin(), mActiveTracks.end(), track);
mActiveTracks.insert(iter, track);
}
catch(std::exception &e)
{
@ -485,6 +487,9 @@ namespace MWSound
void SoundManager::stopTrack(MWBase::SoundStreamPtr stream)
{
mOutput->stopStream(stream);
TrackList::iterator iter = std::lower_bound(mActiveTracks.begin(), mActiveTracks.end(), stream);
if(iter != mActiveTracks.end() && *iter == stream)
mActiveTracks.erase(iter);
}
double SoundManager::getTrackTimeDelay(MWBase::SoundStreamPtr stream)
@ -923,6 +928,24 @@ namespace MWSound
++sayiter;
}
}
TrackList::iterator trkiter = mActiveTracks.begin();
for(;trkiter != mActiveTracks.end();++trkiter)
{
MWBase::SoundStreamPtr sound = *trkiter;
if(!mOutput->isStreamPlaying(sound))
{
mOutput->stopStream(sound);
trkiter = mActiveTracks.erase(trkiter);
}
else
{
sound->updateFade(duration);
mOutput->updateStream(sound);
++trkiter;
}
}
mOutput->finishUpdate();
}
@ -970,6 +993,13 @@ namespace MWSound
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
mOutput->updateStream(sound);
}
TrackList::iterator trkiter = mActiveTracks.begin();
for(;trkiter != mActiveTracks.end();++trkiter)
{
MWBase::SoundStreamPtr sound = *trkiter;
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
mOutput->updateStream(sound);
}
if(mMusic)
{
mMusic->setBaseVolume(volumeFromType(mMusic->getPlayType()));
@ -1099,6 +1129,10 @@ namespace MWSound
for(;sayiter != mActiveSaySounds.end();++sayiter)
mOutput->stopStream(sayiter->second.first);
mActiveSaySounds.clear();
TrackList::iterator trkiter = mActiveTracks.begin();
for(;trkiter != mActiveTracks.end();++trkiter)
mOutput->stopStream(*trkiter);
mActiveTracks.clear();
mPendingSaySounds.clear();
mUnderwaterSound.reset();
stopMusic();

@ -79,9 +79,6 @@ namespace MWSound
typedef std::deque<Sound_Buffer*> SoundList;
SoundList mUnusedBuffers;
MWBase::SoundStreamPtr mMusic;
std::string mCurrentPlaylist;
typedef std::pair<MWBase::SoundPtr,Sound_Buffer*> SoundBufferRefPair;
typedef std::vector<SoundBufferRefPair> SoundBufferRefPairList;
typedef std::map<MWWorld::Ptr,SoundBufferRefPairList> SoundMap;
@ -95,7 +92,11 @@ namespace MWSound
typedef std::map<MWWorld::Ptr,DecoderLoudnessPair> SayDecoderMap;
SayDecoderMap mPendingSaySounds;
MWBase::SoundPtr mUnderwaterSound;
typedef std::vector<MWBase::SoundStreamPtr> TrackList;
TrackList mActiveTracks;
MWBase::SoundStreamPtr mMusic;
std::string mCurrentPlaylist;
bool mListenerUnderwater;
osg::Vec3f mListenerPos;
@ -104,6 +105,8 @@ namespace MWSound
int mPausedSoundTypes;
MWBase::SoundPtr mUnderwaterSound;
Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound);
Sound_Buffer *lookupSound(const std::string &soundId) const;

Loading…
Cancel
Save