home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / TOOLS.ZIP / BEEP.C next >
C/C++ Source or Header  |  1993-02-25  |  1KB  |  84 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "tools.h"
  4. #include <conio.h>
  5. #include <dos.h>
  6.  
  7.  
  8. #if ! defined(__TURBOC__)
  9. #include <time.h>        /*  for clock_t and clock()  */
  10.  
  11.  
  12. /*  void sound ( short frequency, long duration )
  13.  *
  14.  *  Makes the PC speaker emit a sound at `frequency' Herz for approximately
  15.  *  `duration' milliseconds.
  16.  */
  17. void sound ( short frequency, long duration )
  18. {
  19.     clock_t start;
  20.  
  21.     duration *= CLK_TCK;
  22.     duration /= 1000;
  23.     frequency = (short) (1193180L / (long) frequency);
  24.     (void) outp ( 0x43, 182 );
  25.     (void) outp ( 0x42, frequency & 0xFF );
  26.     (void) outp ( 0x42, frequency >> 8 );
  27.  
  28.     start = clock();
  29.     (void) outp ( 0x61, inp ( 0x61 ) | 3 );
  30.     while ( clock() - start < duration ) ;
  31.     (void) outp ( 0x61, inp ( 0x61 ) & 0xFC );
  32. }
  33.  
  34. #endif
  35.  
  36.  
  37. /***
  38.  *
  39.  *  Function beep :   Emit a beep.
  40.  *
  41.  ***/
  42.  
  43. void beep(void)
  44. {
  45. #define FREQ  1000
  46. #define DELAY 50
  47.  
  48. #if defined(__TURBOC__)
  49.   sound(FREQ);
  50.   delay(DELAY);
  51.   nosound();
  52. #else
  53.   sound( FREQ, DELAY );
  54. #endif
  55.  
  56. #undef FREQ
  57. #undef DELAY
  58. }
  59.  
  60.  
  61.  
  62. /***
  63.  *
  64.  *  Function buzzer:   Emit a buzzer sound.
  65.  *
  66.  ***/
  67.  
  68. void buzzer(void)
  69. {
  70. #define FREQ  50
  71. #define DELAY 150
  72.  
  73. #if defined(__TURBOC__)
  74.   sound(FREQ);
  75.   delay(DELAY);
  76.   nosound();
  77. #else
  78.   sound( FREQ, DELAY );
  79. #endif
  80.  
  81. #undef FREQ
  82. #undef DELAY
  83. }
  84.