cannam@154: /* Copyright (c) 2001-2011 Timothy B. Terriberry cannam@154: Copyright (c) 2008-2009 Xiph.Org Foundation */ cannam@154: /* cannam@154: Redistribution and use in source and binary forms, with or without cannam@154: modification, are permitted provided that the following conditions cannam@154: are met: cannam@154: cannam@154: - Redistributions of source code must retain the above copyright cannam@154: notice, this list of conditions and the following disclaimer. cannam@154: cannam@154: - Redistributions in binary form must reproduce the above copyright cannam@154: notice, this list of conditions and the following disclaimer in the cannam@154: documentation and/or other materials provided with the distribution. cannam@154: cannam@154: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS cannam@154: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT cannam@154: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR cannam@154: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER cannam@154: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, cannam@154: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, cannam@154: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR cannam@154: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF cannam@154: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING cannam@154: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS cannam@154: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cannam@154: */ cannam@154: cannam@154: #if !defined(_entdec_H) cannam@154: # define _entdec_H (1) cannam@154: # include cannam@154: # include "entcode.h" cannam@154: cannam@154: /*Initializes the decoder. cannam@154: _buf: The input buffer to use. cannam@154: Return: 0 on success, or a negative value on error.*/ cannam@154: void ec_dec_init(ec_dec *_this,unsigned char *_buf,opus_uint32 _storage); cannam@154: cannam@154: /*Calculates the cumulative frequency for the next symbol. cannam@154: This can then be fed into the probability model to determine what that cannam@154: symbol is, and the additional frequency information required to advance to cannam@154: the next symbol. cannam@154: This function cannot be called more than once without a corresponding call to cannam@154: ec_dec_update(), or decoding will not proceed correctly. cannam@154: _ft: The total frequency of the symbols in the alphabet the next symbol was cannam@154: encoded with. cannam@154: Return: A cumulative frequency representing the encoded symbol. cannam@154: If the cumulative frequency of all the symbols before the one that cannam@154: was encoded was fl, and the cumulative frequency of all the symbols cannam@154: up to and including the one encoded is fh, then the returned value cannam@154: will fall in the range [fl,fh).*/ cannam@154: unsigned ec_decode(ec_dec *_this,unsigned _ft); cannam@154: cannam@154: /*Equivalent to ec_decode() with _ft==1<<_bits.*/ cannam@154: unsigned ec_decode_bin(ec_dec *_this,unsigned _bits); cannam@154: cannam@154: /*Advance the decoder past the next symbol using the frequency information the cannam@154: symbol was encoded with. cannam@154: Exactly one call to ec_decode() must have been made so that all necessary cannam@154: intermediate calculations are performed. cannam@154: _fl: The cumulative frequency of all symbols that come before the symbol cannam@154: decoded. cannam@154: _fh: The cumulative frequency of all symbols up to and including the symbol cannam@154: decoded. cannam@154: Together with _fl, this defines the range [_fl,_fh) in which the value cannam@154: returned above must fall. cannam@154: _ft: The total frequency of the symbols in the alphabet the symbol decoded cannam@154: was encoded in. cannam@154: This must be the same as passed to the preceding call to ec_decode().*/ cannam@154: void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft); cannam@154: cannam@154: /* Decode a bit that has a 1/(1<<_logp) probability of being a one */ cannam@154: int ec_dec_bit_logp(ec_dec *_this,unsigned _logp); cannam@154: cannam@154: /*Decodes a symbol given an "inverse" CDF table. cannam@154: No call to ec_dec_update() is necessary after this call. cannam@154: _icdf: The "inverse" CDF, such that symbol s falls in the range cannam@154: [s>0?ft-_icdf[s-1]:0,ft-_icdf[s]), where ft=1<<_ftb. cannam@154: The values must be monotonically non-increasing, and the last value cannam@154: must be 0. cannam@154: _ftb: The number of bits of precision in the cumulative distribution. cannam@154: Return: The decoded symbol s.*/ cannam@154: int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb); cannam@154: cannam@154: /*Extracts a raw unsigned integer with a non-power-of-2 range from the stream. cannam@154: The bits must have been encoded with ec_enc_uint(). cannam@154: No call to ec_dec_update() is necessary after this call. cannam@154: _ft: The number of integers that can be decoded (one more than the max). cannam@154: This must be at least 2, and no more than 2**32-1. cannam@154: Return: The decoded bits.*/ cannam@154: opus_uint32 ec_dec_uint(ec_dec *_this,opus_uint32 _ft); cannam@154: cannam@154: /*Extracts a sequence of raw bits from the stream. cannam@154: The bits must have been encoded with ec_enc_bits(). cannam@154: No call to ec_dec_update() is necessary after this call. cannam@154: _ftb: The number of bits to extract. cannam@154: This must be between 0 and 25, inclusive. cannam@154: Return: The decoded bits.*/ cannam@154: opus_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb); cannam@154: cannam@154: #endif