Commit graph

20 commits

Author SHA1 Message Date
Timothy B. Terriberry
845dfa1986 Changes to ec_dec_cdf() to support 8-bit tables.
This renames ec_dec_cdf() to ec_dec_icdf(), and changes the
 functionality to use an "inverse" CDF table, where
 icdf[i]=ft-cdf[i+1].
The first entry is omitted entirely.
It also adds a corresonding ec_enc_icdf() to the encoder, which uses
 the same table.
One could use ec_encode_bin() by converting the values in the tables
 back to normal CDF values, but the icdf[] table already has them in
 the form ec_encode_bin() wants to use them, so there's no reason to
 translate them and then translate them back.

This is done primarily to allow SILK to use the range coder with
 8-bit probability tables containing cumulative frequencies that
 span the full range 0...256.
With an 8-bit table, the final 256 of a normal CDF becomes 0 in the
 "inverse" CDF.
It's the 0 at the start of a normal CDF which would become 256, but
 this is the value we omit, as it already has to be special-cased in
 the encoder, and is not used at all in the decoder.
2011-01-08 14:57:01 -05:00
Timothy B. Terriberry
1aaa50d1c1 Update ec_dec_cdf() to use an unsigned cdf[].
For our current usage, this doesn't matter, but is more consistent
 with the rest of the API.
We may want to reduce this to an unsigned char[], but I'd rather
 coordinate that optimization with SILK's planned reduction to
 8-bit CDFs, as we may be able to use the same code.
2010-12-21 21:00:41 -05:00
Timothy B. Terriberry
30df6cf3f8 Entropy coder clean-up.
This simplifies a good bit of the error handling, and should make it
 impossible to overrun the buffer in the encoder or decoder, while
 still allowing tell() to operate correctly after a bust.
The encoder now tries to keep the range coder data intact after a
 bust instead of corrupting it with extra bits data, though this is
 not a guarantee (too many extra bits may have already been flushed).
It also now correctly reports errors when the bust occurs merging the
 last byte of range coder and extra bits.

A number of abstraction barrier violations were cleaned up, as well.
This patch also includes a number of minor performance improvements:
 ec_{enc|dec}_bits() in particular should be much faster.

Finally, tf_select was changed to be coded with the range coder
 rather than extra bits, so that it is at the front of the packet
 (for unequal error protection robustness).
2010-12-21 14:23:45 -05:00
Timothy B. Terriberry
e86fb268b0 Replace ec_{enc|dec}_bit_prob() with ec_{enc|dec}_bit_logp().
All of our usage of ec_{enc|dec}_bit_prob had the probability of a
 "one" being a power of two.
This adds a new ec_{enc|dec}_bit_logp() function that takes this
 explicitly into account.
It introduces less rounding error than the bit_prob version, does not
 require 17-bit integers to be emulated by ec_{encode|decode}_bin(),
 and does not require any multiplies or divisions at all.
It is exactly equivalent to
 ec_encode_bin(enc,_val?0:(1<<_logp)-1,(1<<_logp)-(_val?1:0),1<<_logp)

The old ec_{enc|dec}_bit_prob functions are left in place for now,
 because I am not sure if SILK is still using them or not when
 combined in Opus.
2010-12-18 09:06:06 -05:00
Timothy B. Terriberry
8c23a3a0fd Subtract one from dif in the range decoder.
It turns out to be more convenient to store dif=low+rng-code-1
 instead of dif=low+rng-code.
This gets rid of a decrement in the normal decode path, replaces a
 decrement and an "and" in the normalization loop with a single
 add, and makes it clear that the new ec_dec_cdf() will not result
 in an infinite loop.
This does not change the bitstream.
2010-12-18 09:06:06 -05:00
Timothy B. Terriberry
a0b664df3d Add a generic CDF decoding routine.
This decodes a value encoded with ec_encode_bin() without using any
 divisions.
It is only meant for small alphabets.
If a symbol can take on a large number of possible values, a binary
 search would be better.

This patch also converts spread_decision to use it, since it is
 faster and introduces less rounding error to encode a single
 decision for the entire value than to encode it a bit at a time.
2010-12-17 14:21:43 -05:00
Jean-Marc Valin
aaedf1711c Simplifies convoluted raw bits calls. 2010-09-10 20:20:04 -04:00
Jean-Marc Valin
531f2ae7e3 Remove useless use of "long", remove useless prototypes 2010-08-02 09:01:28 -04:00
Jean-Marc Valin
b1e017f58d Error checking on the decoder side 2010-07-18 21:20:35 -04:00
Jean-Marc Valin
9310096e3c Fix misleading comments about ec_{enc|dec}_tell() 2010-07-05 00:33:00 -04:00
Timothy B. Terriberry
43e9406201 Change ec_{enc|dec}_bit_prob to take probabilities in units of 1/65536 instead of 1/256. This allows them to use a single 16x16->32 multiply instead of a 24x8->32 multiply. Also change the time-frequency resolution flag coding to ensure that "0" is always the most-probable symbol (i.e., that prob("1")<50%), as that's where all the rounding error accumulates. 2010-05-29 23:45:28 -04:00
Timothy B. Terriberry
299747ee24 Provide direct implementations ec_{enc|dec}_bit_prob() that do not require a division instead of using the normal entropy coder path. This should be exactly equivalent to the existing code. 2010-05-29 23:45:18 -04:00
Jean-Marc Valin
8035b6589d Adds a range coder call to encode a single bit with arbitrary probability 2010-05-27 16:25:07 -04:00
Jean-Marc Valin
8b2ff0da5a Updated copyright notices 2009-10-17 21:40:10 -04:00
Jean-Marc Valin
30f7f813ea Changed all the celt*int*_t types to remove the _t suffix, which is reserved
by POSIX. The other _t types that are not part of the API are still there
for now. Also, got rid of all that was left of the 64-bit types.
2009-10-17 14:35:13 -04:00
Jean-Marc Valin
949a29bf0c 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.
2009-07-25 20:16:01 -04:00
Jean-Marc Valin
c08be4485b Implemented "raw bits"
Making it so all the information encoded directly with ec_enc_bits() gets
stored at the end of the stream, without going through the range coder. This
should be both faster and reduce the effects of bit errors.

Conflicts:

	tests/ectest.c
2009-07-23 07:33:24 -04:00
Gregory Maxwell
f40bbf751d Include missing copyright information in various files, for signoff.
Signed-off-by: Timothy B. Terriberry <tterribe@xiph.org>
2009-02-03 23:08:31 -05:00
Jean-Marc Valin
c2decd39a6 Made a second version of ec_{en|de}code optimised for encoding bits (no div
required) and using it in ec_{en|de}c_bits()
2008-03-22 22:58:45 +11:00
Jean-Marc Valin
6238bc0ece Moved the content of libentcode into libcelt to reduce dependencies,
especially now that we have a custom version of that code anyway. Moved
the test code to tests/
2008-01-28 22:28:54 +11:00
Renamed from libentcode/entdec.h (Browse further)