Skip to content
Snippets Groups Projects
Commit 949a29bf authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Raw bits encoding/decoding functions renamed to *_raw() and re-introducing

original ec_encode_bin()/ec_decode_bin() to optimize performance when ft is
a power of two.
parent 50cf82f7
No related branches found
No related tags found
No related merge requests found
......@@ -128,13 +128,13 @@ ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb){
unsigned ft;
t=0;
while(_ftb>EC_UNIT_BITS){
s=ec_decode_bin(_this,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;
}
ft=1U<<_ftb;
s=ec_decode_bin(_this,_ftb);
s=ec_decode_raw(_this,_ftb);
/*ec_dec_update(_this,s,s+1,ft);*/
t=t<<_ftb|s;
return t;
......
......@@ -78,7 +78,9 @@ void ec_dec_init(ec_dec *_this,ec_byte_buffer *_buf);
up to and including the one encoded is fh, then the returned value
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_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.
Exactly one call to ec_decode() must have been made so that all necessary
......
......@@ -131,11 +131,11 @@ void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb){
while(_ftb>EC_UNIT_BITS){
_ftb-=EC_UNIT_BITS;
fl=(unsigned)(_fl>>_ftb)&EC_UNIT_MASK;
ec_encode_bin(_this,fl,fl+1,EC_UNIT_BITS);
ec_encode_raw(_this,fl,fl+1,EC_UNIT_BITS);
}
ft=1<<_ftb;
fl=(unsigned)_fl&ft-1;
ec_encode_bin(_this,fl,fl+1,_ftb);
ec_encode_raw(_this,fl,fl+1,_ftb);
}
void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
......
......@@ -78,7 +78,8 @@ void ec_enc_init(ec_enc *_this,ec_byte_buffer *_buf);
decoded value will fall.
_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_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.
......
......@@ -84,7 +84,7 @@ void ec_laplace_encode_start(ec_enc *enc, int *value, int decay, int fs)
fl = 0;
if (s)
fl += fs;
ec_encode(enc, fl, fl+fs, ft);
ec_encode_bin(enc, fl, fl+fs, 15);
}
void ec_laplace_encode(ec_enc *enc, int *value, int decay)
......@@ -102,7 +102,7 @@ int ec_laplace_decode_start(ec_dec *dec, int decay, int fs)
fl = 0;
ft = 32768;
fh = fs;
fm = ec_decode(dec, ft);
fm = ec_decode_bin(dec, 15);
while (fm >= fh && fs != 0)
{
fl = fh;
......
......@@ -154,15 +154,14 @@ unsigned ec_decode(ec_dec *_this,unsigned _ft){
return _ft-EC_MINI(s+1,_ft);
}
unsigned ec_decode_bin(ec_dec *_this,unsigned bits){
#if 0
unsigned ec_decode_bin(ec_dec *_this,unsigned _bits){
unsigned s;
ec_uint32 ft;
ft = (ec_uint32)1<<bits;
_this->nrm=_this->rng>>bits;
_this->nrm=_this->rng>>_bits;
s=(unsigned)((_this->dif-1)/_this->nrm);
return ft-EC_MINI(s+1,ft);
#else
return (1<<_bits)-EC_MINI(s+1,1<<_bits);
}
unsigned ec_decode_raw(ec_dec *_this,unsigned bits){
unsigned value=0;
int count=0;
_this->nb_end_bits += bits;
......@@ -177,7 +176,6 @@ unsigned ec_decode_bin(ec_dec *_this,unsigned bits){
value |= ((_this->end_byte>>(8-_this->end_bits_left))&((1<<bits)-1))<<count;
_this->end_bits_left -= bits;
return value;
#endif
}
void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
......
......@@ -127,18 +127,18 @@ void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft){
ec_enc_normalize(_this);
}
void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
#if 0
ec_uint32 r, ft;
r=_this->rng>>bits;
ft = (ec_uint32)1<<bits;
void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){
ec_uint32 r;
r=_this->rng>>_bits;
if(_fl>0){
_this->low+=_this->rng-IMUL32(r,(ft-_fl));
_this->rng=IMUL32(r,(_fh-_fl));
_this->low+=_this->rng-IMUL32(r,((1<<_bits)-_fl));
_this->rng=IMUL32(r,(_fh-_fl));
}
else _this->rng-=IMUL32(r,(ft-_fh));
else _this->rng-=IMUL32(r,((1<<_bits)-_fh));
ec_enc_normalize(_this);
#else
}
void ec_encode_raw(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
_this->nb_end_bits += bits;
while (bits >= _this->end_bits_left)
{
......@@ -151,7 +151,6 @@ void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
}
_this->end_byte |= (_fl<<(8-_this->end_bits_left)) & 0xff;
_this->end_bits_left -= bits;
#endif
}
long ec_enc_tell(ec_enc *_this,int _b){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment