Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement