[Vorbis-dev] cheap way of getting number of frames in an ogg_page?

Sebastian Gesemann sgeseman
Mon Aug 2 07:37:20 PDT 2004


On Mon, 2 Aug 2004, Christoph Rupp wrote:

> Hi,
>
> i just wonder if there's a cheap way of getting the number of oggVorbis
> pcm frames in an ogg_page, without actually decoding it?
>
> Can i use the granulepos of the page, substract the granulepos of the
> previous page? is this always guaranteed to work?

Mostly, yes. This method will return the number of PCM frames you
would receive from the decoder for this page *IF* it already has
decoded the content of previous pages.

Since Vorbis uses a lapped transform and Vorbis packets can be
stored accross page boundaries you won't receive that many PCM
frames if you start decoding from that page.

Also, the granule pos of a page may be -1 (although less likely in
case of Vorbis). This means you won't receive any new PCM frames
for that page from the decoder because no packet finishes on that
page.
(Just substitute granule positions of -1 for with the granule
position of the previous pages)

(I assume by "PCM frame" you mean the PCM data you need to
represent 1/fs seconds of audio - 4 bytes for 16 bit stereo for
example)

> thanks,
> Chris

Ghis!
Sebastian

--
PGP-Key-ID (long): 572B1778A4CA0707



More information about the Vorbis-dev mailing list