Game Development Reference
In-Depth Information
13. The constructor just creates an OpenAL source handle and sets the default
parameters:
AudioSource(): FWaveDataProvider( NULL )
{
alGenSources( 1, &FSourceID );
alSourcef( FSourceID, AL_GAIN, 1.0 );
alSourcei( FSourceID, AL_LOOPING, 0 );
}
14. The destructor stops the playback and performs the cleanup:
virtual ~AudioSource()
{
Stop();
FWaveDataProvider = NULL;
alDeleteSources( 1, &FSourceID );
alDeleteBuffers( 1, &FBufferID );
}
15. The Play() method switches the OpenAL source into the playing state:
void Play()
{
if ( IsPlaying() ) { return; }
alSourcePlay( FSourceID );
}
16. The Stop() method switches the OpenAL source into the stopped state. The
playback can be resumed after stop ping only from the beginning of the sound buffer:
void Stop()
{
alSourceStop( FSourceID );
}
17. The IsPlaying() method checks if the source is playing audio. The implementation
comes from the previous recipe:
bool IsPlaying() const
{
int State;
alGetSourcei( FSourceID, AL_SOURCE_STATE, &State );
return State == AL_PLAYING;
}
 
Search WWH ::




Custom Search