-
Notifications
You must be signed in to change notification settings - Fork 0
Sound
The SM8521's sound generator has three channels plus a direct DAC. Sound is the machine's weakest-documented subsystem and the hardest to get exactly right — even mature reference emulators flag their Game.com audio as imperfect.
-
SG0 / SG1 — wavetable. Each plays a 32-step, 4-bit waveform (16 bytes of register space)
at a rate set by a 12-bit period; the tone frequency is
2,764,800 / period / 32Hz. Each channel has a 5-bit output level. These produce the beeps, blips, and chiptune-style melodies. - SG2 — noise. A high-rate "almost periodic" noise channel. It exists in the registers but isn't implemented anywhere, including the reference emulators — there's no known-good model to copy.
- SGDA — 8-bit DAC. A direct write-the-sample output. Most games use this for streamed music and speech (ADPCM decoded at 8 kHz), with the other channels stopped. The boot sound plays through here.
A master enable plus per-channel enables (SGC) gate everything.
The hard part isn't generating the waveforms — it's timing the DAC. On real hardware the DAC's playback rate is driven by the Timer 1 interrupt, which is the same timer that drives the kernel's game logic. Speed that interrupt up to make the audio pitch correct and you break game timing; slow it down for correct game timing and the audio becomes unintelligible. There is no documented way the real machine keeps both happy, and no public per-instruction cycle data to calibrate against — so DAC pitch accuracy is fundamentally an open problem, not just a missing feature.
The current implementation generates the two wavetable channels (phase accumulators stepping through the 4-bit tables, scaled by level) and the DAC, mixed to stereo each frame and delivered through the libretro audio callback. The boot sound plays. It is a first pass: the DAC is sampled once per frame rather than streamed at sub-frame resolution, and the TIM1 coupling above means pitch is approximate. Improving it is tied to the cycle-accuracy work described in Interrupts & Timers.
Tigerbyte
Hardware
Development