Making Music with the ZON X-81

Publication

Publication Details

Date

Pages

See all articles from SYNC v3 n6

Programming the ZON, Bi-Pak’s sound generator, to play a simple tune is no simple task. On the other hand, it is far from impossible, and this article should be of help to aspiring computer musicians.

Channel Tuning

Although many ZON registers are involved in programming a melody, the most confusing to deal with are the tuning registers. There are three difficulties involved: finding the correct frequency, determining its load value, and the actual loading process.

While the ZON manual gives the frequency of middle C and an impressive formula that will give you the load value from a frequency, you may be at a loss for any note other than C. To find the values you need, there are three things you must know about music theory:

1) If the frequency of a note is doubled, or halved, the note changes by an octave.

2) There are 12 semitones, or halftones, available from any note to its octave.

3) The pattern of tones needed for a major scale (the familiar DO-RE-MI pattern) is: whole tone, whole tone, half tone, whole, whole, whole, half. Together with the starting note, that makes eight tones in the scale — an octave. The tones found in a scale are more likely to be together in a song.

The key to programming ZON notes is this: forget about frequencies and work directly with load values.

The load value for middle C is 388. In music, doubling a frequency raises the note an octave, but the ZON works in reverse: 194 is the load value for the next higher C. Dividing this range (from middle C to its octave) into twelve equal portions gives the figures in Chart 1.

The notes with no sharps or flats (see Chart 1) are the ones needed to get a C major scale — the DO-RE-MI pattern beginning on the note C. You can derive any other note you need by finding its octave from this chart: the G below middle C would be (274*2), while E above this scale is (322/2). You may find it necessary to make some adjustments to some of the load values for just the right pitch, because the fractional values that were rounded for this scale will be multiplied in another octave. Let your ears be your guide.

Loading the Values

Each channel has two tuning registers, referred to in the manual inaccurately as rough and fine tuning. The lower numbered register of each pair (DO, D2, and D4) cannot hold a number higher than 255. Higher values must be split between the two tuning registers, and, while the second register of each pair (Dl, D3, D5) can only hold a number up to 16, that number represents a multiple of 256.

To tune channel A for an F, registers DO and Dl must be loaded with a total of 308. Dl will hold the multiples of 256, in this case, 308/256, or 1. The remainder, 42, is put into register DO. See Chart 2 for other examples of loading values into the tuning registers.

Programming a Tune

A number of other registers must be attended to in order to make the ZON play a tune. The remainder of this article traces the programming required to play a short piece of music that might be apropriate for the beginning of a new game program. The melody is from the opening bars of Also Sprach Zarathustra, better known as the theme from 2001: A Space Odyssey. The techniques used in the development of this program will have many other applications.

Planning the Notes

The melody in this program consists of three single notes (C, G, and octave C) followed by two chords (C major and C minor). Because both chords have two notes in common with the original single notes, it is only necessary to change the tuning of one channel. Chart 3 shows which notes will be played by which channel. Channel A will be re-tuned for E and Eb because the lower C that it was playing is not needed in the chord.

As each of the single notes is played, the channel tuned to the preceding note has to be turned off, or both notes will sound. This, and other programming points, are best covered in a line-by-line explanation of the accompanying listing. In the text, ZON registers and their contents are referred to parenthetically as (D,C), where D is the register and C is its contents.

Program Line Notes

1-6: ZON loading routine.

10-16: Clear all registers.

18-28: A string-slicing routine that saves program space and typing many LET statements. The computer looks at four digits at a time, the first two being the register number and the next two the contents. String slicing is a little slower than using LET statements, but is appropriate for setting up some of the registers at the beginning of the program. This routine enables tone on all three channels (7,56), enables envelopes (8-10,16), and sets the duration of the note (12,25).

30-42: Tune channel A (0,252), play the note (13,0), and turn off the note by changing the volume (8,0). The subroutine for a delay loop is necessary because otherwise the note will be turned off before it has faded. Not only will the duration then be shorter than planned, but the tone will have an unwanted “chopped off’ sound.

45-72: Tune, play, and shut off the notes in channels B and C.

75-77: Tune channel A to E.

80-83: Turn volume back on for all channels.

85-87: Increase duration of notes.

90-92: Play chord. All three channels are tuned and turned on. Channels B and C retain their original tuning.

95-97: Re-tunes channel A to E. This is done while the chord is still playing, and the change is heard immediately.

This program was written to be run in SLOW mode so it will not interfere with an introductory display. If you want to run it in FAST, you will find it necessary to change the duration of the notes (register 12) and the T value in the delay loop. Also, when running this type of program in FAST, repeated loads to register 13 to get the note to play are not always necessary.

If you wish to program the second strain of this theme, it is the same as the first, except that the C major and C minor chords are switched at the end.

Products

Downloadable Media