The most ubiquitous architectures today consider a 'byte' to be an octet (eight bits) and a word to be a group of two, four or eight bytes (16,32 or 64 bits). Note however that the Vorbis bitpacking convention is still well defined for any native byte size; Vorbis uses the native bit-width of a given storage system. This document assumes that a byte is one octet for purposes of example.
The Vorbis bitpacking convention specifies storage and bitstream manipulation at the byte, not word, level, thus host word ordering is of a concern only during optimization when writing high performance code that operates on a word of storage at a time rather than by byte. Logically, bytes are always coded and decoded in order from byte zero through byte n.
The encoder logically packs integers by writing the LSb of an binary integer to the logical bitstream first, followed by next least significant bit, etc, until the requested number of bits have been coded. When packing the bits into bytes, the encoder begins by placing the LSb of the integer to be written into the least significant unused bit position of the destination byte, followed by the next-least significant bit of the source integer and so on up to the requested number of bits. When all bits of the destination byte have been filled, encoding continues by zeroing all bits of the next byte and writing the next bit into the bit position 0 of that byte. Decoding follows the same process as encoding, but by reading bits from the byte stream and reassembling them into integers.
| V 7 6 5 4 3 2 1 0 byte 0 [0 0 0 0 1 1 0 0] <- byte 1 [ ] byte 2 [ ] byte 3 [ ] ... byte n [ ] bytestream length == 1 byteContinue by coding the 3 bit integer value '-1' [b111]:
| V 7 6 5 4 3 2 1 0 byte 0 [0 1 1 1 1 1 0 0] <- byte 1 [ ] byte 2 [ ] byte 3 [ ] ... byte n [ ] bytestream length == 1 byteContinue by coding the 7 bit integer value '17' [b0010001]:
| V 7 6 5 4 3 2 1 0 byte 0 [1 1 1 1 1 1 0 0] byte 1 [0 0 0 0 1 0 0 0] <- byte 2 [ ] byte 3 [ ] ... byte n [ ] bytestream length == 2 bytes bit cursor == 6Continue by coding the 13 bit integer value '6969' [b110 11001110 01]:
| V 7 6 5 4 3 2 1 0 byte 0 [1 1 1 1 1 1 0 0] byte 1 [0 1 0 0 1 0 0 0] byte 2 [1 1 0 0 1 1 1 0] byte 3 [0 0 0 0 0 1 1 0] <- ... byte n [ ] bytestream length == 4 bytes
| V 7 6 5 4 3 2 1 0 byte 0 [1 1 1 1 1 1 0 0] <- byte 1 [0 1 0 0 1 0 0 0] byte 2 [1 1 0 0 1 1 1 0] byte 3 [0 0 0 0 0 1 1 0] bytestream length == 4 bytesWe read two, two-bit integer fields, resulting in the returned numbers 'b00' and 'b11'. Two things are worth noting here:
Unused space in the last byte of a bytestream is always zeroed during the coding process. Thus, should this unused space be read, it will return binary zeroes.
Attempting to read past the end of an encoded packet results in an 'end-of-packet' condition. End-of-packet is not to be considered an error; it is merely a state indicating that there is insufficient remaining data to fulfill the desired read size. Vorbis uses truncated packets as a normal mode of operation, and as such, decoders must handle reading past the end of a packet as a typical mode of operation. Any further read operations after an 'end-of-packet' condition shall also return 'end-of-packet'.
Ogg Vorbis is the first Ogg audio CODEC. Anyone may freely use and distribute the Ogg and Vorbis specification, whether in a private, public or corporate capacity. However, the Xiph.org Foundation and the Ogg project (xiph.org) reserve the right to set the Ogg Vorbis specification and certify specification compliance.
Xiph.org's Vorbis software CODEC implementation is distributed under a BSD-like license. This does not restrict third parties from distributing independent implementations of Vorbis software under other licenses.
Ogg, Vorbis, Xiph.org Foundation and their logos are trademarks (tm) of the Xiph.org Foundation. These pages are copyright (C) 1994-2002 Xiph.org Foundation. All rights reserved.