Added '-s' option to vqmetrics, vqcascade and vqpartition
authorMonty <xiphmont@xiph.org>
Mon, 10 Jan 2000 10:42:07 +0000 (10:42 +0000)
committerMonty <xiphmont@xiph.org>
Mon, 10 Jan 2000 10:42:07 +0000 (10:42 +0000)
Fixed bug where vqtrain reads a last line of zero vals that doesn't exist
fixed error in <codebook>-me.m file output (numbers were wrong)

Monty

svn path=/trunk/vorbis/; revision=228

vq/bookutil.c
vq/bookutil.h
vq/lspdata.c
vq/metrics.c
vq/run.c
vq/train.c
vq/vqsplit.c

index d69be48..21c4689 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.c,v 1.3 2000/01/06 13:57:10 xiphmont Exp $
+ last mod: $Id: bookutil.c,v 1.4 2000/01/10 10:42:01 xiphmont Exp $
 
  ********************************************************************/
 
@@ -65,8 +65,10 @@ char *get_line(FILE *in){
       {
         long c=fgetc(in);
         switch(c){
-        case '\n':
         case EOF:
+         if(sofar==0)return(NULL);
+         /* fallthrough correct */
+        case '\n':
           linebuffer[sofar]='\0';
           gotline=1;
           break;
@@ -123,20 +125,26 @@ int get_next_ivalue(FILE *in,long *ivalue){
 }
 
 static double sequence_base=0.;
+static int v_sofar=0;
 void reset_next_value(void){
   value_line_buff=NULL;
   sequence_base=0.;
+  v_sofar=0;
 }
 
-int get_vector(codebook *b,FILE *in,double *a){
+int get_vector(codebook *b,FILE *in,int start, int n,double *a){
   int i;
 
   while(1){
 
-    if(get_line_value(in,a)){
-      sequence_base=0.;
+    if(v_sofar==n || get_line_value(in,a)){
+      reset_next_value();
       if(get_next_value(in,a))
        break;
+      for(i=0;i<start;i++){
+       sequence_base=*a;
+       get_line_value(in,a);
+      }
     }
 
     for(i=1;i<b->dim;i++)
@@ -147,6 +155,7 @@ int get_vector(codebook *b,FILE *in,double *a){
       double temp=a[b->dim-1];
       for(i=0;i<b->dim;i++)a[i]-=sequence_base;
       if(b->q_sequencep)sequence_base=temp;
+      v_sofar++;
       return(0);
     }
     sequence_base=0.;
@@ -196,7 +205,7 @@ codebook *codebook_load(char *filename){
   if(sscanf(line,"%ld, %ld, %ld, %ld, %d, %d",
            &(b->dim),&(b->entries),&(b->q_min),&(b->q_delta),&(b->q_quant),
            &(b->q_sequencep))!=6){
-    fprintf(stderr,"syntax in %s in line:\t %s",filename,line);
+    fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
     exit(1);
   }
 
@@ -211,7 +220,7 @@ codebook *codebook_load(char *filename){
   line=get_line(in);
   line=get_line(in);
   if(sscanf(line,"%ld, %ld",&(a->aux),&(a->alloc))!=2){
-    fprintf(stderr,"syntax in %s in line:\t %s",filename,line);
+    fprintf(stderr,"2: syntax in %s in line:\t %s",filename,line);
     exit(1);
   }
     
index ebddf25..55c787c 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: utility functions for loading .vqh and .vqd files
- last mod: $Id: bookutil.h,v 1.2 2000/01/06 13:57:11 xiphmont Exp $
+ last mod: $Id: bookutil.h,v 1.3 2000/01/10 10:42:02 xiphmont Exp $
 
  ********************************************************************/
 
@@ -30,7 +30,7 @@ extern int       get_line_value(FILE *in,double *value);
 extern int       get_next_value(FILE *in,double *value);
 extern int       get_next_ivalue(FILE *in,long *ivalue);
 extern void      reset_next_value(void);
-extern int       get_vector(codebook *b,FILE *in,double *a);
+extern int       get_vector(codebook *b,FILE *in,int start,int num,double *a);
 extern char     *find_seek_to(FILE *in,char *s);
 
 extern codebook *codebook_load(char *filename);
index 9ca2365..bc6a771 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: metrics and quantization code for LSP VQ codebooks
- last mod: $Id: lspdata.c,v 1.8 2000/01/05 15:04:58 xiphmont Exp $
+ last mod: $Id: lspdata.c,v 1.9 2000/01/10 10:42:03 xiphmont Exp $
 
  ********************************************************************/
 
@@ -76,7 +76,7 @@ void vqext_addpoint_adj(vqgen *v,double *b,int start,int dim,int cols){
   if(start>0)base=b[start-1];
   for(i=0;i<dim;i++)a[i]=b[i+start]-base;
   if(start+dim+1>cols) /* +aux */
-    a[i]=M_PI-base;
+    a[i]=a[i-1];
   else
     a[i]=b[i+start]-base;
   
index fcbc930..f7b9b00 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: function calls to collect codebook metrics
- last mod: $Id: metrics.c,v 1.2 2000/01/07 12:11:31 xiphmont Exp $
+ last mod: $Id: metrics.c,v 1.3 2000/01/10 10:42:04 xiphmont Exp $
 
  ********************************************************************/
 
@@ -127,7 +127,7 @@ void process_postprocess(codebook **b,char *basename){
       for(k=0;k<bb->dim;k++){
        fprintf(out,"%ld, %g, %g\n",
                i*bb->dim+k,(bb->valuelist+i*bb->dim)[k],
-               sqrt((histogram_error+i*bb->dim)[k]/histogram[i]));
+               (histogram_error+i*bb->dim)[k]/histogram[i]);
       }
     }
     fclose(out);
index 8389924..bd644e1 100644 (file)
--- a/vq/run.c
+++ b/vq/run.c
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: utility main for loading and operating on codebooks
- last mod: $Id: run.c,v 1.6 2000/01/07 12:11:33 xiphmont Exp $
+ last mod: $Id: run.c,v 1.7 2000/01/10 10:42:05 xiphmont Exp $
 
  ********************************************************************/
 
@@ -48,6 +48,9 @@ int main(int argc,char *argv[]){
   codebook **b=calloc(1,sizeof(codebook *));
   int books=0;
   int input=0;
+
+  int start=0;
+  int num=-1;
   argv++;
 
   if(*argv==NULL){
@@ -61,9 +64,17 @@ int main(int argc,char *argv[]){
   while(*argv){
     if(*argv[0]=='-'){
       /* option */
-
-
-
+      if(argv[0][1]=='s'){
+       /* subvector */
+       if(sscanf(argv[1],"%d,%d",&start,&num)!=2){
+         num= -1;
+         if(sscanf(argv[1],"%d",&start)!=1){
+           fprintf(stderr,"Syntax error using -s\n");
+           exit(1);
+         }
+       }
+       argv+=2;
+      }
     }else{
       /* input file.  What kind? */
       char *dot;
@@ -112,7 +123,7 @@ int main(int argc,char *argv[]){
 
        reset_next_value();
 
-       while(get_vector(*b,in,a)!=-1)
+       while(get_vector(*b,in,start,num,a)!=-1)
          process_vector(b,a);
 
        fclose(in);
@@ -134,7 +145,7 @@ int main(int argc,char *argv[]){
       }
       
       reset_next_value();
-      while(get_vector(*b,stdin,a)!=-1)
+      while(get_vector(*b,stdin,start,num,a)!=-1)
        process_vector(b,a);
     }
   }
index 6da07d3..d95d6fa 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: utility main for training codebooks
- last mod: $Id: train.c,v 1.13 2000/01/05 15:05:00 xiphmont Exp $
+ last mod: $Id: train.c,v 1.14 2000/01/10 10:42:06 xiphmont Exp $
 
  ********************************************************************/
 
@@ -246,7 +246,7 @@ int main(int argc,char *argv[]){
        {
          int i;
          double b[cols];
-         if(start*num+dim>cols){
+         if(start+num*dim>cols){
            fprintf(stderr,"ran out of columns reading %s\n",file);
            exit(1);
          }
index 49bd82e..55732ea 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: build a VQ codebook and the encoding decision 'tree'
- last mod: $Id: vqsplit.c,v 1.11 2000/01/06 13:57:15 xiphmont Exp $
+ last mod: $Id: vqsplit.c,v 1.12 2000/01/10 10:42:07 xiphmont Exp $
 
  ********************************************************************/
 
@@ -391,7 +391,6 @@ static int _node_eq(encode_aux *v, long a, long b){
 void vqsp_book(vqgen *v, codebook *b, long *quantlist){
   long *entryindex=malloc(sizeof(long)*v->entries);
   long *pointindex=malloc(sizeof(long)*v->points);
-  long *membership=malloc(sizeof(long)*v->points);
   long i,j;
   encode_aux *t;
 
@@ -411,25 +410,6 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){
   t->p=malloc(sizeof(long)*t->alloc);
   t->q=malloc(sizeof(long)*t->alloc);
   
-  /* which cells do points belong to?  Only do this once. */
-
-  for(i=0;i<v->points;i++){
-    double *ppt=_point(v,i);
-    long   firstentry=0;
-    double firstmetric=_dist(v,_now(v,0),ppt);
-    
-    for(j=1;j<v->entries;j++){
-      double thismetric=_dist(v,_now(v,j),ppt);
-      if(thismetric<firstmetric){
-       firstmetric=thismetric;
-       firstentry=j;
-      }
-    }
-    
-    membership[i]=firstentry;
-  }
-
-
   /* first, generate the encoding decision heirarchy */
   {
     long pointsofar=0;