In this part of my Game Boy simulator post series, I will cover the details of the wave channel of the so-called Audio Processing Unit (APU). Unlike the other channels of the APU (noise and square), the wave channel allows you to customize the output sound. Well, it only provides 32 samples with a 4-bit resolution, which makes it rather suitable for custom wave forms than anything else. In theory, you can also constantly rewrite the 32 samples in order to play back any kind of recording. For instance, this video provides examples of voice playbacks in Game Boy games. Playing back voices with a 4-bit resolution on a Game Boy speaker sounds horrible, but things like the super crappy “PIKACHU” from Pokémon Yellow also have their own appeal.

When it comes to information about the Game Boy’s hardware, there’s already plenty of information available. The following sources helped me a lot to write this post and my Game Boy simulator:

Official Game Boy Programming Manual
Game Boy Development Wiki
Game Boy CPU Manual
Pan Docs (my favorite source)

Unlike the technical documentation from above, this post follows a more example-driven approach. So, rather than getting lost in every tiny obscure behavior, I first highlight the general principles of the wave channel, which is then followed by some practical examples on how games made use of it.

Overview

Similar to other units of the Game Boy (DMA, Pixel Processing Unit, etc.), communication with the APU is facilitated by memory-mapped I/O. That means if you want to tell the APU something you just write something into certain memory-mapped registers, while information about the APU’s current status can retrieved by reading these registers. For the wave channels, the following registers and addresses are relevant:

Name Address Bits Function
NR30 0xFF1A D--- ---- DAC enable
NR31 0xFF1B LLLL LLLL Length load
NR32 0xFF1C -VV- ---- Volume
NR33 0xFF1D FFFF FFFF Frequency LSB
NR34 0xFF1E TL-- -FFF Trigger, length enable, frequency MSB
Wave pattern 0xFF30 SSSS SSSS Sample 0, Sample 1
Wave pattern 0xFF3F SSSS SSSS Sample 30, Sample 31

The next section highlights their function in greater detail.

Wave Channel

First, the very technical definition of the square wave channel register before we head to some examples.

NR30: DAC Enable

The sweep channel can be used to change the frequency of the square wave over time. This is primarily used to model sound effects, such as hopping on a Goomba in Super Mario Land.

[0:6] 7-bit unused: Unused.
[7:7] 1-bit DAC enable: 0 → DAC (and therefore sound) is turned off. 1 → DAC (and therefore sound) is turned on.

NR31: Length Timer

[0:7] 8-bit length timer: Can be read from or written to. The 8 bits are interpreted as an unsigned number ranging from 0 to 255. This number determines the length of the sound: length = (256-value)*(1/256) seconds. So, the shortest sound is 1/256 second, while the longest is 1 second. Note that the “256-value” part leads to some counterintuitive behavior. When writing 0, you get the longest possible length, an when writing 255, you get the shortest possible length. If you want indefinite sustain, disable Bit 6 in register NR34.

NR32: Volume

[0:4] 5-bit unused: Unused.
[5:6] 2-bit volume: Controls sound volume: 00 → 0%; 01 → 100%; 10 → %50; 11 → %25.
[7:7] 1-bit unused: Unused.

NR33: Frequency LSB

[0:7] 8-bit frequency lower bits: The frequency comprises 11 bits in total (see NR34 as well). The wave channel uses a non-exposed, 11-bit counter that increases every time it is clocked. After 2047 it overflows, generates a signal, and is set to the value of NR33 and NR34. The resulting sample rate is: 2,097,152/(2048-frequency). Hence, the lowest sample rate is 1024 Hz and the highest ones is 2,097,152 Hz. Note that this is the rate at which individual samples of the wave pattern are processed.

NR34: Channel Control & Frequency MSB

[0:2] 3-bit frequency lower bits: Upper bits of the period. See NR33.
[3:5] 3-bit unused: Unused.
[6:6] 1-bit length enable: 0 → Regardless of the length data in NR31 sound can be produced consecutively. 1 → Sound is generated during the time period set by the length data in NR31.
[7:7] 1-bit trigger (write-only): Writing 1 to this bit causes the following things: The wave channel is enabled. If the length timer expired it is reset. Volume is set to contents of NR32 initial volume. Wave RAM index is reset, but not refilled!

Wave Simulator

Here’s a Javascript-based wave channel simulator. Using table and sliders below you can define individual settings and listen to the sound they would create on the Game Boy. Note that the simulator repeats every 2 seconds. Predefined setups of some games are provided in the next section.

Register Setting
NR30: DAC Enable DAC Enable
NR31: Length Timer Length
NR32: Volume Volume
NR33/NR34: Frequency Frequency
NR34: Channel Control Length enable:


Sample values:

Examples

In the following, examples of the wave channel in games are provided. To get these examples I used the Gearboy emulator. Click on “Use this setup” to load the wave simulator with the corresponding setup. Note that all settings are just recordings at one point in time. While most games use the same wave pattern throughout a theme or song, frequency and volume do change frequently.

Tetris

In the very well-known main theme of Tetris the following setting of the wave channel can be found:

Main theme

NR30: 1000 0000 -> DAC enabled
NR31: 0000 0000 -> maximum length, but irrelevant due to NR34
NR32: 0010 0000 -> volume = 100%
NR33: 0000 1010 -> frequency (1546) = 4178 HZ sample rate
NR34: 1000 0110 -> trigger, length disabled

Wave samples:
0123 4567 89AB CDEF
FEDC BA98 7654 3210

While this setting is used mostly unchanged throughout the theme, the actual frequency configuration changes from note to note. In the given example, we have a frequency value of 1546, resulting in a sample rate of 4178 Hz. Dividing this by 32 gives us a frequency of 130 Hz, which corresponds to a C3 note. A relatively deep note, but no surprise as the wave channel is used for the bass. As a wave form, a pretty vanilla triangle wave is used. Click on “Use this setup” to get an immediate visual representation of such a wave form.

In the opening theme of Tetris (not the famous one but the one you hear in the start screen) I found the following sinus-like wave form.

Opening theme

NR30: 1000 0000 -> DAC enable
NR31: 0000 0000 -> maximum length, but irrelevant due to NR34
NR32: 0010 0000 -> volume = 100%
NR33: 1100 0100 -> frequency (1732) = 6636 Hz sample rate
NR34: 1000 0110 -> trigger, length disabled

Wave samples:
1123 5678 9998 7667
9ADF FEC9 8542 1131

Just as in the other Tetris theme, the wave form is again used as a bass. From the 6636 Hz sample rate, you can derive a 207 Hz tone, which corresponds to a G#3. Just the wave form is kind of different than before. It looks like two overlapping sine waves.

In the Legend Of Zelda: Link’s Awakening I found the following setting in the intro of the game:

Intro

NR30: 1000 0000 -> DAC enable
NR31: 0000 0000 -> maximum length, irrelevant due to NR34
NR32: 0010 0000 -> volume = 100%
NR33: 0100 1110 -> frequency (1102) = 2216 Hz sample rate
NR34: 1000 0100 -> trigger, length disable

Wave samples:
9999 9999 0000 00000
9999 9999 0000 00000

You can already see from the data that this is just a simple square wave. From the sample rate of 2216 Hz, we can derive a wave pattern period of 69 Hz. But notice that the 32 samples contain two periods of the wave pattern! Hence, the perceived tone is a C#3 (138 Hz) and the wave channel takes the role of a bass.

After the cinematic intro, you get into the main menu where the iconic TLoZ theme plays. Here, the wave channel is used in a similar way as before. However, this time there is only one period of a square wave in the wave pattern. Also note that in this case the volume of the wave channel is frequently changed to model some decay. While other channels (like noise and square) provide an envelope function for this effect, this feature is absent in the wave channel. The sample rate of 4434 Hz results in a C#3 (138 Hz).

NR30: 1000 0000 -> DAC enable
NR31: 0000 0000 -> maximum length, but irrelevant due to NR34
NR32: 0110 0000 -> volume = 25%
NR33: 0010 0111 -> frequency (1575) -> 4434 Hz sample rate
NR34: 1000 0110 -> trigger, length disabled

Main theme
8888 8888 8888 8888
0000 0000 0000 0000

Super Mario Land

In the Super Mario Land overworld theme I found the following setting:

Theme
NR30: 1000 0000 -> DAC enable
NR31: 0000 0000 -> maximum length, but irrelevant due to NR34
NR32: 0010 0000 -> volume = 100%
NR33: 0000 0110 -> frequency (1798) -> 8389 Hz sample rate
NR34: 1000 0111 -> trigger, length disabled

Wave pattern:
0123 5678 9998 7667
9ADF FEC9 8542 1100

Surprisingly, it’s almost the same wave pattern as in the Tetris opening theme. Also, similar to all examples before, the wave channel again takes the role of a bass. In the given setting, the played sound is at 262 Hz, resulting in a C4.