Important: Inside Macintosh: Sound is deprecated as of Mac OS X v10.5. For new audio development in Mac OS X, use Core Audio. See the Audio page in the ADC Reference Library.
SndPlay
You can use theSndPlay
function to play a sound resource that your application has loaded into memory.
FUNCTION SndPlay (chan: SndChannelPtr; sndHdl: Handle; async: Boolean): OSErr;
chan
- A pointer to a valid sound channel. You can pass
NIL
instead of a pointer to a sound channel if you want the Sound Manager to internally allocate a sound channel in your application's heap zone.sndHdl
- A handle to the sound resource to play.
async
- A Boolean value that indicates whether the sound should be played asynchronously (
TRUE
) or synchronously (FALSE
). This parameter is ignored (and the sound plays synchronously) ifNIL
is passed in the first parameter.DESCRIPTION
TheSndPlay
function attempts to play the sound located atsndHdl
, which is expected to have the structure of a format 1 or format 2'snd '
resource. If the resource has not yet been loaded, theSndPlay
function fails and returns theresProblem
result code.All commands and data contained in the sound handle are then sent to the channel. Note that you can pass
SndPlay
a handle to some data created by calling the Sound Input Manager'sSndRecord
function as well as a handle to an actual'snd '
resource that you have loaded into memory.
The
- WARNING
- In some versions of system software prior to system software version 7.0, the
SndPlay
function will not work properly with sound resources that specify the sound data type twice. This might happen if a resource specifies that a sound consists of sampled-sound data and an application does the same when creating a sound channel. For more information on this problem, see "Allocating Sound Channels" on page 2-20.chan
parameter is a pointer to a sound channel. Ifchan
is notNIL
, it is used as a valid channel. Ifchan
isNIL
, an internally allocated sound channel is used. If you do supply a sound channel pointer in thechan
parameter, you can play the sound asynchronously. When a sound is played asynchronously, a callback procedure can be called when acallBackCmd
command is processed by the channel. (This procedure is the callback procedure supplied toSndNewChannel
.) See "Playing Sounds Asynchronously" on page 2-46 for more information on playing sounds asynchronously. The handle you pass in thesndHdl
parameter must be locked for as long as the sound is playing asynchronously.If a format 1
'snd '
resource does not specify which type of sound data is to be played,SndPlay
defaults to square-wave data.SndPlay
also supports format 2'snd '
resources using sampled-sound data and abufferCmd
command. Note that to useSndPlay
and sampled-sound data with a format 1'snd '
resource, the resource must include abufferCmd
command.SPECIAL CONSIDERATIONS
Because theSndPlay
function moves memory, you should not call it at interrupt time.RESULT CODES
SEE ALSO
For an example of how to play a sound resource using theSndPlay
function, see the chapter "Introduction to Sound on the Macintosh" in this book.For information on playing a sound resource without using the
SndPlay
function, see "Playing Sounds Using Low-Level Routines" on page 2-61.