Game Development Reference
In-Depth Information
Next we increment the generated sample counter while keeping it inside the 0…
FSignalFreq-1 range:
LastOffset += Size / 2;
LastOffset %= FSamplesPerSec;
At the end, the number of generated bytes is returned:
FBufferUsed = Size;
return FBufferUsed;
}
};
We can now use the AudioSource class to stream the sound. Once the audio source is
created, we attach a new streaming provider that generates a 440 Hz sine waveform:
class SoundThread: public iThread
{
virtual void Run()
{
while ( !g_Audio.Finitialized ) {}
clPtr<AudioSource> Src = new AudioSource();
Src->BindWaveform( new ToneGenerator() );
Src->Play();
FPendingExit = false;
double Seconds = Env_GetSeconds();
In the ininite loop, we constantly update the source, forcing it to generate sound data:
While ( !IsPendingExit() )
{
float DeltaSeconds =
(float)( Env_GetSeconds() - Seconds );
Src->Update( DeltaSeconds );
Seconds = Env_GetSeconds();
}
}
}
There's more…
It is easy to notice that in the ToneGenerator::StreamWaveData() member function,
we can use any formula, not just the sine function. We encourage the reader to experiment
and create some sort of software synthesizer.
 
Search WWH ::




Custom Search