Incremental update
[platform/upstream/libvorbis.git] / vq / vqgen.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-1999             *
9  * by 1999 Monty <monty@xiph.org> and The XIPHOPHORUS Company       *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************/
13
14 #ifndef _VQGEN_H_
15 #define _VQGEN_H_
16
17 typedef struct vqgen{
18   int it;
19   int elements;
20
21   /* point cache */
22   double *pointlist; 
23   long   points;
24   long   allocated;
25
26   /* entries */
27   double *entrylist;
28   long   *assigned;
29   double *bias;
30   long   entries;
31
32   double (*metric_func)   (struct vqgen *v,double *a,double *b);
33 } vqgen;
34
35 typedef struct vqbook{
36   long dim;           /* codebook dimensions (elements per vector) */
37   long entries;       /* codebook entries */
38
39   long   min;         /* packed 24 bit float; quant value 0 maps to minval */
40   long   delta;       /* packed 24 bit float; val 1 - val 0 == delta */       
41   int    quant;       /* 0 < quant <= 16 */
42   int    sequencep;   /* bitflag */
43
44   double *valuelist;  /* list of dim*entries quant/actual entry values */
45   long   *codelist;   /* list of bitstream codewords for each entry */
46   long   *lengthlist; /* codeword lengths in bits */
47
48   /* auxiliary encoding/decoding information */
49   /* encode: provided pre-calculated partitioning tree */
50   /* decode: hufftree */
51   long   *ptr0;
52   long   *ptr1;
53
54   /* auxiliary encoding information. Not used in decode */
55   double *n;         /* decision hyperplanes: sum(x_i*n_i)[0<=i<dim]=c */ 
56   double *c;
57   long   aux;
58   long   alloc;
59
60 } vqbook;
61
62 typedef struct {
63   long   min;       /* packed 24 bit float */       
64   long   delta;     /* packed 24 bit float */       
65   int    quant;     /* 0 < quant <= 16 */
66   int    sequencep; /* bitflag */
67 } quant_meta;
68
69 static inline double *_point(vqgen *v,long ptr){
70   return v->pointlist+(v->elements*ptr);
71 }
72
73 static inline double *_now(vqgen *v,long ptr){
74   return v->entrylist+(v->elements*ptr);
75 }
76
77 extern void vqgen_init(vqgen *v,int elements,int entries,
78                        double (*metric)(vqgen *,double *, double *));
79 extern void vqgen_addpoint(vqgen *v, double *p);
80 extern double *vqgen_midpoint(vqgen *v);
81 extern double vqgen_iterate(vqgen *v);
82
83 extern void vqgen_unquantize(vqgen *v,quant_meta *q);
84 extern void vqgen_quantize(vqgen *v,quant_meta *q);
85
86 extern void vqsp_book(vqgen *v,vqbook *b);
87 extern int vqenc_entry(vqbook *b,double *val);
88
89 #endif
90
91
92
93
94