1 line
14 KiB
C
1 line
14 KiB
C
|
//============================================================================
//----------------------------------------------------------------------------
// Sound.c
//----------------------------------------------------------------------------
//============================================================================
// This file handles all sound routines. It handles 2 concurrent sound<6E>
// channels allowing 2 sounds to be played simultaneously. It also handles<65>
// a system of priorites whereby you can ensure that "important" sounds don't<>
// get cut off by "lesser" sounds. In that there are 2 channels however,<2C>
// "lesser" sounds are not discounted outright - both channels are considered<65>
// to determine if one of the channels is not playing at all (priority = 0) or<6F>
// playing a sound of an even lesser priority. Make sense?
#include <Sound.h>
#include "Externs.h"
#define kMaxSounds 17 // Number of sounds to load.
#define kBaseBufferSoundID 1000 // ID of first sound (assumed sequential).
#define kSoundDone 913 // Just a number I chose.
#define kSoundDone2 749 // Just a number I chose.
void PlaySound1 (short, short);
void PlaySound2 (short, short);
pascal void ExternalCallBack (SndChannelPtr, SndCommand *);
pascal void ExternalCallBack2 (SndChannelPtr, SndCommand *);
void LoadAllSounds (void);
OSErr LoadBufferSounds (void);
OSErr DumpBufferSounds (void);
OSErr OpenSoundChannel (void);
OSErr CloseSoundChannel (void);
SndCallBackUPP externalCallBackUPP, externalCallBackUPP2;
SndChannelPtr externalChannel, externalChannel2;
Ptr theSoundData[kMaxSounds];
short externalPriority, externalPriority2;
Boolean channelOpen, soundOn;
//============================================================== Functions
//-------------------------------------------------------------- PlaySound1
// This function takes a sound ID and a priority, and forces that sound to
// play through channel 1 - and saves the priority globally. As well, a
// callback command is queues up in channel 1.
void PlaySound1 (short soundID, short priority)
{
SndCommand theCommand;
OSErr theErr;
theCommand.cmd = flushCmd; // Send 1st a flushCmd to clear the sound queue.
theCommand.param1 = 0;
theCommand.param2 = 0L;
theErr = SndDoImmediate(externalChannel, &theCommand);
theCommand.cmd = quietCmd; // Send quietCmd to stop any current sound.
theCommand.param1 = 0;
theCommand.param2 = 0L;
theErr = SndDoImmediate(externalChannel, &theCommand);
externalPriority = priority; // Copy priority to global variable.
theCommand.cmd = bufferCmd; // Then, send a bufferCmd to channel 1.
theCommand.param1 = 0; // The sound played will be soundID.
theCommand.param2 = (long)(theSoundData[soundID]);
theErr = SndDoImmediate(externalChannel, &theCommand);
theCommand.cmd = callBackCmd; // Lastly, queue up a callBackCmd to notify us<75>
theCommand.param1 = kSoundDone; // when the sound has finished playing.
theCommand.param2 = SetCurrentA5();
theErr = SndDoCommand(externalChannel, &theCommand, TRUE);
}
//-------------------------------------------------------------- PlaySound2
// This function is identical to the above function except that it handles<65>
// playing sounds through channel 2.
void PlaySound2 (short soundID, short priority)
{
SndCommand theCommand;
OSErr theErr;
theCommand.cmd = flushCmd; // Send 1st a flushCmd to clear the sound queue.
theCommand.param1 = 0;
theCommand.param2 = 0L;
theErr = SndDoImmediate(externalChannel2, &theCommand);
theCommand.cmd = quietCmd; // Send quietCmd to stop any current sound.
theCommand.param1 = 0;
theCommand.param2 = 0L;
theErr = SndDoImmediate(externalChannel2, &theCommand);
externalPriority2 = priority; // Copy priority to global variable.
theCommand.cmd = bufferCmd; // Then, send a bufferCmd to channel 1.
theCommand.param1 = 0; // The sound played will be soundID.
theCommand.param2 = (long)(theSoundData[soundID]);
theErr = SndDoImmediate(externalChannel2, &theCommand);
theCommand.cmd = callBackCmd; // L
|