Browse Source

Added a fix for a potential wrap-around bug in BufferingAudioSource

tags/2021-05-28
hogliux 9 years ago
parent
commit
8154ccc4e5
1 changed files with 10 additions and 3 deletions
  1. +10
    -3
      modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp

+ 10
- 3
modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp View File

@@ -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<uint32>::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<int> (endTime - now))))
if (elapsed < timeout && (! bufferReadyEvent.wait (static_cast<int> (timeout - elapsed))))
return false;
now = Time::getMillisecondCounter();
elapsed = (now >= startTime ? now - startTime
: (std::numeric_limits<uint32>::max() - startTime) + now);
}
return false;


Loading…
Cancel
Save