Rather than using trough picker, make the division frequencies drift downhill

This commit is contained in:
Chris Cannam
2022-06-09 14:29:51 +01:00
parent 70a7b6d688
commit ab284f0047
3 changed files with 47 additions and 35 deletions

View File

@@ -137,15 +137,14 @@ public:
return m_configuration; return m_configuration;
} }
void calculate(double ratio, void updateGuidance(double ratio,
const double *const magnitudes, const double *const magnitudes,
const int *const troughs, const double *const prevMagnitudes,
const double *const prevMagnitudes, const BinSegmenter::Segmentation &segmentation,
const BinSegmenter::Segmentation &segmentation, const BinSegmenter::Segmentation &prevSegmentation,
const BinSegmenter::Segmentation &prevSegmentation, const BinSegmenter::Segmentation &nextSegmentation,
const BinSegmenter::Segmentation &nextSegmentation, bool specialCaseUnity,
bool specialCaseUnity, Guidance &guidance) const {
Guidance &guidance) const {
guidance.kick.present = false; guidance.kick.present = false;
guidance.lowPercussive.present = false; guidance.lowPercussive.present = false;
@@ -221,8 +220,20 @@ public:
double lower = snapToTrough(m_defaultLower, troughs); double lower = snapToTrough(m_defaultLower, troughs);
if (lower > m_maxLower) lower = m_maxLower; 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 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); double higher = snapToTrough(prevHigher, troughs, magnitudes);
if (higher < m_minHigher || higher > m_maxHigher) { if (higher < m_minHigher || higher > m_maxHigher) {
higher = snapToTrough(m_defaultHigher, troughs, magnitudes); higher = snapToTrough(m_defaultHigher, troughs, magnitudes);
@@ -231,17 +242,16 @@ public:
} }
} }
*/ */
/*
double higher = m_defaultHigher; double higher = m_defaultHigher;
double prevLower = guidance.fftBands[0].f1;
double lower = snapToTrough(prevLower, troughs, magnitudes);
if (lower < m_minLower || lower > m_maxLower) { if (lower < m_minLower || lower > m_maxLower) {
lower = snapToTrough(m_defaultLower, troughs, magnitudes); lower = snapToTrough(m_defaultLower, troughs, magnitudes);
if (lower < m_minLower || lower > m_maxLower) { if (lower < m_minLower || lower > m_maxLower) {
lower = prevLower; lower = prevLower;
} }
} }
*/
guidance.fftBands[0].f0 = 0.0; guidance.fftBands[0].f0 = 0.0;
guidance.fftBands[0].f1 = lower; guidance.fftBands[0].f1 = lower;
@@ -343,13 +353,22 @@ protected:
return (here > 10.e-3 && here > there * 1.4); return (here > 10.e-3 && here > there * 1.4);
} }
double snapToTrough(double f, double descendToValley(double f, const double *const magnitudes) const {
const int *const troughs,
const double *const magnitudes) const {
// return frequencyForBin(troughs[binForFrequency(f)]); // 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]; int snapped = troughs[bin];
double sf = frequencyForBin(snapped);
std::cout << "snapToTrough: " << f << " -> bin " << bin << " -> snapped " << snapped << " -> " << sf << std::endl; std::cout << "snapToTrough: " << f << " -> bin " << bin << " -> snapped " << snapped << " -> " << sf << std::endl;
for (int i = -3; i <= 3; ++i) { for (int i = -3; i <= 3; ++i) {
if (i == 0) std::cout << "["; if (i == 0) std::cout << "[";
@@ -358,6 +377,8 @@ protected:
std::cout << " "; std::cout << " ";
} }
std::cout << std::endl; std::cout << std::endl;
*/
double sf = frequencyForBin(b);
return sf; return sf;
} }

View File

@@ -38,7 +38,6 @@ R3StretcherImpl::R3StretcherImpl(Parameters parameters,
m_guide(Guide::Parameters(m_parameters.sampleRate, parameters.logger)), m_guide(Guide::Parameters(m_parameters.sampleRate, parameters.logger)),
m_guideConfiguration(m_guide.getConfiguration()), m_guideConfiguration(m_guide.getConfiguration()),
m_channelAssembly(m_parameters.channels), m_channelAssembly(m_parameters.channels),
m_troughPicker(m_guideConfiguration.classificationFftSize / 2 + 1),
m_inhop(1), m_inhop(1),
m_prevOuthop(1), m_prevOuthop(1),
m_draining(false) 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); double instantaneousRatio = double(prevOuthop) / double(prevInhop);
bool specialCaseUnity = true; bool specialCaseUnity = true;
m_guide.calculate(instantaneousRatio, m_guide.updateGuidance(instantaneousRatio,
classifyScale->mag.data(), classifyScale->mag.data(),
classifyScale->troughs.data(), classifyScale->prevMag.data(),
classifyScale->prevMag.data(), cd->segmentation,
cd->segmentation, cd->prevSegmentation,
cd->prevSegmentation, cd->nextSegmentation,
cd->nextSegmentation, specialCaseUnity,
specialCaseUnity, cd->guidance);
cd->guidance);
} }
void void

View File

@@ -109,7 +109,6 @@ protected:
FixedVector<double> mag; FixedVector<double> mag;
FixedVector<double> phase; FixedVector<double> phase;
FixedVector<double> advancedPhase; FixedVector<double> advancedPhase;
FixedVector<int> troughs;
FixedVector<double> prevMag; FixedVector<double> prevMag;
FixedVector<double> accumulator; FixedVector<double> accumulator;
@@ -122,7 +121,6 @@ protected:
mag(bufSize, 0.f), mag(bufSize, 0.f),
phase(bufSize, 0.f), phase(bufSize, 0.f),
advancedPhase(bufSize, 0.f), advancedPhase(bufSize, 0.f),
troughs(bufSize, 0),
prevMag(bufSize, 0.f), prevMag(bufSize, 0.f),
accumulator(_longestFftSize, 0.f) accumulator(_longestFftSize, 0.f)
{ } { }
@@ -261,7 +259,6 @@ protected:
Guide m_guide; Guide m_guide;
Guide::Configuration m_guideConfiguration; Guide::Configuration m_guideConfiguration;
ChannelAssembly m_channelAssembly; ChannelAssembly m_channelAssembly;
Peak<double, std::less<double>> m_troughPicker;
std::unique_ptr<StretchCalculator> m_calculator; std::unique_ptr<StretchCalculator> m_calculator;
std::unique_ptr<Resampler> m_resampler; std::unique_ptr<Resampler> m_resampler;
std::atomic<int> m_inhop; std::atomic<int> m_inhop;