Game Development Reference
In-Depth Information
In the following sections we'll look at how to make use of all three of these APIs and
will also take a look at another module called SoundEngine , that makes using the
s3eSound API a bit easier.
The s3eAudio API
Let's start with the quickest and easiest way of allowing our games to stop being the
strong, silent type.
The s3eAudio API allows us to play compressed music formats such as MP3 and
AAC. Some devices may also allow us to play other formats, such as MIDI files.
Marmalade makes use of whichever audio codecs a particular device may have
built-in rather than decoding the audio itself, so be sure to check that your chosen
audio format is supported by all the devices you wish to target.
Due to its ubiquity, it is recommended that you use MP3 as your
format of choice. There are very few devices (if any) that can't
play an MP3 file and the format itself allows you a wide variety of
bit rates so you can trade-off between audio quality and file size.
Let's now take a look at how we can get an audio track playing and what other
functionality the s3eAudio API provides for us. There is nothing we need to add to
our MKB file in order to allow us to use s3eAudio, as it is one of the low level APIs
of Marmalade that is always available for use. All we need to do is include the
header file s3eAudio.h in any source file that needs access to s3eAudio functions.
Starting audio playback
There are two ways of starting the playback of an audio track. The first allows us to
specify the filename of the audio track we want to play and the number of times we
would like the track to repeat, and looks like this:
s3eAudioPlay("music.mp3", aRepeatCount);
The filename is just a standard C, null-terminated string and is relative to the data
directory when run from Windows or the application install directory on the device.
Specifying a number for the repeat count will cause the audio track to play that many
times, while setting it to zero will cause the track to loop continuously.
The other method is to play the audio track from an area of memory as follows:
s3eAudioPlayFromBuffer(apBuffer, aBufferLength, aRepeatCount);
 
Search WWH ::




Custom Search