diff --git a/libs/celt/cc6_bands.c b/libs/celt/cc6_bands.c index 3df1f28b..b1bba789 100755 --- a/libs/celt/cc6_bands.c +++ b/libs/celt/cc6_bands.c @@ -37,7 +37,7 @@ #include "cc6_bands.h" #include "modes.h" #include "vq.h" -#include "cwrs.h" +#include "cc6_cwrs.h" #include "stack_alloc.h" #include "os_support.h" #include "mathops.h" diff --git a/libs/celt/cc6_bands.h b/libs/celt/cc6_bands.h index 23c29ab7..797fd978 100755 --- a/libs/celt/cc6_bands.h +++ b/libs/celt/cc6_bands.h @@ -34,8 +34,8 @@ #include "cc6_arch.h" #include "modes.h" -#include "entenc.h" -#include "entdec.h" +#include "cc6_entenc.h" +#include "cc6_entdec.h" #include "rate.h" /** Compute the amplitude (sqrt energy) in each of the bands diff --git a/libs/celt/cc6_celt.c b/libs/celt/cc6_celt.c index 564f4552..69a4a41f 100755 --- a/libs/celt/cc6_celt.c +++ b/libs/celt/cc6_celt.c @@ -43,7 +43,7 @@ #include "kiss_fftr.h" #include "cc6_bands.h" #include "modes.h" -#include "entcode.h" +#include "cc6_entcode.h" #include "quant_bands.h" #include "psy.h" #include "rate.h" diff --git a/libs/celt/cc6_cwrs.c b/libs/celt/cc6_cwrs.c index 6e4a70fa..d4208917 100755 --- a/libs/celt/cc6_cwrs.c +++ b/libs/celt/cc6_cwrs.c @@ -36,7 +36,7 @@ #include "os_support.h" #include #include -#include "cwrs.h" +#include "cc6_cwrs.h" #include "mathops.h" #include "cc6_arch.h" diff --git a/libs/celt/cc6_cwrs.h b/libs/celt/cc6_cwrs.h index 343bd8f0..699c5b79 100755 --- a/libs/celt/cc6_cwrs.h +++ b/libs/celt/cc6_cwrs.h @@ -33,8 +33,8 @@ #include "cc6_arch.h" #include "stack_alloc.h" -#include "entenc.h" -#include "entdec.h" +#include "cc6_entenc.h" +#include "cc6_entdec.h" int log2_frac(ec_uint32 val, int frac); diff --git a/libs/celt/cc6_entcode.c b/libs/celt/cc6_entcode.c index a5804ee4..c17ea9b4 100755 --- a/libs/celt/cc6_entcode.c +++ b/libs/celt/cc6_entcode.c @@ -1,70 +1,70 @@ -/* (C) 2001-2008 Timothy B. Terriberry -*/ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Xiph.org Foundation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "entcode.h" - - - - - - - -int ec_ilog(ec_uint32 _v){ -#if defined(EC_CLZ) - return EC_CLZ0-EC_CLZ(_v); -#else - /*On a Pentium M, this branchless version tested as the fastest on - 1,000,000,000 random 32-bit integers, edging out a similar version with - branches, and a 256-entry LUT version.*/ - int ret; - int m; - ret=!!_v; - m=!!(_v&0xFFFF0000)<<4; - _v>>=m; - ret|=m; - m=!!(_v&0xFF00)<<3; - _v>>=m; - ret|=m; - m=!!(_v&0xF0)<<2; - _v>>=m; - ret|=m; - m=!!(_v&0xC)<<1; - _v>>=m; - ret|=m; - ret+=!!(_v&0x2); - return ret; -#endif -} - +/* (C) 2001-2008 Timothy B. Terriberry +*/ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "cc6_entcode.h" + + + + + + + +int ec_ilog(ec_uint32 _v){ +#if defined(EC_CLZ) + return EC_CLZ0-EC_CLZ(_v); +#else + /*On a Pentium M, this branchless version tested as the fastest on + 1,000,000,000 random 32-bit integers, edging out a similar version with + branches, and a 256-entry LUT version.*/ + int ret; + int m; + ret=!!_v; + m=!!(_v&0xFFFF0000)<<4; + _v>>=m; + ret|=m; + m=!!(_v&0xFF00)<<3; + _v>>=m; + ret|=m; + m=!!(_v&0xF0)<<2; + _v>>=m; + ret|=m; + m=!!(_v&0xC)<<1; + _v>>=m; + ret|=m; + ret+=!!(_v&0x2); + return ret; +#endif +} + diff --git a/libs/celt/cc6_entcode.h b/libs/celt/cc6_entcode.h index 67ea3388..08232b8f 100755 --- a/libs/celt/cc6_entcode.h +++ b/libs/celt/cc6_entcode.h @@ -34,7 +34,7 @@ #if !defined(_entcode_H) # define _entcode_H (1) # include -# include "ecintrin.h" +# include "cc6_ecintrin.h" diff --git a/libs/celt/cc6_entdec.c b/libs/celt/cc6_entdec.c index 07eb37f8..2efdba4e 100755 --- a/libs/celt/cc6_entdec.c +++ b/libs/celt/cc6_entdec.c @@ -34,7 +34,7 @@ #endif #include -#include "entdec.h" +#include "cc6_entdec.h" #include "os_support.h" #include "cc6_arch.h" diff --git a/libs/celt/cc6_entdec.h b/libs/celt/cc6_entdec.h index f7c74fa6..6c3c0354 100755 --- a/libs/celt/cc6_entdec.h +++ b/libs/celt/cc6_entdec.h @@ -1,134 +1,134 @@ -/* (C) 2001-2008 Timothy B. Terriberry - (C) 2008 Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Xiph.org Foundation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#if !defined(_entdec_H) -# define _entdec_H (1) -# include "entcode.h" - - - -typedef struct ec_dec ec_dec; - - - -/*The entropy decoder.*/ -struct ec_dec{ - /*The buffer to decode.*/ - ec_byte_buffer *buf; - /*The remainder of a buffered input symbol.*/ - int rem; - /*The number of values in the current range.*/ - ec_uint32 rng; - /*The difference between the input value and the lowest value in the current - range.*/ - ec_uint32 dif; - /*Normalization factor.*/ - ec_uint32 nrm; -}; - - -/*Initializes the decoder. - _buf: The input buffer to use. - Return: 0 on success, or a negative value on error.*/ -void ec_dec_init(ec_dec *_this,ec_byte_buffer *_buf); -/*Calculates the cumulative frequency for the next symbol. - This can then be fed into the probability model to determine what that - symbol is, and the additional frequency information required to advance to - the next symbol. - This function cannot be called more than once without a corresponding call to - ec_dec_update(), or decoding will not proceed correctly. - _ft: The total frequency of the symbols in the alphabet the next symbol was - encoded with. - Return: A cumulative frequency representing the encoded symbol. - If the cumulative frequency of all the symbols before the one that - was encoded was fl, and the cumulative frequency of all the symbols - up to and including the one encoded is fh, then the returned value - will fall in the range [fl,fh).*/ -unsigned ec_decode(ec_dec *_this,unsigned _ft); -unsigned ec_decode_bin(ec_dec *_this,unsigned bits); -/*Advance the decoder past the next symbol using the frequency information the - symbol was encoded with. - Exactly one call to ec_decode() must have been made so that all necessary - intermediate calculations are performed. - _fl: The cumulative frequency of all symbols that come before the symbol - decoded. - _fh: The cumulative frequency of all symbols up to and including the symbol - decoded. - Together with _fl, this defines the range [_fl,_fh) in which the value - returned above must fall. - _ft: The total frequency of the symbols in the alphabet the symbol decoded - was encoded in. - This must be the same as passed to the preceding call to ec_decode().*/ -void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh, - unsigned _ft); -/*Extracts a sequence of raw bits from the stream. - The bits must have been encoded with ec_enc_bits(). - No call to ec_dec_update() is necessary after this call. - _ftb: The number of bits to extract. - This must be at least one, and no more than 32. - Return: The decoded bits.*/ -ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb); -/*Extracts a sequence of raw bits from the stream. - The bits must have been encoded with ec_enc_bits64(). - No call to ec_dec_update() is necessary after this call. - _ftb: The number of bits to extract. - This must be at least one, and no more than 64. - Return: The decoded bits.*/ -ec_uint64 ec_dec_bits64(ec_dec *_this,int _ftb); -/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream. - The bits must have been encoded with ec_enc_uint(). - No call to ec_dec_update() is necessary after this call. - _ft: The number of integers that can be decoded (one more than the max). - This must be at least one, and no more than 2**32-1. - Return: The decoded bits.*/ -ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft); -/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream. - The bits must have been encoded with ec_enc_uint64(). - No call to ec_dec_update() is necessary after this call. - _ft: The number of integers that can be decoded (one more than the max). - This must be at least one, and no more than 2**64-1. - Return: The decoded bits.*/ -ec_uint64 ec_dec_uint64(ec_dec *_this,ec_uint64 _ft); - -/*Returns the number of bits "used" by the decoded symbols so far. - The actual number of bits may be larger, due to rounding to whole bytes, or - smaller, due to trailing zeros that were be stripped, so this is not an - estimate of the true packet size. - This same number can be computed by the encoder, and is suitable for making - coding decisions. - _b: The number of extra bits of precision to include. - At most 16 will be accurate. - Return: The number of bits scaled by 2**_b. - This will always be slightly larger than the exact value (e.g., all - rounding error is in the positive direction).*/ -long ec_dec_tell(ec_dec *_this,int _b); - -#endif +/* (C) 2001-2008 Timothy B. Terriberry + (C) 2008 Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#if !defined(_entdec_H) +# define _entdec_H (1) +# include "cc6_entcode.h" + + + +typedef struct ec_dec ec_dec; + + + +/*The entropy decoder.*/ +struct ec_dec{ + /*The buffer to decode.*/ + ec_byte_buffer *buf; + /*The remainder of a buffered input symbol.*/ + int rem; + /*The number of values in the current range.*/ + ec_uint32 rng; + /*The difference between the input value and the lowest value in the current + range.*/ + ec_uint32 dif; + /*Normalization factor.*/ + ec_uint32 nrm; +}; + + +/*Initializes the decoder. + _buf: The input buffer to use. + Return: 0 on success, or a negative value on error.*/ +void ec_dec_init(ec_dec *_this,ec_byte_buffer *_buf); +/*Calculates the cumulative frequency for the next symbol. + This can then be fed into the probability model to determine what that + symbol is, and the additional frequency information required to advance to + the next symbol. + This function cannot be called more than once without a corresponding call to + ec_dec_update(), or decoding will not proceed correctly. + _ft: The total frequency of the symbols in the alphabet the next symbol was + encoded with. + Return: A cumulative frequency representing the encoded symbol. + If the cumulative frequency of all the symbols before the one that + was encoded was fl, and the cumulative frequency of all the symbols + up to and including the one encoded is fh, then the returned value + will fall in the range [fl,fh).*/ +unsigned ec_decode(ec_dec *_this,unsigned _ft); +unsigned ec_decode_bin(ec_dec *_this,unsigned bits); +/*Advance the decoder past the next symbol using the frequency information the + symbol was encoded with. + Exactly one call to ec_decode() must have been made so that all necessary + intermediate calculations are performed. + _fl: The cumulative frequency of all symbols that come before the symbol + decoded. + _fh: The cumulative frequency of all symbols up to and including the symbol + decoded. + Together with _fl, this defines the range [_fl,_fh) in which the value + returned above must fall. + _ft: The total frequency of the symbols in the alphabet the symbol decoded + was encoded in. + This must be the same as passed to the preceding call to ec_decode().*/ +void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh, + unsigned _ft); +/*Extracts a sequence of raw bits from the stream. + The bits must have been encoded with ec_enc_bits(). + No call to ec_dec_update() is necessary after this call. + _ftb: The number of bits to extract. + This must be at least one, and no more than 32. + Return: The decoded bits.*/ +ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb); +/*Extracts a sequence of raw bits from the stream. + The bits must have been encoded with ec_enc_bits64(). + No call to ec_dec_update() is necessary after this call. + _ftb: The number of bits to extract. + This must be at least one, and no more than 64. + Return: The decoded bits.*/ +ec_uint64 ec_dec_bits64(ec_dec *_this,int _ftb); +/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream. + The bits must have been encoded with ec_enc_uint(). + No call to ec_dec_update() is necessary after this call. + _ft: The number of integers that can be decoded (one more than the max). + This must be at least one, and no more than 2**32-1. + Return: The decoded bits.*/ +ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft); +/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream. + The bits must have been encoded with ec_enc_uint64(). + No call to ec_dec_update() is necessary after this call. + _ft: The number of integers that can be decoded (one more than the max). + This must be at least one, and no more than 2**64-1. + Return: The decoded bits.*/ +ec_uint64 ec_dec_uint64(ec_dec *_this,ec_uint64 _ft); + +/*Returns the number of bits "used" by the decoded symbols so far. + The actual number of bits may be larger, due to rounding to whole bytes, or + smaller, due to trailing zeros that were be stripped, so this is not an + estimate of the true packet size. + This same number can be computed by the encoder, and is suitable for making + coding decisions. + _b: The number of extra bits of precision to include. + At most 16 will be accurate. + Return: The number of bits scaled by 2**_b. + This will always be slightly larger than the exact value (e.g., all + rounding error is in the positive direction).*/ +long ec_dec_tell(ec_dec *_this,int _b); + +#endif diff --git a/libs/celt/cc6_entenc.c b/libs/celt/cc6_entenc.c index f7600103..11c2178b 100755 --- a/libs/celt/cc6_entenc.c +++ b/libs/celt/cc6_entenc.c @@ -34,7 +34,7 @@ #endif #include "os_support.h" -#include "entenc.h" +#include "cc6_entenc.h" #include "cc6_arch.h" diff --git a/libs/celt/cc6_entenc.h b/libs/celt/cc6_entenc.h index d12a4c01..9c0b812d 100755 --- a/libs/celt/cc6_entenc.h +++ b/libs/celt/cc6_entenc.h @@ -1,116 +1,116 @@ -/* (C) 2001-2008 Timothy B. Terriberry - (C) 2008 Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Xiph.org Foundation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#if !defined(_entenc_H) -# define _entenc_H (1) -# include -# include "entcode.h" - - - -typedef struct ec_enc ec_enc; - - - -/*The entropy encoder.*/ -struct ec_enc{ - /*Buffered output.*/ - ec_byte_buffer *buf; - /*A buffered output symbol, awaiting carry propagation.*/ - int rem; - /*Number of extra carry propagating symbols.*/ - size_t ext; - /*The number of values in the current range.*/ - ec_uint32 rng; - /*The low end of the current range (inclusive).*/ - ec_uint32 low; -}; - - -/*Initializes the encoder. - _buf: The buffer to store output bytes in. - This must have already been initialized for writing and reset.*/ -void ec_enc_init(ec_enc *_this,ec_byte_buffer *_buf); -/*Encodes a symbol given its frequency information. - The frequency information must be discernable by the decoder, assuming it - has read only the previous symbols from the stream. - It is allowable to change the frequency information, or even the entire - source alphabet, so long as the decoder can tell from the context of the - previously encoded information that it is supposed to do so as well. - _fl: The cumulative frequency of all symbols that come before the one to be - encoded. - _fh: The cumulative frequency of all symbols up to and including the one to - be encoded. - Together with _fl, this defines the range [_fl,_fh) in which the - decoded value will fall. - _ft: The sum of the frequencies of all the symbols*/ -void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft); -void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits); -/*Encodes a sequence of raw bits in the stream. - _fl: The bits to encode. - _ftb: The number of bits to encode. - This must be at least one, and no more than 32.*/ -void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb); -/*Encodes a sequence of raw bits in the stream. - _fl: The bits to encode. - _ftb: The number of bits to encode. - This must be at least one, and no more than 64.*/ -void ec_enc_bits64(ec_enc *_this,ec_uint64 _fl,int _ftb); -/*Encodes a raw unsigned integer in the stream. - _fl: The integer to encode. - _ft: The number of integers that can be encoded (one more than the max). - This must be at least one, and no more than 2**32-1.*/ -void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft); -/*Encodes a raw unsigned integer in the stream. - _fl: The integer to encode. - _ft: The number of integers that can be encoded (one more than the max). - This must be at least one, and no more than 2**64-1.*/ -void ec_enc_uint64(ec_enc *_this,ec_uint64 _fl,ec_uint64 _ft); - -/*Returns the number of bits "used" by the encoded symbols so far. - The actual number of bits may be larger, due to rounding to whole bytes, or - smaller, due to trailing zeros that can be stripped, so this is not an - estimate of the true packet size. - This same number can be computed by the decoder, and is suitable for making - coding decisions. - _b: The number of extra bits of precision to include. - At most 16 will be accurate. - Return: The number of bits scaled by 2**_b. - This will always be slightly larger than the exact value (e.g., all - rounding error is in the positive direction).*/ -long ec_enc_tell(ec_enc *_this,int _b); - -/*Indicates that there are no more symbols to encode. - All reamining output bytes are flushed to the output buffer. - ec_enc_init() must be called before the encoder can be used again.*/ -void ec_enc_done(ec_enc *_this); - -#endif +/* (C) 2001-2008 Timothy B. Terriberry + (C) 2008 Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#if !defined(_entenc_H) +# define _entenc_H (1) +# include +# include "cc6_entcode.h" + + + +typedef struct ec_enc ec_enc; + + + +/*The entropy encoder.*/ +struct ec_enc{ + /*Buffered output.*/ + ec_byte_buffer *buf; + /*A buffered output symbol, awaiting carry propagation.*/ + int rem; + /*Number of extra carry propagating symbols.*/ + size_t ext; + /*The number of values in the current range.*/ + ec_uint32 rng; + /*The low end of the current range (inclusive).*/ + ec_uint32 low; +}; + + +/*Initializes the encoder. + _buf: The buffer to store output bytes in. + This must have already been initialized for writing and reset.*/ +void ec_enc_init(ec_enc *_this,ec_byte_buffer *_buf); +/*Encodes a symbol given its frequency information. + The frequency information must be discernable by the decoder, assuming it + has read only the previous symbols from the stream. + It is allowable to change the frequency information, or even the entire + source alphabet, so long as the decoder can tell from the context of the + previously encoded information that it is supposed to do so as well. + _fl: The cumulative frequency of all symbols that come before the one to be + encoded. + _fh: The cumulative frequency of all symbols up to and including the one to + be encoded. + Together with _fl, this defines the range [_fl,_fh) in which the + decoded value will fall. + _ft: The sum of the frequencies of all the symbols*/ +void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft); +void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits); +/*Encodes a sequence of raw bits in the stream. + _fl: The bits to encode. + _ftb: The number of bits to encode. + This must be at least one, and no more than 32.*/ +void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb); +/*Encodes a sequence of raw bits in the stream. + _fl: The bits to encode. + _ftb: The number of bits to encode. + This must be at least one, and no more than 64.*/ +void ec_enc_bits64(ec_enc *_this,ec_uint64 _fl,int _ftb); +/*Encodes a raw unsigned integer in the stream. + _fl: The integer to encode. + _ft: The number of integers that can be encoded (one more than the max). + This must be at least one, and no more than 2**32-1.*/ +void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft); +/*Encodes a raw unsigned integer in the stream. + _fl: The integer to encode. + _ft: The number of integers that can be encoded (one more than the max). + This must be at least one, and no more than 2**64-1.*/ +void ec_enc_uint64(ec_enc *_this,ec_uint64 _fl,ec_uint64 _ft); + +/*Returns the number of bits "used" by the encoded symbols so far. + The actual number of bits may be larger, due to rounding to whole bytes, or + smaller, due to trailing zeros that can be stripped, so this is not an + estimate of the true packet size. + This same number can be computed by the decoder, and is suitable for making + coding decisions. + _b: The number of extra bits of precision to include. + At most 16 will be accurate. + Return: The number of bits scaled by 2**_b. + This will always be slightly larger than the exact value (e.g., all + rounding error is in the positive direction).*/ +long ec_enc_tell(ec_enc *_this,int _b); + +/*Indicates that there are no more symbols to encode. + All reamining output bytes are flushed to the output buffer. + ec_enc_init() must be called before the encoder can be used again.*/ +void ec_enc_done(ec_enc *_this); + +#endif diff --git a/libs/celt/laplace.h b/libs/celt/laplace.h index 38669cf3..6b59ae8a 100755 --- a/libs/celt/laplace.h +++ b/libs/celt/laplace.h @@ -1,55 +1,55 @@ -/* (C) 2007 Jean-Marc Valin, CSIRO -*/ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Xiph.org Foundation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "entenc.h" -#include "entdec.h" - -int ec_laplace_get_start_freq(int decay); - -/** Encode a value that is assumed to be the realisation of a - Laplace-distributed random process - @param enc Entropy encoder state - @param value Value to encode - @param decay Probability of the value +/- 1, multiplied by 16384 -*/ -void ec_laplace_encode(ec_enc *enc, int *value, int decay); - -void ec_laplace_encode_start(ec_enc *enc, int *value, int decay, int fs); - -/** Decode a value that is assumed to be the realisation of a - Laplace-distributed random process - @param dec Entropy decoder state - @param decay Probability of the value +/- 1, multiplied by 16384 - @return Value decoded - */ -int ec_laplace_decode(ec_dec *dec, int decay); - -int ec_laplace_decode_start(ec_dec *dec, int decay, int fs); +/* (C) 2007 Jean-Marc Valin, CSIRO +*/ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "cc6_entenc.h" +#include "cc6_entdec.h" + +int ec_laplace_get_start_freq(int decay); + +/** Encode a value that is assumed to be the realisation of a + Laplace-distributed random process + @param enc Entropy encoder state + @param value Value to encode + @param decay Probability of the value +/- 1, multiplied by 16384 +*/ +void ec_laplace_encode(ec_enc *enc, int *value, int decay); + +void ec_laplace_encode_start(ec_enc *enc, int *value, int decay, int fs); + +/** Decode a value that is assumed to be the realisation of a + Laplace-distributed random process + @param dec Entropy decoder state + @param decay Probability of the value +/- 1, multiplied by 16384 + @return Value decoded + */ +int ec_laplace_decode(ec_dec *dec, int decay); + +int ec_laplace_decode_start(ec_dec *dec, int decay, int fs); diff --git a/libs/celt/mathops.h b/libs/celt/mathops.h index f61359bb..e1e1b534 100755 --- a/libs/celt/mathops.h +++ b/libs/celt/mathops.h @@ -36,7 +36,7 @@ #define MATHOPS_H #include "cc6_arch.h" -#include "entcode.h" +#include "cc6_entcode.h" #include "os_support.h" #ifndef OVERRIDE_CELT_ILOG2 diff --git a/libs/celt/mfrngcod.h b/libs/celt/mfrngcod.h index 666074a0..9ea736a0 100755 --- a/libs/celt/mfrngcod.h +++ b/libs/celt/mfrngcod.h @@ -1,60 +1,60 @@ -/* (C) 2001-2008 Timothy B. Terriberry - (C) 2008 Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Xiph.org Foundation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#if !defined(_mfrngcode_H) -# define _mfrngcode_H (1) -# include "entcode.h" - -/*Constants used by the entropy encoder/decoder.*/ - -/*The number of bits to output at a time.*/ -# define EC_SYM_BITS (8) -/*The total number of bits in each of the state registers.*/ -# define EC_CODE_BITS (32) -/*The maximum symbol value.*/ -# define EC_SYM_MAX ((1U<>EC_SYM_BITS) -/*Code for which propagating carries are possible.*/ -# define EC_CODE_CARRY (((ec_uint32)EC_SYM_MAX)<>EC_SYM_BITS) +/*Code for which propagating carries are possible.*/ +# define EC_CODE_CARRY (((ec_uint32)EC_SYM_MAX)< #include "modes.h" -#include "cwrs.h" +#include "cc6_cwrs.h" #include "cc6_arch.h" #include "os_support.h" -#include "entcode.h" +#include "cc6_entcode.h" #include "rate.h" diff --git a/libs/celt/rate.h b/libs/celt/rate.h index b3ec5703..ac8a3170 100755 --- a/libs/celt/rate.h +++ b/libs/celt/rate.h @@ -1,144 +1,144 @@ -/* (C) 2007-2008 Jean-Marc Valin, CSIRO -*/ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Xiph.org Foundation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef RATE_H -#define RATE_H - -#define MAX_PULSES 128 -#define LOG_MAX_PULSES 7 - -#define BITRES 4 -#define BITROUND 8 -#define BITOVERFLOW 30000 - -#include "cwrs.h" - -static __inline int bits2pulses(const CELTMode *m, const celt_int16_t *cache, int N, int bits) -{ - int i; - int lo, hi; - lo = 0; - hi = MAX_PULSES-1; - -#if 0 /* Disabled until we can make that useful */ - /* Use of more than MAX_PULSES is disabled until we are able to cwrs that decently */ - if (bits > cache[MAX_PULSES-1] && N<=4) - { - /*int pulses; - pulses = 127; - while (16 + log2_frac(2*(pulses+1)*(pulses+1) + 1, 4) <= bits && pulses < 32767) - pulses++;*/ - lo = 127; - switch (N) - { - case 3: - hi = 1024; - for (i=0;i<10;i++) - { - int pulses = (lo+hi)>>1; - if (log2_frac(((UMUL16_16(pulses,pulses)>>1)+1)>>1, 4) > bits) - hi = pulses; - else - lo = pulses; - } - break; - case 4: - hi = 1024; - for (i=0;i<10;i++) - { - int pulses = (lo+hi)>>1; - if (log2_frac((UMUL32(UMUL16_16(pulses,pulses)+2,pulses))/3<<3, 4) > bits) - hi = pulses; - else - lo = pulses; - } - break; - } - return lo; - } -#endif - /* Instead of using the "bisection condition" we use a fixed number of - iterations because it should be faster */ - /*while (hi-lo != 1)*/ - for (i=0;i>1; - /* OPT: Make sure this is implemented with a conditional move */ - if (cache[mid] >= bits) - hi = mid; - else - lo = mid; - } - if (bits-cache[lo] <= cache[hi]-bits) - return lo; - else - return hi; -} - - -static __inline int pulses2bits(const celt_int16_t *cache, int N, int pulses) -{ -#if 0 /* Use of more than MAX_PULSES is disabled until we are able to cwrs that decently */ - if (pulses > 127) - { - int bits; - switch (N) - { - case 3: - bits = log2_frac(((UMUL16_16(pulses,pulses)>>1)+1)>>1, 4); - break; - case 4: - bits = log2_frac((UMUL32(UMUL16_16(pulses,pulses)+2,pulses))/3<<3, 4); - break; - } - /*printf ("%d <- %d\n", bits, pulses);*/ - return bits; - } -#endif - return cache[pulses]; -} - -/** Computes a cache of the pulses->bits mapping in each band */ -celt_int16_t **compute_alloc_cache(CELTMode *m, int C); - -/** Compute the pulse allocation, i.e. how many pulses will go in each - * band. - @param m mode - @param offsets Requested increase or decrease in the number of bits for - each band - @param total Number of bands - @param pulses Number of pulses per band (returned) - @return Total number of bits allocated -*/ -void compute_allocation(const CELTMode *m, int *offsets, int total, int *pulses, int *ebits, int *fine_priority); - - -#endif +/* (C) 2007-2008 Jean-Marc Valin, CSIRO +*/ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef RATE_H +#define RATE_H + +#define MAX_PULSES 128 +#define LOG_MAX_PULSES 7 + +#define BITRES 4 +#define BITROUND 8 +#define BITOVERFLOW 30000 + +#include "cc6_cwrs.h" + +static __inline int bits2pulses(const CELTMode *m, const celt_int16_t *cache, int N, int bits) +{ + int i; + int lo, hi; + lo = 0; + hi = MAX_PULSES-1; + +#if 0 /* Disabled until we can make that useful */ + /* Use of more than MAX_PULSES is disabled until we are able to cwrs that decently */ + if (bits > cache[MAX_PULSES-1] && N<=4) + { + /*int pulses; + pulses = 127; + while (16 + log2_frac(2*(pulses+1)*(pulses+1) + 1, 4) <= bits && pulses < 32767) + pulses++;*/ + lo = 127; + switch (N) + { + case 3: + hi = 1024; + for (i=0;i<10;i++) + { + int pulses = (lo+hi)>>1; + if (log2_frac(((UMUL16_16(pulses,pulses)>>1)+1)>>1, 4) > bits) + hi = pulses; + else + lo = pulses; + } + break; + case 4: + hi = 1024; + for (i=0;i<10;i++) + { + int pulses = (lo+hi)>>1; + if (log2_frac((UMUL32(UMUL16_16(pulses,pulses)+2,pulses))/3<<3, 4) > bits) + hi = pulses; + else + lo = pulses; + } + break; + } + return lo; + } +#endif + /* Instead of using the "bisection condition" we use a fixed number of + iterations because it should be faster */ + /*while (hi-lo != 1)*/ + for (i=0;i>1; + /* OPT: Make sure this is implemented with a conditional move */ + if (cache[mid] >= bits) + hi = mid; + else + lo = mid; + } + if (bits-cache[lo] <= cache[hi]-bits) + return lo; + else + return hi; +} + + +static __inline int pulses2bits(const celt_int16_t *cache, int N, int pulses) +{ +#if 0 /* Use of more than MAX_PULSES is disabled until we are able to cwrs that decently */ + if (pulses > 127) + { + int bits; + switch (N) + { + case 3: + bits = log2_frac(((UMUL16_16(pulses,pulses)>>1)+1)>>1, 4); + break; + case 4: + bits = log2_frac((UMUL32(UMUL16_16(pulses,pulses)+2,pulses))/3<<3, 4); + break; + } + /*printf ("%d <- %d\n", bits, pulses);*/ + return bits; + } +#endif + return cache[pulses]; +} + +/** Computes a cache of the pulses->bits mapping in each band */ +celt_int16_t **compute_alloc_cache(CELTMode *m, int C); + +/** Compute the pulse allocation, i.e. how many pulses will go in each + * band. + @param m mode + @param offsets Requested increase or decrease in the number of bits for + each band + @param total Number of bands + @param pulses Number of pulses per band (returned) + @return Total number of bits allocated +*/ +void compute_allocation(const CELTMode *m, int *offsets, int total, int *pulses, int *ebits, int *fine_priority); + + +#endif diff --git a/libs/celt/vq.c b/libs/celt/vq.c index 90ece54e..a1d5f1c3 100755 --- a/libs/celt/vq.c +++ b/libs/celt/vq.c @@ -34,7 +34,7 @@ #endif #include "mathops.h" -#include "cwrs.h" +#include "cc6_cwrs.h" #include "vq.h" #include "cc6_arch.h" #include "os_support.h" diff --git a/libs/celt/vq.h b/libs/celt/vq.h index 5a0715a1..5c1f0a07 100755 --- a/libs/celt/vq.h +++ b/libs/celt/vq.h @@ -1,79 +1,79 @@ -/* (C) 2007-2008 Jean-Marc Valin, CSIRO -*/ -/** - @file vq.h - @brief Vector quantisation of the residual - */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Xiph.org Foundation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef VQ_H -#define VQ_H - -#include "entenc.h" -#include "entdec.h" -#include "modes.h" - -/** Algebraic pulse-vector quantiser. The signal x is replaced by the sum of - * the pitch and a combination of pulses such that its norm is still equal - * to 1. This is the function that will typically require the most CPU. - * @param x Residual signal to quantise/encode (returns quantised version) - * @param W Perceptual weight to use when optimising (currently unused) - * @param N Number of samples to encode - * @param K Number of pulses to use - * @param p Pitch vector (it is assumed that p+x is a unit vector) - * @param enc Entropy encoder state -*/ -void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, celt_norm_t *P, ec_enc *enc); - -/** Algebraic pulse decoder - * @param x Decoded normalised spectrum (returned) - * @param N Number of samples to decode - * @param K Number of pulses to use - * @param p Pitch vector (automatically added to x) - * @param dec Entropy decoder state - */ -void alg_unquant(celt_norm_t *X, int N, int K, celt_norm_t *P, ec_dec *dec); - -celt_word16_t renormalise_vector(celt_norm_t *X, celt_word16_t value, int N, int stride); - -/** Intra-frame predictor that matches a section of the current frame (at lower - * frequencies) to encode the current band. - * @param x Residual signal to quantise/encode (returns quantised version) - * @param W Perceptual weight - * @param N Number of samples to encode - * @param K Number of pulses to use - * @param Y Lower frequency spectrum to use, normalised to the same standard deviation - * @param P Pitch vector (it is assumed that p+x is a unit vector) - * @param B Stride (number of channels multiplied by the number of MDCTs per frame) - * @param N0 Number of valid offsets - */ -void intra_fold(const CELTMode *m, celt_norm_t * __restrict x, int N, int *pulses, celt_norm_t *Y, celt_norm_t * __restrict P, int N0, int B); - -#endif /* VQ_H */ +/* (C) 2007-2008 Jean-Marc Valin, CSIRO +*/ +/** + @file vq.h + @brief Vector quantisation of the residual + */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef VQ_H +#define VQ_H + +#include "cc6_entenc.h" +#include "cc6_entdec.h" +#include "modes.h" + +/** Algebraic pulse-vector quantiser. The signal x is replaced by the sum of + * the pitch and a combination of pulses such that its norm is still equal + * to 1. This is the function that will typically require the most CPU. + * @param x Residual signal to quantise/encode (returns quantised version) + * @param W Perceptual weight to use when optimising (currently unused) + * @param N Number of samples to encode + * @param K Number of pulses to use + * @param p Pitch vector (it is assumed that p+x is a unit vector) + * @param enc Entropy encoder state +*/ +void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, celt_norm_t *P, ec_enc *enc); + +/** Algebraic pulse decoder + * @param x Decoded normalised spectrum (returned) + * @param N Number of samples to decode + * @param K Number of pulses to use + * @param p Pitch vector (automatically added to x) + * @param dec Entropy decoder state + */ +void alg_unquant(celt_norm_t *X, int N, int K, celt_norm_t *P, ec_dec *dec); + +celt_word16_t renormalise_vector(celt_norm_t *X, celt_word16_t value, int N, int stride); + +/** Intra-frame predictor that matches a section of the current frame (at lower + * frequencies) to encode the current band. + * @param x Residual signal to quantise/encode (returns quantised version) + * @param W Perceptual weight + * @param N Number of samples to encode + * @param K Number of pulses to use + * @param Y Lower frequency spectrum to use, normalised to the same standard deviation + * @param P Pitch vector (it is assumed that p+x is a unit vector) + * @param B Stride (number of channels multiplied by the number of MDCTs per frame) + * @param N0 Number of valid offsets + */ +void intra_fold(const CELTMode *m, celt_norm_t * __restrict x, int N, int *pulses, celt_norm_t *Y, celt_norm_t * __restrict P, int N0, int B); + +#endif /* VQ_H */ diff --git a/llcon.pro b/llcon.pro index 70f1221c..ca94f04c 100755 --- a/llcon.pro +++ b/llcon.pro @@ -103,11 +103,11 @@ HEADERS += src/audiomixerboard.h \ libs/celt/cc6_bands.h \ libs/celt/fixed_c5x.h \ libs/celt/fixed_c6x.h \ - libs/celt/cwrs.h \ - libs/celt/ecintrin.h \ - libs/celt/entcode.h \ - libs/celt/entdec.h \ - libs/celt/entenc.h \ + libs/celt/cc6_cwrs.h \ + libs/celt/cc6_ecintrin.h \ + libs/celt/cc6_entcode.h \ + libs/celt/cc6_entdec.h \ + libs/celt/cc6_entenc.h \ libs/celt/fixed_generic.h \ libs/celt/float_cast.h \ libs/celt/kfft_double.h \ @@ -150,9 +150,9 @@ SOURCES += src/audiomixerboard.cpp \ libs/celt/cc6_bands.c \ libs/celt/cc6_celt.c \ libs/celt/cc6_cwrs.c \ - libs/celt/entcode.c \ - libs/celt/entdec.c \ - libs/celt/entenc.c \ + libs/celt/cc6_entcode.c \ + libs/celt/cc6_entdec.c \ + libs/celt/cc6_entenc.c \ libs/celt/header.c \ libs/celt/kfft_single.c \ libs/celt/cc6__kiss_fft.c \