Finished treeless decode optimizations for now.
authorMonty <xiphmont@xiph.org>
Tue, 22 Jan 2002 02:16:40 +0000 (02:16 +0000)
committerMonty <xiphmont@xiph.org>
Tue, 22 Jan 2002 02:16:40 +0000 (02:16 +0000)
Fixed the approx_vbr assignment bug in vorbisenc

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

lib/codebook.c
lib/sharedbook.c
lib/vorbisenc.c

index 469a530..ef19fd0 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.37 2002/01/21 20:51:28 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.38 2002/01/22 02:16:40 xiphmont Exp $
 
  ********************************************************************/
 
@@ -315,12 +315,11 @@ static ogg_uint32_t bitreverse(ogg_uint32_t x){
   return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa);
 }
 
-
-static long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
+STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
   int  read=book->dec_maxlength;
   long lo,hi;
-  long lok = oggpack_look(b, book->dec_firsttablen);
-
+  long lok = oggpack_look(b,book->dec_firsttablen);
   if (lok >= 0) {
     long entry = book->dec_firsttable[lok];
     if(entry&0x80000000UL){
@@ -336,6 +335,7 @@ static long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
   }
 
   lok = oggpack_look(b, read);
+
   while(lok<0 && read>1)
     lok = oggpack_look(b, --read);
   if(lok<0)return -1;
@@ -343,18 +343,17 @@ static long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
   /* bisect search for the codeword in the ordered list */
   {
     ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok);
-    long p=(lo+hi)>>1;
 
     while(hi-lo>1){
-      long test=(book->codelist[p]<=testword)-1;
-      lo+=(p-lo)&(~test);
-      hi-=(hi-p)&test;
-      p=(lo+hi)>>1;
+      long p=(hi-lo)>>1;
+      long test=book->codelist[lo+p]>testword;    
+      lo+=p&(test-1);
+      hi-=p&(-test);
     }
 
-    if(book->dec_codelengths[p]<=read){
-      oggpack_adv(b, book->dec_codelengths[p]);
-      return(p);
+    if(book->dec_codelengths[lo]<=read){
+      oggpack_adv(b, book->dec_codelengths[lo]);
+      return(lo);
     }
   }
   
index 40235fc..5d9fba7 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: basic shared codebook operations
- last mod: $Id: sharedbook.c,v 1.25 2002/01/21 20:51:28 xiphmont Exp $
+ last mod: $Id: sharedbook.c,v 1.26 2002/01/22 02:16:40 xiphmont Exp $
 
  ********************************************************************/
 
@@ -398,14 +398,14 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
      hints for the non-direct-hits */
   {
     ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
+    long lo=0,hi=0;
 
     for(i=0;i<tabn;i++){
-      if(c->dec_firsttable[i]==0){
-       ogg_uint32_t testword=bitreverse(i);
-       long lo=0,hi=0;
-       while((lo+1)<n && c->codelist[lo+1]<=testword)lo++;
-       while(    hi<n && testword>=(c->codelist[hi]&mask))hi++;
-
+      ogg_uint32_t word=i<<(32-c->dec_firsttablen);
+      if(c->dec_firsttable[bitreverse(word)]==0){
+       while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
+       while(    hi<n && word>=(c->codelist[hi]&mask))hi++;
+       
        /* we only actually have 15 bits per hint to play with here.
            In order to overflow gracefully (nothing breaks, efficiency
            just drops), encode as the difference from the extremes. */
@@ -415,7 +415,8 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
 
          if(loval>0x7fff)loval=0x7fff;
          if(hival>0x7fff)hival=0x7fff;
-         c->dec_firsttable[i]=0x80000000UL | (loval<<15) | hival;
+         c->dec_firsttable[bitreverse(word)]=
+           0x80000000UL | (loval<<15) | hival;
        }
       }
     }
index 2134177..2846cb0 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: simple programmatic interface for encoder mode setup
- last mod: $Id: vorbisenc.c,v 1.33 2001/12/23 11:53:53 xiphmont Exp $
+ last mod: $Id: vorbisenc.c,v 1.34 2002/01/22 02:16:40 xiphmont Exp $
 
  ********************************************************************/
 
@@ -915,10 +915,8 @@ int vorbis_encode_setup_managed(vorbis_info *vi,
                                long min_bitrate){
 
   double tnominal=nominal_bitrate;
-  double approx_vbr=approx_bitrate_to_vbr(channels,(channels==2), 
-                                         (float)nominal_bitrate,rate);
+  double approx_vbr;
   int ret=0;
-  if(approx_vbr<0)return(OV_EIMPL);
 
   if(nominal_bitrate<=0.){
     if(max_bitrate>0.){
@@ -932,6 +930,11 @@ int vorbis_encode_setup_managed(vorbis_info *vi,
     }
   }
 
+  approx_vbr=approx_bitrate_to_vbr(channels,(channels==2), 
+                                  (float)nominal_bitrate,rate);
+  if(approx_vbr<0)return(OV_EIMPL);
+
+
   ret=vorbis_encode_setup_vbr(vi,channels,rate,approx_vbr);
   if(ret){
     vorbis_info_clear(vi);