Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!alberta!cpsc.ucalgary.ca!news From: aycock@cs-sun-fsa.cpsc.ucalgary.ca (John Aycock) Newsgroups: comp.sys.amiga.tech Subject: Need help with ports, messages, audio.device... Message-ID: <1991Jan4.122633.26415@cpsc.ucalgary.ca> Date: 4 Jan 91 12:26:33 GMT Organization: University of Calgary Lines: 102 Originator: aycock@rat Nntp-Posting-Host: rat While trying to compile a large program that was prone to errors, I thought it would be nice for it to beep if it stopped. So I wrote this program to do just that. Unfortunately, it causes intermittent machine crashes, so I'm obviously doing something wrong. I suspect it has to do with something not initialized properly, or me not waiting/responding correctly. It seems to be a delayed reaction, though... it doesn't usually crash right away, but later, when I start up the editor, say. Thanks in advance for any help. BTW, is there a good book that would desribe ports and messages (as opposed to flipping through 7 sections in two ungainly RKMs)??? :ja /* * Quick hack to beep the speaker... beep [ [ #include #include char *progname; #include #include #define PRI_EMERG 100 #define WAVELEN 8 typedef unsigned char bool; typedef unsigned char byte; int beep () { int i, error = 0; bool audioopen = FALSE; byte *wave = NULL; struct MsgPort *port = NULL; struct IOAudio *IOB = NULL; static byte ch_alloc[] = { 1, 2, 4, 8 }; static byte sinewave[] = { 0, 90, 127, 90, 0, -90, -127, -90 }; if (!(port = (struct MsgPort *) CreatePort (NULL, 0L))) goto crapout; if (!(IOB = (struct IOAudio *) AllocMem (sizeof(struct IOAudio), MEMF_PUBLIC|MEMF_CLEAR))) goto crapout; IOB->ioa_Request.io_Message.mn_Node.ln_Type = NT_MESSAGE; IOB->ioa_Request.io_Message.mn_Node.ln_Pri = PRI_EMERG; IOB->ioa_Request.io_Message.mn_ReplyPort = port; IOB->ioa_Request.io_Message.mn_Length = sizeof(struct IOAudio); IOB->ioa_Data = ch_alloc; IOB->ioa_Length = 4; if (OpenDevice (AUDIONAME, 0, IOB, 0)) goto crapout; audioopen = TRUE; if (!(wave = (byte *) AllocMem (WAVELEN, MEMF_CHIP))) goto crapout; for (i = 0; i < WAVELEN; i++) wave[i] = sinewave[i]; IOB->ioa_Request.io_Command = CMD_WRITE; IOB->ioa_Request.io_Flags = ADIOF_PERVOL; IOB->ioa_Data = wave; IOB->ioa_Length = WAVELEN; IOB->ioa_Period = 447; IOB->ioa_Volume = 64; /* maximum volume */ IOB->ioa_Cycles = 125; /* a guess */ BeginIO (IOB); WaitIO (IOB); error = 1; crapout: error -= 1; if (port) DeletePort (port); if (IOB) FreeMem (IOB, sizeof(struct IOAudio)); if (audioopen) CloseDevice (IOB); if (wave) FreeMem (wave, WAVELEN); return (error); } void main (argc, argv) int argc; char *argv[]; { int n = 0, deltime = 0; long sigs; for (progname = argv[0] + strlen(argv[0]) - 1; progname != argv[0] && *(progname-1) != '/' && *(progname-1) != ':'; --progname) ; if (argc > 3 || (argc == 2 && !strncmp ("-h", argv[1], 2))) { fprintf (stderr, "Usage: %s [ [