The sound chip in the BBC micro is the Texas SN76489, which is similar in specification and performance to those in many other micros. This might lead one to expect similar abilities, but the BBC micro's sound system is more powerful than other micros by virtue of the software it uses to drive the chip.
The OS (Operating System) is a machine code program roughly 16K in size which is resident in ROM inside the computer. Its overall purpose is to aid the running of high level languages such as BASIC and to provide a kind of buffer between the user and the rather unfriendly world of the CPU (Central Processing Unit). It looks after a host of jobs and, among other things, it provides software to handle the sound generator. It makes extensive use of interrupts to improve the general performance of the machine and also, of special interest to us, the sound chip.
Normally, a computer can only perform one action at a time. It could not, for example, calculate 2+2 at the same time as it was calculating 3+3. If these problems were programmed into a computer, the answers would appear instantaneously, but the computer would have worked its way through the program, one item of information at a time. So, theoretically, it could not make an explosive sound at the same time as it showered pieces of bomb around the screen. In practice, we know it can do exactly that and the reason lies in the OS. By using interrupts and a system of queues, the BBC micro can execute a sound command and apparently do something else at the same time.
It is not necessary to know exactly what's happening to make use of the system, but you may find the information useful at a later date during development of one of your programs.
An interrupt is a means of switching the attention of the CPU from one task to another and back again. For example, the pseudo-variable, TIME, is updated every 1/100th of a second by an interrupt from the VIA (Versatile Interface Adaptor). Whatever task the computer is about, it stops to increment the value of TIME and then continues from where it left off.
Pressing a key on the keyboard causes an interrupt to be sent to a keyboard service routine in the OS. This happens even when a program is running. The routine stores the ASCII value of the key in the keyboard buffer and then goes back to whatever task was in hand before it was interrupted.
Run the following and press some keys while it is running:
10 FOR X=1 TO 10000
20 NEXT X
When the delay loop has finished, you will see the characters you typed appear on the screen. Now type and run this:
10 SOUND1,-15,53,254
If you press some keys while this is sounding, they will immediately appear on the screen. This is because the sound chip is controlled by interrupts. Whenever the computer meets a SOUND command an interrupt directs the system to produce the required sound and immediately reverts back to its previous task. In this case it had nothing to do other than revert to command mode and you will notice the cursor prompt appear on the screen as soon as you hit RETURN.
The sound chip itself has no means of controlling the duration of a note and it will continue to sound until a software command turns it off. The computer uses the timer interrupt to check on the duration of a note. If the tone has sounded for its allotted span, it is switched off.
The ENVELOPE command relies on interrupts, too. The first parameter in the ENVELOPE command, after the envelope number, is a 'step' value. The other parameters are described as a number of changes in pitch or amplitude during each step. The step value is specified in multiples of 1/100ths of a second, which ties in very nicely with the timer interrupt. When the TIME variable is incremented, the computer checks to see if any of the envelope parameters need adjusting: if they do, the sound chip is updated with the new values.
Normally, we will not deal directly with the BBC micro's system of interrupts - this is more the domain of the assembly language programmer and needs to be handled with care - but the beauty of the BBC micro's sound system is that we have access to all the necessary functions through the BASIC language. In fact, all sounds and effects are created with only two commands - SOUND and ENVELOPE.