The fourth sound channel, channel 0, which we have barely mentioned so far, is the noise channel. It is responsible for the unpitched sounds which emanate from the computer. Without it, games would have no bangs or crashes; and it has far more subtle uses in either types of program as we shall see.
It is also capable of producing pitched sounds lower than the pitch of the lowest B (P=1) but we will begin by looking at the parameters and values relevant to channel 0.
The parameters for channel 0 are the same as for the other channels, but the P or pitch parameter has a range of only 0 to 7 and produces a different effect. This was described in Chapter 4, and is repeated in Figure 7.1 for easy reference.
Figure 7 .1
P PARAMETER | EFFECT |
0 | High frequency periodic noise. |
1 | Medium frequency periodic noise. |
2 | Low frequency periodic noise. |
3 | Periodic noise. Frequency is determined by the P parameter on channel 1. |
4 | High frequency white noise. |
5 | Medium frequency white noise. |
6 | Low frequency white noise. |
7 | White noise. Frequency is determined by the P parameter on channel 1 |
The periodic noise is a sort of rasping and the white noise produces a hissing sound. The periodic noise does not sound too dissimilar to that of an ordinary tone but the white noise is clearly not at all musical. Both have their uses in music and in sound effects.
All electronic circuits generate a certain amount of noise and this is generally undesirable. In synthesis this can be used in numerous ways; as a source of unpitched sounds or as an unpitched part of a pitched sound.
White noise is a combination of equal amounts of audio frequencies in the same way that white fight is a combination of all colours. If we move up the scale, say one octave from middle C (P=53) to the C above (P= 101), the actual frequency of the note doubles. The frequency doubles every octave we go up, so there are more frequencies (not counting fractions) in the higher octaves than in the lower ones. White noise, therefore, tends to contain a lot of high frequencies which are responsible for its characteristic hissing sound.
There are other forms of noise. The second most common form is known as pink noise which contains equal amounts of frequencies from all octaves and is similar to white noise with some of the higher frequencies filtered out. This is useful for producing surf and sea sounds. You can make 'red' noise by filtering out even more high frequencies and various other shades by filtering out a bit here and there but we'fl leave that to the synthesists.
There are three ways channel 0 can be used:
Program 7.1 contains six examples of sound effects. You can type in the whole program at once or one section at a time. In some cases, PROCDeIay is a part of the program, in others it is used to separate two effects.
10 REM PROGRAM 7.1
20 REM Examples of Channel 0
30 REM Sound Effects
40
50 REM Machine Gun
60 FOR Burst=1 TO 3
70 FOR Bullet=1 TO 12
80 SOUND0,-15,5,1
90 SOUND0,-15,6,1
100 NEXT Bullet
110 PROCDelay(100)
120 NEXT Burst
130 PROCDelay(100)
140
150 REM Ricochet
160 ENVELOPE1,132,28,-1,0,1,28,0,126,-
8,-3,-6,126,80
170 ENVELOPE2,6,0,0,0,0,0,0,126,-8,-3,
-6,126,80
180 FOR Shot=1 TO 3
190 SOUND2,1,149,20
200 SOUND0,2,6,20
210 NEXT Shot
220 PROCDelay(400)
230
240 REM Cymbal or Anvil
250 ENVELOPE1,3,0,0,0,0,0,0,126,-4,-2,
-4,126,100
260 ENVELOPE2,3,0,0,0,0,0,0,80,-2,-2,-
2,80,40
270 FOR Clang=1 TO 8
280 SOUND&101,1,197,1
290 SOUND&100,2,4,4
300 PROCDelay(100)
310 NEXT Clang
320 PROCDelay(200)
330
340 REM Creature
350 ENVELOPE1,4,0,0,0,0,0,0,32,-1,0,-4
,126,0
360 SOUND1,0,220,0
370 FOR Step=1 TO 8
380 FOR Splodge=5 TO 7
390 SOUND0,1,Splodge,Splodge-3
400 NEXT Splodge
410 PROCDelay(200)
420 NEXT Step
430
440 REM Mad Factory
450 SOUND1,0,100,0
460 FOR Work=1 TO 16
470 FOR Noise=1 TO 7
480 SOUND0,-12,Noise,2
490 NEXT Noise
500 NEXT Work
510 PROCDelay(200)
520
530 REM Space Ship Taking Off
540 ENVELOPE1,40,0,0,0,0,0,0,126,0,0,-
2,126,126
550 SOUND0,-15,7,150
560 FOR Engines=180 TO 255 STEP.5
570 SOUND1,0,Engines,1
580 NEXT Engines
590 SOUND0,1,7,100
600 END
610
620 DEF PROCDelay(Time)
630 TIME=0:REPEAT UNTIL TIME>Time
640 ENDPROC
The Machine Gun just alternates between two pitches of white noise. This principle can be used to produce a number of effects. Alter lines 80 and 90 to produce the sound of a helicopter's blade:
80 SOUND0,-15,4,1
90 SOUND0,-15,5,2
Add this line:
95 SOUND0,-15,6,1
to produce a car that doesn't want to start. Increase the D parameter in line 95 to make it even more reluctant.
The Ricochet is produced by combining white noise from channel 0 with a sound from another channel undergoing a pitch drop produced by a pitch envelope.
Two envelopes are required for this effect, as we cannot use channel 0 with the pitch drop envelope for the following reason. If you run channel 0 from an envelope containing pitch variations, you can probably guess what happens - the pitch changes run through channel 0 as they would through any other channel, and the output changes in accordance with Figure 7.1. This can be used as yet another source of effects although it is not so easy to use methodically, .especially if channel I is undergoing pitch variations too.
Returning to the Ricochet, two envelopes are also needed to ensure that the volume levels of the respective sounds are correct.
The sound produced by channel 2 alone might be acceptable as a passing seagull.
This is similar to the Ricochet in that it combines white noise with a pitch. The two have been synchronized to ensure a clean percussive start, although in this context the difference would be minute. Again, two envelopes are used, this time purely to control relative volumes.
Synthesisers usually produce a cymbal sound with a little chuff of white noise, sometimes with a ping added as we have done here. The result is usually a very electronic-sounding cymbal. If you reduce the duration of the effect, you will get metallic-like clicks.
This is an attempt to produce an organic sound, ie one emanating from a living creature. It is intended to portray a creature with rasping breath walking through wet mud. Obviously, you need some imagination to accept all that but you may find it a useful start for further experiments. Try a backwards envelope to produce a sharp intake of breath and a variation on the Ricochet to produce a wheeze to follow.
This was inspired by comedy scenes from old films in which all mechanical devices bang, clang or hiss - often used for a car as it falls to pieces.
The idea is very simple. The loop calls each of the P parameters in turn. Note that channel 1 has been set in line 360 to fix the pitch when P is 3 and 7.
As mentioned earlier, you could replace the loop with a single envelope; I leave it to you to work out the details. Also, alter the pitch of channel 1 and see how it affects the program as a whole.
Sounds are not generally thought of as humorous. Perhaps you can develop this into something more.
This illustrates an extreme example of the pitch on channel 1 controlling the pitch on channel 0. The STEP value in line 560 makes the build-up last longer and the, possibly excessive, release stretches the final sound out to around half a minute. This could easily be increased . . .
As some of the best effects from channel 0 are produced in association with other channels, and with channel 1 in particular, it is not easy to plan a methodical search to discover all its possibilities. Once you know what each P parameter does, however, it will be easier to imagine them in different contexts. You may find the Envelope Comparison program in Chapter 6 useful. If you add an extra line:
185 SOUND0,-15,3,40
you can put channel 0 under envelope control. If you do not want to hear channel 1, you must make sure the volume sections of the envelopes are silent.
Although the accent of this book is on understanding the principles involved in creating sounds, many of the effects produced with the pitch envelope and channel 0 (not necessarily together) are difficult to predict. If we go one step further, we can give the computer the task of creating new effects: the results will then be totally unpredictable.
The Sound Effects Generator program produces random sets of envelopes while still giving you control over various aspects of the sound.
10 REM PROGRAM 7.2
20 REM Sound Effects Generator
30
40 *TV255,1
50 MODE7
60
70 PROCSetUp
80 PROCOptions
90
100 REPEAT
110 PROCInput
120 REM Cursor Off
130 VDU23;11,0;0;0;0
140 PROCAction
150 PROCPrintEnv
160 PROCOptions
170 REM Cursor On
180 VDU23;11,255;0;0;0
190 UNTIL Input$="Q"
200 END
210
220 DEF PROCSetUp
230 SN$="Both "
240 Rep$="On "
250 P=3
260 Pitch=101
270 Inp$="EPRSNTAQ"
280 PROCSetSN
290 ENDPROC
300
310 DEF PROCSetSN
320 SAA=126:SAD=-1:SAS=0:SAR=-4
330 SALA=126:SALD=80
340 NAA=126:NAD=-1:NAS=0:NAR=-4
350 NALA=126:NALD=80
360 ENDPROC
370
380 DEF PROCOptions
390
400 FOR Title=0 TO 1
410 PRINTTAB(6,Title)CHR$134;CHR$141"S
OUND EFFECTS GENERATOR"
420 NEXT Title
430
440 PRINTTAB(12,3)CHR$133"O P T I O N
S"
450 PRINTTAB(0,5)CHR$129"E"CHR$130"nve
lope"
460 PRINTTAB(0,6)CHR$129"P"CHR$130"lay
"
470 PRINTTAB(0,7)CHR$129"R"CHR$130"epe
at Pitch Envelope"TAB(25)CHR$131;Rep$
480 PRINTTAB(0,8)CHR$129"S"CHR$130"oun
d or Noise"TAB(25)CHR$131;SN$
490 PRINTTAB(0,9)CHR$129"N"CHR$130"ois
e Parameter"TAB(25)CHR$131;"P = ";P
500 PRINTTAB(0,10)CHR$129"T"CHR$130"Pa
rameter - Alter "
510 PRINTTAB(0,11)CHR$129"A"CHR$130"lt
er Pitch"TAB(25)CHR$131;Pitch
520 PRINTTAB(0,12)CHR$129"Q"CHR$130"ui
t"
530 ENDPROC
540
550 DEF PROCInput
560 PRINTTAB(26,13)CHR$131"?? ";
570 REPEAT
580 Input$=GET$
590 Action=INSTR(Inp$,Input$)
600 UNTIL Action>0
610 PRINTInput$
620 ENDPROC
630
640 DEF PROCAction
650 ON Action GOTO 660,670,680,690,700
,710,720,730
660 PROCEnvelope:ENDPROC
670 PROCPlay:ENDPROC
680 PROCRepeat:ENDPROC
690 PROCSoundNoise:ENDPROC
700 PROCNoiseParam:ENDPROC
710 PROCTParam:ENDPROC
720 PROCAlterPitch:ENDPROC
730 ENDPROC
740
750 DEF PROCEnvelope
760 T1=RND(20):T=T1
770 PI1=-129+RND(256)
780 PI2=-129+RND(256)
790 PI3=-129+RND(256)
800 PN1=RND(256)-1
810 PN2=RND(256)-1
820 PN3=RND(256)-1
830 PROCPlay
840 ENDPROC
850
860 DEF PROCPlay
870 ENVELOPE1,T,PI1,PI2,PI3,PN1,PN2,PN
3,SAA,SAD,SAS,SAR,SALA,SALD
880 ENVELOPE2,T,0,0,0,0,0,0,NAA,NAD,NA
S,NAR,NALA,NALD
890 SOUND&11,1,Pitch,254
900 SOUND&10,2,P,254
910 ENDPROC
920
930 DEF PROCRepeat
940 IF Rep$="Off" Rep$="On ":T=T1:ENDP
ROC
950 IF Rep$="On " Rep$="Off":T=T1+128
960 ENDPROC
970
980 DEF PROCSoundNoise
990 PROCSetSN
1000 IF SN$="Sound" SN$="Noise":SAA=-12
6:SAD=0:SAS=0:SAR=-126:SALA=0:SALD=0:END
PROC
1010 IF SN$="Noise" SN$="Both ":ENDPROC
1020 IF SN$="Both " SN$="Sound":NAA=-12
6:NAD=0:NAS=0:NAR=-126:NALA=0:NALD=0
1030 ENDPROC
1040
1050 DEF PROCNoiseParam
1060 IF P=3 P=7 ELSE IF P=7 P=3
1070 ENDPROC
1080
1090 DEF PROCTParam
1100 PRINTTAB(2,10)CHR$133;"Enter T Val
ue 1 - 127"
1110 REPEAT
1120 PRINTTAB(24,10)CHR$133;CHR$136;
1130 INPUT T1
1140 PRINTTAB(26,10)SPC(8)
1150 UNTIL T1>0 AND T1<128
1160 IF Rep$="On ":T=T1 ELSE T=T1+128
1170 ENDPROC
1180
1190 DEF PROCAlterPitch
1200 PRINTTAB(2,11)CHR$133;" Enter Pit
ch 0 - 255 "
1210 REPEAT
1220 PRINTTAB(24,11)CHR$133;CHR$136;
1230 INPUT Pitch
1240 PRINTTAB(26,11)SPC8
1250 UNTIL Pitch>-1 AND Pitch<256
1260 ENDPROC
1270
1280 DEF PROCPrintEnv
1290 PRINTTAB(0,15)CHR$134"Channel 1"
1300 PRINTTAB(0,17)SPC(17)
1310 PRINTTAB(0,16)"ENVLOPE1,";T1;",";P
I1;",";PI2;",";PI3;",";PN1;",";PN2;",";P
N3;",";SAA;",";SAD;",";SAS;",";SAR;",";S
ALA;",";SALD
1320 PRINTTAB(0,19)CHR$134"Channel 0"
1330 PRINTTAB(0,21)SPC(17)
1340 PRINTTAB(0,20)"ENVELOPE2,";T;",0,0
,0,0,0,0,";NAA;",";NAD;",";NAS;",";NAR;"
,";NALA;",";NALD
1350 ENDPROC
When run, the first thing to do is press 'E'. This generates an envelope which will be printed on the screen and sounded at the same time. Every time you press 'E' a new envelope will be generated and the old one will be lost.
'P' enables you to play or repeat the current envelope.
'R' switches the repeat on the pitch envelope on and off.
'S' switches between hearing sound only, noise only or both.
'N' lets you switch the P parameter in the noise channel from 3 (periodic noise) to 7 (white noise).
'T' lets you alter the T parameter, You will be asked for a figure between 1 and 127. Enter the figure and press RETURN. The 'R' option will take care of whether or not the envelope repeats.
'A' lets you alter the pitch. It works in a similar way to the T parameter, only over a 0 to 255 range.
'Q' quits the program.
The procedures and variable names should help you understand the program. Imp$ at line 270 contains the only valid letters accepted by PROCInput. These are tested for at line 590.
PROCsetSN sets the initial amplitude levels for the sound and noise channels. This is called each time a change is made in the Sound/Noise. Both output and the relevant variables are altered in the procedure at fine 990.
PROCEnvelope sets up a random envelope every time it is called. You will notice that T is restricted to a maximum value of 20, but you can alter that if you wish. You will probably find that even values over 10 produce envelopes which are too slow. T1 is used for the initial value of the T parameter and T is finally set according to whether the envelope is to repeat or not.
PROCPlay forms the envelopes. The pitch parameters in the noise envelope are set to 0. If you alter them, alter PROCPrintEny, too. The sounds are programmed with the flush command so that you can play the sound at any time without waiting for the previous sound to terminate .
PROCTParam and PROCAlterPitch are similar and self-explanatory. PROCPrintEnv does just that. If you alter or add anything, be sure to see that this prints the correct envelope.
You may find it useful to restrict the PI and FN parameters. If you want to produce tuneful sequences you can arrange for the steps to be in multiples of four like this:
PI = StartPitch + RND(64)*4
You could also arrange to set the PI values in a certain pattern such as up/down/up.
Taking it a step further, you may want to alter individual PI or FN parameters while the program is running, in a similar way to the ADSR and Pitch Graph program. That, however, is putting the task back in your hands, not the computer's, but please do so if you wish. You could also add a procedure to adjust the relative volumes of the two channels.
Instead of having to write down the envelopes, you could arrange for the program to save the current envelope parameters in an array. A separate recall procedure could transfer the parameters of a previously saved envelope back to the current working envelope. In this way you could save more than l6 envelopes. Personally, I find it just as easy to jot them down.
Sometimes you will get a sound you like but which is not quite what you're after. You could include a less severe procedure to alter the current envelope only slightly, say by four points per parameter. Of course, you're just as likely to move away from what ou want as towards it, but at least it's not likely to be something completely different.
During your experiments, you will have noticed that the periodic noise on channel 0 sounds very like a tone from one of the other channels. If the P parameter is set to 3, we can alter the pitch of the noise by controlling the pitch of channel 1 like this:
10 FOR Pitch=200 TO 1 STEP-4
20 SOUND1 ,0,Pitch,10
30 SOUND0,- 15,3,10
40 NEXT Pitch
That should sound like a reasonable semitone scale but research indicates that the tie-in between the pitch on channel 0 and the pitch on channel 1 may not be as accurate as we would like. Figure 7 .2 indicates the pitch values of channel 1 which are necessary to produce the indicated pitch values on channel 0. These carry on downwards from the octaves fisted in Figure 3.3.
Figure 7.2
C | C# | D | D# | E | F | F# | G | G# | A | A# | B | |
0 | 144 | 148 | 152 | 156 | 160 | 164 | 168 | 172 | 176 | 180 | 183 | 188 |
-1 | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | 128 | 132 | 136 | 140 |
The relationship between these two pitch values on your computer may not be the same but should only deviate by one figure. The only anomaly in the table appears to be the A#1 but check this on your own computer. You can do an ear test by playing the relative pitch along with the same note an octave higher on channel 2. The notes produced by channel 0 may not be exact octaves of those of the other channels but they will be near enough to be of use in a composition.
You will realise that when the pitch drops' to octave -1, it starts to sound more like a buzz although it is arguably useful right down to octave C-1.
All music is written in a specific pitch and key and this method allows us to use one or two octaves of sound not normally available. Many tunes were written in and sound better in the lower octaves and these lower notes can be especially useful if the music range exceeds the five octave range of the sound chip. The only loss is any possible use of channel 0 as a rhythm accompaniment which brings us to that very topic.
After experimenting with the sounds of various guns and vehicles it is not difficult to produce a rhythm unit. The main problem, and the one requiring the most individual attention, lies in producing acceptable drum sounds. The best drum noises seem to come from channel 0 with P set to 4, 5 or 6 - the white noise settings - but do try other settings and use it in conjunction with channel 1 as described above.
You will find that duration of the sound plays a very important part in determining the drum characteristics and, if you use more than one envelope, you can vary the sound and produce quite a reasonable rhythm unit.
The next program is one way of approaching the design of a rhythm generating program. Be wary of renumbering the program because the variable, Rhythm, holds the starting line of the DATA statements containing the rhythms.
10 REM PROGRAM 7.3
20 REM Rhythm Unit
30
40 *TV255,1
50 MODE7
70 PROCSetUp
80 PROCTitlePage
90 PROCPlay
100 END
110
120 DEF PROCSetUp
130 Tempo=2
140 Rhythm=360
150 ENVELOPE1,1,0,0,0,0,0,0,126,-3,-3,
-6,126,100
160 ENVELOPE2,1,0,0,0,0,0,0,32,-4,-4,-
8,110,60
170
180 DEF PROCTitlePage
190 FOR Title=1 TO 2
200 PRINTTAB(6,Title)CHR$141;CHR$134"R
H Y T H M U N I T"
210 NEXT Title
220 PRINTTAB(1,4)CHR$129;"1";CHR$130;"
Bossa Nova"
230 PRINTTAB(1,5)CHR$129;"2";CHR$130;"
Rock"
240 PRINTTAB(1,6)CHR$129;"3";CHR$130;"
12/8 Rock"
250 PRINTTAB(1,7)CHR$129;"4";CHR$130;"
Swing"
260 PRINTTAB(1,8)CHR$129;"5";CHR$130;"
Waltz"
270 PRINTTAB(1,9)CHR$129;"Q";CHR$130;"
Quit"
280 ENDPROC
290
300 DEF PROCPlay
310 REPEAT
320 *FX15,1
330 IF INKEY(-49) Rhythm=450
340 IF INKEY(-50) Rhythm=480
350 IF INKEY(-18) Rhythm=520
360 IF INKEY(-19) Rhythm=550
370 IF INKEY(-20) Rhythm=580
380 READ Env,Pit,Dur
390 SOUND0,Env,Pit,Dur*Tempo
400 IF Env=0 RESTORE Rhythm
410 UNTIL INKEY(-17)
420 ENDPROC
430
440 REM Bossa Nova
450 DATA 1,4,2,2,5,2,2,5,2,1,4,2,2,5,2
,2,5,2,1,4,2,2,5,2,0,0,0
460
470 REM Rock
480 DATA 1,5,2,2,5,2,1,4,2,1,4,1,1,5,2
,2,5,2,2,5,1,1,4,1,2,4,1,2,4,2
490 DATA 1,5,2,2,5,2,1,4,2,1,4,1,1,5,2
,2,5,2,2,5,1,1,4,1,2,5,1,1,6,1,1,6,1,0,0
,0
500
510 REM 12/8 Rock
520 DATA 1,5,2,2,4,1,2,4,1,2,4,2,1,4,2
,2,4,2,2,4,2,1,5,2,2,4,1,2,4,1,2,4,2,1,4
,2,2,4,2,1,6,2,0,0,0
530
540 REM Swing
550 DATA 1,5,4,2,4,3,2,4,1,1,5,4,2,4,3
,2,4,1,1,5,4,2,4,3,2,4,1,1,6,2,2,4,2,2,4
,1,2,4,1,2,4,2,0,0,0
560
570 REM Waltz
580 DATA 1,5,4,2,4,4,2,4,4,1,6,4,2,4,4
,2,4,4,1,5,4,2,4,4,2,4,4,1,6,4,2,4,2,2,4
,2,2,5,2,1,5,2,0,0,0
When run, the program will play a Bossa Nova: pressing the indicated keys will alter the rhythm.
The program should be self-explanatory. As we are only using one channel, the rhythms are produced by alternating between various shades of white noise. Lines 380 to 400 do this by reading information from the DATA statements.
The envelopes in PROCSetUp play a large part in determining the drum sound. Only two have been used but you can add more to produce different instruments. For example, a very short duration will sound like a wood block and a medium-pitched noise with just a little decay will sound like a hand clap. You may wish to bring another channel in, toq. Experiment with the original envelopes to see if you can improve on the sound. The effect will be very different if played through an external speaker.
The rhythms only play one or two bars before repeating. You can add more variations by adding to the data and, of course, create more rhythms. Alter the tempo in line 130, too.
The INKEY function with a negative number in brackets reads a particular key on the keyboard (see the User Guide page 275) to see if it is being pressed. From this, the program sets the next RESTORE operation to the required line.
You will notice, if you have a 1.0 or later operating system, that the CAPS LOCK and SHIFT LOCK lights go on when the program is running. These light whenever the buffers fill up and indicate that the program is being held up waiting for the sound queue to clear. In this program, it does not really matter but if we wanted to do something else, such as play along with the rhythm, we may have a problem or two. One way around it is to replace lines 380, 390 and 400 by this single line:
380 IF ADVAL(-5)>0 READ Env,Pit,Dur:
SOUND0,ENV,Pit,Dur*Tempo:IF Env=0 RESTORE Rhythm
This ADVAL function with a negative parameter in brackets returns the number of free spaces in the channel 0 buffer. If there is a free space, it reads the next data item and processes the next sound command. ADVAL is explained on page 202 of the User Guide and we will look at it in more detail in Chapters 8 and 9.
You will notice that the lights no longer stay on because the program does not come to a halt at line 390 when the buffer is full. Instead, it continually cycles through the REPEAT loop. This means we could put other commands here, such as information for more sounds, without disturbing the rhythm - provided the new information does not hold up the program either.
While the zap of a laser blast might be considered disturbing in a utility program, sound effects can be used to enhance such programs, making them more interesting to work with and generally assisting the user.
Many people, myself included, do not like being beeped at by a computer when we make a wrong input. The most common sound on the BBC micro used for such a purpose can be made by holding down the CTRL key and pressing 'G'. It can be written into a program simply as:
VDU 7
which has the same effect.
The presentation of a program, its ease of operation and its error-trapping techniques all determine how user-friendly it is. Detailed discussions on this topic, however interesting, are beyond the scope of this book but we can look at one or two ways of improving a program through the use of sound.
If using a program is a matter of hitting a certain number of keys, eg selecting items from a menu, you could incorporate a procedure to make a small sound whenever an item is correctly selected. Something like this:
1000 DEF PROCSound
1010 SOUNDO,-12,4,2
1020 ENDPROC
This tends to give the keys a chunky feel; something a bit more solid than the tap or rattle of the keyboard. The user also knows that he or she has hit a correct key and can expect some action from it.
In place of the beep, you could use a different sound to indicate an incorrect selection - may I suggest something a little more quiet and less presumptuous.
Mistakes are generally made because the user does not understand the instructions and nothing is more frustrating than to press a key you think is right and receive only *a beep in response. Action should be directed to another part of the program to give the required information or back to the instruction sheet.
If the inputs are restricted and the program is correctly error-trapped (as it should be) and will not respond to an invalid input there may not be a need for any sound at all on an incorrect key press. This is the opposite of the normal method of operation - silence on a correct entry - and preferable in many instances.
If a program steps through a number of sections which cumulate in a result, eg a character generating program, you could incorporate a small fanfare, such as in the Motility Tester program in Chapter 1, to indicate that a section of the program has been completed and the user is about to move on to the next step. Such fanfares can be constructed from pitch envelopes.
The above suggestions can make utility programs more interesting to work with, as long as they work towards the aim of the program and are not there simply for decoration.
In such programs, it is always advisable to give the user the option of switching the sound off so that they do not have to listen to your creations, however marvellous they may be, if they do not want to.
With such a versatile computer and sound chip, there are lots of sound effect collages you could build up: trains, ships, cars, a factory, the countryside, a laboratory, the jungle, etc. The most interesting are ones which will not repeat for a long time or which do not repeat exactly. The next program uses some of the ideas discussed in this chapter to form a sea soundscape.
10 REM PROGRAM 7.4
20 REM Sea, Surf & Seagulls
30
40 ENVELOPE1,130,28,-1,0,1,28,0,63,-8
,-4,-6,126,80
50 ENVELOPE2,2,0,0,0,0,0,0,63,-1,0,-4
,126,116
60 Foghorn=0
70
80 REPEAT
90 Foghorn=Foghorn+1
100 Pitch=RND(64)+190
110 IF ADVAL(-6)>0 SOUND1,0,Pitch,0
120
130 Pulse=RND(20)+15
140 Lull1=RND(10)+25
150 Lull2=RND(10)+25
160 Flow=RND(6)+8
170 Ebb1=RND(2)+3
180 Force=RND(26)+100
190
200 Wave=RND(3)+3
210 Ebb2=RND(5)^3+129
220
230 REM Envelope for Waves
240 ENVELOPE3,Pulse,0,1,0,Lull1,1,Lull
2,Flow,-Ebb1,-1,-1,Force,90
250
260 IF ADVAL(-5)>3 SOUND0,3,Wave,Ebb2:
SOUND&1000,0,0,Ebb2
270
280 REM Seagull
290 IF ADVAL(-7)>0:IF RND(80)=1 SOUND2
,1,RND(76)+101,20
300
310 REM Foghorn
320 IF ADVAL(-8)>0:IF Foghorn>140 SOUN
D&113,2,0,80:SOUND&112,2,0,80:IF Foghorn
>140 Foghorn=0
330 UNTIL FALSE
As it stands, you just run the program, sit back and listen.
The variables in lines 130 to 180 repeatedly redefine ENVELOPE 3 in fine 240.
Wave in line 200 selects white noise with a P value of from 4 to 6. The PI2 parameter of the envelope increases the pitch parameter on channel 0 by one, so a complete wave will use two white noise types. These will be 4 and 5, 5 and 6, 6 and 7. As 7 is based on the pitch of channel 1 this is selected randomly in fine 100. Ebb2 determines how quickly one wave will finish and another begin. Notice the use of a dummy parameter in the second sound command in line 260 which lets the release phase occur and the wave ebb.
The Foghorn variable is increased automatically so the foghorn sounds regularly. Inclusion of the flush parameter will cut off a seagull in mid-call.
The seagull is produced by a variation on our Ricochet envelope in Program 7.1.
The use of ADVAL functions ensure that the program never sticks and, by using similar methods, you can add even more to it. If you add:
315 PRINT Foghorn
you will see that the program is not held up by sound queues. If you then remove the ADVAL statement in line 260:
260 SOUND0,3,Wave,Ebb2:SOUND&1000,0,0,Ebb2
you will see how the program grinds to a halt.
Although we do not have the facilities of a full-blown synthesiser, we can still produce background effects which can be played throughout a program. An extension to a soundscape could be a graphics design program controlled, possibly, by the random values produced by the soundscape. See what you can do.