Advertisement

OpenAL streaming buffer size

Started by July 17, 2004 05:54 AM
0 comments, last by Fingers_ 20 years, 4 months ago
I am currently making an OpenAL + OggVorbis streaming sound and am having some problems with the buffer size. I made a DirectSound + OggVorbis streaming sound before and buffer size never become a problem but it does in OpenAL. If I put less than 128kb, and once there is just a little disk activity, the streaming would stop. It seems OpenAL would unqueue the buffers when no sound is played. So I have to make the buffer size big enough that things such as disk activities would not cause the streaming to stop. However, how big is big? On my computer, it might be 128kb, but on other's computer, that might be some other number. If I allocate some big number, say, 1MB, I think it's way too big for a buffer size. Even 128kb I think is big enough already. Or maybe you have other solutions? Currently, this is how I do the streaming:

On Play:
   stream both buffers
   queue buffers and attach to source
   play source

On Update:
   check if there is any processed buffers
   for each processed buffer
      unqueue
      stream buffer
      re-queue
   next buffer
and basically that's how it's done.

StreamingSound ss1;
ss1.load( "c:\\song.ogg" );
ss1.play();

// main loop
...
ss1.update();
...

OpenAL sources will stop playing if they run out of queued buffers. You just need to check for this and restart the source if it happens. Basically, when you're checking the number of buffers queued (to find out if you need to load more), if it's zero you will need to call alSourcePlay after adding the new chunk into the queue. So under "re-queue" you'd add a conditional "play source".

You'll still get a "hitch" but that's going to happen with any streaming audio when it stalls. That said, 128K should be big enough to avoid this most of the time. (I'm actually using 32K and it rarely hitches)

This topic is closed to new replies.

Advertisement