Processing Sound Library Distorted

So I am trying to run a basic game using this library to play gunshot sounds. It works great, up until a couple hundred shots when out of no where the audio will get distorted and never end. When this is happening the audio from any other objects no longer functions and I get stuck in random glitch sounds for the rest of the game. Is this something I can fix or is this because of the library?

In case you’re curious the code I made is here (I know it’s not well programmed I am just learning):

1 Like

this happens when you play too many ( same or different ) “songs”
at the same time,
so i suspect that your check on .isPlaying() is missing??

like here?

      if (randomNum == 0)
        bulletImpact.play();
      else if (randomNum == 1)
        bulletImpactTwo.play();

if the “song” is to long, cut it,
and use .loop() instead .play(),
but faster for play one is not possible,
can check how many times you start the .play() ?
with put in a

  println(counter++); 
1 Like

I would recommend switching to minim library and using either AudioSample (up to 20 simultaneous overlapping voices)

http://code.compartmental.net/minim/audiosample_class_audiosample.html

or Sampler (customize your number of simultaneous voices)

http://code.compartmental.net/minim/sampler_class_sampler.html

For short sound effect playbacks that happen many times and may happen simultaneously, these classes are specifically designed for what you are trying to do.

1 Like

Hey, I never actually got around to testing this until just now but it worked great. Thanks for the advice!