Initial beta 4 merge
[platform/upstream/libvorbis.git] / vq / cascade.c
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5  * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
6  * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
7  *                                                                  *
8  * THE OggVorbis 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.10 2000/12/21 21:04:49 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 float count=0.f;
29
30
31 void process_preprocess(codebook **bs,char *basename){
32 }
33
34 void process_postprocess(codebook **b,char *basename){
35   fprintf(stderr,"Done.                      \n");
36 }
37
38 float process_one(codebook *b,float *a,int dim,int step,int addmul,
39                    float base){
40   int j;
41
42   if(b->c->q_sequencep){
43     float temp;
44     for(j=0;j<dim;j++){
45       temp=a[j*step];
46       a[j*step]-=base;
47     }
48     base=temp;
49   }
50
51   vorbis_book_besterror(b,a,step,addmul);
52   
53   return base;
54 }
55
56 void process_vector(codebook **bs,int *addmul,int inter,float *a,int n){
57   int i,bi=0;
58   int booknum=0;
59   
60   while(*bs){
61     float base=0.f;
62     codebook *b=*bs;
63     int dim=b->dim;
64     
65     if(inter){
66       for(i=0;i<n/dim;i++)
67         base=process_one(b,a+i,dim,n/dim,addmul[bi],base);
68     }else{
69       for(i=0;i<=n-dim;i+=dim)
70         base=process_one(b,a+i,dim,1,addmul[bi],base);
71     }
72
73     bs++;
74     booknum++;
75     bi++;
76   }
77
78   for(i=0;i<n;i++)
79     fprintf(stdout,"%f, ",a[i]);
80   fprintf(stdout,"\n");
81   
82   if((long)(count++)%100)spinnit("working.... lines: ",count);
83 }
84
85 void process_usage(void){
86   fprintf(stderr,
87           "usage: vqcascade [-i] +|*<codebook>.vqh [ +|*<codebook.vqh> ]... \n"
88           "                 datafile.vqd [datafile.vqd]...\n\n"
89           "       data can be taken on stdin.  residual error data sent to\n"
90           "       stdout.\n\n");
91
92 }