Game Development Reference
In-Depth Information
The following code example puts the functionality described previosuly into practice:
// Simple structure used to indicate the next sound sample to play
typedef struct
{
void* mSampleData;
uint32 mSampleCount;
} NewSoundData;
// Sample callback function that will start a new sound effect
// playing if one has been specified when registering the
// callback function
int32 SoundEndCallback(s3eSoundEndSampleInfo* apInfo,
NewSoundData* apSound)
{
if (apSound)
{
apInfo->m_NewData = apSound->mSampleData;
apInfo->m_NumSamples = apSound->mSampleCount;
apInfo->m_RepsRemaining = 1;
}
return apInfo->m_RepsRemaining;
}
// Register the callback function to play a new sound when
// current sound completes
s3eSoundChannelRegister(lChannel, S3E_CHANNEL_END_SAMPLE,
(s3eCallback) SoundEndCallback,
&lNewSoundDataInstance);
The second callback type we'll consider is S3E_CHANNEL_STOP_AUDIO . This callback
will occur whenever a sound channel finishes playing a sound completely (for
example, if we have an S3E_CHANNEL_END_SAMPLE callback set and we return zero
from it to end all playback). It is passed a pointer to an s3eSoundEndSampleInfo
structure, but the only valid field is the m_Channel member.
The SoundEngine module
As the previous section of this chapter shows, the basics of using s3eSound are
actually fairly straightforward. The main issue that we have to deal with as
developers is the fact that s3eSound can only support raw uncompressed 16-bit
PCM samples, which means it is our responsibility to get the sound data into
memory so it can be played.
 
Search WWH ::




Custom Search