From 53eca719fb47c99f8eaaa6dacbf0ac74351589d6 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Thu, 18 Aug 2022 16:41:43 +0100 Subject: [PATCH] Apply gradual phase-reset on unity in the R2 stretcher (R3 already does this) --- src/faster/StretcherChannelData.cpp | 2 ++ src/faster/StretcherChannelData.h | 1 + src/faster/StretcherProcess.cpp | 21 +++++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/faster/StretcherChannelData.cpp b/src/faster/StretcherChannelData.cpp index 376b76c..483c572 100644 --- a/src/faster/StretcherChannelData.cpp +++ b/src/faster/StretcherChannelData.cpp @@ -87,6 +87,8 @@ R2Stretcher::ChannelData::construct(const std::set &sizes, interpolator = allocate_and_zero(maxSize); interpolatorScale = 0; + unityResetLow = 16000.f; + for (std::set::const_iterator i = sizes.begin(); i != sizes.end(); ++i) { ffts[*i] = new FFT(*i); diff --git a/src/faster/StretcherChannelData.h b/src/faster/StretcherChannelData.h index 1b2d673..b0ce210 100644 --- a/src/faster/StretcherChannelData.h +++ b/src/faster/StretcherChannelData.h @@ -113,6 +113,7 @@ public: float *ms; // only used when mid-side processing float *interpolator; // only used when time-domain smoothing is on int interpolatorScale; + float unityResetLow; // for gradual phase-reset on unity ratio float *fltbuf; process_t *dblbuf; // owned by FFT object, only used for time domain FFT i/o diff --git a/src/faster/StretcherProcess.cpp b/src/faster/StretcherProcess.cpp index 5074a93..4757d5e 100644 --- a/src/faster/StretcherProcess.cpp +++ b/src/faster/StretcherProcess.cpp @@ -744,12 +744,29 @@ R2Stretcher::modifyChunk(size_t channel, int bandlow = lrint((150 * m_fftSize) / rate); int bandhigh = lrint((1000 * m_fftSize) / rate); + float r = getEffectiveRatio(); + + bool unity = (fabsf(r - 1.f) < 1.e-6f); + if (unity) { + if (!phaseReset) { + phaseReset = true; + bandlimited = true; + bandlow = lrint((cd.unityResetLow * m_fftSize) / rate); + bandhigh = count; + if (bandlow > 0) { + m_log.log(2, "unity: bandlow & high", bandlow, bandhigh); + } + } + cd.unityResetLow *= 0.9f; + } else { + cd.unityResetLow = 16000.f; + } + float freq0 = m_freq0; float freq1 = m_freq1; float freq2 = m_freq2; - + if (laminar) { - float r = getEffectiveRatio(); if (r > 1) { float rf0 = 600 + (600 * ((r-1)*(r-1)*(r-1)*2)); float f1ratio = freq1 / freq0;