home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / MKTONE.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  63 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  MKTONE.C
  5. **
  6. **  Original Copyright 1988-1991 by Bob Stout as part of
  7. **  the MicroFirm Function Library (MFL)
  8. **
  9. **  The user is granted a free limited license to use this source file
  10. **  to create royalty-free programs, subject to the terms of the
  11. **  license restrictions specified in the LICENSE.MFL file.
  12. */
  13.  
  14. #include <stddef.h>
  15. #include "uclock.h"
  16. #include "sound.h"
  17. #include "pchwio.h"
  18.  
  19.  
  20. void dosound(int freq)
  21. {
  22.       unsigned i;
  23.  
  24.       outp(C8253, SETIMER);
  25.       i = (unsigned)freq%256;
  26.       outp(F8253, i);
  27.       i = (unsigned)freq/256;
  28.       outp(F8253, i);
  29. }
  30.  
  31. void mktone(int freq, int update, unsigned delay)
  32. {
  33.       if (0 == freq)
  34.       {
  35.             soundoff();
  36.             return;
  37.       }
  38.       dosound(freq);
  39.       if (update != UPDATE)
  40.             soundon();
  41.       if (delay == 0)
  42.             return;
  43.       else  usec_delay(1000L * (unsigned long)delay);
  44.       if (update == TOGGLE)
  45.             soundoff();
  46. }
  47.  
  48. #ifdef TEST
  49.  
  50. #include <stdio.h>
  51.  
  52. main()
  53. {
  54.       puts("Playing A2 for 1 sec.");
  55.       mktone(A2, ON, 1000);
  56.       puts("Playing A3 for 1 sec.");
  57.       mktone(A3, UPDATE, 1000);
  58.       mktone(0,  UPDATE, 0);
  59.       return 0;
  60. }
  61.  
  62. #endif /* TEST */
  63.