Classic Computer Magazine Archive COMPUTE! ISSUE 52 / SEPTEMBER 1984 / PAGE 148

Musical TI Keyboard

Randal J. Reifsnider

The TI music chip has long been regarded as an excellent sound chip, but few programs have yet demonstrated its capabilities. "Musical TI keyboard" changes all that by turning your TI's keys into simulated piano keys.

In the book Beginner's BASIC that comes with the TI-99/4A computer, there is a short demonstration program illustrating how you can use the computer's keyboard to make musical tones. When you run this program and press the A key, the musical tone A will sound. The tone will continue as long as you hold down the key, with a slight gap of silence between repetitions of the tone. This sounds like a musical machine gun. It is an interesting program, but very limited. Since it uses only seven letters of the alphabet to represent musical notes, you could play only seven notes on the computer in this fashion (A through G, with no sharps or flats).

Also, if you play the piano and are familiar with its keyboard arrangement, you'll find that looking for letters feels unnatural and difficult. Hence, "Musical TI Keyboard," which makes the computer's keyboard more closely resemble that of a piano.

This program first READs frequency values from DATA statements into an array, then mathematically converts the ASCII code returned by the CALL KEY statement, and uses that value in the CALL SOUND statement to locate the corresponding frequency value within the array. The figure shows the arrangement of the keyboard. Since not all the keys are used, the program includes a check to silence any unwanted keys. ASCII code numbers of silenced keys which fall within the array are assigned a DATA value of 1 as a filler. This allows the array to be easily filled and insures that the ASCII code for a given key corresponds to the proper frequency.

Program Variations

One variation of this program you may want to try would be:

90 CALL SOUND (100, NOTE(Q), 1, 1.26*NOTE(Q), 5, 1.5*NOTE(Q), 5)

This would produce a major chord for each key pressed. To create minor chords, try:

90 CALL SOUND (100, NOTE(Q), 1, 1.19*NOTE(Q), 5, 1.5*NOTE(Q), 5)

If you change the duration from 100 to –150, the computer will play continuous tones. A value for a noise (–1 through –8) could be added to the CALL SOUND statement for an interesting effect. The space bar could be assigned a noise value for use as percussion. Since this program requires that the ALPHA LOCK be on, additional tones or noises could be assigned to what would be the lowercase letters.

Even though we do have a piano, our four-year-old daughter would rather play the computer. However, you can take the program further. You could include a routine within the program to print out the duration, frequency, and sequence of the notes you play on the computer's keyboard. This could be extremely helpful when tackling the laborious task of transposing sheet music so that it can be played by the computer. You could also try creating a routine that would play back any song played on the computer.

To make playing your computer/piano keyboard easier, you might want to buy two different colors of small gummed labels, like those sold in office supply stores. These may be placed on the computer keys to distinguish the white keys from the black keys. Novice musicians may also wish to write the name of the note on the label as an aid to playing. These labels can be easily removed when you are ready to let the computer go back to its regular keyboard functions.

Musical TI Keyboard

10 CALL CLEAR
20 DIM NOTE(47)
30 FOR C = 1 TO 47
40 READ NOTE(C)
50 NEXT C
60 CALL KEY(0, N, S)
70 IF (N < 44) + (N = 45) + (N = 49) + (N = 52) + (N = 56) + ((N > 57) * (N < 66)) + (N = 68) + (N = 72) + (N > 90) THEN 60
80 Q = N - 43
90 CALL SOUND (100, NOTE(Q), 1)
100 GOTO 60
110 DATA 220, 1, 247, 698, 622, 1, 277, 311, 1, 370, 415, 466, 1, 554, 1, 1, 1, 1, 1, 1, 1, 1, 165, 131, 1, 330, 139, 156, 1
120 DATA 523, 185, 208, 233, 196, 175, 587, 659, 262, 349, 117, 392, 494, 147, 294, 123, 444, 110