O'Reilly logo

Android NDK Game Development Cookbook by Viktor Latypov, Sergey Kosarevsky

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

Abstracting basic audio components

In the previous recipe, we learned how to initialize OpenAL and how to play the uncompressed .wav files. Here, we present the AudioSource and AudioThread classes which help us to manage the initialization process.

Getting ready

Check out the example 0_AL_On_Android in the supplementary materials to understand the basic concepts of OpenAL.

How to do it…

  1. Let's carefully move the initialization of OpenAL to another thread called AudioThread:
    class AudioThread: public iThread
    {
    public:
      AudioThread():
        FDevice( NULL ),
        FContext( NULL ),
        FInitialized( false ) {}
      virtual ~AudioThread() {}
    
      virtual void Run()
      {
  2. The code at the beginning of the Run() method performs the initialization of a default OpenAL device and creates an ...

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