1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/entenc.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +/* Copyright (c) 2001-2011 Timothy B. Terriberry 1.5 + Copyright (c) 2008-2009 Xiph.Org Foundation */ 1.6 +/* 1.7 + Redistribution and use in source and binary forms, with or without 1.8 + modification, are permitted provided that the following conditions 1.9 + are met: 1.10 + 1.11 + - Redistributions of source code must retain the above copyright 1.12 + notice, this list of conditions and the following disclaimer. 1.13 + 1.14 + - Redistributions in binary form must reproduce the above copyright 1.15 + notice, this list of conditions and the following disclaimer in the 1.16 + documentation and/or other materials provided with the distribution. 1.17 + 1.18 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.19 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.20 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.21 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 1.22 + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.23 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.24 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.25 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.26 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.27 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.28 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.29 +*/ 1.30 + 1.31 +#if !defined(_entenc_H) 1.32 +# define _entenc_H (1) 1.33 +# include <stddef.h> 1.34 +# include "entcode.h" 1.35 + 1.36 +/*Initializes the encoder. 1.37 + _buf: The buffer to store output bytes in. 1.38 + _size: The size of the buffer, in chars.*/ 1.39 +void ec_enc_init(ec_enc *_this,unsigned char *_buf,opus_uint32 _size); 1.40 +/*Encodes a symbol given its frequency information. 1.41 + The frequency information must be discernable by the decoder, assuming it 1.42 + has read only the previous symbols from the stream. 1.43 + It is allowable to change the frequency information, or even the entire 1.44 + source alphabet, so long as the decoder can tell from the context of the 1.45 + previously encoded information that it is supposed to do so as well. 1.46 + _fl: The cumulative frequency of all symbols that come before the one to be 1.47 + encoded. 1.48 + _fh: The cumulative frequency of all symbols up to and including the one to 1.49 + be encoded. 1.50 + Together with _fl, this defines the range [_fl,_fh) in which the 1.51 + decoded value will fall. 1.52 + _ft: The sum of the frequencies of all the symbols*/ 1.53 +void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft); 1.54 + 1.55 +/*Equivalent to ec_encode() with _ft==1<<_bits.*/ 1.56 +void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits); 1.57 + 1.58 +/* Encode a bit that has a 1/(1<<_logp) probability of being a one */ 1.59 +void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp); 1.60 + 1.61 +/*Encodes a symbol given an "inverse" CDF table. 1.62 + _s: The index of the symbol to encode. 1.63 + _icdf: The "inverse" CDF, such that symbol _s falls in the range 1.64 + [_s>0?ft-_icdf[_s-1]:0,ft-_icdf[_s]), where ft=1<<_ftb. 1.65 + The values must be monotonically non-increasing, and the last value 1.66 + must be 0. 1.67 + _ftb: The number of bits of precision in the cumulative distribution.*/ 1.68 +void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb); 1.69 + 1.70 +/*Encodes a raw unsigned integer in the stream. 1.71 + _fl: The integer to encode. 1.72 + _ft: The number of integers that can be encoded (one more than the max). 1.73 + This must be at least one, and no more than 2**32-1.*/ 1.74 +void ec_enc_uint(ec_enc *_this,opus_uint32 _fl,opus_uint32 _ft); 1.75 + 1.76 +/*Encodes a sequence of raw bits in the stream. 1.77 + _fl: The bits to encode. 1.78 + _ftb: The number of bits to encode. 1.79 + This must be between 1 and 25, inclusive.*/ 1.80 +void ec_enc_bits(ec_enc *_this,opus_uint32 _fl,unsigned _ftb); 1.81 + 1.82 +/*Overwrites a few bits at the very start of an existing stream, after they 1.83 + have already been encoded. 1.84 + This makes it possible to have a few flags up front, where it is easy for 1.85 + decoders to access them without parsing the whole stream, even if their 1.86 + values are not determined until late in the encoding process, without having 1.87 + to buffer all the intermediate symbols in the encoder. 1.88 + In order for this to work, at least _nbits bits must have already been 1.89 + encoded using probabilities that are an exact power of two. 1.90 + The encoder can verify the number of encoded bits is sufficient, but cannot 1.91 + check this latter condition. 1.92 + _val: The bits to encode (in the least _nbits significant bits). 1.93 + They will be decoded in order from most-significant to least. 1.94 + _nbits: The number of bits to overwrite. 1.95 + This must be no more than 8.*/ 1.96 +void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits); 1.97 + 1.98 +/*Compacts the data to fit in the target size. 1.99 + This moves up the raw bits at the end of the current buffer so they are at 1.100 + the end of the new buffer size. 1.101 + The caller must ensure that the amount of data that's already been written 1.102 + will fit in the new size. 1.103 + _size: The number of bytes in the new buffer. 1.104 + This must be large enough to contain the bits already written, and 1.105 + must be no larger than the existing size.*/ 1.106 +void ec_enc_shrink(ec_enc *_this,opus_uint32 _size); 1.107 + 1.108 +/*Indicates that there are no more symbols to encode. 1.109 + All reamining output bytes are flushed to the output buffer. 1.110 + ec_enc_init() must be called before the encoder can be used again.*/ 1.111 +void ec_enc_done(ec_enc *_this); 1.112 + 1.113 +#endif