Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Minim Question: Is there a possibility to sync multiple mp3s?

$
0
0

Hello there, newbie here.

I made a sketch which plays 9 mp3 files simultaneously using Minim. Those 9 files represent a whole track split into its individual instruments. My problem is that the files are not being triggered at the exact same time and therefore don't play in sync. Is there a way to preload the files in advance so processing can trigger them at the exact same time, or is there anything else i could do?

Thanks in advance! :)

import ddf.minim.*;
Minim minim;
AudioPlayer player;
AudioPlayer player2;
AudioPlayer player3;
AudioPlayer player4;
AudioPlayer player5;
AudioPlayer player6;
AudioPlayer player7;
AudioPlayer player8;
AudioPlayer player9;

void setup()
{
  size(1128, 575, P2D);
  minim = new Minim(this);
  player = minim.loadFile("track1.mp3");
  player2 = minim.loadFile("track2.mp3");
  player3 = minim.loadFile("track3.mp3");
  player4 = minim.loadFile("track4.mp3");
  player5 = minim.loadFile("track5.mp3");
  player6 = minim.loadFile("track6.mp3");
  player7 = minim.loadFile("track7.mp3");
  player8 = minim.loadFile("track8.mp3");
  player9 = minim.loadFile("track9.mp3");
}

void draw()
{
  background(240);
  stroke(150, 100, 40);

  //WAVEFORMS
  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, 75 + player.left.get(i)*50, x2, 75 + player.left.get(i+1)*50 );
    line( x1, 100 + player.right.get(i)*50, x2, 75 + player.right.get(i+1)*50 );
  }

  stroke(20, 150, 90);

  for (int i = 0; i < player2.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player2.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player2.bufferSize(), 0, width);
    line( x1, 125 + player2.left.get(i)*50, x2, 125 + player2.left.get(i+1)*50 );
    line( x1, 150 + player2.right.get(i)*50, x2, 125 + player2.right.get(i+1)*50 );
  }

  stroke(0, 70, 130);

  for (int i = 0; i < player3.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player3.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player3.bufferSize(), 0, width );
    line( x1, 175 + player3.left.get(i)*50, x2, 175 + player3.left.get(i+1)*50 );
    line( x1, 200 + player3.right.get(i)*50, x2, 175 + player3.right.get(i+1)*50 );
  }

  stroke(80, 70, 130);

  for (int i = 0; i < player4.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player4.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player4.bufferSize(), 0, width );
    line( x1, 225 + player4.left.get(i)*50, x2, 225 + player4.left.get(i+1)*50 );
    line( x1, 250 + player4.right.get(i)*50, x2, 225 + player4.right.get(i+1)*50 );
  }

  stroke(#9CC6A1);

  for (int i = 0; i < player5.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player5.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player5.bufferSize(), 0, width );
    line( x1, 275 + player5.left.get(i)*50, x2, 275 + player5.left.get(i+1)*50 );
    line( x1, 300 + player5.right.get(i)*50, x2, 275 + player5.right.get(i+1)*50 );
  }


  stroke(#FA8A56);

  for (int i = 0; i < player6.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player6.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player6.bufferSize(), 0, width );
    line( x1, 325 + player6.left.get(i)*50, x2, 325 + player6.left.get(i+1)*50 );
    line( x1, 350 + player6.right.get(i)*50, x2, 325 + player6.right.get(i+1)*50 );
  }

  stroke(#1ACFFF);

  for (int i = 0; i < player7.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player7.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player7.bufferSize(), 0, width );
    line( x1, 375 + player7.left.get(i)*50, x2, 375 + player7.left.get(i+1)*50 );
    line( x1, 400 + player7.right.get(i)*50, x2, 375 + player7.right.get(i+1)*50 );
  }

  stroke(#D567DE);

  for (int i = 0; i < player8.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player8.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player8.bufferSize(), 0, width );
    line( x1, 425 + player8.left.get(i)*50, x2, 425 + player8.left.get(i+1)*50 );
    line( x1, 450 + player8.right.get(i)*50, x2, 425 + player8.right.get(i+1)*50 );
  }

  stroke(#5A555A);

  for (int i = 0; i < player9.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player9.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player9.bufferSize(), 0, width );
    line( x1, 475 + player9.left.get(i)*50, x2, 475 + player9.left.get(i+1)*50 );
    line( x1, 500 + player9.right.get(i)*50, x2, 475 + player9.right.get(i+1)*50 );
  }
}

void keyPressed()
{

    player.rewind();
    player.play();
    player2.rewind();
    player2.play();
    player3.rewind();
    player3.play();
    player4.rewind();
    player4.play();
    player5.rewind();
    player5.play();
    player6.rewind();
    player6.play();
    player7.rewind();
    player7.play();
    player8.rewind();
    player8.play();
    player9.rewind();
    player9.play();
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles