[vorbis] developing with libvorbis
Michael Smith
msmith at labyrinth.net.au
Wed Mar 26 18:21:15 PST 2003
> except i get decodes that can go like this
>
> 2304
> 4096
>
> Now there is no easy way to handle something like that. Suppose the
> smallest data i can write to the soundcard is 2048bytes. Vorbis is
> giving me stuff that's like 512, 1024 ...and sometimes 2304 and 4096.
> If i dont use all of what it decodes because say it gives me 2304 and
> then 4096, how can i tell it that i didn't read all it's packets and
> that it should start where i left off on it's next cycle of decoding? I
> dont think it's a matter of saying to only seek X amount in the file
> since we're talking about decoded data and there's no easy way to figure
> out where exactly in the file I left off at decoding. I dont think it's
> possible to leave an offset from a decode.
<p>libvorbis will not buffer more than one packet in the output layer - so you
can't say "decode to 4096 bytes, never more or less", but it will buffer
partial decoded packets, so you CAN (and should) say "decode a packet, and try
to fill this buffer, but do not overflow it" - the remaining partial packet
will still be kept in internal buffers, and will be returned on the next read.
So, assuming a 2048 byte buffer (as you say above), your reads will be as follows:
Request 2048 bytes: fills buffer, you process this (send to card, whatever)
Request 2048 bytes: only 256 samples (2304-2048) are returned, buffer is not
full (1792 bytes remain).
Request 1792 bytes: libvorbis decodes next packet (giving 4096 bytes in your
example), fills buffer with 1792 of these bytes. Remaining 2304 bytes are in
an internal buffer. Your buffer is now full, you send it to the soundcard.
Request 2048 bytes: 2048 bytes from internal buffer are returned, external
buffer is sent to soundcard.
Request 2048 bytes: remaining 256 bytes are placed in buffer, next call will
go to the next packet, whatever size that might be.
This is _very_ simple - implementing it is trivial using the API provided.
By the way, you should almost certainly (there are exceptions, but they're for
fairly uncommon circumstances) be using libvorbisfile, not directly using
libvorbis. The API there is higher-level and more convenient for most
purposes. Reads act the same as in libvorbis in this respect, though - it'll
decode one packet at a time, so this advice applies there as well.
libvorbisfile also has better and more complete documentation, since it's the
normal interface for application developers.
<p>Mike
--- >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-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
mailing list