diff --git a/source/native-plugins/audio-base.hpp b/source/native-plugins/audio-base.hpp index 8446d9a79f..41daded36c 100644 --- a/source/native-plugins/audio-base.hpp +++ b/source/native-plugins/audio-base.hpp @@ -362,10 +362,11 @@ class AudioFileReader } // within bounds, skip frames until we reach the end of the memory pool - if (fRingBufferR.getReadableDataSize() >= numPoolFrames * sizeof(float)) + const uint32_t framesUpToPoolEnd = numPoolFrames - fRingBufferFramePos; + if (fRingBufferR.getReadableDataSize() / sizeof(float) >= framesUpToPoolEnd) { - fRingBufferL.skipRead(numPoolFrames * sizeof(float)); - fRingBufferR.skipRead(numPoolFrames * sizeof(float)); + fRingBufferL.skipRead(framesUpToPoolEnd * sizeof(float)); + fRingBufferR.skipRead(framesUpToPoolEnd * sizeof(float)); fRingBufferFramePos = numPoolFrames; } @@ -383,9 +384,9 @@ class AudioFileReader carla_zeroFloats(outR, frames); carla_zeroFloats(playCV, frames); - // wait until there previous relocation is done + // wait until the previous relocation is done if (fNextFileReadPos == -1) - fNextFileReadPos = framePos; + fNextFileReadPos = framePos - frames; return true; } @@ -408,8 +409,8 @@ class AudioFileReader return framePos < fTotalResampledFrames; } - fRingBufferL.readCustomData(outL, sizeof(float) * usableFrames); - fRingBufferR.readCustomData(outR, sizeof(float) * usableFrames); + fRingBufferL.readCustomData(outL, usableFrames * sizeof(float)); + fRingBufferR.readCustomData(outR, usableFrames * sizeof(float)); carla_fillFloatsWithSingleValue(playCV, 10.f, usableFrames); fRingBufferFramePos += usableFrames; diff --git a/source/utils/CarlaRingBuffer.hpp b/source/utils/CarlaRingBuffer.hpp index f4a572e8bd..906005b291 100644 --- a/source/utils/CarlaRingBuffer.hpp +++ b/source/utils/CarlaRingBuffer.hpp @@ -172,7 +172,7 @@ class CarlaRingBufferControl const uint32_t wrap = fBuffer->tail > fBuffer->wrtn ? 0 : fBuffer->size; - return wrap + fBuffer->tail - fBuffer->wrtn; + return wrap + fBuffer->tail - fBuffer->wrtn - 1; } // ---------------------------------------------------------------------------------------------------------------- @@ -448,7 +448,7 @@ class CarlaRingBufferControl const uint32_t wrtn = fBuffer->wrtn; const uint32_t wrap = tail > wrtn ? 0 : fBuffer->size; - if (size > wrap + tail - wrtn) + if (size >= wrap + tail - wrtn) { if (! fErrorWriting) {