ZeroCross: fix a regression for octave, and better logs

This commit is contained in:
Louis-Joseph Fournier 2016-01-03 11:05:34 +01:00
parent f961e01452
commit a5e74d6300
2 changed files with 12 additions and 6 deletions

View file

@ -13,6 +13,9 @@ using namespace patterns;
#define CORRECT_TIME_DEVIATION 1 #define CORRECT_TIME_DEVIATION 1
/// max factor of deviation to consider multiple to be dropped /// max factor of deviation to consider multiple to be dropped
#define MAX_TIME_DEVIATION_FACTOR_MULTIPLE 2 #define MAX_TIME_DEVIATION_FACTOR_MULTIPLE 2
/// Correct pattern, good enough to drop every lower
#define CORRECT_TIME_DEVIATION_NO_LOWER 0.001
//#define CORRECT_ENERGY_DEVIATION 1 //#define CORRECT_ENERGY_DEVIATION 1
// local functions // local functions
@ -71,7 +74,7 @@ PatternMatch FindPattern(const vector<Pattern> &values, double pattern_min, doub
res = IsPattern(values, interval); res = IsPattern(values, interval);
// cout << " " << res.time << " " << 16000/res.time << " " << res.time_deviation << " " << res.energy_deviation << endl; // cout << " " << res.time << " " << 16000/res.time << " " << res.time_deviation << " " << res.energy_deviation << endl;
if (res.time && (res.time_deviation < best.time_deviation || best.time == 0)) { if (res.time && ((res.time_deviation < best.time_deviation && best.time_deviation > CORRECT_TIME_DEVIATION_NO_LOWER) || best.time == 0)) {
if (best.time && best.time_deviation < CORRECT_TIME_DEVIATION && best.time_deviation / res.time_deviation < MAX_TIME_DEVIATION_FACTOR_MULTIPLE) { if (best.time && best.time_deviation < CORRECT_TIME_DEVIATION && best.time_deviation / res.time_deviation < MAX_TIME_DEVIATION_FACTOR_MULTIPLE) {
double div = res.time / best.time; double div = res.time / best.time;
// it is a multiple of previous // it is a multiple of previous
@ -81,7 +84,7 @@ PatternMatch FindPattern(const vector<Pattern> &values, double pattern_min, doub
best = res; best = res;
} }
} }
//cerr << " -> " << best.first << " " << best.second << endl; //cout << " -> " << best.time << " " << best.time_deviation << endl;
if (best.time_deviation > CORRECT_TIME_DEVIATION) return PatternMatch(); // empty pattern if (best.time_deviation > CORRECT_TIME_DEVIATION) return PatternMatch(); // empty pattern
return best; return best;
} }

View file

@ -22,7 +22,10 @@ static void analyse_file(const char *filename)
fin.read((char*) buffer, sizeof(buffer)); fin.read((char*) buffer, sizeof(buffer));
tuner->AudioAnalyse(buffer, sizeof(buffer) >> 1); tuner->AudioAnalyse(buffer, sizeof(buffer) >> 1);
cout << tuner->GetFreq() << " " << tuner->GetNoteName() << " " << tuner->GetOctave() << endl; cout << tuner->GetFreq() << " ";
if (tuner->GetFound())
cout << tuner->GetNoteName() << " " << tuner->GetOctave() << " " << tuner->GetDeviation();
cout << endl;
if (fin.eof()) break; if (fin.eof()) break;
} }