O'Reilly logo

Android NDK Beginner's Guide by Sylvain Ratabouil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – creating and playing a sound buffer queue

First, let’s create a new object to hold sound buffers:

  1. In jni/Sound.hpp, create a new class Sound to manage a sound buffer. It features a method load() to load a PCM file and unload() to release it:
    #ifndef _PACKT_SOUND_HPP_
    #define _PACKT_SOUND_HPP_
    
    class SoundService;
    
    #include "Context.hpp"
    #include "Resource.hpp"
    #include "Types.hpp"
    
    namespace packt {
        class Sound {
        public:
            Sound(android_app* pApplication, const char* pPath);
    
            const char* getPath();
    
            status load();
            status unload();
    
        private:
            friend class SoundService;
    
        private:
            Resource mResource;
            uint8_t* mBuffer; off_t mLength;
        };
    }
    #endif
  2. Sound loading implementation is quite simple: it creates a buffer with the same size as the PCM file ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required