[Speex-dev] Ogg embedding, problem with spec and/or bugs in speexenc

Ralph Giles giles at xiph.org
Sat Jul 15 14:35:05 PDT 2006

On Sat, Jul 15, 2006 at 02:17:22PM -0500, Joe Wreschnig wrote:

> I'm working on support for tagging Speex files for Mutagen[0] and part
> of the specification at [1] is confusing me. It says the first page
> should have granulepos 0 and packetno 0. Does this really mean page
> sequence number 0, since the Ogg format doesn't number packets?

Sounds like a spec bug. The libogg reference implementation always 
flushes a page after the zeroth packet, so packetno=0 is effectively
page sequence no zero. But as you say, packetno doesn't exist in the 
bitstream, and page number does, so this is what the spec should

> It says the comment packet should have granulepos 0. However, when I
> force a multipage comment packet, all but the last page have granulepos
> -1. Regardless of the above, I believe this is a speexenc bug. Either it
> should mark all these pages 0, or only allow one page.

A granulepos of -1 means 'no value'. Since you're splitting a single 
comment packet over multiple pages, only the final page can be marked
with a valid granulepos. The others get -1 since no packet ends there.

On a related note:

The granulepos field is only stored on a per-page basis, and corresponds 
to the granulepos of the last packet to finish on that page. So while 
the encoder fills out all the ogg_packet structures it generates, most 
of these are discarded when they are packed into ogg pages. When the
packets are later unpacked from the stream, libogg doesn't attempt to 
reconstruct the granulepos (this requires codec-specific knowledge) so
only packets which happen to be the last to finish on a page will be 
marked with a granulepos; all other packets will have -1; it's up to
the layer of software above libogg to reconstruct them if necessary.


More information about the Speex-dev mailing list