annotate src/opus-1.3/celt/entenc.h @ 169:223a55898ab9 tip default

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