Start to bring in unit tests

This commit is contained in:
Chris Cannam
2022-06-08 09:57:12 +01:00
parent 36f993b9a6
commit 95a1d6df25
10 changed files with 1556 additions and 6 deletions

View File

@@ -214,17 +214,38 @@ public:
guidance.phaseReset.f1 = std::max(segmentation.residualAbove,
nextSegmentation.residualAbove);
}
/*
double higher = snapToTrough(m_defaultHigher, troughs);
if (higher > m_maxHigher) higher = m_maxHigher;
double lower = snapToTrough(m_defaultLower, troughs);
if (lower > m_maxLower) lower = m_maxLower;
*/
/*
double prevHigher = guidance.fftBands[1].f1;
double higher = snapToTrough(prevHigher, troughs, magnitudes);
if (higher < m_minHigher || higher > m_maxHigher) {
higher = snapToTrough(m_defaultHigher, troughs, magnitudes);
if (higher < m_minHigher || higher > m_maxHigher) {
higher = prevHigher;
}
}
*/
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;
// std::cout << "x:" << lower << std::endl;
std::cout << "x:" << lower << std::endl;
guidance.fftBands[1].f0 = lower;
guidance.fftBands[1].f1 = higher;
@@ -322,8 +343,22 @@ protected:
return (here > 10.e-3 && here > there * 1.4);
}
double snapToTrough(double f, const int *const troughs) const {
return frequencyForBin(troughs[binForFrequency(f)]);
double snapToTrough(double f,
const int *const troughs,
const double *const magnitudes) const {
// return frequencyForBin(troughs[binForFrequency(f)]);
int bin = binForFrequency(f);
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 << "[";
std::cout << magnitudes[bin + i];
if (i == 0) std::cout << "]";
std::cout << " ";
}
std::cout << std::endl;
return sf;
}
double betaFor(double f, double ratio) const {

View File

@@ -654,7 +654,7 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
cd->nextSegmentation = cd->segmenter->segment(cd->nextClassification.data());
m_troughPicker.findNearestAndNextPeaks
(classifyScale->mag.data(), 1, nullptr,
(classifyScale->mag.data(), 3, nullptr,
classifyScale->troughs.data());
double instantaneousRatio = double(prevOuthop) / double(prevInhop);