Commodore 64 SID music programming with BASIC – playing a simple three voices tune (part 2)

On the first part, we have seen a simple technique for programming a three voices tune with BASIC. The program we have presented there works fine, but it takes a lot of seconds before the tune can actually start playing.

The original program by Jim Butterfield required no time for music data processing instead. That’s because each data statement contains note frequencies for voice 1, voice 2 and voice 3 (in this sequence). So, the READ instruction can read notes while the tune is actually being played.

Such an arrangement of music data is not optimal for typing-in the notes of the song. So, on the first part of this article I have modified the original program by Mr. Butterfield so that separate data statement blocks for voice 1, voice 2 and voice 3 have been possible. That makes musical notes entering quite easy. But, notes from data lines must be loaded on an array first, so that they can be accessed in the required order by the music player. In fact, random access to DATA statements is normally not possible. Even if we manage to get random access to DATA statements [1]See “Compute’s Mapping the Commodore 64”, page 20, locations 61-62 decimal., that would be slower than normal access. And, we need speed here.

Now, we are going to find out a way of creating data statements out of the content of the array with separate music data blocks. This way, we can create a new version of the program that can read in notes while playing the tune. This way, we will have to wait no time for music data processing.


The new version of the program

You can download the new version of the program here:


Three voices tune with C64 BASIC (fast version)


As you can see from the code, data statements now have note frequencies for voice one, two and three on each data line. This way, the player can directly read and play notes from data statements.


three voices tune with C64 BASIC


A conversion from one music data format to the other was required. I coded a few simple BASIC programs to do that. They work but are quite slow, so I am not going to publish them for now. This way, I didn’t have to rewrite musical data again.

On each data statement, six numbers can be found. The first two numbers refer to voice one, the third and the fourth to voice two, the fifth and the sixth to voice three. Each number can either be low byte or high byte of note frequency, a pause (0), or “sustain” (-2, that is, keep playing the note on the previous data statement for this voice).

On line 100, the timer TI is reset (setting TI$ to “000000” just accomplishes this). This way, TI will not become too big, as it will be set to 0 each time the program is started. TI must be prevented to be too big, otherwise the BASIC interpreter may take too much time to process it. Please note that there is no need to reset TI$ on the player loop (like I did in the three voices program on the previous post). This way, the player will be faster, as resetting TI$ on each loop takes some time.

Tune speed can be easily changed on line 278. Current value is 8. A bigger value results in a lower tune speed. If that value is decreased instead, the tune will play faster. As the player seems to be efficient, the tune can be played very fast if desired.



1 See “Compute’s Mapping the Commodore 64”, page 20, locations 61-62 decimal.

Leave a Reply

Your email address will not be published. Required fields are marked *

Insert math as
Additional settings
Formula color
Text color
Type math using LaTeX
Nothing to preview