Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ddf.minim.*;
- import ddf.minim.analysis.*;
- AudioInput in;
- FFT fft;
- BeatDetect beat;
- int rep;
- void setup()
- {
- size(800, 600);
- background(0);
- // always start Minim before you do anything with it
- Minim.start(this);
- rep = 0; //repetitions
- // get a line out from Minim, default bit depth is 16
- beat = new BeatDetect();
- in = Minim.getLineIn(Minim.MONO, 512, 11050);
- fft = new FFT(in.bufferSize(), in.sampleRate());
- }
- void draw()
- {
- beat.detect(in.left);
- stroke(255);
- // draw the waveforms
- if(rep > 1000)
- {
- background(0);
- rep = 0;
- }
- int bwidth = 20;
- if(beat.isOnset())
- {
- fill(0);
- stroke(0);
- for(int j = 0; j < width / 20; j++)
- {
- rect(j * bwidth, 0, 10, height);
- }
- }
- //TODO: sustain after beats.
- if(in.left.level() > 0.07)
- {
- for(int i = 0; i < in.bufferSize() - 1; i++)
- {
- stroke(255 - abs(0.05 + in.left.get(i))*20000, 0, abs(0.05 + in.left.get(i))*20000);
- //line(i*1.5, 100 + in.left.get(i)*200, (i*1.5)+1, 100 + in.left.get(i+1)*200);
- strokeWeight(in.left.level() * 40);
- point(i*1.5, (rep/60) + ((rep % 60) * 10) + in.left.get(i)*200);
- }
- }
- stroke(255);
- rep++;
- smooth();
- }
- void stop()
- {
- // always close Minim audio classes when you are done with them
- in.close();
- // always stop Minim before exiting
- Minim.stop();
- super.stop();
- }
Add Comment
Please, Sign In to add comment