[xiph-cvs] cvs commit: vorbis/vq huffbuild.c latticetune.c make_residue_books.pl

Monty xiphmont at xiph.org
Sun Jun 3 22:50:13 PDT 2001



xiphmont    01/06/03 22:50:12

  Modified:    lib      codebook.c codebook.h floor0.c mapping0.c os.h
                        res0.c
               vq       huffbuild.c latticetune.c make_residue_books.pl
  Log:
  Cascading fully functional

Revision  Changes    Path
1.25      +9 -51     vorbis/lib/codebook.c

Index: codebook.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codebook.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- codebook.c	2001/05/27 06:43:59	1.24
+++ codebook.c	2001/06/04 05:50:10	1.25
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.24 2001/05/27 06:43:59 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.25 2001/06/04 05:50:10 xiphmont Exp $
 
  ********************************************************************/
 
@@ -341,52 +341,10 @@
   return(-ptr);
 }
 
-/* returns the entry number or -1 on eof *************************************/
-long vorbis_book_decodevs(codebook *book,float *a,oggpack_buffer *b,
-			  int step,int addmul){
-  long entry=vorbis_book_decode(book,b);
-  int i,o;
-  float *t;
-  if(entry==-1)return(-1);
-  t = book->valuelist+entry*book->dim;
-  switch(addmul){
-  case -1:
-    for(i=0,o=0;i<book->dim-3;i+=4,o+=4*step) {
-      a[o]=t[i];
-      a[o+step]=t[i+1];
-      a[o+2*step]=t[i+2];
-      a[o+3*step]=t[i+3];
-    }
-    for(;i<book->dim;i++,o+=step)
-      a[o]=t[i];
-    break;
-  case 0:
-    for(i=0,o=0;i<book->dim-3;i+=4,o+=4*step) {
-      a[o]+=t[i];
-      a[o+step]+=t[i+1];
-      a[o+2*step]+=t[i+2];
-      a[o+3*step]+=t[i+3];
-    }
-    for(;i<book->dim;i++,o+=step)
-      a[o]+=t[i];
-    break;
-  case 1:
-    for(i=0,o=0;i<book->dim-3;i+=4,o+=4*step) {
-      a[o]*=t[i];
-      a[o+step]*=t[i+1];
-      a[o+2*step]*=t[i+2];
-      a[o+3*step]*=t[i+3];
-    }
-    for(;i<book->dim;i++,o+=step)
-      a[o]*=t[i];
-    break;
-  }
-  return(entry);
-}
-
 /* returns 0 on OK or -1 on eof *************************************/
-long s_vorbis_book_decodevs(codebook *book,float *a,oggpack_buffer *b,
-                         int step,int addmul){
+long vorbis_book_decodevs(codebook *book,float *a,oggpack_buffer *b,
+                         int n,int addmul){
+  int step=n/book->dim;
   long *entry = alloca(sizeof(long)*step);
   float **t = alloca(sizeof(float *)*step);
   int i,j,o;
@@ -416,14 +374,14 @@
   return(0);
 }
 
-long s_vorbis_book_decodev(codebook *book,float *a,oggpack_buffer *b,
-			   int partsize,int addmul){
+long vorbis_book_decodev(codebook *book,float *a,oggpack_buffer *b,
+			 int n,int addmul){
   int i,j,entry;
   float *t;
 
   switch(addmul){
   case -1:
-    for(i=0;i<partsize;){
+    for(i=0;i<n;){
       entry = vorbis_book_decode(book,b);
       if(entry==-1)return(-1);
       t     = book->valuelist+entry*book->dim;
@@ -432,7 +390,7 @@
     }
     break;
   case 0:
-    for(i=0;i<partsize;){
+    for(i=0;i<n;){
       entry = vorbis_book_decode(book,b);
       if(entry==-1)return(-1);
       t     = book->valuelist+entry*book->dim;
@@ -441,7 +399,7 @@
     }
     break;
   case 1:
-    for(i=0;i<partsize;){
+    for(i=0;i<n;){
       entry = vorbis_book_decode(book,b);
       if(entry==-1)return(-1);
       t     = book->valuelist+entry*book->dim;

1.7       +4 -6      vorbis/lib/codebook.h

Index: codebook.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codebook.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- codebook.h	2001/05/27 06:43:59	1.6
+++ codebook.h	2001/06/04 05:50:10	1.7
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: basic shared codebook operations
- last mod: $Id: codebook.h,v 1.6 2001/05/27 06:43:59 xiphmont Exp $
+ last mod: $Id: codebook.h,v 1.7 2001/06/04 05:50:10 xiphmont Exp $
 
  ********************************************************************/
 
@@ -150,11 +150,9 @@
 
 extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
 extern long vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
-				 int step,int stagetype);
-extern long s_vorbis_book_decodevs(codebook *book, float *a, oggpack_buffer *b,
-				   int step,int stagetype);
-extern long s_vorbis_book_decodev(codebook *book, float *a, oggpack_buffer *b,
-				   int partsize,int stagetype);
+				   int n,int stagetype);
+extern long vorbis_book_decodev(codebook *book, float *a, oggpack_buffer *b,
+				   int n,int stagetype);
 
 
 

1.41      +2 -2      vorbis/lib/floor0.c

Index: floor0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/floor0.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- floor0.c	2001/05/27 06:43:59	1.40
+++ floor0.c	2001/06/04 05:50:10	1.41
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.40 2001/05/27 06:43:59 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.41 2001/06/04 05:50:10 xiphmont Exp $
 
  ********************************************************************/
 
@@ -422,7 +422,7 @@
       memset(out,0,sizeof(float)*look->m);    
       
       for(j=0;j<look->m;j+=b->dim)
-	if(vorbis_book_decodevs(b,lsp+j,&vb->opb,1,-1)==-1)goto eop;
+	if(vorbis_book_decodev(b,lsp+j,&vb->opb,b->dim,-1)==-1)goto eop;
       for(j=0;j<look->m;){
         for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
         last=lsp[j-1];

1.29      +6 -1      vorbis/lib/mapping0.c

Index: mapping0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/mapping0.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- mapping0.c	2001/05/27 06:44:00	1.28
+++ mapping0.c	2001/06/04 05:50:10	1.29
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.28 2001/05/27 06:44:00 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.29 2001/06/04 05:50:10 xiphmont Exp $
 
  ********************************************************************/
 
@@ -147,6 +147,7 @@
   int i;
   vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
 
+  /* leave submaps as a hook to be filled in later */
   oggpack_write(opb,info->submaps-1,4);
   /* we don't write the channel submappings if we only have one... */
   if(info->submaps>1){
@@ -317,6 +318,10 @@
     
     look->residue_func[i]->forward(vb,look->residue_look[i],
                                    pcmbundle,ch_in_bundle);
+  }
+
+  for(j=0;j<vi->channels;j++){
+    _analysis_output("resres",seq-vi->channels+j,vb->pcm[j],n/2,0,0);
   }
   
   look->lastframe=vb->sequence;

1.26      +1 -9      vorbis/lib/os.h

Index: os.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/os.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- os.h	2001/05/27 20:33:19	1.25
+++ os.h	2001/06/04 05:50:10	1.26
@@ -13,7 +13,7 @@
  ********************************************************************
 
  function: #ifdef jail to whip a few platforms into the UNIX ideal.
- last mod: $Id: os.h,v 1.25 2001/05/27 20:33:19 xiphmont Exp $
+ last mod: $Id: os.h,v 1.26 2001/06/04 05:50:10 xiphmont Exp $
 
  ********************************************************************/
 
@@ -40,14 +40,6 @@
 #  define rint(x)   (floor((x)+0.5f)) 
 #  define NO_FLOAT_MATH_LIB
 #  define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
-#endif
-
-#ifndef __GNUC__
-#  define NO_FLOAT_MATH_LIB
-#endif
-
-#ifdef DARWIN
-#  define NO_FLOAT_MATH_LIB
 #endif
 
 #ifdef HAVE_SQRTF

1.28      +186 -151  vorbis/lib/res0.c

Index: res0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/res0.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- res0.c	2001/05/27 06:44:01	1.27
+++ res0.c	2001/06/04 05:50:10	1.28
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: residue backend 0 and 1 implementation
- last mod: $Id: res0.c,v 1.27 2001/05/27 06:44:01 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.28 2001/06/04 05:50:10 xiphmont Exp $
 
  ********************************************************************/
 
@@ -37,11 +37,17 @@
   int         map;
   
   int         parts;
+  int         stages;
+  codebook   *fullbooks;
   codebook   *phrasebook;
   codebook ***partbooks;
 
   int         partvals;
   int       **decodemap;
+
+  long        phrase;
+  long        bits[32];
+  long        vals[32];
 } vorbis_look_residue0;
 
 vorbis_info_residue *res0_copy_info(vorbis_info_residue *vr){
@@ -62,6 +68,20 @@
   int j;
   if(i){
     vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
+    long resbitsT=0;
+    long resvalsT=0;
+
+    for(j=0;j<look->parts;j++)resbitsT+=look->bits[j];
+    for(j=0;j<look->parts;j++)resvalsT+=look->vals[j];
+    fprintf(stderr,
+	    "Encoded %ld res vectors in %ld phrasing and %ld res bits\n\t",
+	    resvalsT,look->phrase,resbitsT);
+    for(j=1;j<look->parts;j++)
+      fprintf(stderr,"%ld(%ld):%ld  %g/sample\n",j,look->vals[j],look->bits[j],
+	      (float)look->bits[j]/look->vals[j]);
+    fprintf(stderr,"\n");
+ 
+
     for(j=0;j<look->parts;j++)
       if(look->partbooks[j])_ogg_free(look->partbooks[j]);
     _ogg_free(look->partbooks);
@@ -73,6 +93,25 @@
   }
 }
 
+static int ilog(unsigned int v){
+  int ret=0;
+  while(v){
+    ret++;
+    v>>=1;
+  }
+  return(ret);
+}
+
+static int icount(unsigned int v){
+  int ret=0;
+  while(v){
+    ret+=v&1;
+    v>>=1;
+  }
+  return(ret);
+}
+
+
 void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
   vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
   int j,acc=0;
@@ -83,9 +122,19 @@
                                              code with a partitioned book */
   oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
   oggpack_write(opb,info->groupbook,8);  /* group huffman book */
+
+  /* secondstages is a bitmask; as encoding progresses pass by pass, a
+     bitmask of one indicates this partition class has bits to write
+     this pass */
   for(j=0;j<info->partitions;j++){
-    oggpack_write(opb,info->secondstages[j],4); /* zero *is* a valid choice */
-    acc+=info->secondstages[j];
+    if(ilog(info->secondstages[j])>3){
+      /* yes, this is a minor hack due to not thinking ahead */
+      oggpack_write(opb,info->secondstages[j],3); 
+      oggpack_write(opb,1,1);
+      oggpack_write(opb,info->secondstages[j]>>3,5); 
+    }else
+      oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
+    acc+=icount(info->secondstages[j]);
   }
   for(j=0;j<acc;j++)
     oggpack_write(opb,info->booklist[j],8);
@@ -103,17 +152,15 @@
   info->grouping=oggpack_read(opb,24)+1;
   info->partitions=oggpack_read(opb,6)+1;
   info->groupbook=oggpack_read(opb,8);
+
   for(j=0;j<info->partitions;j++){
-    int cascade=info->secondstages[j]=oggpack_read(opb,4);
-    if(cascade>1)goto errout; /* temporary!  when cascading gets
-                                 reworked and actually used, we don't
-                                 want old code to DTWT */
-    acc+=cascade;
+    int cascade=info->secondstages[j]=oggpack_read(opb,3);
+    if(oggpack_read(opb,1))
+      cascade|=(oggpack_read(opb,5)<<3);
+    acc+=icount(cascade);
   }
-  for(j=0;j<acc;j++){
+  for(j=0;j<acc;j++)
     info->booklist[j]=oggpack_read(opb,8);
-    if(info->booklist[j]==255)info->booklist[j]=-1;
-  }
 
   if(info->groupbook>=ci->books)goto errout;
   for(j=0;j<acc;j++)
@@ -133,24 +180,30 @@
 
   int j,k,acc=0;
   int dim;
+  int maxstage=0;
   look->info=info;
   look->map=vm->mapping;
 
   look->parts=info->partitions;
+  look->fullbooks=be->fullbooks;
   look->phrasebook=be->fullbooks+info->groupbook;
   dim=look->phrasebook->dim;
 
   look->partbooks=_ogg_calloc(look->parts,sizeof(codebook **));
 
   for(j=0;j<look->parts;j++){
-    int stages=info->secondstages[j];
+    int stages=ilog(info->secondstages[j]);
     if(stages){
-      look->partbooks[j]=_ogg_malloc(stages*sizeof(codebook *));
-      look->partbooks[j][0]=be->fullbooks+info->booklist[acc++];
+      if(stages>maxstage)maxstage=stages;
+      look->partbooks[j]=_ogg_calloc(stages,sizeof(codebook *));
+      for(k=0;k<stages;k++)
+	if(info->secondstages[j]&(1<<k))
+	  look->partbooks[j][k]=be->fullbooks+info->booklist[acc++];
     }
   }
 
   look->partvals=rint(pow(look->parts,dim));
+  look->stages=maxstage;
   look->decodemap=_ogg_malloc(look->partvals*sizeof(int *));
   for(j=0;j<look->partvals;j++){
     long val=j;
@@ -252,97 +305,68 @@
 }
 
 static int _interleaved_encodepart(oggpack_buffer *opb,float *vec, int n,
-				   int stages, codebook **books,int mode,
-				   int part){
-  int i,j=0,bits=0;
-  if(stages){
-    int dim=books[j]->dim;
-    int step=n/dim;
-    for(i=0;i<step;i++){
-      int entry=vorbis_book_besterror(books[j],vec+i,step,0);
+				   codebook *book,vorbis_look_residue0 *look){
+  int i,bits=0;
+  int dim=book->dim;
+  int step=n/dim;
 #ifdef TRAIN_RESENT      
-      {
-	char buf[80];
-	FILE *f;
-	sprintf(buf,"res0_%da%d_%d.vqd",mode,j,part);
-	f=fopen(buf,"a");
-	fprintf(f,"%d\n",entry);
-	fclose(f);
-      }
+  char buf[80];
+  FILE *f;
+  sprintf(buf,"res0_b%d.vqd",book-look->fullbooks);
+  f=fopen(buf,"a");
 #endif
-      bits+=vorbis_book_encode(books[j],entry,opb);
-    }
+
+  for(i=0;i<step;i++){
+    int entry=vorbis_book_besterror(book,vec+i,step,0);
+
+#ifdef TRAIN_RESENT      
+    fprintf(f,"%d\n",entry);
+#endif
+
+    bits+=vorbis_book_encode(book,entry,opb);
   }
+
+#ifdef TRAIN_RESENT      
+  fclose(f);
+#endif
   return(bits);
 }
  
 static int _encodepart(oggpack_buffer *opb,float *vec, int n,
-		       int stages, codebook **books,int mode,int part){
-  int i,j=0,bits=0;
-  if(stages){
-    int dim=books[j]->dim;
-    int step=n/dim;
-    for(i=0;i<step;i++){
-      int entry=vorbis_book_besterror(books[j],vec+i*dim,1,0);
+		       codebook *book,vorbis_look_residue0 *look){
+  int i,bits=0;
+  int dim=book->dim;
+  int step=n/dim;
 #ifdef TRAIN_RESENT      
-      {
-	char buf[80];
-	FILE *f;
-	sprintf(buf,"res0_%da%d_%d.vqd",mode,j,part);
-	f=fopen(buf,"a");
-	fprintf(f,"%d\n",entry);
-	fclose(f);
-      }
+  char buf[80];
+  FILE *f;
+  sprintf(buf,"res0_b%d.vqd",book-look->fullbooks);
+  f=fopen(buf,"a");
 #endif
-      bits+=vorbis_book_encode(books[j],entry,opb);
-    }
-  }
-  return(bits);
-}
 
-/* doesn;t yet deal with cascading */
-static int _interleaved_decodepart(oggpack_buffer *opb,float *work,
-				   float *vec, int n,
-				   int stages, codebook **books){
-  int i;
-  
-  memset(work,0,sizeof(float)*n);
-  if(stages){
-    int step=n/books[0]->dim;
-    if(s_vorbis_book_decodevs(books[0],work,opb,step,0)==-1)
-      return(-1);
-  }
-  
-  for(i=0;i<n;i++)
-    vec[i]*=work[i];
-  
-  return(0);
-}
+  for(i=0;i<step;i++){
+    int entry=vorbis_book_besterror(book,vec+i*dim,1,0);
 
-static int _decodepart(oggpack_buffer *opb,float *work,
-		       float *vec, int n,
-		       int stages, codebook **books){
-  int i;
-  
-  memset(work,0,sizeof(float)*n);
-  if(stages){
-    if(s_vorbis_book_decodev(books[0],work,opb,n,0)==-1)
-      return(-1);
+#ifdef TRAIN_RESENT      
+    fprintf(f,"%d\n",entry);
+#endif
+
+    bits+=vorbis_book_encode(book,entry,opb);
   }
-  
-  for(i=0;i<n;i++)
-    vec[i]*=work[i];
-  
-  return(0);
+
+#ifdef TRAIN_RESENT      
+  fclose(f);
+#endif
+  return(bits);
 }
 
 static int _01forward(vorbis_block *vb,vorbis_look_residue *vl,
                       float **in,int ch,
                       int (*classify)(float *,int,vorbis_look_residue0 *,
                                       int,int),
-		      int (*encode)(oggpack_buffer *,float *,int,int,
-				    codebook **,int,int)){
-  long i,j,k,l;
+		      int (*encode)(oggpack_buffer *,float *,int,
+				    codebook *,vorbis_look_residue0 *)){
+  long i,j,k,l,s;
   vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
   vorbis_info_residue0 *info=look->info;
 
@@ -351,9 +375,6 @@
   int possible_partitions=info->partitions;
   int partitions_per_word=look->phrasebook->dim;
   int n=info->end-info->begin;
-  long phrasebits=0,resbitsT=0;
-  long *resbits=alloca(sizeof(long)*possible_partitions);
-  long *resvals=alloca(sizeof(long)*possible_partitions);
 
   int partvals=n/samples_per_partition;
   int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
@@ -364,10 +385,7 @@
   /* we find the patition type for each partition of each
      channel.  We'll go back and do the interleaved encoding in a
      bit.  For now, clarity */
-  
-  memset(resbits,0,sizeof(long)*possible_partitions);
-  memset(resvals,0,sizeof(long)*possible_partitions);
-
+ 
   for(i=0;i<ch;i++){
     partword[i]=_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(long));
     memset(partword[i],0,n/samples_per_partition*sizeof(long));
@@ -386,45 +404,48 @@
      words for a partition per channel until we've written all the
      residual words for that partition word.  Then write the next
      partition channel words... */
-  
-  for(i=info->begin,l=0;i<info->end;){
-    
-    /* first we encode a partition codeword for each channel */
-    for(j=0;j<ch;j++){
-      long val=partword[j][l];
-      for(k=1;k<partitions_per_word;k++)
-	val= val*possible_partitions+partword[j][l+k];
-      phrasebits+=vorbis_book_encode(look->phrasebook,val,&vb->opb);
-    }
-    /* now we encode interleaved residual values for the partitions */
-    for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition)
-      for(j=0;j<ch;j++){
-	/*resbits[partword[j][l]]+=*/
-	resbitsT+=encode(&vb->opb,in[j]+i,samples_per_partition,
-			 info->secondstages[partword[j][l]],
-			 look->partbooks[partword[j][l]],look->map,partword[j][l]);
-	resvals[partword[j][l]]+=samples_per_partition;
+
+  for(s=0;s<look->stages;s++){
+    for(i=info->begin,l=0;i<info->end;){
+
+      /* first we encode a partition codeword for each channel */
+      if(s==0){
+	for(j=0;j<ch;j++){
+	  long val=partword[j][l];
+	  for(k=1;k<partitions_per_word;k++)
+	    val= val*possible_partitions+partword[j][l+k];
+	  look->phrase+=vorbis_book_encode(look->phrasebook,val,&vb->opb);
+	}
       }
-      
+
+      /* now we encode interleaved residual values for the partitions */
+      for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition){
+	
+	for(j=0;j<ch;j++){
+	  if(info->secondstages[partword[j][l]]&(1<<s)){
+	    codebook *statebook=look->partbooks[partword[j][l]][s];
+	    if(statebook){
+	      int ret=encode(&vb->opb,in[j]+i,samples_per_partition,
+			       statebook,look);
+	      look->bits[partword[j][l]]+=ret;
+	      if(s==0)look->vals[partword[j][l]]+=samples_per_partition;
+	    }
+	  }
+	}
+      }
+    }
   }
 
-  for(i=0;i<possible_partitions;i++)resbitsT+=resbits[i];
-  /*fprintf(stderr,
-    "Encoded %ld res vectors in %ld phrasing and %ld res bits\n\t",
-    ch*(info->end-info->begin),phrasebits,resbitsT);
-    for(i=0;i<possible_partitions;i++)
-    fprintf(stderr,"%ld(%ld):%ld ",i,resvals[i],resbits[i]);
-    fprintf(stderr,"\n");*/
- 
   return(0);
 }
 
 /* a truncated packet here just means 'stop working'; it's not an error */
 static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
                       float **in,int ch,
-		      int (*decodepart)(oggpack_buffer *,float *,float *,
-					int,int,codebook **)){
-  long i,j,k,l,transend=vb->pcmend/2;
+		      long (*decodepart)(codebook *, float *, 
+					 oggpack_buffer *,int,int)){
+
+  long i,j,k,l,s,transend=vb->pcmend/2;
   vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
   vorbis_info_residue0 *info=look->info;
 
@@ -435,37 +456,51 @@
 
   int partvals=n/samples_per_partition;
   int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
-  int **partword=alloca(ch*sizeof(long *));
-  float *work=alloca(sizeof(float)*samples_per_partition);
+  int ***partword=alloca(ch*sizeof(int **));
+  float **work=alloca(ch*sizeof(float *));
   partvals=partwords*partitions_per_word;
 
   /* make sure we're zeroed up to the start */
-  for(j=0;j<ch;j++)
-    memset(in[j],0,sizeof(float)*info->begin);
-
-  for(i=info->begin,l=0;i<info->end;){
-    /* fetch the partition word for each channel */
-    for(j=0;j<ch;j++){
-      int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
-      if(temp==-1)goto eopbreak;
-      partword[j]=look->decodemap[temp];
-      if(partword[j]==NULL)goto errout;
-    }
-    
-    /* now we decode residual values for the partitions */
-    for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition)
-      for(j=0;j<ch;j++){
-	int part=partword[j][k];
-	if(decodepart(&vb->opb,work,in[j]+i,samples_per_partition,
-		      info->secondstages[part],
-		      look->partbooks[part])==-1)goto eopbreak;
+  for(j=0;j<ch;j++){
+    work[j]=_vorbis_block_alloc(vb,n*sizeof(float));
+    partword[j]=_vorbis_block_alloc(vb,partwords*sizeof(int *));
+    memset(work[j],0,sizeof(float)*n);
+  }
+
+  for(s=0;s<look->stages;s++){
+    for(i=info->begin,l=0;i<info->end;l++){
+
+      if(s==0){
+	/* fetch the partition word for each channel */
+	for(j=0;j<ch;j++){
+	  int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
+	  if(temp==-1)goto eopbreak;
+	  partword[j][l]=look->decodemap[temp];
+	  if(partword[j][l]==NULL)goto errout;
+	}
       }
+      
+      /* now we decode residual values for the partitions */
+      for(k=0;k<partitions_per_word;k++,i+=samples_per_partition)
+	for(j=0;j<ch;j++){
+	  if(info->secondstages[partword[j][l][k]]&(1<<s)){
+	    codebook *stagebook=look->partbooks[partword[j][l][k]][s];
+	    if(stagebook){
+	      if(decodepart(stagebook,work[j]+i,&vb->opb,
+			    samples_per_partition,0)==-1)goto eopbreak;
+	    }
+	  }
+	}
+    } 
   }
 
  eopbreak:
-  if(i<transend){
-    for(j=0;j<ch;j++)
-      memset(in[j]+i,0,sizeof(float)*(transend-i));
+  
+  for(j=0;j<ch;j++){
+    for(i=0;i<n;i++)
+      in[j][i]*=work[j][i];
+    for(;i<transend;i++)
+      in[j][i]=0;
   }
 
   return(0);
@@ -484,16 +519,16 @@
 }
 
 int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,float **in,int ch){
-    return(_01inverse(vb,vl,in,ch,_interleaved_decodepart));
+  return(_01inverse(vb,vl,in,ch,vorbis_book_decodevs));
 }
 
 int res1_forward(vorbis_block *vb,vorbis_look_residue *vl,
-	    float **in,int ch){
+		 float **in,int ch){
   return(_01forward(vb,vl,in,ch,_testhack,_encodepart));
 }
 
 int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,float **in,int ch){
-    return(_01inverse(vb,vl,in,ch,_decodepart));
+  return(_01inverse(vb,vl,in,ch,vorbis_book_decodev));
 }
 
 vorbis_func_residue residue0_exportbundle={

1.10      +2 -3      vorbis/vq/huffbuild.c

Index: huffbuild.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/vq/huffbuild.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- huffbuild.c	2001/05/27 06:44:07	1.9
+++ huffbuild.c	2001/06/04 05:50:12	1.10
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: hufftree builder
- last mod: $Id: huffbuild.c,v 1.9 2001/05/27 06:44:07 xiphmont Exp $
+ last mod: $Id: huffbuild.c,v 1.10 2001/06/04 05:50:12 xiphmont Exp $
 
  ********************************************************************/
 
@@ -82,7 +82,6 @@
       loval=atoi(argv[2]);
       maxval=atoi(dpos+1);
       subn=1;
-      subn=1;
       begin=0;
     }else{
       begin=atoi(argv[2]);
@@ -138,7 +137,7 @@
       i/=subn;
       while(!feof(file)){
         long val=getval(file,begin,n,subn,maxval);
-	if(val==-1 || val>=maxval)break;
+	if(val==-1 || val>=vals)break;
         hist[val]++;
         if(!(i--&0xff))spinnit("loading... ",i*subn);
       }

1.8       +17 -5     vorbis/vq/latticetune.c

Index: latticetune.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/vq/latticetune.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- latticetune.c	2001/02/26 03:51:12	1.7
+++ latticetune.c	2001/06/04 05:50:12	1.8
@@ -12,7 +12,7 @@
 
  function: utility main for setting entropy encoding parameters
            for lattice codebooks
- last mod: $Id: latticetune.c,v 1.7 2001/02/26 03:51:12 xiphmont Exp $
+ last mod: $Id: latticetune.c,v 1.8 2001/06/04 05:50:12 xiphmont Exp $
 
  ********************************************************************/
 
@@ -106,11 +106,15 @@
     }
   }
 
-  if(!strrcmp_i(argv[0],"restune")){
-    long step;
+  if(!strrcmp_i(argv[0],"res0tune") || !strrcmp_i(argv[0],"res1tune")){
+    long step,adv,max;
     long lines=0;
     long cols=-1;
     float *vec;
+    long interleave=1;
+    if(!strrcmp_i(argv[0],"res1tune"))
+      interleave=0;
+
     line=setup_line(in);
     while(line){
       int code;
@@ -124,7 +128,15 @@
           while(*temp==' ')temp++;
         }
         vec=alloca(sizeof(float)*cols);
-	step=cols/dim;
+	if(interleave){
+	  step=cols/dim;
+	  adv=1;
+	  max=step;
+	}else{
+	  step=1;
+	  adv=dim;
+	  max=cols-dim+1;
+	}
       }
       
       for(j=0;j<cols;j++)
@@ -133,7 +145,7 @@
           exit(1);
         }
       
-      for(j=0;j<step;j++){
+      for(j=0;j<max;j+=adv){
         lines++;
         code=_best(b,vec+j,step);
               hits[code]++;

1.3       +126 -6    vorbis/vq/make_residue_books.pl

Index: make_residue_books.pl
===================================================================
RCS file: /usr/local/cvsroot/vorbis/vq/make_residue_books.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- make_residue_books.pl	2001/01/22 01:38:52	1.2
+++ make_residue_books.pl	2001/06/04 05:50:12	1.3
@@ -6,15 +6,15 @@
 
 #eg:
 
-# >res0_128_128
+# >res0_128_128 interleaved
 # haux res0_96_128aux.vqd 0,4,2
 # :1 res0_128_128_1.vqd, 4, nonseq cull, 0 +- 1
-# +a 4, nonseq, 0 +- .25 .5
+# +1a, 4, nonseq, 0 +- .25 .5
 # :2 res0_128_128_2.vqd, 4, nonseq, 0 +- 1 2
 # :3 res0_128_128_3.vqd, 4, nonseq, 0 +- 1 3 5
 # :4 res0_128_128_4.vqd, 2, nonseq, 0 +- 1 3 5 8 11
 # :5 res0_128_128_5.vqd, 1, nonseq, 0 +- 1 3 5 8 11 14 17 20 24 28 31 35 39 
-# +a 4, nonseq, 0 +- .5 1
+# +1a, 4, nonseq, 0 +- .5 1
 
 
 die "Could not open $ARGV[0]: $!" unless open (F,$ARGV[0]);
@@ -24,9 +24,10 @@
     print "\n#### $line\n\n";
 
     # >res0_128_128
-    if($line=~m/^>(.*)/){
+    if($line=~m/^>(\S+)\s+(\S*)/){
         # set the output name
         $globalname=$1;
+	$interleave=$2;
         next;
     }
 
@@ -83,13 +84,109 @@
         die "Couldn't pre-hint latticebook.\n\tcommand:$command\n" 
             if syst($command);
         
+	if($interleave=~/non/){
+	    $restune="res1tune";
+	}else{
+	    $restune="res0tune";
+	}
+
+	if($seqp=~/cull/){
+	    my $command="$restune temp$$.vqh $datafile 1 > $globalname$name.vqh";
+	    print ">>> $command\n";
+	    die "Couldn't tune latticebook.\n\tcommand:$command\n" 
+		if syst($command);
+	}else{
+	    my $command="$restune temp$$.vqh $datafile > $globalname$name.vqh";
+	    print ">>> $command\n";
+	    die "Couldn't tune latticebook.\n\tcommand:$command\n" 
+		if syst($command);
+	}
+
+	my $command="latticehint $globalname$name.vqh > temp$$.vqh";
+	print ">>> $command\n";
+	die "Couldn't post-hint latticebook.\n\tcommand:$command\n" 
+	    if syst($command);
+
+	my $command="mv temp$$.vqh $globalname$name.vqh";
+	print ">>> $command\n";
+	die "Couldn't rename latticebook.\n\tcommand:$command\n" 
+	    if syst($command);
+
+	# run the training data through book to cascade
+	if($interleave=~/non/){
+	    $vqcascade="vqcascade";
+	}else{
+	    $vqcascade="vqcascade -i";
+	}
+
+	my $command="$vqcascade +$globalname$name.vqh $datafile > temp$$.vqd";
+	print ">>> $command\n";
+	die "Couldn't cascade latticebook.\n\tcommand:$command\n" 
+	    if syst($command);
+
+
+	my $command="rm temp$$.vql";
+	print ">>> $command\n";
+	die "Couldn't remove temp files.\n\tcommand:$command\n" 
+	    if syst($command);
+
+	next;
+    }
+    # +a 4, nonseq, 0 +- 1
+    if($line=~m/^\+(.*)/){
+	my($name,$dim,$seqp,$vals)=split(',',$1);
+
+	# build value list
+	my$plusminus="+";
+	my$list;
+	my$count=0;
+	foreach my$val (split(' ',$vals)){
+	    if($val=~/\-?\+?\d+/){
+		if($plusminus=~/-/){
+		    $list.="-$val ";
+		    $count++;
+		}
+		if($plusminus=~/\+/){
+		    $list.="$val ";
+		    $count++;
+		}
+	    }else{
+		$plusminus=$val;
+	    }
+	}
+	die "Couldn't open temp file temp$$.vql: $!" unless
+	    open(G,">temp$$.vql");
+	print G "$count $dim 0 ";
+	if($seqp=~/non/){
+	    print G "0\n$list\n";
+	}else{	
+	    print G "1\n$list\n";
+	}
+	close(G);
+
+	my $command="latticebuild temp$$.vql > $globalname$name.vqh";
+	print ">>> $command\n";
+	die "Couldn't build latticebook.\n\tcommand:$command\n" 
+	    if syst($command);
+
+	my $command="latticehint $globalname$name.vqh > temp$$.vqh";
+	print ">>> $command\n";
+	die "Couldn't pre-hint latticebook.\n\tcommand:$command\n" 
+	    if syst($command);
+	
+	if($interleave=~/non/){
+	    $restune="res1tune";
+	}else{
+	    $restune="res0tune";
+	}
+
         if($seqp=~/cull/){
-	    my $command="restune temp$$.vqh $datafile 1 > $globalname$name.vqh";
+	    my $command="$restune temp$$.vqh temp$$.vqd 1 > $globalname$name.vqh";
             print ">>> $command\n";
             die "Couldn't tune latticebook.\n\tcommand:$command\n" 
                 if syst($command);
         }else{
-	    my $command="restune temp$$.vqh $datafile > $globalname$name.vqh";
+	    my $command="$restune temp$$.vqh temp$$.vqd > $globalname$name.vqh";
             print ">>> $command\n";
             die "Couldn't tune latticebook.\n\tcommand:$command\n" 
                 if syst($command);
@@ -105,14 +202,37 @@
         die "Couldn't rename latticebook.\n\tcommand:$command\n" 
             if syst($command);
 
+	# run the training data through book to cascade
+	if($interleave=~/non/){
+	    $vqcascade="vqcascade";
+	}else{
+	    $vqcascade="vqcascade -i";
+	}
+
+	my $command="$vqcascade +$globalname$name.vqh temp$$.vqd > tempa$$.vqd";
+	print ">>> $command\n";
+	die "Couldn't cascade latticebook.\n\tcommand:$command\n" 
+	    if syst($command);
+
+
         my $command="rm temp$$.vql";
         print ">>> $command\n";
         die "Couldn't remove temp files.\n\tcommand:$command\n" 
             if syst($command);
 
+	my $command="mv tempa$$.vqd temp$$.vqd";
+	print ">>> $command\n";
+	die "Couldn't rename temp file.\n\tcommand:$command\n" 
+	    if syst($command);
+
         next;
     }
 }
+
+$command="rm temp$$.vqd";
+print ">>> $command\n";
+die "Couldn't remove temp files.\n\tcommand:$command\n" 
+    if syst($command);
 
 sub syst{
     system(@_)/256;

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list