From 2119c432878d42d3f0af315d0a7fcd2c5ca5bf5c Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Fri, 10 May 2024 13:09:58 +0100 Subject: [PATCH] Don't do this after we begin; correct ratio --- src/finer/R3LiveShifter.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/finer/R3LiveShifter.cpp b/src/finer/R3LiveShifter.cpp index 5affff9..6cd1692 100644 --- a/src/finer/R3LiveShifter.cpp +++ b/src/finer/R3LiveShifter.cpp @@ -182,9 +182,13 @@ void R3LiveShifter::setPitchScale(double scale) { m_log.log(2, "R3LiveShifter::setPitchScale", scale); + if (scale == m_pitchScale) return; m_pitchScale = scale; - measureResamplerDelay(); + + if (m_firstProcess) { + measureResamplerDelay(); + } } void @@ -241,9 +245,20 @@ R3LiveShifter::measureResamplerDelay() int bs = getBlockSize(); std::vector inbuf(bs * m_parameters.channels, 0.f); auto outbuf = inbuf; + + double inRatio = 1.0; + if (m_expandThenContract) { + if (m_pitchScale < 1.0) { + inRatio = 1.0 / m_pitchScale; + } + } else { + if (m_pitchScale > 1.0) { + inRatio = 1.0 / m_pitchScale; + } + } int outcount = m_inResampler->resampleInterleaved - (outbuf.data(), bs, inbuf.data(), bs, m_pitchScale, false); + (outbuf.data(), bs, inbuf.data(), bs, inRatio, false); m_inResampler->reset();