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;
}
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;
}

View File

@@ -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

View File

@@ -109,7 +109,6 @@ protected:
FixedVector<double> mag;
FixedVector<double> phase;
FixedVector<double> advancedPhase;
FixedVector<int> troughs;
FixedVector<double> prevMag;
FixedVector<double> 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<double, std::less<double>> m_troughPicker;
std::unique_ptr<StretchCalculator> m_calculator;
std::unique_ptr<Resampler> m_resampler;
std::atomic<int> m_inhop;