home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / SUPER_C.ZIP / NOISE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  4.0 KB  |  101 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.  
  27.         while (TRUE) {
  28.                 /* Make sure any previous sounds are turned off. */
  29.                 sndOff();
  30.                 /* Ask the user for which type of sound. */
  31.                 printf("1-siren; 2-overload; 3-whoop; 4-phaser; 0-exit: ");
  32.                 /* Read the answer. */
  33.                 scanf("%d",&snd);
  34.                 /* If the answer is to exit, do so. */
  35.                 if (snd == 0) break;
  36.                 /* Ask how many times to repeat the sound. */
  37.                 printf("Number of times: ");
  38.                 /* Get the answer. */
  39.                 scanf("%d",&cnt);
  40.                 /* Repeat the sound the number of time specified. */
  41.                 while (cnt--) {
  42.                         /* Switch on type of sound to produce. */
  43.                         switch (snd) {
  44.                                 case 1:
  45.                                         /* Do a siren: sweep up. */
  46.                                         for (note = 1000; note > 150; 
  47.                                              note -= 10) {
  48.                                                 sound(note); delay(200);
  49.                                         };
  50.                                         /* Sweep down. */
  51.                                         for (; note < 1000; note += 10) {
  52.                                                 sound(note); delay(200);
  53.                                         };
  54.                                         break;
  55.                                 case 2:
  56.                                         /* Do an overload: sweep up. */
  57.                                         for (note = 4000; note > 10; 
  58.                                              note -= 10) {
  59.                                                 sound(note); delay(700);
  60.                                         };
  61.                                         break;
  62.                                 case 3:
  63.                                         /* Do a whoop: sweep up. */
  64.                                         for (note = 1000; note > 10; 
  65.                                              note -= 10) {
  66.                                                 sound(note); delay(200);
  67.                                         };
  68.                                         break;
  69.                                 case 4:
  70.                                         /* Do a phaser: sweep down. */
  71.                                         for (note = 60; note < 2000; 
  72.                                              note += 10) {
  73.                                                 sound(note); delay(100);
  74.                                         };
  75.                                         break;
  76.                                 default:
  77.                                         /* Unknown, ask again. */
  78.                                         printf("Invalid entry; try again.\n");
  79.                                         break;
  80.                         };
  81.                 };
  82.         };
  83. }
  84.  
  85. /*      delay(cnt)
  86.  
  87.         Function: Delay for an amount of time proportional to cnt.
  88.  
  89.         Algorithm: Just waste time in a for loop.
  90. */
  91.  
  92. delay(cnt)
  93.  
  94. {
  95.         int i;
  96.  
  97.         /* Loop to burn time... */
  98.         for (i = 0; i < cnt; i++);
  99. }
  100.  
  101.