Bottom     Previous     Contents

CHAPTER 13
The All-singing, All-dancing BBC Micro

The ideas and programs presented in this book have been developed using the BASIC language. Some musical applications are really only accessible through machine code and many of the programs could be developed beyond the bounds of BASIC by making use of the BBC micro's built-in assembler. It is hoped that, whatever your present level of computing ability, you will continue to experiment with the programs.
One such application which is best written in machine code is the production of music as a continuous background to whatever else the computer may be doing. The problem lies not in carrying out the normal sound and envelope functions but in supplying the sound chip with new note information. The system of interrupts described briefly in Appendix 1 will ensure that whatever information is stored in the sound queues will be carried out. The relative slowness of BASIC, however, sometimes leaves the sound generator waiting for a new note which causes a gap in the music production. You will notice such hiccups if you try to play a piece of music too fast, in some of the compositional programs for example. If we work at the same level as the interrupts it is easier to maintain control over information and pass on new note data.
Not to be outdone, however, we will see what we can do with BASIC.

Background music from BASIC

Background music is most evident in arcade-style games, which are usually written in machine code. With BASIC we can still achieve a certain degree of success in this area if we bear in mind two things which will set the limits on our music and our BASIC program. The optimum arrangement is for fairly long notes and fairly frequent access times between SOUND command updates. The balance between these will determine our success.
The overall limiting factor will depend upon the purpose of the BASIC program. If it is in the nature of an arcade game then the time taken by BASIC to update the SOUND command may slow down the game too much. In such cases, rather man pray something fast and furious you could try interweaving notes on the channels by laying one sound over another to create a texture as opposed to a tune.
If the program does not require constant use of all the computer's facilities, the solution should be easier. You could program the computer to play a tune while waiting for an input to a utility program, etc. In such a case, the computer would have nothing else to do and you would not be stealing time from another operation.
If you use the negative ADVAL method to feed SOUND commands (which should at least ensure that your main program never grinds to a halt) you must also ensure that the channels never run dry for lack of note information: otherwise they may run out of time or out of sync. This may not be so important if you use only one channel, and this would be easier to control, too.
We have already used the principles just described, albeit in a very small way, when we printed out the notes the computer was playing in the programs in Chapters 10 and 11.
The ideas should be familiar to you now and, rather than illustrate the principle with another similar program, we will take a look at a slightly different aspect of the same thing involving sound and animation synchronization.

Cartoons

Cartoons are the ultimate in sound and visual synchronization. Every single action is accompanied by an over-exaggerated sound effect or snippet of music.
Sophisticated computers are already being used in cartoon studios to help draw the pictures. They are used to draw a sequence of character movements, eg walking or running. An artist will draw the first and last frames and the computer will fill in the others. This process is known as 'inbetweening' because it fills the gaps in between two pictures.
The calculation of the shape as one picture turns into the other is ideally suited to a computer and such programs can be duplicated on the BBC micro, although we will not be able to achieve the precision, speed or quality of a dedicated computer. It is quite possible for a program to illustrate a building crumbling to the ground or a man's outline dissolving into a heap or to show a square turning into a triangle.
Fascinating though this subject is, we are now encroaching upon computer graphics, which is not within our domain. We will still dabble a little in their territory, however, as we explore the next topic.

Sound and animation synchronization

If we have an animated display of a man jumping around the screen on a pogo stick it is quite easy to make the computer produce a 'boing' whenever the pogo stick hits the ground. In the same way, it is easy to produce a bang when a gun is fired or a zap when a laser beam is fired. In these cases, the sounds are being synchronized to the animation. There are no problems because the animation is controlled from BASIC and does not run ahead as a series of SOUND commands will do,
If we try the opposite approach and attempt to synchronize a display (or anything else controlled directly from BASIC) with a series of SOUND commands, say a piece of music, then the music will tend to run ahead of the display. This is a result of the queues used by the sound generator.
However, operating solely from within BASIC, with a little care we can still achieve a fair degree of sound and animation synchronization. The principle behind this operation is to keep the sound queue as empty as possible so that each new command will be executed as soon as it is sent. In this way, as we send a SOUND command we can order a movement, so keeping the two close together. There are a few potential problems we need to be aware of which we will discuss later.
The following program illustrates how this can be done and is for insertion into Program 9.5. The additional fines are not very long and provide a good, if simple, demonstration of what is possible.

1 REM PROGRAM 14.1

2 REM Animated/Synchronised Dancer

3 REM Insert in PROGRAM 9.5/9.2

4

195 MODE 5

197 PROCFigures

198 VDU23,1,0;0;0;0;

634 x%=0:y%=10:m%=0:d%=0

640

650 Ch1=0:Ch2=0:Ch3=0

680 IF ADVAL(-6)>14 AND Ch1 +1:SOUNDChan1(1,Ch1)+1,Chan1(2,Ch1),Chan

1(3,Ch1),Chan1(4,Ch1)*Tempo:IF Ch1<82 OR

Ch1>97 PROCCartoon

690 IF ADVAL(-7)>14 AND Ch2 +1:SOUNDChan2(1,Ch2)+2,Chan2(2,Ch2),Chan

2(3,Ch2),Chan2(4,Ch2)*Tempo:IF Ch2>69 AN

D Ch2<92 PROCCartoon

725 VDU23,1,1,0;0;0;

2000 DEF PROCFigures

2010 VDU23,224,124,254,68,130,130,68,40

,100

2020 VDU23,225,16,56,40,16,56,84,146,56

2030 VDU23,227,40,40,40,40,40,0,0,0

2040 VDU23,228,146,16,56,124,254,40,40,

40

2050 VDU23,229,0,16,56,40,16,56,84,146

2060 M1$=" "+CHR$8+CHR$8+CHR$8+CHR$10

+" "+CHR$225+" "+CHR$8+CHR$8+CHR$8+CHR$1

0+" "+CHR$224+" "

2070 M2$=" "+CHR$229+CHR$8+CHR$8+CHR$10

+" "+CHR$228+" "+CHR$8+CHR$8+CHR$8+CHR$1

0+" "+CHR$227+" "

2080

2090 COLOUR 2

2100 ENDPROC

2110

2120

2130 DEF PROCCartoon

2140 m%=m% EOR 1

2150 IF m%=1 PRINTTAB(x%,y%)M2$ ELSE PR

INTTAB(x%,y%)M1$

2160 IF x%>17 d%=1

2170 IF x%<2 d%=0

2180 IF d%=0 x%=x%+1 ELSE x%=x%-1

2190 ENDPROC

Program notes

It is important that the animation be performed as quickly as possible, hence the use of short integer variables. In this short example, however, they are not essential.
PROCFigures at line 2000 designs two sets of figures which are stored in Ml$ and M2$. The putting together of figures containing more than one user-definable character is covered in the User Guide, Chapter 29.
PROCCartoon at line 2130 moves the figures around. The variables, x% and y%, are set at fine 634 and control the horizontal and vertical positions of the figure. m% is used to switch from Ml$ to M2$ using the EOR function at fine 2140. This has the same effect as writing:

IF m%=0 THEN m%=1 ELSE m%=0

EOR is one of a number of logical operators and is described in the User Guide on page 250.
d% is used to determine if the figure is to move left or right across the screen and is set by the value of x%, in lines 2160 and 2170. Line 2180 adjusts the horizontal position.
PROCCartoon is called from fines 680 and 690. These are similar to the original lines in Programs 9.5 and 9.2 but, instead of keeping the queues full, new notes are only sent when required - as near as we can gauge with BASIC. This done by checking the state of the buffers with the negative ADVAL function. You will notice that, as we have not altered fine 700, channel 3 will still be topped up whenever there is space in its buffer, but the three remain in sync. In other pieces of music it may be necessary to adjust the sync parameters or the conditional statements which allow other notes to be sent.
Conditional statements have been added at the end of fines 680 and 690 which call PROCCartoon when a new note is sent to the SOUND command. Chl and Ch2 are used to take control of the figure at different points in the music.
The result is interesting, quite amusing and capable of much further development. The next program goes a step further and produces a more sophisticated presentation which is built around an animated character.

Hercules

The principles behind the following program are the same as those behind the previous one. It uses the routines in Program 9.2 and is for insertion into that program. It introduces another piece of music - Bizet's March of the Toreadors - and a more complex set of animated characters.

10 REM PROGRAM 14.2

20 REM "Hercules"

30 REM Sound and Animation in Sync

40 REM Insert in PROGRAM 9.2

50

90 C1=53:C2=47:C3=35

250 ENVELOPE1,1,0,0,0,0,0,0,126,-4,-1,

-6,126,100

260 ENVELOPE2,2,0,0,1,4,0,1,126,-3,0,-

6,126,100

270 ENVELOPE3,3,0,8,-8,0,1,1,110,0,0,-

10,110,110

272 ENVELOPE4,4,0,0,1,1,0,1,126,-8,-8,

-16,126,100

274 ENVELOPE5,3,0,0,1,1,0,1,63,-8,-8,-

16,126,100

276 ENVELOPE6,6,0,0,0,0,0,0,126,0,0,-1

,126,126

278 ENVELOPE7,1,0,0,0,0,0,0,126,-10,-1

0,-10,126,0

330 IF Note$="R" Env=0 ELSE IF (N=35 O

R N=42) Env=3 ELSE IF N<19 Env=1 ELSE En

v=2

450 IF Note$="R" Env=0 ELSE Env=4

570 IF Note$="R" Env=0 ELSE Env=5

651 PROCMan

652 MODE 5

653 VDU23,1,0;0;0;0;

654 m%=0:x%=8:y%=12

655 COLOUR1

656 PRINT'"Ladies and Gentlemen"

657 PRINTTAB(5)"Presenting"

658 PRINT''TAB(6)"HERCULES"

659 SOUND0,6,4,40:SOUND1,0,0,180

660 SOUND&1000,0,0,80:FOR S=1 TO 4:SOU

ND0,7,4,4:NEXT S

661 COLOUR 2

662

670 REPEAT

680 IF ADVAL(-6)>14 AND Ch1 +1:PROCCartoon:SOUNDChan1(1,Ch1)+1,Chan1

(2,Ch1),Chan1(3,Ch1),Chan1(4,Ch1)*Tempo

690 IF ADVAL(-7)>14 AND Ch2 +1:SOUNDChan2(1,Ch2)+2,Chan2(2,Ch2),Chan

2(3,Ch2),Chan2(4,Ch2)*Tempo

700 IF ADVAL(-8)>14 AND Ch3 +1:SOUNDChan3(1,Ch3)+3,Chan3(2,Ch3),Chan

3(3,Ch3),Chan3(4,Ch3)*Tempo

710 UNTIL Ch1=C1 AND Ch2=C2 AND Ch3=C3

721 COLOUR1

722 PRINTTAB(10,y%+5)"Thank You"

723 PRINT'TAB(6)"...Signed HERC"

724 VDU23,1,1;0;0;0;

725 SOUND0,6,4,40

880 REM Channel 1

890 DATA &200,D3,8,E3,6,D3,2,B2,8,B2,8

900 DATA &200,B2,6,A2,2,B2,6,C3,2,B2,1

6

910 DATA &200,C3,8,A2,6,D3,2,B2,16

920 DATA &200,G2,8,E2,6,A2,2,D2,16

930 DATA &200,A2,20,E3,4,D3,4,C3,4

940 DATA &200,B2,4,A2,4,B2,4,C3,4,B2,1

6

950 DATA &200,F#2,8,B2,8,B2,8,A#2,6,C#

3,2

960 DATA &200,F#3,32

970 DATA &200,R,4,E3,4,D#3,4,E3,4,A2,4

,B2,4,C3,8

980 DATA &200,R,4,B2,4,G2,4,E3,4,D3,16

990 DATA &200,R,4,G2,4,D2,4,C3,4,B2,8,

A2,8

1000 DATA &200,G2,16,R,16

1010 REM Channel 2

1020 DATA &200,G1,8,D1,8,G1,8,D1,8

1030 DATA &200,G1,8,D1,8,G1,8,D1,8

1040 DATA &200,A1,8,F#1,8,G1,8,F#1,8

1050 DATA &200,E1,8,C#1,8,D1,8,F#1,8

1060 DATA &200,A1,8,C2,8,A1,8,C2,8

1070 DATA &200,G1,8,B1,8,E1,8,B1,8

1080 DATA &200,F#1,8,B1,8,F#1,8,A#1,8

1090 DATA &200,B1,8,F#1,8,D#1,8,B0,8

1100 DATA &200,C1,8,A1,8,E1,8,A1,8

1110 DATA &200,D1,8,G1,8,R,4,B1,4,G1,4,

E2,4

1120 DATA &200,D2,8,R,16,F#1,8

1130 DATA &200,G1,16,R,16

1140 REM Channel 3

1150 DATA &200,B1,8,R,8,B1,8,R,8

1160 DATA &200,B1,8,R,8,B1,8,R,8

1170 DATA &200,R,32

1180 DATA &200,R,32

1190 DATA &200,R,8,E2,8,R,8,E2,8

1200 DATA &200,R,8,E2,8,R,8,E2,8

1210 DATA &200,D2,8,R,8,C#2,8,R,8

1220 DATA &200,D#2,8,R,24

1230 DATA &200,R,8,C2,8,R,8,C2,8

1240 DATA &200,R,8,B1,8,R,16

1250 DATA &200,R,24,D1,8

1260 DATA &200,B1,16,R,16

1270

1280 DEF PROCMan

1290 VDU23,234,128,128,128,128,128,128,

128,255

1300 VDU23,235,0,6,8,16,32,76,158,255

1310 VDU23,236,24,60,90,255,90,36,24,25

5

1320 VDU23,237,7,1,1,1,1,1,1,255

1330 VDU23,238,0,96,16,8,4,50,121,255

1340 VDU23,241,255,126,60,24,24,24,24,1

26

1350 VDU23,242,24,24,24,24,24,24,24,126

1360 VDU23,246,126,36,38,38,100,100,36,

231

1370 VDU23,247,126,36,100,100,38,38,36,

231

1380 Man1$=CHR$234+CHR$236+CHR$237+CHR$

8+CHR$8+CHR$10+CHR$241+CHR$8+CHR$10+CHR$

246

1390 Man2$=CHR$234+CHR$236+CHR$238+CHR$

8+CHR$8+CHR$10+CHR$241+CHR$8+CHR$10+CHR$

247

1400 Man3$=CHR$234+CHR$236+CHR$238+CHR$

8+CHR$8+CHR$10+CHR$242+CHR$8+CHR$10+CHR$

247

1410 Man4$=CHR$234+CHR$236+CHR$237+CHR$

8+CHR$8+CHR$10+CHR$241+CHR$8+CHR$10+CHR$

247

1420 Man5$=CHR$234+CHR$236+CHR$237+CHR$

8+CHR$8+CHR$10+CHR$242+CHR$8+CHR$10+CHR$

246

1430 ENDPROC

1440

1450 DEF PROCCartoon

1460 m%=m% EOR 1

1470 PRINTTAB(x%,y%);

1480 IF Ch1=1 PRINTMan4$:ENDPROC

1490 IF Ch1=C1 Wait=INKEY(60):PRINTMan4

$:ENDPROC

1500 IF Ch1<19 AND m%=0 PRINTMan1$:ENDP

ROC ELSE IF Ch1<19 AND m%=1 PRINTMan2$:E

NDPROC

1510 IF Ch1<35 AND m%=0 PRINTMan4$:ENDP

ROC ELSE IF Ch1<35 AND m%=1 PRINTMan5$:E

NDPROC

1520 IF m%=0 PRINTMan1$ ELSE IF m%=1 PR

INTMan3$

1530 ENDPROC

Program notes

The salient points of the program were covered during examination of Programs 9.2 and 14.1, but we will have a closer look at some of its more important routines.
PROCMan at line 1280 constructs nine user-definable characters which are put together to form five different figures.
After the tune has been assembled into its arrays, fine 659 produces a round of applause. The second statement on this line ties up channel 1 until the applause is over to prevent the program running straight into the tune. It is interesting to realise that as the applause is sounding, channels 2 and 3 will already be waiting for channel I to empty so they can all synchronize and play.
The first statement in fine 660 incorporates a Hold parameter to let the applause die away slowly. The following statements produce the sound of the orchestra conductor rapping his baton on the podium four times.
The animation orders are taken only from' channel 1 and PROCCartoon does all the calculations regarding which figure to print. We will look at it in more detail.
PROCCartoon basically switches between two figures and the switches are activated by line 1460 as they were in Program 14.1. The switching occurs between three sets of two figures, and the remaining fines of the procedure are used to determine which set of figures to use.
Line 1470 sets the print position for the figures. Lines 1480 and 1490 print a stationary figure at the very start and end of the program.
As the program moves through the procedure, line 1500 picks up the first few bars and prints Man1$ and Man2$. When Ch1 reaches 19, line 1510 takes over and prints Man4$ and Man5$. When Ch1 reaches 35, control passes through to line 1520 which prints Man1$ and Man3$.
And so, at line 1490, when Ch1 is equal to C1, the last figure is printed and control reaches line 725 which ends the program with another tumultuous round of applause.

Further experiments in animation

Although we must be careful not to over-extend the capacity of BASIC to (apparently) control more than one sequence of events at a time, these programs have by no means overtaxed its abilities. BBC BASIC is very fast and you could expand these ideas into more complex and complicated graphic routines - bearing in mind the restrictions of the system.
It should be possible, for example, to print more than one Hercules on the screen during PROCCartoon. Alternatively, you could design a larger figure or a multi-coloured figure made up from different coloured user-definable characters superimposed on each other. The latter is only possible in a graphics mode and would require some modifications to the printing procedure, but the overall effect would be suitably impressive.

Computer art

Other than direct animation, you could generate a pattern triggered at suitable points by the music. This could include starbursts, radiating lines, colour changes (use VDU 19), the printing of various geometrical shapes or pre-defined characters. If a programmed piece of music was playing - as opposed to a computer-generated piece - to avoid repetition the graphic designs could be selected at random. If we were running a composition program, the combination of computer music and computer-generated art would prove a very interesting spectacle. To begin with, you could add a screen display to many of the programs in this book.

Tomorrow's BBC micro

As you know, the BBC micro was designed to be capable of expansion. Aiready the use of disk drives, plug-in EPROMs and the interface capabilities of the user port and 1MHz bus give us a potentially very powerful machine. When the Tube£ and second processor are in common use, its power will increase enormously.
Not only from a computing but from a musical point of view, technology can make so many more things possible. If manufacturers take advantage of the BBC micro's expansion facilities, we can expect to see plug-in piano type keyboards and add-on synthesizer voice modules. Sound sampling devices will be able to listen to a sound and let the user play it back at any pitch - a facility at present only available on synthesisers costing several thousands of pounds.
The ever-increasing speed and versatility of the microcomputer will secure it a place in all areas of music from sound generation and production to recording and playback. Many recording studios already rely upon computers and the trend is likely to continue. There is no reason why one day a BBC micro should not be performing similar functions.
In this world of rapidly developing technology, after tomorrow - who knows?


Next     Top