Playing sounds

The technique presented to play BGM from a MIME source is very practical but, sadly, not flexible enough. Recreating an AudioPlayer object is not necessary and accessing asset files each time is not good in terms of efficiency.

So, when it comes to playing sounds quickly in response to an event and generating them dynamically, we need to use a sound buffer queue. Each sound is preloaded or generated in a memory buffer, and placed into a queue when the playback is requested. No need to access a file at runtime!

A sound buffer, in the current OpenSL ES Android implementation, can contain PCM data. Pulse Code Modulation (PCM) is a data format dedicated to the representation of digital sounds. It is the format used in CD and in some Wave ...

Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.