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 >
Text File  |  1990-06-24  |  3KB  |  71 lines

  1.                               SOUNDING OUT
  2.  
  3.  
  4.                      Roland Waddilove shows how to add
  5.                    sampled sound effects to your programs
  6.  
  7.  
  8. ------------------------------------------------------------------------------
  9. SAMPLED sound effects make a tremendous difference to programs, particularly
  10. games where they are already extensively used. RunTime is an invaluable source
  11. of these superb sounds and over the coming months you'll find several on each
  12. Cover Disk. There are two this month and there will be more next month so
  13. you'll soon build up a library of exciting effects.
  14. ------------------------------------------------------------------------------
  15.  
  16. To replay the samples you need a suitable utility - which you'll also find on
  17. this month's Cover Disk. In fact, there are two versions: a Fast BASIC and
  18. HiSoft BASIC listing. To replay the samples you'll need to boot up HiSoft BASIC
  19. and load SAMPLE.BAS or Fast BASIC and load SAMPLE.BSC.
  20.  
  21.     Run the program (either version) and use the file selector to choose the
  22. sampled sound you want to play, click on the speed from the options in the
  23. Alert box and turn up the volume on your monitor to hear the effects. The
  24. samples were recorded at 10kHz so sound best when replayed at this speed.
  25.  
  26.     The source code is supplied on the disk so you can load it, modify it and
  27. then insert the relevent sound replay section in your own programs. (If you
  28. haven't got either HiSoft or Fast BASIC then you can still replay samples using
  29. the compiled program supplied on the July cover disk.)
  30.  
  31. HOW THE PROGRAMS WORK...
  32. -------------------------
  33. Playing samples is really quite easy. First you must reserve two chunks of
  34. memory, one for the machine code program called BASPLAY.EXE which replays the
  35. sound, and the other for the sample data itself. The machine code and sample
  36. are loaded into memory:
  37.  
  38. RESERVE pgm%,1500            :REM space for program code
  39. RESERVE sample%,20000        :REM space for sample
  40. BLOAD "basplay.exe",pgm%
  41. BLOAD "sample1.snd",sample%  :REM load sample data into buffer
  42.  
  43.     Now you need to find out how long the sample is:
  44.  
  45. file% = OPENIN "sample1.snd" :REM get sample length
  46. size% = EXT#file% - 648      :REM size of sample file - 648 (envelope data)
  47. CLOSE#file%
  48.  
  49.     One minor point to watch out for is that programs stored on disc have a
  50. small (28-byte) header before the start of the code and this must be skipped:
  51.  
  52. pgm% = pgm% + 28   :REM skip header
  53.  
  54.     The machine code program must then be told where in memory the sample is
  55. stored, its size and how fast to replay it:
  56.  
  57. pgm%!6 = sample%        :REM set start of sample data
  58. pgm%!10 = size%         :REM set sample length
  59. speed% = 5              :REM 5k=7/8k=6/10k=5/16k=4/20k=3/25k=2/32k=1/40k=0
  60. pgm%!14 = speed%        :REM set sample speed
  61.  
  62.     Now all that remains is to call the machine code program and turn up the
  63. volume:
  64.  
  65. CALL pgm%               :REM play sample
  66.  
  67.  
  68. HARDWARE: ALL STs, MONO AND COLOUR
  69.  
  70.  
  71.