Game Development Reference
In-Depth Information
Assuming a channel is available we must set up the playback rate of our sample
data, which is done like this:
s3eSoundChannelSetInt(lChannel, S3E_CHANNEL_RATE, lFrequency);
The first parameter is the sound channel ID we just allocated. The second parameter
indicates that we want to set the playback rate for that channel, and the third
parameter is the actual desired playback rate in Hertz (Hz). The maximum frequency
that can be set is specified by the define S3E_SOUND_MAX_FREQ .
We should also set the volume that we want the sound to be played at, which is also
done using the s3eSoundChannelSetInt function:
s3eSoundChannelSetInt(lChannel, S3E_CHANNEL_VOLUME, lVolume);
The valid values for the lVolume parameter are from 0 to the define S3E_SOUND_
MAX_VOLUME .
It is possible to change the volume and playback rate at any time once
the sound has started playing. This makes it possible to implement
effects such as volume fades or pitch shifts.
Now we can start playing our sound sample. We do this with the following call:
s3eSoundChannelPlay(lChannel, lSampleData, lNumSamples, lRepeatCount,
lLoopIndex);
Unsurprisingly, we first pass in the channel ID we are using, followed by the address
in memory where the 16-bit PCM sample data can be found in the lSampleData
parameter. The lNumSamples parameter is the number of actual sound samples in
our waveform (not the number of bytes), and lRepeatCount indicates how often
we want the sound to repeat. A value of 0 will play the sound forever. Finally the
lLoopIndex parameter allows us to specify which sample to start at if the sound
repeats. This makes it possible to use sounds that only need to repeat a portion of
the sample data.
Pausing, resuming, and stopping playback
Once a sound channel has started playing a sound sample, we might want to
temporarily suspend its playback or stop it entirely. To pause a sound channel we
use the function s3eSoundChannelPause , and we can start playing it again from the
paused position using s3eSoundChannelResume . To stop a sound channel entirely
we call s3eSoundChannelStop . Each of these functions takes a single parameter,
which is the channel ID we want to affect.
 
Search WWH ::




Custom Search