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:

Qt Code:
  1. void MainWindow::fftSlot(QAudioBuffer buffer) // it's a public slot
  2. {
  3. int n = 44100;
  4. fftw_complex x[n]; // input
  5. fftw_complex y[n]; // output
  6.  
  7. const double *data = buffer.data<double>();
  8.  
  9. for(int i=0; i<=n; i++)
  10. {
  11. x[i][REAL] = *data;
  12. x[i][IMAG] = 0;
  13. }
  14.  
  15. fftw_plan myPlan = fftw_plan_dft_1d(n, x, y, FFTW_FORWARD, FFTW_ESTIMATE);
  16. fftw_execute(myPlan);
  17. }
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