Sound gets distorted

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.

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

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

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

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.

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.


1 Like