From 0a571ef92a40cfa18ef1a9d47a39f7ba2756f36c Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sat, 5 Jun 2010 23:12:19 -0400 Subject: [PATCH] Encoding the tf parameters after coarse energy Also a minor cleanup to the recombining/division --- libcelt/bands.c | 41 +++++++++++++++++------------------------ libcelt/celt.c | 22 +++++++++++++++------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 84582454..4b49b281 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -808,6 +808,8 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ if (resynth) { + int k; + if (split) { int j; @@ -831,34 +833,25 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ if (lowband) interleave_vector(lowband, N_B, spread0); } - if (time_divide) + + N_B = N_B0; + spread = spread0; + for (k=0;k>= 1; - N_B <<= 1; - haar1(X, N_B, spread); - if (lowband) - haar1(lowband, N_B, spread); - } + spread >>= 1; + N_B <<= 1; + haar1(X, N_B, spread); + if (lowband) + haar1(lowband, N_B, spread); } - if (!stereo && level == 0) + for (k=0;k>=1; - spread <<= 1; - } + haar1(X, N_B, spread); + if (lowband) + haar1(lowband, N_B, spread); + N_B>>=1; + spread <<= 1; } if (lowband_out && !stereo) diff --git a/libcelt/celt.c b/libcelt/celt.c index 93e1e073..acac0c06 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -536,9 +536,9 @@ static void mdct_shape(const CELTMode *mode, celt_norm *X, int start, renormalise_bands(mode, X, C, M); } -static void tf_encode(celt_word16 *bandLogE, celt_word16 *oldBandE, int len, int C, int isTransient, int *tf_res, int nbCompressedBytes, ec_enc *enc) +static void tf_analysis(celt_word16 *bandLogE, celt_word16 *oldBandE, int len, int C, int isTransient, int *tf_res, int nbCompressedBytes) { - int i, curr; + int i; celt_word16 threshold; VARDECL(celt_word32, metric); celt_word32 cost0; @@ -614,6 +614,12 @@ static void tf_encode(celt_word16 *bandLogE, celt_word16 *oldBandE, int len, int else tf_res[i] = path0[i+1]; } + RESTORE_STACK +} + +static void tf_encode(int len, int isTransient, int *tf_res, ec_enc *enc) +{ + int curr, i; ec_enc_bit_prob(enc, tf_res[0], isTransient ? 16384 : 4096); curr = tf_res[0]; for (i=1;imode->nbEBands, int); - tf_encode(bandLogE, st->oldBandE, st->mode->nbEBands, C, isTransient, tf_res, nbCompressedBytes, enc); + tf_analysis(bandLogE, st->oldBandE, st->mode->nbEBands, C, isTransient, tf_res, nbCompressedBytes); /* Bit allocation */ ALLOC(error, C*st->mode->nbEBands, celt_word16); @@ -970,6 +975,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c ec_byte_shrink(&buf, nbCompressedBytes); } + tf_encode(st->mode->nbEBands, isTransient, tf_res, enc); + ALLOC(offsets, st->mode->nbEBands, int); ALLOC(fine_priority, st->mode->nbEBands, int); @@ -1691,13 +1698,14 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da pitch_index = 0; } - ALLOC(tf_res, st->mode->nbEBands, int); - tf_decode(st->mode->nbEBands, C, isTransient, tf_res, dec); ALLOC(fine_quant, st->mode->nbEBands, int); /* Get band energies */ unquant_coarse_energy(st->mode, st->start, bandE, st->oldBandE, len*4-8, intra_ener, st->mode->prob, dec, C); - + + ALLOC(tf_res, st->mode->nbEBands, int); + tf_decode(st->mode->nbEBands, C, isTransient, tf_res, dec); + ALLOC(pulses, st->mode->nbEBands, int); ALLOC(offsets, st->mode->nbEBands, int); ALLOC(fine_priority, st->mode->nbEBands, int);