home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 191_01 / sound.txt < prev    next >
Text File  |  1986-05-25  |  53KB  |  1,783 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                             S O U N D   E F F E C T S
  16.  
  17.                                C Function Library
  18.                                   Version 1.0b
  19.  
  20.  
  21.                        Copyright (C) 1986 by Paul Canniff
  22.                               All Rights Reserved.
  23.  
  24.  
  25.  
  26.  
  27.                                   Paul Canniff
  28.                                   P.O. Box 1056
  29.                                 Marlton NJ 08053
  30.  
  31.                             CompuServe ID 73047,3715
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.                             
  56.                                                         Updated 05 Mar 86
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.                                  C O N T E N T S
  75.  
  76.                   Introduction  .......................  1
  77.                   Installation for Aztec C  ...........  2
  78.                   Installation for Ecosoft C  .........  3
  79.                   Installation for Lattice C  .........  4
  80.                   Installation for other compilers  ...  5
  81.                   Using The Library  ..................  6
  82.                   Making Music (using PLAY)  ..........  8
  83.                   Making Noise (using SOUND)  ......... 10
  84.                   Function Summary List  .............. 11
  85.                   Individual Function Descriptions  ... 12
  86.                   Technical Information  .............. 18
  87.                   What To Do When It Doesn't Work  .... 23
  88.                   Change Log .......................... 24
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.                                   Introduction
  138.  
  139.         This library facilitates the use of sound and music on the IBM-PC 
  140.         family  and  compatibles.   It has been tested with  the  Lattice 
  141.         compiler  version 2.15 and the Manx Aztec compiler version  3.20.  
  142.         Other compilers (or versions of these compilers) should work just 
  143.         fine,  provided  you can rewrite or modify the  assembly-language 
  144.         portions.   I  will be glad to help get the library working  with 
  145.         other compilers.
  146.  
  147.         The  main  functions in the  library  are  play(),  sound(),  and 
  148.         sounds().   Play()  accepts  a form of  musical  notation,  while 
  149.         sounds()  and sounds() accept specific frequencies and  durations 
  150.         for  greater  flexibility  (at the expense of more work  for  the 
  151.         programmer).  These functions are discussed in more detail in the 
  152.         sections "Making Music" and "Making Noise".  Calls to sound() and 
  153.         play()   can  be  freely  intermixed  in  either  foreground   or 
  154.         background,  providing  a  flexible high-level interface  to  the 
  155.         speaker.
  156.  
  157.         All  of  these  sound-making routines can run  in  foreground  or 
  158.         background.  Foreground means that the sound is generated in much 
  159.         the  same  way  that most other  PC  output  is  generated;   the 
  160.         application  requests that it be done,  the driver does  it,  and 
  161.         then it returns to the application.   This is straightforward and 
  162.         clean.
  163.  
  164.         Background is the fancy way.   The music or the sound effects are 
  165.         requested  by  the application,  which can then continue  to  run 
  166.         while the driver controls the speaker.   This allows you to  play 
  167.         some  music  while your program performs some  operations,  which 
  168.         might be better than just flashing WAIT at the user.
  169.  
  170.         In addition,  the library includes a number of low-level routines 
  171.         that access the speaker directly.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.                                         1
  194.  
  195.  
  196.  
  197.  
  198.  
  199.         Sound Effects                                General Installation
  200.  
  201.  
  202.  
  203.         The  following  general  installation procedure  applies  to  all 
  204.         supported compilers.  
  205.  
  206.         (1)  First, set up your "work area", whether it be a subdirectory 
  207.              on  a hard disk,  or a floppy disk.   If you have room on  a 
  208.              current work disk,  or in your usual C subdirectory, you may 
  209.              want  to use them.   Wherever you decide upon,  this disk or 
  210.              diectory will be referred to as your "work area".
  211.  
  212.         (2)  Copy all .C and .H files from the distribution disk to  your 
  213.              work  area.   
  214.  
  215.         (3)  There are also some assembly-langauge source files which you 
  216.              will need, called DELAY and SOUNDINT.  There are versions of 
  217.              these files on the disk for each supported  compiler.   Copy 
  218.              the  proper files to your work area,  changing the extension 
  219.              to .ASM in the process.
  220.  
  221.                     AZTEC:    *.ASZ  ->  *.ASM
  222.                     LATTICE:  *.ASL  ->  *.ASM
  223.                     ECOSOFT:  *.ASE  ->  *.ASM
  224.             
  225.         (*)  Keep  the original distribution disk in a safe  place;   all 
  226.              further actions discussed should be done on your work  area, 
  227.              not the distribution disk.
  228.  
  229.         (2)  Edit  the file SOUND.H and make sure that the only  compiler 
  230.              flag set is the one for your compiler.   That flag should be 
  231.              set to 1, all others to 0.
  232.  
  233.         (3)  Compile  the C files.   They include the following H  files, 
  234.              which should be included with your compiler:
  235.  
  236.                   Lattice, Ecosoft:     STDIO.H, DOS.H
  237.                   Aztec:                STDIO.H, MODEL.H
  238.  
  239.         (4)  Assemble  the  .ASM files using the assembler provided  with 
  240.              your   compiler,   the  Miscrosoft   Macro   Assembler,   or 
  241.              equivalent.   The  following "macro" headers are included by 
  242.              the assembly files:
  243.  
  244.                   Lattice:       DOS.MAC
  245.                   (all others)   -none-     
  246.  
  247.         (5)  The  file  SOUNDTST  is  not a part  of  the  Sound  Effects 
  248.              library,  but  is furnished as an example of an  application 
  249.              calling  the sound functions.   To test  the  library,  link 
  250.              SOUNDTST  to  all  the sound functions,  and  any  necessary 
  251.              modules.  The following modules are required:
  252.  
  253.                   Lattice:       C.OBJ, LC.LIB
  254.                   Ecosoft:       ??
  255.                   Aztec:         C.LIB
  256.  
  257.  
  258.  
  259.                                         2
  260.  
  261.  
  262.  
  263.  
  264.  
  265.         Sound Effects                         Installation - Manx / Aztec
  266.  
  267.  
  268.  
  269.                      Manx Aztec C Version 3.20 Installation
  270.  
  271.         Note:  Older Manx compilers (such as version 1.06) should require 
  272.                no change to the following procedure.
  273.  
  274.         Before  starting,  set  up  your "work area",  whether  it  be  a 
  275.         subdirectory on a hard disk, or a floppy disk.   Then ...
  276.  
  277.         (1)  Copy  the .C and .H files to your work diskette or hard disk 
  278.              subdirectory.   Copy  all .ASL files to .ASM files  on  your 
  279.              work  area.   Keep the original distribution disk in a  safe 
  280.              place;  all further actions discussed should be done on your 
  281.              work area, not the distribution disk.
  282.  
  283.         (2)  Edit  the file SOUND.H and make sure that the only  compiler 
  284.              flag set to 1 is C_AZTEC. 
  285.  
  286.         (3)  Compile  the C files.   They include the following H  files, 
  287.              which should be included with your compiler:
  288.  
  289.                   STDIO.H     MODEL.H
  290.  
  291.         (4)  Assemble  the  .ASM  files using the Manx  Aztec  Assembler, 
  292.              Miscrosoft Macro Assembler or equivalent.
  293.  
  294.         (5)  Link  the file SOUNDTEST.OBJ to the rest of .OBJ's  produced 
  295.              by the above commands, and to the C library (C.LIB). 
  296.  
  297.         (6)  If  you hear music,  you have correctly installed your sound 
  298.              routines.   You  may use LIB or PLIB86 to form them  into  a 
  299.              library if you want.   Note that you will have to repeat the 
  300.              installation procedure for every memory model you use.   Oh, 
  301.              yes,  you  can delete the SOUNDTST files when you are  done, 
  302.              though the source gives a good example of the correct way to 
  303.              access the library.
  304.  
  305.                                    Aztec Notes
  306.  
  307.         (1)  Sound_done() must also be called before exiting an  overlay, 
  308.              if the overlay contains the Sound Effects code and data.  If 
  309.              both  code and data of the Sound Effects functions reside in 
  310.              the root, this is not necessary.
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.                                         3
  326.  
  327.  
  328.  
  329.  
  330.  
  331.         Sound Effects                              Installation - Ecosoft
  332.  
  333.  
  334.  
  335.                        Ecosoft C Version 3.02 Installation
  336.  
  337.         Before  starting,  set  up  your "work area",  whether  it  be  a 
  338.         subdirectory on a hard disk, or a floppy disk.   Then ...
  339.  
  340.         (1)  Copy  the .C and .H files to your work diskette or hard disk 
  341.              subdirectory.   Copy  all .ASE files to .ASM files  on  your 
  342.              work  area.   Keep the original distribution disk in a  safe 
  343.              place;  all further actions discussed should be done on your 
  344.              work area, not the distribution disk.
  345.  
  346.         (2)  Edit  the file SOUND.H and make sure that the only  compiler 
  347.              flag set to 1 is C_ECOSOFT.
  348.  
  349.         (3)  Compile  the C files.   They include the following H  files, 
  350.              which should be included with your Lattice Compiler:
  351.  
  352.                   STDIO.H     DOS.H
  353.  
  354.         (4)  Assemble  the .ASM files using the Microsoft Macro Assembler 
  355.              or equivalent.   The file PRO.H must be present.   This file 
  356.              is included in the Ecosoft C package and allows the assembly 
  357.              modules to know the memory model in use.
  358.  
  359.         (5)  Link  the file SOUNDTEST.OBJ to the rest of .OBJ's  produced 
  360.              by  the  above  commands,  and  to  the  Ecosoft  C  library 
  361.              (ECOC.LIB). 
  362.  
  363.         (6)  If  you hear music,  you have correctly installed your sound 
  364.              routines.   You  may use LIB or PLIB86 to form them  into  a 
  365.              library if you want.   Note that you will have to repeat the 
  366.              installation procedure for every memory model you use.   Oh, 
  367.              yes,  you  can delete the SOUNDTST files when you are  done, 
  368.              though the source gives a good example of the correct way to 
  369.              access the library.
  370.  
  371.                                   Ecosoft Notes
  372.  
  373.         (1)  The  file SOUNDP.H is provided to define the  Sound  Effects 
  374.              callable  functions,  using the prototype form.   If you are 
  375.              using  prototyping,  this  file should be  included  in  any 
  376.              source module that calls the Sound Effects library.
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.                                         4
  392.  
  393.  
  394.  
  395.  
  396.  
  397.         Sound Effects                              Installation - Lattice
  398.  
  399.  
  400.  
  401.                    Lattice C Version 2.14 or 2.15 Installation
  402.  
  403.         Note:  The new Lattice compilers (version 3.xx) should require no 
  404.                change to the following procedure.
  405.  
  406.         Before  starting,  set  up  your "work area",  whether  it  be  a 
  407.         subdirectory on a hard disk, or a floppy disk.   Then ...
  408.  
  409.         (1)  Copy  the .C and .H files to your work diskette or hard disk 
  410.              subdirectory.   Copy  all .ASL files to .ASM files  on  your 
  411.              work  area.   Keep the original distribution disk in a  safe 
  412.              place;  all further actions discussed should be done on your 
  413.              work area, not the distribution disk.
  414.  
  415.         (2)  Edit  the file SOUND.H and make sure that the only  compiler 
  416.              flag set to 1 is C_LATTICE.
  417.  
  418.         (3)  Compile  the C files.   They include the following H  files, 
  419.              which should be included with your Lattice Compiler:
  420.  
  421.                   STDIO.H     DOS.H
  422.  
  423.         (4)  Assemble the .ASM files using the Microsoft Macro  Assembler 
  424.              or equivalent.  The file DOS.MAC must be present.  This file 
  425.              is included in the Lattice C package and allows the assembly 
  426.              modules to know the memory model in use.
  427.  
  428.         (5)  Link  the file SOUNDTEST.OBJ to the rest of .OBJ's  produced 
  429.              by  the  above  commands,  and  to  the  Lattice  C  library 
  430.              (LC.LIB). 
  431.  
  432.         (6)  If  you hear music,  you have correctly installed your sound 
  433.              routines.   You  may use LIB or PLIB86 to form them  into  a 
  434.              library if you want.   Note that you will have to repeat the 
  435.              installation procedure for every memory model you use.   Oh, 
  436.              yes,  you  can delete the SOUNDTST files when you are  done, 
  437.              though the source gives a good example of the correct way to 
  438.              access the library.
  439.  
  440.                                   Lattice Notes
  441.  
  442.         (1)  When compiling the Sound Effects functions,  be usure to use 
  443.              the  correct  compiler flags and DOS.MAC file,  so that  the 
  444.              Sound  Effects functions are using the same memory model  as 
  445.              your application.   You may want to compile four versions of 
  446.              the Sound Effects functions, one for each memory model.
  447.  
  448.         (2)  Be  sure  to compile Sound Effects functions using the  "-v" 
  449.              compiler flag to disable stack checking.  This is compatible 
  450.              with  the  Lattice library.   Not disabling  stack  checking 
  451.              could result in detection of a bogus "stack overflow" during 
  452.              the   timer  interrupt  handler's  execution.    This   will 
  453.              terminate the application.
  454.  
  455.  
  456.  
  457.                                         5
  458.  
  459.  
  460.  
  461.  
  462.  
  463.         Sound Effects                               Installation - Others
  464.  
  465.  
  466.  
  467.  
  468.                              Non-Supported Compilers
  469.  
  470.         To  use  the  Sound Effects library with a  compiler  other  than 
  471.         Lattice  or  Aztec,  you  will  have to  be  familiar  with  your 
  472.         compiler  in order to customize the few assembler routines.   The 
  473.         following  questions should be answered first.   The answers  for 
  474.         the supported compilers are given for reference.
  475.  
  476.  
  477.                                                     Lattice  Manx  Yours?
  478.                                                     -------  ----  ------
  479.          o Does  your compiler append or  prepend 
  480.            an  underscore  to  the name  of  each 
  481.            function?                                   N      Y
  482.  
  483.          o Where does the compiler put parameters?   Stack   Stack
  484.  
  485.          o Where  does  your compiler  place  its 
  486.            return values for int?                     AX      AX
  487.            For long int?                             AX,BX   DX,AX
  488.  
  489.          o Does your compiler use near calls, far 
  490.            calls, or allows both?                    Both    Both
  491.  
  492.          o What provision does your library make     inp()  inport()
  493.            for access to the I/O ports?             outp()  outport()
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.                                         6
  524.  
  525.  
  526.  
  527.  
  528.  
  529.         Sound Effects                                 General Information
  530.  
  531.  
  532.  
  533.                                 Using The Library
  534.  
  535.         Using the Sound Effects library is similar to using the  standard 
  536.         library's  I/O functions.   There is an "open",  some operations, 
  537.         the  a  "close".   In the case,  the opening function  is  called 
  538.         sound_init() and the closing function is sound_done().  One point 
  539.         that  cannot  be stressed overmuch is the importance  of  calling 
  540.         sound_done()  before exiting the program.   Any application which 
  541.         uses  the sound library should call sound_done() at all  possible 
  542.         exit points.
  543.  
  544.         Note the following things about sound_done():
  545.  
  546.              (1)  It  never  hurts to call  it.   Sound_done()  knows  if 
  547.                   sound_init() has been called, and acts accordingly.
  548.  
  549.              (2)  When called it will kill any music still playing.
  550.  
  551.         The opposite number of sound_done() is sound_init(),  who  should 
  552.         (of  course) be called first,  before any other sound  functions.  
  553.         It  is possible to get away without calling sound_init(),  if you 
  554.         want to play in mode 1.   But it really is much neater to call it 
  555.         anyway.
  556.  
  557.         What is mode 1?   Glad you asked.   In the play() function, there 
  558.         is a MODE sub-command which has to do with how notes are  played.  
  559.         But  outside  of that little corner,  when we say "mode"  we  are 
  560.         talking about then WHEN and HOW of the sound output.
  561.  
  562.         You  got  a  taste of the meaning of modes in the  discussion  of 
  563.         Background  and  Foreground  in  the   introduction.    Real-time 
  564.         programmers,  forget your usual understanding of these terms.  In 
  565.         terms  of this library music playing in Foreground plays when you 
  566.         tell  it to,  and your application can do nothing else until  the 
  567.         music is finished.   Music in Background is just "set up" by your 
  568.         command to play,  and actually plays while your application runs.  
  569.         So,  it  is  "background music" for the  application,  hence  the 
  570.         terminology.  
  571.  
  572.         Note   that   the   terms  music  and  sound  are   used   rather 
  573.         interchangeably.    Music  using  normal  notes  is  most  easily 
  574.         generated  by  the play() function,  while sound() gives  a  more 
  575.         flexible  interface if you are into  strange  frequencies.   Both 
  576.         functions can operate in Foreground and Background.
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.                                         7
  590.  
  591.  
  592.  
  593.  
  594.  
  595.         Sound Effects                                 General Information
  596.  
  597.  
  598.         There  are  actually five modes in which the sound  routines  can 
  599.         run.  See the "Technical Information" section for a more complete 
  600.         description of the timing techniques.  The default mode is 1.
  601.  
  602.           Mode      When          Timing Method
  603.           ----   ----------    -------------------------
  604.             1    Foreground    Delay Loop
  605.             2    Foreground    Standard Clock Interrupt
  606.             3    Foreground    Enhanced Clock Interrupt  (*)
  607.             4    Background    Standard Clock Interrupt
  608.             5    Background    Enhanced Clock Interrupt  (*)
  609.  
  610.  
  611.         The  mode number shown above is the value you should give to  the 
  612.         first parameter to sound_init().  The second parameter is sued as 
  613.         a  true/false flag,  and tells sound_init() whether to install  a 
  614.         break handler.   The break handler acts as a safety feature;   it 
  615.         makes sure that sound_done() is called before the application  is 
  616.         terminated by the user typing Control-C or Control-Break.
  617.  
  618.         If  you provide your own break handler,  you will want to disable 
  619.         the  built-in  handler.   Just make sure that you  included  that 
  620.         handler  in  the  list  of  possible  exits,  so  that  it  calls 
  621.         sound_done() before terminating the application.  
  622.  
  623.         If  you don't have a break handler built in to  the  application, 
  624.         let sound_init() put one in for you.
  625.  
  626.         OK,  now   you  know that your application should look  something 
  627.         like this:
  628.  
  629.              main()
  630.              {
  631.                   sound_init(m,1);
  632.                   .
  633.                   .     
  634.                   .
  635.                   sound_done();
  636.              }
  637.  
  638.         That's  pretty  boring.   You can spice it up after  reading  the 
  639.         sections  "Making  Music" and "Making Noise".   One  more  useful 
  640.         function before you go ...  quiet().   If you set up a long piece 
  641.         of  background music,  and for some reason have to kill it  early 
  642.         (but not get ready to exit),  call quiet().   It has no effect in 
  643.         Foreground modes.
  644.  
  645.  
  646.                                    ----------
  647.  
  648.              (*)  The enhanced modes currently produce the same
  649.                   results as the standard modes.  In a future 
  650.                   version these modes will provide better time
  651.                   resolution.  See "Tech Tips" for details.
  652.  
  653.  
  654.  
  655.                                         8
  656.  
  657.  
  658.  
  659.  
  660.  
  661.         Sound Effects                                        Making Music
  662.  
  663.  
  664.  
  665.                                   Making Music 
  666.                                   (Using Play)
  667.  
  668.         The  play function translates a musical score into  sounds.   The 
  669.         score is written using a special notation described below.   This 
  670.         notation  allows  the  use of 8 octaves of 12  notes  each,  with 
  671.         various tempos, etc.  The format of pla() is:
  672.  
  673.              void play(m)
  674.              char *m;
  675.  
  676.         Commands are a single letter followed immediately by one or  more 
  677.         arguments,  if  necessary.   Spaces,  commas,  and semicolons may 
  678.         appear between commands for clarity, but are ignored by play().
  679.  
  680.  
  681.         A to G:   These are the notes A through G, in the current octave.  
  682.                   A  note  may be followed by up to three  modifiers,  in 
  683.                   this order only:
  684.  
  685.                        Sharp/Flat indication:  # or + is sharp;
  686.                                                - is flat.
  687.                        Note length:  number from 1 to 64 (see L)
  688.                        Dots: Up to 10 dots.  A dotted note plays for 3/2
  689.                              of it's normal time.  Two dots = 9/4, three
  690.                              dots = 27/8, etc.
  691.  
  692.                   Examples (assuming the current note length is 4):
  693.  
  694.                        C+        C sharp 1/4 note
  695.                        C+8       C sharp 1/8 note
  696.                        B-.       C sharp 1/4 note dotted = 3/8 note
  697.                        A2.       A 1/2 note dotted = 3/4 note
  698.  
  699.  
  700.         Ln        Sets the current note length.  Note length is 1/n, so a 
  701.                   parameter  of 4 will set subsequent note to 1/4  notes.  
  702.                   Individual  notes may override the current length  with 
  703.                   an explicit length (see above examples).   The range is 
  704.                   1 to 64.
  705.  
  706.                   Note  length  combines  with  tempo  to  determine  the 
  707.                   duration of the note.  Length is measured as a fraction 
  708.                   of  a whole note,  while tempo is in quarter-notes  per 
  709.                   second.   For  example,  with a tempo of 32 and a  note 
  710.                   length of 2, a note will last for 1/16 of a second.
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.                                         9
  722.  
  723.  
  724.  
  725.  
  726.  
  727.         Sound Effects                                        Making Music
  728.  
  729.  
  730.         Mx        Sets the mode of the music.  There are three modes:
  731.  
  732.                      x=N (NORMAL):   notes are played for 7/8 of the note 
  733.                          time, with the remaining 1/8 being a rest.
  734.  
  735.                      x=S (STACCATO): notes are played for 3/4 of the note 
  736.                          time, with the remaining 1/4 being a rest.
  737.  
  738.                      x=L (LEGATO):  notes  are played for the  full  note 
  739.                          time, with no rest.
  740.  
  741.                   The modes Foreground and Background have nothing to  do 
  742.                   with these modes !
  743.  
  744.         Nn        Plays note n (range 0..84),  where 0 means silence.  If 
  745.                   the  argument is missing or out of range,  no  note  is 
  746.                   played.  Cannot be dotted or given explicit length.
  747.  
  748.         On        Sets octave to n (range 0..7).   If argument is out  of 
  749.                   range, current octave remains unchanged.
  750.  
  751.         P[n][.]   Pause or rest;   see the rules for note length (n)  and 
  752.                   dotting  for  the  regular notes  A-G  above.   If  the 
  753.                   argument is missing or invalid, no pause takes place.
  754.  
  755.         R         Resets to default values.  Resets the following:
  756.                             Octave = 4
  757.                             Length = 1
  758.                             Mode = Normal
  759.                             Tempo = 120
  760.  
  761.         Tn        Tempo,  which  may range from 32 to 255,  controls  the 
  762.                   number  of quarter-notes per second.   The  default  is 
  763.                   120.
  764.  
  765.         <         Moves down one octave.   If already at octave 0,  stays 
  766.                   there.
  767.  
  768.         >         Moves  up one octave.   If already at octave  7,  stays 
  769.                   there.
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.                                        10
  788.  
  789.  
  790.  
  791.  
  792.  
  793.         Sound Effects                                        Making Noise
  794.  
  795.  
  796.  
  797.                                   Making Noise 
  798.                             (Using Sound and Sounds)
  799.  
  800.         The  function  sound() and sounds() allow the program to  produce 
  801.         sounds other than those on the normal musical scale.  The penalty 
  802.         for  this flexibility is that more work is usually  required   to 
  803.         specify the frequency and duration of each sound, especially when 
  804.         forming complex noises.
  805.  
  806.         To  produce a single sound,  call  sound().   Simple,  eh?   Just 
  807.         provide  the  frequency  as  (Hz * 100),  and  the  duration  in 
  808.         milliseconds.   To produce a series of sounds,  you can set up an 
  809.         array  of  structures  of the type sound_element and pass  it  to 
  810.         sounds(),  along  with a count of the number of  elements.   Each 
  811.         element  takes up six bytes;  four bytes for the frequency  (long 
  812.         int) and two for the duration (unsigned).
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.                                        11
  854.  
  855.  
  856.  
  857.  
  858.  
  859.         Sound Effects                               Function Descriptions
  860.  
  861.  
  862.  
  863.                               Summary Function List
  864.  
  865.         These  functions  are described in detail later,  but here  is  a 
  866.         comprehensive list of the functions in the library, with the file 
  867.         location and a short description of each one.
  868.  
  869.  
  870.                                    High-Level
  871.  
  872.         sound_init   SOUNDCTL    Call to set mode, etc.
  873.         sound_done   SOUNDCTL    Call before exit.
  874.         sound_mode   SOUNDCTL    Returns current mode.
  875.         sound        SOUND       Make a noise.
  876.         sounds       SOUND       Make several noises.
  877.         play         PLAY        Make pleasant noises using easy notation.
  878.         quiet        SOUNDOUT    Kill playing background music.
  879.         sound_bchk   SOUNDOUT    Check status of sound buffer.
  880.          
  881.                                     Low-Level
  882.                   
  883.         spkr_on      SPKRCTL     Speaker on  (continuous noise) 
  884.         spkr_off     SPKRCTL     Speaker off (blissful quiet)
  885.         spkr_freq    SPKRCTL     Sets the frequency of the noise
  886.         spkr_cntr    SPKRCTL     Sets frequency also (see func description)
  887.                   
  888.                              Internal --- DO NOT USE
  889.                   
  890.         sound_out    SOUNDOUT    Interrupt-driven output routine
  891.         snd_irh      SOUNDINT    Assembly interface for sound_out
  892.         snd_brk      SOUNDINT    Built-in break handler
  893.         snd_giv      SOUNDINT    Utility - get interrupt vector
  894.         snd_siv      SOUNDINT    Utility - set interrupt vector
  895.         delay        DELAY       Internal delay loop used in mode 1               
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.                                        12
  920.  
  921.  
  922.  
  923.  
  924.  
  925.         Sound Effects                               Function Descriptions
  926.  
  927.  
  928.                               SOUND_INIT and SOUND_DONE
  929.  
  930.         Purpose:
  931.  
  932.              Set up and tear down the interrupt vectors needed to provide 
  933.              sound.
  934.  
  935.         Summary:
  936.  
  937.              int sound_init(mode,install_bh)
  938.              int mode, install_bh;
  939.  
  940.              int sound_done();
  941.  
  942.         Parameters:
  943.  
  944.              Mode:          Must be in the range 1..5;  sets the mode for 
  945.                             subsequent   calls  to  sound()  and  play().  
  946.                             Values are:
  947.  
  948.                              1  Foreground w/ Delay Loop               
  949.                              2  Foreground w/ Standard Clock Interrupt 
  950.                              3  Foreground w/ Enhanced Clock Interrupt
  951.                              4  Background w/ Standard Clock Interrupt 
  952.                              5  Background w/ Enhanced Clock Interrupt
  953.  
  954.              Install_bh:    If  this  is  0,  no  break-handler  will  be 
  955.                             installed.   Otherwise,  a break handler will 
  956.                             be installed.   See Technical Information for 
  957.                             a complete description of the break handler.
  958.  
  959.         Returns:
  960.  
  961.              Zero  indicates success.   Sound_init will return -1  if  an 
  962.              invalid mode is passed.
  963.  
  964.         Notes:
  965.  
  966.              Sound_init()  may  be called more than once without  harmful 
  967.              effects.   When called,  any music currently playing will be 
  968.              killed.   You can use calls to sound_init() to change  modes 
  969.              during the application.
  970.  
  971.              Sound_done() shust off background music and the speaker, and 
  972.              cleans  up any interrupt vectors which may have been changed 
  973.              by sound_init().  This lets the application safely exit.
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.                                        13
  986.  
  987.  
  988.  
  989.  
  990.  
  991.         Sound Effects                               Function Descriptions
  992.  
  993.  
  994.                                    SOUND_MODE
  995.  
  996.         Purpose:
  997.  
  998.              Returns  the current sound mode.   See sound_init() for  the 
  999.              possible values.
  1000.  
  1001.         Summary:
  1002.  
  1003.              int sound_mode()
  1004.  
  1005.         Parameters:
  1006.  
  1007.              None
  1008.  
  1009.         Returns:
  1010.  
  1011.              Returns   current  mode,   range  1-5.    See   sound_init() 
  1012.              description for complete list of modes.
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.                                        14
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.         Sound Effects                               Function Descriptions
  1058.  
  1059.  
  1060.                                 SOUND  &  SOUNDS
  1061.  
  1062.         Purpose:
  1063.  
  1064.              Produce a sound or sounds for a certain time.
  1065.  
  1066.         Summary:
  1067.  
  1068.              void sound(freq,dur)
  1069.              long freq;
  1070.              unsigned dur;
  1071.  
  1072.              void sounds(n,sa)
  1073.              int n;
  1074.              struct sound_desc *sa;     
  1075.  
  1076.         Parameters:
  1077.  
  1078.              freq:  Frequency in MHz * 10.   Ex: 400MHz passed as 40000L.  
  1079.                     The  allowable  range is ???.   A frequency of  0  is 
  1080.                     treated  as "silence".   A sound with a duration of 0 
  1081.                     is ignored.
  1082.  
  1083.              dur:   Duration of sound in milliseconds.
  1084.  
  1085.              n:     Number of sounds passed.   Numbers less than zero are 
  1086.                     treated as zero.
  1087.  
  1088.              sa:    Array  of  sound  descriptions,   each  containing  a 
  1089.                     frequency  and a duration,  as per the freq  and  dur 
  1090.                     parameters passed to sound.
  1091.  
  1092.         Returns:
  1093.  
  1094.              0 if all parameters all OK
  1095.             -1 if error in parameters (out of range).     
  1096.  
  1097.         Error Handling:
  1098.  
  1099.              Checks parameter range only.
  1100.  
  1101.         Notes:
  1102.  
  1103.              These  functions  are effected by the mode currently set  by 
  1104.              the  most recent call to sound_init.   They may be used  for 
  1105.              either foreground or background operation.
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.                                        15
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.         Sound Effects                               Function Descriptions
  1124.  
  1125.  
  1126.                                       PLAY
  1127.  
  1128.         Purpose:
  1129.  
  1130.              Play a series of musical notes using an easy notation.
  1131.  
  1132.         Summary:
  1133.  
  1134.              void play(music)
  1135.              char *music;
  1136.  
  1137.         Parameters:
  1138.  
  1139.              The  music  parameter  is a string which  can  contain  many 
  1140.              complex  operations,  all  of  which are  described  in  the 
  1141.              section "Making Music".
  1142.  
  1143.         Returns:
  1144.  
  1145.              Nothing.
  1146.  
  1147.         Error Handling:
  1148.  
  1149.              Any  problems encountered in the music string are handled as 
  1150.              described in the section "Making Music."
  1151.  
  1152.         Notes:
  1153.  
  1154.              The  play function introduces an amount of overhead in terms 
  1155.              of code size,  as it must parse the string.  A program which 
  1156.              is  memory-critical  should use  sounds();   of  course  the 
  1157.              programmer  must  then perform the task of  converting  each 
  1158.              note into one or more sounds. 
  1159.  
  1160.              See "Making Music" for details on play()'s operation.
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.                                        16
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.         Sound Effects                               Function Descriptions
  1190.  
  1191.  
  1192.                         DIRECT SPEAKER CONTROL FUNCTIONS
  1193.  
  1194.         Purpose:
  1195.  
  1196.              Direct control of speaker port.
  1197.  
  1198.         Summary:
  1199.  
  1200.              void spkr_on()
  1201.  
  1202.              void spkr_off()
  1203.  
  1204.              void spkr_freq(f)
  1205.              long f;
  1206.  
  1207.              void spkr_cntr(c)
  1208.              unsigned c;
  1209.  
  1210.         Parameters:
  1211.  
  1212.              The  parameter  to spkr_freq is the frequency in MHz to  set 
  1213.              the  speaker to.   The parameter to spkr_cntr is the  actual 
  1214.              counter  value to be passed to the 8253  timer  chip.   Note 
  1215.              that  the only functions to actually turn the speaker on  or 
  1216.              off  are spkr_on and spkr_off;   setting the frequency  does 
  1217.              not imply activating or deactivating the speaker.
  1218.  
  1219.         Returns:
  1220.  
  1221.              Nothing.
  1222.  
  1223.         Error Handling:
  1224.  
  1225.              None.  
  1226.  
  1227.         Notes:
  1228.  
  1229.              Unlike sound(),  sounds(),  and play(),  which can be freely 
  1230.              intermixed,  use  of  these  low-level  functions  while  in 
  1231.              background  mode  can disrupt the background  music.   While 
  1232.              this  is far from fatal,  is can produce unpleasant  noises.  
  1233.              Call quiet() before using these functions.
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.                                        17
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.         Sound Effects                               Function Descriptions
  1256.  
  1257.  
  1258.  
  1259.                            BACKGROUND-BUFFER FUNCTIONS
  1260.  
  1261.         Purpose:
  1262.  
  1263.              Control music playing in background.
  1264.  
  1265.         Summary:
  1266.  
  1267.              void quiet()
  1268.  
  1269.              void sound_bchk(used,avail)
  1270.              int *used, *avail;
  1271.  
  1272.         Parameters:         
  1273.  
  1274.              quite:              none.
  1275.  
  1276.              sound_buffchk():    used to return values (see below).
  1277.  
  1278.         Returns:            
  1279.  
  1280.              quiet() has no return value.
  1281.  
  1282.              buffchk() returns the number of sound elements in the buffer 
  1283.              and the number of free elements,  via the parameters  "used" 
  1284.              and "avail" respectively.
  1285.  
  1286.         Error Handling:     
  1287.  
  1288.              None.
  1289.  
  1290.         Notes:
  1291.  
  1292.              A  call to quiet will kill any background music,  flush  the 
  1293.              buffer, and shut off the speaker.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.                                        18
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.         Sound Effects                               Technical Information
  1322.  
  1323.  
  1324.  
  1325.                              =======================
  1326.                               TECHNICAL INFORMATION
  1327.                              =======================
  1328.  
  1329.         I  have tried to be clear and precise in these  technical  notes.  
  1330.         Should  you  find any errors in code or  documentation,  or  have 
  1331.         suggestions for improvement,   I would appreciate your  feedback.  
  1332.         These  paragraphs  are  not for the faint  of  heart.   For  more 
  1333.         details,  I  suggest some of Peter Norton's  excellent PC  books, 
  1334.         and the ever-cryptic but fact-filled IBM Technical Reference.
  1335.  
  1336.         Here is a brief summary of this section:
  1337.  
  1338.  
  1339.              Timing Sound Duration (MODES)
  1340.                 Delay Loop - How, Pro & Con
  1341.                 Timer Interrupt - How, Pro & Con
  1342.                 Enhanced Interrupt - How, Pro & Con
  1343.  
  1344.              Sound Generation Mechanics
  1345.                 Speaker Logic
  1346.                 Setting The Frequency
  1347.  
  1348.              The Background Buffer
  1349.  
  1350.              The Break Handler
  1351.  
  1352.              The Interrupt Handler
  1353.  
  1354.                   
  1355.                             =========================
  1356.                             TIMING THE SOUND DURATION
  1357.                             =========================
  1358.  
  1359.         There  are five modes in which the sound routines can run.   They 
  1360.         define  WHEN  the music plays,  and how the  proper  DURATION  is 
  1361.         determined.  The FREQUENCY of the sounds is always determined and 
  1362.         produced by the same method regardless of mode,  and is described 
  1363.         a few paragraphs below.
  1364.  
  1365.           Mode   When          Timing
  1366.           ----   ----          ------
  1367.             1    Foreground    Delay Loop
  1368.             2    Foreground    Standard Clock Interrupt
  1369.             3    Foreground    Enhanced Clock Interrupt
  1370.             4    Background    Standard Clock Interrupt
  1371.             5    Background    Enhanced Clock Interrupt
  1372.  
  1373.         The  default mode is mode 1.   It poses the fewest problems,  but 
  1374.         has some limitations.  The timing is achieved using a delay loop, 
  1375.         which  is  simply  a small piece of code with a  known  execution 
  1376.         time.   By looping through this piece of code you can approximate 
  1377.         the duration of the sounds fairly well.   
  1378.  
  1379.  
  1380.  
  1381.                                        19
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.         Sound Effects                               Technical Information
  1388.  
  1389.  
  1390.         Unfortunately,  the  delay loop method has problems.   It is very 
  1391.         dependent on the hardware, for one thing.   A processor  running 
  1392.         at  8MHz  will  execute the code in close to half the time  of  a 
  1393.         standard  PC running at 4.77MHz,  so the sounds will be  shorter.  
  1394.         Also, the timing becomes dependent on processor type.  The normal 
  1395.         PC has an 8088;  on an  AT&T 6300  (8086) or on a PC-AT (80286),
  1396.         there  will be a noticeable timing difference due to the  varying 
  1397.         bus widths and execution speeds, even if the base processor clock 
  1398.         speed was the same.   And as the coup-de-grace,  this method will 
  1399.         be thrown off by the occurance of interrupts.   An interrupt will 
  1400.         cause  other code to be executed which will extend the  execution 
  1401.         time of the loop.
  1402.  
  1403.         Fortunately there is a better timing method available.   There is 
  1404.         an  on-board main system clock chip which provides a pulse with a 
  1405.         frequency  of about 1.19MHz.   This is stepped down to  a  more 
  1406.         reasonable rate by the 8253 counter chip.   The most familiar use 
  1407.         of  this is to provide the system tick,  which occurs 18.2 time a 
  1408.         second and generates the hardware clock interrupt (IRQ0,  INT 8).  
  1409.         This  is  generally  independent  of  the  clock  speed  of   the 
  1410.         processor,  and so is a good timing source across the extended PC 
  1411.         family.
  1412.  
  1413.         We can use this system tick to time the sounds.   Both foreground 
  1414.         and  background methods can do this;   the foreground modes  will 
  1415.         merely  wait  around  until the sound  is  over.   Therefore  the 
  1416.         following  discussions  of the use of the system  tick  interrupt 
  1417.         apply to both foreground and background.
  1418.  
  1419.         The  standard  interrupt modes (2 and 4) tie  into  the  software 
  1420.         interrupt  vector  0x1C.   This  is the  "user  timer  interrupt" 
  1421.         vector, and is provided by the BIOS as a nice way to tie software 
  1422.         into   the  timer.    The  BIOS  interrupt  handler  retains  all 
  1423.         responsibility  for handling the messy tasks of  sending  end-of-
  1424.         interrupt  to  the interrupt controller  chip,  incrementing  the 
  1425.         time-of-day  clock tick,  etc.   This is a clean way to  use  the 
  1426.         system tick to time events.
  1427.  
  1428.                                 Possible Problems
  1429.  
  1430.         There  are  only two possible problems (that I can see) to  using 
  1431.         the  system  tick.   One  is that some  memory-resident  software 
  1432.         packages  are very possessive about interrupts.   That is why  so 
  1433.         many of them are incompatible with each other.   In  theory,  any 
  1434.         number  of  drivers could share the user system tick by  chaining 
  1435.         themselves together,  but they often don't.   This software does, 
  1436.         so it will work with well-behaved utilities.
  1437.  
  1438.         The other problem mainly involves background mode.   If the  user 
  1439.         aborts the program by using control Ctrl-Break, interrupt vectors 
  1440.         will  not be restored,  and eventually the system will crash  and 
  1441.         need  rebooting.   This  can be prevented by using  the  provided 
  1442.         break handler (see SOUND_INIT) or by calling sound_done() if your 
  1443.         application already provides its own break handler.
  1444.  
  1445.  
  1446.  
  1447.                                        20
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.         Sound Effects                               Technical Information
  1454.  
  1455.  
  1456.                                  Enhanced Modes 
  1457.  
  1458.         The  enhanced  interrupt  modes  (3 and  5)  are  not  yet  fully 
  1459.         implemented,  and  are  presently  the  same as  modes  2  and  4 
  1460.         respectively.   In a future release, they will follow the example 
  1461.         of  BASIC and change the system tick generation to provide better 
  1462.         resolution.   This tick is sped up by a factor of 4.   The  sound 
  1463.         system  must intercept this tick at the INT 8 level,  and provide 
  1464.         the tick to the BIOS only every fourth time,  to keep the  system 
  1465.         time-of-day  clock from speeding ahead.   The advantage is better 
  1466.         time resolution.
  1467.  
  1468.         The  disadvantages to the enhanced modes include all of the  ones 
  1469.         given for the standard clock modes, plus the code has to dig even 
  1470.         deeper  into  territory  where  applications  programs  are   not 
  1471.         encouraged  to  venture.   Still,  taking proper care to  restore 
  1472.         vectors upon exit,  this should be clean enough for everyday use.  
  1473.         There is a question as to the value of the more precise timing of 
  1474.         the sounds, which may not be of great importance anyway.
  1475.  
  1476.  
  1477.                            ==========================
  1478.                            SOUND GENERATION MECHANICS
  1479.                            ==========================
  1480.  
  1481.                                   Speaker Logic
  1482.  
  1483.         The  sounds  are produced using the speaker attached to  the  IBM 
  1484.         motherboard.   The  speaker  is pulsed to provide  sound  of  the 
  1485.         desired  frequency.   The pulsing action is provided courtesy  of 
  1486.         the   main   system  clock,   stepped  down  through   the   8253 
  1487.         programmable counter.  There is also an on/off switch provided by 
  1488.         a  bit  in  the  PPI chip.   The  speaker  control  circuitry  is 
  1489.         logically (not electrically) diagrammed as:
  1490.  
  1491.             +-------+    +--------+
  1492.             | 8284A |--->| 8253-5 |----+                      
  1493.             +-------+    +--------+    |    ____               /|
  1494.                                        +--> )   \             / |
  1495.                                             |AND >---------->[  |
  1496.                                        +--> )___/             \ |
  1497.                       +-----+          |                       \|
  1498.                       | PPI |----------+                    
  1499.                       +-----+                                Speaker
  1500.  
  1501.         The  PPI switch is accessed as bits 0 and 1 at I/O address  0x61.  
  1502.         When the bits are set the speaker switch is on,  when cleared the 
  1503.         speaker  switch  is  off.    See  the  spkr_on()  and  spkr_off() 
  1504.         functions to see how to do this from C.   Note that the value  of 
  1505.         the  PPI  is  first read,  the required bits  changed,  and  then 
  1506.         written  out.   This is necessary because the PPI has many  other 
  1507.         uses for the rest of the bits.
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.                                        21
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.         Sound Effects                               Technical Information
  1520.  
  1521.  
  1522.                         Setting Frequency using the 8253
  1523.  
  1524.         The   system  clock  oscillates  at  about  1.19MHz.    The  8253 
  1525.         programmable counter steps down this frequency by sending a pulse 
  1526.         for  every so many input pulses.   The well-known system tick  of 
  1527.         18.2  ticks per second is obtained using this chip and a  divisor 
  1528.         of 0xFFFF.  The chip has two counters;  while one output connects 
  1529.         to  the system clock interrupt,  the other ties to  the  speaker.  
  1530.         So,  by  changing the divisor in the counter,  we can change  the 
  1531.         frequency  of  the  pulses  sent to the  speaker  and  hence  the 
  1532.         frequency of the sound it produces.
  1533.  
  1534.         For  more  details on the use of the 8253  programmable  counter, 
  1535.         consult the Intel part spec.  
  1536.  
  1537.  
  1538.                               =====================
  1539.                               THE BACKGROUND BUFFER
  1540.                               =====================
  1541.  
  1542.         Sounds  to be played in modes 2 through 5 are placed in a  buffer 
  1543.         and  played  under interrupt control.   Since this buffer  is  of 
  1544.         finite size, it is possible to overflow.  Overflowing sounds will 
  1545.         be discarded.
  1546.  
  1547.         Each entry takes up four (4) bytes,  and the number of entries in 
  1548.         the  buffer  is fixed when you build the library.   The  compiled 
  1549.         files on the disk have a default buffer size of 64 entries.   You 
  1550.         can   change  this  by  changing  the  value  of   the   constant 
  1551.         SND_BUFFSIZE in SOUND.H and recompiling the system.
  1552.  
  1553.         Each  note sent to play() will usually generate two entries,  one 
  1554.         for the note and one for the inter-note pause.  Using sound() and 
  1555.         sounds() will generate exactly one entry per sound element.
  1556.  
  1557.         The  sound buffer is circular,  so that as entries are output  to 
  1558.         the speaker,  more can be added.   Check the status of the buffer 
  1559.         using the function sound_bchk(),  which will get you both  the 
  1560.         number of entries used and the number of entries free.
  1561.  
  1562.  
  1563.                                ===================
  1564.                                 THE BREAK HANDLER
  1565.                                ===================
  1566.  
  1567.         The  built-in  break handler has a simplistic view of  life.   It 
  1568.         accepts  control,  calls sound_done() to clean  up,  then  passes 
  1569.         control  to the break handler that precedes it.   This means that 
  1570.         the usual net result is an exit to DOS, but safely.  Feel free to 
  1571.         use  the  given function as a template,  but  keep  the  original 
  1572.         around in case you accidentally muck it up a bit.
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.                                        22
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.         Sound Effects                               Technical Information
  1586.  
  1587.  
  1588.                              =======================
  1589.                               THE INTERRUPT HANDLER
  1590.                              =======================
  1591.  
  1592.         This  refers   to  the timer interrupt  handler,  a  very  simple 
  1593.         routine.   Its  job is to save the registers,  load  the  segment 
  1594.         registers that C functions expect, call sound_out() to do all the 
  1595.         work,  and restore all the registers.   It then calls the routine 
  1596.         which  was  previously  the interrupt handler.   This is  a  nice 
  1597.         courteous  thing  to do,  as it allows sharing of  this  valuable 
  1598.         resource, the system tick.
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.                                        23
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.         Sound Effects                               Technical Information
  1652.  
  1653.  
  1654.                               WHEN THINGS GO WRONG
  1655.  
  1656.         First of all,  please feel free to ask me (the author) questions.  
  1657.         I cannot accept phone questions at this time, mainly because I am 
  1658.         not  near any particular phone during the day.   You can reach me 
  1659.         by mail or by CompuServe EASYMAIL (73047,3715).   But first,  see 
  1660.         if the following list has your problem on it.
  1661.  
  1662.  
  1663.         "I cannot read the distribution disk."
  1664.  
  1665.              The  distribution  disk is provided in IBM  double-sided  9-
  1666.              sector format.  You will not be able to read it with single-
  1667.              sided drives or with a DOS version before 2.0.
  1668.  
  1669.              If you can read such disks normally,  there is a chance that 
  1670.              the diskette has been damaged in transit.  Please return the 
  1671.              diskette and you will get another copy, no charge.
  1672.  
  1673.  
  1674.         "The files will not compile on my system."
  1675.  
  1676.              If  you are using a non-supported compiler,  all I can do is 
  1677.              refer you to the section on Setting Up for Other Compilers".  
  1678.              If  you  do  get  everything working,  even  if  just  on  a 
  1679.              different  version  of  Lattice  or  Manx/Aztec,   I   would 
  1680.              appreciate  if you let me know.   I will do everything I can 
  1681.              to help you get it compiled and running,  but without a copy 
  1682.              of  the  compiler (DO NOT SEND ME  COPYRIGHTED  SOFTWARE)  I 
  1683.              cannot promise much.
  1684.  
  1685.              Be  sure  you have the file SOUND.H where your compiler  can 
  1686.              find  it.   Also be sure that you have enough room  on  your 
  1687.              diskettes for the compiler's output.
  1688.  
  1689.         "My system locks up when I run a program using sound."
  1690.  
  1691.              First,  if you have any memory-resident utilities, let's get 
  1692.              rid  of them for the moment.   De-install them,  even remove 
  1693.              them  from your AUTOEXEC.BAT file,  then reboot the  system.  
  1694.              Try the program again.  If it still crashes ...
  1695.  
  1696.              Make sure you are calling quiet() before the program exits.
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.                                        24
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.         Sound Effects                               Technical Information
  1718.  
  1719.  
  1720.  
  1721.  
  1722.                                    ==========
  1723.                                    CHANGE LOG
  1724.                                    ==========
  1725.  
  1726.         Version 1.0b  (OPEN)
  1727.  
  1728.                 Added new file SOUNDP.H containing prototypes for all
  1729.                 user-callable functions, for compilers which support
  1730.                 prototyping.
  1731.  
  1732.                 Added support for Ecosoft Eco-C88 compiler.
  1733.  
  1734.                 Compressed definition of Install in SOUNDCTL, by combining
  1735.                 all definitions using typedef's and #defines to allow for
  1736.                 compiler and library differences.
  1737.  
  1738.  
  1739.         Version 1.0a  (2/20/85)
  1740.  
  1741.                 Delay now written in assembler.
  1742.  
  1743.                 Corrected error in play(), which would not play dotted
  1744.                 notes if a length was also specified.  
  1745.  
  1746.                 Corrected error in SOUND.H's definition of MS2TICKS, which
  1747.                 was miscalculated and rounding badly.
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.                                        25
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.