# Sound Source: GBATEK "DS Sound" (Channels 0..15, Control Registers, Capture, Block Diagrams, Notes). DOC unless marked. The sound unit is the ARM7's (registers at 4000400h-400051Fh); the ARM9 cannot reach it. It shares nothing with the GBA's sound (the DS has no Game Boy channels in NDS mode; GBA mode uses the GBA's sound hardware, gba-python's with gb-apu-python's AGB row), so no family core carries over. The family's "sound good enough" rule (sound less exact than pictures) applies. ## The unit - **16 channels**, each with control (volume 0-127 with a divider 1/2/4/16, pan 0-127, repeat mode, format, hold, start/busy), source address, timer (sample rate = 16.756991 MHz / (10000h - timer)), loop start and length. Formats: PCM8, PCM16, IMA-ADPCM on all channels; PSG square waves (duty 0-7 in 12.5% steps) on channels 8-13; white noise on 14-15. - Start delays: PSG/noise 1 sample, PCM 3, ADPCM 11 (GBATEK "Sound Notes"). Busy clears at the start of a one-shot's last sample. Lengths under 4 words hang the channel. - **Mixer**: SOUNDCNT master volume and enable, left/right sources (mixer or channels 1/3 directly), SOUNDBIAS (usually 200h). "The sampling frequency of the mixer is 1.04876 MHz with an amplitude resolution of 24 bits, but ... after mixing with PWM modulation is 32.768 kHz with ... 10 bits". - **Two capture units** (SNDCAP0/1): record the mixer's (or a channel's) output into memory, used for echo and reverb effects; channels 1 and 3 can play the captured data back. Capture writes main RAM, so it is visible to the CPUs. - The microphone (through the TSC's AUX channel, peripherals.md) and the speakers' amplifier (power management register 0) are outside the unit. ## Modelling level (proposal) Per output sample at 32.768 kHz with each channel stepped by its timer in between. GBATEK's mixer rate, 1.04876 MHz, is not an integer division of the bus clock (bus / 32 would be 1.04731 MHz; 32.768 kHz x 32 = 1.04858 MHz): which clock drives the mixer is C1 below, and the output rate's relation to the bus clock (bus / 1,024 = 32.73 kHz?) with it. Busy bits and capture writes are observable: the busy bit must be right at the CPU's cycle (computable from the timer arithmetic without running the mixer), capture's RAM writes at their time (a channel to the CPU domain, domains.md). ## Unknowns (U) - U1 The ADPCM decoder's exact clamping and the step table's behaviour at extremes (DOC gives the algorithm; no recorded outputs found). - U2 Mixer rounding through the 24-bit stage to 10 bits; the PWM's effect on what is heard. - U3 Capture's timing relative to the mixer (which sample, which cycle the RAM write lands). - U4 Noise LFSR seed and polynomial details beyond GBATEK's description. - U5 How channel reads of main RAM contend with the CPUs (a sound FIFO per channel is implied; its depth is undocumented). - C1 The mixer's 1.04876 MHz and the 32.768 kHz output (GBATEK) do not divide the 33.513982 MHz bus clock evenly, while every sound timer counts at bus / 2. GBATEK's DSi chapter names the DSi's external audio clock "32.73kHz or 47.61kHz" (selected in SNDEXCNT), and 32.73 kHz is bus / 1,024. Default: the output sample period is 1,024 bus cycles (32.73 kHz), HYPOTHESIS until a recording or a capture-timing test settles it.