The audio processing unit (APU) is part of the 2A03 (2A07 on PAL). It has five channels: two pulse waves, a triangle wave, noise and the delta modulation channel (DMC) that plays one-bit samples. Pulse, triangle and noise have a timer and a length counter. The pulse channels and noise also have an envelope. A frame counter makes the slow clocks. The channel outputs go through a non-linear mixer. Bit patterns have bit 7 on the left. The Famicom can add more channels from the cartridge; see expansion audio. This page follows the NESdev Wiki pages named under Sources.
Register map
| Addresses | Channel | Units |
|---|---|---|
$4000–$4003 | Pulse 1 | Timer, length counter, envelope, sweep |
$4004–$4007 | Pulse 2 | Timer, length counter, envelope, sweep |
$4008–$400B | Triangle | Timer, length counter, linear counter |
$400C–$400F | Noise | Timer, length counter, envelope, shift register |
$4010–$4013 | DMC | Timer, memory reader, sample buffer, output unit |
$4014 | (not sound) | OAM DMA |
$4015 | All | Channel enable and status |
$4016 | (not sound) | Controller strobe and port 1, see controller ports |
$4017 | All | Frame counter (write); controller port 2 (read) |
Pulse, $4000–$4007
Pulse 1 uses $4000–$4003 and pulse 2 uses $4004–$4007, with the same layout.
| Register | Bits | Meaning |
|---|---|---|
$4000 / $4004 | DDLC VVVV | D duty (0: 12.5%, 1: 25%, 2: 50%, 3: 75%). L is the length counter halt and envelope loop flag (1: the envelope repeats and the length counter is frozen). C is constant volume (1: the volume is V, 0: the envelope sets it, starting at 15). V is the volume, or the envelope period. |
$4001 / $4005 | EPPP NSSS | Sweep unit: E enable, P period, N negate, S shift. |
$4002 / $4006 | TTTT TTTT | Timer low 8 bits. |
$4003 / $4007 | LLLL LTTT | L length counter load (an index into the length table below), T timer high 3 bits. The write restarts the envelope and resets the pulse phase. |
The timer is 11 bits (t). The output frequency is fCPU ÷ (16 × (t + 1)), where the CPU clock is 1.789773 MHz (NTSC) or 1.662607 MHz (PAL). A period below 8 silences the channel. The sweep makes the pitch rise or fall continually and silences the channel at the end of the range. To avoid a click, vibrato should write only the low timer byte, because a write to the high byte resets the phase. A length counter at 0 silences the channel whatever L says. (NESdev Wiki, “APU”.)
Triangle, $4008–$400B
| Register | Bits | Meaning |
|---|---|---|
$4008 | CRRR RRRR | C halts the length counter and holds the linear counter reload. R is the linear counter reload value. |
$4009 | Unused. | |
$400A | TTTT TTTT | Timer low 8 bits. |
$400B | LLLL LTTT | Length counter load and timer high 3 bits. The write also sets the linear counter reload flag. |
The wave has 32 steps of 4 bits. There is no volume control. The pitch is one octave below a pulse channel with the same timer value. The linear counter is clocked four times per frame-counter sequence and silences the channel when it reaches 0; the length counter does too, so whichever is shorter wins. On a reload clock the reload value R is copied only when the flag is set, and the flag clears only when C is 0. Silencing the triangle only halts it, so it keeps its last output level. Its phase cannot be reset. (NESdev Wiki, “APU”.)
Noise, $400C–$400F
| Register | Bits | Meaning |
|---|---|---|
$400C | --LC VVVV | Envelope loop and length counter halt (L), constant volume (C), volume or envelope period (V), as on the pulse channels. |
$400D | Unused. | |
$400E | M--- PPPP | M selects the periodic (short, buzzing) mode. P is an index into the period table. |
$400F | LLLL L--- | Length counter load. |
The shift register is loaded with 1 at power-up and a reset does not touch it. The earliest 2A03 revisions (first Famicoms, Vs. System boards and arcade sound boards) had no mode bit, and rate $F lasted 2,046 M2 cycles instead of 4,068. Noise periods in CPU cycles:
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| NTSC | 4 | 8 | 16 | 32 | 64 | 96 | 128 | 160 | 202 | 254 | 380 | 508 | 762 | 1016 | 2034 | 4068 |
| PAL | 4 | 8 | 14 | 30 | 60 | 88 | 118 | 148 | 188 | 236 | 354 | 472 | 708 | 944 | 1890 | 3778 |
(NESdev Wiki, “APU Noise”.)
DMC, $4010–$4013
| Register | Bits | Meaning |
|---|---|---|
$4010 | IL.. RRRR | I enables the sample-end interrupt. L loops the sample (a looping sample never sets the interrupt flag). R is the rate index. |
$4011 | .DDD DDDD | Sets the 7-bit output level directly. Fast writes play raw PCM. The output level also changes the loudness of the triangle and noise because of the non-linear mixer. |
$4012 | AAAA AAAA | Sample address: $C000 + A × 64. |
$4013 | LLLL LLLL | Sample length: L × 16 + 1 bytes. |
A sample is a stream of one-bit deltas, read from the least significant bit of each byte. A 1 adds to the 7-bit counter, a 0 subtracts, and it stops at the ends of the range. Periods between output changes, in CPU cycles:
| Rate | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| NTSC | 428 | 380 | 340 | 320 | 286 | 254 | 226 | 214 | 190 | 160 | 142 | 128 | 106 | 84 | 72 | 54 |
| PAL | 398 | 354 | 316 | 298 | 276 | 236 | 210 | 198 | 176 | 148 | 132 | 118 | 98 | 78 | 66 | 50 |
Dendy clones use the NTSC table. The memory reader fetches the next byte by DMC DMA when the buffer is empty. When the last byte has been fetched, and L is clear and I is set, the interrupt flag is set. The flag drives the CPU IRQ line until it is cleared by a write to $4015 or by clearing I in $4010. The DMC IRQ can also be used as a timer for screen splits. (NESdev Wiki, “APU DMC”.)
Status and channel enable, $4015
| Access | Bits | Meaning |
|---|---|---|
| write | ---D NT21 | Enable DMC (D), noise (N), triangle (T), pulse 2 (2) and pulse 1 (1). Clearing a bit forces that channel’s length counter to 0 (for the DMC, its bytes-remaining counter). Setting D restarts the sample only if no bytes remain. Any write clears the DMC interrupt flag. Power-up and reset act as a write of 0. |
| read | IF-D NT21 | I is the DMC interrupt flag, F the frame interrupt flag, D is 1 while the DMC has bytes remaining, N T 2 1 are 1 while that channel’s length counter is above 0. The read clears F but not I. Bit 5 is open bus. The register is inside the CPU, so the cartridge cannot see the read and open bus is not updated by it. |
Frame counter, $4017 (write)
| Bits | Meaning |
|---|---|
7 (M) | Mode. 0 is the free-running four-step sequence. 1 is the external synchronisation (five-step) mode. |
6 (I) | Interrupt inhibit. Setting it clears the frame interrupt flag. |
| 5–0 | Unused. |
A write resets the sequence. The effect comes 3 CPU cycles after the write (4 if it fell between APU cycles). If M is written as 1, the quarter-frame and half-frame clocks are generated at once. The quarter-frame clock steps the envelopes and the triangle’s linear counter; the half-frame clock steps the length counters and sweep units. The sequencer counts APU cycles (two CPU cycles each).
| Mode | Step | APU cycle (NTSC / PAL) | Quarter | Half | IRQ flag |
|---|---|---|---|---|---|
| M = 0 | 1 | 3728 / 4156 | yes | ||
| 2 | 7456 / 8313 | yes | yes | ||
| 3 | 11185 / 12469 | yes | |||
| 4 | 14914 / 16626 (then 0) | yes | yes | set if I is clear (on the get and put cycles of 14914 and again at cycle 0) | |
| M = 1 | 1 | 3728 / 4156 | yes | ||
| 2 | 7456 / 8313 | yes | yes | ||
| 3 | 11185 / 12469 | yes | |||
| 5 | 18640 / 20782 (then 0) | yes | yes | never set |
In mode 0 the quarter-frame rate is about 240 Hz (200 Hz PAL), the half-frame rate 120 Hz (100 Hz) and the interrupt every 29,830 CPU cycles (33,254 on the 2A07), about 60 Hz (50 Hz). The flag drives the IRQ line until a read of $4015 or a write to $4017 with I set. In mode 1 there is a gap of about 7,454 CPU cycles (8,314 on the 2A07) after the fourth step in which the program can restart the sequence, so writing $4017 with M set in the NMI keeps the envelopes in time with the video frame. (NESdev Wiki, “APU Frame Counter” and “APU”.)
Length counter table
The five-bit value written to $4003, $4007, $400B or $400F (bits 7–3) is an index. The number is the count of half-frame ticks (about 120 Hz NTSC, 100 Hz PAL) before the channel falls silent. (NESdev Wiki, “APU”.)
| Index | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Ticks | 10 | 254 | 20 | 2 | 40 | 4 | 80 | 6 | 160 | 8 | 60 | 10 | 14 | 12 | 26 | 14 |
| Index | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B | 1C | 1D | 1E | 1F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Ticks | 12 | 16 | 24 | 18 | 48 | 20 | 96 | 22 | 192 | 24 | 72 | 26 | 16 | 28 | 32 | 30 |
Mixer
The two pulse channels come out of one pin and the triangle, noise and DMC out of another, each through its own non-linear DAC. The two signals are then combined. A low-pass and a high-pass filter may follow; a television’s RF circuit usually adds a strong low-pass. (NESdev Wiki, “APU”.)
Sources
- NESdev Wiki: APU
- NESdev Wiki: APU Pulse, Triangle, Noise, DMC
- NESdev Wiki: APU Frame Counter
- NESdev Wiki: APU Length Counter
The NESdev Wiki text is available under CC BY-SA 3.0. This page is written in our own words. The sweep and envelope unit internals and the exact mixer formulae are on APU sweep, envelope and mixer. The per-cycle details of each channel are on the wiki pages and are not repeated here.