Skip to content

Commit

Permalink
Fix audio file buffering with files that align perfectly in buffer
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Sep 13, 2023
1 parent dd092c7 commit 9317df5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions source/native-plugins/audio-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/utils/CarlaRingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

// ----------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 9317df5

Please sign in to comment.