1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
6 * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and the XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: basic shared codebook operations
15 last mod: $Id: codebook.h,v 1.3 2000/11/08 06:08:11 xiphmont Exp $
17 ********************************************************************/
19 #ifndef _V_CODEBOOK_H_
20 #define _V_CODEBOOK_H_
24 /* This structure encapsulates huffman and VQ style encoding books; it
25 doesn't do anything specific to either.
27 valuelist/quantlist are nonNULL (and q_* significant) only if
28 there's entry->value mapping to be done.
30 If encode-side mapping must be done (and thus the entry needs to be
31 hunted), the auxiliary encode pointer will point to a decision
32 tree. This is true of both VQ and huffman, but is mostly useful
37 typedef struct static_codebook{
38 long dim; /* codebook dimensions (elements per vector) */
39 long entries; /* codebook entries */
40 long *lengthlist; /* codeword lengths in bits */
42 /* mapping ***************************************************************/
43 int maptype; /* 0=none
44 1=implicitly populated values from map column
45 2=listed arbitrary values */
47 /* The below does a linear, single monotonic sequence mapping. */
48 long q_min; /* packed 32 bit float; quant value 0 maps to minval */
49 long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
50 int q_quant; /* bits: 0 < quant <= 16 */
51 int q_sequencep; /* bitflag */
53 long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
54 map == 2: list of dim*entries quantized entry vals
57 /* encode helpers ********************************************************/
58 struct encode_aux_nearestmatch *nearest_tree;
59 struct encode_aux_threshmatch *thresh_tree;
60 struct encode_aux_pigeonhole *pigeon_tree;
65 /* this structures an arbitrary trained book to quickly find the
67 typedef struct encode_aux_nearestmatch{
68 /* pre-calculated partitioning tree */
72 long *p; /* decision points (each is an entry) */
73 long *q; /* decision points (each is an entry) */
74 long aux; /* number of tree entries */
76 } encode_aux_nearestmatch;
78 /* assumes a maptype of 1; encode side only, so that's OK */
79 typedef struct encode_aux_threshmatch{
84 } encode_aux_threshmatch;
86 typedef struct encode_aux_pigeonhole{
98 } encode_aux_pigeonhole;
100 typedef struct decode_aux{
107 long aux; /* number of tree entries */
110 typedef struct codebook{
111 long dim; /* codebook dimensions (elements per vector) */
112 long entries; /* codebook entries */
113 const static_codebook *c;
115 float *valuelist; /* list of dim*entries actual entry values */
116 long *codelist; /* list of bitstream codewords for each entry */
117 struct decode_aux *decode_tree;
122 extern void vorbis_staticbook_clear(static_codebook *b);
123 extern void vorbis_staticbook_destroy(static_codebook *b);
124 extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
125 extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
126 extern void vorbis_book_clear(codebook *b);
128 extern float *_book_unquantize(const static_codebook *b);
129 extern float *_book_logdist(const static_codebook *b,float *vals);
130 extern float _float32_unpack(long val);
131 extern long _float32_pack(float val);
132 extern int _best(codebook *book, float *a, int step);
133 extern int _ilog(unsigned int v);
134 extern long _book_maptype1_quantvals(const static_codebook *b);
136 extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
137 extern long vorbis_book_codeword(codebook *book,int entry);
138 extern long vorbis_book_codelen(codebook *book,int entry);
142 extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
143 extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
145 extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
146 extern int vorbis_book_errorv(codebook *book, float *a);
147 extern int vorbis_book_encodev(codebook *book, int best,float *a,
149 extern int vorbis_book_encodevs(codebook *book, float *a, oggpack_buffer *b,
150 int step,int stagetype);
152 extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
153 extern long vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
154 int step,int stagetype);
155 extern long s_vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
156 int step,int stagetype);