Make particles synchronize with sound

edited April 20 in Library Questions

Hello there. I'm trying make the rain particles fall synchronized with the sound using the minim library, but I know nothing about this and I have no idea how to make this happen. If someone could explain me how to do it, it would be great. This is what I have right now. Thank you and sorry for the slightly dumb question!

import ddf.minim.*;

Minim minim;
AudioPlayer player;
int numero = 200; // how many rain drops on your screen??
Rain[] rains = new Rain[numero]; 

void setup()
  size(512, 200, P3D);
  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("sound.mp3");

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

void draw()
  for(int i=0 ; i<numero ; i=i+1){
  // 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(), 0, width );
    float x2 = map( i+1, 0, player.bufferSize(), 0, width );
   line( x1, 50 + player.left.get(i)*50, x2, 50 + player.left.get(i+1)*50 );
    line( x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50 );
class Rain {  //this class setups the shape and movement of raindrop.
 float x = random(0,600);
 float y = random(-1000,0);
 float size = random(3,7); // size of raindrop 
 float speed = random(20,80); // speed range
  void update() 
    y += speed; 
    ellipse(x, y-20, size, size*6); // tail of raindrop
    ellipse(x, y, size, size*6); //head of raindrop 

    if (y> height) //initialize raindrop which arrives bottom.
       x = random(0,600);
       y = random(-1200,0);



  • minim will either give you a number for each point on the waveform of a sound (lines 41 to 47) OR, using fft, a number representing the frequencies within that sound. so, hundreds of numbers or twenty(ish) numbers.

    it's up to you what you use those numbers for. you need to decide.

Sign In or Register to comment.