/**
HalfOctaveVUDemo.pde
Dave Bollinger Mar 2007
http://www.davebollinger.com
Demonstration of log-sized averaging bins for FFT analysis.
Note how strongly you can distinguish the kick (bands 1&2)
from the snare (bands 7&8) from the hihat (bands 15&16) in
this snippet from the intro of Cameo's "Word Up".
('fair use' ought to cover using this one bar as demonstration material)
That would not be the case with a similar number of averaging
bins if allocated linearly across the full spectrum - instead
what you'd find is that both kick and snare probably fall into
the same bin, or at least have a great deal of crosstalk.
*/
import krister.Ess.*;
String audioFilename = "cameo_wordup_snippet.aif";
AudioChannel chn;
FFT fft;
FFTOctaveAnalyzer oct;
int bufferSize = 1024;
int samplingRate = 44100;
void setup() {
// init p5
size(320,240);
frameRate(30);
noStroke();
// init ess
Ess.start(this);
// init audio channel (should be using stream+file, but this hack is simpler and mostly works)
chn = new AudioChannel(audioFilename, samplingRate);
chn.play(Ess.FOREVER);
// init fft
fft = new FFT(bufferSize*2);
fft.limits();
fft.damp(0.5f);
// init averages
oct = new FFTOctaveAnalyzer(fft, samplingRate, 2);
// common things you might want to "tweak" (see code for further comments)
oct.peakHoldTime = 15; // hold longer
oct.peakDecayRate = 0.95f; // decay slower
oct.linearEQIntercept = 0.9f; // reduced gain at lowest frequency
oct.linearEQSlope = 0.01f; // increasing gain at higher frequencies
}
void draw() {
// update the fft and averages
fft.getSpectrum(chn);
oct.calculate();
// figure out screen size stuff
float margin = 16f;
float xspan = floor((width - margin * 2f) / (float)(oct.nAverages));
float yspan = height - margin * 2f;
// draw all bands:
background(0);
for (int i=0; i 0)
fill(color(64,128,192)); // peak color
else
fill(color(48,96,144)); // decay color
rect(x1, y2, xspan-1, -2);
}
}
public void stop() {
Ess.stop();
super.stop();
}