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…
- 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() {
- The code at the beginning of the
Run()
method performs the initialization of a default OpenAL device and creates an audio context:if ( !LoadAL() ) { return; } FDevice = alcOpenDevice( NULL ); FContext = alcCreateContext( FDevice, NULL ); alcMakeContextCurrent( FContext );
- We set the flag that tells other threads...