/******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015 * * by the Xiph.Org Foundation https://xiph.org/ * * * ******************************************************************** function: basic codebook pack/unpack/code/decode operations ********************************************************************/ #include <stdlib.h> #include <string.h> #include <math.h> #include <ogg/ogg.h> #include "vorbis/codec.h" #include "codebook.h" #include "scales.h" #include "misc.h" #include "os.h" /* packs the given codebook into the bitstream **************************/ int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){ … } /* unpacks a codebook from the packet buffer into the codebook struct, readies the codebook auxiliary structures for decode *************/ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ … } /* returns the number of bits ************************************************/ int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){ … } /* the 'eliminate the decode tree' optimization actually requires the codewords to be MSb first, not LSb. This is an annoying inelegancy (and one of the first places where carefully thought out design turned out to be wrong; Vorbis II and future Ogg codecs should go to an MSb bitpacker), but not actually the huge hit it appears to be. The first-stage decode table catches most words so that bitreverse is not in the main execution path. */ static ogg_uint32_t bitreverse(ogg_uint32_t x){ … } STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){ … } /* Decode side is specced and easier, because we don't need to find matches using different criteria; we simply read and map. There are two things we need to do 'depending': We may need to support interleave. We don't really, but it's convenient to do it here rather than rebuild the vector later. Cascades may be additive or multiplicitive; this is not inherent in the codebook, but set in the code using the codebook. Like interleaving, it's easiest to do it here. addmul==0 -> declarative (set the value) addmul==1 -> additive addmul==2 -> multiplicitive */ /* returns the [original, not compacted] entry number or -1 on eof *********/ long vorbis_book_decode(codebook *book, oggpack_buffer *b){ … } /* returns 0 on OK or -1 on eof *************************************/ /* decode vector / dim granularity gaurding is done in the upper layer */ long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){ … } /* decode vector / dim granularity gaurding is done in the upper layer */ long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){ … } /* unlike the others, we guard against n not being an integer number of <dim> internally rather than in the upper layer (called only by floor0) */ long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){ … } long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch, oggpack_buffer *b,int n){ … }