diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index 243a498a1..f6923daea 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -44,7 +44,8 @@ SoundSDL2::SoundSDL2(OSystem& osystem) myVolume(100), myVolumeFactor(0xffff), myAudioQueue(0), - myCurrentFragment(0) + myCurrentFragment(0), + myFragmentBufferSize(0) { myOSystem.logMessage("SoundSDL2::SoundSDL2 started ...", 2); @@ -124,6 +125,12 @@ void SoundSDL2::open(shared_ptr audioQueue) myCurrentFragment = 0; myTimeIndex = 0; myFragmentIndex = 0; + myFragmentBufferSize = static_cast( + ceil( + 1.5 * static_cast(myHardwareSpec.samples) / static_cast(myAudioQueue->fragmentSize()) + * static_cast(myAudioQueue->sampleRate()) / static_cast(myHardwareSpec.freq) + ) + ); // Adjust volume to that defined in settings setVolume(myOSystem.settings().getInt("volume")); @@ -215,7 +222,7 @@ void SoundSDL2::adjustVolume(Int8 direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SoundSDL2::processFragment(Int16* stream, uInt32 length) { - if (myUnderrun && myAudioQueue->size() > 1) { + if (myUnderrun && myAudioQueue->size() > myFragmentBufferSize) { myUnderrun = false; myCurrentFragment = myAudioQueue->dequeue(myCurrentFragment); myFragmentIndex = 0; diff --git a/src/common/SoundSDL2.hxx b/src/common/SoundSDL2.hxx index da141959d..49217a0ed 100644 --- a/src/common/SoundSDL2.hxx +++ b/src/common/SoundSDL2.hxx @@ -123,6 +123,7 @@ class SoundSDL2 : public Sound Int16* myCurrentFragment; uInt32 myTimeIndex; uInt32 myFragmentIndex; + uInt32 myFragmentBufferSize; bool myUnderrun; private: