home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 06user / sounds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  926 b   |  75 lines

  1. /*
  2.  *    sounds -- make various sounds on demand
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <math.h>
  8.  
  9. #define ESC    27
  10.  
  11. extern void sound(unsigned int, float);
  12.  
  13. main()
  14. {
  15.     int ch;
  16.  
  17.     fprintf(stderr, "1=warble 2=error 3=confirm 4=warn\n");
  18.     fprintf(stderr, "Esc=quit\n");
  19.     while ((ch = getch()) != ESC)
  20.         switch (ch) {
  21.         case '1':
  22.             warble();
  23.             break;
  24.         case '2':
  25.             error();
  26.             break;
  27.         case '3':
  28.             confirm();
  29.             break;
  30.         case '4':
  31.             warn();
  32.             break;
  33.         }
  34.     exit(0);
  35. }
  36.  
  37. #define CYCLES    3
  38. #define LOTONE    600
  39. #define HITONE    1200
  40. #define PERIOD    0.1
  41.  
  42. warble()
  43. {
  44.     int i;
  45.  
  46.     for (i = 0; i < 2 * CYCLES; ++i)
  47.         if (i % 2)
  48.             sound(LOTONE, PERIOD);
  49.         else
  50.             sound(HITONE, PERIOD);
  51. }
  52.  
  53. error()
  54. {
  55.     float d = 0.15;
  56.  
  57.     sound(440, d);
  58.     sound(220, d);
  59. }
  60.  
  61. confirm()
  62. {
  63.     float d = 0.15;
  64.  
  65.     sound(440, d);
  66.     sound(880, d);
  67. }
  68.  
  69. warn()
  70. {
  71.     float d = 0.2;
  72.  
  73.     sound(100, d);
  74. }
  75.