Squeezing more audio channels out of the 1989 Nintendo Gameboy
Welcome! For the 2019 Retro Challenge, utz and I are adding additional sound capabilities to the original 1989 Nintendo Gameboy (DMG-01) by writing custom code that runs on normal Gameboy cartridges. To understand why and how, let's first look at how the Gameboy makes sound.
The Gameboy has five hardware sound channels. Each one can only produce one sound at a time. The code stored on a Gameboy cartridge can change certain parameters in each of these sound channels as the Gameboy runs it. With precise timing and clever composition, the Gameboy can produce some seriously impressive chiptunes.
Each sound channel is controlled by parameters, which differ depending on the channel. Let's dive deeper into the sounds each channel can make.
The first two channels are pulse wave generators, each of which can produce pulses with duty cycles of 12.5%, 25%, 50%, or 75%. These pulse channels sound quite synthetic. Music made with pulse waves either embraces the electronic sounds they produce, or applies heavy effects to make them sound like more traditional instruments. The Gameboy provides volume envelopes to change the volume of the generated sound over time to emulate real instrument effects, like the slow "decay" of vibrating strings in a guitar or piano.
The next channel can play arbitrary waveforms, though it has many limitations including very low sample quality (four bits) and hardware bugs that cause pops and hissing. Despite these issues, original games and homebrews alike use the wave channel for sample playback and to produce somewhat more natural-sounding waves than the pulse channels are capable of.
The noise channel makes noise, which is used for drum sounds and sound effects. At extreme parameter values, it can also be used to make weird and extremely limited tonal sounds.
There is a "fifth channel" allows game cartridges to provide analog input, which will then be mixed with the rest of the audio channels as if it were generated by the Gameboy itself. No game ever used this channel, but the GB303 homebrew hardware synthesizer (one of the most impressive Gameboy projects out there) uses this channel alone to produce sound. This doesn't really count as a Gameboy hardware channel, as it requires special external hardware that was never made commercially.
Ignoring the analog channel (as this is a software project), that gives utz and I four channels to work with.
Each of these channels should only be capable of making one sound at a time. No Gameboy game ever had more than three tonal sounds and one noise playing at a time. Clever composers evoke the feeling of multiple notes by quickly switching between pitches to make arpeggios that sound convincingly like chords, or switch between very different sound parameters to allow two different "instruments" to share the same channel. These techniques hide the Gameboy's simplistic nature by making it sound like it's much more powerful than it is, and the best chiptunes are made by composers who have mastered these techniques and adapted their compositions to make maximal use of them.
But what if we could do more? If we throw away the idea of making a proper game, with its intensive use of the CPU to put pretty pictures on the screen and move them around with precise timing, could we use the CPU cycles we save to squeeze more sound out of this 1989 portable gaming console?
As it turns out, yes. Thanks to extensive hardware documentation compiled by the Gameboy homebrew community, chiptune artists, and retro hardware hackers, as well as some impressive prior experimentation in this area, you can squeeze a hell of a lot out of this beige brick.
Stay tuned for details!
For a deeper dive into the Gameboy audio hardware, check out Michael Steil's excellent Ultimate Gameboy Talk from 33c3.