[Openal-devel] NEWBIE: Playing OggVorbis files without queued buffers

Chris Robinson chris.kcat at gmail.com
Sat Mar 7 07:08:19 PST 2009


On Saturday 07 March 2009 6:42:32 am vexator wrote:
> The adjusted line is ulBufferSize *= 12. If I
> don't do this, only the first split second is being played.
>
> ulBufferSize *= 12; // <- why do I have to do this?!

Likely because you're only specifying a buffer size that's originally 1/4th of 
a second. ulFrequency is the number of sample frames per second (say, 44100). 
For mono16, you divide this by 2 (giving a 22050 buffer size). Mono16 data 
needs 2 bytes per sample frame (so one second would be 44100*2, or 88200, 
bytes per second). Thus: 22050/88200 = 0.25, or 1/4th of a second.

The ulBufferSize *= 12 then increases that, to 12 * 0.25 (or 12 / 4) = 3 
seconds.

Likely what you'll want to do is allocate a couple seconds to start with, then 
every time the buffer fills up, realloc and double it's size (eg. start with 2 
seconds, then expand to 4, 8, 16, 32..). When the Vorbis file ends, realloc 
once more to the amount of data actually filled, so unused buffer space isn't 
left over.

Hope that helps :)
- Chris


More information about the Openal-devel mailing list