This is just a quick write-up of the steps necessary to write frequency-reactive stuff with Processing.
In your sketch, import the Ess library. It's available by default.
Declare AudioChannel and FFT instances like this.
AudioChannel chan; // Audio channel FFT fft; int bands = 64; // Number of FFT bands float bass = 0; // Amount of bass
Load the channel with some audio. This might for example be done in the init() method of your sketch. The file has to be added to the "data" directory of your sketch.
void init() {
Ess.start(this);
chan = new AudioChannel("myfile.wav");
chan.play(Ess.FOREVER);
// The FFT constructor takes the number of
// frequency bins, not bands.
fft = new FFT(bands * 2);
}
And in your draw method, do something like this:
void draw() {
fft.getSpectrum(chan);
bass = max(bass, fft.spectrum[0]);
// Do stuff with the bass
// Let the bass amount decay smoothly
bass *= 0.98;
}
Leave a comment