We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Often when I execute the following code, I'll get a crash. "Java Platform SE binary has stopped working" (Windows 7)
But at the point of the crash, a couple of max values were already printed in the console. All of them being 0.0.
import processing.sound.*;
FFT fft;
AudioIn in;
int bands = 512;
float[] spectrum = new float[bands];
void setup() {
size(512, 360);
background(255);
// Create an Input stream which is routed into the Amplitude analyzer
fft = new FFT(this, bands);
in = new AudioIn(this, 0);
// start the Audio Input
in.start();
// patch the AudioIn
fft.input(in);
}
void draw() {
background(255, 0, 0);
// have to check somehow whether this is ready
fft.analyze(spectrum);
float max = 0;
for(int i = 0; i < bands; i++){
// The result of the FFT is normalized
// draw the line for frequency band i scaling it up by 5 to get more amplitude.
line( i, height, i, height - spectrum[i]*height*50 );
if(spectrum[i]*50 > max)
max = spectrum[i];
}
print(max + "\n");
}
Answers
I tested your code and it works fine in 3.1.2
I will suggest running other examples testing the AudioIn to ensure your sound system is being recognized. This is just a guess and hopefully a starting point.
Kf
I intentionally wrote "often". ;) Sometimes, it does work just fine.