Let's talk about SIDs, baby




Welcome, SID enthusiasts!

I have already shared recordings on my YouTube channel (https://www.youtube.com/@sidemu), but now I would like to share some technical information about the SIDemu board itself.


.: How the SIDemu's sub-sampler works :.


Output audio samples are generated every 20th PHI2 clock cycle, which means a mixing frequency of ~49KHz for a PAL system C64.
One might think that this would not sound as good as an FPGA implementation, which generates an output audio sample for every PHI2 clock cycle, but let me explain a little more about what actually happens on the SIDemu:

In fact, SIDemu does not omit any waveform generator audio samples from the final audio output, it just generates a precisely down-sampled audio sample every 20 PHI2 clocks.

The emulation is divided into slices, which are actually PHI2 clock groups. The basic slice size is 20 PHI2 clocks, but in the case of register writes, sub-slices are created, which are added together to form the output audio sample.

Each clock cycle of each slice generates an audio sample, which feeds a buffered moving-sum sample, so the quality of the ~49KHz output will be as if we were recording real ~985KHz audio at ~49KHz.


.: The filter :.

The filter does not calculate audio samples per clock cycle, but uses 4x oversampling relative to the output frequency, so the internal frequency of the filter is ~196KHz. I tuned my filter model with my own emulator (C64emu), using oscilloscope and spectrometer visualizers.

Several parameters of the filter can be modified to create 3 custom SID templates, such as:
  • Minimum and maximum cutoff frequency
  • The order and the offset of the cutoff curve
  • The amount of distortion
  • Minimum and maximum resonance
  • ADSR bias and waveform center (yes, these all affect the distortion of the 6581 filter)


.: The audio output :.

SIDemu has a 16-bit audio output, which is achieved with two 8-bit DACs: one for the upper 8 bits and one for the lower 8 bits, which has 1/256th the volume of the upper 8 bits and these two are mixed together.


.: How can SIDemu behave almost like a real SID in test programs and modern demos :.

The SID has two registers that are not so obvious at first glance, but are nevertheless very important: the OSC3 and ENV3 read-only registers.

As their names suggest, OSC3 returns the current value of the third oscillator’s waveform generator, while ENV3 returns the current value of the third envelope generator.

The OSC3 register is most often used by music players to distinguish between the 6581 and 8580, but it can also be used to map the behavior of combined waveforms, which is key to the proper sound of the music playing during the final part of the Wonderland 13 and 14 demos by Censor Design, for example.

The value read back from the ENV3 register is most often used to control the filter cutoff, but we never know what new ideas someone might come up with tomorrow for using both OSC3 and ENV3, so there is no question that cycle-accurate servicing of these two registers is very important.

The real-time processing of the calculations described above is achieved by using two MCUs on the SIDemu board.

Register writes can be buffered for fast and precise audio generation, but buffering makes it impossible to serve OSC3 and ENV3 in real time in the intermediate PHI2 clocks. However, no affordable MCU is capable of synchronized, non-buffered operation per PHI2 clock.

As a SID replacement developer, I have to say it's very fortunate that the SID can only return two real-time data items via readable registers, so only these two data items need to be generated in real time by a second MCU (however, due to the hard-sync function, the first and second oscillators must also be emulated minimally), which of course must be perfectly synchronized with the sound-generating MCU, otherwise the software controlling the SID based on the read data will not produce the correct result. The C64 reset line is perfectly suited for synchronization, so the two MCUs start counting the PHI2 clocks when the reset line goes high after the machine is turned on, and they resynchronize themselves on each reset.

Of course, both MCUs listen to the C64 data bus, but only the one that has the current read request puts data on the data lines. The main MCU also reads back the values returned at the OSC3 and ENV3 register addresses so that it can return the data generated by the other MCU when reading write-only registers, since the SID always returns the last data placed on its own data line when reading its write-only registers.

Why don't I just use a single dual-core MCU? 
Because, on the one hand, they are more expensive, and on the other hand, more advanced MCUs have a larger footprint and do not fit between the two rows of pins on the DIL-28. Another argument in favor of using two separate MCUs is that the data and address buses, write buffers, and IRQ lines of the two MCUs are not shared, so nothing can disrupt the operation of the real-time MCU.


.: Yes, I know there are other readable registers as well :.

SIDemu also handles the POTX and POTY lines, but on the first core (which generates the sound, hereinafter referred to as SIDemu core, the other being DummySID core), using IRQs.

The POT lines on the SIDs work by connecting both lines to an external capacitor on the motherboard, which is charged through resistors connected to the control ports (the potentiometers of the paddles). The SID pulls the POT lines down to GND for 256 PHI2 clock cycles, discharging the capacitors, then releases them for the next 256 PHI2 cycles and starts a counter. As soon as the charge level of the capacitors exceeds the comparison level, or the 256 cycles elapse, the current value of the counter is written to the corresponding POT register, and the whole process starts over with the capacitors being discharged.

Since the MCU used in SIDemu operates at 3.3V, the comparison level does not match that of a real SID, which is compensated by an intermediate resistor, but to be honest, the resistance measurement used to connect paddles to the POT lines is not the most stable in original SIDs either, so I introduced a smoothing option that can be parameterized, because mice do not use a variable resistance solution like paddles, but send timed pulses, which can be disrupted by stronger smoothing.


.: The EXTIN line :.

The EXTIN line is not yet implemented in the firmware, but I have already designed it onto the PCB, so (if nothing went wrong during the design phase) it will be possible to use it later, but currently it is not available, which does not mean that it will never be.


.: How is SIDemu different from other SID replacements :.

That's a very bad question. The question is not how one SID replacement compares to another, but how each SID replacement compares to the original SIDs.
Obviously, most comparisons include original SID recordings, but we should always strive to test with music that sounds very different or very bad on many SID replacements compared to the original SIDs. And those pieces of music must first be observed with many original SIDs to see what kind of differences there are, so that we are aware of whether a particular difference is a shortcoming of the emulation or simply corresponds to variations that are also present in the real SIDs.
If you don't listen to original SIDs regularly, you won't be able to tell what is an acceptable difference and what is an error, but it is also common that something may seem like an error even though it also occurs on the original SID, so certain specific glitches are actually signs of correct emulation.

Listen to original SID recordings regularly! This is ongoing homework for everyone who is a fan of SID music.
Stone Okvalley put a lot of work into making this possible for anyone without having multiple SIDs:


.: When will SIDemu board be available :.

I plan to manufacture a few pieces in January, but I will only order larger quantities once I have received feedback on these. I have been testing and fine-tuning the SIDemu board V2 for about two years (V1, with one MCU, was never released), but it still need to tested with the C64 Ultimate, in both PAL and NTSC modes, so I ask for your patience, but the process is not at a standstill, it just has many components.


.: Let's help each other navigate in the world of SIDs and "SIDs" :.

I recently created a Facebook group for comparing SID replacements and original SIDs called "SID Comparison Arena":

Please help fill the group with useful content to make it easier to navigate between the many SID revisions and SID replacements.


Feel free to leave a comment.

Cheers,
DaemonPig

Comments