first cut of complete VQ utilities
[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-2000             *
9  * by Monty <monty@xiph.org> and The XIPHOPHORUS Company            *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: build a VQ codebook 
15  last mod: $Id: vqgen.h,v 1.10 2000/01/06 13:57:14 xiphmont Exp $
16
17  ********************************************************************/
18
19 #ifndef _VQGEN_H_
20 #define _VQGEN_H_
21
22 typedef struct vqgen{
23   int it;
24   int elements;
25   int aux;
26
27   /* point cache */
28   double *pointlist; 
29   long   points;
30   long   allocated;
31
32   /* entries */
33   double *entrylist;
34   long   *assigned;
35   double *bias;
36   long   entries;
37
38   double  (*metric_func) (struct vqgen *v,double *entry,double *point);
39   double *(*weight_func) (struct vqgen *v,double *point);
40 } vqgen;
41
42 typedef struct {
43   long   min;       /* packed 24 bit float */       
44   long   delta;     /* packed 24 bit float */       
45   int    quant;     /* 0 < quant <= 16 */
46   int    sequencep; /* bitflag */
47 } quant_meta;
48
49 static inline double *_point(vqgen *v,long ptr){
50   return v->pointlist+((v->elements+v->aux)*ptr);
51 }
52
53 static inline double *_aux(vqgen *v,long ptr){
54   return _point(v,ptr)+v->aux;
55 }
56
57 static inline double *_now(vqgen *v,long ptr){
58   return v->entrylist+(v->elements*ptr);
59 }
60
61 extern void vqgen_init(vqgen *v,int elements,int aux,int entries,
62                        double  (*metric)(vqgen *,double *, double *),
63                        double *(*weight)(vqgen *,double *));
64 extern void vqgen_addpoint(vqgen *v, double *p,double *aux);
65
66 extern double vqgen_iterate(vqgen *v);
67 extern void vqgen_unquantize(vqgen *v,quant_meta *q);
68 extern void vqgen_quantize(vqgen *v,quant_meta *q);
69
70 #endif
71
72
73
74
75