Classic Computer Magazine Archive COMPUTE! ISSUE 70 / MARCH 1986 / PAGE 10

TI Music

I have seen TI-99/4A programs that create music with DATA statements. Please show me how this is done.

Tim Huemmer

Though the DATA statements play a part in the process, the TI actually makes sound with CALL SOUND. Here's the simplest form of the statement:

CALL SOUND(d,f,v)

The first value in parentheses (d) sets the duration for the sound. The second value (f) sets the frequency, and the third (v) sets the volume. CALL SOUND lets you produce as many as four tones at once, so with a statement like CALL SOUND (d,f1,v1,f2,v2,f3,v3) it's possible to create a three-note chord. In this case, f1, f2, and f3 represent the frequencies of the three notes, and v1, v2, and v3 represent their respective volumes. Of course, in a program you'd substitute real numbers or variables inside the parameters.

Where do DATA statements come into the picture? In most cases, it's simplest to read the music data from DATA statements and assign it to variables inside parentheses in CALL SOUND. This saves program space and makes the music data easier to understand and modify. Here's a short example of how it's done:

100 V = 5
110 FOR I = 1 TO 5
120 READ D, F1, F2, F3
130 CALL SOUND(D, F1, V, F2, V, F3, V)
140 NEXT I
150 DATA 1500, 262, 330, 390
160 DATA 250, 262, 349, 440
170 DATA 1500, 262, 349, 415
180 DATA 250, 277, 349, 415
190 DATA 1500, 277, 370, 466
200 DATA 250, 262, 392, 466

This program plays five three-note chords. Line 100 assigns the value 5 to the variable V. Since the CALL SOUND statement uses V to set the volume for every note, it stays the same throughout the program. Line 120 READs in new DATA items for each chord, setting the duration with the variable D and the three note frequencies with variables F1, F2, and F3. The frequency values for the notes are found in the appendix in the TI User's Reference Guide. You can read more about TI sound in COMPUTE!'s Programmer's Reference Guide to the TI-99/4A by C. Regena. Several of her monthly columns in COMPUTE! have also covered this topic.