cb23f703ed7d4e58a0e85d4de14407a84c6bc12f
[platform/upstream/libvorbis.git] / include / vorbis / codebook.h
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5  * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
6  * PLEASE READ THESE TERMS DISTRIBUTING.                            *
7  *                                                                  *
8  * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
9  * by Monty <monty@xiph.org> and The XIPHOPHORUS Company            *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: codebook types
15  last mod: $Id: codebook.h,v 1.7 2000/10/12 03:12:41 xiphmont Exp $
16
17  ********************************************************************/
18
19 #ifndef _V_CODEBOOK_H_
20 #define _V_CODEBOOK_H_
21
22 /* This structure encapsulates huffman and VQ style encoding books; it
23    doesn't do anything specific to either.
24
25    valuelist/quantlist are nonNULL (and q_* significant) only if
26    there's entry->value mapping to be done.
27
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
31    with VQ.
32
33 */
34
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 */
39
40   /* mapping ***************************************************************/
41   int    maptype;        /* 0=none
42                             1=implicitly populated values from map column 
43                             2=listed arbitrary values */
44
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 */
50
51   long     *quantlist;  /* map == 1: (int)(entries^(1/dim)) element column map
52                            map == 2: list of dim*entries quantized entry vals
53                         */
54
55   /* encode helpers ********************************************************/
56   struct encode_aux_nearestmatch *nearest_tree;
57   struct encode_aux_threshmatch  *thresh_tree;
58   struct encode_aux_pigeonhole  *pigeon_tree;
59 } static_codebook;
60
61 /* this structures an arbitrary trained book to quickly find the
62    nearest cell match */
63 typedef struct encode_aux_nearestmatch{
64   /* pre-calculated partitioning tree */
65   long   *ptr0;
66   long   *ptr1;
67
68   long   *p;         /* decision points (each is an entry) */
69   long   *q;         /* decision points (each is an entry) */
70   long   aux;        /* number of tree entries */
71   long   alloc;       
72 } encode_aux_nearestmatch;
73
74 /* assumes a maptype of 1; encode side only, so that's OK */
75 typedef struct encode_aux_threshmatch{
76   float *quantthresh;
77   long   *quantmap;
78   int     quantvals; 
79   int     threshvals; 
80 } encode_aux_threshmatch;
81
82 typedef struct encode_aux_pigeonhole{
83   float min;
84   float del;
85
86   int  mapentries;
87   int  quantvals;
88   long *pigeonmap;
89
90   long fittotal;
91   long *fitlist;
92   long *fitmap;
93   long *fitlength;
94 } encode_aux_pigeonhole;
95
96 typedef struct decode_aux{
97   long   *tab;
98   int    *tabl;
99   int    tabn;
100
101   long   *ptr0;
102   long   *ptr1;
103   long   aux;        /* number of tree entries */
104 } decode_aux;
105
106 typedef struct codebook{
107   long dim;           /* codebook dimensions (elements per vector) */
108   long entries;       /* codebook entries */
109   const static_codebook *c;
110
111   float  *valuelist;  /* list of dim*entries actual entry values */
112   long   *codelist;   /* list of bitstream codewords for each entry */
113   struct decode_aux *decode_tree;
114
115 } codebook;
116
117 #endif
118
119
120
121
122