From 9317df59709ae646f6e08a1e2c9834b4a0325101 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 13 Sep 2023 18:34:27 +0200 Subject: [PATCH] Fix audio file buffering with files that align perfectly in buffer Signed-off-by: falkTX --- source/native-plugins/audio-base.hpp | 15 ++++++++------- source/utils/CarlaRingBuffer.hpp | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/source/native-plugins/audio-base.hpp b/source/native-plugins/audio-base.hpp index 8446d9a79..41daded36 100644 --- a/source/native-plugins/audio-base.hpp +++ b/source/native-plugins/audio-base.hpp @@ -362,10 +362,11 @@ public: } // 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 @@ public: 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 @@ public: 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 f4a572e8b..906005b29 100644 --- a/source/utils/CarlaRingBuffer.hpp +++ b/source/utils/CarlaRingBuffer.hpp @@ -172,7 +172,7 @@ public: 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 @@ protected: 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) { -- 2.11.4.GIT