Basic FFT with Processing

| | Comments (0) | TrackBacks (0)

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;
}

0 TrackBacks

Listed below are links to blogs that reference this entry: Basic FFT with Processing.

TrackBack URL for this entry: http://words.alchre.org/cgi-bin/mt/mt-tb.cgi/5

Leave a comment

About me

I'm an undergrad CS student and part time consultant with an interest in software development, algorithms and other geeky stuff.

About this Entry

This page contains a single entry by Henrik published on November 29, 2007 2:46 PM.

Graphviz is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.