home *** CD-ROM | disk | FTP | other *** search
- /*************************************/
- /* */
- /* AUoH Progressive Door Prize Lotto */
- /* */
- /* Bleeps and bloops routines */
- /* */
- /* Michael D. Groshart - 16 Sep 89 */
- /* */
- /*************************************/
-
- #include <exec/memory.h>
- #include <devices/audio.h>
- #include <functions.h>
-
- #define WAVELENGTH 2L
- #define AUDIO_PRI 127
- #define VOLUME 64
- #define HERTZ (3579545 / WAVELENGTH)
- #define CLOCK 50
-
- struct IOAudio *ioaudio;
- struct MsgPort *audio_port;
-
- UBYTE allocation [] = { 1,8,2,4 };
- UBYTE *waveform, audio_open;
-
- init_beep()
- {
- if (!(ioaudio = AllocMem((long)sizeof(struct IOAudio),MEMF_PUBLIC|MEMF_CLEAR)))
- quit();
-
- if (!(audio_port = CreatePort("beep.port",NULL)))
- quit();
-
- if (!(waveform = AllocMem(WAVELENGTH,MEMF_CHIP)))
- quit();
-
- waveform[0] = 127;
- waveform[1] = -127;
-
- ioaudio->ioa_Request.io_Message.mn_Node.ln_Pri = AUDIO_PRI;
- ioaudio->ioa_Request.io_Message.mn_ReplyPort = audio_port;
- ioaudio->ioa_Data = allocation;
- ioaudio->ioa_Length = (long)sizeof(allocation);
-
- if (OpenDevice("audio.device",NULL,ioaudio,NULL))
- quit();
-
- ioaudio->ioa_Request.io_Command = CMD_WRITE;
- ioaudio->ioa_Request.io_Flags = ADIOF_PERVOL;
- ioaudio->ioa_Data = waveform;
- ioaudio->ioa_Length = WAVELENGTH;
- ioaudio->ioa_Period = HERTZ / 4096;
- ioaudio->ioa_Volume = 64;
- ioaudio->ioa_Cycles = 5L * 4096 / CLOCK;
- BeginIO(ioaudio);
-
- return (audio_open = 1);
- }
-
- beep(freq,ticks)
- int freq,ticks;
- {
- if (freq < 128)
- freq = 128;
- else if (freq > 8192)
- freq = 8192;
-
- if (!CheckIO(ioaudio))
- {
- AbortIO(ioaudio);
- }
- Remove(ioaudio);
-
- if (ioaudio->ioa_Request.io_Error == 0)
- {
- ioaudio->ioa_Period = HERTZ / freq;
- ioaudio->ioa_Cycles = (long) ticks * freq / CLOCK;
-
- BeginIO(ioaudio);
- }
- }
-
- exit_beep()
- {
- if (!CheckIO(ioaudio))
- {
- AbortIO(ioaudio);
- Remove(ioaudio);
- }
- if (audio_open)
- CloseDevice(ioaudio);
- if (waveform)
- FreeMem(waveform,WAVELENGTH);
- if (audio_port)
- DeletePort(audio_port);
- if (ioaudio)
- FreeMem(ioaudio,(long)sizeof(struct IOAudio));
- }
-