diff --git a/external/celt-0.11.1/fixed_c5x.h b/external/celt-0.11.1/fixed_c5x.h deleted file mode 100644 index 7e2aa32..0000000 --- a/external/celt-0.11.1/fixed_c5x.h +++ /dev/null @@ -1,89 +0,0 @@ -/* Copyright (C) 2003 Jean-Marc Valin */ -/** - @file fixed_c5x.h - @brief Fixed-point operations for the TI C5x DSP family -*/ -/* - 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. - - 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 FIXED_C5X_H -#define FIXED_C5X_H - -#include "dsplib.h" - -#undef IMUL32 -static inline long IMUL32(long i, long j) -{ - long ac0, ac1; - ac0 = _lmpy(i>>16,j); - ac1 = ac0 + _lmpy(i,j>>16); - return _lmpyu(i,j) + (ac1<<16); -} - -#undef MAX16 -#define MAX16(a,b) _max(a,b) - -#undef MIN16 -#define MIN16(a,b) _min(a,b) - -#undef MAX32 -#define MAX32(a,b) _lmax(a,b) - -#undef MIN32 -#define MIN32(a,b) _lmin(a,b) - -#undef VSHR32 -#define VSHR32(a, shift) _lshl(a,-(shift)) - -#undef MULT16_16_Q15 -#define MULT16_16_Q15(a,b) (_smpy(a,b)) - -#undef MULT16_16SU -#define MULT16_16SU(a,b) _lmpysu(a,b) - -#undef MULT_16_16 -#define MULT_16_16(a,b) _lmpy(a,b) - -/* FIXME: This is technically incorrect and is bound to cause problems. Is there any cleaner solution? */ -#undef MULT16_32_Q15 -#define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),(b)),15)) - - -#define celt_ilog2(x) (30 - _lnorm(x)) -#define OVERRIDE_CELT_ILOG2 - -#define celt_maxabs16(x, len) MAX16(maxval((DATA *)x, len),-minval((DATA *)x, len)) -#define OVERRIDE_CELT_MAXABS16 - -#define OVERRIDE_FIND_MAX16 -static inline int find_max16(celt_word16 *x, int len) -{ - DATA max_corr16 = -VERY_LARGE16; - DATA pitch16 = 0; - maxvec((DATA *)x, len, &max_corr16, &pitch16); - return pitch16; -} - -#endif /* FIXED_C5X_H */ diff --git a/external/celt-0.11.1/fixed_c6x.h b/external/celt-0.11.1/fixed_c6x.h deleted file mode 100644 index 47b851a..0000000 --- a/external/celt-0.11.1/fixed_c6x.h +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (C) 2008 CSIRO */ -/** - @file fixed_c6x.h - @brief Fixed-point operations for the TI C6x DSP family -*/ -/* - 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. - - 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 FIXED_C6X_H -#define FIXED_C6X_H - -#undef MULT16_16SU -#define MULT16_16SU(a,b) _mpysu(a,b) - -#undef MULT_16_16 -#define MULT_16_16(a,b) _mpy(a,b) - -#define celt_ilog2(x) (30 - _norm(x)) -#define OVERRIDE_CELT_ILOG2 - -#undef MULT16_32_Q15 -#define MULT16_32_Q15(a,b) (_mpylill(a, b) >> 15) - -#if 0 -#include "dsplib.h" - -#undef MAX16 -#define MAX16(a,b) _max(a,b) - -#undef MIN16 -#define MIN16(a,b) _min(a,b) - -#undef MAX32 -#define MAX32(a,b) _lmax(a,b) - -#undef MIN32 -#define MIN32(a,b) _lmin(a,b) - -#undef VSHR32 -#define VSHR32(a, shift) _lshl(a,-(shift)) - -#undef MULT16_16_Q15 -#define MULT16_16_Q15(a,b) (_smpy(a,b)) - -#define celt_maxabs16(x, len) MAX16(maxval((DATA *)x, len),-minval((DATA *)x, len)) -#define OVERRIDE_CELT_MAXABS16 - -#define OVERRIDE_FIND_MAX16 -static inline int find_max16(celt_word16 *x, int len) -{ - DATA max_corr16 = -VERY_LARGE16; - DATA pitch16 = 0; - maxvec((DATA *)x, len, &max_corr16, &pitch16); - return pitch16; -} -#endif - -#endif /* FIXED_C6X_H */ diff --git a/external/celt-0.11.1/COPYING b/external/celt-e18de77/COPYING similarity index 100% rename from external/celt-0.11.1/COPYING rename to external/celt-e18de77/COPYING diff --git a/external/celt-0.11.1/README b/external/celt-e18de77/README similarity index 100% rename from external/celt-0.11.1/README rename to external/celt-e18de77/README diff --git a/external/celt-e18de77/README.Win32 b/external/celt-e18de77/README.Win32 new file mode 100644 index 0000000..4694994 --- /dev/null +++ b/external/celt-e18de77/README.Win32 @@ -0,0 +1,10 @@ +Here are a few tips for building on Windows: + +1) Create a config.h file that defines out things that defines out all the + features that your compiler doesn't understand (e.g. inline, restrict). + It also needs to define the CELT_BUILD macro + +2) Define the HAVE_CONFIG_H macro in the project build options (NOT in config.h) + +3) If you want things to be a lot easier, just use a compiler that supports + C99, such as gcc diff --git a/external/celt-0.11.1/_kiss_fft_guts.h b/external/celt-e18de77/_kiss_fft_guts.h similarity index 100% rename from external/celt-0.11.1/_kiss_fft_guts.h rename to external/celt-e18de77/_kiss_fft_guts.h diff --git a/external/celt-0.11.1/arch.h b/external/celt-e18de77/arch.h similarity index 100% rename from external/celt-0.11.1/arch.h rename to external/celt-e18de77/arch.h diff --git a/external/celt-0.11.1/bands.c b/external/celt-e18de77/bands.c similarity index 99% rename from external/celt-0.11.1/bands.c rename to external/celt-e18de77/bands.c index 1948bae..d51feee 100644 --- a/external/celt-0.11.1/bands.c +++ b/external/celt-e18de77/bands.c @@ -1161,7 +1161,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c void quant_all_bands(int encode, const CELTMode *m, int start, int end, celt_norm *_X, celt_norm *_Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses, int shortBlocks, int spread, int dual_stereo, int intensity, int *tf_res, int resynth, - celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int LM, int codedBands, ec_uint32 *seed) + celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int LM, int codedBands, celt_uint32 *seed) { int i; celt_int32 remaining_bits; diff --git a/external/celt-0.11.1/bands.h b/external/celt-e18de77/bands.h similarity index 99% rename from external/celt-0.11.1/bands.h rename to external/celt-e18de77/bands.h index d0fcf1b..d3d3dc8 100644 --- a/external/celt-0.11.1/bands.h +++ b/external/celt-e18de77/bands.h @@ -84,7 +84,7 @@ void haar1(celt_norm *X, int N0, int stride); void quant_all_bands(int encode, const CELTMode *m, int start, int end, celt_norm * X, celt_norm * Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses, int time_domain, int fold, int dual_stereo, int intensity, int *tf_res, int resynth, - celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int M, int codedBands, ec_uint32 *seed); + celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int M, int codedBands, celt_uint32 *seed); void stereo_decision(const CELTMode *m, celt_norm * restrict X, int *stereo_mode, int len, int M); diff --git a/external/celt-0.11.1/celt.c b/external/celt-e18de77/celt.c similarity index 91% rename from external/celt-0.11.1/celt.c rename to external/celt-e18de77/celt.c index 23d2e30..671ac58 100644 --- a/external/celt-0.11.1/celt.c +++ b/external/celt-e18de77/celt.c @@ -61,6 +61,40 @@ static const unsigned char spread_icdf[4] = {25, 23, 2, 0}; static const unsigned char tapset_icdf[3]={2,1,0}; +static const unsigned char toOpusTable[20] = { + 0xE0, 0xE8, 0xF0, 0xF8, + 0xC0, 0xC8, 0xD0, 0xD8, + 0xA0, 0xA8, 0xB0, 0xB8, + 0x00, 0x00, 0x00, 0x00, + 0x80, 0x88, 0x90, 0x98, +}; + +static const unsigned char fromOpusTable[16] = { + 0x80, 0x88, 0x90, 0x98, + 0x40, 0x48, 0x50, 0x58, + 0x20, 0x28, 0x30, 0x38, + 0x00, 0x08, 0x10, 0x18 +}; + +static inline int toOpus(unsigned char c) +{ + int ret=0; + if (c<0xA0) + ret = toOpusTable[c>>3]; + if (ret == 0) + return -1; + else + return ret|(c&0x7); +} + +static inline int fromOpus(unsigned char c) +{ + if (c<0x80) + return -1; + else + return fromOpusTable[(c>>3)-16] | (c&0x7); +} + #define COMBFILTER_MAXPERIOD 1024 #define COMBFILTER_MINPERIOD 15 @@ -108,14 +142,16 @@ struct CELTEncoder { celt_int32 bitrate; int vbr; + int signalling; int constrained_vbr; /* If zero, VBR can do whatever it likes with the rate */ + int loss_rate; /* Everything beyond this point gets cleared on a reset */ #define ENCODER_RESET_START rng - ec_uint32 rng; + celt_uint32 rng; int spread_decision; - int delayedIntra; + celt_word32 delayedIntra; int tonal_average; int lastCodedBands; int hf_average; @@ -226,6 +262,8 @@ CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int st->upsample = 1; st->start = 0; st->end = st->mode->effEBands; + st->signalling = 1; + st->constrained_vbr = 1; st->clip = 1; @@ -317,9 +355,9 @@ static int transient_analysis(const celt_word32 * restrict in, int len, int C, for (i=0;istorage*8; tell = ec_tell(enc); logp = isTransient ? 2 : 4; @@ -727,8 +765,8 @@ static void tf_decode(int start, int end, int isTransient, int *tf_res, int LM, int tf_select_rsv; int tf_changed; int logp; - ec_uint32 budget; - ec_uint32 tell; + celt_uint32 budget; + celt_uint32 tell; budget = dec->storage*8; tell = ec_tell(dec); @@ -915,13 +953,11 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i int anti_collapse_rsv; int anti_collapse_on=0; int silence=0; - SAVE_STACK; + ALLOC_STACK; if (nbCompressedBytes<2 || pcm==NULL) return CELT_BAD_ARG; - /* Can't produce more than 1275 output bytes */ - nbCompressedBytes = IMIN(nbCompressedBytes,1275); frame_size *= st->upsample; for (LM=0;LM<=st->mode->maxLM;LM++) if (st->mode->shortMdctSize<>3; } + + if (st->signalling && enc==NULL) + { + int tmp = (st->mode->effEBands-st->end)>>1; + st->end = IMAX(1, st->mode->effEBands-tmp); + compressed[0] = tmp<<5; + compressed[0] |= LM<<3; + compressed[0] |= (C==2)<<2; + /* Convert "standard mode" to Opus header */ + if (st->mode->Fs==48000 && st->mode->shortMdctSize==120) + { + int c0 = toOpus(compressed[0]); + if (c0<0) + return CELT_BAD_ARG; + compressed[0] = c0; + } + compressed++; + nbCompressedBytes--; + } + + /* Can't produce more than 1275 output bytes */ + nbCompressedBytes = IMIN(nbCompressedBytes,1275); nbAvailableBytes = nbCompressedBytes - nbFilledBytes; if (st->vbr) { celt_int32 den=st->mode->Fs>>BITRES; vbr_rate=(st->bitrate*frame_size+(den>>1))/den; - effectiveBytes = vbr_rate>>3; + if (st->signalling) + vbr_rate -= 8<>(3+BITRES); } else { celt_int32 tmp; vbr_rate = 0; @@ -960,7 +1020,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i if (tell>1) tmp += tell; nbCompressedBytes = IMAX(2, IMIN(nbCompressedBytes, - (tmp+4*st->mode->Fs)/(8*st->mode->Fs))); + (tmp+4*st->mode->Fs)/(8*st->mode->Fs)-!!st->signalling)); effectiveBytes = nbCompressedBytes; } @@ -1083,6 +1143,12 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i if (pitch_index > COMBFILTER_MAXPERIOD-2) pitch_index = COMBFILTER_MAXPERIOD-2; gain1 = MULT16_16_Q15(QCONST16(.7f,15),gain1); + if (st->loss_rate>2) + gain1 = HALF32(gain1); + if (st->loss_rate>4) + gain1 = HALF32(gain1); + if (st->loss_rate>8) + gain1 = 0; prefilter_tapset = st->tapset_decision; } else { gain1 = 0; @@ -1238,7 +1304,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i quant_coarse_energy(st->mode, st->start, st->end, effEnd, bandLogE, oldBandE, total_bits, error, enc, C, LM, nbAvailableBytes, st->force_intra, - &st->delayedIntra, st->complexity >= 4); + &st->delayedIntra, st->complexity >= 4, st->loss_rate); tf_encode(st->start, st->end, isTransient, tf_res, LM, tf_select, enc); @@ -1366,17 +1432,23 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i nbAvailableBytes = IMAX(min_allowed,nbAvailableBytes); nbAvailableBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes) - nbFilledBytes; - if(silence) - { - nbAvailableBytes = 2; - target = 2*8<vbr_count < 970) { st->vbr_count++; @@ -1603,9 +1675,12 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i it's already filled with zeros */ ec_enc_done(enc); + if (st->signalling) + nbCompressedBytes++; + RESTORE_STACK; if (ec_get_error(enc)) - return CELT_CORRUPTED_DATA; + return CELT_INTERNAL_ERROR; else return nbCompressedBytes; } @@ -1618,7 +1693,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, int int j, ret, C, N; VARDECL(celt_int16, in); ALLOC_STACK; - SAVE_STACK; if (pcm==NULL) return CELT_BAD_ARG; @@ -1647,7 +1721,6 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, int f int j, ret, C, N; VARDECL(celt_sig, in); ALLOC_STACK; - SAVE_STACK; if (pcm==NULL) return CELT_BAD_ARG; @@ -1688,14 +1761,6 @@ int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...) va_start(ap, request); switch (request) { - case CELT_GET_MODE_REQUEST: - { - const CELTMode ** value = va_arg(ap, const CELTMode**); - if (value==0) - goto bad_arg; - *value=st->mode; - } - break; case CELT_SET_COMPLEXITY_REQUEST: { int value = va_arg(ap, celt_int32); @@ -1729,6 +1794,14 @@ int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...) st->force_intra = value==0; } break; + case CELT_SET_LOSS_PERC_REQUEST: + { + int value = va_arg(ap, celt_int32); + if (value<0 || value>100) + goto bad_arg; + st->loss_rate = value; + } + break; case CELT_SET_VBR_CONSTRAINT_REQUEST: { celt_int32 value = va_arg(ap, celt_int32); @@ -1775,6 +1848,22 @@ int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...) st->clip = value; } break; +#ifdef OPUS_BUILD + case CELT_SET_SIGNALLING_REQUEST: + { + celt_int32 value = va_arg(ap, celt_int32); + st->signalling = value; + } + break; + case CELT_GET_MODE_REQUEST: + { + const CELTMode ** value = va_arg(ap, const CELTMode**); + if (value==0) + goto bad_arg; + *value=st->mode; + } + break; +#endif default: goto bad_request; } @@ -1806,11 +1895,13 @@ struct CELTDecoder { int downsample; int start, end; + int signalling; /* Everything beyond this point gets cleared on a reset */ #define DECODER_RESET_START rng - ec_uint32 rng; + celt_uint32 rng; + int error; int last_pitch_index; int loss_count; int postfilter_period; @@ -1824,10 +1915,10 @@ struct CELTDecoder { celt_sig _decode_mem[1]; /* Size = channels*(DECODE_BUFFER_SIZE+mode->overlap) */ /* celt_word16 lpc[], Size = channels*LPC_ORDER */ - /* celt_word16 oldEBands[], Size = channels*mode->nbEBands */ - /* celt_word16 oldLogE[], Size = channels*mode->nbEBands */ - /* celt_word16 oldLogE2[], Size = channels*mode->nbEBands */ - /* celt_word16 backgroundLogE[], Size = channels*mode->nbEBands */ + /* celt_word16 oldEBands[], Size = 2*mode->nbEBands */ + /* celt_word16 oldLogE[], Size = 2*mode->nbEBands */ + /* celt_word16 oldLogE2[], Size = 2*mode->nbEBands */ + /* celt_word16 backgroundLogE[], Size = 2*mode->nbEBands */ }; int celt_decoder_get_size(int channels) @@ -1841,7 +1932,7 @@ int celt_decoder_get_size_custom(const CELTMode *mode, int channels) int size = sizeof(struct CELTDecoder) + (channels*(DECODE_BUFFER_SIZE+mode->overlap)-1)*sizeof(celt_sig) + channels*LPC_ORDER*sizeof(celt_word16) - + 4*channels*mode->nbEBands*sizeof(celt_word16); + + 4*2*mode->nbEBands*sizeof(celt_word16); return size; } @@ -1906,6 +1997,7 @@ CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int st->downsample = 1; st->start = 0; st->end = st->mode->effEBands; + st->signalling = 1; st->loss_count = 0; @@ -1959,6 +2051,11 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p VARDECL(celt_norm, X); VARDECL(celt_ener, bandE); celt_uint32 seed; + int effEnd; + + effEnd = st->end; + if (effEnd > st->mode->effEBands) + effEnd = st->mode->effEBands; ALLOC(freq, C*N, celt_sig); /**< Interleaved signal MDCTs */ ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ @@ -1967,18 +2064,42 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p log2Amp(st->mode, st->start, st->end, bandE, backgroundLogE, C); seed = st->rng; - for (i=0;i>20; + for (i=0;i<(st->mode->eBands[st->start]<mode->effEBands;i++) + { + int j; + int boffs; + int blen; + boffs = N*c+(st->mode->eBands[i]<mode->eBands[i+1]-st->mode->eBands[i])<>20; + } + renormalise_vector(X+boffs, blen, Q15ONE); + } + for (i=(st->mode->eBands[st->end]<rng = seed; - for (c=0;cmode->nbEBands;i++) - renormalise_vector(X+N*c+(st->mode->eBands[i]<mode->eBands[i+1]-st->mode->eBands[i])<mode, X, freq, bandE, st->mode->nbEBands, C, 1<mode, X, freq, bandE, st->mode->effEBands, C, 1<mode->eBands[st->start]<mode->eBands[effEnd]<downsample!=1) + bound = IMIN(bound, N/st->downsample); + for (i=bound;imode, 0, freq, out_syn, overlap_mem, C, LM); plc = 0; } else if (st->loss_count == 0) @@ -2194,20 +2315,10 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da int anti_collapse_rsv; int anti_collapse_on=0; int silence; - const int C = CHANNELS(st->stream_channels); - - SAVE_STACK; - - if (len<0 || len>1275 || pcm==NULL) - return CELT_BAD_ARG; + int C = CHANNELS(st->stream_channels); + ALLOC_STACK; frame_size *= st->downsample; - for (LM=0;LM<=st->mode->maxLM;LM++) - if (st->mode->shortMdctSize<st->mode->maxLM) - return CELT_BAD_ARG; - M=1<_decode_mem + c*(DECODE_BUFFER_SIZE+st->overlap); @@ -2215,10 +2326,43 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da overlap_mem[c] = decode_mem[c]+DECODE_BUFFER_SIZE; } while (++c_decode_mem+(DECODE_BUFFER_SIZE+st->overlap)*CC); - oldBandE = lpc+CC*LPC_ORDER; - oldLogE = oldBandE + CC*st->mode->nbEBands; - oldLogE2 = oldLogE + CC*st->mode->nbEBands; - backgroundLogE = oldLogE2 + CC*st->mode->nbEBands; + oldBandE = lpc+LPC_ORDER; + oldLogE = oldBandE + 2*st->mode->nbEBands; + oldLogE2 = oldLogE + 2*st->mode->nbEBands; + backgroundLogE = oldLogE2 + 2*st->mode->nbEBands; + + if (st->signalling && data!=NULL) + { + int data0=data[0]; + /* Convert "standard mode" to Opus header */ + if (st->mode->Fs==48000 && st->mode->shortMdctSize==120) + { + data0 = fromOpus(data0); + if (data0<0) + return CELT_CORRUPTED_DATA; + } + st->end = IMAX(1, st->mode->effEBands-2*(data0>>5)); + LM = (data0>>3)&0x3; + C = 1 + ((data0>>2)&0x1); + data++; + len--; + if (LM>st->mode->maxLM) + return CELT_CORRUPTED_DATA; + if (frame_size < st->mode->shortMdctSize<mode->shortMdctSize<mode->maxLM;LM++) + if (st->mode->shortMdctSize<st->mode->maxLM) + return CELT_BAD_ARG; + } + M=1<1275 || pcm==NULL) + return CELT_BAD_ARG; N = M*st->mode->shortMdctSize; @@ -2226,40 +2370,36 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da if (effEnd > st->mode->effEBands) effEnd = st->mode->effEBands; - ALLOC(freq, CC*N, celt_sig); /**< Interleaved signal MDCTs */ - ALLOC(X, CC*N, celt_norm); /**< Interleaved normalised MDCTs */ - ALLOC(bandE, st->mode->nbEBands*CC, celt_ener); + ALLOC(freq, IMAX(CC,C)*N, celt_sig); /**< Interleaved signal MDCTs */ + ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ + ALLOC(bandE, st->mode->nbEBands*C, celt_ener); c=0; do for (i=0;imode->eBands[st->start];i++) X[c*N+i] = 0; - while (++cmode->eBands[effEnd];idownsample; } if (len<0) { RESTORE_STACK; return CELT_BAD_ARG; } - + if (dec == NULL) { ec_dec_init(&_dec,(unsigned char*)data,len); dec = &_dec; } - if (C>CC) - { - RESTORE_STACK; - return CELT_CORRUPTED_DATA; - } else if (Cmode->nbEBands;i++) oldBandE[i]=MAX16(oldBandE[i],oldBandE[st->mode->nbEBands+i]); @@ -2395,7 +2535,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da fine_quant, fine_priority, len*8-ec_tell(dec), dec, C); if (anti_collapse_on) - anti_collapse(st->mode, X, collapse_masks, LM, C, CC, N, + anti_collapse(st->mode, X, collapse_masks, LM, C, C, N, st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng); log2Amp(st->mode, st->start, st->end, bandE, oldBandE, C); @@ -2436,6 +2576,11 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da for (i=0;imode, shortBlocks, freq, out_syn, overlap_mem, CC, LM); @@ -2467,7 +2612,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da } #endif /* ENABLE_POSTFILTER */ - if (CC==2&&C==1) { + if (C==1) { for (i=0;imode->nbEBands;i++) oldBandE[st->mode->nbEBands+i]=oldBandE[i]; } @@ -2479,17 +2624,17 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da oldBandE[c*st->mode->nbEBands+i]=0; for (i=st->end;imode->nbEBands;i++) oldBandE[c*st->mode->nbEBands+i]=0; - } while (++cmode->nbEBands;i++) + for (i=0;i<2*st->mode->nbEBands;i++) oldLogE2[i] = oldLogE[i]; - for (i=0;imode->nbEBands;i++) + for (i=0;i<2*st->mode->nbEBands;i++) oldLogE[i] = oldBandE[i]; - for (i=0;imode->nbEBands;i++) + for (i=0;i<2*st->mode->nbEBands;i++) backgroundLogE[i] = MIN16(backgroundLogE[i] + M*QCONST16(0.001f,DB_SHIFT), oldBandE[i]); } else { - for (i=0;imode->nbEBands;i++) + for (i=0;i<2*st->mode->nbEBands;i++) oldLogE[i] = MIN16(oldLogE[i], oldBandE[i]); } st->rng = dec->rng; @@ -2497,10 +2642,11 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da deemphasis(out_syn, pcm, N, CC, st->downsample, st->mode->preemph, st->preemph_memD); st->loss_count = 0; RESTORE_STACK; - if (ec_tell(dec) > 8*len || ec_get_error(dec)) - return CELT_CORRUPTED_DATA; - else - return CELT_OK; + if (ec_tell(dec) > 8*len) + return CELT_INTERNAL_ERROR; + if(ec_get_error(dec)) + st->error = 1; + return frame_size/st->downsample; } #ifdef FIXED_POINT @@ -2511,7 +2657,6 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da int j, ret, C, N; VARDECL(celt_int16, out); ALLOC_STACK; - SAVE_STACK; if (pcm==NULL) return CELT_BAD_ARG; @@ -2521,8 +2666,8 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da ALLOC(out, C*N, celt_int16); ret=celt_decode_with_ec(st, data, len, out, frame_size, dec); - if (ret==0) - for (j=0;j0) + for (j=0;j0) + for (j=0;jmode; - } - break; case CELT_SET_START_BAND_REQUEST: { celt_int32 value = va_arg(ap, celt_int32); @@ -2607,6 +2743,23 @@ int celt_decoder_ctl(CELTDecoder * restrict st, int request, ...) st->stream_channels = value; } break; + case CELT_GET_AND_CLEAR_ERROR_REQUEST: + { + int *value = va_arg(ap, int*); + if (value==NULL) + goto bad_arg; + *value=st->error; + st->error = 0; + } + break; + case CELT_GET_LOOKAHEAD_REQUEST: + { + int *value = va_arg(ap, int*); + if (value==NULL) + goto bad_arg; + *value = st->overlap/st->downsample; + } + break; case CELT_RESET_STATE: { CELT_MEMSET((char*)&st->DECODER_RESET_START, 0, @@ -2614,6 +2767,22 @@ int celt_decoder_ctl(CELTDecoder * restrict st, int request, ...) ((char*)&st->DECODER_RESET_START - (char*)st)); } break; +#ifdef OPUS_BUILD + case CELT_GET_MODE_REQUEST: + { + const CELTMode ** value = va_arg(ap, const CELTMode**); + if (value==0) + goto bad_arg; + *value=st->mode; + } + break; + case CELT_SET_SIGNALLING_REQUEST: + { + celt_int32 value = va_arg(ap, celt_int32); + st->signalling = value; + } + break; +#endif default: goto bad_request; } @@ -2632,7 +2801,7 @@ const char *celt_strerror(int error) static const char *error_strings[8] = { "success", "invalid argument", - "invalid mode", + "buffer too small", "internal error", "corrupted stream", "request not implemented", diff --git a/external/celt-e18de77/config.h b/external/celt-e18de77/config.h new file mode 100644 index 0000000..4abd80d --- /dev/null +++ b/external/celt-e18de77/config.h @@ -0,0 +1,27 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define CELT_BUILD 1 + +#define restrict +#define inline __inline + +#define USE_ALLOCA 1 + +/* Comment out the next line for floating-point code */ +//#define FIXED_POINT 1 + +#define OPUS_BUILD 1 + +/* Get rid of the CELT VS compile warnings */ +#if 1 +#pragma warning(disable : 4018)// signed/unsigned mismatch +#pragma warning(disable : 4244)// conversion from 'double' to 'celt_word16', possible loss of data +#pragma warning(disable : 4267)// conversion from 'size_t' to 'int', possible loss of data +#pragma warning(disable : 4305)// truncation from 'double' to 'const float' +#pragma warning(disable : 4311)// pointer truncation from 'char *' to 'long' +#pragma warning(disable : 4554)// check operator precedence for possible error; use parentheses to clarify precedence +#pragma warning(disable : 4996)// This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. +#endif + +#endif CONFIG_H diff --git a/external/celt-0.11.1/cwrs.c b/external/celt-e18de77/cwrs.c similarity index 99% rename from external/celt-0.11.1/cwrs.c rename to external/celt-e18de77/cwrs.c index 40dcc55..21d278f 100644 --- a/external/celt-0.11.1/cwrs.c +++ b/external/celt-e18de77/cwrs.c @@ -42,7 +42,7 @@ with frac bits of fractional precision. Tested for all possible 32-bit inputs with frac=4, where the maximum overestimation is 0.06254243 bits.*/ -int log2_frac(ec_uint32 val, int frac) +int log2_frac(celt_uint32 val, int frac) { int l; l=EC_ILOG(val); diff --git a/external/celt-0.11.1/cwrs.h b/external/celt-e18de77/cwrs.h similarity index 97% rename from external/celt-0.11.1/cwrs.h rename to external/celt-e18de77/cwrs.h index 1224a26..443213f 100644 --- a/external/celt-0.11.1/cwrs.h +++ b/external/celt-e18de77/cwrs.h @@ -35,7 +35,7 @@ #include "entenc.h" #include "entdec.h" -int log2_frac(ec_uint32 val, int frac); +int log2_frac(celt_uint32 val, int frac); void get_required_bits(celt_int16 *bits, int N, int K, int frac); diff --git a/external/celt-0.11.1/ecintrin.h b/external/celt-e18de77/ecintrin.h similarity index 96% rename from external/celt-0.11.1/ecintrin.h rename to external/celt-e18de77/ecintrin.h index 4591d07..5012917 100644 --- a/external/celt-0.11.1/ecintrin.h +++ b/external/celt-e18de77/ecintrin.h @@ -26,6 +26,7 @@ */ /*Some common macros for potential platform-specific optimization.*/ +#include "celt_types.h" #include #include #if !defined(_ecintrin_H) @@ -81,6 +82,9 @@ All other code should use EC_ILOG() instead.*/ #if defined(_MSC_VER) # include +/*In _DEBUG mode this is not an intrinsic by default.*/ +# pragma intrinsic(_BitScanReverse) + static __inline int ec_bsr(unsigned long _x){ unsigned long ret; _BitScanReverse(&ret,_x); @@ -91,7 +95,7 @@ static __inline int ec_bsr(unsigned long _x){ #elif defined(ENABLE_TI_DSPLIB) # include "dsplib.h" # define EC_CLZ0 (31) -# define EC_CLZ(_x) (_lnorm(x)) +# define EC_CLZ(_x) (_lnorm(_x)) #elif defined(__GNUC_PREREQ) # if __GNUC_PREREQ(3,4) # if INT_MAX>=2147483647 @@ -111,6 +115,8 @@ static __inline int ec_bsr(unsigned long _x){ When we need to, it can be special cased.*/ # define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x)) #else +int ec_ilog(celt_uint32 _v); + # define EC_ILOG(_x) (ec_ilog(_x)) #endif diff --git a/external/celt-0.11.1/entcode.c b/external/celt-e18de77/entcode.c similarity index 95% rename from external/celt-0.11.1/entcode.c rename to external/celt-e18de77/entcode.c index 17d08df..0626e51 100644 --- a/external/celt-0.11.1/entcode.c +++ b/external/celt-e18de77/entcode.c @@ -34,7 +34,7 @@ #if !defined(EC_CLZ) -int ec_ilog(ec_uint32 _v){ +int ec_ilog(celt_uint32 _v){ /*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.*/ @@ -59,11 +59,11 @@ int ec_ilog(ec_uint32 _v){ #endif -ec_uint32 ec_tell_frac(ec_ctx *_this){ - ec_uint32 nbits; - ec_uint32 r; - int l; - int i; +celt_uint32 ec_tell_frac(ec_ctx *_this){ + celt_uint32 nbits; + celt_uint32 r; + int l; + int i; /*To handle the non-integral number of bits still left in the encoder/decoder state, we compute the worst-case number of bits of val that must be encoded to ensure that the value is inside the range for any possible diff --git a/external/celt-0.11.1/entcode.h b/external/celt-e18de77/entcode.h similarity index 89% rename from external/celt-0.11.1/entcode.h rename to external/celt-e18de77/entcode.h index 581a07b..f24e1c4 100644 --- a/external/celt-0.11.1/entcode.h +++ b/external/celt-e18de77/entcode.h @@ -35,8 +35,8 @@ -typedef celt_int32 ec_int32; -typedef celt_uint32 ec_uint32; +/*OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a + larger type, you can speed up the decoder by using it here.*/ typedef celt_uint32 ec_window; typedef struct ec_ctx ec_ctx; typedef struct ec_ctx ec_enc; @@ -44,8 +44,6 @@ typedef struct ec_ctx ec_dec; -/*OPT: This must be at least 32 bits, but if you have fast arithmetic on a - larger type, you can speed up the decoder by using it for ec_window.*/ # define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT) /*The number of bits to use for the range-coded part of unsigned integers.*/ @@ -64,9 +62,9 @@ struct ec_ctx{ /*Buffered input/output.*/ unsigned char *buf; /*The size of the buffer.*/ - ec_uint32 storage; + celt_uint32 storage; /*The offset at which the last byte containing raw bits was read/written.*/ - ec_uint32 end_offs; + celt_uint32 end_offs; /*Bits that will be read from/written at the end.*/ ec_window end_window; /*Number of valid bits in end_window.*/ @@ -75,16 +73,16 @@ struct ec_ctx{ This does not include partial bits currently in the range coder.*/ int nbits_total; /*The offset at which the next range coder byte will be read/written.*/ - ec_uint32 offs; + celt_uint32 offs; /*The number of values in the current range.*/ - ec_uint32 rng; + celt_uint32 rng; /*In the decoder: the difference between the top of the current range and the input value, minus one. In the encoder: the low end of the current range.*/ - ec_uint32 val; + celt_uint32 val; /*In the decoder: the saved normalization factor from ec_decode(). In the encoder: the number of oustanding carry propagating symbols.*/ - ec_uint32 ext; + celt_uint32 ext; /*A buffered input/output symbol, awaiting carry propagation.*/ int rem; /*Nonzero if an error occurred.*/ @@ -97,7 +95,7 @@ static inline void ec_reset(ec_ctx *_this){ _this->offs=_this->end_offs=0; } -static inline ec_uint32 ec_range_bytes(ec_ctx *_this){ +static inline celt_uint32 ec_range_bytes(ec_ctx *_this){ return _this->offs; } @@ -125,8 +123,6 @@ static inline int ec_tell(ec_ctx *_this){ Return: The number of bits scaled by 2**BITRES. This will always be slightly larger than the exact value (e.g., all rounding error is in the positive direction).*/ -ec_uint32 ec_tell_frac(ec_ctx *_this); - -int ec_ilog(ec_uint32 _v); +celt_uint32 ec_tell_frac(ec_ctx *_this); #endif diff --git a/external/celt-0.11.1/entdec.c b/external/celt-e18de77/entdec.c similarity index 93% rename from external/celt-0.11.1/entdec.c rename to external/celt-e18de77/entdec.c index f5676c6..8b4d2ee 100644 --- a/external/celt-0.11.1/entdec.c +++ b/external/celt-e18de77/entdec.c @@ -125,7 +125,7 @@ static void ec_dec_normalize(ec_dec *_this){ } } -void ec_dec_init(ec_dec *_this,unsigned char *_buf,ec_uint32 _storage){ +void ec_dec_init(ec_dec *_this,unsigned char *_buf,celt_uint32 _storage){ _this->buf=_buf; _this->storage=_storage; _this->end_offs=0; @@ -160,7 +160,7 @@ unsigned ec_decode_bin(ec_dec *_this,unsigned _bits){ } void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){ - ec_uint32 s; + celt_uint32 s; s=IMUL32(_this->ext,_ft-_fh); _this->val-=s; _this->rng=_fl>0?IMUL32(_this->ext,_fh-_fl):_this->rng-s; @@ -169,10 +169,10 @@ void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){ /*The probability of having a "one" is 1/(1<<_logp).*/ int ec_dec_bit_logp(ec_dec *_this,unsigned _logp){ - ec_uint32 r; - ec_uint32 d; - ec_uint32 s; - int ret; + celt_uint32 r; + celt_uint32 d; + celt_uint32 s; + int ret; r=_this->rng; d=_this->val; s=r>>_logp; @@ -184,11 +184,11 @@ int ec_dec_bit_logp(ec_dec *_this,unsigned _logp){ } int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb){ - ec_uint32 r; - ec_uint32 d; - ec_uint32 s; - ec_uint32 t; - int ret; + celt_uint32 r; + celt_uint32 d; + celt_uint32 s; + celt_uint32 t; + int ret; s=_this->rng; d=_this->val; r=s>>_ftb; @@ -204,7 +204,7 @@ int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb){ return ret; } -ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){ +celt_uint32 ec_dec_uint(ec_dec *_this,celt_uint32 _ft){ unsigned ft; unsigned s; int ftb; @@ -213,12 +213,12 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){ _ft--; ftb=EC_ILOG(_ft); if(ftb>EC_UINT_BITS){ - ec_uint32 t; + celt_uint32 t; ftb-=EC_UINT_BITS; ft=(unsigned)(_ft>>ftb)+1; s=ec_decode(_this,ft); ec_dec_update(_this,s,s+1,ft); - t=(ec_uint32)s<error=1; return _ft; @@ -231,10 +231,10 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){ } } -ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){ - ec_window window; - int available; - ec_uint32 ret; +celt_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){ + ec_window window; + int available; + celt_uint32 ret; window=_this->end_window; available=_this->nend_bits; if(available<_bits){ @@ -244,7 +244,7 @@ ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){ } while(available<=EC_WINDOW_SIZE-EC_SYM_BITS); } - ret=(ec_uint32)window&((ec_uint32)1<<_bits)-1; + ret=(celt_uint32)window&((celt_uint32)1<<_bits)-1; window>>=_bits; available-=_bits; _this->end_window=window; diff --git a/external/celt-0.11.1/entdec.h b/external/celt-e18de77/entdec.h similarity index 96% rename from external/celt-0.11.1/entdec.h rename to external/celt-e18de77/entdec.h index 5119e0a..593979b 100644 --- a/external/celt-0.11.1/entdec.h +++ b/external/celt-e18de77/entdec.h @@ -35,7 +35,7 @@ /*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,unsigned char *_buf,ec_uint32 _storage); +void ec_dec_init(ec_dec *_this,unsigned char *_buf,celt_uint32 _storage); /*Calculates the cumulative frequency for the next symbol. This can then be fed into the probability model to determine what that @@ -89,7 +89,7 @@ int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb); _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); +celt_uint32 ec_dec_uint(ec_dec *_this,celt_uint32 _ft); /*Extracts a sequence of raw bits from the stream. The bits must have been encoded with ec_enc_bits(). @@ -97,6 +97,6 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft); _ftb: The number of bits to extract. This must be between 0 and 25, inclusive. Return: The decoded bits.*/ -ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb); +celt_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb); #endif diff --git a/external/celt-0.11.1/entenc.c b/external/celt-e18de77/entenc.c similarity index 93% rename from external/celt-0.11.1/entenc.c rename to external/celt-e18de77/entenc.c index 9297b5f..df649a6 100644 --- a/external/celt-0.11.1/entenc.c +++ b/external/celt-e18de77/entenc.c @@ -114,7 +114,7 @@ static void ec_enc_normalize(ec_enc *_this){ } } -void ec_enc_init(ec_enc *_this,unsigned char *_buf,ec_uint32 _size){ +void ec_enc_init(ec_enc *_this,unsigned char *_buf,celt_uint32 _size){ _this->buf=_buf; _this->end_offs=0; _this->end_window=0; @@ -131,7 +131,7 @@ void ec_enc_init(ec_enc *_this,unsigned char *_buf,ec_uint32 _size){ } void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft){ - ec_uint32 r; + celt_uint32 r; r=_this->rng/_ft; if(_fl>0){ _this->val+=_this->rng-IMUL32(r,(_ft-_fl)); @@ -142,7 +142,7 @@ 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){ - ec_uint32 r; + celt_uint32 r; r=_this->rng>>_bits; if(_fl>0){ _this->val+=_this->rng-IMUL32(r,((1<<_bits)-_fl)); @@ -154,9 +154,9 @@ void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){ /*The probability of having a "one" is 1/(1<<_logp).*/ void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp){ - ec_uint32 r; - ec_uint32 s; - ec_uint32 l; + celt_uint32 r; + celt_uint32 s; + celt_uint32 l; r=_this->rng; l=_this->val; s=r>>_logp; @@ -167,7 +167,7 @@ void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp){ } void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb){ - ec_uint32 r; + celt_uint32 r; r=_this->rng>>_ftb; if(_s>0){ _this->val+=_this->rng-IMUL32(r,_icdf[_s-1]); @@ -177,7 +177,7 @@ void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb){ ec_enc_normalize(_this); } -void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){ +void ec_enc_uint(ec_enc *_this,celt_uint32 _fl,celt_uint32 _ft){ unsigned ft; unsigned fl; int ftb; @@ -190,12 +190,12 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){ ft=(_ft>>ftb)+1; fl=(unsigned)(_fl>>ftb); ec_encode(_this,fl,fl+1,ft); - ec_enc_bits(_this,_fl&((ec_uint32)1<end_window; @@ -231,14 +231,14 @@ void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits){ } else if(_this->rng<=EC_CODE_TOP>>shift){ /*The renormalization loop has never been run.*/ - _this->val=_this->val&~((ec_uint32)mask<val=_this->val&~((celt_uint32)mask<error=-1; } -void ec_enc_shrink(ec_enc *_this,ec_uint32 _size){ +void ec_enc_shrink(ec_enc *_this,celt_uint32 _size){ celt_assert(_this->offs+_this->end_offs<=_size); CELT_MOVE(_this->buf+_size-_this->end_offs, _this->buf+_this->storage-_this->end_offs,_this->end_offs); @@ -246,11 +246,11 @@ void ec_enc_shrink(ec_enc *_this,ec_uint32 _size){ } void ec_enc_done(ec_enc *_this){ - ec_window window; - int used; - ec_uint32 msk; - ec_uint32 end; - int l; + ec_window window; + int used; + celt_uint32 msk; + celt_uint32 end; + int l; /*We output the minimum number of bits that ensures that the symbols encoded thus far will be decoded correctly regardless of the bits that follow.*/ l=EC_CODE_BITS-EC_ILOG(_this->rng); diff --git a/external/celt-0.11.1/entenc.h b/external/celt-e18de77/entenc.h similarity index 95% rename from external/celt-0.11.1/entenc.h rename to external/celt-e18de77/entenc.h index e64e887..7e30617 100644 --- a/external/celt-0.11.1/entenc.h +++ b/external/celt-e18de77/entenc.h @@ -35,7 +35,7 @@ /*Initializes the encoder. _buf: The buffer to store output bytes in. _size: The size of the buffer, in chars.*/ -void ec_enc_init(ec_enc *_this,unsigned char *_buf,ec_uint32 _size); +void ec_enc_init(ec_enc *_this,unsigned char *_buf,celt_uint32 _size); /*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. @@ -70,13 +70,13 @@ void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb); _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); +void ec_enc_uint(ec_enc *_this,celt_uint32 _fl,celt_uint32 _ft); /*Encodes a sequence of raw bits in the stream. _fl: The bits to encode. _ftb: The number of bits to encode. This must be between 0 and 25, inclusive.*/ -void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _ftb); +void ec_enc_bits(ec_enc *_this,celt_uint32 _fl,unsigned _ftb); /*Overwrites a few bits at the very start of an existing stream, after they have already been encoded. @@ -102,7 +102,7 @@ void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits); _size: The number of bytes in the new buffer. This must be large enough to contain the bits already written, and must be no larger than the existing size.*/ -void ec_enc_shrink(ec_enc *_this,ec_uint32 _size); +void ec_enc_shrink(ec_enc *_this,celt_uint32 _size); /*Indicates that there are no more symbols to encode. All reamining output bytes are flushed to the output buffer. diff --git a/external/celt-0.11.1/fixed_generic.h b/external/celt-e18de77/fixed_generic.h similarity index 100% rename from external/celt-0.11.1/fixed_generic.h rename to external/celt-e18de77/fixed_generic.h diff --git a/external/celt-0.11.1/float_cast.h b/external/celt-e18de77/float_cast.h similarity index 100% rename from external/celt-0.11.1/float_cast.h rename to external/celt-e18de77/float_cast.h diff --git a/external/celt-0.11.1/header.c b/external/celt-e18de77/header.c similarity index 97% rename from external/celt-0.11.1/header.c rename to external/celt-e18de77/header.c index b31a5b7..37b11bf 100644 --- a/external/celt-0.11.1/header.c +++ b/external/celt-e18de77/header.c @@ -55,7 +55,8 @@ int celt_header_init(CELTHeader *header, const CELTMode *m, int frame_size, int CELT_COPY(header->codec_id, "CELT ", 8); CELT_COPY(header->codec_version, "experimental ", 20); - celt_mode_info(m, CELT_GET_BITSTREAM_VERSION, &header->version_id); + /* FIXME: Set that to zero when we freeze */ + header->version_id = 0x80001000; header->header_size = 56; header->sample_rate = m->Fs; header->nb_channels = channels; diff --git a/external/celt-0.11.1/include/celt/celt.h b/external/celt-e18de77/include/celt/celt.h similarity index 94% rename from external/celt-0.11.1/include/celt/celt.h rename to external/celt-e18de77/include/celt/celt.h index eaa2622..2bbf506 100644 --- a/external/celt-0.11.1/include/celt/celt.h +++ b/external/celt-e18de77/include/celt/celt.h @@ -50,7 +50,8 @@ extern "C" { #endif #define _celt_check_int(x) (((void)((x) == (celt_int32)0)), (celt_int32)(x)) -#define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (CELTMode**)(ptr))) +#define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr))) +#define _celt_check_int_ptr(ptr) ((ptr) + ((ptr) - (int*)(ptr))) /* Error codes */ /** No error */ @@ -58,7 +59,7 @@ extern "C" { /** An (or more) invalid argument (e.g. out of range) */ #define CELT_BAD_ARG -1 /** The mode struct passed is invalid */ -#define CELT_INVALID_MODE -2 +#define CELT_BUFFER_TOO_SMALL -2 /** An internal error was detected */ #define CELT_INTERNAL_ERROR -3 /** The data passed (e.g. compressed data to decoder) is corrupted */ @@ -70,10 +71,8 @@ extern "C" { /** Memory allocation has failed */ #define CELT_ALLOC_FAIL -7 -/* Requests */ -#define CELT_GET_MODE_REQUEST 1 -/** Get the CELTMode used by an encoder or decoder */ -#define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, _celt_check_mode_ptr_ptr(x) + +/* Encoder/decoder Requests */ #define CELT_SET_COMPLEXITY_REQUEST 2 /** Controls the complexity from 0-10 (int) */ @@ -91,8 +90,8 @@ extern "C" { /** Set the target VBR rate in bits per second(int); 0=CBR (default) */ #define CELT_SET_BITRATE(x) CELT_SET_BITRATE_REQUEST, _celt_check_int(x) -/** Reset the encoder/decoder memories to zero*/ #define CELT_RESET_STATE_REQUEST 8 +/** Reset the encoder/decoder memories to zero*/ #define CELT_RESET_STATE CELT_RESET_STATE_REQUEST #define CELT_SET_VBR_CONSTRAINT_REQUEST 10 @@ -104,22 +103,25 @@ extern "C" { #define CELT_SET_INPUT_CLIPPING_REQUEST 14 #define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, _celt_check_int(x) +#define CELT_GET_AND_CLEAR_ERROR_REQUEST 15 +#define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, _celt_check_int_ptr(x) + +#define CELT_GET_LOOKAHEAD_REQUEST 17 +#define CELT_GET_LOOKAHEAD(x) CELT_GET_LOOKAHEAD_REQUEST, _celt_check_int_ptr(x) + +#define CELT_SET_CHANNELS_REQUEST 18 +#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, _celt_check_int(x) + +#define CELT_SET_LOSS_PERC_REQUEST 20 +#define CELT_SET_LOSS_PERC(x) CELT_SET_LOSS_PERC_REQUEST, _celt_check_int(x) + +/* Internal */ #define CELT_SET_START_BAND_REQUEST 10000 #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x) #define CELT_SET_END_BAND_REQUEST 10001 #define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, _celt_check_int(x) -#define CELT_SET_CHANNELS_REQUEST 10002 -#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, _celt_check_int(x) - -/** GET the lookahead used in the current mode */ -#define CELT_GET_LOOKAHEAD 1001 -/** GET the sample rate used in the current mode */ -#define CELT_GET_SAMPLE_RATE 1003 - -/** GET the bit-stream version for compatibility check */ -#define CELT_GET_BITSTREAM_VERSION 2000 /** Contains the state of an encoder. One encoder state is needed @@ -163,9 +165,6 @@ EXPORT CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error); */ EXPORT void celt_mode_destroy(CELTMode *mode); -/** Query information from a mode */ -EXPORT int celt_mode_info(const CELTMode *mode, int request, celt_int32 *value); - /* Encoder stuff */ EXPORT int celt_encoder_get_size(int channels); diff --git a/external/celt-0.11.1/include/celt/celt_header.h b/external/celt-e18de77/include/celt/celt_header.h similarity index 100% rename from external/celt-0.11.1/include/celt/celt_header.h rename to external/celt-e18de77/include/celt/celt_header.h diff --git a/external/celt-0.11.1/include/celt/celt_types.h b/external/celt-e18de77/include/celt/celt_types.h similarity index 100% rename from external/celt-0.11.1/include/celt/celt_types.h rename to external/celt-e18de77/include/celt/celt_types.h diff --git a/external/celt-0.11.1/kiss_fft.c b/external/celt-e18de77/kiss_fft.c similarity index 99% rename from external/celt-0.11.1/kiss_fft.c rename to external/celt-e18de77/kiss_fft.c index adc617a..4909231 100644 --- a/external/celt-0.11.1/kiss_fft.c +++ b/external/celt-e18de77/kiss_fft.c @@ -644,10 +644,13 @@ kiss_fft_state *kiss_fft_alloc(int nfft,void * mem,size_t * lenmem ) void kiss_fft_free(const kiss_fft_state *cfg) { - celt_free((celt_int16*)cfg->bitrev); - if (cfg->shift < 0) - celt_free((kiss_twiddle_cpx*)cfg->twiddles); - celt_free((kiss_fft_state*)cfg); + if (cfg) + { + celt_free((celt_int16*)cfg->bitrev); + if (cfg->shift < 0) + celt_free((kiss_twiddle_cpx*)cfg->twiddles); + celt_free((kiss_fft_state*)cfg); + } } #endif /* CUSTOM_MODES */ diff --git a/external/celt-0.11.1/kiss_fft.h b/external/celt-e18de77/kiss_fft.h similarity index 100% rename from external/celt-0.11.1/kiss_fft.h rename to external/celt-e18de77/kiss_fft.h diff --git a/external/celt-0.11.1/laplace.c b/external/celt-e18de77/laplace.c similarity index 100% rename from external/celt-0.11.1/laplace.c rename to external/celt-e18de77/laplace.c diff --git a/external/celt-0.11.1/laplace.h b/external/celt-e18de77/laplace.h similarity index 100% rename from external/celt-0.11.1/laplace.h rename to external/celt-e18de77/laplace.h diff --git a/external/celt-0.11.1/mathops.c b/external/celt-e18de77/mathops.c similarity index 100% rename from external/celt-0.11.1/mathops.c rename to external/celt-e18de77/mathops.c diff --git a/external/celt-0.11.1/mathops.h b/external/celt-e18de77/mathops.h similarity index 100% rename from external/celt-0.11.1/mathops.h rename to external/celt-e18de77/mathops.h diff --git a/external/celt-0.11.1/mdct.c b/external/celt-e18de77/mdct.c similarity index 100% rename from external/celt-0.11.1/mdct.c rename to external/celt-e18de77/mdct.c diff --git a/external/celt-0.11.1/mdct.h b/external/celt-e18de77/mdct.h similarity index 100% rename from external/celt-0.11.1/mdct.h rename to external/celt-e18de77/mdct.h diff --git a/external/celt-0.11.1/mfrngcod.h b/external/celt-e18de77/mfrngcod.h similarity index 92% rename from external/celt-0.11.1/mfrngcod.h rename to external/celt-e18de77/mfrngcod.h index 9a065f0..5e7a5bb 100644 --- a/external/celt-0.11.1/mfrngcod.h +++ b/external/celt-e18de77/mfrngcod.h @@ -40,17 +40,17 @@ /*Bits to shift by to move a symbol into the high-order position.*/ # define EC_CODE_SHIFT (EC_CODE_BITS-EC_SYM_BITS-1) /*Carry bit of the high-order range symbol.*/ -# define EC_CODE_TOP (((ec_uint32)1U)<>EC_SYM_BITS) /*Code for which propagating carries are possible.*/ -# define EC_CODE_CARRY (((ec_uint32)EC_SYM_MAX)<overlap; - break; - case CELT_GET_BITSTREAM_VERSION: - *value = CELT_BITSTREAM_VERSION; - break; - case CELT_GET_SAMPLE_RATE: - *value = mode->Fs; - break; - default: - return CELT_UNIMPLEMENTED; - } - return CELT_OK; -} - #ifdef CUSTOM_MODES /* Defining 25 critical bands for the full 0-20 kHz audio bandwidth @@ -243,23 +224,12 @@ static void compute_allocation_table(CELTMode *mode) CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) { int i; - CELTMode *mode=NULL; #ifdef CUSTOM_MODES + CELTMode *mode=NULL; int res; celt_word16 *window; celt_int16 *logN; int LM; -#endif -#ifdef STDIN_TUNING - scanf("%d ", &MIN_BINS); - scanf("%d ", &BITALLOC_SIZE); - band_allocation = celt_alloc(sizeof(int)*BARK_BANDS*BITALLOC_SIZE); - for (i=0;i>LM)*300 > Fs) { if (error) - *error = CELT_INVALID_MODE; + *error = CELT_BAD_ARG; return NULL; } @@ -425,7 +395,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) return mode; failure: if (error) - *error = CELT_INVALID_MODE; + *error = CELT_ALLOC_FAIL; if (mode!=NULL) celt_mode_destroy(mode); return NULL; diff --git a/external/celt-0.11.1/modes.h b/external/celt-e18de77/modes.h similarity index 92% rename from external/celt-0.11.1/modes.h rename to external/celt-e18de77/modes.h index 8ea39e9..9e0384e 100644 --- a/external/celt-0.11.1/modes.h +++ b/external/celt-e18de77/modes.h @@ -100,6 +100,13 @@ struct CELTMode { #endif #ifdef OPUS_BUILD +#define CELT_SET_SIGNALLING_REQUEST 10003 +#define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, _celt_check_int(x) + +#define CELT_GET_MODE_REQUEST 10004 +/** Get the CELTMode used by an encoder or decoder */ +#define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, _celt_check_mode_ptr_ptr(x) + /* Prototypes for _ec versions of the encoder/decoder calls (not public) */ int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc); int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc); diff --git a/external/celt-0.11.1/os_support.h b/external/celt-e18de77/os_support.h similarity index 100% rename from external/celt-0.11.1/os_support.h rename to external/celt-e18de77/os_support.h diff --git a/external/celt-0.11.1/pitch.c b/external/celt-e18de77/pitch.c similarity index 100% rename from external/celt-0.11.1/pitch.c rename to external/celt-e18de77/pitch.c diff --git a/external/celt-0.11.1/pitch.h b/external/celt-e18de77/pitch.h similarity index 100% rename from external/celt-0.11.1/pitch.h rename to external/celt-e18de77/pitch.h diff --git a/external/celt-0.11.1/plc.c b/external/celt-e18de77/plc.c similarity index 100% rename from external/celt-0.11.1/plc.c rename to external/celt-e18de77/plc.c diff --git a/external/celt-0.11.1/plc.h b/external/celt-e18de77/plc.h similarity index 100% rename from external/celt-0.11.1/plc.h rename to external/celt-e18de77/plc.h diff --git a/external/celt-0.11.1/quant_bands.c b/external/celt-e18de77/quant_bands.c similarity index 94% rename from external/celt-0.11.1/quant_bands.c rename to external/celt-e18de77/quant_bands.c index 9aa05fe..f33bf3f 100644 --- a/external/celt-0.11.1/quant_bands.c +++ b/external/celt-e18de77/quant_bands.c @@ -139,7 +139,7 @@ static const unsigned char e_prob_model[4][2][42] = { static const unsigned char small_energy_icdf[3]={2,1,0}; -static int intra_decision(const celt_word16 *eBands, celt_word16 *oldEBands, int start, int end, int len, int C) +static celt_word32 loss_distortion(const celt_word16 *eBands, celt_word16 *oldEBands, int start, int end, int len, int C) { int c, i; celt_word32 dist = 0; @@ -150,12 +150,12 @@ static int intra_decision(const celt_word16 *eBands, celt_word16 *oldEBands, int dist = MAC16_16(dist, d,d); } } while (++c 2*C*(end-start); + return MIN32(200,SHR32(dist,2*DB_SHIFT-4)); } static int quant_coarse_energy_impl(const CELTMode *m, int start, int end, const celt_word16 *eBands, celt_word16 *oldEBands, - ec_int32 budget, ec_int32 tell, + celt_int32 budget, celt_int32 tell, const unsigned char *prob_model, celt_word16 *error, ec_enc *enc, int _C, int LM, int intra, celt_word16 max_decay) { @@ -258,9 +258,9 @@ static int quant_coarse_energy_impl(const CELTMode *m, int start, int end, } void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, - const celt_word16 *eBands, celt_word16 *oldEBands, ec_uint32 budget, + const celt_word16 *eBands, celt_word16 *oldEBands, celt_uint32 budget, celt_word16 *error, ec_enc *enc, int _C, int LM, int nbAvailableBytes, - int force_intra, int *delayedIntra, int two_pass) + int force_intra, celt_word32 *delayedIntra, int two_pass, int loss_rate) { const int C = CHANNELS(_C); int intra; @@ -268,15 +268,15 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, VARDECL(celt_word16, oldEBands_intra); VARDECL(celt_word16, error_intra); ec_enc enc_start_state; - ec_uint32 tell; + celt_uint32 tell; int badness1=0; + celt_int32 intra_bias; + celt_word32 new_distortion; SAVE_STACK; - intra = force_intra || (*delayedIntra && nbAvailableBytes > (end-start)*C); - if (/*shortBlocks || */intra_decision(eBands, oldEBands, start, effEnd, m->nbEBands, C)) - *delayedIntra = 1; - else - *delayedIntra = 0; + intra = force_intra || (!two_pass && *delayedIntra>2*C*(end-start) && nbAvailableBytes > (end-start)*C); + intra_bias = ((budget**delayedIntra*loss_rate)/(C*512)); + new_distortion = loss_distortion(eBands, oldEBands, start, effEnd, m->nbEBands, C); tell = ec_tell(enc); if (tell+3 > budget) @@ -307,8 +307,8 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, { ec_enc enc_intra_state; int tell_intra; - ec_uint32 nstart_bytes; - ec_uint32 nintra_bytes; + celt_uint32 nstart_bytes; + celt_uint32 nintra_bytes; int badness2; VARDECL(unsigned char, intra_bits); @@ -329,7 +329,7 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget, tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay); - if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ec_tell_frac(enc) > tell_intra))) + if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ec_tell_frac(enc)+intra_bias > tell_intra))) { *enc = enc_intra_state; /* Copy intra bits to bit-stream */ @@ -337,11 +337,19 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, intra_bits, nintra_bytes - nstart_bytes); CELT_COPY(oldEBands, oldEBands_intra, C*m->nbEBands); CELT_COPY(error, error_intra, C*m->nbEBands); + intra = 1; } } else { CELT_COPY(oldEBands, oldEBands_intra, C*m->nbEBands); CELT_COPY(error, error_intra, C*m->nbEBands); } + + if (intra) + *delayedIntra = new_distortion; + else + *delayedIntra = ADD32(MULT16_32_Q15(MULT16_16_Q15(pred_coef[LM], pred_coef[LM]),*delayedIntra), + new_distortion); + RESTORE_STACK; } @@ -421,8 +429,8 @@ void unquant_coarse_energy(const CELTMode *m, int start, int end, celt_word16 *o celt_word16 coef; celt_word16 beta; const int C = CHANNELS(_C); - ec_int32 budget; - ec_int32 tell; + celt_int32 budget; + celt_int32 tell; if (intra) diff --git a/external/celt-0.11.1/quant_bands.h b/external/celt-e18de77/quant_bands.h similarity index 93% rename from external/celt-0.11.1/quant_bands.h rename to external/celt-e18de77/quant_bands.h index cc478a3..c1749b2 100644 --- a/external/celt-0.11.1/quant_bands.h +++ b/external/celt-e18de77/quant_bands.h @@ -45,9 +45,10 @@ unsigned char *quant_prob_alloc(const CELTMode *m); void quant_prob_free(const celt_int16 *freq); void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, - const celt_word16 *eBands, celt_word16 *oldEBands, ec_uint32 budget, + const celt_word16 *eBands, celt_word16 *oldEBands, celt_uint32 budget, celt_word16 *error, ec_enc *enc, int _C, int LM, - int nbAvailableBytes, int force_intra, int *delayedIntra, int two_pass); + int nbAvailableBytes, int force_intra, celt_word32 *delayedIntra, + int two_pass, int loss_rate); void quant_fine_energy(const CELTMode *m, int start, int end, celt_word16 *oldEBands, celt_word16 *error, int *fine_quant, ec_enc *enc, int _C); diff --git a/external/celt-0.11.1/rate.c b/external/celt-e18de77/rate.c similarity index 95% rename from external/celt-0.11.1/rate.c rename to external/celt-e18de77/rate.c index ed7e872..24037c0 100644 --- a/external/celt-0.11.1/rate.c +++ b/external/celt-e18de77/rate.c @@ -523,7 +523,7 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int } int compute_allocation(const CELTMode *m, int start, int end, const int *offsets, const int *cap, int alloc_trim, int *intensity, int *dual_stereo, - int total, celt_int32 *balance, int *pulses, int *ebits, int *fine_priority, int _C, int LM, ec_ctx *ec, int encode, int prev) + celt_int32 total, celt_int32 *balance, int *pulses, int *ebits, int *fine_priority, int _C, int LM, ec_ctx *ec, int encode, int prev) { int lo, hi, len, j; const int C = CHANNELS(_C); @@ -584,18 +584,19 @@ int compute_allocation(const CELTMode *m, int start, int end, const int *offsets int mid = (lo+hi) >> 1; for (j=end;j-->start;) { + int bitsj; int N = m->eBands[j+1]-m->eBands[j]; - bits1[j] = C*N*m->allocVectors[mid*len+j]<>2; - if (bits1[j] > 0) - bits1[j] = IMAX(0, bits1[j] + trim_offset[j]); - bits1[j] += offsets[j]; - if (bits1[j] >= thresh[j] || done) + bitsj = C*N*m->allocVectors[mid*len+j]<>2; + if (bitsj > 0) + bitsj = IMAX(0, bitsj + trim_offset[j]); + bitsj += offsets[j]; + if (bitsj >= thresh[j] || done) { done = 1; /* Don't allocate more than we can actually use */ - psum += IMIN(bits1[j], cap[j]); + psum += IMIN(bitsj, cap[j]); } else { - if (bits1[j] >= C<= C<eBands[j+1]-m->eBands[j]; - bits1[j] = C*N*m->allocVectors[lo*len+j]<>2; - bits2[j] = hi>=m->nbAllocVectors ? + bits1j = C*N*m->allocVectors[lo*len+j]<>2; + bits2j = hi>=m->nbAllocVectors ? cap[j] : C*N*m->allocVectors[hi*len+j]<>2; - if (bits1[j] > 0) - bits1[j] = IMAX(0, bits1[j] + trim_offset[j]); - if (bits2[j] > 0) - bits2[j] = IMAX(0, bits2[j] + trim_offset[j]); + if (bits1j > 0) + bits1j = IMAX(0, bits1j + trim_offset[j]); + if (bits2j > 0) + bits2j = IMAX(0, bits2j + trim_offset[j]); if (lo > 0) - bits1[j] += offsets[j]; - bits2[j] += offsets[j]; + bits1j += offsets[j]; + bits2j += offsets[j]; if (offsets[j]>0) skip_start = j; - bits2[j] = IMAX(0,bits2[j]-bits1[j]); + bits2j = IMAX(0,bits2j-bits1j); + bits1[j] = bits1j; + bits2[j] = bits2j; } codedBands = interp_bits2pulses(m, start, end, skip_start, bits1, bits2, thresh, cap, total, balance, skip_rsv, intensity, intensity_rsv, dual_stereo, dual_stereo_rsv, diff --git a/external/celt-0.11.1/rate.h b/external/celt-e18de77/rate.h similarity index 100% rename from external/celt-0.11.1/rate.h rename to external/celt-e18de77/rate.h diff --git a/external/celt-0.11.1/stack_alloc.h b/external/celt-e18de77/stack_alloc.h similarity index 89% rename from external/celt-0.11.1/stack_alloc.h rename to external/celt-e18de77/stack_alloc.h index 3b9cf6c..69daf06 100644 --- a/external/celt-0.11.1/stack_alloc.h +++ b/external/celt-e18de77/stack_alloc.h @@ -125,14 +125,14 @@ extern char *global_stack_top; #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) #define PUSH(stack, size, type) (VALGRIND_MAKE_MEM_NOACCESS(stack, global_stack_top-stack),ALIGN((stack),sizeof(type)/sizeof(char)),VALGRIND_MAKE_MEM_UNDEFINED(stack, ((size)*sizeof(type)/sizeof(char))),(stack)+=(2*(size)*sizeof(type)/sizeof(char)),(type*)((stack)-(2*(size)*sizeof(type)/sizeof(char)))) #define RESTORE_STACK ((global_stack = _saved_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack)) -#define ALLOC_STACK ((global_stack = (global_stack==0) ? ((global_stack_top=celt_alloc_scratch(GLOBAL_STACK_SIZE*2)+(GLOBAL_STACK_SIZE*2))-(GLOBAL_STACK_SIZE*2)) : global_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack)) +#define ALLOC_STACK char *_saved_stack; ((global_stack = (global_stack==0) ? ((global_stack_top=celt_alloc_scratch(GLOBAL_STACK_SIZE*2)+(GLOBAL_STACK_SIZE*2))-(GLOBAL_STACK_SIZE*2)) : global_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack)); _saved_stack = global_stack; #else #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) #define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/sizeof(char)),(stack)+=(size)*(sizeof(type)/sizeof(char)),(type*)((stack)-(size)*(sizeof(type)/sizeof(char)))) #define RESTORE_STACK (global_stack = _saved_stack) -#define ALLOC_STACK (global_stack = (global_stack==0) ? celt_alloc_scratch(GLOBAL_STACK_SIZE) : global_stack) +#define ALLOC_STACK char *_saved_stack; (global_stack = (global_stack==0) ? celt_alloc_scratch(GLOBAL_STACK_SIZE) : global_stack); _saved_stack = global_stack; #endif /*ENABLE_VALGRIND*/ diff --git a/external/celt-0.11.1/static_modes_fixed.c b/external/celt-e18de77/static_modes_fixed.c similarity index 100% rename from external/celt-0.11.1/static_modes_fixed.c rename to external/celt-e18de77/static_modes_fixed.c diff --git a/external/celt-0.11.1/static_modes_float.c b/external/celt-e18de77/static_modes_float.c similarity index 100% rename from external/celt-0.11.1/static_modes_float.c rename to external/celt-e18de77/static_modes_float.c diff --git a/external/celt-0.11.1/vq.c b/external/celt-e18de77/vq.c similarity index 100% rename from external/celt-0.11.1/vq.c rename to external/celt-e18de77/vq.c diff --git a/external/celt-0.11.1/vq.h b/external/celt-e18de77/vq.h similarity index 100% rename from external/celt-0.11.1/vq.h rename to external/celt-e18de77/vq.h diff --git a/premake/celt.lua b/premake/celt.lua index 941b65c..4d56a4a 100644 --- a/premake/celt.lua +++ b/premake/celt.lua @@ -1,5 +1,5 @@ -local base_dir = (solution().basedir .. "/external/celt-0.11.1/") +local base_dir = (solution().basedir .. "/external/celt-e18de77/") group "external" project "celt" @@ -9,9 +9,10 @@ group "external" defines { - "restrict=", "CUSTOM_MODES", - "CUSTOM_MODES_ONLY" + "CUSTOM_MODES_ONLY", + "DISABLE_FLOAT_API", + "HAVE_CONFIG_H" } includedirs {