media/libopus/celt/entenc.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Copyright (c) 2001-2011 Timothy B. Terriberry
michael@0 2 Copyright (c) 2008-2009 Xiph.Org Foundation */
michael@0 3 /*
michael@0 4 Redistribution and use in source and binary forms, with or without
michael@0 5 modification, are permitted provided that the following conditions
michael@0 6 are met:
michael@0 7
michael@0 8 - Redistributions of source code must retain the above copyright
michael@0 9 notice, this list of conditions and the following disclaimer.
michael@0 10
michael@0 11 - Redistributions in binary form must reproduce the above copyright
michael@0 12 notice, this list of conditions and the following disclaimer in the
michael@0 13 documentation and/or other materials provided with the distribution.
michael@0 14
michael@0 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
michael@0 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 26 */
michael@0 27
michael@0 28 #if !defined(_entenc_H)
michael@0 29 # define _entenc_H (1)
michael@0 30 # include <stddef.h>
michael@0 31 # include "entcode.h"
michael@0 32
michael@0 33 /*Initializes the encoder.
michael@0 34 _buf: The buffer to store output bytes in.
michael@0 35 _size: The size of the buffer, in chars.*/
michael@0 36 void ec_enc_init(ec_enc *_this,unsigned char *_buf,opus_uint32 _size);
michael@0 37 /*Encodes a symbol given its frequency information.
michael@0 38 The frequency information must be discernable by the decoder, assuming it
michael@0 39 has read only the previous symbols from the stream.
michael@0 40 It is allowable to change the frequency information, or even the entire
michael@0 41 source alphabet, so long as the decoder can tell from the context of the
michael@0 42 previously encoded information that it is supposed to do so as well.
michael@0 43 _fl: The cumulative frequency of all symbols that come before the one to be
michael@0 44 encoded.
michael@0 45 _fh: The cumulative frequency of all symbols up to and including the one to
michael@0 46 be encoded.
michael@0 47 Together with _fl, this defines the range [_fl,_fh) in which the
michael@0 48 decoded value will fall.
michael@0 49 _ft: The sum of the frequencies of all the symbols*/
michael@0 50 void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft);
michael@0 51
michael@0 52 /*Equivalent to ec_encode() with _ft==1<<_bits.*/
michael@0 53 void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits);
michael@0 54
michael@0 55 /* Encode a bit that has a 1/(1<<_logp) probability of being a one */
michael@0 56 void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp);
michael@0 57
michael@0 58 /*Encodes a symbol given an "inverse" CDF table.
michael@0 59 _s: The index of the symbol to encode.
michael@0 60 _icdf: The "inverse" CDF, such that symbol _s falls in the range
michael@0 61 [_s>0?ft-_icdf[_s-1]:0,ft-_icdf[_s]), where ft=1<<_ftb.
michael@0 62 The values must be monotonically non-increasing, and the last value
michael@0 63 must be 0.
michael@0 64 _ftb: The number of bits of precision in the cumulative distribution.*/
michael@0 65 void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb);
michael@0 66
michael@0 67 /*Encodes a raw unsigned integer in the stream.
michael@0 68 _fl: The integer to encode.
michael@0 69 _ft: The number of integers that can be encoded (one more than the max).
michael@0 70 This must be at least one, and no more than 2**32-1.*/
michael@0 71 void ec_enc_uint(ec_enc *_this,opus_uint32 _fl,opus_uint32 _ft);
michael@0 72
michael@0 73 /*Encodes a sequence of raw bits in the stream.
michael@0 74 _fl: The bits to encode.
michael@0 75 _ftb: The number of bits to encode.
michael@0 76 This must be between 1 and 25, inclusive.*/
michael@0 77 void ec_enc_bits(ec_enc *_this,opus_uint32 _fl,unsigned _ftb);
michael@0 78
michael@0 79 /*Overwrites a few bits at the very start of an existing stream, after they
michael@0 80 have already been encoded.
michael@0 81 This makes it possible to have a few flags up front, where it is easy for
michael@0 82 decoders to access them without parsing the whole stream, even if their
michael@0 83 values are not determined until late in the encoding process, without having
michael@0 84 to buffer all the intermediate symbols in the encoder.
michael@0 85 In order for this to work, at least _nbits bits must have already been
michael@0 86 encoded using probabilities that are an exact power of two.
michael@0 87 The encoder can verify the number of encoded bits is sufficient, but cannot
michael@0 88 check this latter condition.
michael@0 89 _val: The bits to encode (in the least _nbits significant bits).
michael@0 90 They will be decoded in order from most-significant to least.
michael@0 91 _nbits: The number of bits to overwrite.
michael@0 92 This must be no more than 8.*/
michael@0 93 void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits);
michael@0 94
michael@0 95 /*Compacts the data to fit in the target size.
michael@0 96 This moves up the raw bits at the end of the current buffer so they are at
michael@0 97 the end of the new buffer size.
michael@0 98 The caller must ensure that the amount of data that's already been written
michael@0 99 will fit in the new size.
michael@0 100 _size: The number of bytes in the new buffer.
michael@0 101 This must be large enough to contain the bits already written, and
michael@0 102 must be no larger than the existing size.*/
michael@0 103 void ec_enc_shrink(ec_enc *_this,opus_uint32 _size);
michael@0 104
michael@0 105 /*Indicates that there are no more symbols to encode.
michael@0 106 All reamining output bytes are flushed to the output buffer.
michael@0 107 ec_enc_init() must be called before the encoder can be used again.*/
michael@0 108 void ec_enc_done(ec_enc *_this);
michael@0 109
michael@0 110 #endif

mercurial