Game Development Reference
In-Depth Information
See also
F
Chapter 2
,
Porting Common Libraries
F
The
Implementing portable memory-mapped iles
recipe in
Chapter 4
,
Organizing a
Virtual Filesystem
Abstracting basic audio components
In the previous recipe, we learned how to initialize OpenAL and how to play the uncompressed
.wav
iles. 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 audio context:
if ( !LoadAL() ) { return; }
FDevice = alcOpenDevice( NULL );
FContext = alcCreateContext( FDevice, NULL );
alcMakeContextCurrent( FContext );
3.
We set the lag that tells other threads if they can use our audio subsystem:
FInitialized = true;