Chariots of Fire

23.07.2007 0:15

Chariots of Fire is a short (260 bytes) program for Galaksija that plays a part of "Chariots of Fire" track by Vangelis.

The music it produces resembles some of the more advanced beeper music from Sinclair Spectrum. I was always curious how people were able to reproduce anything else than simple tones on a 1-bit D/A converter and this small program was nice a opportunity to learn about it.

It turns out that the code implements two independently running loops with a slightly different frequency. Each one of them changes the state of the audio output on each iteration (from 1 to 0 or 0 to 1). Result is an oscillator that slowly changes its duty cycle from 0% to 100% and back again. Here's the waveform of one note:

(listen)

The changing duty cycle periodically shifts the signal's energy from lower to higher frequencies and back again. Since the beeper (or whatever is between the audio output and your brain, including your ear) has a limited bandwidth, a lot of the higher frequencies get cut off. This means that the sound gets periodically stronger and weaker, which can be used to produce the illusion that the square wave signal has an envelope added to it.

Compare this with a simple square wave of the same frequency:

(listen)

And here is the same square wave with an added envelope, roughly matching the changing duty cycle:

(listen)

Posted by Tomaž | Categories: Code

Add a new comment


(No HTML tags allowed. Separate paragraphs with a blank line.)