# Sounds bugging out when I try to play a lot of them

**URL:** <https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [December 12, 2018, 2:30am UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527 "2018-12-12T02:30:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haxorouse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/haxorouse/32/2776_2.png) [@Haxorouse](https://discourse.processing.org/u/Haxorouse)\
**Post date:** [December 12, 2018, 2:30am UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/1 "2018-12-12T02:30:49Z")

</div>

I have a project where I am trying to play a sound every time an enemy shoots at you, The only problem is that when too many sounds are played they all get super distorted and never actually stop playing, I will try to include the code but the whole game is several thousand lines so I have added a video showing it instead of the code because even when I shortened it as much as possible I was still almost 10,000 characters over the limit

[![]( " - YouTube") ](https://www.youtube.com/watch?v=3niKgJfg4Co)

here is the video link, the problem starts at about 1:07 if you want I can share some of the code

---

<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:** [December 15, 2018, 11:58pm UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/2 "2018-12-15T23:58:02Z")

</div>

Create a version of your code that deletes everything except the audio clip and the call to the sound, like this:

```auto
// import libraries
// global audio variables

void setup(){
  frameRate(4);
  // set up your audio object(s)
}
void draw(){
  myObject.playSound(); // just play your sound
}

```

This will start playing the sound file four times per second. It will help explore your problem and also show us what spefically.

Share that. Are you using a minim Sampler object? This is what they are for.

[http://code.compartmental.net/minim/sampler\_class\_sampler.html](http://code.compartmental.net/minim/sampler_class_sampler.html)

---

<div class="post-metadata">

**Author:** ![Haxorouse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/haxorouse/32/2776_2.png) [@Haxorouse](https://discourse.processing.org/u/Haxorouse)\
**Post date:** [December 17, 2018, 1:12am UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/3 "2018-12-17T01:12:39Z")

</div>

here I just put the whole project on github

> **[Haxorouse/Space-shooter-alpha](https://github.com/Haxorouse/Space-shooter-alpha/tree/master)**
>
> Contribute to Haxorouse/Space-shooter-alpha development by creating an account on GitHub.

---

<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:** [December 17, 2018, 5:16pm UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/4 "2018-12-17T17:16:47Z")

</div>

It looks like you aren’t using a minim Sampler object. I would recommend using a minim Sampler object. Multiple overlapping “voices” is what they are for.

---

<div class="post-metadata">

**Author:** ![Haxorouse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/haxorouse/32/2776_2.png) [@Haxorouse](https://discourse.processing.org/u/Haxorouse)\
**Post date:** [December 17, 2018, 5:49pm UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/5 "2018-12-17T17:49:10Z")

</div>

I couldn’t find the documentation for that, could you link it?

---

<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:** [December 17, 2018, 5:54pm UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/6 "2018-12-17T17:54:55Z")

</div>

I already included the link in my last post.

[http://code.compartmental.net/minim/sampler\_class\_sampler.html](http://code.compartmental.net/minim/sampler_class_sampler.html)

> Sampler is the UGen version of AudioSample and is the preferred method of triggering short audio files. You will also find Sampler much more flexible, since it provides ways to trigger only part of a sample, and to trigger a sample at different playback rates. Also, unlike AudioSample, a Sampler lets you specify how many voices (i.e. simultaneous playbacks of the sample) should have.

You could also use the older minim class AudioSample.

[http://code.compartmental.net/minim/audiosample\_class\_audiosample.html](http://code.compartmental.net/minim/audiosample_class_audiosample.html)

> An `AudioSample` keeps the entire file in an internal buffer and all you can do is `trigger()` the sound. However, you can trigger the sound even if it is still playing back. It is not advised that you use this class for long sounds (like entire songs, for example) because the entire file is kept in memory.

There is a demo sketch in the minim examples, PDE \> File \> Examples \> Contributed \> Minim \> Basics \> TriggerAsSample

---

<div class="post-metadata">

**Author:** ![Haxorouse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/haxorouse/32/2776_2.png) [@Haxorouse](https://discourse.processing.org/u/Haxorouse)\
**Post date:** [December 17, 2018, 5:55pm UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/7 "2018-12-17T17:55:25Z")

</div>

oh, sorry, Im in school and my brain is scattered right now

---

<div class="post-metadata">

**Author:** ![Haxorouse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/haxorouse/32/2776_2.png) [@Haxorouse](https://discourse.processing.org/u/Haxorouse)\
**Post date:** [December 17, 2018, 7:57pm UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/8 "2018-12-17T19:57:59Z")

</div>

ok, Ive done all that and now the sounds play without issue so thank you, but I now can’t figure out how to change the amplitude on the sound files with a variable that can be changed and stored as a volume setting, with different volumes for certain types of sounds eg, music, enemies, etc.

---

<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:** [December 17, 2018, 8:05pm UTC](https://discourse.processing.org/t/sounds-bugging-out-when-i-try-to-play-a-lot-of-them/6527/9 "2018-12-17T20:05:45Z")

</div>

It is in the documentation. If you are using a Sampler, then just use the sampler amplitude field.

[http://code.compartmental.net/minim/sampler\_field\_amplitude.html](http://code.compartmental.net/minim/sampler_field_amplitude.html)

> The amplitude of this Sampler. This acts as an overall volume control. So changing the amplitude will effect all currently active voices.

You can see all the available fields and methods of the Sampler on the left of its documentation page.
