# Processing Sound Library Distorted

**URL:** <https://discourse.processing.org/t/processing-sound-library-distorted/9982>\
**Category:** Libraries\
**Created:** [April 5, 2019, 3:15am UTC](https://discourse.processing.org/t/processing-sound-library-distorted/9982 "2019-04-05T03:15:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordBruce](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@LordBruce](https://discourse.processing.org/u/LordBruce)\
**Post date:** [April 5, 2019, 3:15am UTC](https://discourse.processing.org/t/processing-sound-library-distorted/9982/1 "2019-04-05T03:15:32Z")

</div>

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):

> **[BryceTheGrand/Two-Player-Car-Game](https://github.com/BryceTheGrand/Two-Player-Car-Game)**
>
> small processing game. Contribute to BryceTheGrand/Two-Player-Car-Game development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 5, 2019, 9:56am UTC](https://discourse.processing.org/t/processing-sound-library-distorted/9982/2 "2019-04-05T09:56:49Z")

</div>

> [@LordBruce](#):
>
> up until a couple hundred shots when out of no where the audio will get distorted and never end.

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?

```auto
      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

```auto
  println(counter++); 

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 7, 2019, 4:26pm UTC](https://discourse.processing.org/t/processing-sound-library-distorted/9982/3 "2019-04-07T16:26:31Z")

</div>

> [@LordBruce](#):
>
> using this library to play gunshot sounds.

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](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](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.

---

<div class="post-metadata">

**Author:** ![LordBruce](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@LordBruce](https://discourse.processing.org/u/LordBruce)\
**Post date:** [April 9, 2019, 12:36am UTC](https://discourse.processing.org/t/processing-sound-library-distorted/9982/4 "2019-04-09T00:36:30Z")

</div>

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