The Commodore 64 did not have any hardware dedicated to digital audio playback, so how were some games and songs able to achieve this on an unmodified and unextended Commodore 64? Did these techniques require specific hardware revisions?
4 Answers
No hardware revisions are necessary. The digitization playback is achieved by bit-banging the volume register of the SID chip to simulate a digital playback device. Essentially, the SID can be used as a 4-bit digital playback device. What's amazing is that the thing sounds as good as it does playing back digital data.
A great article about digis on the C64 can be found here: http://sid.kubarth.com/articles/the_c64_digi.txt
-
3Actually, 4 bits. The volume register is 4 bit wide, and it happened that any change to the volume register produced a "clic" sound with the new volume (hence a 16 level volume). Changing the volume register value very quickly allowed the "clic" sound to follow the instant values of a 4 bit digital signal. Commented Apr 27, 2016 at 22:56
-
Would be good if the answer would be edited to correct the bit-depth, in line with the document it cites. Commented May 25, 2016 at 22:56
-
1This does not really answer the question. Changing the volume on my PC does not make it possible to play samples. You need to incorporate the comment by @mcleod_ideafix for it to make sense.– pipeCommented May 30, 2016 at 19:50
-
It was the same technique used on all machines with a AY-3-8910 sound chip (Atari ST, MSX, Amstrad CPC, etc); On the ST it was typical to use the Timer B to generate a scanline interrupt to change the volume at that time, at around 15khz, allowing sounds of up to 7.5khz, the lack of filter made the result quite harsh. The three channels were playing a carrier signal like what Stavr00 described below.– ThomasCommented Dec 9, 2016 at 20:10
-
The best audio quality was obtained with pulse width modulation
using the square wave voice. The oscillator was set to 0 and the pulse width was set by flipping the pulse width from 0 to maximum.
With the CPU speed at 1mHz the fastest pulse switch rate achievable is around 15kHz, producing a sound wave of 7.5 kHz or less. Setting the low pass filter help smooth the sound.
Source: https://en.wikipedia.org/wiki/Pulse-width_modulation
-
1Pulse-width modulation needs a carrier greater than 4KHz to get good results; even with a perfect reconstruction filter, an A440 (not a particularly high note) would need to have all harmonics beyond the fourth filtered out; an A880 would only get to have the fundamental and octave harmonic. Most sounds need at least the fifth harmonic before they even start to get "interesting", so a 4KHz PWM rate isn't going to cut it except when trying to produce very low notes.– supercatCommented Dec 9, 2016 at 19:48
-
I re-read the digi article in the original answer, and it explains a different way of doing PWM. Will rewrite.– Stavr00Commented Dec 9, 2016 at 20:06
There were also some more recent creative alternatives taking advantage of filters and undocumented test bits as well. Check out the Cubase64 demo by Mahoney: http://www.livet.se/mahoney/cubase64 You can also find versions of it playing on the real thing on YouTube, naturally. (spoiler alert: your face will melt -- it's that awesome.)
-
3You need to actually write how that works, in this answer, otherwise it's just a comment.– pipeCommented May 30, 2016 at 19:47
-
Noticed your comment -- I could have copy/pasted the article body of the page I linked to and just credit the author but it was rather long and honestly I didn't want to take credit for someone else's work. Instead I linked to the article that explains it better than I ever could. I'm not sure how your nit-picky response was any more helpful, suppose you were better off not having someone show you an awesome demo? Sheesh! If what I wrote was just a comment I can only imagine how others would classify your reply. Commented Jan 13, 2020 at 22:10
-
I came back to post this after re-moulding my face back on. That was insane!– DomariusCommented Oct 7, 2021 at 14:06
It seems that all the earlier posts only give partial answers to the question. The below extract of the relevant parts of my doc https://bitbucket.org/wothke/websid/src/master/docs/digi-samples.txt should remedy that situation and give a more comprehensive overview of all the respective techniques:
There are basically 4 general approaches [that are used to play digi samples on the C64]:
[..]
- $d418 "volume register" based
This is probably the oldest technique: The SID's audio output is directly modulated by changing the master volume. The result of this approach primarily depends on the original output available for modulation, i.e. ideally the original output would need to be at a constant maximum which would then allow the technique to modulate it to "anything" between 0 and that maximum. A flaw in the old 6581 SIDs made them particularly suceptible to this exploit: respective chips always produce a relatively large DC voltage offset on the master volume D/A which means that there is always "some" kind of original signal that can be modulated via the master volume - even when there is no regular voice output.
[..]
However this technique usually works poorly on the newer 8580 SID chips, since those no longer produce the flawed DC voltage offset, meaning that there may be very little original signal avilable for modulation (depending on what other regular output the SID's voices are producing).
[The technique can still work on the 8580, provided that there is suitable output from the SID's regular voices that can be modulated.] [..]
Mahoney's "8-bit samples"
There is a more recent "turbo charged" variant of the $d418 approach [..] Here the trick is to carefully setup the regular voice output such that not only the volume but also different filter activation will influence the modulated result. [..]
Due to the fact that the "carrier signal" has been specifically set up, the approach runs fine also on newer 8580 models. [i.e it runs on all SID models but a specific implementation is always optimized for a particular SID model's filter and D/A converter characteristics and will not yield optimum results when used on other models] [..]
- frequency modulation based
This technique probably produces the highest-quality sample playback, allowing for actual 8-bit samples. [Respective players typically only use the high-byte of the frequency register to control the "step width" - see below.]
The underlying principle is to use one of the waveforms that linearly transition from 0x0 to 0xfff (i.e sawtooth or triangle), to start it at 0 and then let it go up for a fixed number of clock cycles until it has reached the desired output level and then output that level for the duration of a sample.
The sample playback rate of this type of player is fixed, e.g. the player might play a new sample every 129 cycles. This means the SID will always "step up" the waveform output for exactly 129 cycles and it is then just a matter of finding suitable frequency settings [i.e. the size of each step] that will result in the desired output levels after 129 clock cycles [aka steps].
[This technique works on all SID models.] [..]
- pulse waveform based
An early/primitive form of pulse-waveform based sample output can be found in Slapshot_1987.sid. Here a 7kHz 1-bit signal is generated by manually turning the test-bit on/off and thereby toggling betweeen the 0x0 and 0xfff output level. [This works on all SID models but the audio quality is generally abysmal.]
More sophisticated later players use what might be be called a "pulse width modulation" approach. [..]
Their principle is to use a high frequency pulse-waveform and then manipulate the "average" output signal by shifting the pulse-width one way or another to get any average level between 0x0 and 0xfff.
[This approach works on all SID models eventhough the audio quality oftentimes suffers due to the used carrier signal.] [..]
- waveform toggling based
Finally there is an approach that tries to let one voice create different output levels by toggling between different waveforms. The respective frequency and pulse-width settings of that voice are previously configured in such a way that the respective waveforms result in the desired output levels.
[This works on all SID models but the resolution available for each audio sample is usually small.. due to the limited amount of different waveforms available.] [..]
PS: for some hands on experience you might use my below playlist to try out respective digi-songs online and see what technique these are actually using: https://deepsid.chordian.net/?file=/$TinyRSid%27s%20Digi%20Favourites/
-
4
-
4I appreciate that the linked article is quite lengthy, but quoting the (most) relevant parts would make this answer useful in the future, even a dystopian future where the BitBucket website is no longer accessible.– KazCommented Jun 25, 2021 at 12:13
-
1I updated the response and inlined the relevant parts directly– wothkeCommented Jun 26, 2021 at 14:21