Game Development Reference
In-Depth Information
9.
In the Update() method, we use the StreamBuffer() member function, which
does the job of illing the buffer with decoded or generated data from the provider:
int StreamBuffer( unsigned int BufferID, int Size )
{
int ActualSize =
FWaveDataProvider->StreamWaveData(Size);
ubyte* Data = FWaveDataProvider->GetWaveData();
int Sz = (int)FWaveDataProvider->GetWaveDataSize();
alBufferData( BufferID,
FWaveDataProvider->GetALFormat(),
Data, Sz,
FWaveDataProvider->FSamplesPerSec );
return ActualSize;
}
10. The BUFFER_SIZE constant is set to be big enough to hold the data for a couple of
seconds of streamed data:
const int BUFFER_SIZE = 352800;
The value 352800 is derived as follows:
2 channels × 44,100 samples per second × 2 bytes per sample × 2
seconds = 352,800 bytes .
How it works…
The code in this recipe does not implement the StreamWaveData() method. To hear
something from the speakers, we write the ToneGenerator class, which generates a pure
sine wave as the output data. This class is derived from StreamingWaveDataProvider :
class ToneGenerator : public StreamingWaveDataProvider
{
The parameters of the signal and an internal sample counter are declared irst:
int FSignalFreq;
float FFrequency;
float FAmplitude;
private:
int LastOffset;
 
Search WWH ::




Custom Search