How can AudioIn control Gravity/Speed?

edited December 2014 in How To...

Hello,

I am three or 4 weeks in to processing at a university and am trying to collect data through the input of sound.

My goal is to have the AudioIn ( to the mac desktop) control the gravity and speed at which the objects falls. Once the volume that controls the rate of gravity reaches a certain volume (50%) pdf is saved with visual data of time.

this is my code so far, (I know I am only beginning) and am completely lost on how to connect the two dots together. Any help would be greatly appreciated.

Thank you.

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

// Declare 1 minim Class Object
Minim son ;

// Declare an audio entry
AudioInput entree ;


Ball r1;

int numballs = 40;
Ball[] drops = new Ball[10]; // Declare and create the array

float speed = 0;   // speed of square
float gravity = 0.1;

void setup() {
  size(1280,720);


  // Initialize the main sound object
  son = new Minim (this) ;

  // Initialize the audio input
 entree = son.getLineIn (Minim.MONO, 64) ;

  smooth();
  noStroke();
  //Loop through array to create each object
  for (int i = 0; i < drops.length; i++) {

    drops[i] = new Ball(); // Create each object
    r1 = new Ball();
  }
}

void draw(){
  background(255);
  fill(255,100);

  // getting the sound value and applying it to the gravity
  // variable
  gravity = entree.left.get(1);
  // println (gravity) ;

  speed = speed + gravity;

  //Loop through array to use objects.
  for (int i = 0; i < drops.length; i++) {
    drops[i].fall();

  }

}

class Ball {
  float r = random(1280);
  float y = random(-height);

  void fall() {
    y = y + speed;
    fill(255,0,0,500);
    ellipse(r, y, 10, 10);

   if(y > height){

   speed = speed * -0.95; 
   }

  }
}

void stop() {
entree.close() ;
son.stop() ; 
super.stop() ;


}
Sign In or Register to comment.