Game Development Reference
In-Depth Information
6.1 Foundations
Sound effects (or audio effects) are artificially created sounds that are used to express artistic
content of video games, animation or other media.
Android SoundPool is a collection of samples that can be loaded into memory from a re-
source inside the Android Application Package (APK). The SoundPool library uses the Me-
diaPlayer service to decode the audio into a raw 16-bit PCM mono or stereo stream. This
allows applications to ship with sounds without latency of decompressing during playback.
To utilize the Android SoundPool, the game logic should create a new SoundPool object
when the sounds are first loaded, and then its public methods below will be called during the
stream lifecycle (table 6.1):
Method
Description
load()
Iterates through the list of sounds to load streams. This is typically done
early in the process to allow time for decompressing the audio to raw PCM
format before they are needed for playback.
play()
Once the sounds are loaded and play has started, the application can trigger
sounds by calling play(). Playing streams can be paused or resumed, and
the application can also alter the pitch by adjusting the playback rate in
real-time.
pause()
Pauses the stream specified by the streamID, the value returned by the
play() method. If the stream is playing, it will be paused. If the stream is
not playing, calling this method will have no effect.
resume()
Resumes the stream specified by the streamID, the value returned by the
play() method. If the stream is paused, this will resume playback. If the
stream was not previously paused, calling this method will have no effect.
stop()
Stops the stream specified by the streamID, the value returned by the play()
method. If the stream is playing, it will be stopped. It also releases any nat-
ive resources associated with this stream. If the stream is not playing, it
will have no effect.
release()
Releases all the native resources in use and then set the SoundPool refer-
ence to null. If the player starts another level, a new SoundPool is created,
sounds are loaded, and play resumes.
Table 6.1 SoundPool's Public Methods
Search WWH ::




Custom Search