[Vorbis-dev] Splitting Ogg Vorbis file

Conrad Parker conrad at metadecks.org
Sun Jun 28 15:21:25 PDT 2009


2009/6/29 Timur Elzhov <elzhov at gmail.com>:
> ogg.k & Conrad, thanks for yours reply.
>
> 2009/6/28 Conrad Parker <conrad at metadecks.org>:
>> My understanding is that for Vorbis, no data will be produced until
>> the third packet is received, so if you're missing the 2 previous
>> preroll packets then the output PCM stream will simply be shorter, ie.
>> missing the first 2 packets worth of audio (a few hundredths of a
>> second).
>
> Well, I tried to insert 2 logging lines in decoding_example.c from
> libvrbis examples, the first one is
>
>  fprintf(stderr, "decoding packet no %lld\n", op.packetno);
>
> as we got full data packet from the stream; and second
>
>  fprintf(stderr, "  and have %d samples\n", samples);
>
> after every call of "samples = vorbis_synthesis_pcmout(&vd, &pcm)".
> The log looks like:
>
> -----------------------------------------------------------
> Bitstream is 2 channel, 44100Hz
> Encoded by: Xiph.Org libVorbis I 20050304
>
> decoding packet no 3
>  and have 0 samples
> decoding packet no 4
>  and have 576 samples
>  and have 0 samples
> decoding packet no 5
>  and have 1024 samples
>  and have 0 samples
> decoding packet no 6
>  and have 1024 samples
>  and have 0 samples
> decoding packet no 7
>  and have 1024 samples
>  and have 0 samples
>  ...
> -----------------------------------------------------------
>
> I believe we start from 4th packet (no 3) because of three first are
> occupied by Vorbis headers, but from this log pcm samples (namely 576)
> seem to appear just *in* second data packet, not *after* them!

yes, you're right. I was wrong to say that "no data will be produced
until the third packet is received". Some data will be produced on
decode of the second packet.

> Next, I looked at the vcut.c, found there get_blocksize() function,
> and logged packet's blocksize too:
>
>  blocksize = 64
>  blocksize = 576
>  blocksize = 1024
>  blocksize = 1024
>  blocksize = 1024
>  ...
>
> the values are the same as in previous log, except that first data
> packet has size of 64 intead of expected 0. Is this allowed?
>
> I probably misunderstand something, but how should I interpret that
> packets begin to return decoded samples from second (not third)
> packet, and also two first packets *both* have non-zero blocksizes?

Look at the shape of the windows:

http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-260001.3.2

each sample is calculated using some data from the previous red
packet, and some from the current green packet. The contribution of
each varies across the duration of the packet.

Conrad.


More information about the Vorbis-dev mailing list