One clock, four timers
The APU runs off the same 4.194304 MHz crystal as the CPU. Every channel has a countdown timer. When it hits zero, the channel steps its waveform one position and reloads. The 11-bit value x you write to NRx3/NRx4 sets the reload, so a bigger x means a higher pitch.
- Pulse (CH1, CH2):
131072 / (2048 − x) Hz, 8 duty steps
- Wave (CH3):
65536 / (2048 − x) Hz, 32 four-bit samples
- Noise (CH4): LFSR clocked at
262144 / (r × 2^s) Hz, with r = 0 counting as 0.5
The frame sequencer
A 512 Hz counter, driven by the CPU's DIV timer, clocks the slow modulators: length at 256 Hz, sweep at 128 Hz, envelope at 64 Hz.
| Step | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| Length | ● | | ● | | ● | | ● | |
| Sweep | | | ● | | | | ● | |
| Envelope | | | | | | | | ● |
Trigger, DAC, mixer
Writing bit 7 of NRx4 restarts a channel: it reloads the timer, the volume from NRx2, a zero length counter, CH1's sweep shadow register, and CH4's LFSR (all ones). If the top five bits of NRx2 (or bit 7 of NR30) are zero, the channel's DAC is off and it stays silent. NR51 routes each channel left and/or right, NR50 scales each side from 1/8 to 8/8, and a capacitor strips the DC offset. That capacitor causes the Game Boy's familiar clicks when a DAC switches on.
Not emulated: zombie-mode volume changes, the wave-RAM corruption on CH3 retrigger, extra length clocks on NRx4 writes, and CGB differences.