From e75e79bb2d27c74ebb8e94a8766a6b469c943ef4 Mon Sep 17 00:00:00 2001 From: Louis-Joseph Fournier Date: Mon, 4 Jan 2016 09:47:09 +0100 Subject: [PATCH] Sources: add comments and details fixes --- src/Tuner.cpp | 29 +++++++++++++++++++---------- src/audio/LinearFilter.hpp | 10 ++++++++++ src/audio/ZeroCross.hpp | 4 ++++ src/scale/Temperaments.cpp | 7 +++++-- src/scale/Temperaments.hpp | 5 ++++- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/Tuner.cpp b/src/Tuner.cpp index 1970487..4950420 100644 --- a/src/Tuner.cpp +++ b/src/Tuner.cpp @@ -58,6 +58,8 @@ Tuner::Tuner() note = octave = 0; found = false; count_found = count_not_found = 0; + nb_sample_running = 0; + note_found = octave_found = -1; if (filename_record) file_record.open(filename_record); @@ -98,7 +100,9 @@ Tuner::~Tuner() delete high_filter; delete cross; delete recorder; + delete probe; delete scale; + delete temperaments; } void Tuner::Start() @@ -208,25 +212,30 @@ void Tuner::AudioAnalyse(const int16_t *ptr, int nb_frame) { nb_sample_running += nb_frame; + // record in file is needed if (filename_record && file_record.is_open()) file_record.write((char*) ptr, nb_frame * sizeof(int16_t)); + // compute every audio frame while (nb_frame--) ComputeFrame(*ptr++); + // update frequency if (freq != cross->Freq()) { freq = cross->Freq(); freqChanged(); - - if (freq) { - int n, o; - double d; - n = scale->FindNote(freq, o, d); - SetFound(n, o, d); - } - else { // no freq - SetNotFound(); - } } + // find note, octave, deviation + if (freq) { + int n, o = 0; + double d = 0; + n = scale->FindNote(freq, o, d); + SetFound(n, o, d); + } + else { // no freq + SetNotFound(); + } + + // prevent screen blanking if (nb_sample_running >= nbSamplePreventRunning && running) { nb_sample_running = 0; blank_prevent(true); diff --git a/src/audio/LinearFilter.hpp b/src/audio/LinearFilter.hpp index 975c09f..c558906 100644 --- a/src/audio/LinearFilter.hpp +++ b/src/audio/LinearFilter.hpp @@ -27,11 +27,21 @@ template class LinearFilter { double *backx, *backy; public: + /** + * filter constructor + * + * @param order Order of filter (2 = biquads) + * @param a Array of a coefficiants + * @param b Array of b coefficiants + */ LinearFilter(int order, double *a, double *b); ~LinearFilter(); + /// Clear audio stream void Clear(); + /// Compute one audio sample A operator() (A x); + /// Compute an audio buffer in place void operator() (A *ptr, int nbFrame); }; diff --git a/src/audio/ZeroCross.hpp b/src/audio/ZeroCross.hpp index 69a5f97..9314b0b 100644 --- a/src/audio/ZeroCross.hpp +++ b/src/audio/ZeroCross.hpp @@ -53,10 +53,14 @@ template class ZeroCross { public: ZeroCross(const Config &config); + /// analyse audio buffer double operator() (sample_t *ptr, int nbFrame); + /// analyse one audio sample void operator() (sample_t v); + /// Clear stream analyse void Clear(); + /// Get current frequency computed double Freq(); }; diff --git a/src/scale/Temperaments.cpp b/src/scale/Temperaments.cpp index ae0c989..1285fc2 100644 --- a/src/scale/Temperaments.cpp +++ b/src/scale/Temperaments.cpp @@ -105,8 +105,11 @@ bool Temperaments::SetTemperament(unsigned int index) qDebug() << __func__ << "index" << index << "out of range"; return false; } - current = index; - return CheckoutTemperament(list[current]); + if (CheckoutTemperament(list[index])) { + current = index; + return true; + } + return false; } bool Temperaments::SetTemperament(const QString name) diff --git a/src/scale/Temperaments.hpp b/src/scale/Temperaments.hpp index 6214eb3..e2bb9ed 100644 --- a/src/scale/Temperaments.hpp +++ b/src/scale/Temperaments.hpp @@ -42,14 +42,17 @@ class Temperaments { std::vector list; double notes[nb_notes]; + /// Check data files in directory void GetDir(const QString & dirname); + /// Check temperaments in file void CheckFile(const QString & filename); + /// Load given temperament bool CheckoutTemperament(const temp_t & temperament); public: /// constructor with dir name to find data files Temperaments(const QString & dirname); - ~Temperaments(); + ~Temperaments() {} /// set current temperament bool SetTemperament(const QString name);