Now that we can play short audio samples, it is time to organize our audio system into classes and take a closer look at the 2_Streaming
example. Long audio samples, such as background music, require a lot of memory in a decompressed form. Streaming is a technique to decompress them in small chunks, piece by piece. The clAudioThread
class manages the initialization and does everything from the previous sample except playing the sound:
class clAudioThread: public iThread { public: clAudioThread() : FDevice( nullptr ) , FContext( nullptr ) , FInitialized( false ) {} virtual void Run() { if ( !LoadAL() ) { return; } FDevice = alcOpenDevice( nullptr ); FContext = alcCreateContext( FDevice, nullptr ); alcMakeContextCurrent( FContext ); FInitialized = true; while ( !IsPendingExit() ) { Env_Sleep( 100 ); } alcDestroyContext( FContext ); alcCloseDevice( FDevice ); UnloadAL(); }