Friday, September 10, 2010

VIC-20 (CR)'s bad waveform clipping.

Poor MOS6560, it could so much better outside a VIC-20!

For chipsounds 1.0, I got the help of eslapion from the Denial forum to analyze the RC filter output of the VIC-20. Eslapion got me to learn how to understand the link between the resistors and capacitors and how to extract the exact low pass filter coefficients that was needed to implement in DSP. It simply turns out to be a 1.6Khz one pole low pass filter. (third party confirmation here).

Such a low cutoff makes for one REALLY DULL sounding chip

But that's not the only sound coloration present on the real VIC. There is also quite a bit of clipping going on when all voices play at once. This clipping does add quite a bit of character when there are a combination of more than one pulse voices playing, as well as the noise channel.

Lets look at the phenomenon on a scope:







Quoting Eslapion:

"The specs sheet of the 6560 specifies the audio pin has an output impedance of 1kOhms. This impedance interacts with C9 (0.01uF) to create a 1st order low pass filter of 15.9kHz.

This is followed by R8 (1kOhms) and C10 (0.1uF) which combine to create another 1st order filter of 1.6kHz.


In other words, these two filters combine to provide a 20dB/decade attenuation from 1.6kHz to 16Khz and then 40 dB/decade above that.

Q1 acts as a current multiplier to ensure enough driving power on the final output but, as we can see, R27 acts as a pull down only device and there is no biasing. The output of the 6560, multiplied by Q1 pulls up and R27 pulls down.

Add to that, the fact that the volume control induces a DC offset.

DC offset values for register 36878: (average) (values picked after R8)
0:4.06
1:4.17
2:4.28
3:4.41
4:4.53
5:4.64
6:4.76
7:4.86
8:4.95
9:5.06
10:5.17
11:5.27
12:5.37
13:5.47
14:5.56
15:5.64

This DC offset, on the final output, is cancelled out by C11 which combines with R27 to create a high pass filter of 339Hz with 20dB/decade attenuation. Therefore, when no sound is playing there is no way to tell on the output that a DC level forms on the base input of Q1 as the volume is increased.

If the 6560 is going to pull up in DC when the volume rises then the maximum excursion of a sound wave is limited by a combination of the pull down current (set by R27) as well as the voltage feed which, in this specific case is 0 to 5volts. When the volume goes above a certain level, clipping of the positive side of the wave occurs as the 6560 attempts to pull up above 5V.

This clipping effect is even more intense when playing multiple voices simultaneously as their combined excursion adds to each other.

Obviously, the smallest amount of clipping occurs when the DC offset provides a DC level of 2.5V on the base of Q1. This is achieved when setting the volume level to 8.


Now, looking at the rise and fall time of the signal taken directly at pin 19 of the 6560, we see that the rise time is much greater than the fall time. Considering the effect of Q1, as seen by the 6560, R27 should appear as about 100 times greater.

This asymetrical voltage change is caused by the diode in the base of Q1 which can draw current on voltage rise but not give back any on the falling edge. This causes C9 and C10 to charge slowly as Q1 "steals" current used to charge these capacitors but not restore it when the 6560 discharges them. This assymetrical time constant is less dramatic on the actual output as C10 and C11 are still discharging at the very instant C9 appears to be empty.
"


Heres an audio capture form the final analog output of the VIC-20 CR:

Clipping sound

So there you have it!

The VIC emulation im working on for 2.0 includes that clipping and filtering and is starting to sound very close to the real thing.... stay tuned

4 comments:

  1. I'm not sure how accurate you want to be, but having two RC filters in series like that isn't the same as two one-pole digital filters in series. In the analog world it becomes quite a messy equation because the loading between stages causes the overall response to change. According to ltspice, an RC cascade like that is going to be more than 6dB down at 1.6k, with a different overall shape in the audio band. Here's a screenshot of the simulation results comparing two RC filters in series (v_actual) to a series combination of a pole at 1.6k and a pole at 16k (v_two_pole_buffered)
    http://www.skrasoft.com/blog/blogfiles/vic_filter.png

    ReplyDelete
  2. Hi skrasms.

    Thanks for the tip! I'm in fact starting to experiment with a SPICE derivative myself (CircuitLogix) for another circuit I'm checking out. I'll surely try out the VIC audio output in there to see with my own eyes. In any case I always compare recordings with my emu, and I often manually tweak things here and there.

    Emulating Analog electronics is where I hope to get in the future, so theres lots of learning left to do on my part. thanks

    ReplyDelete
  3. For something like this, where there aren't non-linear components in the filter (it's just Rs and Cs), you can do this:
    1) Work out the transfer function of the circuit.
    2) Use the bilinear transform to convert the analog transfer function into a digital version.
    3) Re-factor the digital transfer function into second order sections.
    4) Use a standard biquad filter for each second order section.

    When the filter itself has nonlinear components like diodes and transistors, then it gets into solving nonlinear differential equations in real time. That's where most of the "analog modeling" work is.

    How is CircuitLogix? I really like ltspice. The UI takes a little getting used to at first, but it's free and very powerful.

    ReplyDelete
  4. Hi

    Yes I know those steps, just havent really been doing much of that myself, and concentrated instead on the digital logic.

    Circuit Logix is really hands on, the editor and simulator are combined and you can see voltage values change live while hitting switches for instance, it will recreate the nodes and give you a new readout instantly.

    I'm still using the 30day demo, big question is will i use those tools enough to jump on a license? Maybe!

    ReplyDelete