Hello,
I'm working on my school project, and my task is to get musical tone value (for example for 440Hz sine wave it's tone "A") in real time from audio recorder.
What I remember from math lessons, the fast fourier transformation would be great to solve it. But implementing it in C++ it's not easy for me. I've spent today some time to implement FFTW project to my code, and I think I am on good way, but now I can't figure out how to send audio signal to my fft_function.
I tried something like that:
void MainWindow::fftSlot(QAudioBuffer buffer) // it's a public slot
{
int n = 44100;
fftw_complex x[n]; // input
fftw_complex y[n]; // output
const double *data = buffer.data<double>();
for(int i=0; i<=n; i++)
{
x[i][REAL] = *data;
x[i][IMAG] = 0;
}
fftw_plan myPlan = fftw_plan_dft_1d(n, x, y, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(myPlan);
}
void MainWindow::fftSlot(QAudioBuffer buffer) // it's a public slot
{
int n = 44100;
fftw_complex x[n]; // input
fftw_complex y[n]; // output
const double *data = buffer.data<double>();
for(int i=0; i<=n; i++)
{
x[i][REAL] = *data;
x[i][IMAG] = 0;
}
fftw_plan myPlan = fftw_plan_dft_1d(n, x, y, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(myPlan);
}
To copy to clipboard, switch view to plain text mode
But ot doesn't work for my. When I start:
QAudioProbe *probka;
probka = new QAudioProbe;
connect(probka, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(fftSlot(QAudioBuffer)));
The program crashes with info: "The program has unexpectedly finished."
I'm pretty sure it's because that strange loop in slot. But I have no idea how to impute QAudioBuffer to the fftw_complex x[n], and what should be in that case int n=???;
Maybe anybody could help?
For any help thanks in advance.
Best Regards
Bookmarks