Sources: add comments and details fixes

This commit is contained in:
Louis-Joseph Fournier 2016-01-04 09:47:09 +01:00
parent 986f736b68
commit e75e79bb2d
5 changed files with 42 additions and 13 deletions

View file

@ -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();
}
// find note, octave, deviation
if (freq) {
int n, o;
double d;
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);

View file

@ -27,11 +27,21 @@ template<typename A> 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);
};

View file

@ -53,10 +53,14 @@ template<typename sample_t> 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();
};

View file

@ -105,8 +105,11 @@ bool Temperaments::SetTemperament(unsigned int index)
qDebug() << __func__ << "index" << index << "out of range";
return false;
}
if (CheckoutTemperament(list[index])) {
current = index;
return CheckoutTemperament(list[current]);
return true;
}
return false;
}
bool Temperaments::SetTemperament(const QString name)

View file

@ -42,14 +42,17 @@ class Temperaments {
std::vector<temp_t> 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);