From fc8e07c79109cefdef2353548ea07064fc87e5f6 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 15 Nov 2015 12:21:14 +0100 Subject: [PATCH] Add some extra checks, ref #254 --- code/nel/src/sound/driver/xaudio2/source_xaudio2.cpp | 10 +++++++--- code/nel/src/sound/driver/xaudio2/source_xaudio2.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/code/nel/src/sound/driver/xaudio2/source_xaudio2.cpp b/code/nel/src/sound/driver/xaudio2/source_xaudio2.cpp index 21290951c..a22c68f55 100644 --- a/code/nel/src/sound/driver/xaudio2/source_xaudio2.cpp +++ b/code/nel/src/sound/driver/xaudio2/source_xaudio2.cpp @@ -32,7 +32,7 @@ using namespace NLMISC; namespace NLSOUND { CSourceXAudio2::CSourceXAudio2(CSoundDriverXAudio2 *soundDriver) -: _SoundDriver(soundDriver), _SourceVoice(NULL), _StaticBuffer(NULL), _OperationSet(soundDriver->getUniqueOperationSet()), +: _SoundDriver(soundDriver), _SourceVoice(NULL), _StaticBuffer(NULL), _LastPreparedBuffer(NULL), _OperationSet(soundDriver->getUniqueOperationSet()), _Format(IBuffer::FormatUnknown), _Frequency(0), _PlayStart(0), _Doppler(1.0f), _Pos(0.0f, 0.0f, 0.0f), _Relative(false), _Alpha(1.0), _DirectDryVoice(NULL), _DirectFilterVoice(NULL), _EffectDryVoice(NULL), _EffectFilterVoice(NULL), @@ -407,6 +407,7 @@ void CSourceXAudio2::submitStreamingBuffer(IBuffer *buffer) uint32 frequency; buffer->getFormat(bufferFormat, channels, bitsPerSample, frequency); preparePlay(bufferFormat, channels, bitsPerSample, frequency); + _LastPreparedBuffer = NULL; } submitBuffer(static_cast(buffer)); @@ -455,7 +456,8 @@ void CSourceXAudio2::setLooping(bool l) if (FAILED(_SourceVoice->FlushSourceBuffers())) nlwarning(NLSOUND_XAUDIO2_PREFIX "FAILED FlushSourceBuffers"); // resubmit with updated looping settings - submitBuffer(_StaticBuffer); + if (_LastPreparedBuffer == _StaticBuffer) + submitBuffer(_StaticBuffer); } else { @@ -478,7 +480,8 @@ void CSourceXAudio2::setLooping(bool l) if (FAILED(_SourceVoice->FlushSourceBuffers())) nlwarning(NLSOUND_XAUDIO2_PREFIX "FAILED FlushSourceBuffers"); // queue buffer with correct looping parameters - submitBuffer(_StaticBuffer); + if (_LastPreparedBuffer == _StaticBuffer) + submitBuffer(_StaticBuffer); } } } @@ -635,6 +638,7 @@ bool CSourceXAudio2::play() _StaticBuffer->getChannels(), _StaticBuffer->getBitsPerSample(), _StaticBuffer->getFrequency()); + _LastPreparedBuffer = _StaticBuffer; submitBuffer(_StaticBuffer); _PlayStart = CTime::getLocalTime(); if (SUCCEEDED(_SourceVoice->Start(0))) _IsPlaying = true; diff --git a/code/nel/src/sound/driver/xaudio2/source_xaudio2.h b/code/nel/src/sound/driver/xaudio2/source_xaudio2.h index a2d542349..4e50774b2 100644 --- a/code/nel/src/sound/driver/xaudio2/source_xaudio2.h +++ b/code/nel/src/sound/driver/xaudio2/source_xaudio2.h @@ -41,6 +41,8 @@ private: CSoundDriverXAudio2 *_SoundDriver; /// Buffer that should be playing. CBufferXAudio2 *_StaticBuffer; + /// Last buffer that was prepared for playing. + CBufferXAudio2 *_LastPreparedBuffer; // -- Pointers -- /// Source voice, can be NULL!