1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-23 20:09:43 +00:00

Use separate lists for openal sounds and streams

This commit is contained in:
Chris Robinson 2015-11-23 07:51:52 -08:00
parent 0f33f41d8d
commit 16f72886e9
2 changed files with 33 additions and 39 deletions

View file

@ -296,7 +296,7 @@ OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, ALuint src, Decode
mBufferSize = static_cast<ALuint>(sBufferLength*srate); mBufferSize = static_cast<ALuint>(sBufferLength*srate);
mBufferSize = framesToBytes(mBufferSize, chans, type); mBufferSize = framesToBytes(mBufferSize, chans, type);
mOutput.mActiveSounds.push_back(this); mOutput.mActiveStreams.push_back(this);
} }
catch(std::exception&) catch(std::exception&)
{ {
@ -318,8 +318,8 @@ OpenAL_SoundStream::~OpenAL_SoundStream()
mDecoder->close(); mDecoder->close();
mOutput.mActiveSounds.erase(std::find(mOutput.mActiveSounds.begin(), mOutput.mActiveStreams.erase(std::find(mOutput.mActiveStreams.begin(),
mOutput.mActiveSounds.end(), this)); mOutput.mActiveStreams.end(), this));
} }
void OpenAL_SoundStream::play() void OpenAL_SoundStream::play()
@ -802,12 +802,11 @@ void OpenAL_Output::unloadSound(Sound_Handle data)
SoundVec::const_iterator iter = mActiveSounds.begin(); SoundVec::const_iterator iter = mActiveSounds.begin();
for(;iter != mActiveSounds.end();++iter) for(;iter != mActiveSounds.end();++iter)
{ {
OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter); if((*iter)->mSource && (*iter)->mBuffer == buffer)
if(sound && sound->mSource && sound->mBuffer == buffer)
{ {
alSourceStop(sound->mSource); alSourceStop((*iter)->mSource);
alSourcei(sound->mSource, AL_BUFFER, 0); alSourcei((*iter)->mSource, AL_BUFFER, 0);
sound->mBuffer = 0; (*iter)->mBuffer = 0;
} }
} }
alDeleteBuffers(1, &buffer); alDeleteBuffers(1, &buffer);
@ -947,22 +946,17 @@ void OpenAL_Output::updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdi
void OpenAL_Output::pauseSounds(int types) void OpenAL_Output::pauseSounds(int types)
{ {
std::vector<ALuint> sources; std::vector<ALuint> sources;
SoundVec::const_iterator iter = mActiveSounds.begin(); SoundVec::const_iterator sound = mActiveSounds.begin();
while(iter != mActiveSounds.end()) for(;sound != mActiveSounds.end();++sound)
{ {
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter); if(*sound && (*sound)->mSource && ((*sound)->getPlayType()&types))
if(stream) sources.push_back((*sound)->mSource);
{
if(stream->mSource && (stream->getPlayType()&types))
sources.push_back(stream->mSource);
} }
else StreamVec::const_iterator stream = mActiveStreams.begin();
for(;stream != mActiveStreams.end();++stream)
{ {
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter); if(*stream && (*stream)->mSource && ((*stream)->getPlayType()&types))
if(sound && sound->mSource && (sound->getPlayType()&types)) sources.push_back((*stream)->mSource);
sources.push_back(sound->mSource);
}
++iter;
} }
if(!sources.empty()) if(!sources.empty())
{ {
@ -974,22 +968,17 @@ void OpenAL_Output::pauseSounds(int types)
void OpenAL_Output::resumeSounds(int types) void OpenAL_Output::resumeSounds(int types)
{ {
std::vector<ALuint> sources; std::vector<ALuint> sources;
SoundVec::const_iterator iter = mActiveSounds.begin(); SoundVec::const_iterator sound = mActiveSounds.begin();
while(iter != mActiveSounds.end()) for(;sound != mActiveSounds.end();++sound)
{ {
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter); if(*sound && (*sound)->mSource && ((*sound)->getPlayType()&types))
if(stream) sources.push_back((*sound)->mSource);
{
if(stream->mSource && (stream->getPlayType()&types))
sources.push_back(stream->mSource);
} }
else StreamVec::const_iterator stream = mActiveStreams.begin();
for(;stream != mActiveStreams.end();++stream)
{ {
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter); if(*stream && (*stream)->mSource && ((*stream)->getPlayType()&types))
if(sound && sound->mSource && (sound->getPlayType()&types)) sources.push_back((*stream)->mSource);
sources.push_back(sound->mSource);
}
++iter;
} }
if(!sources.empty()) if(!sources.empty())
{ {

View file

@ -16,6 +16,9 @@ namespace MWSound
class SoundManager; class SoundManager;
class Sound; class Sound;
class OpenAL_Sound;
class OpenAL_SoundStream;
class OpenAL_Output : public Sound_Output class OpenAL_Output : public Sound_Output
{ {
ALCdevice *mDevice; ALCdevice *mDevice;
@ -24,8 +27,10 @@ namespace MWSound
typedef std::deque<ALuint> IDDq; typedef std::deque<ALuint> IDDq;
IDDq mFreeSources; IDDq mFreeSources;
typedef std::vector<Sound*> SoundVec; typedef std::vector<OpenAL_Sound*> SoundVec;
SoundVec mActiveSounds; SoundVec mActiveSounds;
typedef std::vector<OpenAL_SoundStream*> StreamVec;
StreamVec mActiveStreams;
Environment mLastEnvironment; Environment mLastEnvironment;