ref: 7b5a086b4581c71e9a6c47188a285fca010a8943
parent: fd3139cccfc543f1e2fb201dab4e7b58234bced5
author: Jean-Marc Valin <[email protected]>
date: Thu Jul 29 11:01:24 EDT 2010
Measuring the normalized error directly within the encoder
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -434,6 +434,46 @@
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;i<nbMSEBands;i++)
+ {
+ printf ("%f ", MSE[i]/MSECount[i]);
+ }
+ printf ("\n");
+}
+
+void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M)
+{
+ static int init = 0;
+ int i;
+ if (!init)
+ {
+ atexit(dump_norm_mse);
+ init = 1;
+ }
+ for (i=0;i<m->nbEBands;i++)
+ {
+ int j;
+ float g = bandE[i]/(1e-15+bandE0[i]);
+ if (bandE0[i]<1)
+ continue;
+ for (j=M*m->eBands[i];j<M*m->eBands[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;
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -1046,10 +1046,23 @@
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;i<N;i++)
+ X0[i] = X[i];
+ for (i=0;i<st->mode->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)