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