Command line run with input audio file argument

This commit is contained in:
Louis-Joseph Fournier 2015-12-28 14:16:08 +01:00
parent 6e6e0f7191
commit d322ec1c5e
4 changed files with 41 additions and 5 deletions

View file

@ -77,9 +77,13 @@ void Tuner::ComputeFrame(int16_t v)
void Tuner::AudioCb(const QAudioBuffer &buffer)
{
const int16_t *ptr = buffer.constData<int16_t>();
int nbFrame = buffer.sampleCount();
const int nbFrame = buffer.sampleCount();
AudioAnalyse(ptr, nbFrame);
}
while (nbFrame--) ComputeFrame(*ptr++);
void Tuner::AudioAnalyse(const int16_t *ptr, int nb_frame)
{
while (nb_frame--) ComputeFrame(*ptr++);
if (freq != cross->Freq()) {
freq = cross->Freq();
@ -129,7 +133,7 @@ int Tuner::GetOctave()
return octave;
}
QString Tuner::GetNoteName()
const char* Tuner::GetNoteName()
{
return scale->NoteName(note);
}

View file

@ -44,13 +44,15 @@ class Tuner : public QObject {
void Start();
void Stop();
void AudioAnalyse(const int16_t *buffer, int size);
bool GetRunning();
void SetRunning(bool r);
double GetFreq();
int GetNote();
int GetOctave();
double GetDeviation();
QString GetNoteName();
const char* GetNoteName();
signals:
void runningChanged();

View file

@ -2,10 +2,40 @@
#include <QQuickView>
#include <QtQml>
#include <iostream>
#include <fstream>
#include "Tuner.hpp"
static void analyse_file(const char *filename)
{
using namespace std;
cout << "analyse file " << filename << endl;
ifstream fin;
fin.open(filename);
const int nb_frame = 1024;
Tuner *tuner = new Tuner();
int16_t buffer[nb_frame];
while (1) {
fin.read((char*) buffer, sizeof(buffer));
tuner->AudioAnalyse(buffer, sizeof(buffer) >> 1);
cout << tuner->GetFreq() << " " << tuner->GetNoteName() << " " << tuner->GetOctave() << endl;
if (fin.eof()) break;
}
delete tuner;
}
Q_DECL_EXPORT int main(int argc, char* argv[])
{
if (argc == 2) {
analyse_file(argv[1]);
return 0;
}
qmlRegisterType<Tuner>("LJTuner", 1, 0, "Tuner");
QGuiApplication app(argc, argv);

View file

@ -62,7 +62,7 @@ int Scale::FindNote(double freq, int &octave, double &deviation)
int note = 0;
octave = findOctave(freq);
std::cerr << octave << " " << freq << std::endl;
//std::cerr << octave << " " << freq << std::endl;
assert(freq >= actualRange[0] && freq <= actualRange[1]);
while (actualNoteFreq[note] < freq && note < nbNote - 1) note++;