[vorbis-dev] packet rearranging questions
Michael Smith
msmith at xiph.org
Tue Oct 28 23:08:15 PST 2003
On Wednesday 29 October 2003 17:55, Joshua Haberman wrote:
> Thanks for the reply!
>
> On Tue, 2003-10-28 at 16:27, Michael Smith wrote:
> > On Tuesday 28 October 2003 18:49, Joshua Haberman wrote:
> > > 1. how exactly will the overlap/add nature of Vorbis packets affect me
> > > as I attempt to rearrange them? Is it correct to say that for any
> > > Vorbis packet I take from an existing stream (other than the first
> > > packet) I must also take the packet preceding it?
> >
> > Yes. The reason that the first packet is an exception here is that it
> > produces no output audio (because the overlap is _always_ required).
>
> Ahh, I see.
>
> > > 3. I notice that you can get decoders to discard some of the samples
> > > from the end of a packet by subtracting from the granulepos the number
> > > of samples you want discarded. A similar way to do this for discarding
> > > samples from the beginning of a packet (used by vcut) is to set the
> > > granulepos to -x, where x is the number of samples you want discarded
> > > from the beginning. But will this work in the middle of a stream,
> > > where the granulepos should reflect the total sample offset of the
> > > stream?
> >
> > No, a negative granulepos (other than -1) is undefined.
>
> Quoting from http://www.xiph.org/ogg/vorbis/doc/vorbis-ogg.html:
>
> "The granule (PCM) position of the first page need not indicate that the
> stream started at position zero. Although the granule position belongs
> to the last completed packet on the page and a valid granule position
> must be positive, by inference it may indicate that the PCM position of
> the beginning of audio is positive or negative.
Right. Note "a valid granule position must be positive", here. Remember, the
granulepos is of the last packet in the page - it essential says "after
decoding everything in this page, the final sample output will be number X".
So (using some made-up numbers, these can't actually occur due to window-size
power-of-two limitations), if you decode 1000 samples, but granulepos says
"800", this infers that the _start_ of the audio in this page is at -200.
This negative value is what is referred to in the paragraph below, and
indicates that the first 200 samples should be discarded.
>
> [...]
>
> "* A negative value indicates that output samples preceeding time zero
> should be discarded during decoding; this technique is used to allow
> sample-granularity editing of the stream start time of already-encoded
> Vorbis streams. The number of samples to be discarded must not exceed
> the overlap-add span of the first two audio packets."
>
> > This only works at the beginning and end of stream, never in the middle.
>
> Bummer. I suppose this will force me to create lots of logical
> bitstreams concatenated inside a physical bitstream to accomplish my
> goals.
>
Yes. The unfortunate downside... The alternative being some complex procedure
where you re-encode only those parts at the boundaries, and reassemble as a
complete single bitstream. Lossy and complex, though.
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Vorbis-dev
mailing list