Here is part 2 of my sound experimentation.
What I’m trying to do here is to analyse Fast Fourier Transform data from a sine wave, to determine what the initial pitch of the sound is.
First of all I’m generating a sine wave (see part 1). The pitch of this wave is relative to the mouse X position. This frequency is represented on the graph as a white line.
Then the sound data is put through the Fast Fourier Transform (FFT) using
SoundMixer.computeSpectrum(bytes, true, 2);
This data is plotted on the graph and the 5 highest peaks are marked with the red cross.
I want to determine the initial frequency of the sound that was put through FFT. This version calculates this by finding the middle point of the 3rd and 4th highest peaks, and then averaging this value with the weighted average height of the three highest peaks. The calculated frequency is represented on the graph by the red line.
In the bottom right-hand corner you can see the two pitches, and the difference between them.
Obviously this still has quite a way to go as the estimated frequency moves around quite a bit.