Game Development Reference
In-Depth Information
29. Prevent the position from outrunning the end of stream:
if ( OGG->FOGGRawPosition > (ogg_int64_t)DataSize )
{
OGG->FOGGRawPosition = (ogg_int64_t)DataSize;
}
return static_cast<int>( OGG->FOGGRawPosition );
}
30. Since we use the memory block as a data source, the OGG_CloseFunc()
function returns zero immediately because we don't need to close any handles:
int OGG_CloseFunc( void* DataSource ) { return 0; }
31. The OGG_TellFunc() function returns the current read position:
long OGG_TellFunc( void* DataSource )
{
return (int)
(((OggProvider*)DataSource)->FOGGRawPosition);
}
How it works…
We initialize the OpenAL as in the previous recipes and bind OggProvider as a data source
for the AudioSource instance:
clPtr<AudioSource> Src = new AudioSource();
clPtr<Data> = LoadFileAsBlob( "test.ogg" );
Src->BindWaveform( new OggProvider(Data) );
Src->Play();
FPendingExit = false;
double Seconds = Env_GetSeconds();
Update the audio source in a loop, just as we do with ToneGenerator :
While ( !IsPendingExit() )
{
float DeltaSeconds =
(float)(Env_GetSeconds() - Seconds );
Src->Update(DeltaSeconds);
Seconds = Env_GetSeconds();
}
The LoadFileAsBlob() function is the same as the one we used to load .wav iles.
 
Search WWH ::




Custom Search