ab73875c49cb31c331029f8973ab5db950a67f04
[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.7 2000/10/12 03:13:01 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 "vorbis/codebook.h"
25 #include "../lib/sharedbook.h"
26 #include "bookutil.h"
27
28 /* set up metrics */
29
30 float count=0.;
31
32
33 void process_preprocess(codebook **bs,char *basename){
34 }
35
36 void process_postprocess(codebook **b,char *basename){
37   fprintf(stderr,"Done.                      \n");
38 }
39
40 float process_one(codebook *b,float *a,int dim,int step,int addmul,
41                    float base){
42   int j;
43
44   if(b->c->q_sequencep){
45     float temp;
46     for(j=0;j<dim;j++){
47       temp=a[j*step];
48       a[j*step]-=base;
49     }
50     base=temp;
51   }
52
53   vorbis_book_besterror(b,a,step,addmul);
54   
55   return base;
56 }
57
58 void process_vector(codebook **bs,int *addmul,int inter,float *a,int n){
59   int i,bi=0;
60   int booknum=0;
61   
62   while(*bs){
63     float base=0.;
64     codebook *b=*bs;
65     int dim=b->dim;
66     
67     if(inter){
68       for(i=0;i<n/dim;i++)
69         base=process_one(b,a+i,dim,n/dim,addmul[bi],base);
70     }else{
71       for(i=0;i<=n-dim;i+=dim)
72         base=process_one(b,a+i,dim,1,addmul[bi],base);
73     }
74
75     bs++;
76     booknum++;
77     bi++;
78   }
79
80   for(i=0;i<n;i++)
81     fprintf(stdout,"%f, ",a[i]);
82   fprintf(stdout,"\n");
83   
84   if((long)(count++)%100)spinnit("working.... lines: ",count);
85 }
86
87 void process_usage(void){
88   fprintf(stderr,
89           "usage: vqcascade [-i] +|*<codebook>.vqh [ +|*<codebook.vqh> ]... \n"
90           "                 datafile.vqd [datafile.vqd]...\n\n"
91           "       data can be taken on stdin.  residual error data sent to\n"
92           "       stdout.\n\n");
93
94 }