Game Development Reference
In-Depth Information
The parameters
apBuffer
and
aBufferLength
provide the memory location where
the audio track resides and the length of audio data in bytes. The repeat count is
specified in the same manner as with
s3eAudioPlay
.
In most cases we will find that the first method is good enough since it is easy to
use and doesn't require us to allocate blocks of memory and fill it with data. You
may find that the buffer method provides slightly faster initial playback if you have
preloaded the audio data, but on most recent devices the difference is negligible.
If you make a call to either of these functions while an audio track is currently
playing, that track will be stopped and the new track will begin playing.
Pausing, resuming, and stopping playback
Once an audio track is playing, we can pause playback by calling the
s3eAudioPause
function. The audio can be started again from the point at which it was paused by
calling
s3eAudioResume
. Finally, to stop playback completely just call
s3eAudioStop
.
All three of these functions take no parameters and will return
S3E_RESULT_
SUCCESS
when no errors occur. An error is raised if any of these functions are
called when it makes no sense to do so, for example calling
s3eAudioPause
when there is no audio playing.
Changing volume
Like most of the low level APIs in Marmalade, s3eAudio features a pair of functions
called
s3eAudioGetInt
and
s3eAudioSetInt
that are used to change attributes
related to that API. In s3eAudio, one of the things we use these functions for is to
change the volume of audio playback.
To set the playback volume we can make the following call:
s3eAudioSetInt(S3E_AUDIO_VOLUME, S3E_AUDIO_MAX_VOLUME / 2);
In the aforementioned example we set the volume to half of
S3E_AUDIO_MAX_VOLUME
,
which is the maximum allowed volume.
To determine the current volume we use this code:
int32 lVolume = s3eAudioGetInt(S3E_AUDIO_VOLUME);
We can also request the default volume for audio by passing in the value
S3E_
AUDIO_VOLUME_DEFAULT
. This is the default volume level for playing audio and has
been chosen by the Marmalade SDK so as to provide a fairly consistent volume level
across all devices.
Search WWH ::
Custom Search