Command line run with input audio file argument
This commit is contained in:
parent
6e6e0f7191
commit
d322ec1c5e
4 changed files with 41 additions and 5 deletions
|
@ -77,9 +77,13 @@ void Tuner::ComputeFrame(int16_t v)
|
||||||
void Tuner::AudioCb(const QAudioBuffer &buffer)
|
void Tuner::AudioCb(const QAudioBuffer &buffer)
|
||||||
{
|
{
|
||||||
const int16_t *ptr = buffer.constData<int16_t>();
|
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()) {
|
if (freq != cross->Freq()) {
|
||||||
freq = cross->Freq();
|
freq = cross->Freq();
|
||||||
|
@ -129,7 +133,7 @@ int Tuner::GetOctave()
|
||||||
return octave;
|
return octave;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Tuner::GetNoteName()
|
const char* Tuner::GetNoteName()
|
||||||
{
|
{
|
||||||
return scale->NoteName(note);
|
return scale->NoteName(note);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,15 @@ class Tuner : public QObject {
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
|
void AudioAnalyse(const int16_t *buffer, int size);
|
||||||
|
|
||||||
bool GetRunning();
|
bool GetRunning();
|
||||||
void SetRunning(bool r);
|
void SetRunning(bool r);
|
||||||
double GetFreq();
|
double GetFreq();
|
||||||
int GetNote();
|
int GetNote();
|
||||||
int GetOctave();
|
int GetOctave();
|
||||||
double GetDeviation();
|
double GetDeviation();
|
||||||
QString GetNoteName();
|
const char* GetNoteName();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void runningChanged();
|
void runningChanged();
|
||||||
|
|
|
@ -2,10 +2,40 @@
|
||||||
#include <QQuickView>
|
#include <QQuickView>
|
||||||
#include <QtQml>
|
#include <QtQml>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "Tuner.hpp"
|
#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[])
|
Q_DECL_EXPORT int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
if (argc == 2) {
|
||||||
|
analyse_file(argv[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
qmlRegisterType<Tuner>("LJTuner", 1, 0, "Tuner");
|
qmlRegisterType<Tuner>("LJTuner", 1, 0, "Tuner");
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
|
@ -62,7 +62,7 @@ int Scale::FindNote(double freq, int &octave, double &deviation)
|
||||||
int note = 0;
|
int note = 0;
|
||||||
octave = findOctave(freq);
|
octave = findOctave(freq);
|
||||||
|
|
||||||
std::cerr << octave << " " << freq << std::endl;
|
//std::cerr << octave << " " << freq << std::endl;
|
||||||
assert(freq >= actualRange[0] && freq <= actualRange[1]);
|
assert(freq >= actualRange[0] && freq <= actualRange[1]);
|
||||||
|
|
||||||
while (actualNoteFreq[note] < freq && note < nbNote - 1) note++;
|
while (actualNoteFreq[note] < freq && note < nbNote - 1) note++;
|
||||||
|
|
Loading…
Reference in a new issue