oggs are too big to load at once, so i'm trying to get it to switch off buffers, i'm trying to get it to:
Load first buffer
load second buffer
start playing first buffer
//from here it loops
start playing second buffer, load next buffer into first buffer
start playing first buffer, load next buffer into second buffer, and repeat
well, it does that, but it still lurches when it switches buffers. i'm pretty sure its because of the way i check to see if a buffer is done playing, but i don't know any other way, as openAL doesn't have a GetPosition() like directsound buffers do. how do i get it to switch buffers just before the buffer runs out?
void XOgg::Update()
{
if(!MultiChunk)
return; //if its a one chunker
if(!Started)
return;
alGetSourcei(Source, AL_SOURCE_STATE, &BufferState);//check if the buffer finished playing
if(BufferState != AL_PLAYING) //if its not playing, we need to load the next chunk
{
if(Done)
{
if(Loop)
{
Done = false;
ov_pcm_seek(&vf, 0);
}
else
{
Started = false;
alSourceStop(Source);
ov_pcm_seek(&vf, 0);
return;
}
}
if(UseFirstBuffer)
alSourcei (Source, AL_BUFFER, MusBuffer1 );
else
alSourcei (Source, AL_BUFFER, MusBuffer2 );
alSourcePlay(Source);
LoadNextBuffer();
}
}
here is the load buffers function if it matters, togglebool just switches a bool's value.
void XOgg::LoadNextBuffer()
{
DWORD ReadPos = 0;
int p = 0;
if(UseFirstBuffer)
{
while(ReadPos < ChunkSize && Done == false)
{
p = ov_read(&vf, InBuffer + ReadPos, ChunkSize - ReadPos, 0, 2, 1, 0);
if(p == 0)
{
Done = true;
}
ReadPos += p;
}
alBufferData(MusBuffer2, AL_FORMAT_STEREO16, (ALvoid*)InBuffer, ReadPos, vi->rate); //fill the sound buffer with the temporary buffer
}
else
{
while(ReadPos < ChunkSize && Done == false)
{
p = ov_read(&vf, InBuffer + ReadPos, ChunkSize - ReadPos, 0, 2, 1, 0);
if(p == 0)
{
Done = true;
}
ReadPos += p;
}
alBufferData(MusBuffer1, AL_FORMAT_STEREO16, (ALvoid*)InBuffer, ReadPos, vi->rate); //fill the sound buffer with the temporary buffer
}
ToggleBool(UseFirstBuffer);
}
[edited by - billybob on December 28, 2002 4:12:52 PM]
[edited by - billybob on December 28, 2002 4:18:59 PM]