mirror of
https://github.com/softdorothy/GliderPRO.git
synced 2024-11-25 10:30:45 +00:00
1 line
11 KiB
C
1 line
11 KiB
C
|
//============================================================================
//----------------------------------------------------------------------------
// Sound.c
//----------------------------------------------------------------------------
//============================================================================
#include <Resources.h>
#include <Sound.h>
#include "Externs.h"
#define kBaseBufferSoundID 1000
#define kMaxSounds 64
#define kNoSoundPlaying -1
pascal void CallBack0 (SndChannelPtr, SndCommand *);
pascal void CallBack1 (SndChannelPtr, SndCommand *);
pascal void CallBack2 (SndChannelPtr, SndCommand *);
OSErr LoadBufferSounds (void);
void DumpBufferSounds (void);
OSErr OpenSoundChannels (void);
OSErr CloseSoundChannels (void);
SndCallBackUPP callBack0UPP, callBack1UPP, callBack2UPP;
SndChannelPtr channel0, channel1, channel2;
Ptr theSoundData[kMaxSounds];
short numSoundsLoaded, priority0, priority1, priority2;
short soundPlaying0, soundPlaying1, soundPlaying2;
Boolean soundLoaded[kMaxSounds], dontLoadSounds;
Boolean channelOpen, isSoundOn, failedSound;
//============================================================== Functions
//-------------------------------------------------------------- PlayPrioritySound
void PlayPrioritySound (short which, short priority)
{
short lowestPriority, whosLowest;
if (failedSound || dontLoadSounds)
return;
if ((priority == kTriggerPriority) &&
((priority0 == kTriggerPriority) ||
((priority1 == kTriggerPriority)) ||
((priority2 == kTriggerPriority))))
return;
whosLowest = 0;
lowestPriority = priority0;
if (priority1 < lowestPriority)
{
lowestPriority = priority1;
whosLowest = 1;
}
if (priority2 < lowestPriority)
{
lowestPriority = priority2;
whosLowest = 2;
}
if (priority >= lowestPriority)
{
switch (whosLowest)
{
case 0:
PlaySound0(which, priority);
break;
case 1:
PlaySound1(which, priority);
break;
case 2:
PlaySound2(which, priority);
break;
}
}
}
//-------------------------------------------------------------- FlushAnyTriggerPlaying
void FlushAnyTriggerPlaying (void)
{
SndCommand theCommand;
OSErr theErr;
if (priority0 == kTriggerPriority)
{
theCommand.cmd = quietCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel0, &theCommand);
theCommand.cmd = flushCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel0, &theCommand);
}
if (priority1 == kTriggerPriority)
{
theCommand.cmd = quietCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel1, &theCommand);
theCommand.cmd = flushCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel1, &theCommand);
}
if (priority2 == kTriggerPriority)
{
theCommand.cmd = quietCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel2, &theCommand);
theCommand.cmd = flushCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel2, &theCommand);
}
}
//-------------------------------------------------------------- PlaySound0
void PlaySound0 (short soundID, short priority)
{
SndCommand theCommand;
OSErr theErr;
if (failedSound || dontLoadSounds)
return;
theErr = noErr;
if (isSoundOn)
{
priority0 = priority;
soundPlaying0 = soundID;
theCommand.cmd = bufferCmd;
theCommand.param1 = 0;
theCommand.param2 = (long)(theSoundData[soundID]);
theErr = SndDoImmediate(channel0, &theCommand);
theCommand.cmd = callBackCmd;
theCommand.param1 = 0;
theCommand.param2 = SetCurrentA5();
theErr = SndDoCommand(channel0, &theCommand, true);
}
}
//-------------------------------------------------------------- PlaySound1
void PlaySound1 (short soundID, short priority)
{
SndCommand theCommand;
OSErr theErr;
if (failedSound || dontLoadSounds)
return;
theErr = noErr;
if (isSoundOn)
{
priority1 = priority;
soundPlaying1 = soundID;
theCommand.c
|