home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / super_c / noise2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  4.4 KB  |  109 lines

  1. /*                      Noise Maker Main Program
  2.  */
  3.  
  4. #define FALSE 0
  5. #define TRUE 1
  6.  
  7. /*      main()
  8.  
  9.         Function: Produce sound-effect. Repeatedly ask the user what
  10.         sound to make, and then make it.
  11.  
  12.         Algorithm: Loop, asking the user for which sound and how many
  13.         times to make it. Then repeat the sound generation code the
  14.         number of times requested. To generate the sound, switch on the
  15.         type of sound to generate. Each sound is generated by sweeping
  16.         through a set of frequencies in a particular order at a particular
  17.         rate.
  18. */
  19.  
  20. main()
  21.  
  22. {
  23.         int snd;        /* Which sound to produce. */
  24.         int cnt;        /* Number of times to repeat sound. */
  25.         int note;       /* Current note, when sweeping frequencies. */
  26.         int adj100;     /* A delay of 100, adjusted for processor speed. */
  27.         int adj200;     /* Delay of 200, adjusted for processor speed. */
  28.         int adj700;     /* Delay of 700, adjusted for processor speed. */
  29.  
  30.         /* Calculate the delays needed for this processor. */
  31.         adj100 = calib();
  32.         adj200 = 2*adj100;
  33.         adj700 = 7*adj100;
  34.  
  35.         while (TRUE) {
  36.                 /* Make sure any previous sounds are turned off. */
  37.                 sndOff();
  38.                 /* Ask the user for which type of sound. */
  39.                 printf("1-siren; 2-overload; 3-whoop; 4-phaser; 0-exit: ");
  40.                 /* Read the answer. */
  41.                 scanf("%d",&snd);
  42.                 /* If the answer is to exit, do so. */
  43.                 if (snd == 0) break;
  44.                 /* Ask how many times to repeat the sound. */
  45.                 printf("Number of times: ");
  46.                 /* Get the answer. */
  47.                 scanf("%d",&cnt);
  48.                 /* Repeat the sound the number of time specified. */
  49.                 while (cnt--) {
  50.                         /* Switch on type of sound to produce. */
  51.                         switch (snd) {
  52.                                 case 1:
  53.                                         /* Do a siren: sweep up. */
  54.                                         for (note = 1000; note > 150; 
  55.                                              note -= 10) {
  56.                                                 sound(note); delay(adj200);
  57.                                         };
  58.                                         /* Sweep down. */
  59.                                         for (; note < 1000; note += 10) {
  60.                                                 sound(note); delay(adj200);
  61.                                         };
  62.                                         break;
  63.                                 case 2:
  64.                                         /* Do an overload: sweep up. */
  65.                                         for (note = 4000; note > 10; 
  66.                                              note -= 10) {
  67.                                                 sound(note); delay(adj700);
  68.                                         };
  69.                                         break;
  70.                                 case 3:
  71.                                         /* Do a whoop: sweep up. */
  72.                                         for (note = 1000; note > 10; 
  73.                                              note -= 10) {
  74.                                                 sound(note); delay(adj200);
  75.                                         };
  76.                                         break;
  77.                                 case 4:
  78.                                         /* Do a phaser: sweep down. */
  79.                                         for (note = 60; note < 2000; 
  80.                                              note += 10) {
  81.                                                 sound(note); delay(adj100);
  82.                                         };
  83.                                         break;
  84.                                 default:
  85.                                         /* Unknown, ask again. */
  86.                                         printf("Invalid entry; try again.\n");
  87.                                         break;
  88.                         };
  89.                 };
  90.         };
  91. }
  92.  
  93. /*      delay(cnt)
  94.  
  95.         Function: Delay for an amount of time proportional to cnt.
  96.  
  97.         Algorithm: Just waste time in a for loop.
  98. */
  99.  
  100. delay(cnt)
  101.  
  102. {
  103.         int i;
  104.  
  105.         /* Loop to burn time... */
  106.         for (i = 0; i < cnt; i++);
  107. }
  108.  
  109.