← All sound labs
Chip Sound Labs

FAQ

A line or two about this page.

General

What are the Chip Sound Labs?

This is a list of super vibecoded Javascript simulators of old sound chipsets.

The tracker and the songs

How do I play a song?

Look for the tracker window, load a song and click play.

Can I add my own songs to the library?

You can't. The only thing you can do is load song one to the webpage to play it.

The game songs

Where do the game songs come from?

For each console there is a small emulator that runs nothing but that code. It has the processor, the cartridge’s memory banking and the timing of the video frame, and draws no picture. It boots the game until the driver is running, asks the driver for one song, then calls it once per frame the way the game does, with the rest of the game stopped. Every write to the sound chip is logged. Finding each driver, and how its game asks for a song, meant tracing the game and reading its code.

  • Game Boy, NES, Master System: from the cartridge ROMs. For NES games whose NSF rip matches the cartridge, the NSF’s track list gave the song numbers and its playlist gave the titles.
  • SNES: Chrono Trigger runs from its cartridge, on a 65816 core that passes all 5 million SingleStepTests cases. The other eleven games start each song from its .spc file (a snapshot of the sound module as the song begins) and run the sound processor alone.
  • Mega Drive: from the VGM logs on vgmrips.net, which already hold every chip write with its time. The work there is recovering the driver’s ticks from the timing of the writes.

A converter then turns the log into a tracker song:

  • Each note the driver starts (a key-on, or a jump in pitch) becomes a note in the pattern.
  • Everything the driver writes to that channel until the next note becomes the note’s instrument: a macro that replays those writes tick by tick, with pitch relative to the note. Notes that sound alike share an instrument.
  • Vibratos and slides become pitch lists that many notes can share.
  • The tempo comes from fitting a row grid to where the notes fall. It is often a fractional number of frames per row, because many drivers keep time with a counter that overflows.
  • Samples (NES DMC, Mega Drive DAC, SNES BRR) are the game’s own bytes, at the addresses the game used.

The music belongs to the games’ publishers and is here for study. The ROMs and the ripping tools are not published.

How exact are they?

There has been an attempt at being as exact as possible, and have the simulator play the "score" from the video game code, exactly like a console would (and looping the way it would when you play the game). The limits are these:

  • Exact to the frame, not the cycle. A game spreads a frame’s writes over its first few thousand cycles. The labs apply them all at the start of the frame. On the NES, the order of writes between channels inside a frame is not compared.
  • The chips are emulated, not real. The writes are the game’s own, but the sound is only as close to the hardware as each lab’s emulation, and each lab lists what it does not emulate.
  • Loops. Some drivers come back to exactly the same state, and those songs loop forever as in the game. Others return to the same point in the song with a random generator, a vibrato phase or a tempo counter somewhere else, so later passes in the game would drift by a fraction of a tick. For those, the tracker repeats the first pass, which is exact. On the SNES, where tempo runs in fractions of a tick, most songs work this way. Songs that never repeat keep their first few minutes and then start over. Songs that end in the game end here too.
  • Per console: the SNES driver sometimes loses a timer tick when it is busy, while the tracker plays every tick on time. Mega Drive songs are as exact as their VGM logs. The Master System emulator has no FM unit, so games that support it play their PSG music.

The pattern view is one reading of the music, not the composer’s original file. The rows and instruments are what the converter worked out, so where a driver’s timing is irregular, some notes sit on delay effects instead of their own rows. Some songs play at super high "bpm", because instead of having clean 'notes' happening a few times per second, the game code actually does many many writes to the sound chip to play the music, which is what is kept

How the scores were generated

What is the general idea?

A game doesn’t contain a score in a format a tracker could read. It contains a sound driver: a small program that reads the game’s own music data and writes to the sound chip every frame. Each score here was made in three steps.

  • Capture. An emulator runs the game’s driver alone and logs every write it makes to the sound chip. The driver is called the way the game calls it (once per frame, or on its timer), but with interrupts masked and the rest of the game stopped. Nothing else touches the chip, and the run is repeatable. Since only the driver runs, its RAM is its whole state: when that state repeats, the song has looped.
  • Convert. The log becomes a tracker song. A note is a key-on, or a jump in pitch without one. The writes that follow a note become its instrument, and vibratos become pitch lists. A row grid is fitted to where the notes fall, and the loop point is placed on a row. The grid fit and the pitch lists are code shared by all the rippers.
  • Check. The finished song is compiled by the lab page’s own player, run headless in QuickJS, and its chip writes are compared with the captured ones, through the whole song and again around the loop. Any song that differs is reported with the first frame or tick where it goes wrong, and the converter was fixed until no songs differed.

Most of the work is in the first step. You have to find out where the driver is, how the game asks it for a song, and what in its RAM counts as its state. Nothing documents this, so it came from tracing each game while it ran and reading the driver’s machine code.

Game Boy

Reverse engineering

  • A headless Game Boy written in C for this: the LR35902 CPU, the MBC1/2/3/5 cartridge mappers, the timer, LY/STAT and OAM DMA, but no pixels. Ruby drives it.
  • Every write to the sound registers (FF10–FF3F) is logged with its cycle, program counter, ROM bank and call chain. That shows which routine is the driver, and which routine calls it once a frame.
  • The emulator counts RAM reads and writes. The bytes the driver reads and the game writes are its inputs, which is how a game asks for a song.
  • The drivers were then read in a disassembler (a small one written for this, and radare2). That gave, for each game, how to start a song, how to run one frame of the driver, which RAM is the driver’s state, and which bytes only hold fractional timing.
  • Each game has its own quirks. Tetris asks for a song by writing one RAM byte. Pokémon Blue’s songs are listed in tables in three ROM banks, read straight from the ROM. Donkey Kong Land copies a song’s data into cartridge RAM before playing it. Some drivers run on the timer interrupt instead of the video frame.

Checking

  • gb.html’s own compiler must make the same writes as the game, frame by frame, once through and again around the loop. The second pass is entered from the end of the song, as it is when the song plays.
  • A second check renders the converted song and the game’s raw writes through gb.html’s sound engine, then compares the audio sample by sample.
  • The sound engine itself is tested against the hardware formulas: frequency timers, noise, length, envelope and sweep rates.
NES

Reverse engineering

  • A headless NES written in C: the 6502 (including the common unofficial opcodes), mappers 0/1/2/4/5, and PPU timing without pixels (vblank, NMI, a faked sprite-0 hit, the MMC3/MMC5 scanline interrupts). The CPU is checked instruction by instruction against the standard nestest log.
  • One script boots each game, presses Start now and then, and lists the call chains behind every sound write. The routine the NMI calls before those writes is the play routine.
  • Another lists the RAM the play routine reads, then which code outside the NMI writes those bytes, and with what values. Those writes are the game’s sound requests.
  • A probe then tries each bit of each request byte, or each value passed to a request routine, and reports what plays. Drivers were read with the da65 disassembler.
  • For eight games, the NSF rip (the music extracted for NES players) matches the cartridge. The NSF’s init code gives each track’s request, and its playlist gives the titles. Castlevania II, Kid Icarus and Zelda II only have NSFs of their Famicom Disk System versions, so they were traced in the cartridge. Zelda II has two players, one for the title and one in game, and its in-game songs depend on which world you are in.
  • The capture uses the banks the game’s NMI had mapped. DMC drum samples are read from the ROM in those banks. A loop is found when the RAM repeats, with bytes such as a random generator set aside. A loop where no channel can be heard counts as the song ending, because an idle driver with a counter running repeats every 256 frames.

Checking

  • nes.html’s compiler must make the same writes as the driver, channel by channel and frame by frame, once through and around the loop. The order of writes between channels inside a frame is not compared.
  • The APU timers, the frame counter and the length, envelope and sweep rules are tested on both NTSC and PAL.
Master System

Reverse engineering

  • A headless Master System built around the z80ex Z80 core: the Sega mapper and cartridge RAM, VDP timing (counters, frame and line interrupts), and the joypad and region ports. There is no FM unit, so games that can use one play their PSG music.
  • Every byte sent to the PSG is logged with its cycle, program counter, banks and a shadow call stack. As on the NES, scripts find the routine the interrupt calls before PSG writes, the RAM it reads that game code writes, and the entry points the game calls with a song number. Drivers were read in radare2.
  • A survey script plays every song number of a game and reports its length, whether it loops, and which channels it uses. It also records whether the game is NTSC or PAL.
  • The capture calls the driver once per frame. The whole RAM is the driver’s state, so a repeat is an exact loop. Ten silent seconds end a song.

Checking

  • On the SN76489, a write that leaves a register unchanged does nothing, except a noise-control write, which restarts the noise. So the check compares chip state rather than raw writes: sms.html’s compiler must leave the PSG exactly as the driver did at the end of every frame (tone periods, attenuations, noise control and its restarts), once through and around the loop.
Mega Drive

Reverse engineering

  • There is no emulator here. The source is each game’s VGM set from vgmrips.net, which logs every YM2612 and PSG write with its time.
  • A reader parses the VGM files: the writes, the PCM data block, the DAC runs (a seek, then bytes, which give a sample’s start, end and rate), the tags and the loop.
  • The hard part is the driver’s tick, which the log doesn’t record. A driver run by a YM2612 timer resets the timer’s flag once a tick, so those writes mark the boundaries: OutRun runs on timer A at 126 Hz, Battletoads on timer A at about 58 Hz, and Batman & Robin on timer B at 118.7 Hz. The other drivers run once a video frame, and each burst of writes starts a tick. A fixed 60 Hz grid doesn’t work, because the logged frames drift between 721 and 747 samples and the grid would move notes by a tick. With the real ticks, Sonic 2’s Emerald Hill Zone went from 1 to 6.48 ticks per row: its driver skips a frame on its tempo counter.
  • Some drivers write a channel a tick after the others (Batman & Robin: FM 5 and 6). The ripper measures that lag by lining up note starts between channels and starts those notes earlier. That took Batman & Robin from 1 to 18 ticks per row.

Checking

  • md.html’s compiler must make the same chip writes per tick: each channel’s in order, the global registers as one list, the PSG bytes in order, and the same DAC samples started. The song length and loop tick must match too. All 110 songs pass.
SNES

Reverse engineering

  • A headless SNES. Its 65816 CPU matches registers, memory and bus cycles on all 5,080,400 SingleStepTests cases. The sound CPU (SPC700) and DSP are snes.html’s own code ported line for line to C, checked to make the same DSP writes cycle for cycle. There is also DMA, NMI and IRQ timing, and the PPU only as timing. A small disassembler reads the sound drivers.
  • Chrono Trigger runs from its cartridge. The game asks for a song with a command at $7E:1E00 and a call to $C7:0004, which uploads the song and its samples to the sound module. The ripper waits for the game’s first request, swaps in the song it wants, then runs the sound module alone. A tick is each read of timer 0 that finds it nonzero. The driver adds its tempo byte to an 8-bit counter every tick and steps on overflow, and those grids guide the row fit. Titles come from the SPC set, by finding the .spc whose audio RAM holds what the upload wrote.
  • The other eleven games start from each song’s .spc snapshot. Each driver counts timer 0 its own way. Some take one tick per nonzero read (Earthworm Jim, Super Castlevania IV, and Rare’s driver in Donkey Kong Country, whose tempo bytes were found by hand). Nintendo’s N-SPC driver counts the value read (F-Zero, Zelda, Star Fox, Super Mario World, Yoshi’s Island, Super Metroid); its tempo bytes are found in audio RAM by searching for the code that adds them. Capcom’s driver (Mega Man X, Street Fighter II) gets a tick each time it reaches its catch-up loop.
  • Most .spc files were dumped just after the driver asked for the first notes and before the chip played them. The capture keys those notes on at tick 0; before that fix, one Castlevania song opened with 7 seconds of silence.
  • Tempo runs in fractions of a tick and vibratos keep their own phase, so the writes almost never repeat exactly. A loop is where the key-ons, with their samples and rough pitches, repeat until the end of a 20-minute capture.

Checking

  • snes.html’s compiler must match the capture per voice and per tick, once through and around the loop. The comparison uses what the DSP actually acts on: within a tick only each register’s last write counts, key-on is the combination of all its writes, and key-off is a pulse.
  • A loop must come round twice in the capture. A repeat found only late in the capture is treated as chance, and each voice is checked on its own instead. That caught a false 6-second loop in Mega Man X.
  • A standalone C player runs any .spc so its output can be compared with snes.html’s.

Something else?