Game Development Reference
In-Depth Information
std::vector< clAudioSource* > FActiveSources;
Mutex FMutex;
};
3.
The method clAudioThread::Run() gets more complicated. Besides the
initialization of OpenAL, it has to update active audio sources so they can pull the
audio data from their providers:
void clAudioThread::Run()
{
if ( !LoadAL() ) { return; }
FDevice = alcOpenDevice( NULL );
FContext = alcCreateContext( FDevice, NULL );
alcMakeContextCurrent( FContext );
FInitialized = true;
FPendingExit = false;
double Seconds = GetSeconds();
4.
The inner loop updates active audio sources based on the elapsed time:
while ( !IsPendingExit() )
{
float DeltaSeconds = static_cast<float>(
GetSeconds() - Seconds );
5.
Note the following scope for the mutex:
{
LMutex Lock(&FMutex );
for( auto i = FActiveSources.begin();
i != FActiveSources.end(); i++ )
{
( *i )->Update( DeltaSeconds );
}
}
Seconds = GetSeconds();
6.
Audio sources are updated every 100 milliseconds. This value is purely empirical
and is suitable for non-realtime audio playback as a tradeoff between the audio
subsystem lag and power consumption of your Android device:
Env_Sleep( 100 );
}
alcDestroyContext( FContext );
alcCloseDevice( FDevice );
UnloadAL();
}
 
Search WWH ::




Custom Search