bugfixes for new functionality
[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 actual entry values */
47   long   *quantlist;  /* list of dim*entries quantized entry values */
48   long   *codelist;   /* list of bitstream codewords for each entry */
49   long   *lengthlist; /* codeword lengths in bits */
50
51   /* auxiliary encoding/decoding information */
52   /* encode: provided pre-calculated partitioning tree */
53   /* decode: hufftree */
54   long   *ptr0;
55   long   *ptr1;
56
57   /* auxiliary encoding information. Not used in decode */
58   double *n;         /* decision hyperplanes: sum(x_i*n_i)[0<=i<dim]=c */ 
59   double *c;
60   long   aux;
61   long   alloc;
62
63 } vqbook;
64
65 typedef struct {
66   long   min;       /* packed 24 bit float */       
67   long   delta;     /* packed 24 bit float */       
68   int    quant;     /* 0 < quant <= 16 */
69   int    sequencep; /* bitflag */
70 } quant_meta;
71
72 static inline double *_point(vqgen *v,long ptr){
73   return v->pointlist+((v->elements+v->aux)*ptr);
74 }
75
76 static inline double *_aux(vqgen *v,long ptr){
77   return _point(v,ptr)+v->aux;
78 }
79
80 static inline double *_now(vqgen *v,long ptr){
81   return v->entrylist+(v->elements*ptr);
82 }
83
84 extern void vqgen_init(vqgen *v,int elements,int aux,int entries,
85                        double  (*metric)(vqgen *,double *, double *),
86                        double *(*weight)(vqgen *,double *));
87 extern void vqgen_addpoint(vqgen *v, double *p,double *aux);
88
89 extern double vqgen_iterate(vqgen *v);
90 extern void vqgen_unquantize(vqgen *v,quant_meta *q);
91 extern void vqgen_quantize(vqgen *v,quant_meta *q);
92 extern long float24_pack(double val);
93 extern double float24_unpack(long val);
94
95 extern void vqsp_book(vqgen *v,vqbook *b,long *quantlist);
96 extern int vqenc_entry(vqbook *b,double *val);
97
98 #endif
99
100
101
102
103