diff --git a/libcelt/bands.c b/libcelt/bands.c index 920a9e96..c83fdc5d 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -282,7 +282,7 @@ static void stereo_merge(celt_norm *X, celt_norm *Y, celt_word16 mid, celt_word1 } /* Decide whether we should spread the pulses in the current frame */ -int folding_decision(const CELTMode *m, celt_norm *X, int *average, int *last_decision, int end, int _C, int M) +int spreading_decision(const CELTMode *m, celt_norm *X, int *average, int last_decision, int end, int _C, int M) { int i, c, N0; int sum = 0, nbBands=0; @@ -293,7 +293,7 @@ int folding_decision(const CELTMode *m, celt_norm *X, int *average, int *last_de N0 = M*m->shortMdctSize; if (M*(eBands[end]-eBands[end-1]) <= 8) - return 0; + return SPREAD_NONE; c=0; do { for (i=0;i>1; *average = sum; /* Hysteresis */ - sum = (3*sum + ((*last_decision<<7) + 64) + 2)>>2; - /* decision and last_decision do not use the same encoding */ + sum = (3*sum + (((3-last_decision)<<7) + 64) + 2)>>2; if (sum < 80) { - decision = 2; - *last_decision = 0; + decision = SPREAD_AGGRESSIVE; } else if (sum < 256) { - decision = 1; - *last_decision = 1; + decision = SPREAD_NORMAL; } else if (sum < 384) { - decision = 3; - *last_decision = 2; + decision = SPREAD_LIGHT; } else { - decision = 0; - *last_decision = 3; + decision = SPREAD_NONE; } return decision; } @@ -828,7 +823,7 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ int j; if (lowband != NULL && resynth) { - if (spread==2 && B<=1) + if (spread==SPREAD_AGGRESSIVE && B<=1) { /* Noise */ for (j=0;jforce_intra = 0; st->delayedIntra = 1; st->tonal_average = 256; - st->fold_decision = 1; + st->spread_decision = SPREAD_NORMAL; st->complexity = 5; if (error) @@ -719,7 +719,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i #endif int i, c, N; int bits; - int has_fold=1; ec_byte_buffer buf; ec_enc _enc; VARDECL(celt_sig, in); @@ -950,17 +949,17 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i { if (st->complexity == 0) { - has_fold = 0; - st->fold_decision = 3; + st->spread_decision = SPREAD_NONE; } else { - has_fold = 1; - st->fold_decision = 1; + st->spread_decision = SPREAD_NORMAL; } } else { - has_fold = folding_decision(st->mode, X, &st->tonal_average, &st->fold_decision, effEnd, C, M); + st->spread_decision = spreading_decision(st->mode, X, &st->tonal_average, st->spread_decision, effEnd, C, M); } - ec_enc_bit_prob(enc, has_fold>>1, 8192); - ec_enc_bit_prob(enc, has_fold&1, (has_fold>>1) ? 32768 : 49152); + /* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */ + ec_enc_bit_prob(enc, st->spread_decision>>1, 18432); + ec_enc_bit_prob(enc, st->spread_decision&1, + (st->spread_decision>>1) ? 5699 : 14564); ALLOC(offsets, st->mode->nbEBands, int); @@ -1144,7 +1143,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i /* Residual quantisation */ quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, - bandE, pulses, shortBlocks, has_fold, dual_stereo, intensity, tf_res, resynth, + bandE, pulses, shortBlocks, st->spread_decision, dual_stereo, intensity, tf_res, resynth, nbCompressedBytes*8, enc, LM, codedBands); quant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(enc, 0), enc, C); @@ -1388,7 +1387,7 @@ int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...) ((char*)&st->ENCODER_RESET_START - (char*)st)); st->vbr_offset = 0; st->delayedIntra = 1; - st->fold_decision = 1; + st->spread_decision = SPREAD_NORMAL; st->tonal_average = QCONST16(1.f,8); } break; @@ -1695,7 +1694,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da { #endif int c, i, N; - int has_fold; + int spread_decision; int bits; ec_dec _dec; ec_byte_buffer buf; @@ -1824,8 +1823,8 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da ALLOC(tf_res, st->mode->nbEBands, int); tf_decode(st->start, st->end, C, isTransient, tf_res, LM, dec); - has_fold = ec_dec_bit_prob(dec, 8192)<<1; - has_fold |= ec_dec_bit_prob(dec, (has_fold>>1) ? 32768 : 49152); + spread_decision = ec_dec_bit_prob(dec, 18432)<<1; + spread_decision |= ec_dec_bit_prob(dec, (spread_decision>>1) ? 5699 : 14564); ALLOC(pulses, st->mode->nbEBands, int); ALLOC(offsets, st->mode->nbEBands, int); @@ -1868,7 +1867,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da /* Decode fixed codebook */ quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, - NULL, pulses, shortBlocks, has_fold, dual_stereo, intensity, tf_res, 1, + NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res, 1, len*8, dec, LM, codedBands); unquant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE, diff --git a/libcelt/vq.c b/libcelt/vq.c index b80b65cf..ed2c46a9 100644 --- a/libcelt/vq.c +++ b/libcelt/vq.c @@ -39,6 +39,7 @@ #include "vq.h" #include "arch.h" #include "os_support.h" +#include "bands.h" #include "rate.h" #ifndef M_PI @@ -71,6 +72,7 @@ static void exp_rotation1(celt_norm *X, int len, int stride, celt_word16 c, celt static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread) { + static const int SPREAD_FACTOR[3]={5,10,15}; int i; celt_word16 c, s; celt_word16 gain, theta; @@ -84,14 +86,9 @@ static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int X[14] = 1; K=5; }*/ - if (2*K>=len || spread==0) + if (2*K>=len || spread==SPREAD_NONE) return; - if (spread==1) - factor=10; - else if (spread==2) - factor=5; - else - factor=15; + factor = SPREAD_FACTOR[spread-1]; gain = celt_div((celt_word32)MULT16_16(Q15_ONE,len),(celt_word32)(len+factor*K)); /* FIXME: Make that HALF16 instead of HALF32 */