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

Play single audio file multiple times

$
0
0

I am trying to make a particle attractor with processing where some particles are moving randomly and they get attracted towards a master attarctor when they come close to it. Doing this was fairly easy and I have completed the code. The problem is with the minim sound play part where I need to play a sound file when the particles hit the master attractor. I am using only one audio file which needs to play whenever the particle hits the master attractor.

The problem is that when a particle hits the master attractor it plays the sound but as soon as another particle hits the sound it reset the sound and sound doesn't play properly.

when I do this processing plays multiple instance and it doesn't sound good.

  if (P.loc.dist(M.loc)<50) {
      stroke(0, 50);
      line(P.loc.x, P.loc.y, M.loc.x, M.loc.y);
        player.pause();
        player.rewind();
        player.play();
    }

When I do this the whole processing sketch gets slowed down

   if (P.loc.dist(M.loc)<50) {
      stroke(0, 50);
      line(P.loc.x, P.loc.y, M.loc.x, M.loc.y);
       player = minim.loadFile("1.MP3", 2048);
        player.pause();
    }

And when I do this the sound plays only few times because it waits until the previous instance gets finished.

  if (P.loc.dist(M.loc)<50) {
      stroke(0, 50);
      line(P.loc.x, P.loc.y, M.loc.x, M.loc.y);
      if (!player.isPlaying()) {
        player.pause();
        player.rewind();
        player.play();
      }
    }

Viewing all articles
Browse latest Browse all 2896

Trending Articles