Skip to content
ZapskiRetro

Game Boy sound toy

Play the Game Boy's four sound channels, shape a sound effect, and take away the register values and a GBDK C snippet that plays it on real hardware.

Channel
Start from a preset
Keyboard, octaves 4 and 5

On a computer, the keys A W S E D F T G Y H U J K play the lower octave. Z and X move down and up an octave.

Registers

NameAddressValue
NR21$FF160x80
NR22$FF170xC1
NR23$FF180x83
NR24$FF190x87
Duty
Envelope direction

Everything happens in your browser. This approximates the hardware; it is not an emulator.

The four channels

A Game Boy makes all its sound from four simple channels. Two are pulse channels: a wave that is either high or low, with a choice of how much of each cycle it spends high. That choice is the duty, and it is the difference between a thin, reedy tone and a full one. The first pulse channel can also sweep, sliding its pitch up or down by a fraction of itself many times a second. A downward sweep is a laser; an upward one is a jump or a power-up.

The third channel plays a wave you draw: 32 samples, each one of 16 levels, looped at the pitch you ask for. It has no envelope, only four volume settings, and it sounds an octave lower than a pulse channel given the same pitch value. Games use it for bass lines.

The fourth is noise from a shift register, a row of bits that shuffles along on every clock tick. At its full 15 bits it hisses; cut to 7 bits the pattern repeats so quickly it turns into a metallic buzz. Pulse and noise channels share an envelope that steps the volume up or down over time, and every channel has a length timer that can cut the sound off.

Using the snippet

Paste the code into a GBDK project and call the function when the sound should play:

if (joypad() & J_A) {
    play_sound();
}

The first three lines switch the sound hardware on and only need to run once, so move them to your start-up code if you have several sounds. The last write is the one that starts the sound: it sets the trigger bit, so the other registers have to be written before it. The register table gives the same values if you are writing assembly.

How close is it?

  • This is not an emulator. The pitches, envelope and sweep timing and the noise pattern follow the hardware; the analogue character of a real speaker does not.
  • The register values and the code are exact. Trust those over your ears, and test on an emulator or a console.
  • Very fast noise settings change faster than a browser can play back, so they sound rougher here than on a Game Boy.
  • One channel at a time. A real game plays all four at once.

More tools