annotate src/opus-1.3/celt/entdec.h @ 69:7aeed7906520

Add Opus sources and macOS builds
author Chris Cannam
date Wed, 23 Jan 2019 13:48:08 +0000
parents
children
rev   line source
Chris@69 1 /* Copyright (c) 2001-2011 Timothy B. Terriberry
Chris@69 2 Copyright (c) 2008-2009 Xiph.Org Foundation */
Chris@69 3 /*
Chris@69 4 Redistribution and use in source and binary forms, with or without
Chris@69 5 modification, are permitted provided that the following conditions
Chris@69 6 are met:
Chris@69 7
Chris@69 8 - Redistributions of source code must retain the above copyright
Chris@69 9 notice, this list of conditions and the following disclaimer.
Chris@69 10
Chris@69 11 - Redistributions in binary form must reproduce the above copyright
Chris@69 12 notice, this list of conditions and the following disclaimer in the
Chris@69 13 documentation and/or other materials provided with the distribution.
Chris@69 14
Chris@69 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@69 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@69 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@69 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
Chris@69 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@69 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@69 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@69 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@69 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@69 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@69 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@69 26 */
Chris@69 27
Chris@69 28 #if !defined(_entdec_H)
Chris@69 29 # define _entdec_H (1)
Chris@69 30 # include <limits.h>
Chris@69 31 # include "entcode.h"
Chris@69 32
Chris@69 33 /*Initializes the decoder.
Chris@69 34 _buf: The input buffer to use.
Chris@69 35 Return: 0 on success, or a negative value on error.*/
Chris@69 36 void ec_dec_init(ec_dec *_this,unsigned char *_buf,opus_uint32 _storage);
Chris@69 37
Chris@69 38 /*Calculates the cumulative frequency for the next symbol.
Chris@69 39 This can then be fed into the probability model to determine what that
Chris@69 40 symbol is, and the additional frequency information required to advance to
Chris@69 41 the next symbol.
Chris@69 42 This function cannot be called more than once without a corresponding call to
Chris@69 43 ec_dec_update(), or decoding will not proceed correctly.
Chris@69 44 _ft: The total frequency of the symbols in the alphabet the next symbol was
Chris@69 45 encoded with.
Chris@69 46 Return: A cumulative frequency representing the encoded symbol.
Chris@69 47 If the cumulative frequency of all the symbols before the one that
Chris@69 48 was encoded was fl, and the cumulative frequency of all the symbols
Chris@69 49 up to and including the one encoded is fh, then the returned value
Chris@69 50 will fall in the range [fl,fh).*/
Chris@69 51 unsigned ec_decode(ec_dec *_this,unsigned _ft);
Chris@69 52
Chris@69 53 /*Equivalent to ec_decode() with _ft==1<<_bits.*/
Chris@69 54 unsigned ec_decode_bin(ec_dec *_this,unsigned _bits);
Chris@69 55
Chris@69 56 /*Advance the decoder past the next symbol using the frequency information the
Chris@69 57 symbol was encoded with.
Chris@69 58 Exactly one call to ec_decode() must have been made so that all necessary
Chris@69 59 intermediate calculations are performed.
Chris@69 60 _fl: The cumulative frequency of all symbols that come before the symbol
Chris@69 61 decoded.
Chris@69 62 _fh: The cumulative frequency of all symbols up to and including the symbol
Chris@69 63 decoded.
Chris@69 64 Together with _fl, this defines the range [_fl,_fh) in which the value
Chris@69 65 returned above must fall.
Chris@69 66 _ft: The total frequency of the symbols in the alphabet the symbol decoded
Chris@69 67 was encoded in.
Chris@69 68 This must be the same as passed to the preceding call to ec_decode().*/
Chris@69 69 void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft);
Chris@69 70
Chris@69 71 /* Decode a bit that has a 1/(1<<_logp) probability of being a one */
Chris@69 72 int ec_dec_bit_logp(ec_dec *_this,unsigned _logp);
Chris@69 73
Chris@69 74 /*Decodes a symbol given an "inverse" CDF table.
Chris@69 75 No call to ec_dec_update() is necessary after this call.
Chris@69 76 _icdf: The "inverse" CDF, such that symbol s falls in the range
Chris@69 77 [s>0?ft-_icdf[s-1]:0,ft-_icdf[s]), where ft=1<<_ftb.
Chris@69 78 The values must be monotonically non-increasing, and the last value
Chris@69 79 must be 0.
Chris@69 80 _ftb: The number of bits of precision in the cumulative distribution.
Chris@69 81 Return: The decoded symbol s.*/
Chris@69 82 int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb);
Chris@69 83
Chris@69 84 /*Extracts a raw unsigned integer with a non-power-of-2 range from the stream.
Chris@69 85 The bits must have been encoded with ec_enc_uint().
Chris@69 86 No call to ec_dec_update() is necessary after this call.
Chris@69 87 _ft: The number of integers that can be decoded (one more than the max).
Chris@69 88 This must be at least 2, and no more than 2**32-1.
Chris@69 89 Return: The decoded bits.*/
Chris@69 90 opus_uint32 ec_dec_uint(ec_dec *_this,opus_uint32 _ft);
Chris@69 91
Chris@69 92 /*Extracts a sequence of raw bits from the stream.
Chris@69 93 The bits must have been encoded with ec_enc_bits().
Chris@69 94 No call to ec_dec_update() is necessary after this call.
Chris@69 95 _ftb: The number of bits to extract.
Chris@69 96 This must be between 0 and 25, inclusive.
Chris@69 97 Return: The decoded bits.*/
Chris@69 98 opus_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb);
Chris@69 99
Chris@69 100 #endif