1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/entcode.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 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 +#include "opus_types.h" 1.32 +#include "opus_defines.h" 1.33 + 1.34 +#if !defined(_entcode_H) 1.35 +# define _entcode_H (1) 1.36 +# include <limits.h> 1.37 +# include <stddef.h> 1.38 +# include "ecintrin.h" 1.39 + 1.40 +/*OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a 1.41 + larger type, you can speed up the decoder by using it here.*/ 1.42 +typedef opus_uint32 ec_window; 1.43 +typedef struct ec_ctx ec_ctx; 1.44 +typedef struct ec_ctx ec_enc; 1.45 +typedef struct ec_ctx ec_dec; 1.46 + 1.47 +# define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT) 1.48 + 1.49 +/*The number of bits to use for the range-coded part of unsigned integers.*/ 1.50 +# define EC_UINT_BITS (8) 1.51 + 1.52 +/*The resolution of fractional-precision bit usage measurements, i.e., 1.53 + 3 => 1/8th bits.*/ 1.54 +# define BITRES 3 1.55 + 1.56 +/*The entropy encoder/decoder context. 1.57 + We use the same structure for both, so that common functions like ec_tell() 1.58 + can be used on either one.*/ 1.59 +struct ec_ctx{ 1.60 + /*Buffered input/output.*/ 1.61 + unsigned char *buf; 1.62 + /*The size of the buffer.*/ 1.63 + opus_uint32 storage; 1.64 + /*The offset at which the last byte containing raw bits was read/written.*/ 1.65 + opus_uint32 end_offs; 1.66 + /*Bits that will be read from/written at the end.*/ 1.67 + ec_window end_window; 1.68 + /*Number of valid bits in end_window.*/ 1.69 + int nend_bits; 1.70 + /*The total number of whole bits read/written. 1.71 + This does not include partial bits currently in the range coder.*/ 1.72 + int nbits_total; 1.73 + /*The offset at which the next range coder byte will be read/written.*/ 1.74 + opus_uint32 offs; 1.75 + /*The number of values in the current range.*/ 1.76 + opus_uint32 rng; 1.77 + /*In the decoder: the difference between the top of the current range and 1.78 + the input value, minus one. 1.79 + In the encoder: the low end of the current range.*/ 1.80 + opus_uint32 val; 1.81 + /*In the decoder: the saved normalization factor from ec_decode(). 1.82 + In the encoder: the number of oustanding carry propagating symbols.*/ 1.83 + opus_uint32 ext; 1.84 + /*A buffered input/output symbol, awaiting carry propagation.*/ 1.85 + int rem; 1.86 + /*Nonzero if an error occurred.*/ 1.87 + int error; 1.88 +}; 1.89 + 1.90 +static OPUS_INLINE opus_uint32 ec_range_bytes(ec_ctx *_this){ 1.91 + return _this->offs; 1.92 +} 1.93 + 1.94 +static OPUS_INLINE unsigned char *ec_get_buffer(ec_ctx *_this){ 1.95 + return _this->buf; 1.96 +} 1.97 + 1.98 +static OPUS_INLINE int ec_get_error(ec_ctx *_this){ 1.99 + return _this->error; 1.100 +} 1.101 + 1.102 +/*Returns the number of bits "used" by the encoded or decoded symbols so far. 1.103 + This same number can be computed in either the encoder or the decoder, and is 1.104 + suitable for making coding decisions. 1.105 + Return: The number of bits. 1.106 + This will always be slightly larger than the exact value (e.g., all 1.107 + rounding error is in the positive direction).*/ 1.108 +static OPUS_INLINE int ec_tell(ec_ctx *_this){ 1.109 + return _this->nbits_total-EC_ILOG(_this->rng); 1.110 +} 1.111 + 1.112 +/*Returns the number of bits "used" by the encoded or decoded symbols so far. 1.113 + This same number can be computed in either the encoder or the decoder, and is 1.114 + suitable for making coding decisions. 1.115 + Return: The number of bits scaled by 2**BITRES. 1.116 + This will always be slightly larger than the exact value (e.g., all 1.117 + rounding error is in the positive direction).*/ 1.118 +opus_uint32 ec_tell_frac(ec_ctx *_this); 1.119 + 1.120 +#endif