Playing Sampled Sounds From Files
There are three functions that you can use to initiate and control a continuous
suspend a sound from playing. If a sound is playing and you call
toggles the tape between playing and pa using. (You can determine the current
complete details ,Obtaining Information About a Single Sound
Channel under the section,
(either format 1 or format 2) or in files that conform to the AIFF or
AIFF-C format. In addition, you can specify whether the play from disk should
internally. However, since you must specify a sound-channel pointer when
asynchronously if you want to be able to pause or stop the sound prior to its
natural ending point.
Playing an 'snd ' Resource From Disk
To play a sampled sound that is contained in an 'snd ' resource, you need to
following code example illustrates how to play an 'snd ' resource
synchronously from disk.
0. That parameter is used only when playing files from disk.
// Playing an 'snd ' resource from disk
// Assuming inclusion of MacHeaders
#include
// constants used in routine
#define kTotalSize 16*1024
#define kAsync TRUE // play sound asynchronously
#define kQuietNow TRUE // quiet channel now
// Prototype routine like this prior to calling it
void SyncStartFilePlay( short);
void SyncStartFilePlay (short myResNum)
{
SndChannelPtr mySndChan;
// Prototype for error handling routine
// allocate a sound channel
mySndChan = nil;
myErr = SndNewChannel (& mySndChan, sampledSynth, initMono, nil); if ( myErr )
DoError( myErr);
// play the 'snd ' resource
nil, nil, !kAsync);
// if error occured handle it
if ( myErr )
DoError( myErr);
// dispose of the channel, if soundchannel was allocated
if ( mySndChan )
myErr = SndDisposeChannel( mySndChan, !kQuietNow);
// if error occured, handle it
if ( myErr )
DoError( myErr);
}
Playing a File From Disk
To play a sampled sound that is contained in a file, you need to pass
should be stored in either AIFF or AIFF-C format. If the sample is compressed,
then it will be automatically expanded during playback.
For example, to play a sampled sound that is found in a file whose file
reference number is stored in the variable my fRefNum, you could write
myErr = SndStartFilePlay ( mySndChan, my fRefNum, 0, kTotalSize, NULL, l
NULL,NULL, FALSE);
That parameter is used only when playing resources from disk.
Playing Selections
AudioSelection record, which allows you to specify that only part of the sound be played. If that parameter has a value different from NULL, then
indicate which part of the entire sound to play by giving two offsets from the
beginning of the sound, a time at which to start the selection and a time at
which to end the selection. Currently, both time offsets must be specified in
seconds.