1 #define CODEBOOK _vq_book_lsp_256_32_44100_8
2 #include "lsp_256_32_44100_8.vqh"
3 /********************************************************************
5 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
6 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
7 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
8 * PLEASE READ THESE TERMS DISTRIBUTING. *
10 * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
11 * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
12 * http://www.xiph.org/ *
14 ********************************************************************
16 function: utility main for loading/testing/running finished codebooks
17 last mod: $Id: run.c,v 1.3 2000/01/05 03:11:11 xiphmont Exp $
19 ********************************************************************/
27 /* this is a bit silly; it's a C stub used by a Perl script to build a
28 quick executable against the chosen codebook and run tests */
30 static char *linebuffer=NULL;
31 static int lbufsize=0;
32 static char *rline(FILE *in){
34 if(feof(in))return NULL;
43 linebuffer=malloc(lbufsize);
46 linebuffer=realloc(linebuffer,lbufsize);
57 linebuffer[sofar++]=c;
58 linebuffer[sofar]='\0';
64 if(linebuffer[0]=='#'){
72 void vqbook_unquantize(vqbook *b){
74 double mindel=float24_unpack(b->min);
75 double delta=float24_unpack(b->delta);
76 if(!b->valuelist)b->valuelist=malloc(sizeof(double)*b->entries*b->dim);
78 for(j=0;j<b->entries;j++){
80 for(k=0;k<b->dim;k++){
81 double val=b->quantlist[j*b->dim+k]*delta+last+mindel;
82 b->valuelist[j*b->dim+k]=val;
83 if(b->sequencep)last=val;
89 double _ssqe(int el,double *a, double *b){
93 double val=(a[i]-b[i]);
101 run outbase [-m] [-s <start>,<n>] datafile [-s <start>,<n>] [datafile...]
103 produces: outbase-residue.m (error between input data and chosen codewords;
104 can be used to cascade)
105 outbase-cells.m (2d gnuplot file of cells if -m)
107 currently assumes a 'sequenced' codebook wants its test data to be
108 normalized to begin at zero... */
110 int main(int argc,char *argv[]){
119 double mean=0.,br_mean=0.,mean_count=0.;
124 fprintf(stderr,"Need a basename.\n");
129 vqbook_unquantize(b);
133 snprintf(buf,80,"%s-residue.vqd",name);
134 residue=fopen(buf,"w");
136 fprintf(stderr,"Unable to open output file %s\n",buf);
141 /* parse the command line; handle things as the come */
150 snprintf(buf,80,"%s-cells.m",name);
151 cells=fopen(buf,"w");
153 fprintf(stderr,"Unable to open output file %s\n",buf);
161 fprintf(stderr,"Option %s missing argument.\n",argv[0]);
164 if(sscanf(argv[1],"%d,%d",&start,&num)!=2){
166 if(sscanf(argv[1],"%d",&start)!=1){
167 fprintf(stderr,"Option %s syntax error.\n",argv[0]);
175 /* it's an input file */
176 char *file=strdup(*argv++);
182 fprintf(stderr,"Could not open input file %s\n",file);
186 while((line=rline(in))){
189 while(*temp==' ')temp++;
190 for(cols=0;*temp;cols++){
191 while(*temp>32)temp++;
192 while(*temp==' ')temp++;
197 double *p=malloc(cols*sizeof(double));
198 if(start*num+b->dim>cols){
199 fprintf(stderr,"ran out of columns reading %s\n",file);
202 while(*line==' ')line++;
205 /* static length buffer bug workaround */
208 while(*temp>32)temp++;
215 while(*line>32)line++;
216 while(*line==' ')line++;
218 if(num<=0)num=(cols-start)/b->dim;
219 for(i=num-1;i>=0;i--){
221 double *base=p+start+i*b->dim;
223 /* if this is a sequenced book and i||start,
224 normalize the beginning to zero */
225 if(b->sequencep && (i>0 || start>0)){
226 for(k=0;k<b->dim;k++)
230 /* assign the point */
231 entry=vqenc_entry(b,base);
233 /* accumulate metrics */
234 mean+=_ssqe(b->dim,base,b->valuelist+entry*b->dim);
236 /* brute force it as a sanity check of the decision
237 table... did that work better? */
239 double best=_ssqe(b->dim,base,b->valuelist);
241 for(j=0;j<b->entries;j++){
242 double this=_ssqe(b->dim,base,b->valuelist+j*b->dim);
254 /* paint the cell if -m */
256 fprintf(cells,"%g %g\n%g %g\n\n",
258 b->valuelist[0+entry*b->dim],
259 b->valuelist[1+entry*b->dim]);
262 /* write cascading data */
276 if(cells)fclose(cells);
278 /* print accumulated error statistics */
279 fprintf(stderr,"results:\n\tsqrt(mean squared error) from decision tree:%g\n"
280 "\tsqrt(mean squared error) by brute force:%g\n\n",
281 sqrt(mean/mean_count),sqrt(br_mean/mean_count));