Skip to Main Content
Android NDK Beginner`s Guide - Second Edition
book

Android NDK Beginner`s Guide - Second Edition

by Sylvain Ratabouil
April 2015
Beginner to intermediate content levelBeginner to intermediate
494 pages
10h 26m
English
Packt Publishing
Content preview from Android NDK Beginner`s Guide - Second Edition

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:

  1. Update jni/Resource.hpp again to add a new method getLength(), which provides the size in bytes of an asset file:
    ...
    class Resource {
    public:
        ...
    
        ResourceDescriptor descriptor();
        off_t getLength();
        ...
    };
    
    #endif
  2. Implement this method in jni/Resource.cpp:
    ...
    off_t Resource::getLength() {
        return AAsset_getLength(mAsset);
    }
    ...
  3. Create jni/Sound.hpp to manage a sound buffer.

    Define a method load() to load a PCM file and unload() 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_ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro Android C++ with the NDK

Pro Android C++ with the NDK

Onur Cinar
Learning Embedded Android N Programming

Learning Embedded Android N Programming

Ivan Morgillo, Stefano Viola

Publisher Resources

ISBN: 9781783989645Supplemental Content