There's work left to do, but progress toward first cut: lib and
authorMonty <xiphmont@xiph.org>
Mon, 7 Feb 2000 20:03:17 +0000 (20:03 +0000)
committerMonty <xiphmont@xiph.org>
Mon, 7 Feb 2000 20:03:17 +0000 (20:03 +0000)
examples are back together and running.

Monty

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

lib/codebook.c
lib/envelope.c
lib/floor0.c

index d55baa2..f21bc7f 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.7 2000/02/06 13:40:39 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.8 2000/02/07 20:03:15 xiphmont Exp $
 
  ********************************************************************/
 
@@ -361,12 +361,24 @@ int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
   return(book->c->lengthlist[a]);
 }
 
-/* returns the number of bits and *modifies a* to the residual error *****/
+static double _dist(int el,double *a, double *b){
+  int i;
+  double acc=0.;
+  for(i=0;i<el;i++){
+    double val=(a[i]-b[i]);
+    acc+=val*val;
+  }
+  return acc;
+}
+
+/* returns the number of bits and *modifies a* to the quantized value *****/
 int vorbis_book_encodev(codebook *book, double *a, oggpack_buffer *b){
   encode_aux *t=book->c->encode_tree;
   int dim=book->dim;
   int ptr=0,k;
 
+#if 1
+  /* optimized, using the decision tree */
   while(1){
     double c=0.;
     double *p=book->valuelist+t->p[ptr];
@@ -381,7 +393,19 @@ int vorbis_book_encodev(codebook *book, double *a, oggpack_buffer *b){
       ptr= -t->ptr1[ptr];
     if(ptr<=0)break;
   }
-  for(k=0;k<dim;k++)a[k]-=(book->valuelist-ptr*dim)[k];
+#else
+  /* brute force */
+  double this,best=_dist(book->dim,a,book->valuelist);
+  int i;
+  for(i=1;i<book->entries;i++){
+    this=_dist(book->dim,a,book->valuelist+i*book->dim);
+    if(this<best){
+      ptr=-i;
+      best=this;
+    }
+  }
+#endif
+  memcpy(a,book->valuelist-ptr*dim,dim*sizeof(double));
   return(vorbis_book_encode(book,-ptr,b));
 }
 
@@ -581,7 +605,7 @@ int main(){
        exit(1);
       }
     for(i=0;i<TESTSIZE;i++)
-      if(fabs(testvec[ptr][i]-qv[i]-iv[i])>.000001){
+      if(fabs(qv[i]-iv[i])>.000001){
        fprintf(stderr,"input (%g) != output (%g) at position (%ld)\n",
                iv[i],testvec[ptr][i]-qv[i],i);
        exit(1);
index 5f80473..6d07640 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.c,v 1.14 2000/01/22 13:28:18 xiphmont Exp $
+ last mod: $Id: envelope.c,v 1.15 2000/02/07 20:03:16 xiphmont Exp $
 
  Preecho calculation.
 
@@ -59,11 +59,12 @@ static void _ve_deltas(double *deltas,double *pcm,int n,double *window,
   for(j=0;j<n;j++){
     double acc=0.;
  
-    memcpy(out,pcm+j*winsize,winsize);
+    memcpy(out,pcm+j*winsize,winsize*sizeof(double));
     for(i=0;i<winsize;i++)
       out[i]*=window[i];
-   
+
     mdct_forward(m,out,out);
+
     for(i=winsize/10;i<winsize/2;i++)
       acc+=fabs(out[i]);
     if(deltas[j]<acc)deltas[j]=acc;
index e18689f..4b8df14 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.6 2000/02/06 13:39:40 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.7 2000/02/07 20:03:17 xiphmont Exp $
 
  ********************************************************************/
 
@@ -111,33 +111,20 @@ static int forward(vorbis_block *vb,vorbis_look_floor *i,
   vorbis_lpc_to_lsp(out,out,look->m);
   memcpy(work,out,sizeof(double)*look->m);
 
-  for(j=12;j<20;j++)
-    fprintf(stderr,"%0.3g, ",out[j]);
-  fprintf(stderr,"\n");
-
-  /* code the spectral envelope, and keep track of the actual quantized
-     values */
+  /* code the spectral envelope, and keep track of the actual
+     quantized values; we don't want creeping error as each block is
+     nailed to the last quantized value of the previous block. */
   _oggpack_write(&vb->opb,amp*32768,18);
   {
     codebook *b=vb->vd->fullbooks+info->books[0];
     double last=0.;
     for(j=0;j<look->m;){
-      double next=out[j+b->dim-1];
-      for(k=0;k<b->dim;k++,j++)out[j]-=last;
-      last=next;
-    }
-  }
-
-  for(k=0;k<info->stages;k++){
-    codebook *b=vb->vd->fullbooks+info->books[k];
-    for(j=0;j<look->m;j+=b->dim)
+      for(k=0;k<b->dim;k++)out[j+k]-=last;
       vorbis_book_encodev(b,out+j,&vb->opb);
+      for(k=0;k<b->dim;k++,j++)out[j]+=last;
+      last=out[j-1];
+    }
   }
-  
-  for(j=0;j<look->m;j++)
-    out[j]=work[j]-out[j];
-
-        
 
   /* take the coefficients back to a spectral envelope curve */
   vorbis_lsp_to_lpc(out,out,look->m); 
@@ -168,11 +155,6 @@ static int inverse(vorbis_block *vb,vorbis_look_floor *i,double *out){
     }
   }
 
-  for(j=12;j<20;j++)
-    fprintf(stderr,"%0.3g, ",out[j]);
-  fprintf(stderr,"\n");
-  
-
   /* take the coefficients back to a spectral envelope curve */
   vorbis_lsp_to_lpc(out,out,look->m); 
   vorbis_lpc_to_curve(out,out,amp,&look->lpclook);