I read some related information in a SAM question but I want to know exactly how to write amplitudes directly to the DAC, sample by sample, like in a bytebeat formula. I understand it is possible on C64, is it? And if you know how to do the same on similars like VIC-20, it would be appreciate, thanks in advance!
DAC is a digital analog converter. There is no such periphery on C64, but the closest to it is the SID chip, for playing sound.
Also the SID chip was not designed for that. It can play ADSR (attack-decay-sustain-release) sounds with 4 pre-configured waveforms:
This can be hacked to work like a DAC. It can only 16 signal levels, but it is enough to produce recognizable sound (for example, human speech).
You can also set a master sound volume with the lower 4 bits of the register
$D418. (The higher 4 bit configures the filters, best to leave them unmodified!)
The hack is the following:
- Start a sound with an short AD.
- The important thing is that you can make the "sustain" phase so long, as you wish! It requires a write to a SID register to start the "release" phase.
- On this way, you have a constant sound. Ideally, best if you set up a pulse waveform with the highest possible frequency (around 8kHz)1, and with a high duty level (to approximate a constant output level).
- Then, by regulating the master volume2, you effectively have the DAC.
The result will be only 4 bits and it will be contaminated with the original sound, but it will work: it is enough to make recognizable human speech, although only at some tens of seconds have place in the RAM.
The output will appear on the audio output (needless to say, this and requirement for the master volume control2 makes the play of other sounds impossible).
1Thanks @Janka the important fix.
2Comments (another thanks @Janka) suggest that it can be done with the sustain level, too, what gives yet another 4 bits. Combining these, we could have a nearly-logarithmic 8-bit signal output. As I can remember, the master volume control is a requirement for this trick, but I am not sure. This doc says that the sustain level can be set up for all the 3 sound channels independently.