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