Browser Gaming

How Browser Game Sound Works

Illustration of a waveform rising from a game canvas

None of the sounds in these games were recorded. They are generated by the browser at the moment they play, from a description of a waveform - which means no audio files are downloaded and the whole sound design of a game costs a few kilobytes of code.

Synthesis instead of files

The Web Audio API lets a page create an oscillator - a tone generator - connect it to a volume control, and start it. A jump sound is a square wave sliding from about 330Hz to 620Hz over a tenth of a second, with the volume rising sharply and falling away. That description is the entire sound.

Assembling effects this way is a matter of choosing a waveform, a pitch movement and a volume envelope.

EffectWaveformPitchLength
JumpSquareRising~0.11s
CoinSquareTwo quick rising notes~0.15s total
CollisionSawtooth plus noiseFalling sharply~0.24s
Power-upTriangleRising, longer~0.18s
Level completeTriangleFour ascending notes~0.6s

Noise - the rushing sound in a collision - is made by filling a buffer with random values that fade out. It is a few lines of code and it is what gives an impact its weight.

Why the volume envelope matters most

A tone that starts and stops abruptly produces an audible click, because the waveform jumps discontinuously. The fix is to ramp the volume up over a few milliseconds and down over the remainder of the sound.

That envelope also carries most of the character. A fast rise and a quick fall reads as a click or a hit. A slower rise reads as something swelling. The same oscillator with two different envelopes produces two sounds that seem unrelated.

Why audio cannot start immediately

Browsers refuse to let a page produce sound until the user has interacted with it. This is a deliberate protection against pages that blare at you the moment they load, and it applies to every site equally.

In practice it means a game creates its audio system on your first click, key press or tap rather than when the page loads. If you start a game with the keyboard, the first sound may be very slightly late while the audio context starts up. There is no way around it and it is a rule worth having.

Why sound helps you play better

This is not a claim about audio being pleasant. It is about information channels.

  • Audio does not compete for your eyes. Your visual attention is already fully occupied by the play area. A sound adds information without taking any away.
  • Audio cues register slightly faster. A sound confirms an outcome a fraction sooner than a visual change, which matters when windows are short.
  • Some information is only in the audio. In Cat Chase the dog's bark gets more frequent as it closes, so you register trouble before consciously checking the gauge.
  • In one game it is nearly essential. Cat Paw Pattern gives each pad its own pitch, so the sequence arrives as a melody. Melodies are held far better than lists of positions, and most players gain several rounds with sound on.

The sound toggle

Every game here has a sound toggle in the controls above the canvas, and the preference is saved in your browser so it applies to every game and every visit. If you play muted by default, that is respected without you having to set it each time.

Two things commonly cause unexpected silence on a phone: the hardware mute switch, which on many devices silences web audio even with the media volume up, and the interaction rule above if you have not yet touched the page.

Key Takeaways

  • Game sounds here are synthesised at the moment of playing - no audio files are downloaded.
  • An effect is a waveform, a pitch movement and a volume envelope; the envelope carries most of the character.
  • Browsers block audio until you interact with the page, which is why sound starts on your first input.
  • Sound adds information on a channel that is not competing with your eyes, and registers slightly faster.
  • In the sequence game, tones turn the pattern into a melody and are worth several rounds.

Frequently Asked Questions

Why is there no music?

A short arcade game does not need a soundtrack, and a loop that repeats every ninety seconds becomes tiresome quickly. The sound is entirely functional.

Why is the game silent on my phone?

Most often the hardware mute switch, which silences web audio on many devices even when the media volume is up.

Does the sound setting apply everywhere?

Yes. It is stored once in your browser and every game on the site respects it.

Why is the first sound sometimes late?

The audio system starts on your first interaction, so the very first effect can be a fraction behind while it initialises.

Can I play without sound?

Every game is fully playable muted. Cat Paw Pattern is noticeably harder that way, and the rest are unaffected in any meaningful sense.

Play the games this covers

Keep reading

Browser Gaming

Canvas Games Explained

A rectangle the browser hands to the game, repainted sixty times a second - and completely opaque to screen readers.

Browser Gaming

How HTML5 Browser Games Work

From URL to playable game in about a second. Here is every step of what happens in between.

Tips & Strategy

Cat Puzzle Game Strategies

Four techniques that reliably improve memory game results, and one claim we are not going to make.