================================================================================ SID-Article 0.1.2 MOS Technology SID soundchip internals and applications on the Commodore 64 ================================================================================ Who is SID? The soundchip that contributed heavily to the success of the Commodore 64 personal computer. It's unique among the soundchips with its outstanding sound quality and capabilities for the microcomputer era. Designed in 1982 by Bob Yannes's team, it sported synthesizer techniques yet unseen with other computer brands: analog filter and mixing combined with highly flexible digital control of 3-channel pitch, timbre, volume and cutoff curve. It shortly became the beloved playground of great musicians making music for game industry, like Rob Hubbard, Ben Daglish, Tim Follin, just to name a few of the first sailors. Thanks to its capabilities it still achieves juicy sounds today in good hands, be it any music genre or trend, like Drum'n'Bass and Dubstep wave, for instance. Every now and then new possibilities of SID are revealed by creative demoscene enthusiasts who create new pieces of music for games, demos or just for fun. What is this document about? I mostly cover the internals of how the SID works behind the scene, but that doesn't mean this document is for geeks only. I'll try to make it an explanatory easy read, gradually increasing the complexity. Even when a harder to undersand part comes I'll try to explain it in the simplest way, accompanied by pictures. SID musicians who want to get a deeper understandig of the Hard Restart and other mysterious workings of the SID will probably find parts of this document just as beneficial as music-player routine developers or implementors of software/hardware SID-emulation engines. In my opinion whatever you use in your life, you can utilize it better if you know its internals, than treating it as a mere black-box. It's up to you whether you feel genious enough to compose SID music by instinct or you try to ever expand your knowledge. I found many resourceful materials about SID already on the internet when I developed SID-Wizard, SwinSID-Ultimate and jsSID/cSID engines, but it can be very tiresome to dig them all up from different places. There is an overall technical document about the graphic chip of the C64 called VIC-article. To my surprise there were still no such kind of texts for the SID. Some of my sources were an interview with Yannes, the source-code comments of Dag Lem's ReSID and the ReSID-FP engine, the Kevtris reverse-engineering site, a document about DC levels by Levente Hársfalvi, and my very own findouts I'll explain later. So hopefully I collected enough information for you in this article at one place to get the big picture. :) Revisions, residence and pinout of SID There are two major versions called by their partnumber: the original one is called '6581' and the new refined SID is '8580'. The 6581 can be found in the top-middle region of the old C64 mainboards and it requires 12V power-supply for its analog circuitry beside the 5V digital supply. The 8580 is found slightly to the right at the bottom of new C64 boards and it requires 9V and 5V power rails. There are two external capacitors to support the filter circuits integrated into SID. These capacitors are quite different in value for old and new models, therefore the SID versions are not readily interchangeable without any modding. 6581 models also prefer an 1kOhm resistor towards ground on their output for the simplified output-stage driver circuit. At least their 28-legged DIP package form-factor is the same so they fit into each others' sockets without any hassles. Both models are nearly equivalent in their digital portions, but the different silicon process they are based on (6581:NMOS, 8580:HMOS-II) and the different designs make apparent differences how their analog circuits sound like, especially mixing, filter curves and combined waveforms. More on these later... There are big differences even between 6581 revisions themselves. (A 6582 model was also released but it's internals are of the 8580, only the label differs.) How does C64 control SID? (Registers) The method to control the sound-parameters of SID is called Memory-mapped I/O. This means the Commodore 64 sees the SID at address $D400..$D420 (hexadecimal) and it can write the internal registers ('control-bytes') of the SID just like any other portion of the memory. Whenever you write to these addresses you essentially modify the flip-flops inside the SID, which in turn sets parameters like pitch, envelope, filter, etc. in real-time. Simple, isn't it? (More SID chips can be added to the C64 and in that case their base-addresses differ from $d400. There's no specification yet where they should reside.) Most registers are write-only and you can't read them back, but there is also a little feedback from SID towards the C64 in the form of read-only registers, not to mention bit-fading which makes tricks like Hein's ROR D400,X possible. Let's see the registers one-by-one for the 3 channels: 1: D400,D401 Pitch low- and high-byte. These bytes together control the pitch 2: D407,D408 of the oscillators. 16 bits give us quite enough resolution to make 3: D40E,D40F perfect pitches in the region of 15Hz to 3848Hz (PAL) with equal steps of cca 0.06Hz. Human ear and brain perceives pitches in a non-linear fashion, that is we hear less difference between the equal frequency steps in higher regions than in the lower. Every upper octave has twice as much of the frequency as its lower counterpart. So for scales of musical notes we need to have a frequency-table to map them into these SID frequency-values. In the most widely used equally tempered chromatic (western) scale successive notes have the frequency-ratio of 12th root of 2. 1: D402,D403 Pulsewidth (duty-cycle) of the square waveform. This is a really 2: D409,D40A important feature of SID because variations of the pulse (square) 3: D410,D411 wave has very different spectral characteristics. This is really useful for smooth transitions between timbres (called sweep) that makes a sound more lively than a monotonic beep. Solo instruments are created this way most of the time. Fast-sweeping of pulsewidth enriches the spectrum of the sound and adds a kind of chorus effect. Luckily the shape of some combined waveforms can also be altered by the duty-cycle setting, giving even more timbres to choose from. The upper byte has only the lower nybble (4 bits) wired in so there are 4096 possibilities of pulsewidth to choose from, between 0 and 100% duty-cycle from the thinnest to the fattest sound. One of the strengths of SID is that it essentially operates at 1MHz 'sampling' frequency and the thinnest sounds are clear. This is not always the case with emulated SID sounds of only 44kHz or so. 1: D404 Waveform and envelope-control. This register have bits that control 2: D40B different things separately. The upper nybble controls which of the 3: D412 4 available waveforms are turned on. They can also be turned on at the same time due to the properties of the underlying silicon technology. This results in the the so-called 'combined waveforms' which Bob Yannes is officially against of, which is understandable because these connect some outputs togenther. Never mind, these are used in many masterworks from the beginning. The new 8580 has more defined and louder combined waveforms. How this is done, deserves a separate topic in this article, stay tuned... Control-bits of the waveform: bit7($80): noise, bit6($40):pulse bit5($20): sawtooth, bit4($10):triangle If none of the waveforms are selected then the floating of the last wave-output value can be observed for a while, then it decays, on a real C64 the duration is temperature (uptime) dependent. The oscillator in the SID can anytime be reset and stopped by the bit3 (value:8) 'TEST'-bit turned on. It was probably implemented in SID for factory testing but it comes handy as a tool in chipmusic. Whether it generates a high or low steady output depends on the selected waveform. (Contrary to a misbelief, test-bit doesn't have any effect on the envelope-generator, but the oscillator only.) If you want really special, jawdropping tones, there are 2 more weapons to utilize, one is bit2 (value:4) 'RING'-modulation, the other is bit1 (value:2) channel-'SYNC'. Ring-modulation has effect only on the waveforms containing triangle but not sawtooth, and in a nutshell it mirrors/folds the wave's upper half when the neighbor channel's oscillator is in the 2nd half of its period. This creates richer spectrum and very interesting effects including formant-like sounds, all without filters. Channel-synchronization on the other hand resets the oscillator whenever a neighboring oscillator enters the 2nd half of its period. This also creates fascinating waves that resemble human voice (where formants are synced to vocalcords) The controlling channels in these scenarios are always the lower channels. For example, channel 2 is controlled by channel 1. Mostly these 2 functions are mastered by experimenting as it's hard to get a grasp how it really works and to estimate the results. As with the waveforms, ringmod and sync can be combined together. Last but not least there is the 'GATE'-bit which does more than one would think at first sight. It controls the volume-envelope of the generated waveform: starts and stops the notes, so to speak. 1: D405,D406 Attack/Decay and Sustain/Release ADSR envelope generator settings. 2: D40C,D40D When GATE-bit is turned on, the 'ADSR' envelope-generator starts an 3: D413,D414 'attack' phase, thus it starts the sound and if it's kept active, the volume rises at the rate of the corresponding ADSR setting until it reaches the maximum level. Then it falls to the 'sustain' level at the rate of 'decay' setting. Turning off gate-bit starts the 'release' phase, which means the note-volume falls towards zero at the rate of the 'release' setting. Though this is the basic operation of the GATE-bit, it can be turned on/off during any phase of the ADSR envelope. As a rule of thumb when it turns on it always starts an attack phase, and initiates release when it's turned off, though the envelope isn't reset to 0 if it's in the middle region. But unfortunately, with SID life is not so simple. As you will see later in the more thorough explanations, ADSR sometimes does not do what it's told to. You'll get weaker or even missed notes with certain ADSR values and GATE-triggering schemes. No, it's not a 'humanize' function intentionally built into the SID. I think the reason is the resourcefullness that was a must for people making VLSI chip design in the beginning of 80s. Maybe some rush came on top of it too, so ADSR rate-counters are never reset in SID. It would be logical to reset them when a note gets triggered by the GATE-bit but that's not the case. What worsens it further is the fact that the counters can overlook their rate-settings. I'll explain it later, for now on it's enough to know that luckily people came up with a solution long ago: the 'Hard restart'. The optimal way to reset the ADSR before triggering notes is still a subject of discussions at CSDb forums. Different music players implement it in slightly different ways. There are also some less known wraparound issues in the envelope-generator that I'll explain in the upcoming parts of this document. Attack happens on a linear scale Here's a list of Attack times on PAL C64: 2ms, 8ms, 16ms, 24ms, 38ms, 56ms, 68ms, 80ms, 100ms, 250ms, 500ms, 800ms, 1s, 3s, 5s, 8s Decay and Release has a longer (3 times Attack) non-linear curve. D415,D416 Filter cutoff-frequency control low- and high-byte. One of SID's strengths is its analog filter. The process of creating raw waves with rich spectral content and then filtering out some of the components is called substractive sound-synthesis, the SID way. The filter is common for all the channels but it can be applied to them separately on demand. Once the filter is set on a channel the cutoff-frequency can be controlled at 11bit resolution. (Low-byte has only the lower 3 bits implemented, the others have no effect.) On the 6581 the curve of the cutoff-control is nonlinear, with cca 200Hz below a 'threshold' and often the basses sound more muffled compared to the 8580 which has nearly perfect linear control-curve. (But again our ears hear the same difference at low frequencies better than at the high ones so we perceive it as nonlinear too.) As a flipside the 6581 cutoff frequency can go up to the top of hearable range while 8580 can go down near 0Hz but tops at ~13kHz. 6581 has an interesting distortion at low frequencies which I will explain later. 8580's new filter-design lacks this 'feature' and there's only distortion when high resonances boost the signal. D417 Filter-switch and resonance. The high-nybble here controls the resonance of the filter, the hump at the cutoff frequency. Filter sounds more prominent with this setting than a neutral curve with no emphasis. This behaves differently for the SID-models similarly to the cutoff-control: 6581 has no much change up to a point while 8580 resonance-control is continuous, although it's non-linear. Setting high resonance can lead to distortions as the magnified signal's level approaches the limits presented by the 9V/12V power. The low nybble has 3 bits dedicated to turn filter on/off on the channels: bit2(value4):channel3, bit1(2):channel2, bit0(1):channel1 The amount of filtered channels has a little effect on the cutoff and resonance, but it's not very much noticable. Bit3 (value:8) is the switch for the external audio input which can be fed to the SID and mixed into the output beside the internal channels. Some people use this bit to decrease noise coming into the SID from outside by filtering it out. Originally it might have been added so that SID could be used like a wah-effect pedal. D418 Main volume and filter-band. The low nybble of this register has control over the main volume of the SID. There is a little bit of leakage though, so even when you set it to 0 it passes through a little amount of sound. The more important fact about this nybble is however, that it causes a little shift in the output signal. The bigger the volume the more the offset is. This is very useful to play 'digis' since the 80s. This effect is much less noticable in the refined 8580 circuitry, so this is a classical problem with new C64 machines that digitalized speech is barely hearable. But this somewhat compensates for the harsh clicks of the 6581 that appear when the master volume or filter-parameters are changed. High nybble of this register has 3 bits that control what kind of filter to use: bit6(value $40): high-pass, bit5($20):band-pass, bit4($10):low-pass These modes can be combined together to form a notch-filter or a low-pass filter with brighter sound, whatever. Bit7 (value:$80) has a special function, it can prevent channel3 from going to the mixer, though it's still passed to the filter, so this has no effect on a filtered 3rd channel. The idea was to use channel3 as a LFO (low-frequency oscillator) to control parameters without the need of the CPU to do that task. But in practice we don't want to lose a precious channel when the CPU can create any control-waveform easily. So let's leave this bit at zero, please. D419,D41A POTX,POTY Paddle read values. SID took the responsibility for reading analog resistance values on the C64 inputs. Mostly for paddles to control games but mouse can be connected to these inputs or any potentiometer with around 500kOhm maximal resistance to utilize the full range of 0..255 values. Voltage can't be applied to these inputs to digitize sound, etc. It works by charging and discharging a capacitor through the connected resistance and it determines the resistance periodically by how much time it took to charge the capacitor. Unfortunately this measurement has a jittering even with steady input. Software-based filtering can help to smooth this out. (A 'moving average' filter proved to be fine.) D41B,D41C OSC3 and ENV3. These are the 8bit readable registers that represent the waveform-selector and envelope-generator outputs of the 3rd channel. In combination with the channel3 disabling mentioned before these can be used as LFO in rare cases. But a more useful feature is to determine which model of SID is present in the machine by checking for waveform and envelope differences. I used these registers many times to display an oscilloscope for the 3rd channel or control graphic effects by the music. Use your imagination what else it could be used for. How does SID produce sound? (SID-internals) A simplified block-diagram for SID's internal circuitry: _ Capacitors<-->| | .-------------. Gate, CutoffFrequency=>| | Main Potmeters ->|Switched-Cap.| Test, LowPass->|A| Volume .---. | ADC | Ring, (ADSR BandPass->|N| | | | |<=='-------------' Sync Apmlitude- HighPass->|A| .-. D |D|R|=>Freq,PulseWidth,.. | Modulators) |L| |M| A |A|E|=> Oscillator1 -> Waveform -> Envelope -> Filter --->|O| |A| T |T|G| Generator1 Generator1 Switch1-. |G|->|I| A |A|I|=>Freq,PulseWidth,.. | | | |->|N| B<=>|B|S|=> Oscillator2 -> Waveform -> Envelope -> Filter -|->|F|->| | U |U|T| Generator2 Generator2 Switch2-+ |I| F|O| S |F|E|=>Freq,PulseWidth,.. | | |L| i|U| |F|R|=> Oscillator3 -> Waveform -> Envelope -> Filter -|->|T| l|T| A |E|S| Generator3 Generator3 Switch3-+ |E| t|P|->Audio D |R|_|<================(OSC3,ENV3) | |R| e|U| Output D '-'| Filter -|->| | r|T| R .---^---------------------------------------. Switch -+ | | e| | E=>| Chip Access Control | External | '-' d|M| S '-------------------------------------------' | | |I| S-BUS, ChipSelect , R/Wn , Clock(phase2), Reset External `------>|X| AudioInput Non- |E| Filtered|R| '-' Phase-accumulators (oscillators, pitch) First of all, let's start with the three oscillators. Without oscillation a sound could never be heard through the air, you know. In the SID this is done by the 'phase-accumulators'. A phase-accumulator is basically a 24bit counter which can be incremented not only with a single step each clock but from 0 to 65535 steps. That 16bit value which we can add at each clock pulse directly determines the frequency of the oscillation. How? The phase accumulator wraps around when it reaches its maximal value, and starts over to count up again. This represents a sawtooth-like waveform. We build upon this base in the next stages of the sound-generation chain. The master clock-frequency and so the SID clock is 985248Hz in the PAL C64. If the frequency value is 0 in the frequency-registers we don't add to the phase accumulator, the oscillation is stopped. Adding 1 gives the lowest hearable frequency we can produce. With the 24bit phase-accumulator it takes 24th power of 2 clock pulses to fully count up, so at the C64 clock frequency this happens 17 times. 17Hz is the lowest. Adding 65535, the maximal value needs 256 clock steps to reach the top, so the highest pitch can be 3849 Hz. Beside pitch-setting we have some more control over the phase-accumulators, they can be zeroed (reset) by: -Setting TEST-bit (mentioned above) to 1 on the corresponding channel -When SYNC-bit is 1 on a channel, the phase-accumulator on that channel is zeroed at the moment the other (source) channel's MSB (bit23) rises to 1. (Again, Sync source-to-destination channel-pairs are: 1->2 , 2->3 , 3->1 ) Waveform-generators (unfiltered waveforms/timbres) As mentioned before we have 4 basic waveforms to choose from on each cannel. They are created in different ways in 12-bit resolution. Sawtooth is the simplest one, it's simply the upper 12 bits of the phase-accumulator. Pulse/square-waveform is derived by comparing the pulsewidth/duty-cycle registers (value 0..4095) to the current top 12 bits of the phase-accumulator, and connecting all output-bits to 1 (Vcc) when it's greater, and to 0 (GND) when it's smaller. Triangle waveform is made from the phase-accumulator (sawtooth) by XOR-ing all of its 11 upper bits with its MSB (bit23). This causes the folding back of the 2nd half of the sawtooth-wave giving the triangle waveform. But as this has a halved amplitude, the 12-bit wave-output must be generated from the left-shifted form of this, so the output has the same amplitude as sawtooth's. The ring-modulation for triangle is achieved by enhancing the above-mentioned MSB XOR-ing with an extra XOR if the RING-bit is set. This extra XOR with the MSB happens whenever the source (modulation) channel's phase-accumulator-MSB is 1. In other words, the triangle is inverted/flipped by the other channel (again, Ring source-to-destination channel-pairs are: 1->2 , 2->3 , 3->1 ) Noise waveform has its own 'counter' in the form of a pseudo-random sequence generator. It's realized by a 23-bit LFSR (Linear Feedback Shift-register), which is a shift-register that when clocked, simply shifts its 0/1 contents to the 'left'. What makes it an LFSR is the feedback mechanism that generates the signal to be fed back to its rightmost bit (LSB). There are so-called 'taps' on carefully selected places, bit 22 and 17 of the LFSR, that are XOR-ed and that value is fed back to the LSB. This generates a very long sequence of pseudo-random values before it repeats. The LFSR is clocked by the rising edge of bit19 of phase-accumulator so the noise spectrum, the sense of pitch can be controlled. With TEST-bit enabled the feedback can be forced to 1 in the LFSR so it can be filled with 1s over a cca 8000 cycles' period, reaching the value of $7FFFFF which is probably the initial value of it at startup. The 23bit LFSR value still has some linearity/predictability between the adjacent bits so we take the noise-output from a so-called 'scrambler' instead. In case of SID the scrambling is simply done by using 8 different bits of the LFSR to contribute to the wave-output (bit 20,18,14,11,9,5,2,0) which has only 8 bits of resolution, enough for a noise. The 4 low-bits are not used for noise. Waveform-routing: Now we have the 4 basic waveforms (still digital, 12-bit wide) generated and ready for routing. Inside the SID there are pass-transistors (FETs) on all 12 bits of the waveform-outputs acting as series-switches to select which of the 4 waveform-ouptputs we want to route to a channel's output bit-drivers. Ideally only one of them is turned on at a time but there's no multiplexing logic to ensure that. This brings us further possibilities. Bob Yannes himself discouraged the usage of combining the waveforms by turning more outputs on, probably because connecting active output-drivers together is never a good idea in electronics, they will fight against each other if one wants to drive a low signal while the other wants to drive a high signal. However, in chips made by NMOS and HMOS chip-fabrication technologies the driving strengths of outputs are less for high logic signals than for low, due to the 'upper' MOSFETs used as 'active'/'dynamic' resistors. (CMOS can drive both logic values equally as strong, that would be more prone to high currents and failures if SID was ever to be recreated with this up-to-date technology.) In practice there are no reports that SIDs went wrong due to the usage of combined waveforms but who can tell? They can become hot enough by the standard usage already... Combined waveforms (more thorough explanation): During the development of jsSID I made researches how the complex combined waveforms are generated. (I could generate them by functions, see jsSID source code for more details and ASCII schematics.) If you look at them closely you probably notice that they look like fractals, small portions of them resembling their overall shape. It's logical to deduce from this that there is some recursive bit-wise reason for that. Checking on the great reverse-engineering results of decapped SIDs at Kevtris page revealed the circuit of the above-mentioned waveform-selector logic. There are simple amplifiers for all of the selected (routed) waveform-bits before the DAC (Digital-to-Analog) stage. The waveform-combining happens BEFORE these bit-amplifiers and DAC, so the combining is not made on the analog outputs, but bit-by-bit in the previous digital stage. To understand how the combined waveforms are generated, the analog behaviours of this digital circuit-region needs to be discussed. The 3 crucial analog contributors are the above mentioned weak driving of high-bits, the resistance of chip-fabric and the threshold-level of the amplifiers before the DACs: For example, take the simplest case: when you connect sawtooth and pulse waveforms together, you connect all their bits together through a weaker connection, because that is what square waveform does, as explained above, it connects all 12 bits to GND or power-rail. If the square/pulse output is 0, driving it to GND is so strong that no matter if the sawtooth-bit wants to drive 1, it will be below the threshold of the bit-amplifier so the DAC gets 0 to output. But when the pulse-output is 1 the bits are driven by it to high only 'weakly'. In that case a 0 sawtooth-bit can bring the combined bit-value low enough to ensure 0 at the output of the bit- amplifier and the DAC. This sounds like an AND operation between the pulse and sawtooth waveform-bits, and we would get a sawtooth if pulsewidth is 100%. But it's not that simple: as the pulse-waveform connects all bits together through a given resistance (depending on the chip-technology) it's possible for neighboring bits of the sawtooth to affect each other. The closer a bit to the other bit is, the more it pulls it down towards 0 or up towards 1, vice-versa, eventually agreeing on a level that is above / below the bit-output's threshold. This is the recursive process responsible for the fractal-like look. (In code I made it by two nested for loops where each bit has a value affected by all the others. With proper parameters the waveforms were very close to the original.) It's worth noting that if you look at a pulse+sawtooth with 100% duty-cycle, the combined waveform samples don't go above the corresponding sawtooth values, only below. This means that the FETs driving high are really much weaker than the ones driving low. Especially on 6581 old SID where most combined waveforms are weak (contain many 0s) and have MSB suppressed (as a result their amplitudes are halved but frequencies doubled except with pulse+triangle combination). If you add triangle to the 'mix' it gets even more complex, it connects adjacent bits (for the left-shifting mentioned at waveform-generators) and provides even more connections to 0 level, so combined waveforms containing triangle have more low or zero values as seen looking at them. Noise can be combined with other waveforms but the discussed zeroing effect is able to clear the bits in the LFSR gradually and when the LFSR is filled with 0s it 'locks up' and can only be restarted by test-bits. (Interestingly in VICE emulator I could set a pulsewidth very close to 100% and combine that pulse with a noise ($C1 waveform) without locking it up. Never tried this on real SID btw.) Envelope-generator (ADSR aka channel-volume) ADSR envelope-generator affects the analog part of SID around DAC. Each channel has one, and its output is a 8bit value (0..255) controlling the VCA (Voltage- controlled amplifier) that determines the volume of the corresponding channel. Based on the ADSR parameters given in register and the GATE bit in the waveform control register, three internal counters (per channel) are operated: -The 8bit 'Envelope-counter' which is fed to the DAC controlling the channel-VCA -The 15bit 'Rate-counter' is a prescaler to set the steepness (speed) of the envelope-counter in Attack/Decay/Release phases, these are the prescale values (periods) for Attack/Decay/Release values of 0..F: 0:9, 1:32, 2:63, 3:95, 4:149, 5:220, 6:267, 7:313, 8:392, 9:977, A:1954, B:3126, C:3907, D:11720, E:19532, F:31251 (Note that a value of 0 still has a period, and therefore there's nothing like zero-time Attack/Decay. That's why sounds with AD=00 have clicky starts.) -The 'Exponent-counter' is a further prescaler for the envelope-counter in Decay and Release phases to ensure more ear-friendly nonlinear sound-decays. There's a space-efficient exponential-table in SID with prescale-values paired to envelope-counter value-ranges/stages: 255..95:1x, 93..55:2x, 54..27:4x, 26..15:8x, 14..7:16x, 6..1:30x, 0:1x (At the start a fast 1x prescaling/division, it gradually grows to a 30x slow decay when envelope-counter falls below 6.) Several state-bits determine the current ADSR state/phase: Attack-phase, Decay+Sustain phase, Hold-at-zero state A transition of GATE-bit to 1 turns on Attack-phase and prepares for the next Decay+Sustain-phase, disables any Hold-at-zero state. Attack-phase lasts until the envelope-counter counts up to $FF then it's turned off and Decay+Sustain-phase dominates in which the envelope-counter through the exponent-counter prescaling counts down until it reaches the sustain-value. (Which is expanded to 0..$FF by doubling the 0..F sustain-value to the high-nybble). A transition of GATE-bit to 0 turns off any Attack or Decay+Sustain-phase and counts down through the exp-prescaler until it reaches 0 (Release-phase) and enters 'Hold-at-zero' state and only leaves this state when GATE goes to 1. ADSR delay-bug: For hardware-efficiency in SID most counters are made from LFSRs that need less parts and it doesn't matter if they don't count linearly, the comparison values are simply selected according to their predetermined (pseudo-random) sequence. But that turned out to be a problem with rate-counters that determine the speed of the envelope-counter. The rate-counters are only reset when they count up to their current comparison value which is based on prescale-table looked up by the 0..F Attack/Decay/Release value, depending on the current ADSR phase. As there's a single rate-counter for all the 3 timed ADSR-phases and starting a new phase doesn't reset it, it's possible for the rate-counter to miss prescale-value (rate-period) that it already went through: when for example a faster (lower-period) Attack follows a slower (greater-period) Release. In that case the match is not found until the rate-counter goes up through its full sequence and starts over by wrapping around. That can take as long as 32.8ms (counting at 1MHz, cycletime is 1us, 32768*1us=32.8ms). The next note can delay that long, and it's quite audible. This is the so-called ADSR delay-bug. The ADSR delay-bug appears statistically rarely when the difference between the rate-periods of adjacent phases is small (doesn't decrease much), but is more frequent when the next rate-period is much smaller than the previous. (It's less known/noticed but is logical: this delay-bug can happen after a transition from an Sustain to a Release phase too.) We'll see later how to overcome (or how to enforce) this delay-bug situation. But for now these are all the important details how the ADSR basically works. Filter (shaped timbre, substractive synthesis) After the channel-DACs there are 2 routes for the now analog waveforms to take, the direct lines to the main output mixer or through the filter-circuitry. In the register-section I described the exact addresses and bits of the filter- controls which determine this route. The channels going into the filter are summed thourgh resistors. This circuit in the SID is a '2-integrator loop bi-quadratic' filter and as its name suggests, it contains two integrators in a loop through a 3rd member, a simple amplifier for resonance/emphasis. The integrators are basically inverting operational amplifiers with capacitive feedback, these capacitors are both outside the SID-chip on the motherboard and are of fixed values. What makes it possible to change the filter cutoff-frequency is the VCR (Voltage-controlled Resistance) in series to the inputs of these integrators, serving as the variable resistors (both controlled in tandem) in the RC filter/integrator. The 8580 and the old 6581 SIDs differ very much in their solution of the VCR: The 6581 uses 2 single FETs as VCRs with some attempts for linearity by having negative feedback resistances to their gates and operating in their near-zero signal-region. There are resistor-ladder DACs having the filter-frequency set in the registers converted to an analog signal, that controls the gates of the VCR MOSFETs. But this simple control of a series (common-source) FET has its disadvantage of feedback from the signal-path: The FET is a transconductance device that transforms voltage between its Gate and Source terminals. But the source is not at GND so the Gate-Source voltage depends not only on the cutoff control signal but slightly on the integrator's small input-signal too. That causes a kind of distortion unique to the 6581 old SID, because thanks to the 'resistance-modulation' of the VCR the cutoff-control signal gets a bit of the audio-signal, so the audio signal essentially alters its own filter-cutoff frequency even during a single wave, the waveform becomes less rounded. This unique fat sound is liked very much by many people. The control-curve of the 6581 SID is also nonlinear because there are about 1.5GOhm 'shunt' resistors between the Drain and Source terminals of the VCR-FETs so when their resistances go above this value, less and less change is seen in the cutoff-frequency. On average this 1.5GOhm resistance ensures about 200Hz minimum of cutoff-frequency. There is big spread among 6581 SIDs so these resistance-values and the cutoff-frequencies vary wildly from chip-to-chip. (There are the so-called 'dark' and 'light' SIDs cutoff-curves...) The 8580 SID's redesign affected its filter very much: As seen in the die photos at kevtris.org, the single-FET VCRs were replaced by a different method, essentially the filter-cutoff control-voltage DACs seem to be integrated with the VCRs into a digitally controllabre resistor-ladder VCR. Anyhow, this results in a very precise (I'd say laboratory quality) and linear filter-cutoff control, and filter-distortion seems to be gone too. (Back in time Robert Moog could only make sophisticated analog VCFs from bipolar transistors connected as differential amplifiers in a ladder layout having capacitors in the rungs, the 'Moog-filter'. MOSFETs in SID made it easier.) Mixing and Output (main volume) The output stage is simply mixing the non-filtered audio route and the filter's output and applies the main volume on them thourgh a VCA, then the SID-sound ready for amplification goes to the outside world in ways described earlier. (Some people say the simple transistor-based output-amplifier in the C64 might add some characteristic nonlinearity to the SID-sound... maybe.) Usage of SID in practice, tips, tricks and secrets -------------------------------------------------- Knowing the internals of SID is not enough for squeezing good music out of it. We still need an interface from the SID to the Human, namely: the composer. The composer needs a tool to compose and execute his/her ideas. There are many trackers around and most of them add a lot of extras by software to the SID to bring it closer to ready-made synthesizers: frequency-tables,vibratos,LFOs,etc. Hard-Restart (delay-bug prevention) One of the most important features of tools is to eliminate the ADSR delay-bug so the composer can rely on sound-starts. The workaround to the bug is called 'Hard-Restart'. (I've made another writing about it in FlexSID user-manual.) The method 'resets' the ADSR rate-counters so when a new sound (Attack) happens we know the rate-counter is not anywhere, but it's counting inside the first 9 steps rapidly. To achieve this we simply need to set both AD and SR registers to 00 and GATE to 0 at least 2 PAL-frames (40ms) before a new sound is about to start. This also ensures that the Release-phase arrives at 0 level. At least this is the method that always works, no matter what ADSR settings the previous and the next instruments have. Different programs use different approaches, many times only SR is zeroed, which is OK too. In programs where the Hard-Restart-ADSR can be set to any value, people tend to use inbetween values in the pursuit of softer sound-starts, but to me most methods seem casually suitable for a given piece. There's a 'new kind of hard-restart' mentioned at CodeBase64 (by Shrydar, and Lft is involved here too), they call it 'Bottle', and it's a totally different cycle-exact code approach. It is able to reset the rate-counter in the timeframe of about 10 rasterlines (less than 1ms) instead of a 20ms frame, by utilizing the delaybug-free safe transition from a slow attack to a fast decay. There's an other ADSR-bug in SID too: envelope-counter too can wrap around when it is at value $FF and an Attack is triggered. This is used to bring the envelope back to $00 fast in this 'Bottle' approach. Only time will tell how soon this restart-method gets implemented in players... To delaybug or not to delaybug? (sexy-start) What differs in most editors and their players/drivers is how the new sound starts after the Hard-Restart. Different recipes work differently. To avoid a new delay-bug after Hard-Ristart IMO the best write-order is to set AD first before turning on GATE so it won't affect the rate-counter (thanks to being in release-phase after Hard-Restart), then set the GATE-bit to 1 to change to Attack phase, and then immediately set the SR-register which will only have any effect when the next GATE-bit turnoff happens (note ends). But most player-routines does quite the opposite instead (cause the delay-bug) to achieve the so-called 'sexy-start' of sounds: They write AD and SR before turning GATE-bit on and if the Release-value is big enough (above 3..4), a new sound with a small Attack value of 0..1 is started, the rate-counter had a chance to advance meanwhile and cause a miss of the Attack compare-value. The more one waits between AD+SR and GATE writing the more probable this situation becomes. The result is having a delay in the start of sound of about 32.8ms, so the 1st frame of the sound is silent (usually waveform $09 is set here to set TEST-bit), but the 2nd frame's last 7..8 milliseconds are audible. And that is what musicians need, a very short waveform (the first row of a waveform- sequencer table in the instrument-editor) to make the start of sound percussive without turning to multi-speed tunes. Usually high-pitched white-noise is placed here. Our ears are much more sensitive to changes and a sound-start fulfills that scenario. It's not important to use Hard-Restart for fairly stable 'sexy-start' notes but the release of previous note should be much bigger than the attack of the new note, and it's advised to decay to 0 level before the new note starts. It's easier with drums that are decayed fast from within the waveform-tables. Many composers in the past didn't use Hard-Restart at all but knew these rules and selected ADSR values of adjacent sounds carefully. To allow more diverse instruments but still have much bigger release before attack we can set the SR register to $0F artificially 1 frame before the sound-start. This is a simpler kind of 'hard-restart' and this doesn't zero the rate-counter but the opposite: it lets enough time (20ms) for it to count into a region which will almost surely be above the compare-value of the next Attack and cause a delay-bug, and thanks to that, a shortened 1st frame of the next sound aka 'sexy-start'. Digital samples on the SID Digis were not the strongest side of SID in the past. The volume-register setting trick causing an offset is described in the section about SID-registers but it could only produce 4bit-quality sound and that affected the main volume of SID so if normal SID-music was played beside it sounded distorted/modulated. (Not to mention the big difference between the digi-volume on SIDs. In my emulations I could separate the AC-component of the main volume and send it to a separate digi-channel, and the DC-component still used as main volume was even freed from audible pops when volume was changed slowly for fade-in.) The next 'easiest' method to play digital samples on C64 is Mahoney's method: He measured the offsets caused by all the bits (lowpass/highpass/volume/etc.) in the SID with different settings of 100% duty-cycle pulses and ordered them in a 256-byte table for 8580 and 6581 SIDs. There are about 30..50 different quantization-levels can be reached with the proper settings and tables which is better than the 16 levels of simple digis. The downside is that no normal SID-channels can be used beside the digi, but it's still as simple as writing $d418 at a given sampling frequency. The other methods that can achieve 8-bit digi-resolution on SID needs precisely timed (cycle-exact) code. Some methods (e.g. Wonderland demo-series) used the pulsewidth-control in SID to create up to about 15kHz PWM signal by resetting the phase-accumulator at this rate. Because of the audible carrier frequency this was not so appealing for music (maybe a lowpass-filter is a solution for the carrier noise) but a forward-step nevertheless. The ultimate solution at the moment is SounDemon's digi-routine which utilizes the floating signal on a channel when no waveform is selected (waveform $01). The task of this method is similar to the PWM-method, to periodically reset the phase-accumulator at the given samplerate with the TEST-bit, and set the oscillator-frequency proportionally to the desired sample level. The ADSR must be kept at sustain-level, so the waveform is kept at value $01 most of the time. Then after a given amount of time (that should fit in the sample-period) the waveform is set to $11 (triangle) for a short moment to update the floating value at the waveform-selector output. The next round comes so fast that the floating value doesn't decay significantly. This is like a sample-and-hold circuitry. The upward-slope of the triangle waveform instead of a sawtooth ensures higher range (resolution) in less time. The SounDemon digi's only disadvantage is the strict timing and CPU resource in needs but it sounds good, the other SID-channels can be used beside the digi just fine. Sound-design & composing tips ----------------------------- Here I collect some of my findouts about the good SID sounds. In the past I coded a tool called 'SIDhack' to separate SID-channels and debug in realtime what different SID tunes do to sound so good. That tool came handy and I made some tunes containing ripoffs from other SIDs as case studies, like the tune 'sidhack' in the SID-Wizard package. CSDb forum can be a good source too for sound-design tips & tricks, experiences of people shared between each other. In general our brain, our neurons are sensitive to changes instead of steady signals. This might be evolutional solution to long-term stimuli and to focus on better on new events. We have 'differentators' built-in. For example the sense of smells and colours and even touch degrades over a short time: we get used to smells, we see the opposite of a color when it's removed, placing our hand on a raw surface feels it but the feeling fades. Our eyes make micro-movements just to keep the nerve-signals frequently updated, stopping them by will leads to slowly losing the view. The ears work similarly and our whole appreciation of music too: We like the changing sounds better than the steady ones, therefore a pulsewidth-modulation instead of a fixed duty cycle can make a big difference in a solo instrument. This is the same for the filter, a filtersweep on a bass sound or keyboard-track (opening with pitch-increase) is more desirable than a muffled steady cutoff frequency. So one ingredient of good SID-sound is pulse/filter-sweep. Even better if the program supports turning off the filter/pulsewidth-program reset when the new sound starts, that gives even more variations. Speaking about variations, rhythic variations, syncope and of course melodic variations, and even variations at higher level (in the structure, arrangement) are desired in music, but that's a whole other topic on it's own right, I'll stay with the sound-design for now. Sawtooth and triangle waveforms are invariable compared to pulse but sometimes they give the character of an instrument much better. I especially like when arpeggios are made with triangle, gives a feeling of ambient. But I guess pulse/square is the most used because its spectral content can vary much. The thin pulses are similar to sawtooth waves, the 50% pulses are glassy and Nintendo-like, but for a bit more harmonic contents I usually like to set a pulsewidth somewhere near 50% instead. Slow pulse-sweep is the key for the most beautiful solo-sounds, but very fast pulse-sweep is the key for some 'corus' effect. (Probably the reason for the 'chorus'/'room' effect is twofold: the change of harmonic content might cause a bit of percieved detuning and my other assumption is that when a pulsewidth is changed it doesn't happen in sync with the phase-accumulator and there are many partial pulses as a result causing different frequencies temporarily.) And last but not least the pitches: Our ears are very sophisticated to minimal changes in sound but to me it seems we're the most sensitive to pitch in music. A very minimal detuning can cause inconvenience in melodies. But detuning can be our friend too to create good instruments. Sure, detuning a channel compared to an other can achieve choir effect like with the accordion, doing it with vibrato can make the music even more lively. Vibratos are ment to be used with a little bit of delay even on live instruments because our ear needs a stable note-start before letting the rest of it to vibrate. Vibratos are good tools to emphasize notes just like dynamics. Some chorus effect comes very handy for basses too to appear stronger under the lowpass-filter. For highpass-filters I usually don't prefer to use big resonances but they're nearly essential on SID where the resonance is not too strong compared to analog syths and VSTs. To make the bass-sound somewhat richer I usually set both low-pass and bandbass filters. For special sounds like claps or speech, the bandbass filter alone seems very good and should be used more frequently in SID-tunes. Sometimes it's good to enhance a solo instrument by dedicating the sole filter to it. Basses in a mix can stay unfiltered and still sound good because they have the deepness but their harmonic contents still keep the richness of the music. Sometimes with jazzy and silent tunes the triangle waveform is good as doublebass-like sound or even in techno tunes, and the filter can be used to make the solos modern, sound more like an expensive synth. Sync/ringmod? The have always been mysterious despite knowing how they work. Most of the time some good sounds could be made by tweaking. In general, sync-effect seems to be more deterministic, but ringmod gives frequencies that are hard to follow. Using both is even more interesting and uncontrollable but playing around can lead to good results... Echo-simulations on a single channel in a melody are quite possible by inserting silent notes between the normal notes. I don't know the others but I usually feel the notes that best fit there and they're not necessarily some notes appearing earlier on that channel or notes in the melody. Good bassdrums can be made without filter in the waveform-table, sometimes even with triangles. But the stronges bassdrums contain ~50% square waves in a sudden frequency-drop at the first 1..2 frames, then only several notes of drops in the last frames. Good snare-sound can be made by only 1 but maximum 2 frames of ~50% square, then the decaying white-noise sould continue asap. I like snares in funky music which end abruptly but it's not obvious how to make them on SID. Usually release values of 5..7 are fine for snare. I like the snares of Shogoon which are made on 2 channels and you can really hear the oomph and the snarenoise at the same time. But that's not always possible. Arpeggios are tricky beasts. They can sound ugly when the pitch changes every frame, I usually let pitches last at least 2..3 frames. To reduce the abrupt pitch-changes even further, arpeggios can return to the base note. Having chord-invertions can help further in making arpeggios more listenable. If done well, complex harmonies with dissonant intervals sometimes are more listenable as arpeggios than being played together. After all an arpeggio is a fast melody so dissonances disappear fast, maybe that's why. Dynamics in music are usually desired, there's more variety in a hihat or kick or snare when there are strong and weak hits in good places. But interestingly for some oldschool C64 tunes the fast repetitions without any dynamics sound better, maybe they emphasize that this is a different style of music and not something played by a human who automatically adds dynamics by the law of physics. All in all, good ears and being open-minded for new possibilities are probably the best leads for creating interesting SID-music. And the importance of composing should never be underestimated, a good composition with simple instruments is often more joy to listen than a music with good sounds but out of ideas and story. Hermit (Mihaly Horvath) Year 2022