home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / c / curses / src / beep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-30  |  3.5 KB  |  121 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.2  92/06/10  23:44:19  sie
  42.  * Added serial support.
  43.  * 
  44.  * Revision 1.1  91/09/07  11:39:58  sie
  45.  * Initial revision
  46.  * 
  47.  *
  48.  */
  49.  
  50. static char *rcsid = "$Header: SRC:lib/curses/src/RCS/beep.c,v 1.2 92/06/10 23:44:19 sie Exp $";
  51.  
  52. #include <fcntl.h>
  53. #include "acurses.h"
  54.  
  55. beep(void)
  56. {
  57.   struct IOAudio *AIOptr;
  58.   struct MsgPort *port;
  59.   UBYTE whichannel[] = { 1, 2, 4, 8 };
  60.   ULONG device;
  61.   BYTE *sound_data;
  62.  
  63.   if(!(CursesFlags & CFLAG_INITSCR))  /* Haven't called initscr() */
  64.     return ERR;
  65.   
  66.   if(CursesType == CUST_CURSES) {
  67.     AIOptr = (struct IOAudio *) AllocMem(sizeof(struct IOAudio), MEMF_CHIP|MEMF_PUBLIC);
  68.     if(!AIOptr)
  69.       CleanExit(1);
  70.     
  71.     port = (struct MsgPort *)CreatePort(0, 0);
  72.     if(!port) {
  73.       FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  74.       return ERR;
  75.     }
  76.     
  77.     AIOptr->ioa_Request.io_Message.mn_ReplyPort = port;
  78.     AIOptr->ioa_Request.io_Message.mn_Node.ln_Pri = 0;
  79.     AIOptr->ioa_Request.io_Command = ADCMD_ALLOCATE;
  80.     AIOptr->ioa_Request.io_Flags = ADIOF_NOWAIT;
  81.     AIOptr->ioa_AllocKey = 0;
  82.     AIOptr->ioa_Data = whichannel;
  83.     AIOptr->ioa_Length = sizeof(whichannel);
  84.     
  85.     device = OpenDevice("audio.device", 0L, (struct IORequest *)AIOptr, 0L);
  86.     if(device) {
  87.       printf("Curses beep() - Can't open Audio Device\n");
  88.       FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  89.       return ERR;
  90.     }
  91.     
  92.     sound_data = (BYTE *) AllocMem(SOUNDLENGTH, MEMF_CHIP|MEMF_PUBLIC);
  93.     if(!sound_data) {
  94.       FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  95.       return ERR;
  96.     }
  97.     
  98.     sound_data[0]=127;
  99.     sound_data[1]=-127;
  100.     
  101.     AIOptr->ioa_Request.io_Message.mn_ReplyPort = port;
  102.     AIOptr->ioa_Request.io_Command = CMD_WRITE;
  103.     AIOptr->ioa_Request.io_Flags = ADIOF_PERVOL;
  104.     AIOptr->ioa_Data = (UBYTE *)sound_data;
  105.     AIOptr->ioa_Cycles = 200;
  106.     AIOptr->ioa_Length = SOUNDLENGTH;
  107.     AIOptr->ioa_Period = 2000;
  108.     AIOptr->ioa_Volume = 64;
  109.     
  110.     BeginIO((struct IORequest *)AIOptr);
  111.     WaitIO((struct IORequest *)AIOptr);
  112.     
  113.     FreeMem((APTR)sound_data, SOUNDLENGTH);
  114.     DeletePort(port);
  115.     CloseDevice((struct IORequest *)AIOptr);
  116.     FreeMem((APTR)AIOptr, sizeof(struct IOAudio));
  117.   } else if(CursesType == ANSI_CURSES) {
  118.     write(1, "\007", 1);
  119.   }
  120. }
  121.