shithub: opus

Download patch

ref: ee2506b2c7e9a0ef05eb489ed554d38d9b71a3e5
parent: 3afc6ffff068cd9696de7fc3b88a0cd3ab79940a
author: Jean-Marc Valin <[email protected]>
date: Sun Jun 16 16:24:52 EDT 2013

Moves log2Amp inside denormalise_bands() and get rid of bandE[]

Also get rid of the MSE measurement code which is outdated and no longer useful

--- a/celt/bands.c
+++ b/celt/bands.c
@@ -40,6 +40,7 @@
 #include "os_support.h"
 #include "mathops.h"
 #include "rate.h"
+#include "quant_bands.h"
 
 int hysteresis_decision(opus_val16 val, const opus_val16 *thresholds, const opus_val16 *hysteresis, int N, int prev)
 {
@@ -188,7 +189,7 @@
 
 /* De-normalise the energy to produce the synthesis from the unit-energy bands */
 void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X,
-      celt_sig * OPUS_RESTRICT freq, const celt_ener *bandE, int start, int end, int C, int M)
+      celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandLogE, int start, int end, int C, int M)
 {
    int i, c, N;
    const opus_int16 *eBands = m->eBands;
@@ -204,7 +205,12 @@
       for (i=start;i<end;i++)
       {
          int j, band_end;
-         opus_val32 g = SHR32(bandE[i+c*m->nbEBands],1);
+         celt_ener bandE;
+         opus_val32 g;
+         opus_val16 lg;
+         lg = ADD16(bandLogE[i+c*m->nbEBands], SHL16((opus_val16)eMeans[i],6));
+         bandE = PSHR32(celt_exp2(lg),4);
+         g = SHR32(bandE,1);
          j=M*eBands[i];
          band_end = M*eBands[i+1];
          do {
@@ -501,50 +507,6 @@
 #endif
    return 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 ("%g ", MSE[i]/MSECount[i]);
-   }
-   printf ("\n");
-}
-
-void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C)
-{
-   static int init = 0;
-   int i;
-   if (!init)
-   {
-      atexit(dump_norm_mse);
-      init = 1;
-   }
-   for (i=0;i<m->nbEBands;i++)
-   {
-      int j;
-      int c;
-      float g;
-      if (bandE0[i]<10 || (C==2 && bandE0[i+m->nbEBands]<1))
-         continue;
-      c=0; do {
-         g = bandE[i+c*m->nbEBands]/(1e-15+bandE0[i+c*m->nbEBands]);
-         for (j=M*m->eBands[i];j<M*m->eBands[i+1];j++)
-            MSE[i] += (g*X[j+c*N]-X0[j+c*N])*(g*X[j+c*N]-X0[j+c*N]);
-      } while (++c<C);
-      MSECount[i]+=C;
-   }
-   nbMSEBands = m->nbEBands;
-}
-
-#endif
 
 /* Indexing table for converting from natural Hadamard to ordery Hadamard
    This is essentially a bit-reversed Gray, on top of which we've added
--- a/celt/bands.h
+++ b/celt/bands.h
@@ -59,7 +59,7 @@
  * @param bandE Square root of the energy for each band
  */
 void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X,
-      celt_sig * OPUS_RESTRICT freq, const celt_ener *bandE, int start, int end, int C, int M);
+      celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandE, int start, int end, int C, int M);
 
 #define SPREAD_NONE       (0)
 #define SPREAD_LIGHT      (1)
--- a/celt/celt_decoder.c
+++ b/celt/celt_decoder.c
@@ -375,8 +375,8 @@
       /* Noise-based PLC/CNG */
       celt_sig *freq;
       VARDECL(celt_norm, X);
-      VARDECL(celt_ener, bandE);
       opus_uint32 seed;
+      opus_val16 *plcLogE;
       int end;
       int effEnd;
 
@@ -387,10 +387,9 @@
          deemphasis scratch buffer. */
       freq = scratch;
       ALLOC(X, C*N, celt_norm);   /**< Interleaved normalised MDCTs */
-      ALLOC(bandE, nbEBands*C, celt_ener);
 
       if (loss_count >= 5)
-         log2Amp(mode, start, end, bandE, backgroundLogE, C);
+         plcLogE = backgroundLogE;
       else {
          /* Energy decay */
          opus_val16 decay = loss_count==0 ?
@@ -400,7 +399,7 @@
             for (i=start;i<end;i++)
                oldBandE[c*nbEBands+i] -= decay;
          } while (++c<C);
-         log2Amp(mode, start, end, bandE, oldBandE, C);
+         plcLogE = oldBandE;
       }
       seed = st->rng;
       for (c=0;c<C;c++)
@@ -422,7 +421,7 @@
       }
       st->rng = seed;
 
-      denormalise_bands(mode, X, freq, bandE, start, effEnd, C, 1<<LM);
+      denormalise_bands(mode, X, freq, plcLogE, start, effEnd, C, 1<<LM);
 
       c=0; do {
          int bound = eBands[effEnd]<<LM;
@@ -659,7 +658,6 @@
    ec_dec _dec;
    VARDECL(celt_sig, freq);
    VARDECL(celt_norm, X);
-   VARDECL(celt_ener, bandE);
    VARDECL(int, fine_quant);
    VARDECL(int, pulses);
    VARDECL(int, cap);
@@ -913,9 +911,6 @@
       anti_collapse(mode, X, collapse_masks, LM, C, N,
             st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng);
 
-   ALLOC(bandE, nbEBands*C, celt_ener);
-
-   log2Amp(mode, st->start, st->end, bandE, oldBandE, C);
    ALLOC(freq, IMAX(CC,C)*N, celt_sig); /**< Interleaved signal MDCTs */
 
    if (silence)
@@ -926,7 +921,7 @@
          freq[i] = 0;
    } else {
       /* Synthesis */
-      denormalise_bands(mode, X, freq, bandE, st->start, effEnd, C, M);
+      denormalise_bands(mode, X, freq, oldBandE, st->start, effEnd, C, M);
    }
    c=0; do {
       OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2);
--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1849,17 +1849,6 @@
 
    quant_fine_energy(mode, st->start, st->end, oldBandE, error, fine_quant, enc, C);
 
-#ifdef MEASURE_NORM_MSE
-   float X0[3000];
-   float bandE0[60];
-   c=0; do
-      for (i=0;i<N;i++)
-         X0[i+c*N] = X[i+c*N];
-   while (++c<C);
-   for (i=0;i<C*nbEBands;i++)
-      bandE0[i] = bandE[i];
-#endif
-
    /* Residual quantisation */
    ALLOC(collapse_masks, C*nbEBands, unsigned char);
    quant_all_bands(1, mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks,
@@ -1893,17 +1882,13 @@
                st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng);
       }
 
-      log2Amp(mode, st->start, st->end, bandE, oldBandE, C);
       if (silence)
       {
          for (i=0;i<C*N;i++)
             freq[i] = 0;
       } else {
-#ifdef MEASURE_NORM_MSE
-         measure_norm_mse(mode, X, X0, bandE, bandE0, M, N, C);
-#endif
          /* Synthesis */
-         denormalise_bands(mode, X, freq, bandE, st->start, effEnd, C, M);
+         denormalise_bands(mode, X, freq, oldBandE, st->start, effEnd, C, M);
       }
 
       c=0; do {
--- a/celt/quant_bands.c
+++ b/celt/quant_bands.c
@@ -536,25 +536,6 @@
    }
 }
 
-void log2Amp(const CELTMode *m, int start, int end,
-      celt_ener *eBands, const opus_val16 *oldEBands, int C)
-{
-   int c, i;
-   c=0;
-   do {
-      for (i=0;i<start;i++)
-         eBands[i+c*m->nbEBands] = 0;
-      for (;i<end;i++)
-      {
-         opus_val16 lg = ADD16(oldEBands[i+c*m->nbEBands],
-                         SHL16((opus_val16)eMeans[i],6));
-         eBands[i+c*m->nbEBands] = PSHR32(celt_exp2(lg),4);
-      }
-      for (;i<m->nbEBands;i++)
-         eBands[i+c*m->nbEBands] = 0;
-   } while (++c < C);
-}
-
 void amp2Log2(const CELTMode *m, int effEnd, int end,
       celt_ener *bandE, opus_val16 *bandLogE, int C)
 {
--- a/celt/tests/test_unit_mathops.c
+++ b/celt/tests/test_unit_mathops.c
@@ -41,6 +41,8 @@
 #include "entdec.c"
 #include "entcode.c"
 #include "bands.c"
+#include "quant_bands.c"
+#include "laplace.c"
 #include "vq.c"
 #include "cwrs.c"
 #include <stdio.h>