home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / curses-2.10.lha / curses / src / beep.c < prev    next >
C/C++ Source or Header  |  1994-02-21  |  4KB  |  124 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : beep.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
  7.  *
  8.  * Date     : Friday 23rd August 1991.
  9.  *
  10.  * Desc     : Produce a audiable sound.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1991, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is provided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectivly.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log: beep.c,v $
  41.  * Revision 1.3  1993/05/17  23:33:10  sie
  42.  * Underscores added to names.
  43.  * Changes for version 2.10
  44.  *
  45.  * Revision 1.2  1992/06/10  23:44:19  sie
  46.  * Added serial support.
  47.  *
  48.  * Revision 1.1  91/09/07  11:39:58  sie
  49.  * Initial revision
  50.  * 
  51.  *
  52.  */
  53.  
  54. static char *rcsid = "$Header: /SRC/lib/curses/src/RCS/beep.c,v 1.3 1993/05/17 23:33:10 sie Exp $";
  55.  
  56. #include <fcntl.h>
  57. #include "acurses.h"
  58.  
  59. beep(void)
  60. {
  61.   struct IOAudio *AIOptr;
  62.   struct MsgPort *port;
  63.   UBYTE whichannel[] = { 1, 2, 4, 8 };
  64.   ULONG device;
  65.   BYTE *sound_data;
  66.  
  67.   if(!(_CursesFlags & CFLAG_INITSCR))  /* Haven't called initscr() */
  68.     return ERR;
  69.   
  70.   if(_CursesType == CUST_CURSES) {
  71.     AIOptr = (struct IOAudio *) AllocMem(sizeof(struct IOAudio), MEMF_CHIP|MEMF_PUBLIC);
  72.     if(!AIOptr)
  73.       _CleanExit(1);
  74.     
  75.     port = (struct MsgPort *)CreatePort(0, 0);
  76.     if(!port) {
  77.       FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  78.       return ERR;
  79.     }
  80.     
  81.     AIOptr->ioa_Request.io_Message.mn_ReplyPort = port;
  82.     AIOptr->ioa_Request.io_Message.mn_Node.ln_Pri = 0;
  83.     AIOptr->ioa_Request.io_Command = ADCMD_ALLOCATE;
  84.     AIOptr->ioa_Request.io_Flags = ADIOF_NOWAIT;
  85.     AIOptr->ioa_AllocKey = 0;
  86.     AIOptr->ioa_Data = whichannel;
  87.     AIOptr->ioa_Length = sizeof(whichannel);
  88.     
  89.     device = OpenDevice("audio.device", 0L, (struct IORequest *)AIOptr, 0L);
  90.     if(device) {
  91.       printf("Curses beep() - Can't open Audio Device\n");
  92.       FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  93.       return ERR;
  94.     }
  95.     
  96.     sound_data = (BYTE *) AllocMem(SOUNDLENGTH, MEMF_CHIP|MEMF_PUBLIC);
  97.     if(!sound_data) {
  98.       FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  99.       return ERR;
  100.     }
  101.     
  102.     sound_data[0]=127;
  103.     sound_data[1]=-127;
  104.     
  105.     AIOptr->ioa_Request.io_Message.mn_ReplyPort = port;
  106.     AIOptr->ioa_Request.io_Command = CMD_WRITE;
  107.     AIOptr->ioa_Request.io_Flags = ADIOF_PERVOL;
  108.     AIOptr->ioa_Data = (UBYTE *)sound_data;
  109.     AIOptr->ioa_Cycles = 200;
  110.     AIOptr->ioa_Length = SOUNDLENGTH;
  111.     AIOptr->ioa_Period = 2000;
  112.     AIOptr->ioa_Volume = 64;
  113.     
  114.     BeginIO((struct IORequest *)AIOptr);
  115.     WaitIO((struct IORequest *)AIOptr);
  116.     
  117.     FreeMem((APTR)sound_data, SOUNDLENGTH);
  118.     DeletePort(port);
  119.     CloseDevice((struct IORequest *)AIOptr);
  120.     FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  121.   } else
  122.     fputc(BELL, stdout);
  123. }
  124.