From ab284f0047f7aa57629c89435de9549daed32a69 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Thu, 9 Jun 2022 14:29:51 +0100 Subject: [PATCH] Rather than using trough picker, make the division frequencies drift downhill --- src/finer/Guide.h | 57 ++++++++++++++++++++++++----------- src/finer/R3StretcherImpl.cpp | 22 +++++--------- src/finer/R3StretcherImpl.h | 3 -- 3 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/finer/Guide.h b/src/finer/Guide.h index 5524404..e3239a9 100644 --- a/src/finer/Guide.h +++ b/src/finer/Guide.h @@ -137,15 +137,14 @@ public: return m_configuration; } - void calculate(double ratio, - const double *const magnitudes, - const int *const troughs, - const double *const prevMagnitudes, - const BinSegmenter::Segmentation &segmentation, - const BinSegmenter::Segmentation &prevSegmentation, - const BinSegmenter::Segmentation &nextSegmentation, - bool specialCaseUnity, - Guidance &guidance) const { + void updateGuidance(double ratio, + const double *const magnitudes, + const double *const prevMagnitudes, + const BinSegmenter::Segmentation &segmentation, + const BinSegmenter::Segmentation &prevSegmentation, + const BinSegmenter::Segmentation &nextSegmentation, + bool specialCaseUnity, + Guidance &guidance) const { guidance.kick.present = false; guidance.lowPercussive.present = false; @@ -221,8 +220,20 @@ public: double lower = snapToTrough(m_defaultLower, troughs); if (lower > m_maxLower) lower = m_maxLower; */ -/* + double prevLower = guidance.fftBands[0].f1; + double lower = descendToValley(prevLower, magnitudes); + if (lower > m_maxLower || lower < m_minLower) { + lower = m_defaultLower; + } + double prevHigher = guidance.fftBands[1].f1; + double higher = descendToValley(prevHigher, magnitudes); + if (higher > m_maxHigher || higher < m_minHigher) { + higher = m_defaultHigher; + } + + +/* double higher = snapToTrough(prevHigher, troughs, magnitudes); if (higher < m_minHigher || higher > m_maxHigher) { higher = snapToTrough(m_defaultHigher, troughs, magnitudes); @@ -231,17 +242,16 @@ public: } } */ + /* double higher = m_defaultHigher; - double prevLower = guidance.fftBands[0].f1; - double lower = snapToTrough(prevLower, troughs, magnitudes); if (lower < m_minLower || lower > m_maxLower) { lower = snapToTrough(m_defaultLower, troughs, magnitudes); if (lower < m_minLower || lower > m_maxLower) { lower = prevLower; } } - + */ guidance.fftBands[0].f0 = 0.0; guidance.fftBands[0].f1 = lower; @@ -343,13 +353,22 @@ protected: return (here > 10.e-3 && here > there * 1.4); } - double snapToTrough(double f, - const int *const troughs, - const double *const magnitudes) const { + double descendToValley(double f, const double *const magnitudes) const { // return frequencyForBin(troughs[binForFrequency(f)]); - int bin = binForFrequency(f); + int b = binForFrequency(f); + + for (int i = 0; i < 3; ++i) { + if (magnitudes[b+1] < magnitudes[b]) { + ++b; + } else if (magnitudes[b-1] < magnitudes[b]) { + --b; + } else { + break; + } + } + +/* int snapped = troughs[bin]; - double sf = frequencyForBin(snapped); std::cout << "snapToTrough: " << f << " -> bin " << bin << " -> snapped " << snapped << " -> " << sf << std::endl; for (int i = -3; i <= 3; ++i) { if (i == 0) std::cout << "["; @@ -358,6 +377,8 @@ protected: std::cout << " "; } std::cout << std::endl; +*/ + double sf = frequencyForBin(b); return sf; } diff --git a/src/finer/R3StretcherImpl.cpp b/src/finer/R3StretcherImpl.cpp index 2742425..f10483c 100644 --- a/src/finer/R3StretcherImpl.cpp +++ b/src/finer/R3StretcherImpl.cpp @@ -38,7 +38,6 @@ R3StretcherImpl::R3StretcherImpl(Parameters parameters, m_guide(Guide::Parameters(m_parameters.sampleRate, parameters.logger)), m_guideConfiguration(m_guide.getConfiguration()), m_channelAssembly(m_parameters.channels), - m_troughPicker(m_guideConfiguration.classificationFftSize / 2 + 1), m_inhop(1), m_prevOuthop(1), m_draining(false) @@ -677,22 +676,17 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop) } */ - m_troughPicker.findNearestAndNextPeaks - (classifyScale->mag.data(), 3, nullptr, - classifyScale->troughs.data()); - double instantaneousRatio = double(prevOuthop) / double(prevInhop); bool specialCaseUnity = true; - m_guide.calculate(instantaneousRatio, - classifyScale->mag.data(), - classifyScale->troughs.data(), - classifyScale->prevMag.data(), - cd->segmentation, - cd->prevSegmentation, - cd->nextSegmentation, - specialCaseUnity, - cd->guidance); + m_guide.updateGuidance(instantaneousRatio, + classifyScale->mag.data(), + classifyScale->prevMag.data(), + cd->segmentation, + cd->prevSegmentation, + cd->nextSegmentation, + specialCaseUnity, + cd->guidance); } void diff --git a/src/finer/R3StretcherImpl.h b/src/finer/R3StretcherImpl.h index fdcec77..ab6db5f 100644 --- a/src/finer/R3StretcherImpl.h +++ b/src/finer/R3StretcherImpl.h @@ -109,7 +109,6 @@ protected: FixedVector mag; FixedVector phase; FixedVector advancedPhase; - FixedVector troughs; FixedVector prevMag; FixedVector accumulator; @@ -122,7 +121,6 @@ protected: mag(bufSize, 0.f), phase(bufSize, 0.f), advancedPhase(bufSize, 0.f), - troughs(bufSize, 0), prevMag(bufSize, 0.f), accumulator(_longestFftSize, 0.f) { } @@ -261,7 +259,6 @@ protected: Guide m_guide; Guide::Configuration m_guideConfiguration; ChannelAssembly m_channelAssembly; - Peak> m_troughPicker; std::unique_ptr m_calculator; std::unique_ptr m_resampler; std::atomic m_inhop;