Monday, 10 January 2011

VIC-20 audio output - square wave tone generators, noise generator, DC offsets, clipping

I've been doing some more investigations into the VIC-20 audio output recently, initially focusing on the noise generator but later returning to the subject of DC offsets and clipping.

There are four audio generators summed together and amplified at adjustable gain by a 4 bit volume control to produce the audio output in a VIC-20. While one of these may be operated at full volume (level 15) without distortion, operating all four at full volume will produce clipping distortion. The distortion is asymmetric, occurring on the high side of the waveform when measured at the audio output but not on the low side.

One subject of interest is what volume level can be used with all three tone generators and the noise generator without causing distortion. This may vary between VIC to VIC but broadly speaking a setting of 7 or 8 generally produces no distortion or very little distortion depending on the machine. Because 7 is 0111 in binary and 8 is 1000, the difference between these two settings relies on the magnitude of all four bits and so it is the most susceptible to error. One of my VICs has almost no difference between 7 and 8, producing undistorted sound on both. The VIC in eslapion's video posted on the following post is undistorted at volume 7 and starting to distort at volume 8.

A good test is to play a chorused three oscillator note and listen for periodic distortion as the squares constructively interfere. At times there will be no distortion, when the tone generators are out of phase with each other, other times there will be distortion depending upon the volume level. Example POKEs for this are as follows.

POKE 36878, (from 0 to 15)
POKE 36874, 255-32 (Sets the bass tone generator to period 32, equivalent to 128 on the soprano generator)
POKE 36875, 255-63 (Sets the alto tone generator to 63, equivalent to 126 on soprano)
POKE 36876, 255-127 (Sets the soprano tone generator to 127)

When the VIC is reset, the tone generators are silenced and output 0, which corresponds to the minimum offset. However, the noise generator, which is also silenced, outputs 1 from reset state. Since the distortion occurs on the 1 side of the waveform, when you determine the maximum volume level for three tone oscillators without clipping from the reset state, you are in fact determining the maximum level for all three tone oscillators plus noise.

When the noise generator is turned on and then off again, the state it outputs is sometimes 0 and sometimes 1. When outputting 0, a higher maximum level for three tone oscillators is possible without distortion, and a higher level for two oscillators is also possible. On my VIC it is possible to play two tone generators at volume 15 without distortion, when the noise generator is stopped and outputting 0. When it is outputting 1, the maximum level for two tone generators is 10.

When the noise generator is stopped and outputting 1, that level 1 is equivalent to the highs when it is started and outputting noise. However, the level when it is stopped and outputting 0 is not equivalent to the lows when outputting noise. The voltage for the 0 state when stopped is somewhere between the low and high on states, not quite half way but biased slightly towards the low side.

The same turns out to be true for the tone generators as well. These are always in the 0 state when stopped, but that 0 state level is not the same as the lows of the square waveforms but somewhere between the low and high points, near the mid point but slightly towards the low side.

The effect is to remove most of the DC offset when a tone generator is turned on and off, thus VIC tone generators do not emit loud clicks when they are switched on or off, unlike some other square wave based tone generators.

When the noise generator stops on output state 0, the same is true, but there is a click when it stops on output state 1, and there will be another one when it starts again. This can be seen on an oscilloscope.

Greater understanding of the noise generator may provide the ability to control which state it stops in, as well as the ability to control which of several noise polynomial sequences it produces. In many VIC games and demos the noise generator can be heard changing in timbre from time to time, varying from a very pitchless 'white' noise to a sound with a strong bias toward one frequency, sounding a bit like white noise going through an analogue filter at high resonance.

This is more noticeable when the cutoff frequency of the filter in the audio output stage has been moved from 1.6kHz to 16kHz, as in my earlier post.