Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Created December 2, 2014 00:33
Show Gist options
  • Save gregtemp/73ea1869f3cfb681194c to your computer and use it in GitHub Desktop.
Save gregtemp/73ea1869f3cfb681194c to your computer and use it in GitHub Desktop.
Stereo Spectrogram
// Stereo Spectrogram //
// - gregtemp - //
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
FFT fftL;
FFT fftR;
int buffSize = 512;
void setup()
{
size(1030, 580);
frameRate(24);
minim = new Minim(this);
player = minim.loadFile("sound.mp3");
player.play();
fftL = new FFT(player.bufferSize(), player.sampleRate());
fftL.window(FFT.HAMMING);
fftR = new FFT(player.bufferSize(), player.sampleRate());
fftR.window(FFT.HAMMING);
background(0);
strokeWeight(1);
noFill();
}
void draw() {
//fft.forward(player.mix);
fftL.forward(player.left);
fftR.forward(player.right);
copy(0, 4, width, height, 0, 0, width, height);
strokeWeight(1);
for (int i = 0; i < buffSize; i++) {
int j = 0;
if (i > 300) {
j = i - 300;
}
stroke(100 * (log(100 * fftL.getBand(i)) / log(10)) - j);
point((width/2) + (i), height);
stroke(100 * (log(100 * fftR.getBand(i)) / log(10)) - j);
point((width/2) - (i), height);
}
println(frameRate);
}
void stop()
{
// always close Minim audio classes when you finish with them
player.close();
minim.stop();
super.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment