How to manually apply FFT to sound input?

edited June 2015 in Android Mode

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 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() {


  minim = new Minim( this );
  in = minim.getLineIn( Minim.STEREO , bufferSize , sampleRate );

  real = new double[bufferSize];
  imag = new double[bufferSize];
  fft = new FFT( bufferSize );



void draw() {

  background( 100 , 100 , 200 );
  stroke( 255 , 255 , 255 );

  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: )


Sign In or Register to comment.