nuclear@1: /******************************************************************** nuclear@1: * * nuclear@1: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * nuclear@1: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * nuclear@1: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * nuclear@1: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * nuclear@1: * * nuclear@1: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * nuclear@1: * by the Xiph.Org Foundation http://www.xiph.org/ * nuclear@1: * * nuclear@1: ******************************************************************** nuclear@1: nuclear@1: function: basic shared codebook operations nuclear@1: last mod: $Id: codebook.h 17030 2010-03-25 06:52:55Z xiphmont $ nuclear@1: nuclear@1: ********************************************************************/ nuclear@1: nuclear@1: #ifndef _V_CODEBOOK_H_ nuclear@1: #define _V_CODEBOOK_H_ nuclear@1: nuclear@1: #include nuclear@1: nuclear@1: /* This structure encapsulates huffman and VQ style encoding books; it nuclear@1: doesn't do anything specific to either. nuclear@1: nuclear@1: valuelist/quantlist are nonNULL (and q_* significant) only if nuclear@1: there's entry->value mapping to be done. nuclear@1: nuclear@1: If encode-side mapping must be done (and thus the entry needs to be nuclear@1: hunted), the auxiliary encode pointer will point to a decision nuclear@1: tree. This is true of both VQ and huffman, but is mostly useful nuclear@1: with VQ. nuclear@1: nuclear@1: */ nuclear@1: nuclear@1: typedef struct static_codebook{ nuclear@1: long dim; /* codebook dimensions (elements per vector) */ nuclear@1: long entries; /* codebook entries */ nuclear@1: long *lengthlist; /* codeword lengths in bits */ nuclear@1: nuclear@1: /* mapping ***************************************************************/ nuclear@1: int maptype; /* 0=none nuclear@1: 1=implicitly populated values from map column nuclear@1: 2=listed arbitrary values */ nuclear@1: nuclear@1: /* The below does a linear, single monotonic sequence mapping. */ nuclear@1: long q_min; /* packed 32 bit float; quant value 0 maps to minval */ nuclear@1: long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */ nuclear@1: int q_quant; /* bits: 0 < quant <= 16 */ nuclear@1: int q_sequencep; /* bitflag */ nuclear@1: nuclear@1: long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map nuclear@1: map == 2: list of dim*entries quantized entry vals nuclear@1: */ nuclear@1: int allocedp; nuclear@1: } static_codebook; nuclear@1: nuclear@1: typedef struct codebook{ nuclear@1: long dim; /* codebook dimensions (elements per vector) */ nuclear@1: long entries; /* codebook entries */ nuclear@1: long used_entries; /* populated codebook entries */ nuclear@1: const static_codebook *c; nuclear@1: nuclear@1: /* for encode, the below are entry-ordered, fully populated */ nuclear@1: /* for decode, the below are ordered by bitreversed codeword and only nuclear@1: used entries are populated */ nuclear@1: float *valuelist; /* list of dim*entries actual entry values */ nuclear@1: ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */ nuclear@1: nuclear@1: int *dec_index; /* only used if sparseness collapsed */ nuclear@1: char *dec_codelengths; nuclear@1: ogg_uint32_t *dec_firsttable; nuclear@1: int dec_firsttablen; nuclear@1: int dec_maxlength; nuclear@1: nuclear@1: /* The current encoder uses only centered, integer-only lattice books. */ nuclear@1: int quantvals; nuclear@1: int minval; nuclear@1: int delta; nuclear@1: } codebook; nuclear@1: nuclear@1: extern void vorbis_staticbook_destroy(static_codebook *b); nuclear@1: extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source); nuclear@1: extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source); nuclear@1: extern void vorbis_book_clear(codebook *b); nuclear@1: nuclear@1: extern float *_book_unquantize(const static_codebook *b,int n,int *map); nuclear@1: extern float *_book_logdist(const static_codebook *b,float *vals); nuclear@1: extern float _float32_unpack(long val); nuclear@1: extern long _float32_pack(float val); nuclear@1: extern int _best(codebook *book, float *a, int step); nuclear@1: extern int _ilog(unsigned int v); nuclear@1: extern long _book_maptype1_quantvals(const static_codebook *b); nuclear@1: nuclear@1: extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul); nuclear@1: extern long vorbis_book_codeword(codebook *book,int entry); nuclear@1: extern long vorbis_book_codelen(codebook *book,int entry); nuclear@1: nuclear@1: nuclear@1: nuclear@1: extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b); nuclear@1: extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b); nuclear@1: nuclear@1: extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b); nuclear@1: nuclear@1: extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); nuclear@1: extern long vorbis_book_decodevs_add(codebook *book, float *a, nuclear@1: oggpack_buffer *b,int n); nuclear@1: extern long vorbis_book_decodev_set(codebook *book, float *a, nuclear@1: oggpack_buffer *b,int n); nuclear@1: extern long vorbis_book_decodev_add(codebook *book, float *a, nuclear@1: oggpack_buffer *b,int n); nuclear@1: extern long vorbis_book_decodevv_add(codebook *book, float **a, nuclear@1: long off,int ch, nuclear@1: oggpack_buffer *b,int n); nuclear@1: nuclear@1: nuclear@1: nuclear@1: #endif