home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USERAU90.MSA
/
TEXT_SAMPLE.DOC
< prev
next >
Wrap
Text File
|
1990-06-24
|
3KB
|
71 lines
SOUNDING OUT
Roland Waddilove shows how to add
sampled sound effects to your programs
------------------------------------------------------------------------------
SAMPLED sound effects make a tremendous difference to programs, particularly
games where they are already extensively used. RunTime is an invaluable source
of these superb sounds and over the coming months you'll find several on each
Cover Disk. There are two this month and there will be more next month so
you'll soon build up a library of exciting effects.
------------------------------------------------------------------------------
To replay the samples you need a suitable utility - which you'll also find on
this month's Cover Disk. In fact, there are two versions: a Fast BASIC and
HiSoft BASIC listing. To replay the samples you'll need to boot up HiSoft BASIC
and load SAMPLE.BAS or Fast BASIC and load SAMPLE.BSC.
Run the program (either version) and use the file selector to choose the
sampled sound you want to play, click on the speed from the options in the
Alert box and turn up the volume on your monitor to hear the effects. The
samples were recorded at 10kHz so sound best when replayed at this speed.
The source code is supplied on the disk so you can load it, modify it and
then insert the relevent sound replay section in your own programs. (If you
haven't got either HiSoft or Fast BASIC then you can still replay samples using
the compiled program supplied on the July cover disk.)
HOW THE PROGRAMS WORK...
-------------------------
Playing samples is really quite easy. First you must reserve two chunks of
memory, one for the machine code program called BASPLAY.EXE which replays the
sound, and the other for the sample data itself. The machine code and sample
are loaded into memory:
RESERVE pgm%,1500 :REM space for program code
RESERVE sample%,20000 :REM space for sample
BLOAD "basplay.exe",pgm%
BLOAD "sample1.snd",sample% :REM load sample data into buffer
Now you need to find out how long the sample is:
file% = OPENIN "sample1.snd" :REM get sample length
size% = EXT#file% - 648 :REM size of sample file - 648 (envelope data)
CLOSE#file%
One minor point to watch out for is that programs stored on disc have a
small (28-byte) header before the start of the code and this must be skipped:
pgm% = pgm% + 28 :REM skip header
The machine code program must then be told where in memory the sample is
stored, its size and how fast to replay it:
pgm%!6 = sample% :REM set start of sample data
pgm%!10 = size% :REM set sample length
speed% = 5 :REM 5k=7/8k=6/10k=5/16k=4/20k=3/25k=2/32k=1/40k=0
pgm%!14 = speed% :REM set sample speed
Now all that remains is to call the machine code program and turn up the
volume:
CALL pgm% :REM play sample
HARDWARE: ALL STs, MONO AND COLOUR