mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 22:45:35 +00:00
Keep track of the actual active sounds
This commit is contained in:
parent
d348435a1d
commit
20321c4552
2 changed files with 47 additions and 8 deletions
|
@ -131,6 +131,8 @@ class OpenAL_SoundStream : public Sound
|
||||||
OpenAL_SoundStream(const OpenAL_SoundStream &rhs);
|
OpenAL_SoundStream(const OpenAL_SoundStream &rhs);
|
||||||
OpenAL_SoundStream& operator=(const OpenAL_SoundStream &rhs);
|
OpenAL_SoundStream& operator=(const OpenAL_SoundStream &rhs);
|
||||||
|
|
||||||
|
friend class OpenAL_Output;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder);
|
OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder);
|
||||||
virtual ~OpenAL_SoundStream();
|
virtual ~OpenAL_SoundStream();
|
||||||
|
@ -232,6 +234,8 @@ 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);
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -252,6 +256,9 @@ OpenAL_SoundStream::~OpenAL_SoundStream()
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
mDecoder->close();
|
mDecoder->close();
|
||||||
|
|
||||||
|
mOutput.mActiveSounds.erase(std::find(mOutput.mActiveSounds.begin(),
|
||||||
|
mOutput.mActiveSounds.end(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenAL_SoundStream::play()
|
void OpenAL_SoundStream::play()
|
||||||
|
@ -402,6 +409,8 @@ protected:
|
||||||
ALuint mSource;
|
ALuint mSource;
|
||||||
ALuint mBuffer;
|
ALuint mBuffer;
|
||||||
|
|
||||||
|
friend class OpenAL_Output;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OpenAL_Sound(const OpenAL_Sound &rhs);
|
OpenAL_Sound(const OpenAL_Sound &rhs);
|
||||||
OpenAL_Sound& operator=(const OpenAL_Sound &rhs);
|
OpenAL_Sound& operator=(const OpenAL_Sound &rhs);
|
||||||
|
@ -435,6 +444,7 @@ public:
|
||||||
OpenAL_Sound::OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf)
|
OpenAL_Sound::OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf)
|
||||||
: mOutput(output), mSource(src), mBuffer(buf)
|
: mOutput(output), mSource(src), mBuffer(buf)
|
||||||
{
|
{
|
||||||
|
mOutput.mActiveSounds.push_back(this);
|
||||||
}
|
}
|
||||||
OpenAL_Sound::~OpenAL_Sound()
|
OpenAL_Sound::~OpenAL_Sound()
|
||||||
{
|
{
|
||||||
|
@ -443,6 +453,9 @@ OpenAL_Sound::~OpenAL_Sound()
|
||||||
|
|
||||||
mOutput.mFreeSources.push_back(mSource);
|
mOutput.mFreeSources.push_back(mSource);
|
||||||
mOutput.bufferFinished(mBuffer);
|
mOutput.bufferFinished(mBuffer);
|
||||||
|
|
||||||
|
mOutput.mActiveSounds.erase(std::find(mOutput.mActiveSounds.begin(),
|
||||||
|
mOutput.mActiveSounds.end(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenAL_Sound::stop()
|
void OpenAL_Sound::stop()
|
||||||
|
@ -597,6 +610,7 @@ void OpenAL_Output::deinit()
|
||||||
{
|
{
|
||||||
mStreamThread->removeAll();
|
mStreamThread->removeAll();
|
||||||
|
|
||||||
|
std::cerr<< "There are "<<mActiveSounds.size()<<" active sources at close" <<std::endl;
|
||||||
mFreeSources.clear();
|
mFreeSources.clear();
|
||||||
if(mSources.size() > 0)
|
if(mSources.size() > 0)
|
||||||
alDeleteSources(mSources.size(), &mSources[0]);
|
alDeleteSources(mSources.size(), &mSources[0]);
|
||||||
|
@ -889,11 +903,22 @@ void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3
|
||||||
|
|
||||||
void OpenAL_Output::pauseAllSounds()
|
void OpenAL_Output::pauseAllSounds()
|
||||||
{
|
{
|
||||||
IDVec sources = mSources;
|
IDVec sources;
|
||||||
IDDq::const_iterator iter = mFreeSources.begin();
|
SoundVec::const_iterator iter = mActiveSounds.begin();
|
||||||
while(iter != mFreeSources.end())
|
while(iter != mActiveSounds.end())
|
||||||
{
|
{
|
||||||
sources.erase(std::find(sources.begin(), sources.end(), *iter));
|
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter);
|
||||||
|
if(stream)
|
||||||
|
{
|
||||||
|
if(stream->mSource)
|
||||||
|
sources.push_back(stream->mSource);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter);
|
||||||
|
if(sound && sound->mSource)
|
||||||
|
sources.push_back(sound->mSource);
|
||||||
|
}
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
if(sources.size() > 0)
|
if(sources.size() > 0)
|
||||||
|
@ -902,11 +927,22 @@ void OpenAL_Output::pauseAllSounds()
|
||||||
|
|
||||||
void OpenAL_Output::resumeAllSounds()
|
void OpenAL_Output::resumeAllSounds()
|
||||||
{
|
{
|
||||||
IDVec sources = mSources;
|
IDVec sources;
|
||||||
IDDq::const_iterator iter = mFreeSources.begin();
|
SoundVec::const_iterator iter = mActiveSounds.begin();
|
||||||
while(iter != mFreeSources.end())
|
while(iter != mActiveSounds.end())
|
||||||
{
|
{
|
||||||
sources.erase(std::find(sources.begin(), sources.end(), *iter));
|
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter);
|
||||||
|
if(stream)
|
||||||
|
{
|
||||||
|
if(stream->mSource)
|
||||||
|
sources.push_back(stream->mSource);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter);
|
||||||
|
if(sound && sound->mSource)
|
||||||
|
sources.push_back(sound->mSource);
|
||||||
|
}
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
if(sources.size() > 0)
|
if(sources.size() > 0)
|
||||||
|
|
|
@ -36,6 +36,9 @@ namespace MWSound
|
||||||
|
|
||||||
uint64_t mBufferCacheMemSize;
|
uint64_t mBufferCacheMemSize;
|
||||||
|
|
||||||
|
typedef std::vector<Sound*> SoundVec;
|
||||||
|
SoundVec mActiveSounds;
|
||||||
|
|
||||||
ALuint getBuffer(const std::string &fname);
|
ALuint getBuffer(const std::string &fname);
|
||||||
void bufferFinished(ALuint buffer);
|
void bufferFinished(ALuint buffer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue