ref: aaedf1711c118e348f64b529ab5d83881907add2
parent: f9fdbffb72d953b6a386d066f6b1c6de4be90a87
author: Jean-Marc Valin <[email protected]>
date: Fri Sep 10 16:20:04 EDT 2010
Simplifies convoluted raw bits calls.
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -60,23 +60,6 @@
else return *(_b->ptr++);
}
-
-ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb){
- ec_uint32 t;
- unsigned s;
- t=0;
- while(_ftb>EC_UNIT_BITS){
- s=ec_decode_raw(_this,EC_UNIT_BITS);
- /*ec_dec_update(_this,s,s+1,EC_UNIT_MASK+1);*/
- t=t<<EC_UNIT_BITS|s;
- _ftb-=EC_UNIT_BITS;
- }
- s=ec_decode_raw(_this,_ftb);
- /*ec_dec_update(_this,s,s+1,ft);*/
- t=t<<_ftb|s;
- return t;
-}
-
ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
ec_uint32 t;
unsigned ft;
@@ -93,7 +76,7 @@
s=ec_decode(_this,ft);
ec_dec_update(_this,s,s+1,ft);
t=t<<EC_UNIT_BITS|s;
- t = t<<ftb|ec_dec_bits(_this,ftb);
+ t = t<<ftb|ec_dec_bits(_this,ftb&(1<<ftb)-1);
if (t>_ft)
{
_this->error |= 1;
--- a/libcelt/entdec.h
+++ b/libcelt/entdec.h
@@ -80,7 +80,6 @@
will fall in the range [fl,fh).*/
unsigned ec_decode(ec_dec *_this,unsigned _ft);
unsigned ec_decode_bin(ec_dec *_this,unsigned _bits);
-unsigned ec_decode_raw(ec_dec *_this,unsigned bits);
/*Advance the decoder past the next symbol using the frequency information the
symbol was encoded with.
@@ -103,7 +102,7 @@
_ftb: The number of bits to extract.
This must be at least one, and no more than 32.
Return: The decoded bits.*/
-ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb);
+ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb);
/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream.
The bits must have been encoded with ec_enc_uint().
No call to ec_dec_update() is necessary after this call.
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -70,20 +70,6 @@
}
}
-
-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 +83,7 @@
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);
}
--- a/libcelt/entenc.h
+++ b/libcelt/entenc.h
@@ -81,12 +81,12 @@
_ft: The sum of the frequencies of all the symbols*/
void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft);
void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits);
-void ec_encode_raw(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits);
/*Encodes a sequence of raw bits in the stream.
_fl: The bits to encode.
_ftb: The number of bits to encode.
This must be at least one, and no more than 32.*/
-void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb);
+void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _ftb);
+
/*Encodes a raw unsigned integer in the stream.
_fl: The integer to encode.
_ft: The number of integers that can be encoded (one more than the max).
--- a/libcelt/rangedec.c
+++ b/libcelt/rangedec.c
@@ -162,7 +162,7 @@
return (1<<_bits)-EC_MINI(s+1,1<<_bits);
}
-unsigned ec_decode_raw(ec_dec *_this,unsigned bits){
+unsigned ec_dec_bits(ec_dec *_this,unsigned bits){
unsigned value=0;
int count=0;
_this->nb_end_bits += bits;
--- a/libcelt/rangeenc.c
+++ b/libcelt/rangeenc.c
@@ -153,7 +153,7 @@
ec_enc_normalize(_this);
}
-void ec_encode_raw(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
+void ec_enc_bits(ec_enc *_this,unsigned _fl,unsigned bits){
_this->nb_end_bits += bits;
while (bits >= _this->end_bits_left)
{