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