Timex-Sinclair Survival Column

Authors

Publication

Date

Pages

One of the features included on the T/S 2068 which is very rarely, if ever, fully utilized is the ability to produce a wide range of sounds. These sounds can range from simple audio prompts through three part harmony. In fact, there are two different commands on the T/S 2068 to utilize the sound making capabilities. Of the two, the BEEP command is the easier to use, and therefore is the most common to find in a program.

The BEEP command utilizes only two arguments; one determines the pitch of the sound (high or low); the second controls the duration (length of time) of the sound. The pitch is represented by numbers in the range of – 60 to 69. The longest note you can produce can be sustained for 10 seconds. Try this program to get some idea of how this command works:

10 PRINT AT 10,5;"PITCH VALUE: ", 
20 FOR I = - 60 TO 69
30 PRINT AT 10,18;t;""
40 BEEP .5,f
50 NEXT f

The sound itself is produced in line 40, where “.5” represents the duration of the sound, and the “f” represents the (varying) pitch of the tone we are producing. Try altering the first argument to see how that affects the tone. As you can see, the very low tones, starting at the pitch represented by -69, are so low that they appear to be a series of slow pulses or clicks. It is not until about the mid – 30’s that a recognizable tone is produced. The pitch in the upper registers eventually go out of the range of many people’s hearing. With this program you can see at what value the sounds occur so that you can use that information in your own programs.

You can use this information to add a sound after any written prompt you may have in your programs, or programs you may have bought and wish to improve. A good set of values to start with may be a duration of .5 and a pitch of 0 (which, for those of you who know some music, represents middle C). You may want to adjust these values for your own taste. You may also use a tone to indicate an illegal choice. A good selection of pitch would be in the lower range as indicated below:

10 PRINT #0;" PRESS ""y"" or ""n""" 
20 LET g$ = INKEY$: IF q$ = "n" THEN GO TO 20
30 IF q$= "y" OR q$ = "n" THEN GO TO 200
40 BEEP .5,- 35
50 GO TO 20
200 PRINT "Correct response"
210 IF INKEY$<>"" THEN GO TO 210
220 GO TO 20

This can be used at a menu prompt or any time a decision is required. If an invalid response is attempted, a razz will be sounded, and the program will be sent back to await a proper entry. In addition to audible prompts, the BEEP command may be used to play music on your T/S 2068. Try this program:

1 FOR 1=0 TO 7: READ a: POKE USR "a" + 1,a: NEXT 1 
2 FOR 1=0 TO 7: READ a: POKE USR "b" + f,a: NEXT f
5 BORDER 6: PAPER 6: CLS
10 FOR i= 1 TO 26
20 PRINT AT 5,t; PAPER 2;" "
30 FOR j=6 TO 16 STEP 2
40 PRINT AT j, PAPER 7;" "
50 PRINT AT j+1,i; PAPER 2;" "
60 NEXT j
70 NEXT i
100 FOR i=1 TO 13
110 FOR j=5 TO 10
120 PRINT AT j,i; PAPER 1;" "
130 NEXT j
140 NEXT i
200 FOR j=6 TO 9
210 FOR i=2 TO 10 STEP 2
220 PRINT AT j,i; PAPER 1; INK 7;"#"
230 NEXT i
240 PRINT AT j,i; PAPER 1; INK 7;""
250 NEXT j
260 PRINT AT 10,2; PAPER 1; INK 7;"#"
270 FOR f=1 TO 12: READ a,i: BEEP a/2,i: NEXT f
280 STOP
1000 DATA 60,60,60,60,0,0,0,0
1010 DATA 0,0,0,0,60,60,60,60
1020 DATA 1.1,7,.5,4,1,0,1,4,1,7,2,12,1,16,.5,14,1,12,1,4,1,6,2,7

NOTE: # = GRAPHIC A * = GRAPHIC B

As you can see, this program creates a picture and then plays an appropriate tune. (No I am not going to tell you what the graphic is or which tune is played. You will have to type this in to find out.) Lines 1 and 2 create user defined graphics which are used by using the GRAPHIC A and GRAPHIC B. (Press CAPS SHIFT/9 to get into or out of GRAPHICS mode.) The DATA statement at line 1000 defines the GRAPHIC A character, while the DATA statement in line 1010 is used for the GRAPHIC B definition. The tune is generated by the single line at 270. As you can see it is a simple loop which READS the DATA at line 1020. This DATA statement contains the sets of duration values and pitch values which are READ in 270:2 and played in 270:3. Notice the BEEP statement in this line. In this example the value for the tone’s duration is divided by 2. Try varying this number and see how that affects the tune. We will discuss this in more detail soon. (How would you replay this tune without erasing or redrawing the picture? This next program contains a clue.)

1 BORDER O: PAPER O: INK 9: CLS 
2 CIRCLE 125,90,3: CIRCLE 125,90,70: CIRCLE 143,107,3: CIRCLE 107,107,3
3 PLOT 125,70: DRAW 50,13: PLOT 125,70: DRAW 50,0: PLOT 125,70: DRAW 50, -13
4 PLOT 125,70:DRAW -50,13: PLOT 125,70: DRAW -50,0:PLOT 125,70: DRAW -50,- 13
5 ON ERR GO TO 9000
10 READ a: READ b
15 BORDER INT (RND*8)
20 BEEP a/2,b
30 GO TO 10
1000 DATA 1.5,12,1.75,12, 5,11, 5,12,1,14,.25,12,25,9
1010 DATA 1.5,12,2,12, 5,11,5,12,.5,14,75,12,.25,7
1020 DATA 1.5,9,2,9,5,5,.5,7, 5,9,5,7, 5,5,4,4
1030 DATA 1,4,.5,7,1.5,7,1,2, 5,4.65,5,65,7,.65,9,.65,11
1040 DATA .5,12,5,11,5,9,3,7,5,-60,5,4,.5,0,4,7,.5,-3,1,-3,5,-1,3,0
9000 ON ERR RESET
9005 INPUT "PRESS ENTER TO REPEAT";2S
9010 GO TO 5

Notice that in this case it was necessary to RESET the DATA pointer to the beginning to play the tune again. In the case of the previous program, in order to simply replay the tune, it would be necessary to RESET the pointer – not to the first DATA statement, but to the beginning of the third DATA statement, as this is the start of the musical data. In the first program we knew just how many notes we wanted to play and made the FOR..NEXT loop exactly that length. In the second program, however, since the tune is quite a bit longer, we made use of the fact that if we instructed the com- puter to READ more than is in the DATA statements, it would return with an error message. Using the T/S 2068’s error trapping capabilities, we cause the program to jump to the routine which will ask if you want to repeat the song. But how do you determine what values to use for both the pitch and the duration of each note? Dismissing trial and error as a method, you need to know just a little about reading music to accomplish this. The accompanying chart will show you the value of the two scales (in the key of C major for those of you who understand these things) centering on middle C – the centermost key on a standard 88 key piano.

C                -12
D -10
E -8
F -7
G -5
A -3
B -1
Middle C 0
D 2
E 4
F 5
G 7
A 9
B 11
C 12

You will recognize this if you type in and run a program:

10 FOR f= 1 TO 15 
20 READ a
30 BEEP .5,a
40 NEXT f
50 DATA -12,-10,-8,-7,-5,-3,-1,0,2,4,5,7,9,11,12

You can use the values not mentioned here for the sharps and flats, which are the pitches between the values listed. A sharp (#) raises the note one half tone, therefore you would use the next higher number. On the other hand, a flat (b) lowers the tone one half step so you would use the next lower value. The duration is determined by the shape of the note. For the most part you will be dealing with four or five different types:

Whole note          4 beats
Half note 2 beats
Quarter note 1 beat
Eighth note 1/2 beat
Sixteenth note 1/4 beat

These values are based on the 4/4 (or COMMON) time musical notation, but the relationships will not vary, and you really do not have to be concerned about this. By assigning a value of 1 to a quarter note, you automatically assign a whole note the value of 4; a half note a value of 2; en eighth note the value of .5; and a sixteenth note the value of .25. As demonstrated in line 270 of the first program, and 20 in the second program, you can speed up or slow down the tempo (speed) of the piece by either dividing (to speed up) or multiplying (to slow down) this number. This is much easier than re-doing (and re-figuring) the values for each new tempo.

The T/S 2068 also has the ability to produce an even wider range of sounds and music by utilizing the SOUND command. With this command you can create sound effects, or music with three part harmony. This was part 1 of a series on sound on the Sinclair computers. The next installment will cover the use of the SOUND command.

Next month, with the holiday season upon us, we will have our second annual round-up of Sinclair related products, and listing of vendors still supporting the line. It you have a favorite product and/or vendor, please drop me a card in care of Computer Shopper. Until then….

Products

 

Downloadable Media

 

Image Gallery

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top