// Example by Krister Olsson
import krister.Ess.*;
AudioChannel myChannel;
FFT myFFT;
void setup() {
size(256,200);
// start up Ess
Ess.start(this);
// load "cell.aif" into a new AudioChannel
myChannel=new AudioChannel("cell.aif");
// we want 256 frequency bands, so we pass 512
myFFT=new FFT(512);
// normalize our spectrum data
myFFT.limits();
// start the sound looping forever
myChannel.play(Ess.FOREVER);
noStroke();
}
void draw() {
background(0,0,255);
// get our spectrum
myFFT.getSpectrum(myChannel);
// draw the value used to normalize our spectrum. .005 is
// the default minimum limit, .05 is the default max limit
fill(127,127,255);
float percent=185-max(0,(myFFT.max-.005)/(.05-.005))*185;
rect(0,percent+.5,256,height-percent+.5);
// draw our frequency bars
for (int i=0; i<256; i++) {
fill(255);
float temp=max(0,185-myFFT.spectrum[i]*185);
rect(i,temp+.5,1,height-temp+.5);
}
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
|