C64 Demo Using Audio for Video and Vice Versa
coolgopher writes:
http://www.quiss.org/signal_carnival/
At Revision 2025, we released "Signal Carnival" (csdb, YouTube). This demo asks you to switch the audio and video cable of your C64:
Technically, "misplugging" those cables is not a completely new idea. In the 90s, it was a common thing to connect audio to both speaker and video, to get screen flickering timed with the music beats.
However, "Signal Carnival" is the first production to switch both these cables, while still being able to play meaningful audio and video.
How to drive audio using a video signal
The C64's VIC chip operates at a frequency of 7.9Mhz, and new values can be written to it by the 6502 at a rate of up to 246kHz. Since even high quality audio rarely exceeds 44kHz, this is easily a high enough frequency to generate music.
Inspired by the music routine from freespin, we combined two timers to get an interesting waveform, which is adjusted once per frame. This is the code that drives audio:
lda $dc06
ora $dd06
eor $02
sta $d020Here, $dc06 and $dd06 are the lower bytes of the B timers of CIA #1 and #2, respectively. They're in turn increased every time their A timers overflow. And those are set to a new value for every new note.
Eor-ing with the value at zeropage $02 allows to slightly tweak the waveform (and volume!), and then the result is written to $d020, which is the screen color. Only the brightness of said color matters (chrominance is encoded at the PAL color carrier frequency, which is outside of the human hearing range). There's no obvious relationship between the brightness of the C64 color and its number, but that's fine - it actually makes the waveforms more interesting.
Of course, the above uses up all four timers the C64 CIAs have, which means there are no timers left for e.g. video stabilization, which is instead done through the lightpen circuitry. (Finally! A use case for $d013. :))
Music is just one voice, but the song switches between voices (and waveforms) often enough to sound mildly polyphonic.
Read more of this story at SoylentNews.