:o My main project is on a Due and as such wanted a spectrum analyser in real time on sound samples.
So basically :-
SD card ---- samples ---> Due ---- samples ---> 4921 DAC ---> PAM8403 amp -----> speakers
As each sample is sent to the DAC I add to the FFT array and when full process the FFT and process the spectrum bins.
Initially a disaster as the code was originally for AVR and had some bugs. The original also offloaded the spectrum data to another micro controller to do the output and the input was sourced from analog A0 rather directly from the SD card. (easy to do this if desired)
The samples are fetched via an interrupt and sent to the 4921 DAC. This oddly enough occurs at the frequency of the audio being played.
The data like most other real time FFT algorithms has 2 buffers as one is being filled while the other is being processed. The code must be fast enough to process one lot before the next lot is ready!
The original used memcpy to copy the entirety of the data from the sample array to the calculation arrays which added overhead to the calculation. I altered the code to simply rotate 2 pointers to the arrays which means no copying of these arrays every calculation cycle.
At the moment the FFT is working well with 22050 stereo 16 bit audio streamed from SD playing on MCP4921 DAC and output on 8x8 MAX7219.
I use a bit of floating point still at the last step I want to get rid of but need to get a fast integer function for 10 * log10(x). I still need to look at possible optimizations... the main one being whether 16 bit integers instead of 32 bit are faster as the arrays are all 32 bit integers at the moment.
The FFT uses fixed point integers and since on a 32 bit controller I changed the 8p8 to 22p10 which gives more accuracy however I still have to see if this makes any real difference to quality or speed.
If people interested I will get some code up.
Here's a video of it working :-