Synchronizing sound

edited June 2017 in Library Questions

Hey there, could someone please tell how do I make these falling ellipses synchronize with the audio clip? Like when the sound is louder, there are more ellipses.. I'm new to the minim library so I have no idea, thank you!!

import ddf.minim.*;

Minim minim;
AudioPlayer player;
int numero = 1000; // gotas de chuva
Rain[] rains = new Rain[numero]; 

void setup()
{
  size(1280, 720);
  frameRate(40);
  noStroke();
  for(int i=0; i<numero ;i=i+1){
     rains[i]=new Rain(); 
  }
  // we pass this to Minim so that it can load files from the data directory
  minim = new Minim(this);

  // loadFile will look in all the same places as loadImage does.
  // this means you can find files that are in the data folder and the 
  // sketch folder. you can also pass an absolute path, or a URL.
  player = minim.loadFile("rain.mp3");

  // play the file from start to finish.
  // if you want to play the file again, 
  // you need to call rewind() first.
  player.play();
}

void draw()
{
  background(147,147,147);
 stroke(255);
  for(int i=0 ; i<numero ; i=i+1){
    rains[i].update();
    }
  // draw the waveforms
  // the values returned by left.get() and right.get() will be between -1 and 1,
  // so we need to scale them up to see the waveform
  // note that if the file is MONO, left.get() and right.get() will return the same value
  for(int i = 0; i < player.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player.bufferSize(), 30, width );
    float x2 = map( i+1, 0, player.bufferSize(), 0, width );

  }
}

class Rain {  
 float x = random(0,1280);
 float y = random(0,1280);
 float size = 1; // size of raindrop 
 float speed = random(5,30); // speed range
  void update() 
  { 
    y += speed; 
    fill(185,197,209);
    ellipse(x, y-20, size, size*6); // rasto
    fill(255-(100-speed));
    ellipse(x, y, size, size*6); //inicio 

    if (y> height) 
       x = random(0,1280);
       y = random(0,1280);
     } 


}
Tagged:

Answers

Sign In or Register to comment.