We are about to switch to a new forum software. Until then we have removed the registration on this forum.

- All Categories 25.7K
- Announcements & Guidelines 13
- Common Questions 30
- Using Processing 22.1K
- Programming Questions 12.2K
- Questions about Code 6.4K
- How To... 4.2K
- Hello Processing 72
- GLSL / Shaders 292
- Library Questions 4K
- Hardware, Integration & Other Languages 2.7K
- Kinect 668
- Arduino 1K
- Raspberry PI 188
- Questions about Modes 2K
- Android Mode 1.3K
- JavaScript Mode 413
- Python Mode 205
- Questions about Tools 100
- Espanol 5
- Developing Processing 548
- Create & Announce Libraries 211
- Create & Announce Modes 19
- Create & Announce Tools 29
- Summer of Code 2018 93
- Rails Girls Summer of Code 2017 3
- Summer of Code 2017 49
- Summer of Code 2016 4
- Summer of Code 2015 40
- Summer of Code 2014 22
- p5.js 1.6K
- p5.js Programming Questions 947
- p5.js Library Questions 315
- p5.js Development Questions 31
- General 1.4K
- Events & Opportunities 289
- General Discussion 365

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 )

Tagged:

## 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 ;)