SOUND
YS MegaBasic provides two new ways in which you can produce sound on
your Spectrum - the 'PLAY_' command and the interrupt sound generator
(ISG). 'PLAY_' takes the form:
PLAY_n,l,s,d,f
Where: 'n' produces pure notes (n=0) or white noise (n=1); 'l' is the length of
each step; 's' is the start frequency; 'd' is the number of steps; and 'f' is the
change of frequency after each step. Variables 'd' and 'f' may be repeated more
than once if required.
INTERRUPT SOUND GENERATOR
Whereas 'PLAY_' is only a glorified BEEP command, YS MegaBasic provides
a new feature, allowing sound to be produced while a program is still running.
This is made possible by the interrupt sound generator (ISG). Fifty times a
second the normal program flow of the Spectrum is interrupted and a jump is
made to a small machine code routine that scans the keyboard. On the
MegaSpectrum, as well as scanning the keyboard, the machine code routine has
been customised to produce sounds. YS MegaBasic provides a number of
commands to handle the ISG and the sound buffer, and these are as follows:
SOFF | Disables the ISG - any sound being made ceases
immediately. |
SON | Enables the ISG, so that it will resume whatever it was
doing before being disabled. |
SREP_n | Requires a single numeric expression (n). If the result
of the expression is zero, then the data stored in the
sound buffer will only be played once - it the result is
one, the sound buffer's contents will be repeated forever. |
SOUND_ | While quite complex, this is the main command used to
manipulate the sound buffer. It takes the form:
SOUND_n,a,b,c,d
Where: 'n' clears the sound buffer before replacing it
with something new (n=0) or adds sound on to the end
of the sound buffer (n=1); 'a' plays a pure sound (a=0)
or white noise (a=1); 'b' is the value to be added to the
frequency after each step; 'c' is the number of steps in
sequence; and 'd' is the number of times the sequence
is to be repeated. |
|