Improving the audio playback mechanism
In the previous chapters we learned how to play audio using OpenAL on Android. Our basic audio subsystem implementation in Chapter 5, Cross-platform Audio Streaming, lacked automatic management of audio sources; we had to control them manually on a separate thread. Now, we will put all of that code into a new audio subsystem usable in a real game.
Getting ready
The complete source code for this recipe is integrated in the example 1_Game
and can be found in the files sound/Audio.h
and sound/Audio.cpp
. Other files in the sound
folder provide decoding capabilities for different audio formats—check them out.
How to do it…
We need our
clAudioThread
class to take care of active audio sources. Let's extend it with methods responsible for their registration:class clAudioThread: public iThread { public: … void RegisterSource( clAudioSource* Src ); void UnRegisterSource( clAudioSource* Src );
We also need a container for active sources as well as mutex to control...