🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

ogg 'lurching' problem

Started by
18 comments, last by billybob 21 years, 6 months ago
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]
Advertisement
To stream audio with OpenAL you queue multiple buffers to a single source. When only a certain number of buffers are left queued, you load more data and queue it too.

I have some code that I wrote that plays an Ogg Vorbis file with OpenAL, if you''d like me to upload it somewhere.

quote: Original post by Null and Void
To stream audio with OpenAL you queue multiple buffers to a single source. When only a certain number of buffers are left queued, you load more data and queue it too.

I have some code that I wrote that plays an Ogg Vorbis file with OpenAL, if you'd like me to upload it somewhere.



that'd be awsome, could you do that? but now that you remind me i'm pretty sure i know how.

[edited by - billybob on December 28, 2002 4:29:04 PM]
well, i got it working with queues, thanks.
The source is pulled out of my engine. It''s pretty easy to read (in my opinion, at least), since OpenAL is one of the few libraries I don''t really abstract away in my engine.

There are lots of little things that are from code that''s not included (gNewStack/gDelStack, gError, gThread), but I''d guess that they''re pretty easy to figure out the purpose of.

Anyway, here''s the link: http://omapi.sourceforge.net/gtw/gtw_as.tar.gz

err, wait, should you load all the buffers and queue them all, or load them two at a time and queue them as needed? it seems it''d take quite a bit of memory if you loaded them all at once.
Load them as needed. Make sure to keep at least one extra buffer queued after the one that is playing (until you run out of data, at least).

won't this cause hiccups every time it loads a buffer? also, queuing one buffer ADDS it to the queue, not replaces it right?

[edited by - billybob on December 28, 2002 5:12:27 PM]
quote: Original post by billybob
won''t this cause hiccups every time it loads a buffer?

Yes. You try to make the size of each buffer small enough where it won''t cause much of one, but still large enough where sound quality isn''t taking a hit (from constant buffer changes, although I only noticed this problem in the Windows/DirectSound builds of OpenAL).
quote: Original post by billybob
also, queuing one buffer ADDS it to the queue, not replaces it right?

Yeah.

grr, it plays the whole song, except that it plays every buffer about 5 times each. its like its queueing every buffer 5 times, but i can't figure out why.

another thing, how did you handle figuring out when to load a new buffer? right now i'm using

if(the buffer isn't playing)
load a new buffer and play it

but i suspect thats the problem

[edited by - billybob on December 28, 2002 5:26:47 PM]

This topic is closed to new replies.

Advertisement