Why nDataLength = 47936 since my sample is 1.780 sec long?
I don't know.
The ptr evidently contains int16_t values, which are signed short ints.
I was fiddling with a guitar tuner last summer, but I've reinstalled the OS to a bigger hard drive and haven't reinstalled Allegro. Give me an hour and I'll see if I can give you an example program that allows you to input sounds through the microphone and see how the "main frequency" and the sample distributions change (also known as timbre).
[EDIT] Well, the last announcement for a WIP in Allegro Development tried to give me allegro-5.0.11 something, which I already had from 2014, so I tried allegro-5.1.8. I can't get this stuff to compile, haven't used it so long I'm a n00b again too.
I think this zip file has the source for some sort of FFT thing, IIRC it tried to print the nearest note of the predominant frequency and how much it was off by. It uses OpenGL, sorry. You may be able to get some relevant bits out of it.
As for how FFT works, I have some totally wild guesses.
<total n00bishness follows>
The FFT thing works by making a sine wave of some given frequency and compares it to the samples to see how well it follows the curve. A good fit results in a large value, so the "bin" for that frequency gets the high value. It then tries higher and higher frequencies to see how well they fit in turn and stores those values in their respective bins. And for low values too, obviously. However, since the generated sine wave starts from a zero point, and the samples waveforms start from a random point, it would most likely guess wrong unless the sample could be forced to start from the zero point of a waveform. This is about as difficult in itself, so what the FFT does is make a "window" to copy the sample to, and reduces the frequencies toward both ends so it "looks" like it starts from a zero point. OTOH, this "window" necessarily averages quite a few sample points to fit one bin, so eventually you have to compromise between accuracy and speed. Also, I got stuck for awhile on the fact that the display of the "bins" seemed to produce a useless S shaped curve, but what I didn't realize was that it was symmetrical and I only needed to examine the very first few "bins" at the beginning to get something reasonable. At least, that's my memory of what I thought last summer.
Note: edited the above again