Time for action – creating and playing a sound buffer queue
Let's use OpenSL ES to play an explosion sound stored in a memory buffer:
- Update
jni/Resource.hpp
again to add a new methodgetLength()
, which provides the size in bytes of anasset
file:... class Resource { public: ... ResourceDescriptor descriptor(); off_t getLength(); ... }; #endif
- Implement this method in
jni/Resource.cpp
:... off_t Resource::getLength() { return AAsset_getLength(mAsset); } ...
- Create
jni/Sound.hpp
to manage a sound buffer.Define a method
load()
to load a PCM file andunload()
to release it.Also, define the appropriate getters. Hold the raw sound data in a buffer along with its size. The sound is loaded from a
Resource
:#ifndef _PACKT_SOUND_HPP_ #define _PACKT_SOUND_HPP_ ...
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.