From 4336d47a02664876b7a0d533d67cff4e20f8722a Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Thu, 1 Sep 2022 10:41:25 +0100 Subject: [PATCH] With longer process sizes we can end up with insufficient space in the inbuf, but enough in the outbuf following the previous retrieve call for a consume to be possible before writing to the inbuf --- main/main.cpp | 1 + src/finer/R3Stretcher.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/main/main.cpp b/main/main.cpp index fcb5920..2bf748d 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -673,6 +673,7 @@ int main(int argc, char **argv) RubberBandStretcher ts(sfinfo.samplerate, channels, options, ratio, frequencyshift); ts.setExpectedInputDuration(sfinfo.frames); + ts.setMaxProcessSize(bs); int frame = 0; int percent = 0; diff --git a/src/finer/R3Stretcher.cpp b/src/finer/R3Stretcher.cpp index dc85c8d..fd719c1 100644 --- a/src/finer/R3Stretcher.cpp +++ b/src/finer/R3Stretcher.cpp @@ -647,6 +647,11 @@ R3Stretcher::process(const float *const *input, size_t samples, bool final) } size_t ws = m_channelData[0]->inbuf->getWriteSpace(); + if (samples > ws) { + m_log.log(2, "R3Stretcher::process: insufficient space in input buffer, attempting consume before write"); + consume(); + ws = m_channelData[0]->inbuf->getWriteSpace(); + } if (samples > ws) { m_log.log(0, "R3Stretcher::process: WARNING: Forced to increase input buffer size. Either setMaxProcessSize was not properly called or process is being called repeatedly without retrieve. Write space and samples", ws, samples); size_t newSize = m_channelData[0]->inbuf->getSize() - ws + samples;