1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:53:50 +00:00

Use a local variable to mark sound streams as finished while processing

This avoids a race condition where the source can underrun while the final
buffers are being queued and the sound can be detected as stopped
This commit is contained in:
Chris Robinson 2012-03-21 14:49:29 -07:00
parent 6a85ef1229
commit 8c5f85ca83

View file

@ -251,6 +251,7 @@ void OpenAL_SoundStream::update(const float *pos)
bool OpenAL_SoundStream::process() bool OpenAL_SoundStream::process()
{ {
bool finished = mIsFinished;
ALint processed, state; ALint processed, state;
alGetSourcei(mSource, AL_SOURCE_STATE, &state); alGetSourcei(mSource, AL_SOURCE_STATE, &state);
@ -267,11 +268,11 @@ bool OpenAL_SoundStream::process()
alSourceUnqueueBuffers(mSource, 1, &bufid); alSourceUnqueueBuffers(mSource, 1, &bufid);
processed--; processed--;
if(mIsFinished) if(finished)
continue; continue;
got = mDecoder->read(data.data(), data.size()); got = mDecoder->read(data.data(), data.size());
mIsFinished = (got < data.size()); finished = (got < data.size());
if(got > 0) if(got > 0)
{ {
alBufferData(bufid, mFormat, data.data(), got, mSampleRate); alBufferData(bufid, mFormat, data.data(), got, mSampleRate);
@ -294,7 +295,8 @@ bool OpenAL_SoundStream::process()
} }
} }
return !mIsFinished; mIsFinished = finished;
return !finished;
} }
// //