Tuner: make average for deviation result
This commit is contained in:
parent
e270506117
commit
f961e01452
2 changed files with 38 additions and 4 deletions
|
@ -74,6 +74,7 @@ void Tuner::Start()
|
|||
cerr << __func__ << endl;
|
||||
count_found = count_not_found = 0;
|
||||
nb_sample_running = 0;
|
||||
ResetDeviation();
|
||||
blank_prevent(true);
|
||||
high_filter->Clear();
|
||||
cross->Clear();
|
||||
|
@ -104,12 +105,36 @@ void Tuner::AudioCb(const QAudioBuffer &buffer)
|
|||
AudioAnalyse(ptr, nbFrame);
|
||||
}
|
||||
|
||||
void Tuner::ResetDeviation()
|
||||
{
|
||||
// reset deviation values
|
||||
nb_deviation = 0;
|
||||
deviation_start = 0;
|
||||
deviation_sum = 0;
|
||||
}
|
||||
|
||||
void Tuner::UpdateDeviation(double d)
|
||||
{
|
||||
if (nb_deviation == nbDeviationValues) {
|
||||
deviation_sum -= deviation_values[deviation_start];
|
||||
deviation_start = (deviation_start + 1) % nbDeviationValues;
|
||||
nb_deviation--;
|
||||
}
|
||||
deviation_values[(deviation_start + nb_deviation) % nbDeviationValues] = d;
|
||||
nb_deviation++;
|
||||
deviation_sum += d;
|
||||
deviation = deviation_sum / nb_deviation;
|
||||
}
|
||||
|
||||
void Tuner::SetFound(int n, int o, double d)
|
||||
{
|
||||
if (n != note_found) {
|
||||
note_found = n;
|
||||
count_found = 0;
|
||||
SetNotFound();
|
||||
|
||||
ResetDeviation();
|
||||
UpdateDeviation(d);
|
||||
}
|
||||
else if (count_found++ >= nbConfirm) {
|
||||
count_not_found = 0;
|
||||
|
@ -125,10 +150,11 @@ void Tuner::SetFound(int n, int o, double d)
|
|||
octave = o;
|
||||
octaveChanged();
|
||||
}
|
||||
if (deviation != d) {
|
||||
deviation = d;
|
||||
deviationChanged();
|
||||
}
|
||||
UpdateDeviation(d);
|
||||
deviationChanged();
|
||||
}
|
||||
else {
|
||||
UpdateDeviation(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,6 +164,7 @@ void Tuner::SetNotFound()
|
|||
count_found = 0;
|
||||
if (found) {
|
||||
found = false;
|
||||
ResetDeviation();
|
||||
foundChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ class Tuner : public QObject {
|
|||
double freq, deviation;
|
||||
int note, octave, nb_sample_running;
|
||||
int note_found, count_found, count_not_found;
|
||||
int nb_deviation, deviation_start;
|
||||
double deviation_sum;
|
||||
|
||||
static const int rate = 16000;
|
||||
static const int defaultNbFrame = 1024;
|
||||
|
@ -38,11 +40,16 @@ class Tuner : public QObject {
|
|||
static const int nbConfirm = 3;
|
||||
/// number of analyses to drop a note
|
||||
static const int nbDefect = 20;
|
||||
/// number of deviation values for average
|
||||
static const int nbDeviationValues = 8;
|
||||
|
||||
double deviation_values[nbDeviationValues];
|
||||
|
||||
inline void ComputeFrame(int16_t v);
|
||||
void SetFound(int note, int octave, double deviation);
|
||||
void SetNotFound();
|
||||
void ResetDeviation();
|
||||
void UpdateDeviation(double d);
|
||||
|
||||
private slots:
|
||||
void AudioCb(const QAudioBuffer &buffer);
|
||||
|
|
Loading…
Reference in a new issue