6a48b40cba451b488120a4117b7e74e1f20382c0
[platform/upstream/libvorbis.git] / vq / cascade.c
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: function call to do simple data cascading
15  last mod: $Id: cascade.c,v 1.4 2000/01/07 12:11:30 xiphmont Exp $
16
17  ********************************************************************/
18
19 /* this one outputs residue to stdout. */
20
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <math.h>
24 #include "bookutil.h"
25
26 /* set up metrics */
27
28 double count=0.;
29 int dim=-1;
30 double *work=NULL;
31
32 void process_preprocess(codebook **bs,char *basename){
33   while(*bs){
34     codebook *b=*bs;
35     if(dim==-1){
36       dim=b->dim;
37       work=malloc(sizeof(double)*dim);
38     }else{
39       if(dim!=b->dim){
40         fprintf(stderr,"Each codebook in a cascade must have the same dimensional order\n");
41         exit(1);
42       }
43     }
44     bs++;
45   }
46 }
47
48 void process_postprocess(codebook **b,char *basename){
49   fprintf(stderr,"Done.                      \n");
50 }
51
52 void process_vector(codebook **bs,double *a){
53   int i;
54   memcpy(work,a,dim*sizeof(double));
55
56   while(*bs){
57     codebook *b=*bs;
58     int entry=codebook_entry(b,work);
59     double *e=b->valuelist+b->dim*entry;
60
61     for(i=0;i<b->dim;i++)work[i]-=e[i];
62     bs++;
63   }
64
65   for(i=0;i<dim;i++)
66     fprintf(stdout,"%f, ",work[i]);
67   fprintf(stdout,"\n");
68   
69   if((long)(count++)%100)spinnit("working.... lines: ",count);
70 }
71
72 void process_usage(void){
73   fprintf(stderr,
74           "usage: vqcascade book.vqh [book.vqh]... datafile.vqd [datafile.vqd]...\n\n"
75           "       data can be taken on stdin.  residual error data sent to\n"
76           "       stdout.\n\n");
77
78 }