[Vorbis-dev] Total uncompressed size

Michael Smith msmith at xiph.org
Fri Sep 2 15:04:02 PDT 2005

On 9/1/05, Tony O'Bryan <TO'Bryan at greenecountymo.org> wrote:
> On Thursday 01 September 2005 11:17 am, Christopher Egner wrote:
> > ...if you're trying to compute how much space you need to store a wave
> > or something similar, you almost always need a header.
> >
> > Christopher
> That was my intent.  The sound system for my game engine is using Vorbis for
> the music, loaded from a zip file ala Q3A, and I need to determine how much
> memory to allocate for the uncompressed file.
> I'm going to try using the header+granulepos approach.  It just means I'll
> have to make two passes through the file: one quick read through the pages to
> calculate the total size, then a second pass to decode it into memory.

Have you considered using libvorbisfile? It has all the logic you need
to do this, and is very easy to use - after calling ov_open() (or in
your case, presumably ov_open_callbacks()), you just need to call
ov_pcm_total(), then multiply by number of channels and number of
bytes per sample (2, if you're doing 16 bit output).

The only complicating factor is that to do this, libvorbisfile
requires random access to the stream, so you'll need to implement seek
callbacks. In turn, this basically means you need to unzip that entire
ogg into a memory buffer and implement callbacks (which are very
simple) to read/seek from the buffer. That's fine, so long as the
extra memory overhead of temporarily having the entire compressed ogg
(as well as the decompressed pcm) in memory at the same time isn't an


More information about the Vorbis-dev mailing list