From 897bd14b8e14246481ef53ffbb1d2c9e633c9494 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Mon, 16 Nov 2020 09:11:12 +0000 Subject: [PATCH] Avoid any smoothing when setting initial ratio --- src/dsp/Resampler.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dsp/Resampler.cpp b/src/dsp/Resampler.cpp index c6ad53c..ff38423 100644 --- a/src/dsp/Resampler.cpp +++ b/src/dsp/Resampler.cpp @@ -578,6 +578,7 @@ protected: int m_iinsize; int m_ioutsize; double m_prevRatio; + bool m_ratioUnset; int m_debugLevel; }; @@ -590,6 +591,7 @@ D_SRC::D_SRC(Resampler::Quality quality, int channels, double, m_iinsize(0), m_ioutsize(0), m_prevRatio(1.0), + m_ratioUnset(true), m_debugLevel(debugLevel) { if (m_debugLevel > 0) { @@ -680,7 +682,14 @@ D_SRC::resampleInterleaved(float *const R__ out, outcount = int(ceil(incount * ratio) + 5); } - if (ratio != m_prevRatio) { + if (m_ratioUnset) { + + // The first time we set a ratio, we want to do it directly + src_set_ratio(m_src, ratio); + m_ratioUnset = false; + m_prevRatio = ratio; + + } else if (ratio != m_prevRatio) { // If we are processing a block of appreciable length, turn it // into two recursive calls, one for the short smoothing block @@ -736,6 +745,7 @@ void D_SRC::reset() { src_reset(m_src); + m_ratioUnset = true; } #endif /* HAVE_LIBSAMPLERATE */