Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 files. A PCM can be Mono (the same sound on all speakers) or Stereo (different sounds for left and right speakers if available).

PCM is not compressed and is not efficient in terms of storage (just compare a musical CD with a data CD full of MP3...