Avoid recalculating window scale factor every time

This commit is contained in:
Chris Cannam
2022-06-09 16:39:30 +01:00
parent bc764c62ea
commit 2298b67869
2 changed files with 13 additions and 15 deletions

View File

@@ -532,8 +532,6 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
// where the inhop has changed as above, in which case we need to
// do both readahead and current)
v_fftshift(readahead.timeDomain.data(), classify);
if (haveValidReadahead) {
v_copy(classifyScale->mag.data(),
readahead.mag.data(),
@@ -543,6 +541,7 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
classifyScale->bufSize);
}
v_fftshift(readahead.timeDomain.data(), classify);
m_scaleData.at(classify)->fft.forward(readahead.timeDomain.data(),
classifyScale->real.data(),
classifyScale->imag.data());
@@ -776,18 +775,7 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop)
auto &scale = cd->scales.at(fftSize);
auto &scaleData = m_scaleData.at(fftSize);
//!!! messy and slow, but leave it until we've
//!!! discovered whether we need a window accumulator
//!!! (we probably do)
int analysisWindowSize = scaleData->analysisWindow.getSize();
int synthesisWindowSize = scaleData->synthesisWindow.getSize();
int offset = (analysisWindowSize - synthesisWindowSize) / 2;
double winscale = 0.0;
for (int i = 0; i < synthesisWindowSize; ++i) {
winscale += scaleData->analysisWindow.getValue(i + offset) *
scaleData->synthesisWindow.getValue(i);
}
winscale = double(outhop) / winscale;
double winscale = double(outhop) / scaleData->windowScaleFactor;
// The frequency filter is applied naively in the frequency
// domain. Aliasing is reduced by the shorter resynthesis

View File

@@ -233,6 +233,7 @@ protected:
FFT fft;
Window<double> analysisWindow;
Window<double> synthesisWindow;
double windowScaleFactor;
GuidedPhaseAdvance guided;
ScaleData(GuidedPhaseAdvance::Parameters guidedParameters) :
fftSize(guidedParameters.fftSize),
@@ -241,7 +242,16 @@ protected:
analysisWindowLength(fftSize)),
synthesisWindow(synthesisWindowShape(fftSize),
synthesisWindowLength(fftSize)),
guided(guidedParameters) { }
guided(guidedParameters),
windowScaleFactor(0.0)
{
int asz = analysisWindow.getSize(), ssz = synthesisWindow.getSize();
int off = (asz - ssz) / 2;
for (int i = 0; i < ssz; ++i) {
windowScaleFactor += analysisWindow.getValue(i + off) *
synthesisWindow.getValue(i);
}
}
WindowType analysisWindowShape(int fftSize);
int analysisWindowLength(int fftSize);