Contents / Part 3 / Previous chapter / Next chapter / Index

30 Sound

The BBC computer contains integrated circuits specifically designed to generate musical sounds and noises on four 'channel'. Two statements control the generation of musical sounds; they are SOUND and ENVELOPE. For simple effects the statement SOUND can be used by itself but if the user wishes to have greater control over the quality of the sounds generated then ENVELOPE can be explored. At its simplest the sound statement is followed by four numbers e.g.


C is the channel number 0 to 3

A is the amplitude or loudness 0 to - 15

P is the pitch 0 to 255

D is the duration 1 to 235

The Channel Number, C, determines which of the four "voices" is to be used. Channel 0 produce 'noise' (this channel will be explained in detail later) whereas channel 1, 2 and 3 produce purer notes.

The amplitude, A can be varied between 0 (off) and - 15(loud).

The pitch P selects notes in quarter semi-tones intervals. Middle C is produced when P is set at 53 and other notes are generated with the values of P given opposite.

As you can see the computer can produce notes spanning five full octaves. The values of P are also shown opposite for a stave in the key of C but one octave up.

The duration D, determines the length of the note and is given in twentieths of a second. Those used to reading music will find that music marked "Moderato =60" will sound about right with the following settings for D.

Octave number
Note 1 2 3 4 5 6 7
B 1 49 97 145 193 241
A # 0 45 93 141 189 237
A 41 89 137 185 233
G # 37 85 133 181 229
G 33 81 129 177 225
F # 29 77 125 173 221
F 25 73 121 169 217
E 21 69 117 165 213
D # 17 65 113 161 209
D 13 61 109 157 205 253
C # 9 57 105 153 201 249
C 5 53 101 149 197 245

That completes the simple description of the SOUND command.

There are two main areas where the SOUND command can be extended. First instead of working with a fixed sound quality one can select an "envelope" to vary both the amplitude and the pitch of the note while it is playing; secondly it is possible to ensure that notes are synchronised so that chords start together. In addition to these major extensions there are a number of other things that can be controlled, and these will be described later.

If you wish to use an envelope to vary either the amplitude or the pitch of a note (or both) then you must first define the envelope and secondly, instead of using a fixed amplitude in the SOUND statement, you must quote the envelope number for A. Four envelopes are normally permitted and they are numbered 1 to 4.


SOUND 1,2,53,20

would produce on channel 1 a note of middle C with a duration of one second and the amplitude and pitch would be controlled by the envelope number 2.

The statement ENVELOPE is followed by 14 numbers and the following labels will be used for the 14 parameters.



A brief description of each parameter follows

Parameter / Range / Function

N / 1 to 4 / Envelope number

T bits 0-6 / 1 to 127 / length of ear h step in hundredth of a second

T bit 7 / 0 or 1 / bit 7 is 0 = auto repeat pitch envelope, 1 = don't repeat pitch envelope

PI1 / -128 to 127 / change of pitch per step in section 1

PI2 / -128 to 127 / change at pitch per step in section 2

PI3 / -128 to 127 / change of pitch per step in section 3

PN1 / 0 to 255 / Number of steps in section l

PN2 / 0 to 255 / Number of steps in section 2

PN3 / 0 to 255 / Number of steps in section 3

AA / -127 to 127 / Change of amplitude per step during attack phase

AD / -127 to 127 / Change of amplitude per step during decay phase

AS / -127 to 0 / Change of amplitude per step during sustain phase

AR / -127 to 0 / Change of amplitude per step during release phase

ALA / 0 to 126 / Target level at end of attack phase

ALD / 0 to 126 / Target level at end of decay phase

Note that the pitch can take on a value between 0 and 255. If the pitch is greater than 255 (e.g, 257) then 256 will be repeatedly subtracted from it until it is in range.

The amplitude has a range of 0 to 127 in the ENVELOPE statement whereas it had a range of 0 to - 15 in the SOUND statement. The amplitude cannot be set outside the range 0 to 127.

Note also that the total duration of the attack, decay and sustain periods (but not the release period) is determined by the SOUND statement and not the ENVELOPE statement.

The ENVELOPE is divided up into a number of steps - usually of a hundredth of a second each and both the pitch and amplitude can be changed at the end of each step.

The pitch envelope

The pitch of the note can be changed in three sections. For each section you can specify the change in pitch at each tick of the clock (step) in the section. Suppose we wish to generate a wailing sound like a police siren. The pitch has to rise and fall like this

During section 1 the pitch changes +2 units per step and section l contains 10 steps. In section 2 the pitch changes - 2 units per step and there are 20 steps. Section 3 contains 10 steps of +2 units. So thus far the envelope command looks like

ENVELOPE 2,1,2,-2,2,10,20,10

The next six numbers control the amplitude of the sound and might well be 1, 0, 0, 1, 100, 100 (these will be explained in a moment).

So the total program to show the pitch envelope working would be

10 ENVELOPE 2,1,2,-2,2,10,20, 10,1,0,0,-1,100,100

20 SOUND 1,2,100,100

there is another pitch envelope - it plays 3 notes in succession.

10 ENVELOPE 3,25,16,12,8,1,1,


It reads:

Now to explain the amplitude envelope

The amplitude envelope

Suppose that we wish to imitate a car driving toward us getting louder all the time and then driving past before stopping nearby and then driving away. The amplitude of the sound against time might well look like this

The first phase of the amplitude envelope, where the sound is getting louder is called the "Attack phase".

The amplitude envelope is specified by giving six parameters. The first (AA) gives the change of amplitude at the end of each step during the attack phase and it must be a positive number. Usually the envelope starts with an amplitude of zero.

However it is possible to start with a non-zero amplitude if you have just interrupted a note on the same channel. The attack phase continues until the amplitude reaches the level given by the parameter ALA.

For reference the six parameters are defined again here.

Parameter / Range / Function

AA / -127 to 127 / Change of amplitude per step during attack phase

AD / -127 to 127 / Change of amplitude per step during decay phase

AS / -127 to 0 / Change of amplitude per step during sustain phase

AR / -127 to 0 / Change of amplitude per step during release phase

ALA / 0 to 126 / Target level at end of attack phase

ALD / 0 to 126 / Target level at end of decay phase

In our example the attack phase takes 4 seconds and each step lasts 1/4 second so there will be 16 steps. We want these 16 steps to get us from an amplitude of zero to an amplitude of at least 100 - if we make each step increase the amplitude by 7 we will get there in 16 steps. So parameter AA = 7.

During the decay phase the amplitude must drop from 100 to 60 in 2 seconds. During 2 seconds there are 8 steps. So the amplitude drops 40 units (100-60) in 8 steps - so each step must reduce the amplitude by 5 units. Thus AD = -5. So far we have determined the following parameters of the amplitude envelope.

AA = 7

AD = -5



In our case the amplitude does not change during the sustain period so we can set AS=0. The sound will go on until the sustain phase is ended. The total time allowed for the attack, decay and sustain phases is given by the duration part of the SOUND command. The release phase then starts.

Note that the length of the attack and decay phases is set by the values chosen for AA, AD, ALA and ALD but that the sustain phase can be terminated either by the amplitude reaching zero or the time set by the duration of the SOUND statement running out. The duration has to be set with care to ensure that it doesn't cut the note off at the wrong moment.

At the end of the sustain period the note enters the release phase where the note changes in amplitude at the rate set by AR until it reaches zero.

As you may have guessed there are numerous wave of getting things wrong so that a phase does not complete as expected. For example with ALA set to 100 and ALD set to 50 and a decay rate (AD) of zero the amplitude will not decay at all during the decay phase. However the sound will be moved to the release phase when the duration is reached.

The envelope statement is very complicated and there is a wide range of possible effects. You will have to use it quite a lot before you can accurately predict what effect you will produce.

Some sample 'envelopes' to try out

ENVELOPE 1,1,0,0,0,0,0,0,2,0,-10,-5,120,0

ENVELOPE 2,3,0,0,0,0,0,0,121,-10,-5,-2, 120,120

ENVELOPE 3,7,2,1,1,1,1,1,121,-10,-5,


ENVELOPE 4,1,0,0,0,0,0,0,61,0,- 10,-120,


ENVELOPE 1,8,1,-1,1,1,1,1,121,-10,-5,-2,


Note synchronization and other effects

The first parameter of the SOUND statement has been considered, up to now, to control only the channel number. It can in fact control a number of other features. For this purpose the channel number should be considered as a four digit hexadecimal number


Parameter / Range / Function

N / 0 to 3 / Channel number itself

F / 0 or 1 / Flush control

S / 0 to 3 / Synchronization control

H / 0 or 1 / Continuation control

N selects the channel number

F If F is zero the sound will be placed in the channel queue if a note is playing on that channel. If F = 1 then the channel queue will be flushed (emptied) so that the sound can be generated immediately.

S It is possible to synchronize two or more channels so that they do not start until all have received a note marked for synchronous production. The value of S determines how many other channels are to form the chord. Thus for a three note chord all three channels should be fed a note with S set to 2.

H This parameter allows the previous event on the channel to continue if it is set to 1. In this case the amplitude, pitch and duration parameters of the new sound command have no effect. Because the "dummy" note thus created is added to the queue in the normal way it can be used to ensure that the release phase of a sound is completed. Normally the release phase is truncated by the next note on the queue. If H=0 then the note is treated as a "real" note in the usual way.

Typical values of C are

C=&201 a note on channel 1 to be synchronized with 2 others.

C=&12 a note on channel 2 is to be played immediately regardless of what was in the channel 2 queue

A more succinct description of SOUND and ENVELOPE are given in the keyword section on pages 347 and 244.

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer

The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail:

Last updated: Monday 12th February 2001