More VQ utility work. Utils now include:
[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.9 2000/01/05 10:14:58 xiphmont Exp $
16
17  ********************************************************************/
18
19 #ifndef _VQGEN_H_
20 #define _VQGEN_H_
21
22 #include <sys/time.h>
23
24 typedef struct vqgen{
25   int it;
26   int elements;
27   int aux;
28
29   /* point cache */
30   double *pointlist; 
31   long   points;
32   long   allocated;
33
34   /* entries */
35   double *entrylist;
36   long   *assigned;
37   double *bias;
38   long   entries;
39
40   double  (*metric_func) (struct vqgen *v,double *entry,double *point);
41   double *(*weight_func) (struct vqgen *v,double *point);
42 } vqgen;
43
44 typedef struct {
45   long   min;       /* packed 24 bit float */       
46   long   delta;     /* packed 24 bit float */       
47   int    quant;     /* 0 < quant <= 16 */
48   int    sequencep; /* bitflag */
49 } quant_meta;
50
51 static inline double *_point(vqgen *v,long ptr){
52   return v->pointlist+((v->elements+v->aux)*ptr);
53 }
54
55 static inline double *_aux(vqgen *v,long ptr){
56   return _point(v,ptr)+v->aux;
57 }
58
59 static inline double *_now(vqgen *v,long ptr){
60   return v->entrylist+(v->elements*ptr);
61 }
62
63 extern void vqgen_init(vqgen *v,int elements,int aux,int entries,
64                        double  (*metric)(vqgen *,double *, double *),
65                        double *(*weight)(vqgen *,double *));
66 extern void vqgen_addpoint(vqgen *v, double *p,double *aux);
67
68 extern double vqgen_iterate(vqgen *v);
69 extern void vqgen_unquantize(vqgen *v,quant_meta *q);
70 extern void vqgen_quantize(vqgen *v,quant_meta *q);
71
72 extern void spinnit(char *s,int n);
73
74 extern long float24_pack(double val);
75 extern double float24_unpack(long val);
76
77 #endif
78
79
80
81
82