« Return to Thread: NEWBIE: Playing OggVorbis files without queued buffers

Re: NEWBIE: Playing OggVorbis files without queued buffers

by vexator :: Rate this Message:

Reply to Author | View in Thread

Bugzilla from chris.kcat@gmail.com wrote:
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
Ah, so the size of the buffer was hard-coded in the sample. I didn't realize. But isn't there a simpler way to find out how big the buffer has to be? Can I, from the data provided by the OggVorbis lib, calculate the exact length of the file and from that the needed buffer size? I'm new to audio programming, so I'm not sure how to do it.

Anyway, thank you very much!

 « Return to Thread: NEWBIE: Playing OggVorbis files without queued buffers