# Sound Effects Deteriorate Issue

**URL:** <https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148>\
**Category:** Phaser 3\
**Created:** [August 10, 2020, 5:08am UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148 "2020-08-10T05:08:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [August 10, 2020, 5:08am UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/1 "2020-08-10T05:08:46Z")

</div>

Hello,

My game has an issue where the quality of the sound effects start out good, then deteriorate as the level goes on. Here is a very short video demonstrating the issue: [https://www.youtube.com/watch?v=zdnmOriUJ0Y](https://www.youtube.com/watch?v=zdnmOriUJ0Y)

I am loading and playing the sounds as instructed in the phaser docs.

In preload:  
`this.load.audio('whoosh1', "assets/sound_effects/whoosh1.mp3")`  
` this.load.audio('whoosh2', "assets/sound_effects/whoosh2.mp3")`  
` this.load.audio('whoosh3', "assets/sound_effects/whoosh3.mp3")`

In the player class constructor:  
`this.whoosh1 = scene.sound.add('whoosh1')`  
`this.whoosh2 = scene.sound.add('whoosh2')`  
`this.whoosh3 = scene.sound.add('whoosh3')`  
`this.whooshes = [this.whoosh1, this.whoosh2, this.whoosh3]`

The sound effects are played from my throw method:  
`throw(){`  
`this.weapon = new Weapon(this.scene) // object thrown`  
`var whoosh_num = Math.floor(Math.random() * this.whooshes.length)`  
`this.whooshes[whoosh_num].play();`  
`}`

And the throw method is being called in my player finite state machine (inside the update method):

```
if(this.player.state=='stand_right'){
  this.player.setVelocityX(0);
  this.player.anims.play('stand_right',true);
  if(!this.player.body.touching.down && !this.player.body.onFloor()){
    this.player.state = 'jump_right'}
  else if(Phaser.Input.Keyboard.JustDown(this.key_jump)){
    this.player.setVelocityY(-750);
    this.jump_sound.play()
    this.player.state = 'jump_right';}
  else if(this.key_right.isDown){
    this.player.state = 'run_right'}
  else if(this.key_left.isDown){
    this.player.state = 'run_left'}
  else if(Phaser.Input.Keyboard.JustDown(this.key_throw)){
    this.scene.time_at_throw_start = Math.trunc(this.scene.time.now)
    this.player.state='stand_right_and_throw'
    this.throw()}
  else if(this.key_down.isDown){
    this.player.state = 'duck_right'}
}

```

The frame rate does not decrease, it stays at 60 fps even as the sound quality gets worse.

Any idea what might be causing this? I’ve searched Google for days and haven’t found a single instance of someone having a similar issue.

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [August 10, 2020, 9:26am UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/2 "2020-08-10T09:26:14Z")

</div>

Hi,  
First thing, throw is a reserved word in js  
[https://www.w3schools.com/js/js\_reserved.asp](https://www.w3schools.com/js/js_reserved.asp)

Secondly, when you play a sound from update, update can call throw multiple times, you use JustDown so it must not happens, but check it so you are sure.

No error message in dev tools?

---

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [August 10, 2020, 4:08pm UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/3 "2020-08-10T16:08:27Z")

</div>

I have changed the method name to throwWeapon(), it has the same behavior.

I am sure it is only being called once because I have a log statement before the throw, and it shows up in the console once per throw.

There is no error message in dev tools.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 10, 2020, 10:36pm UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/4 "2020-08-10T22:36:30Z")

</div>

I would first try to print which sounds are playing in the manager, e.g., in `update()`.

---

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [August 12, 2020, 5:30am UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/5 "2020-08-12T05:30:25Z")

</div>

Upon printing the sound and looking under manager -\> sounds, I see that it does have a large array of sounds in there. It starts out with about 20-25 (first throw) and after about 1 minute of throwing this number is up to 1500, what does this mean? Is it actually playing 1500 sounds at once at that point?

 ![multiple_sounds](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/8/81f8fd0009e398879c8702077ba93f3ca2684baf.png)

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 12, 2020, 2:52pm UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/6 "2020-08-12T14:52:13Z")

</div>

They’re probably not all playing but it’s still too many.

Can you log each `sound.add()`?

---

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [August 13, 2020, 3:44am UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/7 "2020-08-13T03:44:22Z")

</div>

That is what I was logging to see the above object in my image. The problem appears to go away when I clear that array (` sound_name.manager.sounds = []`) before playing the sound. Is it ok to do this?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 13, 2020, 3:14pm UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/8 "2020-08-13T15:14:47Z")

</div>

I think you’ll want to prevent the problem if possible. 🙂

From the code shown there should be only 3 sounds in the manager, ever.

Add something like

```javascript
console.log('add whoosh1');
this.whoosh1 = scene.sound.add('whoosh1');
// …

```

everywhere you use `sound.add()`.

---

<div class="post-metadata">

**Author:** ![t\_rev44](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/t_rev44/32/4157_2.png) [@t\_rev44](https://phaser.discourse.group/u/t_rev44)\
**Post date:** [August 15, 2020, 5:01pm UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/9 "2020-08-15T17:01:00Z")

</div>

I am loading a lot of sounds I didn’t tell you about, and I was adding them to the scene in the constructor of the player’s projectile. That was why there were so many in the manager after throwing for a while. I moved the sound.add() statements to the player’s constructor and the issue is resolved. Thanks samme 🙂

---

<div class="post-metadata">

**Author:** ![Dov](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dov/32/1959_2.png) [@Dov](https://phaser.discourse.group/u/Dov)\
**Post date:** [April 15, 2021, 11:21pm UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/10 "2021-04-15T23:21:07Z")

</div>

@samme thanks for this answer.

I am also experiencing sound deterioration over the course of my game, but the sound manager has only grown from 19 to 270 sounds after 15 minutes. Is this likely to be the source of my deterioration?  
(It becomes noticeable when that count is about 180, but as they say correlation does not prove causation)

---

<div class="post-metadata">

**Author:** ![Dov](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dov/32/1959_2.png) [@Dov](https://phaser.discourse.group/u/Dov)\
**Post date:** [April 16, 2021, 2:08am UTC](https://phaser.discourse.group/t/sound-effects-deteriorate-issue/7148/11 "2021-04-16T02:08:30Z")

</div>

SOLVED  
The 270 sounds in the manager certainly did degrade the sound playback…  
I found it useful to **purge** the sound manager as each scene wakes.  
My sound count went up and down, but never exceeded 50.  
The deterioration is ended and the sounds everywhere are brilliant!  
Holy cow , the music (by Noah Jacobson-Carroll) sounds spectacular and subtle!!

`this.sound.removeAll()` ought to be the right method, but it was not found at runtime.(??!)  
So I used dumb brute force -

> ```
> if( this?.sound?.sounds?.length ) 
> this.sound.sounds.forEach( s=> this.sound.remove(s) );
> 
> ```
