Game Development Reference
In-Depth Information
18. A small SetVolume() method changes the playback volume of the source. Accepted
loat values are in the range of 0.0…1.0 :
void SetVolume( float Volume )
{
alSourcef( FSourceID, AL_GAIN, Volume );
}
19. The main routine, which feeds the data to the audio source, is BindWaveform() .
This function stores a smart pointer to the data provider and generates an OpenAL
buffer object:
void BindWaveform( clPtr<iWaveDataProvider> Wave )
{
FWaveDataProvider = Wave;
if ( !Wave ) return;
alGenBuffers( 1, &FBufferID );
alBufferData( FBufferID,
Wave->GetALFormat(),
Wave->GetWaveData(),
(int)Wave->GetWaveDataSize(),
Wave->FSamplesPerSec );
alSourcei( FSourceID, AL_BUFFER, FBufferID );
}
20. The private section of the AudioSource class contains a reference to an audio
data provider and an internal OpenAL source and buffer handle:
private:
clPtr<iWaveDataProvider> FWaveDataProvider;
ALuint FSourceID;
ALuint FBufferID;
};
21. To be able to read the sound from the ile, we implement the iWaveDataProvider
interface in the WavProvider class:
class WavProvider: public iWaveDataProvider
22. The only ield this class contains is a smart pointer to a Blob object, containing the
ile data:
clPtr<Blob> FRawData;
23. A simple pulse-code modulated .wav ile consists of the sWAVHeader structure at
the beginning and the audio data, which can be directly fed into the OpenAL audio
source. The constructor of the WavProvider class extracts the information about
the audio data:
 
Search WWH ::




Custom Search