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