From b4e921003f02c66088120fca699c3c1ca82934aa Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Fri, 17 Jun 2022 16:52:55 +0100 Subject: [PATCH] Perform polar-to-cartesian conversions only on range that will actually be used --- src/finer/R3StretcherImpl.cpp | 51 +++++++++++++---------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/finer/R3StretcherImpl.cpp b/src/finer/R3StretcherImpl.cpp index cf0d4b3..3a830cf 100644 --- a/src/finer/R3StretcherImpl.cpp +++ b/src/finer/R3StretcherImpl.cpp @@ -976,45 +976,30 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop) // The frequency filter is applied naively in the frequency // domain. Aliasing is reduced by the shorter resynthesis - // window - + // window. We resynthesise each scale individually, then sum - + // it's easier to manage scaling for in situations with a + // varying resynthesis hop + int lowBin = binForFrequency(band.f0, fftSize, m_parameters.sampleRate); int highBin = binForFrequency(band.f1, fftSize, m_parameters.sampleRate); if (highBin % 2 == 0 && highBin > 0) --highBin; - for (int i = 0; i < lowBin; ++i) { - scale->mag[i] = 0.0; + if (lowBin > 0) { + v_zero(scale->real.data(), lowBin); + v_zero(scale->imag.data(), lowBin); } - for (int i = lowBin; i < highBin; ++i) { - scale->mag[i] *= winscale; - } - for (int i = highBin; i < fftSize/2 + 1; ++i) { - scale->mag[i] = 0.0; - } - } - // Resynthesise each FFT size (scale) individually, then sum. This - // is easier to manage scaling for in situations with a varying - // resynthesis hop - - for (auto &it : cd->scales) { - int fftSize = it.first; - auto &scale = it.second; - auto &scaleData = m_scaleData.at(fftSize); - - for (const auto &b : m_guideConfiguration.fftBandLimits) { - if (b.fftSize == fftSize) { - int offset = b.b0min; - v_zero(scale->real.data(), fftSize/2 + 1); - v_zero(scale->imag.data(), fftSize/2 + 1); - v_polar_to_cartesian - (scale->real.data() + offset, - scale->imag.data() + offset, - scale->mag.data() + offset, - scale->advancedPhase.data() + offset, - b.b1max - offset); - break; - } + v_scale(scale->mag.data() + lowBin, winscale, highBin - lowBin); + + v_polar_to_cartesian(scale->real.data() + lowBin, + scale->imag.data() + lowBin, + scale->mag.data() + lowBin, + scale->advancedPhase.data() + lowBin, + highBin - lowBin); + + if (highBin < fftSize/2 + 1) { + v_zero(scale->real.data() + highBin, fftSize/2 + 1 - highBin); + v_zero(scale->imag.data() + highBin, fftSize/2 + 1 - highBin); } scaleData->fft.inverse(scale->real.data(),