5. The Speech buffer - using CLEAR

It was explained earlier that speech data is stored near the top of memory until it is ready to be outputted.

The speech buffer is a "First In - First Out" buffer (a FIFO buffer) which is initialised when you turn on the Spectrum with the MicroSpeech attached. In order to do this, the unit moves the "top of BASIC RAM" pointer (RAMTOP) down by 256 bytes (so that on a 48K machine it will point to 65111) and the speech buffer is then established between the new RAMTOP and the user-defined graphics area. The buffer then fills from top (i.e. highest memory location) downwards as more speech is added to it. The top 6 bytes of the buffer (the "header") contain information on buffer and system status but the ones below it are free for speech data. You may make the buffer as large or as small as you want by use of the clear command.

For instance, on a 48K machine, CLEAR 65000 makes RAMTOP point to 65000, and the memory space free for the speech buffer will be increased by 111 bytes.

To safeguard against the buffer header being corrupted by a CLEAR command, the MicroSpeech unit monitors RAMTOP, and if a CLEAR is attempted into an illegal area (see below), the unit goes through its initialisation sequence again.

You BASIC program is not lost when this happens (unless it was so large that the new RAMTOP established by the unit truncated it), but you will find a new copyright message issued and RAMTOP once again established 256 bytes below the original RAMTOP.

If you try to add speech to the buffer and there is insufficient room for it to be fitted in, then the unit will ignore the speech string s$ until there is sufficient room in the buffer. If you PRINT s$ under these conditions you will find it returned uncorrupted, i.e. without an asterisk or a query, to show that it has not been accepted into the buffer. If you find this occuring in a program, simply use CLEAR as described above to make the buffer a little larger, or alternatively use a PAUSE to allow the buffer to empty a little before attempting to add another string to it.

Since the keyvoices are outputted via a speech buffer, you can observe a similar effect if you enable the keyvoices when the buffer is very small. For instance, if you make the buffer only four bytes long, then any keyvoice longer than four allophones will not be voiced.

Summarising:

On a 18K machine, do not CLEAR greater than 32343

On a 48K machine, do not CLEAR greater than 65360