From afa2cb6de7a708a89630d30478bd21bbbef968b6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 19 Mar 2012 07:51:28 -0700 Subject: [PATCH] Stop trying to read decoded audio once it's finished --- apps/openmw/mwsound/openal_output.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index d63482273..f3cc261a4 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -230,6 +230,13 @@ void OpenAL_SoundStream::stop() bool OpenAL_SoundStream::isPlaying() { + ALint state; + + alGetSourcei(mSource, AL_SOURCE_STATE, &state); + throwALerror(); + + if(state == AL_PLAYING) + return true; return !mIsFinished; } @@ -259,7 +266,11 @@ bool OpenAL_SoundStream::process() alSourceUnqueueBuffers(mSource, 1, &bufid); processed--; + if(mIsFinished) + continue; + got = mDecoder->read(&data[0], data.size()); + mIsFinished = (got < data.size()); if(got > 0) { alBufferData(bufid, mFormat, &data[0], got, mSampleRate); @@ -275,17 +286,14 @@ bool OpenAL_SoundStream::process() alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued); throwALerror(); - if(queued == 0) + if(queued > 0) { - mIsFinished = true; - return false; + alSourcePlay(mSource); + throwALerror(); } - - alSourcePlay(mSource); - throwALerror(); } - return true; + return !mIsFinished; } //