Tuning higher bit-rate to behave a bit more like Vorbis.
[opus.git] / libcelt / entenc.c
index 1e194e6..8b1e1e3 100644 (file)
@@ -45,7 +45,15 @@ void ec_byte_writeinit_buffer(ec_byte_buffer *_b, unsigned char *_buf, ec_uint32
 }
 
 void ec_byte_shrink(ec_byte_buffer *_b, ec_uint32 _size){
-   _b->end_ptr=_b->buf+_size-1;
+   int i;
+   int d;
+   int N;
+   d = _b->storage-_size;
+   N = _b->storage-(_b->end_ptr-_b->buf)-1;
+   /* Copy "raw bytes" */
+   _b->end_ptr=_b->buf+_size-1-N;
+   for (i=0;i<N;i++)
+      _b->end_ptr[i+1] = _b->end_ptr[i+1+d];
    _b->storage=_size;
 }
 
@@ -70,20 +78,6 @@ int ec_byte_write_at_end(ec_byte_buffer *_b,unsigned _value){
   }
 }
 
-
-void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb){
-  unsigned fl;
-  unsigned ft;
-  while(_ftb>EC_UNIT_BITS){
-    _ftb-=EC_UNIT_BITS;
-    fl=(unsigned)(_fl>>_ftb)&EC_UNIT_MASK;
-    ec_encode_raw(_this,fl,fl+1,EC_UNIT_BITS);
-  }
-  ft=1<<_ftb;
-  fl=(unsigned)_fl&ft-1;
-  ec_encode_raw(_this,fl,fl+1,_ftb);
-}
-
 void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
   unsigned  ft;
   unsigned  fl;
@@ -97,7 +91,7 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
     ft=(_ft>>ftb)+1;
     fl=(unsigned)(_fl>>ftb);
     ec_encode(_this,fl,fl+1,ft);
-    ec_enc_bits(_this,_fl,ftb);
+    ec_enc_bits(_this,_fl&(1<<ftb)-1,ftb);
   } else {
     ec_encode(_this,_fl,_fl+1,_ft+1);
   }