From 8154ccc4e5c7df0ee841e7c0804f475186cd8fdc Mon Sep 17 00:00:00 2001 From: hogliux Date: Tue, 22 Nov 2016 11:44:11 +0000 Subject: [PATCH] Added a fix for a potential wrap-around bug in BufferingAudioSource --- .../sources/juce_BufferingAudioSource.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp b/modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp index 98ee3793d0..2037035c34 100644 --- a/modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp +++ b/modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp @@ -168,9 +168,12 @@ bool BufferingAudioSource::waitForNextAudioBlockReady (const AudioSourceChannelI return true; uint32 now = Time::getMillisecondCounter(); - const uint32 endTime = now + timeout; + const uint32 startTime = now; - while (now <= endTime) + uint32 elapsed = (now >= startTime ? now - startTime + : (std::numeric_limits::max() - startTime) + now); + + while (elapsed <= timeout) { { const ScopedLock sl (bufferStartPosLock); @@ -182,10 +185,14 @@ bool BufferingAudioSource::waitForNextAudioBlockReady (const AudioSourceChannelI return true; } - if (endTime > now && (! bufferReadyEvent.wait (static_cast (endTime - now)))) + + + if (elapsed < timeout && (! bufferReadyEvent.wait (static_cast (timeout - elapsed)))) return false; now = Time::getMillisecondCounter(); + elapsed = (now >= startTime ? now - startTime + : (std::numeric_limits::max() - startTime) + now); } return false;