home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Graphics / graphics-16000.iso / msdos / animutil / fastgfx / fg303b / manuals.arj / USER15.DOC < prev    next >
Text File  |  1993-10-02  |  27KB  |  647 lines

  1. Chapter 15
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Sound Effects
  8. 286   Fastgraph User's Guide
  9.  
  10.  
  11. Overview
  12.  
  13.      In the realm of the IBM PC and PS/2 family of systems, a sound is
  14. defined by its frequency, duration, and volume.  The frequency of a sound is
  15. measured in units called Hertz.  While the PC and PS/2 can produce sounds
  16. ranging from 18 to more than one million Hertz, the average human can hear
  17. sounds between 20 and about 20,000 Hertz.  The length of a sound, called its
  18. duration, is expressed in clock ticks; there are either 18.2 of 72.8 clock
  19. ticks per second, depending on the method used to produce the sound.
  20. Finally, the volume determines the loudness of the sound.  As we'll see in
  21. this chapter, we can control a sound's volume only on the PCjr and Tandy 1000
  22. systems.
  23.  
  24.      Fastgraph contains several different methods for producing sound
  25. effects.  These include single tones, a series of tones expressed
  26. numerically, or a series of tones expressed as musical notes.  The sound
  27. effects may be discrete, continuous, or performed at the same time as other
  28. activity.  The sound-related routines are independent of the other parts of
  29. Fastgraph and do not require any initialization routines be called.
  30.  
  31.  
  32. Sound Sources
  33.  
  34.      All members of the PC and PS/2 families can produce sounds using the
  35. 8253-5 programmable timer chip and the internal speaker.  This method is
  36. limited to producing single sounds of given frequencies and durations,
  37. although we can combine these sounds to create interesting audio effects or
  38. play music.  When we use this technique, we have no control over the sound
  39. volume.  In fact, sound volumes often vary slightly on different systems
  40. because the physical properties of the speaker and its housing are not always
  41. the same.
  42.  
  43.      The PCjr and Tandy 1000 systems have an additional, more powerful chip
  44. for producing sounds.  This is the Texas Instruments SN76496A sound chip,
  45. called the TI sound chip for short.  The TI sound chip has three independent
  46. voice channels for producing pure tones, and a fourth channel for generating
  47. periodic or white noise.  Each voice channel has a separate volume control
  48. that allows us to control the loudness of the sound it emits.
  49.  
  50.  
  51. Synchronous Sound
  52.  
  53.      A sound effect is said to be synchronous if it is produced while no
  54. other activity is being performed.  In other words, a program makes a
  55. synchronous sound by starting the sound, waiting for a specified duration,
  56. and then stopping the sound.  The program must wait for the sound to complete
  57. before doing anything else.  As long as the duration is relatively short, the
  58. fact that the sound is synchronous has little or no effect on the program's
  59. execution speed.  Fastgraph includes routines for producing synchronous sound
  60. using either the 8253-5 programmable timer or the TI sound chip.
  61.  
  62.      The fg_sound routine uses the programmable timer to produce a sound of a
  63. given frequency and duration.  The frequency, defined by the first argument,
  64. is expressed in Hertz and must be an integer value between 18 and 32,767.
  65. The second argument defines the duration and is expressed in clock ticks;
  66.                                               Chapter 15:  Sound Effects   287
  67.  
  68. there are 18.2 clock ticks per second.  If the duration is zero or negative,
  69. the sound will continue until it is stopped with the fg_quiet routine.
  70.  
  71.      Example 15-1 uses the fg_sound routine to create different sound
  72. effects, pausing for one second between each.  It first produces three
  73. distinct sounds of 20, 100, and 1,000 Hertz.  Each of these sounds lasts for
  74. approximately 1/6 of a second (three clock ticks).  The program then makes a
  75. warbling noise by quickly alternating sounds of similar frequencies.
  76. Finally, the program creates a sliding tone of increasing frequencies between
  77. 100 and 500 Hertz.  Each tone in this sequence lasts for two clock ticks, so
  78. it takes about 4.5 seconds to play the entire sequence.  In all cases,
  79. example 15-1 displays an identifying message just before each sound.
  80.  
  81.                                 Example 15-1.
  82.  
  83.               #include <fastgraf.h>
  84.               #include <stdio.h>
  85.               void main(void);
  86.  
  87.               void main()
  88.               {
  89.                  int freq;
  90.  
  91.                  printf("20 Hz tone...\n");
  92.                  fg_sound(20,3);
  93.                  fg_waitfor(18);
  94.  
  95.                  printf("100 Hz tone...\n");
  96.                  fg_sound(100,3);
  97.                  fg_waitfor(18);
  98.  
  99.                  printf("1000 Hz tone...\n");
  100.                  fg_sound(1000,3);
  101.                  fg_waitfor(18);
  102.  
  103.                  printf("warble...\n");
  104.                  fg_sound(400,1);
  105.                  fg_sound(410,1);
  106.                  fg_sound(400,1);
  107.                  fg_sound(410,1);
  108.                  fg_waitfor(18);
  109.  
  110.                  printf("sliding tone from 100 to 500 Hz...\n");
  111.                  for (freq = 100; freq <= 500; freq+=10)
  112.                     fg_sound(freq,2);
  113.               }
  114.  
  115.  
  116.      The fg_voice routine is analogous to the fg_sound routine, but it uses
  117. the TI sound chip rather than the programmable timer to create sound.  For
  118. this reason, the fg_voice routine can only be used on the PCjr or Tandy 1000
  119. systems.  The TI sound chip allows us to control the volume of a sound, and
  120. it also offers four distinct voice channels.  Thus, fg_voice requires two
  121. additional arguments besides frequency and duration to define the voice
  122. channel and sound volume.
  123. 288   Fastgraph User's Guide
  124.      The first argument to fg_voice defines the voice channel, as shown
  125. below.
  126.  
  127.                   value  meaning
  128.  
  129.                     1    voice channel #1
  130.                     2    voice channel #2
  131.                     3    voice channel #3
  132.                     4    voice channel #4, periodic noise
  133.                     5    voice channel #4, white noise
  134.  
  135. If we use voice channels 1, 2, or 3, the second argument defines the sound
  136. frequency in Hertz, between 18 and 32,767.  If we use voice channel 4,
  137. however, the second argument instead is a value that represents a specific
  138. frequency, as shown in this table.
  139.  
  140.                        value   frequency
  141.  
  142.                          0     512 Hertz
  143.                          1    1024 Hertz
  144.                          2    2048 Hertz
  145.  
  146. The third argument defines the sound volume.  It must be between 0 and 15,
  147. where 0 is silent and 15 is loudest.  The fourth argument defines the sound
  148. duration in clock ticks.  As with the fg_sound routine, there are 18.2 clock
  149. ticks per second, and if the duration is zero or negative, the sound will
  150. continue until stopped with the fg_quiet routine.
  151.  
  152.      Example 15-2 uses the fg_voice routine to create different sound effects
  153. using the TI sound chip.  As in example 15-1, there is a pause of one second
  154. between each.  The program first calls the fg_testmode routine to be sure it
  155. is running on a PCjr or Tandy 1000 system (video mode 9 is only available on
  156. these systems).  If so, the program uses voice channel #4 to produce a 2,048
  157. Hertz periodic noise, followed by white noise of the same frequency.  Both
  158. sounds are emitted at the maximum volume level (15) and last for about 1/6 of
  159. a second each (three clock ticks).  After these noises, example 15-2 produces
  160. a 500 Hertz tone of increasing volume.  In all cases, the program displays an
  161. identifying message just before each sound.
  162.  
  163.                                 Example 15-2.
  164.  
  165.              #include <fastgraf.h>
  166.              #include <stdio.h>
  167.              #include <stdlib.h>
  168.              void main(void);
  169.  
  170.              void main()
  171.              {
  172.                 int volume;
  173.  
  174.                 if (fg_testmode(9,0) == 0) {
  175.                    printf("This program requires a PCjr or ");
  176.                    printf("a Tandy 1000 system.\n");
  177.                    exit(1);
  178.                    }
  179.  
  180.                 printf("2048 Hz periodic noise...\n");
  181.                                               Chapter 15:  Sound Effects   289
  182.  
  183.                 fg_voice(4,2,15,3);
  184.                 fg_waitfor(18);
  185.  
  186.                 printf("2048 Hz white noise...\n");
  187.                 fg_voice(5,2,15,3);
  188.                 fg_waitfor(18);
  189.  
  190.                 printf("500 Hz tone of increasing volume...\n");
  191.                 for (volume = 1; volume <= 15; volume++) {
  192.                    fg_voice(1,500,volume,0);
  193.                    fg_waitfor(4);
  194.                    }
  195.  
  196.                 fg_quiet();
  197.              }
  198.  
  199.  
  200.      Note how example 15-2 uses a duration of zero (continuous sound) and the
  201. fg_waitfor routine to specify the duration for each volume level the 500
  202. Hertz tone sequence.  This causes the transition between changes in volume to
  203. blend better with each other.  The fg_quiet routine, which stops continuous
  204. sound started with the fg_sound or fg_voice routines, ends the sound after
  205. the final volume level.
  206.  
  207.      The fg_sound and fg_voice routines each produce a single sound.  We've
  208. seen how to combine sounds to produce sound effects, but still the individual
  209. sounds are defined numerically -- that is, by a certain frequency and
  210. duration.  It is often easier to create sounds from musical notes, and for
  211. this reason Fastgraph includes a routine fg_music that produces such sounds.
  212. The fg_music routine uses the programmable timer to produce synchronous
  213. sound; it does not support the TI sound chip.
  214.  
  215.      The fg_music routine has a single argument called the music string,
  216. passed by reference as a byte array or character string.  The music string is
  217. simply a variable-length sequence of music commands, followed by a dollar-
  218. sign ($) terminator.  Music commands are summarized in the following table.
  219.  
  220. command   meaning
  221.  
  222. A thru G  Play the specified note in the current octave.
  223.  
  224. #         May be appended to a note character (A through G) to make that note
  225.           sharp.
  226.  
  227. .         May be appended to a note character (A through G) or a sharp (#) to
  228.           extend that note by half its normal length.  Multiple dots may be
  229.           used, and each will again extend the note by half as much as the
  230.           previous extension.
  231.  
  232. Ln        Set the length of subsequent notes and pauses.  The value of n is
  233.           an integer between 1 and 64, where 1 indicates a whole note, 2 a
  234.           half note, 4 a quarter note, and so forth.  If no L command is
  235.           present, L4 is assumed.
  236.  
  237. On        Set the octave for subsequent notes.  The value of n may be an
  238.           integer between 0 and 6 to set a specific octave.  It also can be a
  239. 290   Fastgraph User's Guide
  240.  
  241.           plus (+) or minus (-) character to increment or decrement the
  242.           current octave number.  Octave 4 contains middle C, and if no O
  243.           command is present, O4 is assumed.
  244.  
  245. P         Pause (rest) for the duration specified by the most recent L
  246.           command.
  247.  
  248. Sn        Set the amount of silence between notes.  The value of n is an
  249.           integer between 0 and 2.  If n is 0, each note plays for the full
  250.           period set by the L command (music legato).  If n is 1, each note
  251.           plays for 7/8 the period set by the L command (music normal).  If n
  252.           is 2, each note plays for 3/4 the period set by the L command
  253.           (music staccato).  If no S command is present, S1 is assumed.
  254.  
  255. Tn        Set the tempo of the music (the number of quarter notes per
  256.           minute).  The value of n is an integer between 32 and 255.  If no T
  257.           command is present, T120 is assumed.
  258.  
  259. The fg_music routine ignores any other characters in the music string.  It
  260. also ignores command values outside the allowable range, such as T20 or O8.
  261.  
  262.      Example 15-3 illustrates some uses of the fg_music routine.  The program
  263. plays the first few bars of "Mary Had a Little Lamb", followed by the musical
  264. scale (including sharps) in two octaves, and finally the introduction to
  265. Beethoven's Fifth Symphony.  There is a pause of one second between each
  266. piece of music, and the program displays the titles before playing the music.
  267. Blank characters appear in the music strings to help make them more readable.
  268.  
  269.                                 Example 15-3.
  270.  
  271.     #include <fastgraf.h>
  272.     #include <stdio.h>
  273.     void main(void);
  274.  
  275.     void main()
  276.     {
  277.        printf("Mary Had a Little Lamb...\n");
  278.        fg_music("T150 L8 EDCDEEE P DDD P EGG P EDCDEEE L16 P L8 EDDEDC$");
  279.        fg_waitfor(18);
  280.  
  281.        printf("up the scale in two octaves...\n");
  282.        fg_music("L16 CC#DD#EFF#GG#AA#B O+ CC#DD#EFF#GG#AA#B$");
  283.        fg_waitfor(18);
  284.  
  285.        printf("Beethoven's Fifth Symphony...\n");
  286.        fg_music("T180 O2 L2 P L8 P GGG L2 D# L24 P L8 P FFF L2 D$");
  287.     }
  288.  
  289.  
  290. Asynchronous Sound
  291.  
  292.      Sounds made concurrently with other activity in a program are said to be
  293. asynchronous.  Fastgraph's routines that produce asynchronous sound just
  294. start the sound and then immediately return control to the calling program.
  295. The sounds will automatically stop when the end of the sequence is reached,
  296. and you also can suspend or stop it on demand before that time.  None of
  297.                                               Chapter 15:  Sound Effects   291
  298.  
  299. Fastgraph's asynchronous sound routines have any effect if there is already
  300. asynchronous sound in progress.  In addition, the asynchronous sound routines
  301. temporarily disable the synchronous sound routines (fg_sound, fg_voice, and
  302. fg_music) while asynchronous sound is in progress.
  303.  
  304.      To expand the range of sound effects and to play fast-tempo music,
  305. Fastgraph temporarily quadruples the clock tick interrupt rate from 18.2 to
  306. 72.8 ticks per second while producing asynchronous sound.  Because many disk
  307. controllers rely on the 18.2 tick per second clock rate to synchronize disk
  308. accesses, your programs should not perform any disk operations when
  309. asynchronous sound is in progress.
  310.  
  311.      The fg_sounds routine is the asynchronous version of the fg_sound
  312. routine.  It uses the programmable timer to play a sequence of tones
  313. simultaneous to other operations.  This routine expects as its first argument
  314. a variable-length integer array, passed by reference, containing pairs of
  315. frequency and duration values.  As with the fg_sound routine, each frequency
  316. is expressed in Hertz and must be between 18 and 32,767.  The durations are
  317. also measured in clock ticks, but because the interrupt rate is quadrupled,
  318. there are 72.8 instead of 18.2 ticks per second.
  319.  
  320.      The format of the frequency and duration array passed to fg_sounds is
  321. shown below.
  322.  
  323.                           [0]    frequency of sound 1
  324.  
  325.                           [1]    duration  of sound 1
  326.  
  327.                           [2]    frequency of sound 2
  328.  
  329.                           [3]    duration  of sound 2
  330.                                           .
  331.                                           .
  332.                                           .
  333.                                           .
  334.                                           .
  335.                        [2n-2]    frequency of sound n
  336.  
  337.                        [2n-1]    duration  of sound n
  338.  
  339.                          [2n]       terminator (0)
  340.  
  341. Note that a null character (that is, a zero byte) terminates the array.  The
  342. second argument passed to fg_sounds is an integer value indicating the number
  343. of times to cycle through the frequency and duration array.  If this value is
  344. negative, the sounds will continue until stopped with the fg_hush or
  345. fg_hushnext routines.
  346.  
  347.      Example 15-4 uses the fg_sounds routine to play the 100 to 500 Hertz
  348. sliding tone sequence of example 15-1.  To prove the sounds are being made
  349. concurrently with other operations, messages are displayed while the sequence
  350. is playing.  This is controlled by the Fastgraph routine fg_playing, which
  351. returns a value of 1 if asynchronous sounds are in progress, and 0 if not.
  352. Note how the duration must be specified as 8 clock ticks (instead of 2 as in
  353. example 15-1) to compensate for the quadrupled clock tick interrupt rate.
  354. 292   Fastgraph User's Guide
  355.  
  356.                                 Example 15-4.
  357.  
  358.                  #include <fastgraf.h>
  359.                  #include <stdio.h>
  360.                  void main(void);
  361.  
  362.                  void main()
  363.                  {
  364.                     int i;
  365.                     int freq;
  366.                     int sound_array[83];
  367.  
  368.                     i = 0;
  369.  
  370.                     for (freq = 100; freq <= 500; freq+=10) {
  371.                        sound_array[i++] = freq;
  372.                        sound_array[i++] = 8;
  373.                        }
  374.                     sound_array[i] = 0;
  375.  
  376.                     fg_sounds(sound_array,1);
  377.  
  378.                     while(fg_playing())
  379.                        printf("Still playing...\n");
  380.                  }
  381.  
  382.  
  383.      Just as the fg_sounds routine is analogous to the fg_sound routine,
  384. there is a Fastgraph routine fg_voices that is similar to the fg_voice
  385. routine.  That is, fg_voices uses the TI sound chip to play an asynchronous
  386. sequence of tones.  Its arguments are the same as those of the fg_sounds
  387. routine, but the structure of the sound array is different.  Its structure
  388. is:
  389.  
  390.                           [0]    channel # of sound 1
  391.  
  392.                           [1]    frequency of sound 1
  393.  
  394.                           [2]    volume    of sound 1
  395.  
  396.                           [3]    duration  of sound 1
  397.                                           .
  398.                                           .
  399.                                           .
  400.                                           .
  401.                                           .
  402.                        [4n-4]    channel # of sound n
  403.  
  404.                        [4n-3]    frequency of sound n
  405.  
  406.                        [4n-2]    volume    of sound n
  407.  
  408.                        [4n-1]    duration  of sound n
  409.  
  410.                          [4n]       terminator (0)
  411.  
  412.                                               Chapter 15:  Sound Effects   293
  413.  
  414. The channel numbers, frequencies, volumes, and durations must be in the same
  415. ranges as discussed in the description of the fg_voice routine, except the
  416. durations are quadrupled because of the accelerated clock tick interrupt
  417. rate.  Again, note that a null character (that is, a zero byte) terminates
  418. the array.
  419.  
  420.      Example 15-5 uses the fg_voices routine to play the 500 Hertz tone
  421. sequence of increasing volume introduced in example 15-2.  As in example
  422. 15-4, the program displays messages while the tone sequence is playing to
  423. demonstrate the sounds are being made concurrently with other operations.
  424. Note how the duration is now 16 clock ticks (instead of 4 as in example 15-2)
  425. because of the quadrupled clock tick interrupt rate.
  426.  
  427.                                 Example 15-5.
  428.  
  429.            #include <fastgraf.h>
  430.            #include <stdio.h>
  431.            void main(void);
  432.  
  433.            void main()
  434.            {
  435.               int voice_array[61];
  436.               int i;
  437.               int volume;
  438.  
  439.               if (fg_testmode(9,0) == 0) {
  440.                  printf("This program requires a PCjr or ");
  441.                  printf("a Tandy 1000 system.\n");
  442.                  exit(1);
  443.                  }
  444.  
  445.               i = 0;
  446.  
  447.               for (volume = 1; volume <= 15; volume++) {
  448.                  voice_array[i++] = 1;      /* use channel 1 */
  449.                  voice_array[i++] = 500;    /* 500 Hz frequency */
  450.                  voice_array[i++] = volume; /* variable volume */
  451.                  voice_array[i++] = 16;     /* duration */
  452.                  }
  453.               voice_array[i] = 0;
  454.  
  455.               fg_voices(voice_array,1);
  456.  
  457.               while(fg_playing())
  458.                  printf("Still playing...\n");
  459.            }
  460.  
  461.  
  462.      There is also an asynchronous version of the fg_music routine.  It is
  463. called fg_musicb, and it uses the same format music string as the fg_music
  464. routine does.  However, the fg_musicb routine has a second argument that
  465. specifies the number of times to cycle through the music string.  If this
  466. value is negative, the music will play repetitively until you stop it with
  467. the fg_hush or fg_hushnext routine.
  468. 294   Fastgraph User's Guide
  469.      Example 15-6 plays the same three pieces of music as example 15-3, but
  470. it does so concurrently with other operations.  As the music plays, the
  471. program continuously displays the title of each piece.  Note how we can take
  472. advantage of the repetition in the music string for the "up the scale"
  473. sequence by playing the sequence twice.
  474.  
  475.                                 Example 15-6.
  476.  
  477.   #include <fastgraf.h>
  478.   #include <stdio.h>
  479.   void main(void);
  480.  
  481.   void main()
  482.   {
  483.      fg_musicb("T150 L8 EDCDEEE P DDD P EGG P EDCDEEE L16 P L8 EDDEDC$",1);
  484.      while (fg_playing())
  485.         printf("Mary Had a Little Lamb...\n");
  486.      fg_waitfor(18);
  487.  
  488.      fg_musicb("L16 CC#DD#EFF#GG#AA#B O+$",2);
  489.      while (fg_playing())
  490.         printf("up the scale in two octaves...\n");
  491.      fg_waitfor(18);
  492.  
  493.      fg_musicb("T180 O2 L2 P L8 P GGG L2 D# L24 P L8 P FFF L2 D$",1);
  494.      while (fg_playing())
  495.         printf("Beethoven's Fifth Symphony...\n");
  496.   }
  497.  
  498.      The next example demonstrates the effects of the Fastgraph routines
  499. fg_hush and fg_hushnext, which stop sounds started with the fg_sounds,
  500. fg_voices, or fg_musicb routines.  The fg_hush routine immediately stops
  501. asynchronous sound, whereas the fg_hushnext routine does so when the current
  502. cycle finishes.  Neither routine has any arguments, and neither routine has
  503. any effect if no asynchronous sound is in progress.  Furthermore, note that
  504. fg_hushnext has no effect unless the asynchronous sound is continuous.
  505.  
  506.      Example 15-7 runs in any text or graphics video mode.  It displays
  507. rectangles in up to 16 colors while playing continuous asynchronous music.
  508. The program periodically checks for keystrokes with the fg_intkey routine,
  509. and it continues to play the music while there is no keyboard activity.  If
  510. you press the Escape key, the program uses fg_hush to stop the music
  511. immediately; this causes an exit from the while loop.  If you press any other
  512. key, the program uses fg_hushnext to stop the music as soon as the current
  513. repetition finishes.  Once it does, the program exits the while loop because
  514. fg_playing will return a value of zero.
  515.  
  516.                                 Example 15-7.
  517.  
  518.       #include <fastgraf.h>
  519.       void main(void);
  520.  
  521.       #define ESC 27
  522.  
  523.       void main()
  524.       {
  525.  
  526.                                               Chapter 15:  Sound Effects   295
  527.          int color;
  528.          int old_mode;
  529.          unsigned char key, aux;
  530.  
  531.          old_mode = fg_getmode();
  532.          fg_setmode(fg_automode());
  533.          color = 0;
  534.  
  535.          fg_musicb("O4 L16 CC#DD#EFF#GG#AA#B O+ CC#DD#EFF#GG#AA#B$",-1);
  536.  
  537.          while (fg_playing())
  538.          {
  539.             color = (color + 1) & 15;
  540.             fg_setcolor(color);
  541.             fg_rect(0,fg_getmaxx(),0,fg_getmaxy());
  542.  
  543.             fg_waitfor(4);
  544.             fg_intkey(&key,&aux);
  545.             if (key == ESC)
  546.                fg_hush();
  547.             else if (key+aux != 0)
  548.                fg_hushnext();
  549.          }
  550.  
  551.          fg_setmode(old_mode);
  552.          fg_reset();
  553.       }
  554.  
  555.      Example 15-7 also demonstrates an important side-effect of the fg_musicb
  556. routine when playing continuous music.  Any length, octave, silence, or tempo
  557. values changed within the string are not reset to their original values at
  558. the beginning of each repetition.  If we did not include the O4 command at
  559. the beginning of the string, the later O+ command would cause the music to
  560. play in octaves 4 and 5 during the first repetition, 5 and 6 during the
  561. second repetition, and octave 6 for all subsequent repetitions (because you
  562. cannot increase the octave number above 6).
  563.  
  564.      The final two routines relating to asynchronous sound are fg_resume and
  565. fg_suspend.  The fg_suspend routine suspends music previously started by
  566. fg_musicb, while fg_resume restarts the music from the point where it was
  567. suspended.  Example 15-8 plays the first few bars of "Mary Had a Little
  568. Lamb".  If you press any key while the song is playing, it stops.  Then,
  569. after another keystroke, the music resumes and continues until finished.
  570.  
  571.                                 Example 15-8.
  572.  
  573.   #include <fastgraf.h>
  574.   #include <stdio.h>
  575.   void main(void);
  576.  
  577.   void main()
  578.   {
  579.      fg_musicb("T150 L8 EDCDEEE P DDD P EGG P EDCDEEE L16 P L8 EDDEDC$",1);
  580.      fg_waitkey();
  581.  
  582.      fg_suspend();
  583.  
  584. 296   Fastgraph User's Guide
  585.  
  586.      printf("Music suspended.  Press any key to resume.\n");
  587.      fg_waitkey();
  588.  
  589.      fg_resume();
  590.      printf("Music resumed.\n");
  591.      while (fg_playing());
  592.      printf("Music finished.\n");
  593.   }
  594.  
  595.  
  596. The fg_suspend routine has no effect if there is no asynchronous music in
  597. progress.  Similarly, fg_resume has no effect if there is no suspended music.
  598. If you call fg_suspend and then need to cancel the music or exit to DOS
  599. instead of restarting the music, call fg_hush instead of fg_resume.
  600.  
  601.  
  602. Summary of Sound Routines
  603.  
  604.      This section summarizes the functional descriptions of the Fastgraph
  605. routines presented in this chapter.  More detailed information about these
  606. routines, including their arguments and return values, may be found in the
  607. Fastgraph Reference Manual.
  608.  
  609.      FG_HUSH immediately stops asynchronous sound started with the fg_sounds,
  610. fg_voices, or fg_musicb routines.
  611.  
  612.      FG_HUSHNEXT is similar to fg_hush, but it does not stop the asynchronous
  613. sound until the current repetition finishes.
  614.  
  615.      FG_MUSIC uses the programmable timer to play a sequence of musical
  616. tones.
  617.  
  618.      FG_MUSICB is the asynchronous version of the fg_music routine.  It uses
  619. the programmable timer to play a sequence of musical tones, concurrent with
  620. other activity.
  621.  
  622.      FG_PLAYING determines whether or not there is any asynchronous sound in
  623. progress.
  624.  
  625.      FG_QUIET stops continuous synchronous sound started with the fg_sound or
  626. fg_voice routines.
  627.  
  628.      FG_RESUME restarts asynchronous music previously suspended by
  629. fg_suspend.
  630.  
  631.      FG_SOUND produces a tone of a specified frequency and duration using the
  632. programmable timer.
  633.  
  634.      FG_SOUNDS is the asynchronous version of the fg_sound routine.  It can
  635. play a series of tones of specified frequencies and durations, concurrent
  636. with other activity.
  637.  
  638.      FG_SUSPEND suspends asynchronous music previously started by fg_musicb.
  639.  
  640.      FG_VOICE produces a tone of a specified frequency, duration, and volume
  641. using one of the TI sound chip's four voice channels.
  642.                                               Chapter 15:  Sound Effects   297
  643.  
  644.      FG_VOICES is the asynchronous version of the fg_voice routine.  It can
  645. play a series of tones of specified frequencies, durations, and volumes,
  646. concurrent with other activity.
  647. 298   Fastgraph User's Guide