Tutorial Details:
Difficulty Level:
Basic
Topics Covered: Playing
sounds using NQC.
Assumed Knowledge:
THe Basics, My
first program
Written By: BILL LANE
BACK
Spybot's are capable of an incredible range of sounds. They
have 64 pre-programmed sounds that can be called by number
and room for an additional 16 user defined sounds (maximum
size 63 bytes each). We won't be looking at defining our own
sounds today. Instead we'll just look at making sounds and
using those 64 pre-programmed sounds.
Let's start with the pre-programmed sounds. If you take a
look in globals.h (it's in Spybot/include) you'll find that
someone has gone to the trouble to provide names for each
of the 64 sound sequences. For this example we can use the
names as a guide use the numbers to make the sounds. So here's
an example program:
task main()
{
PlaySound(41);
Wait(540);
}
This will play sndDizzy. Note the use of wait so we can actually
hear the sound before the program closes down. To play any
of the available sound sequences just replace 42 with the
relevant number download and enjoy. To stop the current sound
you can use MuteSound().
Too easy really and I imagine you could create programs for
the next 10 years without even thinking about making your
own sequences. But you can create and play your own sequences
using PlayTone. All you
need to use PlayTone is to supply a frequency and a duration
(in that order). Here's how:
PlayTone(440, 50);
wait (50);
Repeat these two lines with variations in frequency and duration
and you and your Spybot can make beautiful music together.
The documentation provides the following chart to assist would
be composers.
|