Sound Advice Series

We continue our series by explaining how to fully exploit the sound effects channel.

Volume 2

Number 1

March 1984

Rocket attack? No, it's just white noise

More sound advice from NIGEL PETERS

THE Editor asked me what this month's article would be about. "The sound effects channel, sir", I answered meekly.

He staggered off to a lunch time planning meeting at the Ram and Buffer and I settled down to my work. I nearly leapt out of my skin when he crept up behind me and yelled "Boo".

"So that's how sound affects you", he cackled as he dodged the User Guide.

AS I told the Editor, this month well be covering the sound effects channel. This is the channel you select by making the first parameter of the SOUND command equal to zero.

You'll be using lots of SOUND commands such as:

SOUND 0,-15,2,40

With channel 0 you can create all sorts of weird and wonderful effects -especially when you start to use the ENVELOPE command which we'll come to in next month's Micro User.

In all there are eight basic sound effects available on channel 0. You can get them by making the pitch parameter of a channel 0 command equal to a number between 0 and 7.

Type in Program I, run it and you'll get a conducted tour through the various noises. Figure I summarises the result each value of the pitch parameter has on a channel 0 SOUND command.

10 REM PR0GRAM I
20 REPEAT
30 FOR pitch=0 TO 7
40 CLS
50 PROCnoise(pitch)
60 NEXT pitch
70 UNTIL FALSE
80 END
90 DEF PROCnoise(pitch)
100 PRINT TAB(5,5) "This is noise number ";pitch;"."
110 IF pitch=3 OR pitch=7 THEN PRINT TAB(5,15)"This can be veried by using" TAB(5,17)" a sound on channel 1"
120 PRINT TAB(5,20) Press a key for next noise."
130 SOUND 0,-15,pitch,255
140 Wait=GET
150 SOUND &10,0,0,0
160 ENDPROC

So to use the sound effects channel we use a SOUND command such as:

SOUND 0,-15,pitch,20

where pitch has a value between 0 and 7. The value you give to pitch decides what kind of sound effect you get.

As you'll see from Figure I, putting in values of 0, 1 or 2 all give something called "periodic noise".

Value of P

Noise produced on channel 0

0

High frequency periodic

1

Medium frequency periodic

2

Low frequency periodic

3

Periodic - frequency depends on pitch of channel I

4

High frequency white

5

Medium frequency white

6

Low frequency white

7

White - frequency depends on pitch of channel 1.

Figure I: Pitch values on channel 0

If pitch is equal to 0 you get high frequency periodic noise. Enter:

SOUND 0,-15,0,40

and you'll see (or, rather, hear) what I mean.

As you might guess, values of pitch of 1 and 2 give medium frequency and low frequency periodic noise respectively. Try:

SOUND 0,-15,1,40

and:

SOUND 0,-15,2,40

if you don't believe me.

To hear all three in order run Program II.

10 REM PR0GRAM II
20 FOR pitch=0 TO 2
30 SOUND 0,-15,pitch,20
40 NEXT pitch

This should help you hear the difference between the three.

If you want you can use a selection of periodic noises to produce something approaching a "Close Encounters" noise.

Program III does this by playing each of the periodic noises in turn over and over, the duration of each note getting less each time round the REPEAT . . . UNTIL loop.

10 REM PROGRAM III
20 time=20
30 REPEAT
40 FOR pitch=0 TO 2
50 SOUND 0,-15,pitch,time
60 NEXT pitch
70 time=time-2
80 UNTIL time=0

Notice that it is time and not TIME in the above program. TIME refers to the internal clock of the micro and could cause some funny results if used!

For the moment let's ignore what happens when you make the pitch equal to 3 and go straight on to what happens when you make it 4, 5, or 6.

If pitch has these values, channel 0 produces "white" noise.

If you want to know what that is then enter:

SOUND 0,-15,4,100

This will give you five seconds of high frequency white noise. It won't come as a surprise to learn that:

SOUND 0,-15,5,100

will give you five seconds of medium frequency white noise and:

SOUND 0,-15,6,100

five seconds of low frequency white noise.

Try Program IV which plays all three one after the other for a gradually decreasing time.

It's very like Program HI, so don't type it all in again. Just use the Copy key and change the lines you have to:

10 REM PROGRAM IV
20 time=20
30 REPEAT
40 FOR pitch= 4 TO 6
50 SOUND 0,-l5,pitch,time
60 NEXT pitch
70 time=time-2
80 UNTIL time=0

Now what does all that white noise remind you of? A steam engine?

Try Program V. This uses the white noise pitch parameters in a REPEAT... UNTIL loop to make the sounds of an accelerating engine.

The REPEAT . . . UNTIL FALSE loop takes over when the engine is at full speed.

10 REM PROGRAM V
15 REM STEAM ENGINE
20 time=20
30 REPEAT
40 FOR pitch=5 TO 6
50 SOUND 0,-15,pitch,time
60 NEXT pitch
70 time=time-2
80 UNTIL time=10
90 REPEAT
100 SOUND 0,-15,5,time
110 SOUND 0,-15,6,time
120 UNTIL FALSE

Still, enough of this nostalgia. What about the two values we've ignored? What do they do?

It's quite simple really, if you think about it. We've been using the bit of the SOUND command that we normally use for selecting the pitch (higher or lower) to pick the kind of noise we want, white or periodic.

So how do we change the pitch of the noise we are making? Can we make the white noise and the periodic noise go up and down in pitch like normal notes on the other sound channels?

The answer is that we can, using values of 3 and 7 in the pitch parameter of a channel 0 SOUND command.

If you put these values in the pitch parameter then the pitch of the noise that is played depends on the pitch of a note that is playing on sound channel 1.

In other words, by using 3 or 7 you can use a SOUND command on channel 1 to alter the pitch, higher or lower, of periodic and white noise, respectively.

Program VI shows this being done with the pitch parameter in line 30 set at three. Run it and see what happens.

10 REM PROGRAM VI
20 FOR pitch=100 TO 200
30 SOUND 0,-15,3,20
40 SOUND 1,0,pitch,20
50 NEXT pitch

As you'll hear, the pitch of the noise goes upwards. This is because the FOR ... NEXT loop is raising the note produced by the channel 1 SOUND command in line 40.

The pitch of the note produced by line 30's channel 0 SOUND command varies with the pitch of the note from channel 1.

If you look carefully at line 40 you'll see that the amplitude has a value of 0 which means that you can't hear what is being played on that channel.

It still varies the noise on channel 0, however. In fact it's a good thing that you can't hear the channel 1 note.

Run Program VII and you'll see what I mean.

10 REM PROGRAM VII
20 FOR pitch=100 TO 200
30 SOUND 0,-15,3,20
40 SOUND l,-15,pitch,20
50 NEXT pitch

A mess, isn't it?

Now try Program VIII which, like Program VI, plays a rising sequence of periodic noises.

10 REM PROGRAM VIII
20 FOR pitch=50 TO 100
30 SOUND 0,-15,3,40
40 SOUND 1,0,pitch,40
50 NEXT pitch

Both of the duration parameters of the SOUND commands are the same.

What would happen if they were different?

Try changing the duration parameter in line 40 to 20 or 10 or 60 and see what happens.

Can you explain the odd effects? I'll give you a clue if you just stand in the queue!

If you make the pitch parameter 7 instead of 3 in the last three programs you'll see that channel 1 has the same effect. Only this time it's a rising stream of white noises that are produced.

Finally, let's have some sound effects. Run Programs IX and X and you'll see what you can do with 3 and 7 as the pitch parameters.

The first uses periodic noises to produce a motorbike or moped sound:

10 REM PROGRAM IX
20 REM MOTOR CYCLE
30 FOR pitch= 100 TO 120
40 SOUND 0,-15,3,5
50 SOUND 1,0,pitch,5
60 NEXT pitch
70 SOUND 1,0,pitch,80
80 SOUND 0,-15,3,80
90 FOR pitch= 120 TO 100 STEP -1
100 SOUND 0,-15,3,5
110 SOUND 1,0,pitch,5
120 NEXT pitch
130 SOUND 1,0,pitch,20
140 SOUND 0,-15,3,20

The second uses white noise to imitate an unsuccessful rocket!

10 REM PROGRAM X
20 REM ROCKET
30 FOR pitch= 100 TO 200 STEP 4
40 SOUND 0,-15,7,5
50 SOUND 1,0,pitch,5
60 NEXT pitch
70 SOUND 1,0,pitch,GO
80 SOUND 0,-15,7,80
90 FOR pitch= 200 TO 100 STEP -4
100 SOUND 0,-15,7,5
110 SOUND 1,0,pitch,5
120 NEXT pitch
130 SOUND 0,-15,6,60

Anyway, that's all for now. If you've liked these sound effects, just wait until we deal with the ENVELOPE command.

As it is, I've got to go and tell the Editor that we're not under rocket attack and that it's safe to crawl out from under the desk.

Sound affects him, too!

Nigel Peters