From 450addf448f772dad4138742e401725c2d84b879 Mon Sep 17 00:00:00 2001 From: Monty Date: Wed, 15 Dec 1999 08:55:25 +0000 Subject: [PATCH] quant fix svn path=/trunk/vorbis/; revision=197 --- vq/build.c | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vq/vqgen.c | 2 +- 2 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 vq/build.c diff --git a/vq/build.c b/vq/build.c new file mode 100644 index 0000000..0eac602 --- /dev/null +++ b/vq/build.c @@ -0,0 +1,231 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY * + * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. * + * PLEASE READ THESE TERMS DISTRIBUTING. * + * * + * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-1999 * + * by 1999 Monty and The XIPHOPHORUS Company * + * http://www.xiph.org/ * + * * + ******************************************************************** + + function: utility main for building codebooks from training sets + author: Monty + modifications by: Monty + last modification date: Dec 14 1999 + + ********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "vqgen.h" + +static int rline(FILE *in,FILE *out,char *line,int max,int pass){ + while(fgets(line,160,in)){ + if(line[0]=='#'){ + if(pass)fprintf(out,"%s",line); + }else{ + return(1); + } + } + return(0); +} + +/* command line: + buildvq vq=file out=file quant=n +*/ + +int exiting=0; +void setexit(int dummy){ + fprintf(stderr,"\nexiting... please wait to finish this iteration\n"); + exiting=1; +} + +int main(int argc,char *argv[]){ + vqgen v; + int entries=-1,dim=-1; + char line[1024]; + long i,j,k; + + int init=0; + while(*argv){ + + /* load the trained data */ + if(!strncmp(*argv,"vq=",3)){ + FILE *in=NULL; + char filename[80],*ptr; + if(sscanf(*argv,"vq=%70s",filename)!=1){ + fprintf(stderr,"Syntax error in argument '%s'\n",*argv); + exit(1); + } + + in=fopen(filename,"r"); + ptr=strrchr(filename,'-'); + if(ptr){ + int num; + ptr++; + num=atoi(ptr); + sprintf(ptr,"%d.vqi",num+1); + }else + strcat(filename,"-0.vqi"); + + out=fopen(filename,"w"); + if(out==NULL){ + fprintf(stderr,"Unable to open %s for writing\n",filename); + exit(1); + } + fprintf(out,"# OggVorbis VQ codebook trainer, intermediate file\n"); + + if(in){ + /* we wish to suck in a preexisting book and continue to train it */ + double a; + + rline(in,out,line,160,1); + if(sscanf(line,"%d %d %d",&entries,&dim,&met)!=3){ + fprintf(stderr,"Syntax error reading book file\n"); + exit(1); + } + + metric=set_metric(met); + vqgen_init(&v,dim,entries,metric,0.); + init=1; + + /* entries, bias, points */ + i=0; + for(j=0;jn){ + fprintf(stderr,"ran out of columns reading %s\n",file); + exit(1); + } + vqgen_addpoint(&v,b+start); + } + + fclose(in); + } + argv++; + } + + /* train the book */ + signal(SIGTERM,setexit); + signal(SIGINT,setexit); + + for(i=0;ientries;j++){ - double val=_now(v,0)[k]; + double val=_now(v,j)[k]; if(valmax)max=val; } -- 2.34.1