The SID (by Stephen L. Judd)
to Bob Yannes, the SID designer
Datasheet SID 6581(Acrobat Reader .PDF 1,6Mb)
The Sound Interface Device (SID): it is one of the signature chips in the C64, but to this day a number of people still do not have a good understanding of SID -- the meaning of its registers, the idea behind how it generates sounds, etc. (I myself was in this category not so long ago).
This article exists to rectify this situation once and for all
with a general overview of the chip which everyone should be able to comprehend.
SID is pretty straightforward. There are a total of three voices. There are also three filters which the output of a voice may be run through.
SID is also used to read the paddles (i.e. potentiometer settings). All three voices have a number of features in common. There are four possible waveforms which may be selected: triangle, sawtooth, pulse, and noise. The waveform determines the basic "sound" of the sound. Multiple waveforms may be selected on a voice, which results in a sort of mashing together of the waveforms, although noise should never be selected at the same time as the others.
The frequency of each voice runs from about 0 Hz to around 4000 Hz, with 65536 steps in-between. Higher frequencies may be generated via ring modulation. According to "Mapping the 64", the exact frequency may be calculated as :
FREQUENCY = (REGISTER VALUE * CLOCK)/16777216 Hz
where CLOCK=1022730 for NTSC systems and CLOCK=985250 for PAL systems.
One of the more important features of a SID voice is the ADSR
envelope. The ADSR Envelope is quite easy to understand. Here is how to create an envelope
using a stereo: first turn the volume all the way to zero (my volume goes to 11, so it
takes me a while). Now start turning it up to some level, say 5. As soon as it hits 5,
start going back down again, until it hits 2. Let it sit at 2 until you get tired of
sitting, and then turn it back down to zero. ADSR stands of course for Attack Decay
Sustain Release. The first part, turning it up to 5, is the attack phase. Changing the
attack changes how quickly the volume goes to its maximum. The second phase, turning down
to 2, is the decay phase. Again, changing the decay changes the rate at which the volume
decays from the maximum volume to the sustain volume, which in this case is 2. Changing
the sustain value changes this sustain level. The sound will remain at this volume until
the release phase is initiated.
Changing the release value changes the rate at which the sound will decay to zero.
To start the attack phase, simply set the gate bit. To start the release phase, clear the gate bit.
There are two more important features for each voice: ring modulation and synchronization. Ring modulation produces nonharmonic overtones, i.e. gives it a bell-like or gong-like sound. Synchronization combines two waveforms in a special way, and tends to amplify higher frequencies contained in the waveform. These two features modulate the voice with the one "underneath" it; that is, Voice 1 is modulated by voice 3, voice 2 by voice 1, etc.
Ring modulation can only be applied to the triangle waveform; that is, if ring modulation is selected for voice 1, then voice 1 must have the triangle waveform selected. Using the program, start some note playing with voice 1, and select ring modulation. Then go to voice 3 and select a waveform and a frequency -- the ADSR settings may all be 0.
There are also three filters available, which may be combined. These are not separate filters for each voice, but rather one set of filters which voices may all run through. Any sound generated by SID will contain a number of frequencies. As you might expect, the filters will filter out frequencies in a special way.
To use the filters, the cutoff frequency must first be
All frequency components above or below this cutoff frequency will be reduced in volume -- the further away these frequencies are, the more they will be attenuated. The low pass filters will let all frequencies below the cutoff through, and attenuate frequencies higher than the cutoff.
The high pass filter does the opposite. The bandpass filter
attenuates frequencies on both sides of the cutoff. When low and high filters are selected
simultaneously, the result is called a notch filter.
As an example, let's say we had a sawtooth wave playing at 100 Hz. This wave contains a number of higher harmonics, in particular harmonics at 200 Hz, 300 Hz, 400 Hz, 500 Hz, and so on. If the low pass filter were selected, and the cutoff frequency was set at 380 Hz, the 200 Hz and 300 Hz frequencies would pass right through, but the 400 Hz 500 Hz etc. frequencies would be attenuated, the 500 Hz harmonic being decreased more than the 400 Hz harmonic.
Resonance is a special feature which boosts frequencies near the cutoff frequency. This creates a somewhat sharper filtering effect. The downside of the filters is that they vary quite a bit between different SID chips, so filtered sounds on one machine may sound quite different than the identical settings on another machine. The game Beach-Head even allowed the user to change the filter settings, to try to compensate for this. According to "Mapping the 64" the exact cutoff frequency is :
FREQUENCY = (REGISTER VALUE * 5.8) + 30 Hz
Note that the cutoff frequency is only 11 bits wide, i.e. has values from 0 to 2047. One other setting is bit 7 of location 54286 ($D418), which disconnects the output of voice 3. This lets voice 3 be used, in particular the envelope output register, without having to listen to it.
The waveforms are the "shape" of the sound. Sound is how two sensors on the side of your head interperet pressure variations in the air. Speakers convert changes in voltage into pressure. The waveform generators are what control this voltage.
The first waveform is the Triangle wave. This is SID's closest approximation to a pure sine wave. It starts at some value, increases up to its maximum value, then decreases down to its minimum value, and so on. Mathematically, this wave may be expressed as :
sin(x) - sin(3x)/9 + sin(5x)/25 - sin(7x)/49 + ...
so a triangle wave with fundamental frequency 100 Hz contains frequencies of 300 Hz, 500 Hz, 700 Hz, and so on. Note that the amplitude of each harmonic decreases as the square of the frequency.
The second waveform is the Sawtooth. This waveform increases up to its maximum, like the Triangle, but once it gets there it suddenly drops down to its minimum, so it is like half of a triangle. This wave may be expressed as :
sin(x) + sin(2x)/2 + sin(3x)/3 + sin(4x)/4 + ...
As you can see it has a much higher harmonic content than the triangle wave -- more harmonics are present, and their amplitudes decrease less rapidly than the triangle wave (e.g. compare sin(3x)/3 with sin(3x)/9).
Next up is the Pulse, or Square, waveform. The pulse waveform is either high or low. With SID you can set how much of the time is spent high and how much is spent low. The ratio of the time the signal is high to the time of a complete cycle is called the duty cycle. A duty cycle of 1:2 is a special case called a square wave :
sin(x) + sin(3x)/3 + sin(5x)/5 + ...
The neat thing about pulse waves is that as the duty cycle is changed the harmonic content varies widely -- try using the program to change the pulse width and it will be obvious. Pulse waves can have a very irregular energy distribution among the various harmonics; compare with a sawtooth, where the harmonics decrease smoothly.
The final waveform is the Noise waveform. Noise is simply a randomly generated waveform; that is, random values are output through the waveform generator according to the frequency setting. Obviously the result can't be written down as a harmonic expression like the above waveforms, but the frequency spectrum as a whole may be described.
White Noise contains all frequencies in equal proportion. SID generates what is known as Blue Noise: a minimum frequency is set and all frequencies above this minimum are generated with equal probability; thus SID noise is biased towards higher frequencies.
A few words about ring modulation and synchronization: ring modulation is a multiplication of two signals. To see what happens, consider multiplying two sine waves together :
sin(f1) * sin(f2) = sin(f1-f2+pi/2)/2 - sin(f1+f2+pi/2)/2
where a handy trig identity is used. The important thing to notice is that two new frequencies are generated, f1+f2 and f1-f2, with smaller amplitude and different phase. Try ring modulating a wave at one frequency with another whose frequency differs by 1 or 2. The result is two waves with fundamental frequencies slightly off from one another, which generates beats. In short, though, using ring modulation creates a whole slew of new sum and difference harmonics, which gives a bell-like sound. It should also be clear that frequencies higher than the maximum SID frequency setting may be generated in this way.
SID doesn't work quite this way, though. That is, it does indeed generate all the sum and difference frequencies, but there is no waveform multiplication going on. See the Yannes interview, for more information.
Synchronization synchronizes one voice to another. That is, if voice 1 is synchronized to voice 3, the voice 1 waveform will "start over" according to the frequency of voice 3. Adding a discontinuity like this has the effect of generating higher harmonics, and can change the pitch as well. Imagine a triangle waveform, counting downwards, when suddenly the waveform is reset to zero and starts counting up again.
The triangle is now starting to resemble a sawtooth, which, as was pointed out earlier, contains more high frequencies with larger amplitudes.
That then is a fairly complete summary of SID. For more detail on the inner workings of SID see the interview with Bob Yannes, designer of the SID chip. For information on programming SID, see just about any book on the Commodore 64. Otherwise, have some fun playing with SID!