
Hello,
I’d like to implement a similar visual effects as iTunes plays music. I’m using AVAudioPlayer, my sound files are local. I played the same files in iTunes and captured this screenshot.
Updated:
- I did research Apple’s avTouch sample. Visualization-wise, I’ve got a rough idea. but this sample is about volume metering
- someone told me I need to use FFT, but that’s too much over my head
- I found after iOS 4.1, the Accelerometer framework contains FFT DSP functions
- It seems I need to touch down to Core Audio (Audio Queue?) to get sample buffer then FFT it
Gee, I only want to implement a simple spectrum for my playback, anyone can help?
The FFT “I” or real input is n samples from the sample buffer (preferably with a window weighting applied prior to the transformation). Set the “Q” or imaginary input to al zeros.
The output is the complex spectrum with DC in the index=0 position. Index=1 corresponds to the sampling frequency divided by the FFT length N, index=2 twice that frequency and so on up to index N/2. To get the power at a certain frequency you need to add the squared real and imaginary parts.
Typically you want to display the power in a dB scale, which is calculated as 10*log10(power), each block in the display corresponds to e.g. 3dB. You may also want to add some averaging or peak detection.
The more advanced displays has a logarithmic frequency axis as well, e.g. each column corresponds to 1/12 octave. Ideally each output has its own filter but you may achieve something similar by adding the higher index FFT outputs instead of showing them all.