home *** CD-ROM | disk | FTP | other *** search
- /*
- * MKSoft SnakePit Copyright (c) 1988 by Michael Sinz
- *
- * Sound Effects part of the program...
- */
-
- #include "Snake.h"
-
- /* These are the values needed for the sounds... */
- #define Beat_2_Size 16512L
- extern UBYTE Beat_2[Beat_2_Size];
-
- #define Beat_4_Size 16618L
- extern UBYTE Beat_4[Beat_4_Size];
-
- #define Beat_6_Size 16572L
- extern UBYTE Beat_6[Beat_6_Size];
-
- #define DeathSound_Size 18944L
- extern UBYTE DeathSound[DeathSound_Size];
-
- #define ControlSound_Size 14432L
- extern UBYTE ControlSound[ControlSound_Size];
-
- #define RushSound_Size 800L
- #define RushSound DeathSound
-
- #define EatSound_Size 800L
- #define EatSound Beat_2
-
- /*
- * Note that the sound effects are linked into the executable...
- */
-
- static struct IOAudio *Voices[4]={NULL,NULL,NULL,NULL};
-
- static UBYTE AllocMap[]={1,2,4,8,1,2,4};
-
- static struct MsgPort *AudioPort=NULL;
-
- static Play_Sound(Sound,Size,Period,x,v) register UBYTE *Sound;
- long Size;
- long Period;
- short x;
- register struct IOAudio *v;
- {
- if (v)
- {
- if (!CheckIO(v)) AbortIO(v);
-
- v->ioa_Length=Size;
- v->ioa_Data=Sound;
- v->ioa_Cycles=x;
- v->ioa_Period=(UWORD)Period;
-
- BeginIO(v);
- while (GetMsg(AudioPort)); /* Just to prevent a fireball death */
- }
- }
-
- /* This routine plays the stereo movement sound... */
- VOID Sound_Eat(x) register short x;
- {
- register short loop;
-
- for (loop=2;loop<4;loop++) if (Voices[loop])
- {
- if (!CheckIO(Voices[loop])) AbortIO(Voices[loop]);
- Voices[loop]->ioa_Length=EatSound_Size;
- Voices[loop]->ioa_Data=EatSound;
- Voices[loop]->ioa_Cycles=1;
- Voices[loop]->ioa_Period=180;
- Voices[loop]->ioa_Volume=64-((loop==2)?(40-x):x);
- }
- if (Voices[2]) BeginIO(Voices[2]);
- if (Voices[3]) BeginIO(Voices[3]);
- if (AudioPort) while (GetMsg(AudioPort));
- }
-
- /* This routine plays the stereo movement sound... */
- VOID Sound_Move(x) register short x;
- {
- register short loop;
-
- for (loop=2;loop<4;loop++) if (Voices[loop])
- {
- if (!CheckIO(Voices[loop])) AbortIO(Voices[loop]);
- Voices[loop]->ioa_Length=RushSound_Size;
- Voices[loop]->ioa_Data=RushSound;
- Voices[loop]->ioa_Cycles=1;
- Voices[loop]->ioa_Period=186;
- Voices[loop]->ioa_Volume=64-((loop==2)?(40-x):x);
- }
- if (Voices[2]) BeginIO(Voices[2]);
- if (Voices[3]) BeginIO(Voices[3]);
- if (AudioPort) while (GetMsg(AudioPort));
- }
-
- VOID Sound_Dead() /* This plays the death sound... */
- {
- Play_Sound(DeathSound,DeathSound_Size,SoundPeriod,1,Voices[1]);
- }
-
- VOID Sound_Finish() /* This plays the sound when the exit is found... */
- {
- Play_Sound(ControlSound,ControlSound_Size,SoundPeriod+50L,1,Voices[1]);
- }
-
- /*
- * Values for Sound_Play:
- *
- * 1 First beat...
- * 2 Second beat...
- * 4 Third beat...
- *
- * Bit combinations:
- *
- * 3 First and Second...
- * 6 Second and Third...
- * 7 First, Second, and Third...
- *
- * The value 5 is illegal but not tested for.
- *
- */
- VOID Sound_Play(x,y,z) /* This plays one of the "During Play" sounds... */
- register short x;
- register short y;
- register short z;
- {
- register UBYTE *Sound;
- register long Size=0;
-
- if (x & 4)
- {
- Sound=Beat_6;
- Size+=Beat_6_Size;
- }
- if (x & 2)
- {
- Sound=Beat_4;
- Size+=Beat_4_Size;
- }
- if (x & 1)
- {
- Sound=Beat_2;
- Size+=Beat_2_Size;
- }
- if (Size) Play_Sound(Sound,Size,SoundPeriod-((long)z),y,Voices[0]);
- }
-
- VOID Start_This_Channel(loop) register short loop;
- {
- if (!Voices[loop]) if (Voices[loop]=(struct IOAudio *)AllocMem((long)sizeof(struct IOAudio),MEMF_PUBLIC|MEMF_CLEAR))
- {
- if (!OpenDevice(AUDIONAME,NULL,Voices[loop],NULL))
- {
- Voices[loop]->ioa_Request.io_Message.mn_ReplyPort=AudioPort;
- Voices[loop]->ioa_Request.io_Message.mn_Node.ln_Pri=120-loop;
- Voices[loop]->ioa_Request.io_Command=ADCMD_ALLOCATE;
- Voices[loop]->ioa_Request.io_Flags=ADIOF_NOWAIT;
- Voices[loop]->ioa_AllocKey=0;
- Voices[loop]->ioa_Data=&AllocMap[loop];
- Voices[loop]->ioa_Length=4;
- BeginIO(Voices[loop]);
- if (!WaitIO(Voices[loop]))
- {
- Voices[loop]->ioa_Request.io_Flags=ADIOF_PERVOL;
- Voices[loop]->ioa_Request.io_Command=CMD_WRITE;
- Voices[loop]->ioa_Volume=(loop ? 64:28);
- Voices[loop]->ioa_Cycles=1; /* default to 1 */
- }
- else
- {
- CloseDevice(Voices[loop]);
- FreeMem(Voices[loop],(long)sizeof(struct IOAudio));
- Voices[loop]=NULL;
- }
- }
- else
- {
- FreeMem(Voices[loop],(long)sizeof(struct IOAudio));
- Voices[loop]=NULL;
- }
- }
- }
-
- VOID Init_Sound() /* This sets up all of the good stuff... */
- {
- register short loop;
-
- if (!AudioPort) AudioPort=CreatePort(NULL,NULL);
- if (AudioPort) for (loop=0;loop<4;loop++) Start_This_Channel(loop);
- }
-
- VOID Stop_This_Channel(loop) register short loop;
- {
- if (Voices[loop])
- {
- if (!CheckIO(Voices[loop])) AbortIO(Voices[loop]);
-
- while (GetMsg(AudioPort)); /* Make sure port is empty */
-
- CloseDevice(Voices[loop]);
-
- FreeMem(Voices[loop],(long)sizeof(struct IOAudio));
- Voices[loop]=NULL;
- }
- }
-
- VOID Stop_Sound() /* This closes the whole thing down... */
- {
- register short loop;
-
- for (loop=0;loop<4;loop++) Stop_This_Channel(loop);
- if (AudioPort)
- {
- DeletePort(AudioPort);
- AudioPort=NULL;
- }
- }
-