Look for minim, a core library that deals with sound. You will use it to measure the sound, and than adapt it to replace mouse in the code above. There are a lot of examples, either built in Processing and in the forum. I remember a recent one making ellipses as the sound increase, let me see... well can't find it in the forum, but i happen to have copied the code, so here it is. Is not my code but is available in the forum anyway... It should get you started. Ask here if you need more help. Good luck.
code copied from forum:
- import ddf.minim.*;
- Minim minim;
- AudioInput in;
- int reactLast;
- int reactBetween = 100;
- float soundIntensity = 1;
- ArrayList <Circle> circles = new ArrayList <Circle> ();
- void setup() {
- size(600, 600);
- strokeWeight(3);
- smooth();
- noFill();
- minim = new Minim(this);
- in = minim.getLineIn(Minim.MONO, 64);
- }
- void draw() {
- background(0);
- float sound = 0;
- for (int i=0; i<in.bufferSize()-1; i++) {
- sound += in.left.get(i);
- }
- if (abs(sound)>soundIntensity&&millis()-reactLast>reactBetween) {
- reactLast = millis();
- circles.add( new Circle( new PVector(width/2,height/2),255));
- }
- for (int i=circles.size()-1; i>=0; i--) {
- Circle c = circles.get(i);
- c.run();
- }
- }
- class Circle {
- PVector pos;
- color c;
- int age;
- Circle(PVector _pos, color _c) {
- pos = _pos;
- c = _c;
- }
- void run() {
- stroke(c, max(0, 255-age*0.25));
- ellipse(pos.x, pos.y, age*1.5, age*1.5);
- age += 3;
- if (age>600) {
- circles.remove(this);
- }
- }
- }
- void stop() {
- in.close();
- minim.stop();
- super.stop();
- }