home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / PROGRAMM / FGL112B.ZIP / USER13.DOC < prev    next >
Text File  |  1992-10-05  |  27KB  |  656 lines

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