Skip to content

Instantly share code, notes, and snippets.

@bdaver
Created April 15, 2013 11:26
Show Gist options
  • Save bdaver/5387438 to your computer and use it in GitHub Desktop.
Save bdaver/5387438 to your computer and use it in GitHub Desktop.
Cleaned up version of minim spectrum analyze example using averages
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer jingle;
FFT fftLin;
float height3;
float height23;
float spectrumScale = 4;
PFont font;
void setup() {
size(512, 480);
height3 = height/3;
height23 = 2*height/3;
minim = new Minim(this);
jingle = minim.loadFile("jingle.mp3", 1024);
jingle.loop();
fftLin = new FFT( jingle.bufferSize(), jingle.sampleRate() );
// calculate the averages by grouping frequency bands linearly. use 30 averages.
fftLin.linAverages( 30 );
rectMode(CORNERS);
font = loadFont("ArialMT-12.vlw");
}
void draw() {
background(0);
textFont(font);
textSize( 18 );
float centerFrequency = 0;
fftLin.forward( jingle.mix );
noStroke();
int w = int( width/fftLin.avgSize() );
for (int i = 0; i < fftLin.avgSize(); i++)
{
fill(255);
// draw a rectangle for each average, multiply the value by spectrumScale so we can see it better
rect(i*w, height23, i*w + w, height23 - fftLin.getAvg(i)*spectrumScale);
//rect(x,y,w,h);
}
// ------------------
// eg KICKS
float kickVal = fftLin.getAvg(0)*30;
if( kickVal > 128) {
fill(255,0,0);
println("KICK!");
} else {
fill(255);
}
ellipse(width/2, 200, kickVal,kickVal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment