# Sound gets distorted

**URL:** https://forum.code.org/t/sound-gets-distorted/38368
**Category:** CS Discoveries
**Tags:** gamelab
**Created:** [September 13, 2023, 1:43am UTC](https://forum.code.org/t/sound-gets-distorted/38368 "2023-09-13T01:43:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![azurirou](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/azurirou/32/8803_2.png) [@azurirou](https://forum.code.org/u/azurirou)
#### Post date: [September 13, 2023, 1:43am UTC](https://forum.code.org/t/sound-gets-distorted/38368/1 "2023-09-13T01:43:44Z")

</div>

No matter how short or small the audio file is, unless it’s above the draw function, it distorts and gets loud to the point I threw my headphones off the first time it happened to me.

---

<div class="post-metadata">

### Author: ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)
#### Post date: [September 13, 2023, 2:21am UTC](https://forum.code.org/t/sound-gets-distorted/38368/2 "2023-09-13T02:21:49Z")

</div>

if you have used a loop before you’d understand why that is the case  
the `draw` function by default runs about 33 times every second thus playing the sound over and over until the sound buffer gets exceeded and then distorts to simply not have it do this run a boolean check

```js
var hasPlayed = false;
function draw() {
 if(!hasPlayed) {
  playSound("sound.mp3", false);
  hasPlayed = true;
 }
}
```

---

<div class="post-metadata">

### Author: ![azurirou](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/azurirou/32/8803_2.png) [@azurirou](https://forum.code.org/u/azurirou)
#### Post date: [September 13, 2023, 3:10am UTC](https://forum.code.org/t/sound-gets-distorted/38368/3 "2023-09-13T03:10:55Z")

</div>

thanks! i guess I was just doing this whole boolean thing wrong

---

<div class="post-metadata">

### Author: ![sam\_stafford](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/sam_stafford/32/7651_2.png) [@sam\_stafford](https://forum.code.org/u/sam_stafford)
#### Post date: [September 13, 2023, 8:26pm UTC](https://forum.code.org/t/sound-gets-distorted/38368/4 "2023-09-13T20:26:07Z")

</div>

Hi @azurirou, I reorganized this post to be under CS Discoveries since Gamelab is used in that curriculum. Thank you for posting this question to the forum. If you have any more questions please don’t hesitate to reach out.  
-Sam

---

<div class="post-metadata">

### Author: ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)
#### Post date: [September 13, 2023, 9:33pm UTC](https://forum.code.org/t/sound-gets-distorted/38368/5 "2023-09-13T21:33:16Z")

</div>

Sometimes, you can also put a “stop sound” block/command before the play one (if it is a short sound) and I’ve found that works well, but it is situation dependent.

Mike
