The SID chip
The Commodore 64 (1982) sold in the millions, and its sound chip, the SID (Sound Interface Device), is a large part of why it’s remembered. Bob Yannes, who designed it, was a synthesiser enthusiast who wanted a real synthesiser on a chip, not the beepers other home computers had. He got close: three voices, each with four waveforms and its own envelope, sync and ring modulation between them, and an analogue filter that could sweep and resonate. (He went on to co-found the synthesiser maker Ensoniq.)
Where the Amiga’s Paula, on the trackers page, played recordings, the SID makes its sounds from nothing, as the synthesisers on the subtractive page do. Composers such as Rob Hubbard, Martin Galway, Ben Daglish and Jeroen Tel wrote music for it that people still listen to, and its demoscene is still finding new tricks.
The chip is controlled through 25 registers: a byte each, written by the computer’s processor. Each figure here shows which registers it’s setting. The chip is modelled cycle by cycle, close to how it’s built where that’s documented; where real chips are analogue and vary from one to the next, the page says so.
It leans on:
- Carving away harmonics, for oscillators, envelopes and filters, and A synth to play for sync and ring modulation.
- Trackers and MOD files, for arpeggios, and playing samples on 1980s hardware.
- The first page’s instructions for playing the figures.
1 · An oscillator is a counter
Section titled “1 · An oscillator is a counter”Each voice’s oscillator is a 24-bit counter, the accumulator. On every tick of the chip’s clock (985,248 times a second, on a European PAL machine), it adds the voice’s 16-bit frequency register to itself. When it goes past its top, it wraps round to the bottom, and starts again. So the bigger the number added, the faster it goes round, and the higher the pitch:
All four waveforms are read off that one counter:
- Sawtooth: the counter’s top 12 bits, as they are: a ramp up, then a drop.
- Triangle: the same bits, flipped while the counter’s top bit is set: up, then down.
- Pulse: high while the top 12 bits are below the pulse width register, low after.
- Noise: a separate 23-bit shift register (an LFSR), which steps to a new pseudo-random state whenever bit 19 of the counter goes from 0 to 1, so its “pitch” follows the counter too.
Three cycles of a note, as the counter climbs and wraps (top), and the four waves read from it. A4 needs a frequency register of 7,493, which plays 440.03 Hz: about a tenth of a cent sharp. Play the keyboard to hear any of the waves.
2 · Aliasing, at a megahertz
Section titled “2 · Aliasing, at a megahertz”The subtractive page showed that a sawtooth worked out at the sound card’s rate aliases: its harmonics above half the sample rate fold back down. The SID works out its waves at its clock rate, about a million times a second, and its output is analogue. It does alias, but around its clock, at half a megahertz, where a sawtooth’s harmonics are far quieter.
The SID’s sawtooth (top), worked out every cycle of the chip, against the same sawtooth worked out at 48 kHz (bottom), with their aliases in pink. On A5, the SID’s strongest alias below 8 kHz is at −60 dB; the 48 kHz one’s is at −33 dB. On A4 it’s −67 against −39, and on A6 −54 against −27. (The SID’s numbers include the step from this model’s million samples a second down to your sound card’s rate, which is done carefully enough not to add aliases of its own.)
3 · Combined waveforms
Section titled “3 · Combined waveforms”A voice’s control register has a bit for each waveform, and nothing stops you setting two at once. The chip’s designers didn’t intend it: the waveforms’ outputs are simply connected together, and where one wants a bit low, it pulls it low. The result is roughly the two waves’ bits ANDed: high only where both are. Real chips do it with analogue transistors fighting each other, so the result differs from chip to chip, and between the 6581 and 8580; accurate emulators use tables measured from real chips. The figure shows the simple AND, but composers used these sounds, especially triangle + sawtooth and sawtooth + pulse, for thin, nasal, organ-like tones.
The chosen waves (dashed) and what comes out when both are on (solid): high only where all of them are. Play them on the keyboard: each combination has its own thin, buzzing colour.
4 · The envelope, and hard restart
Section titled “4 · The envelope, and hard restart”Each voice’s envelope is an 8-bit counter, 0 to 255, which scales the wave. Setting the gate bit starts the attack: the counter climbs. At 255 it decays down to the sustain level, and stays there until the gate is cleared, when it releases to 0. Attack, decay and release each have 16 settings, from 2 ms to 8 seconds for the attack. The decay and release are made to fall roughly exponentially by stepping more slowly as the level gets lower: straight-line pieces, with the steps slowing at levels 93, 54, 26, 14 and 6.
How fast the counter steps is set by a second counter, a 15-bit one that counts the chip’s clock ticks up to the rate’s period, then steps the envelope and starts again. Here’s the catch. If the period is changed to one shorter than the count already reached, the count has already gone past it, and has to go all the way round (to 32,768) before it can match. Change from a slow release to a fast attack at the wrong moment, and the attack doesn’t start for up to 33 ms: a note that should snap in lags, or comes out quiet.
So music drivers do a hard restart: a frame or two before each new note, they set the envelope’s registers to 0 (the fastest rates) and clear the gate. The rate counter is then sure to be counting to a short period, and the next note’s attack starts at once.
A note held for 300 ms, let go, and the next note played 60 ms later. Top: played straight, the second note’s attack starts only after 32.6 ms (it waits while the rate counter goes round). Bottom: with a hard restart two frames (40 ms) earlier, it starts within 0.1 ms. Change the settings and the gap: the delay depends on where the counter happened to be.
5 · Sync and ring modulation, as the chip does them
Section titled “5 · Sync and ring modulation, as the chip does them”The synth page explained sync and ring modulation in general. The SID does them its own way, between neighbouring voices: voice 1 takes its timing from voice 3, voice 2 from voice 1, and voice 3 from voice 2.
- Sync: each time the other voice’s counter wraps (its top bit goes from 0 to 1), this voice’s counter is reset to 0.
- Ring modulation isn’t a multiplication. It works only on the triangle: while the other voice’s top bit is set, the triangle is flipped. That’s the triangle multiplied by a square wave at the other voice’s pitch, which is harsher and more metallic than multiplying two smooth waves would be.
Voice 1 against voice 3 (which is silent here: its only job is the timing). Voice 3’s top bit is high for the first half of each of its cycles. With sync, voice 1’s sawtooth restarts at the start of every one of voice 3’s cycles; with ring modulation, voice 1’s triangle is turned upside down while voice 3’s top bit is set.
6 · The filter
Section titled “6 · The filter”The SID has one filter for all three voices, and a bit for each voice saying whether it goes through. It’s an analogue state-variable filter, the kind on the synth page, with low-pass, band-pass and high-pass outputs, each switched in with a bit, so they can be combined: low-pass + high-pass makes a notch. Its cutoff is an 11-bit register, its resonance 4 bits, and its slope 12 dB an octave.
Because it’s analogue, the cutoff a register value gives depends on the chip. The 6581’s curve is anything but straight, and differs from one chip to the next, so a tune’s filter sweep sounds different on different machines. The later 8580 (in the C64C and later machines) has a far more regular filter, close to a straight line from 30 Hz to 12 kHz, but it sounds different again, so composers had to choose.
Top: the filter’s response at these settings (a curve from the formula for an ideal state-variable filter, with the SID’s resonance). Bottom: what the cutoff register means in hertz on each chip. The 6581 curve is a rough fit to a typical chip, from about 220 Hz to 18 kHz; the 8580’s is close to straight. Play the keyboard: a pulse wave goes through the filter.
7 · How C64 music was written
Section titled “7 · How C64 music was written”There were no trackers at first. A C64 composer, or the programmer working with them, wrote a music driver: a small program in machine code that the computer runs once every screen refresh (50 times a second on a PAL machine), alongside the game. (The C64’s processor is a MOS 6510: a 6502 with a small built-in port, which the C64 uses to switch its memory around and to drive the tape deck.) Each time, it moves the song on by one frame: reads the next notes, steps each instrument’s tables, and writes the registers. Everything moves in those 20 ms frames:
- Arpeggio chords: one voice steps through the notes of a chord, a note a frame, as on the trackers page. With three voices, a chord on one leaves two for the bass and the drums.
- Pulse-width sweeps: the pulse width changes a little every frame, which gives a static pulse the moving, chorus-like sound of the C64’s basses.
- Filter sweeps: the cutoff moves every frame, slowly or in a quick “wow”.
- Wave tables: an instrument can change its waveform, and its pitch, every frame. That’s how drums were made from oscillators. Rob Hubbard’s driver for Monty on the Run (1985) shows the idea at its simplest: a drum plays noise for its first frame only, then its own waveform (a square, for a bass drum), while every frame the top byte of its frequency drops by one. That’s a fast slide from high to low, with a quick decay: a click of noise, then a thump.
This page’s tune is played by a driver like that, written in this page’s code: four chords, then the same four with a tune on top, with every instrument made from tables. Its kick drum is made Hubbard’s way; its snare takes turns between noise and a falling pulse. Underneath, it shows every register write, frame by frame: a burst of them every 20 ms, which is all the chip ever sees.
Press Play: each frame’s register writes appear here.
Press Play. The table shows the 25 registers as they change (each voice’s frequency, pulse width, control, envelope settings, and the filter); below it, each frame’s writes. Mute voices to hear them separately, and switch between the two chips. The drums’ wave tables are listed below: play each one on its own.
Notice the hard restarts on the bass, the chords and the tune: two frames before each of their notes, the
voice’s envelope registers drop to 00 and its gate bit clears, then on the note itself they’re set again
with the gate on. (The drums don’t need one: they start from silence each time.)
8 · Samples through the volume register
Section titled “8 · Samples through the volume register”The SID has no way to play a sample. But it has a 4-bit master volume register, and on the 6581, the mixer has a small offset of its own (a steady voltage) that the volume scales. So writing the volume register moves the output up or down by a step, with no voice playing at all: a click. Write it thousands of times a second, at the right levels, and the clicks make a sound: a 4-bit sample, 16 levels. That’s how C64 games talked, and played sampled drums.
The processor has to write every sample itself, at exactly the right moments, which leaves little time for anything else. A common timing source was the screen: the video chip interrupts the processor at chosen screen lines, and a PAL screen draws a line every 63 cycles, 15,640 lines a second.
The 8580 has almost no offset of its own, so on it the trick is nearly silent. The usual fix is to give the mixer something to scale: a voice set to output a steady level (the test bit holds its pulse wave high, with the envelope fully open).
Demo coders kept going. In 2008, Otto “SounDemoN” Järvinen used a voice’s test bit and triangle wave as a sample-and-hold, for about 5 to 6 bits at 16 kHz, though quietly, and at the cost of four register writes for every sample. In 2014 Pex “Mahoney” Tufvesson’s demo Musik Run/Stop played samples at 44 kHz, with one write per sample, to the same register as the volume. His trick was to write the whole byte: the 4-bit volume, but also the filter’s three mode bits and the bit that switches voice 3 off. With every voice set to a steady maximum, two of them routed to the filter and one not, he found the chip’s quirks made each of the 256 values a different level:
- With no filter mode chosen, voices routed to the filter pass straight through instead.
- Switching voice 3 off works only while it isn’t routed to the filter.
- The filter’s output is inverted: a gain of about −1, not +1.
The 256 levels are unevenly spaced, and differ from chip to chip, so he measured many real 6581s and 8580s and made a table: for each level wanted, the byte to write. The result is far better than 4 bits, though not a clean 8. This page’s model follows those three quirks, but none of the analogue imperfections behind the real chips’ measured levels: with just those rules, the 256 values give 91 different levels on its 6581 and 54 on its 8580.
30 ms of the sound (faint), and the 16 levels the volume register can give it (solid). Play it through the model chip: on the 6581 it comes through by itself; on the 8580 it’s silent unless the mixer is given a steady level. Rounding this sentence to 16 levels leaves its signal 8.3 dB above the noise: speech spends most of its time well below its loudest peaks, where there are only a few levels to use. Record yourself to try your own voice.
9 · What’s in a .SID file
Section titled “9 · What’s in a .SID file”C64 music is collected as .SID files: the High Voltage SID Collection has tens of thousands. But a .SID file isn’t like a MOD file. A MOD is data: samples and a score, in a format any player can read. A .SID file is a program: the composer’s own music driver and its song data, exactly as they ran on the C64, plus a short header that says:
| Field | What it says |
|---|---|
PSID or RSID | what kind of file it is (RSID tunes need more of the real C64 around them) |
| load address | where in the C64’s memory the code and data go |
| init address | the routine to call once, to start a song (with the song’s number) |
| play address | the routine to call 50 (or 60) times a second, to play it |
| songs, start song | how many tunes the file holds (games often had several) |
| name, author, released | 32 characters each |
Every composer invented their own driver and their own way of storing music, so there’s no format to read. To play a .SID file, a player has to run its code: it emulates the C64’s 6510 processor, with enough of the rest of the machine around it, calls the init routine, then the play routine every frame, and passes the register writes to an emulated SID, much like this page’s. To go further:
- DeepSID plays the whole collection in a browser.
- sidplayfp is a player for the command line, built on the same emulation (reSID) many players use.
- VICE emulates the whole Commodore 64 (and its relatives).
10 · A SID to play
Section titled “10 · A SID to play”The whole chip, three voices: play up to three notes at once. The settings apply to all three voices, and the registers show what the keyboard is writing.
The registers, as the computer would write them: each voice’s frequency (two bytes), pulse width (two), control (the waveform bits, sync, ring and the gate), attack/decay and sustain/release; then the filter’s cutoff, resonance and routing, and its mode and the volume. Hold a key and watch its voice’s gate bit (the control register’s lowest bit) go on; let go, and it clears.
Summary
Section titled “Summary”- Each of the SID’s three voices is a 24-bit counter; the frequency register sets how fast it goes round, and the sawtooth, triangle and pulse are read from its top bits. Noise is a shift register stepped by it.
- It works at its clock rate, about a megahertz, and its output is analogue, so its aliases are far quieter than those of a wave worked out at an ordinary sample rate.
- Two waveforms at once give combined waveforms: roughly the two ANDed, but analogue and different on every chip.
- The envelope’s rate counter has to go all the way round if its period is shortened past it, delaying an attack by up to 33 ms; music drivers use a hard restart to avoid it.
- Sync and ring modulation come from the neighbouring voice; the ring modulation flips the triangle by the other voice’s top bit.
- One analogue filter, low-, band- and high-pass in combination, whose cutoff curve differs between the 6581 and 8580, and from chip to chip.
- Music was played by drivers, programs run 50 times a second, writing the registers from tables: arpeggio chords, pulse-width and filter sweeps, and drums made by changing waveforms frame by frame.
- Samples were played by writing the volume register thousands of times a second: 4 bits, and, using the same register’s other bits and the chip’s quirks, far more.
- A .SID file is the driver itself, so playing one means emulating the C64’s processor.
Further reading
Section titled “Further reading”- Commodore 64 Programmer’s Reference Guide (Commodore Business Machines and Howard W. Sams, 1982): the SID’s registers, and its datasheet’s envelope times.
- reSID, Dag Lem’s cycle-exact emulation of the SID, and the source of most of what’s known about the chip’s insides (including its combined waveforms and filters).
- Robin Harbron, Levente Harsfalvi and Stephen Judd, “The C64 Digi”, C=Hacking: how volume-register samples work, in detail.
- Pex “Mahoney” Tufvesson, Technical details of Musik Run/Stop: playing 8-bit samples at 44.1 kHz on a computer from 1982 (white paper, 2014): the measurements, the table and the playing loop, at mahoney.c64.org.
- Anthony McSweeney, “Rob Hubbard’s music: disassembled, commented and explained”, C=Hacking issue 5: the Monty on the Run driver, line by line, drums included.
- The High Voltage SID Collection, with documentation of the .SID file format.