I am currently trying to get into the sound library and especially fft analysis. I want to print the number of the band with the highest amplitude in the console for each draw loop. I used the following code but it is only returning 0.0 and 1.0:
import processing.sound.*;
FFT fft;
SoundFile sound;
int bands = 512;
float[] spectrum = new float[bands];
float max = 0;
void setup(){
sound = new SoundFile(this, "demo_II.mp3");
sound.loop();
fft = new FFT(this, bands);
fft.input(sound);
}
void draw(){
fft.analyze(spectrum);
max = 0;
for(int i = 0; i < bands; i++){
//println(i); // <- returning the correct value of i
if(spectrum[i] > max){
max = float(i);
}
}
println(max);
}