From ce5b79bb450d60a9b36e495c37e0a5035b0eda08 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Wed, 21 Oct 2020 16:50:19 +0100 Subject: [PATCH] Avoid passing a very oversize outcount for the reasons given --- src/dsp/Resampler.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/dsp/Resampler.cpp b/src/dsp/Resampler.cpp index 280e817..0b58bc4 100644 --- a/src/dsp/Resampler.cpp +++ b/src/dsp/Resampler.cpp @@ -699,9 +699,23 @@ D_SRC::resampleInterleaved(float *const R__ out, data.input_frames = incount; data.output_frames = outcount; + + // libsamplerate smooths the filter change over the duration of + // the processing block to avoid artifacts due to sudden changes, + // and it uses outcount to determine how long to smooth the change + // over. This is a good thing in principle, but it does mean (a) + // we should never pass outcount significantly longer than the + // actual expected output, and (b) when the ratio has just + // changed, we should aim to supply a shortish block next (this + // part still todo!) + + if (data.output_frames > int(ceil(incount * ratio) + 10)) { + data.output_frames = int(ceil(incount * ratio) + 10); + } + data.src_ratio = ratio; data.end_of_input = (final ? 1 : 0); - + int err = src_process(m_src, &data); if (err) { @@ -711,7 +725,7 @@ D_SRC::resampleInterleaved(float *const R__ out, throw Resampler::ImplementationError; #endif } - + return (int)data.output_frames_gen; }