From 7b5a086b4581c71e9a6c47188a285fca010a8943 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 29 Jul 2010 15:01:24 +0200 Subject: [PATCH] Measuring the normalized error directly within the encoder --- libcelt/bands.c | 40 ++++++++++++++++++++++++++++++++++++++++ libcelt/celt.c | 13 +++++++++++++ 2 files changed, 53 insertions(+) diff --git a/libcelt/bands.c b/libcelt/bands.c index 446e0ef5..0243ceb0 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -434,6 +434,46 @@ int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int return *last_decision; } +#ifdef MEASURE_NORM_MSE + +float MSE[30] = {0}; +int nbMSEBands = 0; +int MSECount[30] = {0}; + +void dump_norm_mse(void) +{ + int i; + for (i=0;inbEBands;i++) + { + int j; + float g = bandE[i]/(1e-15+bandE0[i]); + if (bandE0[i]<1) + continue; + for (j=M*m->eBands[i];jeBands[i+1];j++) + MSE[i] += (g*X[j]-X0[j])*(g*X[j]-X0[j]); + MSECount[i]++; + } + nbMSEBands = m->nbEBands; +} + +#endif + static void interleave_vector(celt_norm *X, int N0, int stride) { int i,j; diff --git a/libcelt/celt.c b/libcelt/celt.c index 81315cc3..5d11be42 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -1046,11 +1046,24 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c quant_fine_energy(st->mode, st->start, st->end, bandE, st->oldBandE, error, fine_quant, enc, C); +#ifdef MEASURE_NORM_MSE + float X0[1000]; + float bandE0[30]; + for (i=0;imode->nbEBands;i++) + bandE0[i] = bandE[i]; +#endif + /* Residual quantisation */ quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, bandE, pulses, shortBlocks, has_fold, tf_res, resynth, nbCompressedBytes*8, enc, LM); quant_energy_finalise(st->mode, st->start, st->end, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(enc, 0), enc, C); +#ifdef MEASURE_NORM_MSE + measure_norm_mse(st->mode, X, X0, bandE, bandE0, M); +#endif + /* Re-synthesis of the coded audio if required */ if (resynth) {