The NES has no sound chip. Its sound comes from the processor. When Ricoh and Nintendo designed the 2A03 in 1982, working from Nintendo’s preliminary circuit diagrams, they put a 6502 core, a sprite DMA unit, the controller strobes and five sound generators on one piece of silicon. Programmers call that sound section the Audio Processing Unit, or APU. Ricoh’s own specification simply letters the generators A to E.
Those five voices are two pulse waves, a triangle wave, a noise generator and a channel that plays back 1-bit delta-modulated samples. Every NES game has only these five voices, unless a Famicom cartridge brought more of its own. Super Mario Bros. uses them, and so does the Western cartridge release of Metroid. There is no filter, no volume control on the triangle and no choice of waveform beyond four pulse widths. Much of what makes NES music sound like NES music comes from composers working round those limits.
Fast facts
- Part: Ricoh 2A03 (NTSC) and 2A07 (PAL), the NES CPU chip. The APU shares the die with the 6502 core.
- Channels: two pulse, one triangle, one noise, one delta modulation channel (DMC).
- Registers: $4000-$4013 for the channels, $4015 for channel enable and status, $4017 for the frame counter.
- Clock: taken from the CPU, 1.789773 MHz on NTSC and 1.662607 MHz on PAL.
- Output: mono, on two pins. One carries the two pulse channels, the other the triangle, noise and DMC. Each pair is mixed non-linearly.
- First machine: the Famicom, launched in Japan on 15 July 1983.
The pulse channels ($4000-$4007)
The two pulse channels play square-ish waves for melody and harmony. Each has an 11-bit period, a volume envelope, a length counter that can cut a note off automatically, and a sweep unit that bends the pitch.
The pitch is f = f_CPU / (16 × (t + 1)), where t is the 11-bit period. That gives a range from about 54 Hz at the bottom to about 12.4 kHz at the top on an NTSC machine. Below a period of 8 the channel is silenced outright, which is why 12.4 kHz is the ceiling.
Duty cycle. Two bits choose the shape of the wave:
| Setting | Duty | Waveform (8 steps) |
|---|---|---|
| 0 | 12.5% | 0 1 0 0 0 0 0 0 |
| 1 | 25% | 0 1 1 0 0 0 0 0 |
| 2 | 50% | 0 1 1 1 1 0 0 0 |
| 3 | 75% (25% negated) | 1 0 0 1 1 1 1 1 |
Ricoh’s specification calls the fourth setting 75%. NESdev calls it “25% negated”, because it is the 25% wave with every step flipped. Both names describe the same wave, and the flip changes its phase but not its harmonics. Played on its own, the fourth setting sounds the same as the second. So a composer has three tones on these channels: thin at 12.5%, reedy at 25% and hollow at 50%. Changing the duty partway through a note is one of the few ways to vary the tone. Pulse-width modulation covers the technique in general.
Sweep. The sweep unit takes the current period, shifts it right by a set number of bits and adds the result to the period, or subtracts it, at a regular interval. That gives the automatic pitch slides heard in many NES sound effects, with no work from the CPU once the slide is set going. The two pulse channels differ by one in how they subtract. NESdev traces this to their adders being wired differently: pulse 1 subtracts one more than pulse 2 for the same settings.
The sweep unit also mutes the channel if the next period it would produce is out of range, and it does this even while it is switched off. With a low note and the sweep’s negate flag clear, the target period overflows and the note never sounds. NESdev notes that this is why several publishers’ games never seem to use the bottom octave of the pulse channels, and that the fix is to write $08 to the sweep register, which sets the negate flag.
Writing the high byte starts the note. A write to $4003 or $4007 reloads the length counter, restarts the envelope and resets the wave to its first step. Ricoh’s register map marks these addresses as the ones that start the sound. NESdev’s advice follows from that: vibrato should change only the low byte, because rewriting the high byte resets the wave and clicks.
The triangle channel ($4008-$400B)
The triangle channel steps through a 32-step triangle wave with 4-bit values. It has no volume control at all: it is either playing at full level or stopped. It was often used for bass lines.
Its timer runs on every CPU cycle, where the other channels’ timers run on every second cycle. At the same period value it therefore plays an octave below a pulse channel, and it can go far higher, to about 55.9 kHz, well above hearing. Some games use that to silence it. Mega Man 2 sets the timer to zero to stop the channel, and NESdev points out the cost: a pop when the next note starts, “easily heard e.g. in Crash Man’s stage”.
Instead of an envelope, the triangle has a linear counter, a second timer that stops the wave after a set time. When either counter runs out the triangle holds whatever level it had reached, rather than dropping to zero.
The noise channel ($400C-$400F)
The noise channel is a 15-bit shift register with feedback, clocked at one of sixteen fixed rates and passed through the same envelope as the pulse channels. It supplies drums, explosions and engine rumble.
A mode bit changes where the feedback comes from. In the normal mode the output repeats only every 32,767 steps, which sounds like hiss. In the other mode the sequence is 93 or 31 steps long, depending on where the register happened to be when the mode was switched, and the result is a buzzing, metallic tone with a definite pitch.
The delta modulation channel ($4010-$4013)
The DMC plays samples. Each byte of sample data holds eight 1-bit steps, and each step moves a 7-bit output level up or down by two. It is delta modulation: the data says which way the waveform moves, not where it is. The rate is one of sixteen, from about 4.2 kHz to 33.1 kHz on NTSC.
The channel fetches its own data by DMA. Each fetch stalls the CPU for up to four cycles, so a game playing samples loses processor time while they play. A sample must start between $C000 and $FFFF, at a 64-byte boundary, and can be up to 4,081 bytes long. When the sample ends the channel can loop it or raise an interrupt. NESdev describes games using that interrupt as a timer on cartridges that had none of their own.
The fetches have a side effect that every NES programmer who uses samples has to deal with. On the NTSC 2A03, a fetch that lands on the same cycle as a read of the controller port makes the port see extra reads, and a button press can be lost or invented. Games that play samples read the controllers repeatedly until two reads agree. Ricoh’s PAL 2A07 fixed the fault by making the DMA wait for the start of an instruction.
Games can also write the output level directly through $4011. Written quickly enough by the CPU, that plays higher-quality samples, but NESdev notes that the CPU can do little else while it does so, and games that use it usually stop the action while it plays.
The frame counter and its interrupt ($4017)
The envelopes, sweeps and length counters do not run from the CPU clock directly. A frame counter divides it down and clocks them about 240 times a second on NTSC and about 200 on PAL, in a sequence of four or five steps. In the four-step mode the frame counter can also raise an IRQ at the end of every sequence, about 60 times a second.
Despite its name the frame counter is not tied to the picture. It runs at its own rate and drifts against the PPU’s frames. Most games leave its interrupt switched off and drive their music from the vertical blank NMI instead. NESdev notes that The Legend of Zelda and Super Mario Bros. write to $4017 once per frame to keep it in step. The sound engine then runs once a frame in the NMI handler. Interrupt-driven music and Sound drivers cover the general approach.
The mixer
The five channels do not simply add up. Each group of outputs passes through its own digital-to-analogue converter, and the converters are non-linear: two pulse channels at full volume are not twice as loud as one. NESdev gives formulas that model the curve.
Because the triangle, noise and DMC share one converter, the DMC’s output level affects the other two. A high level on the DMC makes the triangle and noise quieter. NESdev names Super Mario Bros. and StarTropics as games that write to $4011 for exactly that reason: the triangle has no volume control of its own, and this was the only way to turn it down.
NTSC and PAL
The PAL 2A07 runs from a slower clock and has its own tables of noise and DMC rates, so the same values give slightly different pitches. Its frame counter runs at about 200 Hz, not 240, and its DMA does not corrupt controller reads. The registers are otherwise the same, but a game converted for PAL without adjusting its music data plays flat.
Composers
Nintendo’s own composers wrote some of the best-known music for the chip. Koji Kondo scored Super Mario Bros. and The Legend of Zelda. Looking back in 2004, Retro Gamer judged that later Zelda games had surpassed the first in the breadth of their adventures, but that the original’s theme tune remained one of the most memorable ever written for a game. Hirokazu “Hip” Tanaka wrote the music for Metroid, Kid Icarus, Duck Hunt and Gyromite. In a 2013 interview with Edge, Doug McDiarmid of the band WHY? said that Tanaka’s Metroid music “really stayed with me – it’s thoughtful, intricate and well composed”, and that he had taught himself the tunes on the piano.
Expansion audio
The Famicom’s cartridge slot has an audio input, so a cartridge could carry extra sound hardware and mix it with the 2A03’s output. The NES’s cartridge slot has no such input, so none of these chips are heard on a Western console.
| Chip | Extra channels | Example |
|---|---|---|
| Konami VRC6 | 2 pulse, 1 sawtooth | Akumajō Densetsu |
| Konami VRC7 | 6 FM channels | Lagrange Point |
| Namco 163 | up to 8 wavetable channels | King of Kings |
| Sunsoft 5B | 3 square-wave channels with noise and envelope | Gimmick! |
| Nintendo MMC5 | 2 pulse, 1 sample | |
| Famicom Disk System | 1 wavetable channel with modulation |
Akumajō Densetsu is the Japanese Castlevania III. Its Western release plays through the 2A03 alone.
Sources
-
David Sheff, Game Over (1993; GamePress edition, 1999): Nintendo bringing preliminary circuit diagrams and needing a supplier to “help design and then produce” the Famicom’s chips.
-
Ricoh, development specification for the RP2A03, October 1982, revised December 1982 (unpublished): the five sound sources lettered A to E; the four duty settings, with the fourth given as 75%; the sweep; the high-byte writes that start each channel; the delta modulation channel’s sixteen rates, DMA and 7-bit converter; the two sound output pins.
-
NESdev Wiki, pages “APU”, “APU Pulse”, “APU Sweep”, “APU Envelope”, “APU Triangle”, “APU Noise”, “APU DMC”, “APU Frame Counter”, “APU Length Counter”, “APU Mixer” and “Expansion audio” (community reference, web, secondary). These cover every register-level and timing statement in this entry, including the pulse and triangle frequency ranges, the sweep’s muting and the
$08fix, Mega Man 2’s triangle pop, the noise sequence lengths, the DMC’s sample limits, DMA stalls and controller-read conflict, the frame counter, the mixer formulas, Super Mario Bros. and StarTropics using$4011, and the NTSC and PAL differences. https://www.nesdev.org/wiki/APU -
NESdev Wiki, “List of NES music composers” (community reference, web, secondary): Koji Kondo for Super Mario Bros. and The Legend of Zelda; Hirokazu Tanaka for Metroid, Kid Icarus, Duck Hunt and Gyromite. https://www.nesdev.org/wiki/List_of_NES_music_composers
-
Retro Gamer issue 4, 2004: The Legend of Zelda and “its Koji Kondo-composed score”.
-
Edge issue 259, November 2013: interview with Doug McDiarmid of WHY? on Hirokazu Tanaka’s music for Metroid.
-
Nintendo news release, 30 September 2016: the Family Computer’s Japanese release on 15 July 1983 (web). https://www.nintendo.co.jp/corporate/release/2016/160930.html
See also
- Nintendo Entertainment System: the console around the chip.
- PPU: the NES picture hardware, and the source of the NMI that most sound engines run from.
- Ricoh: the chip’s maker.
- Koji Kondo and Hip Tanaka: two of the composers who wrote for it.
- Arpeggio: chords played by cycling one channel through their notes.
- FamiTracker: a modern tracker for writing NES music.