home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- * FILE: CMSoundSystem.h
- * AUTHOR: David Hay
- * CREATED: March 9, 1995
- * DESCRIPTION: Interface to the Caveman Sound System.
- *
- * Copyright © 1995 David Hay
- *
- * Permission to use, copy, and distribute this software and its documentation
- * for any purpose is hereby granted without fee, provided that (i) the above
- * copyright notices and this permission notice appear in all copies of the
- * software and related documentation, and (ii) the names of David Hay and
- * Caveman Creations may not be used in any advertising or publicity relating
- * to the software without the specific, prior written permission of David Hay
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
- * IMPLIED OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
- * DAVID HAY OR CAVEMAN CREATIONS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
- * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *****************************************************************************/
-
- #ifndef __CMSOUNDSYSTEM__
- #define __CMSOUNDSYSTEM__
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
- #define kMaxChannels 20 /* The maximum number of channels allowed */
- #define kMaxSounds 50 /* Maximum number of sounds that may be registered */
- #define kMaxMusicLen 128 /* Maximum length of a song sequence. */
- #define kNoSound (-1) /* Reference number for no sound at all */
- #define kSoundResource (-2) /* Reference number of an unregistered sound */
- #define kNoLoop (-1) /* In a music sequence, indicates no looping */
- #define kMusicResType 'MUSL' /* Resource type for a music list */
- #define kAsynchronous true /* Constant to define asychronous play */
-
-
-
- /*****************************************************************************
- ** PlaySequence -- Describes a sequence of sounds to play in order to
- ** produce a piece of music.
- **
- ** loopStart - the position in the sequence to jump to after the
- ** sequence as finished.
- ** sequenceLength - the number of sounds to play in the sequence.
- ** sequence[] - the list of sounds to play. This array determines
- ** the order of sounds to play, allowing a sound
- ** to be repeated several times in a piece of music.
- **/
- typedef struct PlaySequence
- {
- short loopStart;
- short sequenceLength;
- short sequence[1]; /* Variable sized */
- } PlaySequence, *PlaySequencePtr, **PlaySequenceHandle;
-
-
-
- /*----------------------- INITIALIZATION/DEALLOCATION -----------------------*/
-
- extern OSErr
- CMSInitSound( short numChannels );
- /*
- * Initialize the sound system.
- *
- * ON ENTRY: 'numChannels' is a number greater than 0
- * ON EXIT: The sound system has been initialized to provide 'numChannels'
- * channels of sound.
- * Any errors are returned.
- *****************************************************************************/
-
- extern void
- CMSDisposeSound( void );
- /*
- * Dispose of any registered sound and internal data used by the sound
- * system. Any sound system functions should not be used after calling
- * this function.
- *
- * ON ENTRY: The sound system has been previously initialized
- * ON EXIT: Any data used by the sound system is disposed of.
- *****************************************************************************/
-
-
- /*---------------------------- CHANNEL MANAGEMENT ---------------------------*/
-
- extern OSErr
- CMSCloseChannel( short channelNum );
- /*
- * Closes sound channel number 'channelNum'. The channel is still allocated,
- * but sound may not be played through it. To reopen the channel, call
- * CMSOpenChannel()
- *
- * ON ENTRY: 'channelNum' is a positive number less than the number of
- * available channels [as passed to CMSInitSound()]
- * The sound system has been initialized
- * ON EXIT: The channel number 'channelNum' has been closed.
- * Any errors are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSCloseAllChannels( void );
- /*
- * Closes all of the open channels. The channels are still allocated, but
- * sound may not be played through them. To reopen a specific channel, call
- * CMSOpenChannel(). To reopen all channels, call CMSOpenAllChannels().
- *
- * ON ENTRY: The sound system has been initialized
- * ON EXIT: All open sound channels have been closed.
- * Any errors are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSOpenChannel( short channelNum );
- /*
- * Opens channel number 'channelNum'. After opening a channel, sound may be
- * played through that sound channel. If the sound channel is alreay open,
- * nothing is done.
- *
- * ON ENTRY: 'channelNum' is a positive number less than the number of
- * available channels [as passed to CMSInitSound()]
- * The sound system has been initialized
- * ON EXIT: The channel, 'channelNum' is opened and ready to play sounds
- * Any errors are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSOpenAllChannels( void );
- /*
- * Opens all currently closed sound channels. After opening a sound channel,
- * sound may be played on that sound channel.
- *
- * ON ENTRY: The sound system has been initialized.
- * ON EXIT: All allocated sound channels have been opened.
- * Any errors are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSStopSound( short channelNum );
- /*
- * Stops any currently playing sounds on sound channel 'channelNum'
- *
- * ON ENTRY: 'channelNum' is a positive number less than the number of
- * available sound channels [as passed to CMSInitSound()]
- * ON EXIT: Any sounds playing on channel, 'channelNum' are stopped. If
- * the sound playing on the sound channel was a sound resource,
- * the resource is unlocked so that it may be purged.
- *****************************************************************************/
-
- extern void
- CMSIdleSoundTask( void );
- /*
- * Handles any housecleaning tasks the sound system may need to perform. It
- * should be called before playing a sound resource.
- *
- * ON ENTRY: The sound system has been initialized
- * ON EXIT: Any routine chores the sound system have been performed.
- *****************************************************************************/
-
- extern OSErr
- CMSGetSoundPlaying( short channelNum, short* refNum );
- /*
- * Get the reference number of the sound currently playing on a sound channel.
- *
- * ON ENTRY: 'channelNum' is a positive number less than the number of
- * available sound channels [as passed to CMSInitSound()]
- * 'refNum' points to location to store the currently playing
- * sound reference number.
- * ON EXIT: The sound playing on the channel, 'channelNum' is returned in
- * the area pointed to by 'refNum'. If no sounds are currently
- * playing, 'kNoSound' is returned in 'refNum'. If the currently
- * playing sound is a sound resource, 'kSoundResource' is returned
- *****************************************************************************/
-
- extern OSErr
- CMSWaitForSilence( short channelNum );
- /*
- * Wait for a sound channel to fall silent. This should not be called on
- * a sound channel that is playing music with a loop as it will never return.
- *
- * ON ENTRY: 'channelNum' is a positive number less than the number of
- * available sound channels [as passed to CMSInitSound()]
- * that is not playing music with a loop.
- * ON EXIT: The channel, 'channelNum' has fallen silent and is no longer
- * producing sound.
- * Any errors are returned.
- *****************************************************************************/
-
-
- /*--------------------------- SOUND DATA MANAGEMENT -------------------------*/
-
- extern OSErr
- CMSRegisterSound( SndListHandle theSound, short* refNum );
- /*
- * Registers a sound with the sound system for later playback.
- *
- * ON ENTRY: 'theSound' is a valid sound handle.
- * 'refNum' points to space to store a sound reference number.
- * ON EXIT: The sound handle 'theSound' has been registered with the
- * sound system. The sound may be played back at a later time
- * by calling CMSPlaySound() with the returned reference number.
- * Any errors are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSRemoveSound( short refNum );
- /*
- * Removes a previously registered sound from the sound system.
- *
- * ON ENTRY: 'refNum' is the reference number of a sound previously
- * registered with the sound system with either
- * CMSRegisterSound() or CMSLoadSound().
- * ON EXIT: The sound referenced by 'refNum' is removed from the sound
- * system and disposed of.
- * Any errors are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSLoadSound( short soundID, short* refNum );
- /*
- * Loads a sound from the current resource file and registers it with the
- * sound system.
- *
- * ON ENTRY: 'soundID' is the resource ID of a valid 'snd ' resource.
- * 'refNum' points to space to store a sound reference number.
- * ON EXIT: The sound resource ('snd ') number 'soundID' is loaded from
- * the current resource file and registered with the sound
- * system.
- * Any error codes are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSPlaySound( short refNum, short channelNum );
- /*
- * Plays a registered sound on a sound channel.
- *
- * ON ENTRY: 'refNum' is the reference number of a sound previously
- * registered with the sound system with either
- * CMSRegisterSound() or CMSLoadSound().
- * 'channelNum' is a positive number less than the number of
- * available sound channels [as passed to CMSInitSound()]
- * ON EXIT: The sound referenced by 'refNum' has begun playing on sound
- * channel, 'channelNum'.
- * Any error codes are returned.
- *****************************************************************************/
-
- extern OSErr
- CMSPlaySoundResource( short resID, short channelNum, Boolean async );
- /*
- * Plays a sound from a resource file. This function is meant to provide
- * the functionality of SndPlay() through the sound system.
- *
- * ON ENTRY: 'resID' is the number of a valid 'snd ' resrouce to play
- * 'channelNum' is a positive number less than the number of
- * available sound channels [as passed to CMSInitSound()]
- * 'async' is a boolean value indicating whether the sound should
- * be played asynchronosly or not.
- * ON EXIT: The sound resource has begun playing on channel, 'channelNum'.
- * If 'async' is false, then CMSPlaySoundResource() will not
- * return until the sound has finished playing in it's entirety.
- * Any error codes are returned.
- *****************************************************************************/
-
-
- /*----------------------------- MUSIC MANAGEMENT ----------------------------*/
-
- extern OSErr
- CMSLoadMusic( short musicID );
- /*
- * Loads the sounds and music sequence data as defined by the music list
- * resource 'musicID'. The music may then be played with a call to
- * CMSPlayMusic().
- *
- * ON ENTRY: 'musicID' is the number of a valid 'MUSL' resource to load.
- * ON EXIT: Loads the music described by the 'MUSL' resource, 'musicID'.
- * Each of the sounds listed in the play sequence is loaded and
- * registered with the sound system. The internal play sequence
- * is set up in preparation for playing music.
- *****************************************************************************/
-
- extern OSErr
- CMSRemoveMusic( void );
- /*
- * Removes the currently loaded piece of music from the sound system. Any
- * sounds associated with playing music are ungregistered and freed.
- *
- * ON ENTRY: The sound system has been initialized
- * ON EXIT: A piece of music previously loaded with CMSLoadMusic() is
- * removed from the system. Any sounds associated with the
- * music are removed from the system and freed. If no music
- * had been previously loaded, control is returned to the caller
- * immediately with no errors.
- *****************************************************************************/
-
- extern OSErr
- CMSPlayMusic( short channelNum );
- /*
- * Begins a piece of music previously loaded with CMSLoadMusic().
- *
- * ON ENTRY: 'channelNum' is a positive number less than the number of
- * available sound channels [as passed to CMSInitSound()]
- * ON EXIT: The music previously loaded has begun to play on sound channel
- * 'channelNum'. The music will continue until it reaches the
- * end of the piece (if there are no loops). Or until the sound
- * on the channel is silenced with a call to CMSStopSound().
- *****************************************************************************/
-
-
- /*----------------------------- UTILITY ROUTINES ----------------------------*/
-
- extern SoundHeaderPtr
- CMSGetSoundHeader( SndListHandle sndHandle );
- /*
- * Obtains a pointer to the sound header in the given sound resource. Because
- * a pointer into the handle is returned, the handle is locked and should not
- * be unlocked until the sound header is no longer needed. A pointer to a
- * sampled sound header is returned even if the sound header is actually an
- * extended sound header or a compressed sound header.
- *
- * ON ENTRY: 'sndHandle' is a valid sound handle.
- * ON EXIT: A pointer to a valid sound header in the sound 'sndHandle' is
- * returned. If there is not a sound header in the given resource,
- * then NULL is returned.
- *****************************************************************************/
-
- extern OSErr
- CMSGetSoundHeaderOffset( SndListHandle soundHandle, long* theOffset );
- /*
- * Traverses a sound resource until it reaches the sound data. It returns
- * the offset in bytes from the beginning of a sound resource to the sound
- * header.
- *
- * ON ENTRY: 'soundHandle' is a valid sound handle.
- * 'theOffset' points to a location to store the header offset.
- * ON EXIT: The offset in the sound handle 'soundHandle' is returned in
- * the space pointed to by 'theOffset'.
- * Any errors are returned.
- *****************************************************************************/
-
-
- /*----------------------------- INQUIRY ROUTINES ----------------------------*/
-
- extern Boolean
- CMSHasNewSoundManager( void );
- /*
- * Determines if the current sound manager is the "new" one. The "new"
- * Sound Manager contains the _SoundDispatch trap and is version 2.0 or
- * greater.
- *
- * ON ENTRY: no preconditions
- * ON EXIT: Returns true if the "new" sound manager is present on the
- * current machine.
- *****************************************************************************/
-
- extern Boolean
- CMSHasMultipleChannels( void );
- /*
- * Determines if the currently running sound manager is capable of supporting
- * multiple channels of sound.
- *
- * ON ENTRY: no preconditions
- * ON EXIT: Returns true if the currently running sound manager is capable
- * of supporting multiple channels of sound.
- *****************************************************************************/
-
- #endif /* __CMSOUNDSYSTEM__ */