7b0b3482b896 — Chris Cannam 11 months ago
Don't do this after we begin; correct ratio
1 files changed, 17 insertions(+), 2 deletions(-)

M src/finer/R3LiveShifter.cpp
M src/finer/R3LiveShifter.cpp +17 -2
@@ 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<float> 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();