Classic Computer Magazine Archive COMPUTE! ISSUE 21 / FEBRUARY 1982 / PAGE 44

Transposition

Janet Whitehead
Saint John, N.B., Canada

Editor's Note: This transposition algorithm works on both Atari and PET/CBM. We hope to see some exciting harmony or other musical applications as suggested by Janet at the end of her article.—RTM

On first observation, the sound command SOUND V,N,T,L seemed to have a lack of pattern for the sequence of numbers representing the note N. I recalled a question in a high school mathematics book that stated that the frequency of A above middle C was 440 cycles per second. To obtain the next higher note on a musical scale multiply by 2&frac112;, for a lower note divide by 2&frac112;; thus one can find the frequency of each of the twelve notes in an octave. (I am considering each octave as containing twelve notes, the five black notes as well as the seven white ones on a piano).

This, I thought, must be the basis for the sequence of numbers used for notes in Atari BASIC. As the value of N is from 0 to 255 (one byte), the frequency was not used, but some multiple of it. As frequency increases the pitch increases, but the value of N decreases as the pitch increases. Therefore, to increase the pitch you divide N by 2&frac112; instead of multiplying by 2&frac112;.

This property can be used to transpose music. To raise a composition by one-half tone, one only needs to divide the N value by 2&frac112;, for a full tone divide by (2&frac112;)2, for a tone and one-half by (2&frac112;)3 etc.

To illustrate these properties, here are two simple programs. Program 1 prints the sequence of number used for N in the sound command. To obtain the sequence in Atari BASIC by Albrecht et al. an original N value of 259 was used instead of 255. If you find that these give values for N which produce sharp or flat tones, just change the 259.

Program 1:

Line 40: T1 finds successive values of (2&frac112;)0, (2&frac112;)1, (2&frac112;)2 etc.

Line 50: Successive one-half tones, N values, are calculated.

Line 60: The results are printed.

Notice that, for notes one octave apart, the ratio of the two N values is 2:1.

Program 2:

This plays a few bars of music to illustrate how a piece of music can be transposed through one octave.

Line 100—Sets the voice to 0, the tone as 10, and the loudness at 10.

Line 110-120—M is the value of 2&frac112; and T1 is the number of half-tones to transpose the music.

Line 140—M1 calculates the value of (2&frac112;)T1 which is the factor by which each N value must be divided to raise a piece by T1 half tones.

Line 150—A holds the original value of N, and B indicates the length of time it is to be played. A is then transposed the desired number of half tones. The note is then played.

Line 170—As the program plays the few bars of music through each successive half tone for one octave, this line increases the amount N is to be transposed one half a tone. As the data must be read each time, it needs to be RESTOREd.

Caution: If you exceed an N value of 255 in your transposition, you will get a very high pitched note. Only one byte is used for N, so 257 would be 1.

Perhaps some reader can expand on this to play chords or generate harmony. Knowing very little about music, I will have to leave that task to someone else.

Program 1.

10 M=2^(1/12)
20 T=0
30 For I=1 To 40
40 T1=M^T
50 N=259/T1
60 PRINT I, INT (N+0.5)
70 T=T+1
80 NEXT I
90 END

Program 2: Atari Version

100 U = 0 : T = 10 : L = 10
110 M = 2^(1/12)
120 T1 = 0
130 ? : ? "HAPPY BIRTHDAY"
140 M1 = M ^ T1
150 FOR X=1 To 26 : READ A, B : A = INT (A/M1 + 0.5) : SOUND V, A, T, L
160 For I = 1 TO B : NEXT I : SOUND V, 0, 0, 0 : NEXT X
170 T1 = T1 + 1
180 IF T1 < 12 THEN RESTORE 190 : GOTO 140
185 END
190 DATA 122, 64, 122, 64, 109, 128, 122, 128, 92, 128, 97, 256
200 DATA 122, 64, 122, 64, 109, 128, 122, 128, 82, 128, 92, 256
210 DATA 122, 64, 122, 64, 61, 128, 73, 128
220 DATA 92, 64, 92, 64, 97, 128, 109, 128
230 DATA 69, 64, 69, 64, 73, 128, 92, 128, 82, 128, 92, 256

Program. 3: CBM Version

100 POKE 59467, 16 : POKE 59466, 15 : POKE 59464, 0 : S = 59464
110 M = 2 ^ (1/2)
120 T1 = 0
130 PRINT "HAPPY BIRTHDAY
140 M1 + M ^ T1
150 FOR X = 1 TO 26 : READA, B : A = INT (A/M1 +.5) : POKES, A
160 FOR I = 1 TO B + B/2 : NEXT I : POKES, 0 : NEXT X
165 REM VALUE OF B IS INCREASED HERE TO EQUALIZE THE DIFFERENCES IN SPEED
168 REM BETWEEN THE CBM/PET AND THE ATARI
170 T1 = T1 + 1
180 IF T1 < 12 THEN RESTORE : GOTO 140
185 POKES 59467, 0 : END
190 DATA 122, 64, 122, 64, 109, 128, 122, 128, 92, 128, 97, 256
200 DATA 122, 64, 122, 64, 109, 128, 122, 128, 82, 128, 92, 256
210 DATA 122, 64, 122, 64, 61, 128, 73, 128
220 DATA 92, 64, 92, 64, 97, 128, 109, 128
230 DATA 69, 64, 69, 64, 73, 128, 92, 128, 82, 128, 92, 256