Skip to content

Instantly share code, notes, and snippets.

@thislooksfun
Created January 28, 2015 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thislooksfun/7191083428dab2de6799 to your computer and use it in GitHub Desktop.
Save thislooksfun/7191083428dab2de6799 to your computer and use it in GitHub Desktop.
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput in;
FFT fft;
int highest=0;
void setup()
{
size(300, 200, P2D);
if (frame != null)
frame.setResizable(true);
minim = new Minim(this);
minim.debugOn();
//in = minim.getLineIn(Minim.MONO, 4096, 44100);
in = minim.getLineIn(Minim.MONO, 2048, 44100);
fft = new FFT(in.mix.size(), 44100);
}
void draw()
{
background(0, 0, 0);
stroke(100, 0, 0);
fft.forward(in.mix);
highest=0;
for (int n = 0; n < fft.specSize(); n++) {
// draw the line for frequency band n, scaling it by 4 so we can see it a bit better
line(n/4, height, n/4, height - (fft.getBand(n)/log(n)));
//find frequency with highest amplitude
if (fft.getBand(n)>fft.getBand(highest))
highest=n;
}
//println(highest);
//println(fft.getFreq(110));
// draw the waveforms
/*for (int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}*/
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment