Encoding the tf parameters after coarse energy
Also a minor cleanup to the recombining/division
diff --git a/libcelt/celt.c b/libcelt/celt.c
index 93e1e07..acac0c0 100644
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -536,9 +536,9 @@
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 @@
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;i<len;i++)
@@ -621,7 +627,6 @@
ec_enc_bit_prob(enc, tf_res[i] ^ curr, 4096);
curr = tf_res[i];
}
- RESTORE_STACK
}
static void tf_decode(int len, int C, int isTransient, int *tf_res, ec_dec *dec)
@@ -905,7 +910,7 @@
}
ALLOC(tf_res, st->mode->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 @@
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 @@
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);