// 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);
// apply damping
myFFT.damp(.1);
// start the sound looping forever
myChannel.play(Ess.FOREVER);
noStroke();
}
void draw() {
background(0,0,255);
// get our spectrum
myFFT.getSpectrum(myChannel);
// draw our frequency bars. first our base spectrum,
// then our shaped spectrum
for (int i=0; i<256; i++) {
fill(127,127,255);
float temp=max(0,185-myFFT.baseSpectrum[i]*512);
rect(i,temp+.5,1,height-temp+.5);
fill(255);
temp=max(0,185-myFFT.spectrum[i]*512);
rect(i,temp+.5,1,height-temp+.5);
}
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
|