Cleanup: Removed tailing white-spaces in C code files
[platform/upstream/libvorbis.git] / vq / latticetune.c
index f7563b4..193d4d1 100644 (file)
@@ -1,19 +1,17 @@
 /********************************************************************
  *                                                                  *
  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
- * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
- * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
- * by Monty <monty@xiph.org> and the XIPHOPHORUS Company            *
- * http://www.xiph.org/                                             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: utility main for setting entropy encoding parameters
            for lattice codebooks
- last mod: $Id: latticetune.c,v 1.5 2000/11/08 03:23:23 xiphmont Exp $
 
  ********************************************************************/
 
@@ -24,7 +22,7 @@
 #include <errno.h>
 #include "bookutil.h"
 
-static char *strrcmp_i(char *s,char *cmp){
+static int strrcmp_i(char *s,char *cmp){
   return(strncmp(s+strlen(s)-strlen(cmp),cmp,strlen(cmp)));
 }
 
@@ -64,7 +62,7 @@ int main(int argc,char *argv[]){
 
     b=codebook_load(filename);
     c=(static_codebook *)(b->c);
-    
+
     ptr=strrchr(filename,'.');
     if(ptr){
       *ptr='\0';
@@ -95,49 +93,33 @@ int main(int argc,char *argv[]){
   if(!strrcmp_i(argv[0],"latticetune")){
     long lines=0;
     line=setup_line(in);
-    while(line){      
+    while(line){
       long code;
       lines++;
       if(!(lines&0xfff))spinnit("codewords so far...",lines);
-      
+
       if(sscanf(line,"%ld",&code)==1)
-       hits[code]++;
+        hits[code]++;
 
       line=setup_line(in);
     }
   }
 
-  if(!strrcmp_i(argv[0],"restune")){
-    long step;
-    long lines=0;
-    long cols=-1;
-    float *vec;
+  /* now we simply count already collated by-entry data */
+  if(!strrcmp_i(argv[0],"res0tune") || !strrcmp_i(argv[0],"res1tune")){
+
     line=setup_line(in);
     while(line){
-      int code;
-      if(!(lines&0xfff))spinnit("codewords so far...",lines);
 
-      if(cols==-1){
-       char *temp=line;
-       while(*temp==' ')temp++;
-       for(cols=0;*temp;cols++){
-         while(*temp>32)temp++;
-         while(*temp==' ')temp++;
-       }
-       vec=alloca(sizeof(float)*cols);
-       step=cols/dim;
-      }
-      
-      for(j=0;j<cols;j++)
-       if(get_line_value(in,vec+j)){
-         fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
-         exit(1);
-       }
-      
-      for(j=0;j<step;j++){
-       lines++;
-       code=_best(b,vec+j,step);
-       hits[code]++;
+      /* code:hits\n */
+      /* likely to have multiple listing for each code entry; must
+         accumulate */
+
+      char *pos=strchr(line,':');
+      if(pos){
+        long code=atol(line);
+        long val=atol(pos+1);
+        hits[code]+=val;
       }
 
       line=setup_line(in);
@@ -150,9 +132,32 @@ int main(int argc,char *argv[]){
   build_tree_from_lengths0(entries,hits,lengths);
 
   c->lengthlist=lengths;
-  write_codebook(stdout,name,c); 
-  
+  write_codebook(stdout,name,c);
+
+  {
+    long bins=_book_maptype1_quantvals(c);
+    long i,k,base=c->lengthlist[0];
+    for(i=0;i<entries;i++)
+      if(c->lengthlist[i]>base)base=c->lengthlist[i];
+
+    for(j=0;j<entries;j++){
+      if(c->lengthlist[j]){
+        int indexdiv=1;
+        fprintf(stderr,"%4ld: ",j);
+        for(k=0;k<c->dim;k++){
+          int index= (j/indexdiv)%bins;
+          fprintf(stderr,"%+3.1f,", c->quantlist[index]*_float32_unpack(c->q_delta)+
+                 _float32_unpack(c->q_min));
+          indexdiv*=bins;
+        }
+        fprintf(stderr,"\t|");
+        for(k=0;k<base-c->lengthlist[j];k++)fprintf(stderr,"*");
+        fprintf(stderr,"\n");
+      }
+    }
+  }
+
   fprintf(stderr,"\r                                                     "
-         "\nDone.\n");
+          "\nDone.\n");
   exit(0);
 }