Hello,
great, great, great thanks for your so detailed answer. But please don’t finish with me yet 
Ofcourse I tried to study Spectrum example from QT creator, even before you adviced that. But actually I am quite new in programming, and also I am 37 years old and my knowledge of FFT function and math at all is also very old. And with those two defects at once it’s almost impossible for me to go through all that code with understanding. And for example, in that example there are two *.pro files, and I’ve never seen before such complicated solution. I hope you forgive me.
But because of your answer I understand much more. But as you probably know - the more you understand, the more things you don’t understand.
I think it would be much clearer in points, so:
1. You mention type
QAudioBuffer::S16U
QAudioBuffer::S16U
To copy to clipboard, switch view to plain text mode
it’s stereo data, and for mono signal there will be data only in one channel - I suppose
frames[i].right
frames[i].right
To copy to clipboard, switch view to plain text mode
But I use monofonic microphone (built in laptop), and when I execute that code:
QAudioBuffer::S16U *frames = buffer->data<QAudioBuffer::S16U>();

for (int i=0; i < buffer->frameCount(); i++)
{
cout << frames[i].right << „ right†<< endl;
cout << frames[i].left << „ left†<< endl;
}

QAudioBuffer::S16U *frames = buffer->data<QAudioBuffer::S16U>();

for (int i=0; i < buffer->frameCount(); i++)
{
cout << frames[i].right << „ right†<< endl;
cout << frames[i].left << „ left†<< endl;
}

To copy to clipboard, switch view to plain text mode
I get various values, sometimes the same, but most often different, and for sure neither righ and left have permanent zeros, there are zeros, but also there are a lot of some data.
I don’t understand why? And in the other hand, can’t I just declare in some way mono data? Something like that QAudioBuffer::??? *monoFrames; ?
2. I am also amateur musician and big fan of audio recording. And until now I thought I understand basics of computer audio technology process. But now I have impression I missed something.
As I know sample rate means „How many audio impuls are in one second of audio recordingâ€, and bit rate means „with what accuracy each impuls is describeâ€.
But I am not sure what means „bufferâ€. You told „n†in my code should be not sampling frequency (I understand you mean here sammple rate) but it should be number of samples in the buffer, so:
buffer->frameCount();
buffer->frameCount();
To copy to clipboard, switch view to plain text mode
But isn’t it the same? I know it isn’t, but why?
My audio format properties is 44100Hz and 16 bit. But when I
cout << buffer->frameCount();
cout << buffer->frameCount();
To copy to clipboard, switch view to plain text mode
I found it’s 2048. What does it mean? Where is any connection between those values?
And, which is makes it much more complicated to understand
cout << buffer->frameCount();
cout << buffer->frameCount();
To copy to clipboard, switch view to plain text mode
occasionally (but very rarely) gives 4096. What does it mean?
3. And last but not least. It’s not concern exactly to your answer, but it’s just next part of my primary issue, and FFT understanding at all. When I use that code:
fftw_plan_dft_1d(n, x, y, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_plan_dft_1d(n, x, y, FFTW_FORWARD, FFTW_ESTIMATE);
To copy to clipboard, switch view to plain text mode
As I understand:
x - is input data - so what exactly is it?
In my case it’s array of
QAudioBuffer::S16U
QAudioBuffer::S16U
To copy to clipboard, switch view to plain text mode
which are array of unsigned shorts. But what exactly each one of those unsigned shorts represent?
Each unsigned short is 2 bytes, so it 16 bits.
So I suppose one unsigned short is value (amplitude) of one audio impuls (one from those 44100 per second). Am I right?
But where is any value represent time. As I understand - in audio world - FFT input should be some wave ( amplitude in function of time) but not only amplitude values. Those amplitude values make sense only if we locate them in timeline.
So:
I suppose „n†is responsible in some way for time value. But in what way?
„n†is number of frame in buffer. But now we back to the first point: I can’t find relationship between frameCount() and sample rate. I understand sample rate because it’s some value in time, but frame count is some value in „bufferâ€. What is buffer?
Ok, I go to google and take my lesson
I hope you are not ungry that I’ve written so much to get by myself „go to google†conclusion
But when I write it’s easier to think slowly and in detailed. And maybe that thread will help somebody else also.
But to the point. There is still one more question about „yâ€.
It’s output of FFT.
But again: it’s only one value. Shouldn’t it be two values - some peaks in the function of frequency? What exactly „y†reprsent? How to read from it value of represent frequency?
For any help thanks in advance so much.
Bookmarks