diff --git a/src/audio/ZeroCross.cpp b/src/audio/ZeroCross.cpp index 56011d5..eaebf57 100644 --- a/src/audio/ZeroCross.cpp +++ b/src/audio/ZeroCross.cpp @@ -13,6 +13,9 @@ using namespace patterns; #define CORRECT_TIME_DEVIATION 1 /// max factor of deviation to consider multiple to be dropped #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 // local functions @@ -70,18 +73,18 @@ PatternMatch FindPattern(const vector &values, double pattern_min, doub if (interval > pattern_max) break; res = IsPattern(values, interval); - // 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 (best.time && best.time_deviation < CORRECT_TIME_DEVIATION && best.time_deviation / res.time_deviation < MAX_TIME_DEVIATION_FACTOR_MULTIPLE) { + // cout << " " << res.time << " " << 16000/res.time << " " << res.time_deviation << " " << res.energy_deviation << endl; + 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) { double div = res.time / best.time; // it is a multiple of previous if (fabs(div - round(div)) < EPS_DIVISOR) continue; -// cout << "... " << div - floor(div) << endl; + //cout << "... " << div - floor(div) << endl; } 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 return best; } diff --git a/src/desktop.cpp b/src/desktop.cpp index e680616..72ea0bd 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -22,7 +22,10 @@ static void analyse_file(const char *filename) fin.read((char*) buffer, sizeof(buffer)); 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; }