Make this fully single-windowed rather than just short-windowed

This commit is contained in:
Chris Cannam
2022-07-14 13:44:22 +01:00
parent 279c44477e
commit e018458736
5 changed files with 55 additions and 46 deletions

View File

@@ -418,7 +418,11 @@ int main(int argc, char **argv)
if (!quiet) { if (!quiet) {
if (finer) { if (finer) {
cerr << "Using R3 (finer) engine" << endl; if (shortwin) {
cerr << "Using intermediate R3 (finer) single-windowed engine" << endl;
} else {
cerr << "Using R3 (finer) engine" << endl;
}
} else { } else {
cerr << "Using R2 (faster) engine" << endl; cerr << "Using R2 (faster) engine" << endl;
cerr << "Using crispness level: " << crispness << " ("; cerr << "Using crispness level: " << crispness << " (";

View File

@@ -105,10 +105,10 @@ public:
struct Parameters { struct Parameters {
double sampleRate; double sampleRate;
bool shortWindowMode; bool singleWindowMode;
Parameters(double _sampleRate, bool _shortWindow) : Parameters(double _sampleRate, bool _singleWindow) :
sampleRate(_sampleRate), sampleRate(_sampleRate),
shortWindowMode(_shortWindow) { } singleWindowMode(_singleWindow) { }
}; };
Guide(Parameters parameters, Log log) : Guide(Parameters parameters, Log log) :
@@ -123,13 +123,16 @@ public:
{ {
double rate = m_parameters.sampleRate; double rate = m_parameters.sampleRate;
m_log.log(1, "Guide: rate and short-window mode", m_log.log(1, "Guide: rate and single-window mode",
rate, m_parameters.shortWindowMode); rate, m_parameters.singleWindowMode);
if (m_parameters.shortWindowMode) { if (m_parameters.singleWindowMode) {
m_minLower = 0.0;
m_defaultLower = 0.0; m_defaultLower = 0.0;
m_maxLower = 0.0; m_defaultHigher = parameters.sampleRate / 2.0;
m_minLower = m_defaultLower;
m_maxLower = m_defaultLower;
m_minHigher = m_defaultHigher;
m_maxHigher = m_defaultHigher;
} }
int bandFftSize = roundUp(int(ceil(rate/16.0))); int bandFftSize = roundUp(int(ceil(rate/16.0)));
@@ -312,9 +315,10 @@ public:
guidance.phaseLockBands[3].f0 = higher; guidance.phaseLockBands[3].f0 = higher;
guidance.phaseLockBands[3].f1 = nyquist; guidance.phaseLockBands[3].f1 = nyquist;
if (m_parameters.shortWindowMode) { if (m_parameters.singleWindowMode) {
guidance.phaseLockBands[1].p = 1; guidance.phaseLockBands[1].p = 1;
guidance.phaseLockBands[2].p = 2; guidance.phaseLockBands[2].p = 2;
guidance.phaseLockBands[3].p = 5;
} }
if (outhop > 256) { if (outhop > 256) {
@@ -436,7 +440,7 @@ protected:
guidance.fftBands[2].f0 = m_minHigher; guidance.fftBands[2].f0 = m_minHigher;
guidance.fftBands[2].f1 = nyquist; guidance.fftBands[2].f1 = nyquist;
if (m_parameters.shortWindowMode) { if (m_parameters.singleWindowMode) {
guidance.fftBands[0].f1 = 0.0; guidance.fftBands[0].f1 = 0.0;
guidance.fftBands[1].f0 = 0.0; guidance.fftBands[1].f0 = 0.0;
guidance.fftBands[1].f1 = nyquist; guidance.fftBands[1].f1 = nyquist;

View File

@@ -43,11 +43,11 @@ public:
int fftSize; int fftSize;
double sampleRate; double sampleRate;
int channels; int channels;
bool shortWindowMode; bool singleWindowMode;
Parameters(int _fftSize, double _sampleRate, int _channels, Parameters(int _fftSize, double _sampleRate, int _channels,
bool _shortWindow) : bool _singleWindow) :
fftSize(_fftSize), sampleRate(_sampleRate), channels(_channels), fftSize(_fftSize), sampleRate(_sampleRate), channels(_channels),
shortWindowMode(_shortWindow) { } singleWindowMode(_singleWindow) { }
}; };
GuidedPhaseAdvance(Parameters parameters, Log log) : GuidedPhaseAdvance(Parameters parameters, Log log) :

View File

@@ -71,7 +71,7 @@ R3Stretcher::R3Stretcher(Parameters parameters,
m_log.log(1, "R3Stretcher::R3Stretcher: offline mode"); m_log.log(1, "R3Stretcher::R3Stretcher: offline mode");
} }
if (isShortWindowed()) { if (isSingleWindowed()) {
m_log.log(1, "R3Stretcher::R3Stretcher: intermediate shorter-window mode requested"); m_log.log(1, "R3Stretcher::R3Stretcher: intermediate shorter-window mode requested");
} }
@@ -112,7 +112,7 @@ R3Stretcher::R3Stretcher(Parameters parameters,
int fftSize = band.fftSize; int fftSize = band.fftSize;
GuidedPhaseAdvance::Parameters guidedParameters GuidedPhaseAdvance::Parameters guidedParameters
(fftSize, m_parameters.sampleRate, m_parameters.channels, (fftSize, m_parameters.sampleRate, m_parameters.channels,
isShortWindowed()); isSingleWindowed());
m_scaleData[fftSize] = std::make_shared<ScaleData> m_scaleData[fftSize] = std::make_shared<ScaleData>
(guidedParameters, m_log); (guidedParameters, m_log);
} }
@@ -146,9 +146,8 @@ R3Stretcher::R3Stretcher(Parameters parameters,
WindowType WindowType
R3Stretcher::ScaleData::analysisWindowShape() R3Stretcher::ScaleData::analysisWindowShape()
{ {
if (shortWindowMode) { if (singleWindowMode) {
if (fftSize >= 2048) return HannWindow; return HannWindow;
else return NiemitaloForwardWindow;
} else { } else {
if (fftSize > 2048) return HannWindow; if (fftSize > 2048) return HannWindow;
else return NiemitaloForwardWindow; else return NiemitaloForwardWindow;
@@ -164,9 +163,8 @@ R3Stretcher::ScaleData::analysisWindowLength()
WindowType WindowType
R3Stretcher::ScaleData::synthesisWindowShape() R3Stretcher::ScaleData::synthesisWindowShape()
{ {
if (shortWindowMode) { if (singleWindowMode) {
if (fftSize >= 2048) return HannWindow; return HannWindow;
else return NiemitaloReverseWindow;
} else { } else {
if (fftSize > 2048) return HannWindow; if (fftSize > 2048) return HannWindow;
else return NiemitaloReverseWindow; else return NiemitaloReverseWindow;
@@ -176,7 +174,7 @@ R3Stretcher::ScaleData::synthesisWindowShape()
int int
R3Stretcher::ScaleData::synthesisWindowLength() R3Stretcher::ScaleData::synthesisWindowLength()
{ {
if (shortWindowMode) { if (singleWindowMode) {
return fftSize; return fftSize;
} else { } else {
if (fftSize > 2048) return fftSize/2; if (fftSize > 2048) return fftSize/2;
@@ -320,12 +318,12 @@ R3Stretcher::calculateHop()
if (proposedOuthop > 512.0) proposedOuthop = 512.0; if (proposedOuthop > 512.0) proposedOuthop = 512.0;
if (proposedOuthop < 128.0) proposedOuthop = 128.0; if (proposedOuthop < 128.0) proposedOuthop = 128.0;
if (isShortWindowed()) { if (isSingleWindowed()) {
// perhaps ironically, the short window mode actually uses a // the single (shorter) window mode actually uses a longer
// longer synthesis window for the 2048-bin FFT and, since // synthesis window for the 2048-bin FFT and drops the
// reduced CPU consumption is the motivation, it can generally // 1024-bin one, so it can survive longer hops, which is good
// survive longer hops // because reduced CPU consumption is the whole motivation
proposedOuthop *= 1.5; proposedOuthop *= 2.0;
} }
m_log.log(1, "calculateHop: ratio and proposed outhop", ratio, proposedOuthop); m_log.log(1, "calculateHop: ratio and proposed outhop", ratio, proposedOuthop);
@@ -764,8 +762,8 @@ R3Stretcher::consume()
for (auto &it : m_channelData[0]->scales) { for (auto &it : m_channelData[0]->scales) {
int fftSize = it.first; int fftSize = it.first;
if (isShortWindowed() && if (isSingleWindowed() &&
fftSize == m_guideConfiguration.longestFftSize) { fftSize != m_guideConfiguration.classificationFftSize) {
continue; continue;
} }
for (int c = 0; c < channels; ++c) { for (int c = 0; c < channels; ++c) {
@@ -905,12 +903,14 @@ R3Stretcher::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
// the longest. (In practice this means we are probably only // the longest. (In practice this means we are probably only
// populating one scale) // populating one scale)
for (auto &it: cd->scales) { if (!isSingleWindowed()) {
int fftSize = it.first; for (auto &it: cd->scales) {
if (fftSize == classify || fftSize == longest) continue; int fftSize = it.first;
int offset = (longest - fftSize) / 2; if (fftSize == classify || fftSize == longest) continue;
m_scaleData.at(fftSize)->analysisWindow.cut int offset = (longest - fftSize) / 2;
(buf + offset, it.second->timeDomain.data()); m_scaleData.at(fftSize)->analysisWindow.cut
(buf + offset, it.second->timeDomain.data());
}
} }
// The classification scale has a one-hop readahead, so populate // The classification scale has a one-hop readahead, so populate
@@ -938,7 +938,7 @@ R3Stretcher::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
} }
// Finally window the longest scale // Finally window the longest scale
if (!isShortWindowed()) { if (!isSingleWindowed()) {
m_scaleData.at(longest)->analysisWindow.cut(buf); m_scaleData.at(longest)->analysisWindow.cut(buf);
} }
@@ -998,7 +998,7 @@ R3Stretcher::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
if (fftSize == classify && haveValidReadahead) { if (fftSize == classify && haveValidReadahead) {
continue; continue;
} }
if (isShortWindowed() && fftSize == longest) { if (isSingleWindowed() && fftSize != classify) {
continue; continue;
} }
@@ -1172,8 +1172,8 @@ R3Stretcher::adjustFormant(int c)
for (auto &it : cd->scales) { for (auto &it : cd->scales) {
int fftSize = it.first; int fftSize = it.first;
if (isShortWindowed() && if (isSingleWindowed() &&
fftSize == m_guideConfiguration.longestFftSize) { fftSize != m_guideConfiguration.classificationFftSize) {
continue; continue;
} }
@@ -1206,7 +1206,7 @@ R3Stretcher::adjustFormant(int c)
void void
R3Stretcher::adjustPreKick(int c) R3Stretcher::adjustPreKick(int c)
{ {
if (isShortWindowed()) return; if (isSingleWindowed()) return;
Profiler profiler("R3Stretcher::adjustPreKick"); Profiler profiler("R3Stretcher::adjustPreKick");
@@ -1250,7 +1250,8 @@ R3Stretcher::synthesiseChannel(int c, int outhop, bool draining)
for (const auto &band : cd->guidance.fftBands) { for (const auto &band : cd->guidance.fftBands) {
int fftSize = band.fftSize; int fftSize = band.fftSize;
if (isShortWindowed() && fftSize == longest) { if (isSingleWindowed() &&
fftSize != m_guideConfiguration.classificationFftSize) {
continue; continue;
} }

View File

@@ -253,7 +253,7 @@ protected:
struct ScaleData { struct ScaleData {
int fftSize; int fftSize;
bool shortWindowMode; bool singleWindowMode;
FFT fft; FFT fft;
Window<process_t> analysisWindow; Window<process_t> analysisWindow;
Window<process_t> synthesisWindow; Window<process_t> synthesisWindow;
@@ -263,7 +263,7 @@ protected:
ScaleData(GuidedPhaseAdvance::Parameters guidedParameters, ScaleData(GuidedPhaseAdvance::Parameters guidedParameters,
Log log) : Log log) :
fftSize(guidedParameters.fftSize), fftSize(guidedParameters.fftSize),
shortWindowMode(guidedParameters.shortWindowMode), singleWindowMode(guidedParameters.singleWindowMode),
fft(fftSize), fft(fftSize),
analysisWindow(analysisWindowShape(), analysisWindow(analysisWindowShape(),
analysisWindowLength()), analysisWindowLength()),
@@ -371,7 +371,7 @@ protected:
RubberBandStretcher::OptionProcessRealTime; RubberBandStretcher::OptionProcessRealTime;
} }
bool isShortWindowed() const { bool isSingleWindowed() const {
return m_parameters.options & return m_parameters.options &
RubberBandStretcher::OptionWindowShort; RubberBandStretcher::OptionWindowShort;
} }