shithub: opus

Download patch

ref: 7a56741b2ee901fbf6cafd6c8fe1e1c63ff7709e
parent: f1ce900717877c334cafab734716df343007b3c1
author: Jean-Marc Valin <[email protected]>
date: Sat Jun 13 18:59:43 EDT 2009

removing redundant calls to log2()

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -509,6 +509,7 @@
    VARDECL(celt_norm_t, X);
    VARDECL(celt_norm_t, P);
    VARDECL(celt_ener_t, bandE);
+   VARDECL(celt_word16_t, bandLogE);
    VARDECL(celt_pgain_t, gains);
    VARDECL(int, fine_quant);
    VARDECL(celt_word16_t, error);
@@ -609,6 +610,7 @@
 
    ALLOC(freq, C*N, celt_sig_t); /**< Interleaved signal MDCTs */
    ALLOC(bandE,st->mode->nbEBands*C, celt_ener_t);
+   ALLOC(bandLogE,st->mode->nbEBands*C, celt_word16_t);
    /* Compute MDCTs */
    compute_mdcts(st->mode, shortBlocks, in, freq);
    if (shortBlocks && !transient_shift) 
@@ -678,9 +680,11 @@
       else printf ("1\n");*/
 
    compute_band_energies(st->mode, freq, bandE);
+   for (i=0;i<st->mode->nbEBands*C;i++)
+      bandLogE[i] = amp2Log(bandE[i]);
 
    intra_ener = (st->force_intra || st->delayedIntra);
-   if (shortBlocks || intra_decision(bandE, st->oldBandE, st->mode->nbEBands))
+   if (shortBlocks || intra_decision(bandLogE, st->oldBandE, st->mode->nbEBands))
       st->delayedIntra = 1;
    else
       st->delayedIntra = 0;
@@ -813,7 +817,7 @@
 
    /* Bit allocation */
    ALLOC(error, C*st->mode->nbEBands, celt_word16_t);
-   coarse_needed = quant_coarse_energy(st->mode, bandE, st->oldBandE, nbCompressedBytes*8/3, intra_ener, st->mode->prob, error, &enc);
+   coarse_needed = quant_coarse_energy(st->mode, bandLogE, st->oldBandE, nbCompressedBytes*8/3, intra_ener, st->mode->prob, error, &enc);
    coarse_needed = ((coarse_needed*3-1)>>3)+1;
 
    /* Variable bitrate */
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -47,13 +47,13 @@
 const celt_word16_t eMeans[24] = {7.5f, -1.33f, -2.f, -0.42f, 0.17f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
 #endif
 
-int intra_decision(celt_ener_t *eBands, celt_word16_t *oldEBands, int len)
+int intra_decision(celt_word16_t *eBands, celt_word16_t *oldEBands, int len)
 {
    int i;
    celt_word32_t dist = 0;
    for (i=0;i<len;i++)
    {
-      celt_word16_t d = SUB16(amp2Log(eBands[i]), oldEBands[i]);
+      celt_word16_t d = SUB16(eBands[i], oldEBands[i]);
       dist = MAC16_16(dist, d,d);
    }
    return SHR32(dist,16) > 2*len;
@@ -84,7 +84,7 @@
    celt_free(freq);
 }
 
-static unsigned quant_coarse_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, unsigned budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc)
+static unsigned quant_coarse_energy_mono(const CELTMode *m, celt_word16_t *eBands, celt_word16_t *oldEBands, unsigned budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc)
 {
    int i;
    unsigned bits;
@@ -110,7 +110,7 @@
       celt_word16_t x;   /* dB */
       celt_word16_t f;   /* Q8 */
       celt_word16_t mean = MULT16_16_Q15(Q15ONE-coef,eMeans[i]);
-      x = amp2Log(eBands[i]);
+      x = eBands[i];
 #ifdef FIXED_POINT
       f = x-mean -MULT16_16_Q15(coef,oldEBands[i])-prev;
       /* Rounding to nearest integer here is really important! */
@@ -118,7 +118,7 @@
 #else
       f = x-mean-coef*oldEBands[i]-prev;
       /* Rounding to nearest integer here is really important! */
-      qi = (int)floor(.5+f);
+      qi = (int)floor(.5f+f);
 #endif
       /* If we don't have enough bits to encode all the energy, just assume something safe.
          We allow slightly busting the budget here */
@@ -154,7 +154,7 @@
       /* Has to be without rounding */
       q2 = (error[i]+QCONST16(.5f,8))>>(8-fine_quant[i]);
 #else
-      q2 = (int)floor((error[i]+.5)*frac);
+      q2 = (int)floor((error[i]+.5f)*frac);
 #endif
       if (q2 > frac-1)
          q2 = frac-1;
@@ -292,7 +292,7 @@
 }
 
 
-unsigned quant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc)
+unsigned quant_coarse_energy(const CELTMode *m, celt_word16_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc)
 {
    int C;
    C = m->nbChannels;
@@ -307,9 +307,9 @@
       {
          int i;
          unsigned coarse_needed;
-         VARDECL(celt_ener_t, E);
+         VARDECL(celt_word16_t, E);
          SAVE_STACK;
-         ALLOC(E, m->nbEBands, celt_ener_t);
+         ALLOC(E, m->nbEBands, celt_word16_t);
          for (i=0;i<m->nbEBands;i++)
             E[i] = eBands[C*i+c];
          coarse_needed=quant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, intra, prob, error+c*m->nbEBands, enc);
--- a/libcelt/quant_bands.h
+++ b/libcelt/quant_bands.h
@@ -53,9 +53,9 @@
 
 void compute_fine_allocation(const CELTMode *m, int *bits, int budget);
 
-int intra_decision(celt_ener_t *eBands, celt_word16_t *oldEBands, int len);
+int intra_decision(celt_word16_t *eBands, celt_word16_t *oldEBands, int len);
 
-unsigned quant_coarse_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc);
+unsigned quant_coarse_energy(const CELTMode *m, celt_word16_t *eBands, celt_word16_t *oldEBands, int budget, int intra, int *prob, celt_word16_t *error, ec_enc *enc);
 
 void quant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_word16_t *error, int *fine_quant, ec_enc *enc);