Created
January 28, 2015 18:54
-
-
Save thislooksfun/7191083428dab2de6799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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