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.2 2000/11/06 00:07:00 xiphmont Exp $
17 ********************************************************************/
19 #ifndef _V_CODEBOOK_H_
20 #define _V_CODEBOOK_H_
22 /* This structure encapsulates huffman and VQ style encoding books; it
23 doesn't do anything specific to either.
25 valuelist/quantlist are nonNULL (and q_* significant) only if
26 there's entry->value mapping to be done.
28 If encode-side mapping must be done (and thus the entry needs to be
29 hunted), the auxiliary encode pointer will point to a decision
30 tree. This is true of both VQ and huffman, but is mostly useful
35 typedef struct static_codebook{
36 long dim; /* codebook dimensions (elements per vector) */
37 long entries; /* codebook entries */
38 long *lengthlist; /* codeword lengths in bits */
40 /* mapping ***************************************************************/
41 int maptype; /* 0=none
42 1=implicitly populated values from map column
43 2=listed arbitrary values */
45 /* The below does a linear, single monotonic sequence mapping. */
46 long q_min; /* packed 32 bit float; quant value 0 maps to minval */
47 long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
48 int q_quant; /* bits: 0 < quant <= 16 */
49 int q_sequencep; /* bitflag */
51 long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
52 map == 2: list of dim*entries quantized entry vals
55 /* encode helpers ********************************************************/
56 struct encode_aux_nearestmatch *nearest_tree;
57 struct encode_aux_threshmatch *thresh_tree;
58 struct encode_aux_pigeonhole *pigeon_tree;
63 /* this structures an arbitrary trained book to quickly find the
65 typedef struct encode_aux_nearestmatch{
66 /* pre-calculated partitioning tree */
70 long *p; /* decision points (each is an entry) */
71 long *q; /* decision points (each is an entry) */
72 long aux; /* number of tree entries */
74 } encode_aux_nearestmatch;
76 /* assumes a maptype of 1; encode side only, so that's OK */
77 typedef struct encode_aux_threshmatch{
82 } encode_aux_threshmatch;
84 typedef struct encode_aux_pigeonhole{
96 } encode_aux_pigeonhole;
98 typedef struct decode_aux{
105 long aux; /* number of tree entries */
108 typedef struct codebook{
109 long dim; /* codebook dimensions (elements per vector) */
110 long entries; /* codebook entries */
111 const static_codebook *c;
113 float *valuelist; /* list of dim*entries actual entry values */
114 long *codelist; /* list of bitstream codewords for each entry */
115 struct decode_aux *decode_tree;
119 extern void vorbis_staticbook_clear(static_codebook *b);
120 extern void vorbis_staticbook_destroy(static_codebook *b);
121 extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
122 extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
123 extern void vorbis_book_clear(codebook *b);
125 extern float *_book_unquantize(const static_codebook *b);
126 extern float *_book_logdist(const static_codebook *b,float *vals);
127 extern float _float32_unpack(long val);
128 extern long _float32_pack(float val);
129 extern int _best(codebook *book, float *a, int step);
130 extern int _ilog(unsigned int v);
131 extern long _book_maptype1_quantvals(const static_codebook *b);
133 extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
134 extern long vorbis_book_codeword(codebook *book,int entry);
135 extern long vorbis_book_codelen(codebook *book,int entry);
139 extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
140 extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
142 extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
143 extern int vorbis_book_errorv(codebook *book, float *a);
144 extern int vorbis_book_encodev(codebook *book, int best,float *a,
146 extern int vorbis_book_encodevs(codebook *book, float *a, oggpack_buffer *b,
147 int step,int stagetype);
149 extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
150 extern long vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
151 int step,int stagetype);
152 extern long s_vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
153 int step,int stagetype);