Classic Computer Magazine Archive COMPUTE! ISSUE 36 / MAY 1983 / PAGE 214

The Atari Musician

Barry Belian

You'll be making music on your Atari in no time with the help of these two programs. You can compute pitch values to play major and minor chords, generate scales, and even tune the computer so that you and Atari can play duets.

COMPUTE! published an eye-opening article in the February 1982 issue entitled "Transposition". The author, Janet Whitehead, explained the simple mathematical relationship between each of the pitch values for the various musical notes available in Atari BASIC. After she explained how this could be put to use in musical transposition, she challenged the reader to find further applications. Here is my crack at it.

Four-Note Chords

The most commonly used chords are the four-note major and minor chords. The four notes of any chord can be defined by the first note of the chord and the interval pattern for that particular type of chord. The first (lowest pitch) note of the C-major chord, for example, is a C. The second note of any major chord is always located four half-steps, or two whole steps, above the first. This gap between the notes is known as an interval.

A half-step interval can be found on the piano by locating any two adjacent keys, such as C and C sharp. It can also be found in the pitch table of the Atari BASIC Manual by locating any two consecutive entries.

Since we know that the first interval of a major chord is four half-steps, we determine the second note in a C-major chord by counting up four half-steps from C, arriving at E. The interval between the first and third notes of a major chord is always seven half-steps. If we again count upward from C, we find that the third note of a C-major chord is a G. The fourth note is always a 12 half-step interval, or octave, above the first, which gives us a C for our final note. Thus, the four notes of a C-major chord are C-E-G-C. In a similar manner, the four notes of an F-major chord are found to be F-A-C-F.

Computing Pitch Values

At this point, let's summarize the previous article. Basically, the author pointed out that the pitch values for any two adjacent notes in the pitch table are related in the same way that the frequencies for those two notes are. Namely, they differ by a constant factor of M = 2^(½) for each half-step interval. Two half-steps would involve a factor of M squared, three half-steps a factor of M cubed, and so forth.

Therefore, to compute the pitch value of the second note of a major chord, multiply the first value by M raised to the fourth power. To compute the third pitch, multiply the first by M to the seventh power, and to compute the fourth, multiply the first pitch by M to the twelfth power, which is just two. This procedure will result in pitch values for any major chord, regardless of the starting value. The only limitation is that we are restricted to eight bits in which to specify a pitch, which gives us a range from zero to 255 to work with.

If we continue with our example of the C-major chord, we start with a pitch value of 121 for middle C and proceed to compute the rest of the chord as follows:

C = 121
E = 121/(2^(4/12)) = 96
G = 121/(2^7/12)) = 81
C = 121/2 = 60

Program 1 is a demonstration which puts all of this information together. This program allows you to select a starting pitch and play either a major or minor chord built upon the selected low note. The desired chord will then be played for a few seconds.

Scales, Chords, And Duets

If you prefer, you can generate scales using a similar technique. Program 2 allows you to play a major, minor, or chromatic scale of one octave, given a starting pitch. All major scales consist of eight notes and have the following interval pattern: whole-step, whole-step, half-step, whole-step, whole-step, whole-step, and half-step. Minor scales also have eight notes, but they differ from major scales in that the third and sixth notes are each dropped down a half-step. A chromatic scale includes every half-step in an octave, which results in 13 notes.

When a song is transposed it simply means that you are playing the same tune, but starting it on a different note. To do this, multiply (or divide) the variable used to hold the pitch values of the song by a constant of your choice.

Do you have a program which plays a few random notes? Perhaps it would sound better to play random chords instead. Once you have selected your random low note, use the previously mentioned techniques to generate the other notes.

Have you tried to play piano along with your Atari? If so, you may have found that they were not quite in tune with each other. It could be expensive to tune your piano, so tune your computer instead. Find a pitch value that sounds in tune with middle C on your piano (or other instrument). Then divide by M repeatedly to generate pitch values for higher notes, and multiply by M to compute the lower notes. Remember, your pitch values must stay in the range from zero to 255. Now use the table you have generated to replace the one given in the Atari BASIC Manual. You can start playing duets with your Atari.

Program 1: Major And Minor Chords

10 DIM D (3)
20 D (1) = 1.25992103
30 D (2) = 1.1892071
40 D (3) = 1.49830706
60 IF X1>255 THEN 50
80 X2=X1/D(Y)
90 X3=X1/D(3)
100 X4=X1/2
110 SOUND 0, X1, 10, 10: SOUND 1, X2, 10, 1
    0:SOUND 2, X3, 10, 10: SOUND 3, X4, 10, 10
120 FOR X=1 TO 1000 : NEXT X
130 FOR X=0 TO 3:SOUND X, 0, 0, 0, : NEXT
140 STOP

Program 2: Scale Generation

10 DIM D (2)
20 D (1) = 1.12246203
30 D (2) = 1.05946308
50 IF X>255 THEN 40
   C";: INPUT Y
70 IF Y=3 THEN 200
80 GOSUB 500
90 X = X/D (1) : GOSUB 500
100 X = X/D (Y) : GOSUB 500
110 IF Y = 2 THEN X = X/D (2)
120 X = X/D (2) : GOSUB 500
130 X = X/D (1) : GOSUB 500
140 X = X/D (Y) : GOSUB 500
150 IF Y = 2 THEN X=X/D (2)
160 X = X/D (1) : GOSUB 500
170 X = X/D (2) : GOSUB 500
180 STOP
200 GOSUB 500
210 FOR I = 1 TO 12
220 X = X/D (2) : GOSUB 500
230 NEXT I
240 STOP
500 SOUND 0, X, 10, 10
510 FOR Z = 1 TO 200 : NEXT Z
520 SOUND 0, 0, 0, 0