BBC Micro Music Masterclass

1 The SOUND Statement

As I mentioned in the Introduction, the basic command used for producing any form of noise on the BBC is the SOUND command. In this chapter we will deal with the use of SOUND to produce music and, for simplicity's sake, we will temporarily ignore the fact that SOUND can also produce white noise and chords, and concentrate solely on the monophonic (one note at a time) case.

The format of the SOUND statement is:



C is the channel number.
A is the amplitude (volume) of the note.
P is the pitch (frequency) of the note.
D is the duration (length) of the note.

The channel number c can take values from zero to three, but for the purposes of this chapter it will always be set to one. Channel one produces a square wave tone which can be heard by typing CTRL-G and holding both keys depressed.

The amplitude parameter A can take values between -15 and 15 but, again for the purposes of this chapter, we need only concentrate on the range zero to -15, which produces a range from silent to loud.

P can take values from zero to 255 and each single value is equivalent to 1/8th of a tone in musical terminology. A semitone (the basic musical building block) would therefore equal an increment of four.

The final parameter, D, can take any value between 0 and 255. In this case each increment is equal to 1/20th of a second, so a value of 20 for D would give a note length of one second.

These cold facts do not provide us with an accurate reflection of the vast possibilities inherent in the SOUND command. To see where we could use this command we must first explore the individual parameters and relate them in some way to everyday musical experience. Let us begin by looking at the effect of volume by trying the following short routine:

20 FOR A=1 TO 15
30 SOUND 1, -A,53, 20

None of these volumes are exactly ear-splitting, but it is the range of dynamics available, rather than mere volume, that is important for most musical applications. We will, however, be looking at the potential for squeezing more decibels out of the sound chip in a later chapter.

The range of frequencies available can be heard by RUNning the following:

10 REM *** PITCH DEMO ***
20 FOR P=0 TO 255
30 SOUND 1,-10,P,3

At this juncture you might think that, as music goes, this program is not exhilaratingly exciting, so bear in mind that its function is to illustrate the range of P! The value of P is obviously one of the more important parameters for musical applications. Whoever designed the BBC Micro obviously knew this, because we can take the above program and simply change Line 20 to read:

20 FOR P= 0 TO 255 STEP 4

We can now hear intervals that are more familiar to most of us: these are known as semitones. Moving on, and using RND(100)*4 to specify pitch, we can now persuade the BBC to compose rather erratic melodies:

 20 REM *** RANDOM ***
 60 P=RND (100)*4
 90 SOUND 1, -10, P, 5
100 UNTIL P=999

Before we become totally involved in trying out and defining values for pitch, try RUNning the following routine which will give you an idea of duration:

 10 REM    *** DURATION DEMO ***
 20 FOR D=1 TO 100
 30 SOUND 1,-10,73,D
 40 SOUND 1,0,0,D
 50 NEXT D

Line 40 has been inserted to provide a period of silence between sounds. This is of equal duration to the sounds themselves. It should be noted at this point that setting the duration D equal to 255 will result in a note without end - presumably a device only of interest to admirers of John Cage!

The pitch parameter

Let us now return to pitch and relate values of P to musical notes by looking at the table below.

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

The first column contains the notes listed as musical symbols. (Refer to Chapter Five for any problems you may have with musical terminology or notation.) The equivalent P values are listed in columns according to octave. These P values are simply an arbitrary choice made by the BBC’s programmer and therefore have no direct significance in themselves. Middle C has a value of 53 in this table and its actual measured frequency is 261.625Hz (cycles per second).

Another point to note before we go much further is the accuracy of P. Up to values of one hundred, P is basically equivalent to text book frequencies. Beyond this, however, the pitch has a tendency to drift, a vagary shared with most normal musical instruments. For most practical purposes this will not be a problem, so from now on let us give the tone generator the benefit of the doubt and treat it as if it has perfect pitch.


One of the fundamental building blocks of music is the scale. Many of you will either remember, or still be experiencing, singing Doh, Re, Mes ad infinitum at school or in an organised music class - which is simply the traditional and rather crude method of instilling the Western harmonic scales into the brains of budding but reluctant Andre Previns. Using a computer is a much less painful method of learning scales and how they relate to Wham or the Eurythmics. (In this chapter we are dealing with how music in the real world relates to SOUND as it is played by the BBC, so it will be necessary for me to assume a certain knowledge of music theory. If any of the concepts or terminology are unfamiliar to you I strongly advise reading Chapter Five, Music Theory for Micros, before proceeding any further.)

The first scale we will look at is the scale of C major:

 10 REM
 20 REM    *** Scale at C Major ***
 30 REM
 40 FOR N=1 TO 4
 60 READ A
 70 SOUND 1, – 10, A, 10
 80 UNTIL A= 101
100 NEXT
110 DATA 53,61,69,73,81,89,97, 101

This program uses a DATA statement to store the actual P values required for the scale. This method of remembering a sequence of notes will come in very handy when we want to program tunes at a later stage. Another method of playing the same scale is shown in the following program:

 10 REM
 20 REM	*** SCALE-2 ***
 30 REM
 40 P=53
 60 SOUND 1, -10, P, 10
 70 READ increase
 80 P=P+increase
 90 UNTIL increase=0
100 DATA 8,8,4,8,8,8,4,0

In this example the DATA statement holds the increase in pitch. Using this method, you can change the key of the scale by the single expedient of changing P in Line 40. Thus for example:

If P =61 the scale would be D Major.
If P=77 the scale would be F# Major.

Let us now see this in practise and create a program which simulates violin practise in action:

 20 REM	*** Violin Practise ***
 40 FOR p=53 TO 101 STEP 4
 50 Pitch=P
 70	SOUND 1, -10, Pitch, 10
 80 READ increase
 90	Pitch=Pitch+increase
100 UNTIL increase=0
110	RESTORE 130
l20 NEXT P
130 DATA 8,8,4,8,8,8,4,0

This program has a major advantage over real violin practise in that the computer never makes a mistake. Anyone who has ever been subjected to listening to an inexperienced violinist will greatly appreciate this advantage.

In practise, you will discover that the scale program which uses actual pitch values is the universally used method, for the simple reason that, in practise, working out the increase or decrease in value for melodies more complex than steadily increasing scales becomes mind-bogglingly complex. Ease of use is a crucial criterion in all music programs since, ultimately, all the methods suggested in this book have been singled out to be used for creative ends. Bear in mind that spontanteity is essential to composition, so we should also aim to program with this in mind as far as practicably possible.

The DATA used in the scale of C Major could easily be used to convert the computer into a simple musical keyboard. The following program allows you to play the notes of the C Major scale using keys 1 to 8.

 20  REM    *** KEYBOARD ***
 40 DATA 53,61,69,73,81,89,97,101
 50 DIM P(8)
 60 FOR N=1 TO 8
 70   READ P(N)
 80   NEXT N
 90 P$=INKEY$(0)
100  IF P$="" THEN GOTO 90
110 SOUND 1,-15,P(VAL(P$)),2
120 GOTO 90

The DATA is first READ into the array P(s). The keyboard is then scanned for a key press using the INKEY$ statement in Line 90. Since the bracketed number is zero, the computer does not wait at Line 90 but immediately returns to Line 100, which in turn sends the computer back to 90 if no key has been pressed. If a key press is detected the program jumps to Line 110 and a note that is equivalent to the value of the number pressed is played. For example; If 1 is pressed then P(1)=53, therefore C is SOUNDed, and if 5 is pressed then P(5)=81, therefore G is SOUNDed.
This program could be extended to produce the full chromatic scale demonstrated earlier:

 20 REM   *** Chromatic Keyboard ***
 50 *FX11,1
 60 *FX12,1
 70 POTE$=GET$
 90 P=INSTR(K$,POTE$)*4+37
100 SOUND 1,-10,P,-1
120 note$=INKEY$(2)
130 UNTIL note$<>POTE$
140 SOUND &11,0,0,0
150 IF note$="" THEN POTE$=GET$ ELSE POTE$=note$
160 UNTIL POTE$=" "
170 *FX12,0
180 END

This program uses the array K$ to store its key names. Line 90 then returns a value for P (pitch) by using the INSTR command to obtain the position of POTE$ in K$. This is then returned as a number from 1 to 16 (sixteen is the number of elements in K$). P is then derived by multiplying by 4, and adding 37. Thus if C is pressed POTE$=C, the INSTR expression will return 4 (i.e. 4th in the array), and P will have the value of (4*4)+37=53 (Middle C).

The *FX commands are used to speed up the auto repeat. *FX 11,1 sets the delay before repeats start to 1/100 of a second. *FX 12,1 sets the repeat period to 1/100th of a second as well. Note that the space bar must be pressed to END the program. If you ESCAPE from the program before Line 170 the new auto repeat values will stay in operation. This will make it very difficult to type any further program information. In Line 170 the statement *FX12,0 resets both the auto repeat and the auto repeat delay values to normal.

The chromatic scale program serves to illustrate the point that a typewriter keyboard is not the easiest musical device to play. Segovia is unlikely to ever trade in his guitar for a BBC and a copy of the above program! This is not to deny the fact that the computer does have a useful role to play in creating music. This is due to the computer’s unique memory and its capacity to repeat series of events accurately and consis-tently without feeling the human emotion of boredom or exhibiting human fallibility. One obvious use for this talent is in controlling a sequencer.

The sequencer is a fairly recently developed phenomenon which was originally created for controlling analogue synthesisers. The first sequencers were clumsy modular machines. Each module was set to generate a particular voltage and each voltage was triggered in sequence using a low frequency oscillator (LFO). These voltages were then fed into the synthesiser, which played notes related to the voltages at a speed controlled by the LFO.

Any system which consists of a number of identical modules which work in sequence is obviously very inefficient. It soon struck the designers that there should be some way of remembering the list of voltages so that only one voltage generator would be required. After a period of tinkering and experimentation computer controlled sequencers were born. The logical extension of solely storing note values is to remember timings as well. Once both pitch and note length are recorded the sequencer becomes a very flexible musical tool.

At present sequencers are enjoying great popularity amongst musicians of all persuasions. Depeche Mode, the Human League and Yazoo, to name but a few of the better known bands committed to sequences, would be completely helpless in the studio without the assistance of such machines as the Roland MC-4 Microcomposer and the Fairlight CMI.

The above mentioned machines are not musical instruments in the standard sense of the word, but are in fact complete music compositional system. (For a fuller description of modern electronic instruments see Chapter Ten.) Both are basically computers that have been programmed to control external synthesisers (in the case of the MC-4) or control and generate sampled sounds (in case of the Fairlight CMI). At present, then, these instruments represent the state of the art of professional machines. Although it is beyond the scope of this book to break down and dissect their wide-ranging facilities, we will go a long way towards indicating both how this type of system works and the type of software that makes it tick. The following program serves to illustrate the basic workings of a simple sequencer:

  5 REM
  6 REM      *** SEQUENCE ***
  7 REM
 10 MODE6: VDU 19,0,4,0,0,0
 20 DIM 
 30 CLS
 35 REM     Enter Pitch" A(N)
 36 REM
 40 FOR N=1 TO 8
 50 INPUT "Enter Pitch" A(N)
 60 SOUND 1,-10,A(N), 10
 70 NEXT
 75 REM      Play Sequence
 76 REM
 60 FOR N=1 TO 8
 90 SOUND 1,-10,A(N),10
100 NEXT N

The program first sets up the array A(8) to hold the pitch information. An INPUT statement then asks for pitches to be entered. When all eight pitches have been entered the sequence plays four times then stops.

"Sequence" has a number of obvious limitations. Pitches must be entered as P values (i.e. adding four for every semitone) so the note/pitch table has to be referred to constantly. In addition, exactly eight notes must be entered and no variation in the tempo or the number of times the sequence is played is possible.

These drawbacks make "Sequence" less than a powerful musical tool, but don’t lose heart or believe I’ve led you up a blind alley. By constantly refining this program as we learn more about the SOUND statement, we will eventually end up with a considerably more flexible program.

Before going any further with the sequencer program let us take a further look at DATA statements as a way of storing musical information. The following examples take the ideas explored in the scale programs and apply them to that well known Scandinavian melody ‘Hall of the Mountain King’.

 10 REM
 20 REM *** HALL ***
 30 REM
 50 READ P
 70 SOUND 1,-10,P,5
100 DATA 61,69,73,81,89,73,89,89,85,69,

“Hall” uses the form of our first scale program but also incorporates a small amount of rhythmical variation by repeating DATA to produce a longer note. Using this method, one DATA entry must equal the shortest note in the place. In this case one entry equals a quaver (1/8 note). The following diagram shows how the numbers in the DATA statement relate to conventional musical notation:


As you will note from the above, this second version is arrived at by recording the note differences. “Hall-2” not only repeats itself after each completed sequence but also changes key by one semitone.

 10 REM
 20 REM     *** HALL-2 ***
 30 REM
 40 P=61
 60 count=1
 70 P=P+4
 80 RESTORE 170
 90 pitch=P
110 READ increase
120 count =count+1
130 pitch=pitch+increase
140 SOUND 1,-10,pitch,5
150 UNTIL count=32
170 DATA 0,8,4,8,8,-16, 16,0,-4,-16,16,
0,-4,-16, 16,0,-20,8,4,8,8,-16,16,20,-8, -12, -16, 16,12,0,0,0,1

The value of P, in Line 40, gives the starting note which, in this case, is D. Two REPEAT... UNTIL loops are used to cycle the program. On completion of each cycle a semitone increment of four is added to P (Line 70) which results in a semitone shift. This program still uses multiple entry of P values to give rhythmical variation. There are more satisfactory ways of achieving this, one of which would be to record values for the duration parameter D as separate items of DATA.

The duration parameter

It is obviously time to say that, in many forms of music, rhythm is as important a factor to consider as pitch. The duration parameter D is the key to providing our control of rhythm on the BBC. In reality, D actually dictates two separate musical quantities, tempo and timing.

The tempo of a piece of music is defined as its speed in beats per minute. The length of one crotchet is equal to the length of one beat, so for a tempo of 120bpm we would hear 120 crotchets go by. Since o is given in 1/20ths of a second the value for D for a crotchet at 120bpm would be given by:

120bpm=120/60 beats per second=2 bps.

As calculated earlier, D=20 gives a duration of 1 second, and therefore the value of D for one beat would equal 20/2=10. The general formula is D=20/Tempo/60, or D=1200/Tempo where Tempo is given in beats per minute.

At this juncture let me introduce a program called “Metronome”, an electronic metronome program with a difference. Instead of entering values for the tempo in beats per minute, you are asked to supply a value for D. Once the metronome is running the tempo can be changed using the up- and down- cursor keys. This program illustrates the important point that, since only integer values of D can be entered and a value of 1 for D = 1/20th of a second at fast tempos, only certain values for TEMPO are available.

This point can be further illustrated by looking at an example. If TEMPO is 120 the value of D is 10 (1200/120), whereas if TEMPO were 110, then D=1200/110=10.9 which is not an integer value and would be interpreted by the SOUND statement as 10, rounding down.

 10 MODE7
 20 VDU23;8202;0;0;0;
 30 PRINT TAB(5,4);CHR$(129);CHR$(141);"* * * ";CHR$(132);"METRONOME";CHR$(129); "* * * "
 40 PRINT TAB(5,5);CHR$(129);CHR$(141);"* * * ";CHR$(132);"METRONOME";CHR$(129); "* * * "
 50 PRINT TAB(7,13);CHR$(131);"TEMPO"; TAB(23,13);"Duration"
 60 PRINT T4B(2,20);CHR$(134);"Press cursor up to increase TEMPO"
 70 PRINT TAB(2,21);CHR$(134);"Press cursor down to decrease TEMPO"
 80 PRINT TAB(2,22);CHR$(134);"Press cursor left to restart"
 90 PRINT TAB(2,23);CHR$(134);"Press cursor right to END"
100 *FX4,1
110 ENVELOPE 1,1,0,0,0,0,0,0,126,-6,0,-4,120,0
140 correct=D>0 AND D<255
150 IF NOT correct THEN PRINT TAB(25,8 );"?? try again"
160 UNTIL correct
170 PRINT TAB(8,8)"                    
190 TEMPO=INT(1200/D)
200 PRINTTAB(9,15);TEMPO;"
";D;"   "
210 SOUND 1,1,100,D
220 K=INKEY(0)

“Amazing Grace” is in 3/4 time, that is to say three beats to the bar. A value of D equal to 12 for a one crotchet duration was chosen both because it seemed a reasonable tempo and also because this number is easily divided by three. As a result, the crotchet triplets in the first bar have D values of 4.


At this juncture we could also incorporate variable durations into our sequencer program:

“Ambulance” is an effect program which has been devised to simulate an ambulance passing. Not only does it include a volume change which alters by one during each step of the loops, this program also simulates a Doppler frequency shift effect by changing pitch. As the ambulance approaches the siren both increase in volume and rises in pitch. Realistically enough, the sequence occurs in reverse when the vehicle ‘passes by’.

So far we have dealt with amplitudes in the range 0 to -15. Positive values for A call up ENVELOPES, which we will look at in detail in the following chapter. Fifteen such ENVELOPES are available to give the sound a rather more interesting ‘shape’ than the on-off tones we have used up to this point.

During the course of this chapter we have dealt with the major uses of the SOUND statement in isolation. The SOUND statement generates Pitch, Duration and Amplitude. In combination, these parameters provide most of the INPUT required to create music and produce certain types of sound effects.

People of refined sensibilities might well be disappointed that the actual sound produced by SOUND appears to be a rather flat, square wave note. Do not despair, for this note can be made to sound much more interesting by utilising the second of the BBC’s Sound of Music commands: ENVELOPE! Undaunted, then, let us proceed to the next chapter...