We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone. I'm having a bit of trouble here, could you give me a hand, please?
I need to read the frequencies from microphone input. My code runs fine on desktop, because I'm using Minim and getting fft to work there is pretty straightforward. But when I went to Android, I had to abandon Minim and I'm stuck at trying to apply fft to input myself (both in desktop and in android).
On Android I get my input from AudioRecord.read( myarray , 0 , bufferSize ); On Desktop I get my input from AudioInput.mix.get( n ) and assign each value to a position in myarray.
Apparently, it's picking up the same input for both. So input is fine, my problem is I don't know how to use FFT.
I got a FFT java class from the internet. It asks for a real and an imaginary array. I pass "myarray" as the real array and another array with all 0-values as the imaginary one.
For some reason, FFT is giving me negative values. Why? Aren't frequency bands supposed to start from zero? Any idea of what I am doing wrong?
I attached a pic of what's happening (sorry for the bright red):
And here's my code in case it helps:
import ddf.minim.*;
AudioInput in;
Minim minim;
double[] real;
double[] imag;
FFT fft;
int bufferSize = 1024;
int sampleRate = 5512;
void setup() {
size(1024,768);
minim = new Minim( this );
in = minim.getLineIn( Minim.STEREO , bufferSize , sampleRate );
real = new double[bufferSize];
imag = new double[bufferSize];
fft = new FFT( bufferSize );
background(100,100,250);
}
void draw() {
background( 100 , 100 , 200 );
noFill();
stroke( 255 , 255 , 255 );
strokeWeight(1);
for ( int i=0; i<bufferSize; i++ ) { real[i] = in.mix.get(i)*1000; imag[i] = 0; }
for ( int i=0; i<bufferSize; i++ ) line( i , 200 , i , 200 - (int)(real[i]) );
fft.fft( real , imag );
stroke( 255 , 255 , 0 );
for ( int i=0; i<bufferSize; i++ ) line( i , 600 , i , 600 - ((int)(real[i])/10) );
}
I'm using a FFT class I got from the interwebs (this one: https://code.google.com/p/opendatakit/source/browse/src/net/hugo/audioAnalyzer/FFT.java?repo=listen&r=1146e38a2c144b6b338f694bc39fda3c26c3d1e1 )
Answers
what's up with using the fft from within minim?
http://code.compartmental.net/minim/fft_class_fft.html
example: http://code.compartmental.net/minim/fft_method_getband.html
None, if you can get that to work on Android.
sorry, didn't see that requirement. the code you posted still has minim calls in it...
I wrote that as a test, just to see if I could get the manual FFT thing on desktop before moving to Android.
Actually, I just stumbled upon a Minim FFT implementation for Android. :D https://github.com/dasaki/android_fft_minim/
I'm still going to try that out, but it should work.
Sorry for coming here a little too desperate, I should have googled this a bit more before bothering you guys ;)