ref: 8035b6589dcbb10e67080088ea6ac837ed3a346d
parent: c4ac57023c28da3cfdff6abccf02ca0eb90c939f
author: Jean-Marc Valin <[email protected]>
date: Thu May 27 12:23:52 EDT 2010
Adds a range coder call to encode a single bit with arbitrary probability
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -111,3 +111,21 @@
return t;
}
}
+
+/* The probability of having a "one" is given in 1/256 */
+int ec_dec_bit_prob(ec_dec *_this,int _prob)
+{
+ int val;
+ int fl=0, fh=256-_prob;
+ val = ec_decode_bin(_this, 8);
+ if (val >= fh)
+ {
+ val = 1;
+ fl=fh;
+ fh=256;
+ } else {
+ val = 0;
+ }
+ ec_dec_update(_this,fl,fh,256);
+ return val;
+}
--- a/libcelt/entdec.h
+++ b/libcelt/entdec.h
@@ -111,6 +111,9 @@
Return: The decoded bits.*/
ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft);
+/* Decode a bit that has a _prob/256 probability of being a one */
+int ec_dec_bit_prob(ec_dec *_this,int _prob);
+
/*Returns the number of bits "used" by the decoded symbols so far.
The actual number of bits may be larger, due to rounding to whole bytes, or
smaller, due to trailing zeros that were be stripped, so this is not an
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -101,3 +101,14 @@
}
}
+/* The probability of having a "one" is given in 1/256 */
+void ec_enc_bit_prob(ec_enc *_this,int val,int _prob)
+{
+ int fl=0, fh=256-_prob;
+ if (val)
+ {
+ fl=fh;
+ fh=256;
+ }
+ ec_encode_bin(_this,fl,fh,8);
+}
--- a/libcelt/entenc.h
+++ b/libcelt/entenc.h
@@ -91,6 +91,9 @@
This must be at least one, and no more than 2**32-1.*/
void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft);
+/* Encode a bit that has a _prob/256 probability of being a one */
+void ec_enc_bit_prob(ec_enc *_this,int val,int _prob);
+
/*Returns the number of bits "used" by the encoded symbols so far.
The actual number of bits may be larger, due to rounding to whole bytes, or
smaller, due to trailing zeros that can be stripped, so this is not an