Comp.Sys.Mac.Game.Programming.Book
Chapter 6: Sounding Off! (Creating sound nuggets)


Introduction to the Sound Manager

Sound is important to any game (unless of course your playing the game at work) and games just don't feel complete unless they squak or blurt out some kind of noise during game play. Fortunatly it is very easy to get the Mac to make noise.

Ever since day one of the Mac, it had a way to produce sound. The first macs could even talk! The Mac's sound software component is called the Sound Manager. It is in its 3rd major release and is capable of multichannel 16 bit stereo sound. Since you go through the Sound Manager, you never have to worry what type of sound card the user has since the Sound Manager takes care of the gory details for you.

Now before I go any further I want to say that there are a few quirks with the Sound Manager (tradeoffs made for performance reasons) that favors using certain sound types over others. We will go into detail on what's the best way to go. Also QuickTime has a new component called Quicktime Music Architecture that allows you store you music as MIDI like data and play it during your game. If you don't want to require Quicktime to use your game there is a third party library that gives you the same functionality. Below is an example of how to load a sound and to play the sound once its loaded.


#define kSync false
#define kAsync true

// Play sound  simple routine to play a sound.
//-------------------------------------------------------------------------
   void PlaySound(short id)
//-------------------------------------------------------------------------
{
    short oe; 
    Handle soundHandle;
	
    soundHandle = GetResource("snd ",id);    //load a sound from the resource file
    if (soundHandle) {                       // if sound was loaded
        oe = SndPlay(nil,soundHandle,kSync); // play the sound 
    }
}

The UMPG has an Artcile written by Larry Rosenstein on how to do Asynchronous sound routines. Click here to check it out.


Back to the Table of Contents