Pan Docs — Audio Details

author gbdev community (Pan Docs; APU diagram by Lior "LIJI32" Halphon)
date 2025-07-03
article Audio → Audio Details (page 3 of 3 of the audio section; file last changed 2025-07-03, fetched 2026-08-30)
created 2026-08-30 · updated 2026-08-30

The internals-and-quirks page of the pan-docs audio section — "The PPU is a bunch of state machines, and the APU is a bunch of counters." It follows the signal from generator through DAC, mixer, master volume and high-pass filter, explains the DIV-APU clock, the sweep unit, the pulse duty counter, the wave sample buffer and the noise LFSR, lists the Game Boy Advance differences and ends with a catalogue of obscure behaviour. Companion to s-pandocs-audio-overview and s-pandocs-audio-registers.

Key claims#

  • Signal path: each channel is a generation circuit producing a digital $0–$F plus a DAC that maps it linearly to analog −1…+1 — with a negative slope: "digital 0 maps to analog 1". The mixer adds the channels selected in NR51 into left and right (range −4…+4; VIN is a fifth mixer input controlled from NR50); each side is scaled by NR50 (which never mutes) and by the volume knob (which can), then passes a high-pass filter.
  • PCM12 / PCM34 ($FF76/$FF77, Game Boy Color and later, read-only): the digital outputs of CH1+CH2 and CH3+CH4 — "not documented in any known Nintendo manual".
  • DIV-APU: a 512 Hz counter driven by DIV bit 4 (bit 5 in double speed). Envelope sweep every 8 ticks (64 Hz), sound length every 2 (256 Hz), CH1 frequency sweep every 4 (128 Hz). Writing to DIV can make it tick faster.
  • Mixer and pops: the HPF removes DC offsets (silent channels with an enabled DAC, off-centre waveforms). "Enabling or disabling a DAC, adding or removing it using NR51, or changing the volume in NR50, will cause an audio pop." A driver avoids it by never turning DACs off: write $08 to NRx2 (silent, DAC on), then $80 to NRx4 to retrigger. The HPF "is more aggressive on GBA than on GBC, which itself is more aggressive than on DMG" — the more aggressive, the faster it pulls towards zero and the more it distorts waveforms.
  • DACs: channel x's DAC is on iff [NRx2] & $F8 != 0 (CH3: NR30 bit 7). The envelope changes the volume but not NRx2, so it cannot switch a DAC off. A disabled DAC fades to analog 0 (= "digital 7.5") in a model-dependent way. NR52's low bits report the channels, not the DACs; a disabled channel outputs digital 0, which an enabled DAC "dutifully" turns into analog +1.
  • Sweep unit (CH1): a shadow period register, a sweep timer clocked at 128 Hz and an enabled flag. On trigger the period is copied to the shadow register, the timer reset, the flag set if pace or step is non-zero, and with a non-zero step a frequency calculation plus overflow check runs immediately. On each timer clock a new frequency is calculated and checked (> 2047 disables CH1); if the step is non-zero it is written to the shadow register and to NR13/NR14, and a second calculation and check follow without write-back. NR13/NR14 writes during an active sweep are lost at the next iteration unless the channel is retriggered.
  • Pulse channels: a "duty step" counter indexes the 8-step waveform at 8 × the channel frequency; it "cannot be reset, except by turning the APU off". Retriggering resets the duty step timer, so "retriggering a pulse channel often enough will cause its 'duty step' to never advance." A freshly started pulse channel always outputs a digital zero first.
  • Wave channel: a sample index at 32 × the frequency (sample 0 is skipped on start); samples pass through a buffer that (re)triggering neither clears nor refreshes — "the last sample ever read will be emitted again"; the buffer is cleared only when the APU is switched on. The output level shifts the digital value, biasing it towards 0 (analog +1); a mid-note level change is smoothed by the HPF "but not instantly".
  • Noise channel: 16 bits (15 state bits plus one for the next bit). Per tick: bit 15 ← XNOR(bit 0, bit 1); in short mode it is also copied to bit 7; then the register shifts right and bit 0 selects 0 or the volume. The LFSR is set to 0 on (re)trigger. Lock-up: "If the 'active' portion of the LFSR only contains '1' bits, only '1' bits will be generated" — silence until retriggered; reachable by switching from 15- to 7-bit mode while the bottom 7 bits are all 1, "which occurs relatively early after triggering the channel".
  • Game Boy Advance: mixing is digital with a SOUNDBIAS offset; there are no DACs (a disabled "DAC" acts as an enabled one fed with 0); CH3's DAC output is inverted, so the channel emits "a loud spike when disabled" — disconnect it via NR51 before touching wave RAM. The extra GBA audio features are unavailable to Game Boy programs.
  • Obscure behaviour: envelope and sweep timers treat a period of 0 as 8; after power-on the first duty step plays as 0 and duty clocking is disabled until the first trigger; CH3's first sample after a trigger is the previous high nibble, then the second nibble of wave RAM (the first nibble only plays when the wave loops); triggering CH1/CH2 leaves the low two bits of the frequency timer alone; extra length clocking when NRx4 is written in certain DIV-APU phases (breaks Prehistorik Man on CGB-02, fixed on CGB-04/05); a length of 64/256 set on trigger in that phase becomes 63/255; in another phase the envelope timer reloads one higher; a clock shift of 14 or 15 gives the LFSR no clocks; clearing the sweep direction bit after a subtraction-mode calculation disables CH1 at once; DMG wave-RAM corruption in detail (the first byte or the first four bytes are overwritten with the bytes being read — Duck Tales suffers from it; stop the wave with 0 then $80 to NR30 before retriggering); "zombie mode" — writing NRx2 while a channel plays changes the volume in model-dependent ways (CGB-02/04 are the most consistent); the one trick that works on every unit tested: write $V8 before the trigger, then write $08 to NRx2 to raise the volume by 1 (15 times = lower it by 1); with all four DACs off the output is 0; the HPF behaves like a capacitor with charge factor 0.999958 per 4194304 Hz sample on the DMG (0.998943 on MGB and CGB), i.e. about 0.996 at 44100 Hz.

Practical takeaways#

Why tracker "kill" commands click (DAC off = pop), why silence should be volume 0 with the DAC on, why LSDj's noise instruments need a SAFE mode (the 15→7-bit lock-up, cured by a trigger), why very fast retrigs change a pulse channel's character (the duty step freezes), and why wave changes on a DMG can corrupt the wave — all of it is on this page. Also useful: the manual-volume "zombie" trick, and the fact that the GBA's filter distorts the most.

Notable quotes#

"The PPU is a bunch of state machines, and the APU is a bunch of counters."

"Retriggering a pulse channel often enough will cause its 'duty step' to never advance."

Relevance#

Supplies the "why" for Game Boy quirks that the LSDj manual only names (s-lsdj-manual): resync, noise muting, kill clicks, wave glitches.

Pages touched#

game-boy-apu · game-boy · retrigger · adsr-envelope · wavetable-programming · stereo-panning · instrument-design · lsdj · pan-docs

source file wiki/summaries/s-pandocs-audio-details.md · graph