I have some question about FFT (in fact, I believe this is more about the Androids FFT output from Visualizer.getFFT ()).
I created a Music Player with its own library function for Android, including many materials (such as genres, dynamic playlists, and visualizations). I currently have some visualization issues that I create when it comes to providing a spectrum of the current AudioStream.
I already read the following questions (and answers) to get the idea of FFT androids:
What kind of output should I see from getFft?
Android 2.3 Visualizer - understanding getFft () problems
Now to my problem: The spectrum that I get from the getFFTs coefficients seems a bit "weird." I notice that the spectrum I render seems to display a lot of “noise” when playing a song, so I tried using some test sounds. One of them is a simple 8 kHz sound, which should lead to one peak on the graph. Unfortunately, the result is as follows:
http://img4.imageshack.us/img4/4181/spectrum8khz.png
The noise that appears below flickers across the entire width of the graph. High bars remain in a slightly flickering position.
When I use a test sound that moves slowly from 1 kHz to 20 kHz, it looks like this (about 2-3 kHz):
http://img846.imageshack.us/img846/7373/spectrum3khz1khz20khz.png
Peaks move from left to right, and each of them is a little faster, so the distance between the peaks increases over time. What is not visible is that the peaks return and go from right to left when they leave the screen on the right (but with a smaller value). Also, all peaks join one large peak for a little more than 0.5 screen.
Here is the code I use to retrieve the data:
for (int i = 1; i < n / 2; i++) { byte rfk = mRawSpecData[2*i]; byte ifk = mRawSpecData[2*i+1]; float magnitude = (float)Math.sqrt(rfk * rfk + ifk * ifk); mFormattedSpecData[i-1] = magnitude / 128f; }
In the code above, mRawSpecData is the result of the visualisers getFFT () function. The length of the captured data is 1024. Currently, the slope starts at 1 because mRawSpecData [0] contains DC and mRawSpecData [1] contains n / 2.
To solve my problem, I also tried to integrate with DC and hopper phase. I thought maybe I had to apply some calculations by values to “clear” the graph. But I did not succeed (maybe because I did not understand what was going on with the DC / phase!).
I spent two weeks searching Google in the evenings and tried different calculations, but nothing helped.
So what is the deal? Am I doing something wrong or am I going out? After that, another question that bothers me is how to scale the values correctly. My goal is to get values between 0f and 1f.
thanks a lot
rampage
PS: Screenshots taken via eclipse from a phone running Android 2.3.
PPS: I also tested sounds with various other players (like winamp), and there I see the correct spectrum behavior.