shithub: opus

Download patch

ref: be37d8663364ba2e062cdfb54a320fb39f9a75f3
parent: 100228e3ed9fc87233e86675eddfca9b0abc64b1
author: Jean-Marc Valin <jeanmarcv@google.com>
date: Thu Jul 18 07:15:22 EDT 2024

Cleanup: use celt_glog for log of the gain

--- a/celt/arch.h
+++ b/celt/arch.h
@@ -134,6 +134,7 @@
 typedef opus_val32 celt_sig;
 typedef opus_val16 celt_norm;
 typedef opus_val32 celt_ener;
+typedef opus_val16 celt_glog;
 
 #ifdef ENABLE_RES24
 typedef opus_val32 opus_res;
@@ -233,6 +234,7 @@
 typedef float celt_sig;
 typedef float celt_norm;
 typedef float celt_ener;
+typedef float celt_glog;
 
 typedef float opus_res;
 
--- a/celt/bands.c
+++ b/celt/bands.c
@@ -207,7 +207,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 opus_val16 *bandLogE, int start,
+      celt_sig * OPUS_RESTRICT freq, const celt_glog *bandLogE, int start,
       int end, int M, int downsample, int silence)
 {
    int i, N;
@@ -250,7 +250,7 @@
          g=0;
       } else {
          /* Handle the fractional part. */
-         g = celt_exp2_frac((lg&((1<<DB_SHIFT)-1))<<(10-DB_SHIFT));
+         g = celt_exp2_frac((lg&((1<<DB_SHIFT)-1))>>(DB_SHIFT-10));
       }
       /* Handle extreme gains with negative shift. */
       if (shift<0)
@@ -279,8 +279,8 @@
 
 /* This prevents energy collapse for transients with multiple short MDCTs */
 void anti_collapse(const CELTMode *m, celt_norm *X_, unsigned char *collapse_masks, int LM, int C, int size,
-      int start, int end, const opus_val16 *logE, const opus_val16 *prev1logE,
-      const opus_val16 *prev2logE, const int *pulses, opus_uint32 seed, int encode, int arch)
+      int start, int end, const celt_glog *logE, const celt_glog *prev1logE,
+      const celt_glog *prev2logE, const int *pulses, opus_uint32 seed, int encode, int arch)
 {
    int c, i, j, k;
    for (i=start;i<end;i++)
@@ -316,8 +316,8 @@
       c=0; do
       {
          celt_norm *X;
-         opus_val16 prev1;
-         opus_val16 prev2;
+         celt_glog prev1;
+         celt_glog prev2;
          opus_val32 Ediff;
          opus_val16 r;
          int renormalize=0;
--- a/celt/bands.h
+++ b/celt/bands.h
@@ -62,7 +62,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 opus_val16 *bandE, int start,
+      celt_sig * OPUS_RESTRICT freq, const celt_glog *bandE, int start,
       int end, int M, int downsample, int silence);
 
 #define SPREAD_NONE       (0)
@@ -112,8 +112,8 @@
 
 void anti_collapse(const CELTMode *m, celt_norm *X_,
       unsigned char *collapse_masks, int LM, int C, int size, int start,
-      int end, const opus_val16 *logE, const opus_val16 *prev1logE,
-      const opus_val16 *prev2logE, const int *pulses, opus_uint32 seed,
+      int end, const celt_glog *logE, const celt_glog *prev1logE,
+      const celt_glog *prev2logE, const int *pulses, opus_uint32 seed,
       int encode, int arch);
 
 opus_uint32 celt_lcg_rand(opus_uint32 seed);
--- a/celt/celt.h
+++ b/celt/celt.h
@@ -83,6 +83,8 @@
 
 #define __celt_check_silkinfo_ptr(ptr) ((ptr) + ((ptr) - (const SILKInfo*)(ptr)))
 
+#define __celt_check_glog_ptr(ptr) ((ptr) + ((ptr) - (celt_glog*)(ptr)))
+
 /* Encoder/decoder Requests */
 
 
@@ -130,7 +132,7 @@
 #define OPUS_SET_LFE(x) OPUS_SET_LFE_REQUEST, __opus_check_int(x)
 
 #define OPUS_SET_ENERGY_MASK_REQUEST    10026
-#define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __opus_check_val16_ptr(x)
+#define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __celt_check_glog_ptr(x)
 
 #define CELT_SET_SILK_INFO_REQUEST    10028
 #define CELT_SET_SILK_INFO(x) CELT_SET_SILK_INFO_REQUEST, __celt_check_silkinfo_ptr(x)
@@ -241,7 +243,7 @@
 #ifdef RESYNTH
 void deemphasis(celt_sig *in[], opus_res *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem, int accum);
 void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[],
-      opus_val16 *oldBandE, int start, int effEnd, int C, int CC, int isTransient,
+      celt_glog *oldBandE, int start, int effEnd, int C, int CC, int isTransient,
       int LM, int downsample, int silence, int arch);
 #endif
 
--- a/celt/celt_decoder.c
+++ b/celt/celt_decoder.c
@@ -116,10 +116,10 @@
 
    celt_sig _decode_mem[1]; /* Size = channels*(DECODE_BUFFER_SIZE+mode->overlap) */
    /* opus_val16 lpc[],  Size = channels*CELT_LPC_ORDER */
-   /* opus_val16 oldEBands[], Size = 2*mode->nbEBands */
-   /* opus_val16 oldLogE[], Size = 2*mode->nbEBands */
-   /* opus_val16 oldLogE2[], Size = 2*mode->nbEBands */
-   /* opus_val16 backgroundLogE[], Size = 2*mode->nbEBands */
+   /* celt_glog oldEBands[], Size = 2*mode->nbEBands */
+   /* celt_glog oldLogE[], Size = 2*mode->nbEBands */
+   /* celt_glog oldLogE2[], Size = 2*mode->nbEBands */
+   /* celt_glog backgroundLogE[], Size = 2*mode->nbEBands */
 };
 
 #if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS)
@@ -171,7 +171,7 @@
    int size = sizeof(struct CELTDecoder)
             + (channels*(DECODE_BUFFER_SIZE+mode->overlap)-1)*sizeof(celt_sig)
             + channels*CELT_LPC_ORDER*sizeof(opus_val16)
-            + 4*2*mode->nbEBands*sizeof(opus_val16);
+            + 4*2*mode->nbEBands*sizeof(celt_glog);
    return size;
 }
 
@@ -372,7 +372,7 @@
 static
 #endif
 void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[],
-                    opus_val16 *oldBandE, int start, int effEnd, int C, int CC,
+                    celt_glog *oldBandE, int start, int effEnd, int C, int CC,
                     int isTransient, int LM, int downsample,
                     int silence, int arch)
 {
@@ -605,7 +605,7 @@
    celt_sig *decode_mem[2];
    celt_sig *out_syn[2];
    opus_val16 *lpc;
-   opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
+   celt_glog *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
    const OpusCustomMode *mode;
    int nbEBands;
    int overlap;
@@ -625,7 +625,7 @@
       out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N;
    } while (++c<C);
    lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+overlap)*C);
-   oldBandE = lpc+C*CELT_LPC_ORDER;
+   oldBandE = (celt_glog*)(lpc+C*CELT_LPC_ORDER);
    oldLogE = oldBandE + 2*nbEBands;
    oldLogE2 = oldLogE + 2*nbEBands;
    backgroundLogE = oldLogE2  + 2*nbEBands;
@@ -644,7 +644,7 @@
       opus_uint32 seed;
       int end;
       int effEnd;
-      opus_val16 decay;
+      celt_glog decay;
       end = st->end;
       effEnd = IMAX(start, IMIN(end, mode->effEBands));
 
@@ -981,7 +981,7 @@
    celt_sig *decode_mem[2];
    celt_sig *out_syn[2];
    opus_val16 *lpc;
-   opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
+   celt_glog *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
 
    int shortBlocks;
    int isTransient;
@@ -1010,7 +1010,7 @@
    int nbEBands;
    int overlap;
    const opus_int16 *eBands;
-   opus_val16 max_background_increase;
+   celt_glog max_background_increase;
    ALLOC_STACK;
 
    VALIDATE_CELT_DECODER(st);
@@ -1023,7 +1023,7 @@
    frame_size *= st->downsample;
 
    lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+overlap)*CC);
-   oldBandE = lpc+CC*CELT_LPC_ORDER;
+   oldBandE = (celt_glog*)(lpc+CC*CELT_LPC_ORDER);
    oldLogE = oldBandE + 2*nbEBands;
    oldLogE2 = oldLogE + 2*nbEBands;
    backgroundLogE = oldLogE2  + 2*nbEBands;
@@ -1163,7 +1163,7 @@
    if (!intra_ener && st->loss_duration != 0) {
       c=0; do
       {
-         opus_val16 safety = 0;
+         celt_glog safety = 0;
          int missing = IMIN(10, st->loss_duration>>LM);
          if (LM==0) safety = QCONST16(1.5f,DB_SHIFT);
          else if (LM==1) safety = QCONST16(.5f,DB_SHIFT);
@@ -1537,8 +1537,8 @@
       case OPUS_RESET_STATE:
       {
          int i;
-         opus_val16 *lpc, *oldBandE, *oldLogE, *oldLogE2;
-         lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+st->overlap)*st->channels);
+         celt_glog *lpc, *oldBandE, *oldLogE, *oldLogE2;
+         lpc = (celt_glog*)(st->_decode_mem+(DECODE_BUFFER_SIZE+st->overlap)*st->channels);
          oldBandE = lpc+st->channels*CELT_LPC_ORDER;
          oldLogE = oldBandE + 2*st->mode->nbEBands;
          oldLogE2 = oldLogE + 2*st->mode->nbEBands;
--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -116,8 +116,8 @@
    opus_val32 overlap_max;
    opus_val16 stereo_saving;
    int intensity;
-   opus_val16 *energy_mask;
-   opus_val16 spec_avg;
+   celt_glog *energy_mask;
+   celt_glog spec_avg;
 
 #ifdef RESYNTH
    /* +MAX_PERIOD/2 to make space for overlap */
@@ -126,10 +126,10 @@
 
    celt_sig in_mem[1]; /* Size = channels*mode->overlap */
    /* celt_sig prefilter_mem[],  Size = channels*COMBFILTER_MAXPERIOD */
-   /* opus_val16 oldBandE[],     Size = channels*mode->nbEBands */
-   /* opus_val16 oldLogE[],      Size = channels*mode->nbEBands */
-   /* opus_val16 oldLogE2[],     Size = channels*mode->nbEBands */
-   /* opus_val16 energyError[],  Size = channels*mode->nbEBands */
+   /* celt_glog oldBandE[],     Size = channels*mode->nbEBands */
+   /* celt_glog oldLogE[],      Size = channels*mode->nbEBands */
+   /* celt_glog oldLogE2[],     Size = channels*mode->nbEBands */
+   /* celt_glog energyError[],  Size = channels*mode->nbEBands */
 };
 
 int celt_encoder_get_size(int channels)
@@ -143,10 +143,10 @@
    int size = sizeof(struct CELTEncoder)
          + (channels*mode->overlap-1)*sizeof(celt_sig)    /* celt_sig in_mem[channels*mode->overlap]; */
          + channels*COMBFILTER_MAXPERIOD*sizeof(celt_sig) /* celt_sig prefilter_mem[channels*COMBFILTER_MAXPERIOD]; */
-         + 4*channels*mode->nbEBands*sizeof(opus_val16);  /* opus_val16 oldBandE[channels*mode->nbEBands]; */
-                                                          /* opus_val16 oldLogE[channels*mode->nbEBands]; */
-                                                          /* opus_val16 oldLogE2[channels*mode->nbEBands]; */
-                                                          /* opus_val16 energyError[channels*mode->nbEBands]; */
+         + 4*channels*mode->nbEBands*sizeof(celt_glog);   /* celt_glog oldBandE[channels*mode->nbEBands]; */
+                                                          /* celt_glog oldLogE[channels*mode->nbEBands]; */
+                                                          /* celt_glog oldLogE2[channels*mode->nbEBands]; */
+                                                          /* celt_glog energyError[channels*mode->nbEBands]; */
    return size;
 }
 
@@ -429,12 +429,12 @@
 
 /* Looks for sudden increases of energy to decide whether we need to patch
    the transient decision */
-static int patch_transient_decision(opus_val16 *newE, opus_val16 *oldE, int nbEBands,
+static int patch_transient_decision(celt_glog *newE, celt_glog *oldE, int nbEBands,
       int start, int end, int C)
 {
    int i, c;
    opus_val32 mean_diff=0;
-   opus_val16 spread_old[26];
+   celt_glog spread_old[26];
    /* Apply an aggressive (-6 dB/Bark) spreading function to the old frame to
       avoid false detection caused by irrelevant bands */
    if (C==1)
@@ -804,9 +804,9 @@
 
 
 static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X,
-      const opus_val16 *bandLogE, int end, int LM, int C, int N0,
+      const celt_glog *bandLogE, int end, int LM, int C, int N0,
       AnalysisInfo *analysis, opus_val16 *stereo_saving, opus_val16 tf_estimate,
-      int intensity, opus_val16 surround_trim, opus_int32 equiv_rate, int arch)
+      int intensity, celt_glog surround_trim, opus_int32 equiv_rate, int arch)
 {
    int i;
    opus_val32 diff=0;
@@ -927,10 +927,10 @@
          > MULT16_32_Q15(m->eBands[13]<<(LM+1), sumLR);
 }
 
-#define MSWAP(a,b) do {opus_val16 tmp = a;a=b;b=tmp;} while(0)
-static opus_val16 median_of_5(const opus_val16 *x)
+#define MSWAP(a,b) do {celt_glog tmp = a;a=b;b=tmp;} while(0)
+static celt_glog median_of_5(const celt_glog *x)
 {
-   opus_val16 t0, t1, t2, t3, t4;
+   celt_glog t0, t1, t2, t3, t4;
    t2 = x[2];
    if (x[0] > x[1])
    {
@@ -967,9 +967,9 @@
    }
 }
 
-static opus_val16 median_of_3(const opus_val16 *x)
+static celt_glog median_of_3(const celt_glog *x)
 {
-   opus_val16 t0, t1, t2;
+   celt_glog t0, t1, t2;
    if (x[0] > x[1])
    {
       t0 = x[1];
@@ -987,22 +987,22 @@
       return t0;
 }
 
-static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2, const opus_val16 *oldBandE,
+static celt_glog dynalloc_analysis(const celt_glog *bandLogE, const celt_glog *bandLogE2, const celt_glog *oldBandE,
       int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN,
       int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM,
-      int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc,
+      int effectiveBytes, opus_int32 *tot_boost_, int lfe, celt_glog *surround_dynalloc,
       AnalysisInfo *analysis, int *importance, int *spread_weight, opus_val16 tone_freq, opus_val32 toneishness)
 {
    int i, c;
    opus_int32 tot_boost=0;
-   opus_val16 maxDepth;
-   VARDECL(opus_val16, follower);
-   VARDECL(opus_val16, noise_floor);
-   VARDECL(opus_val16, bandLogE3);
+   celt_glog maxDepth;
+   VARDECL(celt_glog, follower);
+   VARDECL(celt_glog, noise_floor);
+   VARDECL(celt_glog, bandLogE3);
    SAVE_STACK;
-   ALLOC(follower, C*nbEBands, opus_val16);
-   ALLOC(noise_floor, C*nbEBands, opus_val16);
-   ALLOC(bandLogE3, nbEBands, opus_val16);
+   ALLOC(follower, C*nbEBands, celt_glog);
+   ALLOC(noise_floor, C*nbEBands, celt_glog);
+   ALLOC(bandLogE3, nbEBands, celt_glog);
    OPUS_CLEAR(offsets, nbEBands);
    /* Dynamic allocation code */
    maxDepth=-QCONST16(31.9f, DB_SHIFT);
@@ -1022,10 +1022,10 @@
    {
       /* Compute a really simple masking model to avoid taking into account completely masked
          bands when computing the spreading decision. */
-      VARDECL(opus_val16, mask);
-      VARDECL(opus_val16, sig);
-      ALLOC(mask, nbEBands, opus_val16);
-      ALLOC(sig, nbEBands, opus_val16);
+      VARDECL(celt_glog, mask);
+      VARDECL(celt_glog, sig);
+      ALLOC(mask, nbEBands, celt_glog);
+      ALLOC(sig, nbEBands, celt_glog);
       for (i=0;i<end;i++)
          mask[i] = bandLogE[i]-noise_floor[i];
       if (C==2)
@@ -1041,7 +1041,7 @@
       for (i=0;i<end;i++)
       {
          /* Compute SMR: Mask is never more than 72 dB below the peak and never below the noise floor.*/
-         opus_val16 smr = sig[i]-MAX16(MAX16(0, maxDepth-QCONST16(12.f, DB_SHIFT)), mask[i]);
+         celt_glog smr = sig[i]-MAX16(MAX16(0, maxDepth-QCONST16(12.f, DB_SHIFT)), mask[i]);
          /* Clamp SMR to make sure we're not shifting by something negative or too large. */
 #ifdef FIXED_POINT
          /* FIXME: Use PSHR16() instead */
@@ -1063,9 +1063,9 @@
       int last=0;
       c=0;do
       {
-         opus_val16 offset;
-         opus_val16 tmp;
-         opus_val16 *f;
+         celt_glog offset;
+         celt_glog tmp;
+         celt_glog *f;
          OPUS_COPY(bandLogE3, &bandLogE2[c*nbEBands], end);
          if (LM==0) {
             /* For 2.5 ms frames, the first 8 bands have just one bin, so the
@@ -1489,8 +1489,8 @@
 static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 base_target,
       int LM, opus_int32 bitrate, int lastCodedBands, int C, int intensity,
       int constrained_vbr, opus_val16 stereo_saving, int tot_boost,
-      opus_val16 tf_estimate, int pitch_change, opus_val16 maxDepth,
-      int lfe, int has_surround_mask, opus_val16 surround_masking,
+      opus_val16 tf_estimate, int pitch_change, celt_glog maxDepth,
+      int lfe, int has_surround_mask, celt_glog surround_masking,
       opus_val16 temporal_vbr)
 {
    /* The target rate in 8th bits per frame */
@@ -1606,10 +1606,10 @@
    VARDECL(celt_sig, freq);
    VARDECL(celt_norm, X);
    VARDECL(celt_ener, bandE);
-   VARDECL(opus_val16, bandLogE);
-   VARDECL(opus_val16, bandLogE2);
+   VARDECL(celt_glog, bandLogE);
+   VARDECL(celt_glog, bandLogE2);
    VARDECL(int, fine_quant);
-   VARDECL(opus_val16, error);
+   VARDECL(celt_glog, error);
    VARDECL(int, pulses);
    VARDECL(int, cap);
    VARDECL(int, offsets);
@@ -1619,7 +1619,7 @@
    VARDECL(int, tf_res);
    VARDECL(unsigned char, collapse_masks);
    celt_sig *prefilter_mem;
-   opus_val16 *oldBandE, *oldLogE, *oldLogE2, *energyError;
+   celt_glog *oldBandE, *oldLogE, *oldLogE2, *energyError;
    int shortBlocks=0;
    int isTransient=0;
    const int CC = st->channels;
@@ -1653,7 +1653,7 @@
    int pitch_change=0;
    opus_int32 tot_boost;
    opus_val32 sample_max;
-   opus_val16 maxDepth;
+   celt_glog maxDepth;
    const OpusCustomMode *mode;
    int nbEBands;
    int overlap;
@@ -1661,9 +1661,9 @@
    int secondMdct;
    int signalBandwidth;
    int transient_got_disabled=0;
-   opus_val16 surround_masking=0;
+   celt_glog surround_masking=0;
    opus_val16 temporal_vbr=0;
-   opus_val16 surround_trim = 0;
+   celt_glog surround_trim = 0;
    opus_int32 equiv_rate;
    int hybrid;
    int weak_transient = 0;
@@ -1670,7 +1670,7 @@
    int enable_tf_analysis;
    opus_val16 tone_freq=-1;
    opus_val32 toneishness=0;
-   VARDECL(opus_val16, surround_dynalloc);
+   VARDECL(celt_glog, surround_dynalloc);
    ALLOC_STACK;
 
    mode = st->mode;
@@ -1700,7 +1700,7 @@
    N = M*mode->shortMdctSize;
 
    prefilter_mem = st->in_mem+CC*(overlap);
-   oldBandE = (opus_val16*)(st->in_mem+CC*(overlap+COMBFILTER_MAXPERIOD));
+   oldBandE = (celt_glog*)(st->in_mem+CC*(overlap+COMBFILTER_MAXPERIOD));
    oldLogE = oldBandE + CC*nbEBands;
    oldLogE2 = oldLogE + CC*nbEBands;
    energyError = oldLogE2 + CC*nbEBands;
@@ -1908,10 +1908,10 @@
 
    ALLOC(freq, CC*N, celt_sig); /**< Interleaved signal MDCTs */
    ALLOC(bandE,nbEBands*CC, celt_ener);
-   ALLOC(bandLogE,nbEBands*CC, opus_val16);
+   ALLOC(bandLogE,nbEBands*CC, celt_glog);
 
    secondMdct = shortBlocks && st->complexity>=8;
-   ALLOC(bandLogE2, C*nbEBands, opus_val16);
+   ALLOC(bandLogE2, C*nbEBands, celt_glog);
    if (secondMdct)
    {
       compute_mdcts(mode, 0, in, freq, C, CC, LM, st->upsample, st->arch);
@@ -1942,7 +1942,7 @@
    }
    amp2Log2(mode, effEnd, end, bandE, bandLogE, C);
 
-   ALLOC(surround_dynalloc, C*nbEBands, opus_val16);
+   ALLOC(surround_dynalloc, C*nbEBands, celt_glog);
    OPUS_CLEAR(surround_dynalloc, end);
    /* This computes how much masking takes place between surround channels */
    if (!hybrid&&st->energy_mask&&!st->lfe)
@@ -1958,7 +1958,7 @@
       {
          for(i=0;i<mask_end;i++)
          {
-            opus_val16 mask;
+            celt_glog mask;
             mask = MAX16(MIN16(st->energy_mask[nbEBands*c+i],
                    QCONST16(.25f, DB_SHIFT)), -QCONST16(2.0f, DB_SHIFT));
             if (mask > 0)
@@ -1981,7 +1981,7 @@
       for(i=0;i<mask_end;i++)
       {
          opus_val32 lin;
-         opus_val16 unmask;
+         celt_glog unmask;
          lin = mask_avg + diff*(i-midband);
          if (C==2)
             unmask = MAX16(st->energy_mask[i], st->energy_mask[nbEBands+i]);
@@ -2021,9 +2021,9 @@
    /* Temporal VBR (but not for LFE) */
    if (!st->lfe)
    {
-      opus_val16 follow=-QCONST16(10.0f,DB_SHIFT);
+      celt_glog follow=-QCONST16(10.0f,DB_SHIFT);
       opus_val32 frame_avg=0;
-      opus_val16 offset = shortBlocks?HALF16(SHL16(LM, DB_SHIFT)):0;
+      celt_glog offset = shortBlocks?HALF16(SHL16(LM, DB_SHIFT)):0;
       for(i=start;i<end;i++)
       {
          follow = MAX16(follow-QCONST16(1.f, DB_SHIFT), bandLogE[i]-offset);
@@ -2113,7 +2113,7 @@
       tf_select=0;
    }
 
-   ALLOC(error, C*nbEBands, opus_val16);
+   ALLOC(error, C*nbEBands, celt_glog);
    c=0;
    do {
       for (i=start;i<end;i++)
@@ -2762,8 +2762,8 @@
       case OPUS_RESET_STATE:
       {
          int i;
-         opus_val16 *oldBandE, *oldLogE, *oldLogE2;
-         oldBandE = (opus_val16*)(st->in_mem+st->channels*(st->mode->overlap+COMBFILTER_MAXPERIOD));
+         celt_glog *oldBandE, *oldLogE, *oldLogE2;
+         oldBandE = (celt_glog*)(st->in_mem+st->channels*(st->mode->overlap+COMBFILTER_MAXPERIOD));
          oldLogE = oldBandE + st->channels*st->mode->nbEBands;
          oldLogE2 = oldLogE + st->channels*st->mode->nbEBands;
          OPUS_CLEAR((char*)&st->ENCODER_RESET_START,
@@ -2831,7 +2831,7 @@
       break;
       case OPUS_SET_ENERGY_MASK_REQUEST:
       {
-          opus_val16 *value = va_arg(ap, opus_val16*);
+         celt_glog *value = va_arg(ap, celt_glog*);
           st->energy_mask = value;
       }
       break;
--- a/celt/quant_bands.c
+++ b/celt/quant_bands.c
@@ -139,7 +139,7 @@
 
 static const unsigned char small_energy_icdf[3]={2,1,0};
 
-static opus_val32 loss_distortion(const opus_val16 *eBands, opus_val16 *oldEBands, int start, int end, int len, int C)
+static opus_val32 loss_distortion(const celt_glog *eBands, celt_glog *oldEBands, int start, int end, int len, int C)
 {
    int c, i;
    opus_val32 dist = 0;
@@ -146,7 +146,7 @@
    c=0; do {
       for (i=start;i<end;i++)
       {
-         opus_val16 d = SUB16(SHR16(eBands[i+c*len], 3), SHR16(oldEBands[i+c*len], 3));
+         celt_glog d = SUB16(SHR16(eBands[i+c*len], 3), SHR16(oldEBands[i+c*len], 3));
          dist = MAC16_16(dist, d,d);
       }
    } while (++c<C);
@@ -154,10 +154,10 @@
 }
 
 static int quant_coarse_energy_impl(const CELTMode *m, int start, int end,
-      const opus_val16 *eBands, opus_val16 *oldEBands,
+      const celt_glog *eBands, celt_glog *oldEBands,
       opus_int32 budget, opus_int32 tell,
-      const unsigned char *prob_model, opus_val16 *error, ec_enc *enc,
-      int C, int LM, int intra, opus_val16 max_decay, int lfe)
+      const unsigned char *prob_model, celt_glog *error, ec_enc *enc,
+      int C, int LM, int intra, celt_glog max_decay, int lfe)
 {
    int i, c;
    int badness = 0;
@@ -184,10 +184,10 @@
          int bits_left;
          int qi, qi0;
          opus_val32 q;
-         opus_val16 x;
+         celt_glog x;
          opus_val32 f, tmp;
-         opus_val16 oldE;
-         opus_val16 decay_bound;
+         celt_glog oldE;
+         celt_glog decay_bound;
          x = eBands[i+c*m->nbEBands];
          oldE = MAX16(-QCONST16(9.f,DB_SHIFT), oldEBands[i+c*m->nbEBands]);
 #ifdef FIXED_POINT
@@ -259,14 +259,14 @@
 }
 
 void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
-      const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget,
-      opus_val16 *error, ec_enc *enc, int C, int LM, int nbAvailableBytes,
+      const celt_glog *eBands, celt_glog *oldEBands, opus_uint32 budget,
+      celt_glog *error, ec_enc *enc, int C, int LM, int nbAvailableBytes,
       int force_intra, opus_val32 *delayedIntra, int two_pass, int loss_rate, int lfe)
 {
    int intra;
-   opus_val16 max_decay;
-   VARDECL(opus_val16, oldEBands_intra);
-   VARDECL(opus_val16, error_intra);
+   celt_glog max_decay;
+   VARDECL(celt_glog, oldEBands_intra);
+   VARDECL(celt_glog, error_intra);
    ec_enc enc_start_state;
    opus_uint32 tell;
    int badness1=0;
@@ -295,8 +295,8 @@
       max_decay = QCONST16(3.f,DB_SHIFT);
    enc_start_state = *enc;
 
-   ALLOC(oldEBands_intra, C*m->nbEBands, opus_val16);
-   ALLOC(error_intra, C*m->nbEBands, opus_val16);
+   ALLOC(oldEBands_intra, C*m->nbEBands, celt_glog);
+   ALLOC(error_intra, C*m->nbEBands, celt_glog);
    OPUS_COPY(oldEBands_intra, oldEBands, C*m->nbEBands);
 
    if (two_pass || intra)
@@ -358,7 +358,7 @@
    RESTORE_STACK;
 }
 
-void quant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, ec_enc *enc, int C)
+void quant_fine_energy(const CELTMode *m, int start, int end, celt_glog *oldEBands, celt_glog *error, int *fine_quant, ec_enc *enc, int C)
 {
    int i, c;
 
@@ -371,7 +371,7 @@
       c=0;
       do {
          int q2;
-         opus_val16 offset;
+         celt_glog offset;
 #ifdef FIXED_POINT
          /* Has to be without rounding */
          q2 = (error[i+c*m->nbEBands]+QCONST16(.5f,DB_SHIFT))>>(DB_SHIFT-fine_quant[i]);
@@ -395,7 +395,7 @@
    }
 }
 
-void quant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc, int C)
+void quant_energy_finalise(const CELTMode *m, int start, int end, celt_glog *oldEBands, celt_glog *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc, int C)
 {
    int i, prio, c;
 
@@ -409,7 +409,7 @@
          c=0;
          do {
             int q2;
-            opus_val16 offset;
+            celt_glog offset;
             q2 = error[i+c*m->nbEBands]<0 ? 0 : 1;
             ec_enc_bits(enc, q2, 1);
 #ifdef FIXED_POINT
@@ -425,7 +425,7 @@
    }
 }
 
-void unquant_coarse_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int intra, ec_dec *dec, int C, int LM)
+void unquant_coarse_energy(const CELTMode *m, int start, int end, celt_glog *oldEBands, int intra, ec_dec *dec, int C, int LM)
 {
    const unsigned char *prob_model = e_prob_model[LM][intra];
    int i, c;
@@ -490,7 +490,7 @@
    }
 }
 
-void unquant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, ec_dec *dec, int C)
+void unquant_fine_energy(const CELTMode *m, int start, int end, celt_glog *oldEBands, int *fine_quant, ec_dec *dec, int C)
 {
    int i, c;
    /* Decode finer resolution */
@@ -501,7 +501,7 @@
       c=0;
       do {
          int q2;
-         opus_val16 offset;
+         celt_glog offset;
          q2 = ec_dec_bits(dec, fine_quant[i]);
 #ifdef FIXED_POINT
          offset = SUB16(SHR32(SHL32(EXTEND32(q2),DB_SHIFT)+QCONST16(.5f,DB_SHIFT),fine_quant[i]),QCONST16(.5f,DB_SHIFT));
@@ -513,7 +513,7 @@
    }
 }
 
-void unquant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant,  int *fine_priority, int bits_left, ec_dec *dec, int C)
+void unquant_energy_finalise(const CELTMode *m, int start, int end, celt_glog *oldEBands, int *fine_quant,  int *fine_priority, int bits_left, ec_dec *dec, int C)
 {
    int i, prio, c;
 
@@ -527,7 +527,7 @@
          c=0;
          do {
             int q2;
-            opus_val16 offset;
+            celt_glog offset;
             q2 = ec_dec_bits(dec, 1);
 #ifdef FIXED_POINT
             offset = SHR16(SHL16(q2,DB_SHIFT)-QCONST16(.5f,DB_SHIFT),fine_quant[i]+1);
@@ -542,7 +542,7 @@
 }
 
 void amp2Log2(const CELTMode *m, int effEnd, int end,
-      celt_ener *bandE, opus_val16 *bandLogE, int C)
+      celt_ener *bandE, celt_glog *bandLogE, int C)
 {
    int c, i;
    c=0;
@@ -551,7 +551,7 @@
       {
          bandLogE[i+c*m->nbEBands] =
                celt_log2(bandE[i+c*m->nbEBands])
-               - SHL16((opus_val16)eMeans[i],DB_SHIFT-4);
+               - SHL16((celt_glog)eMeans[i],DB_SHIFT-4);
 #ifdef FIXED_POINT
          /* Compensate for bandE[] being Q12 but celt_log2() taking a Q14 input. */
          bandLogE[i+c*m->nbEBands] += QCONST16(2.f, DB_SHIFT);
--- a/celt/quant_bands.h
+++ b/celt/quant_bands.h
@@ -42,25 +42,25 @@
 #endif
 
 void amp2Log2(const CELTMode *m, int effEnd, int end,
-      celt_ener *bandE, opus_val16 *bandLogE, int C);
+      celt_ener *bandE, celt_glog *bandLogE, int C);
 
 void log2Amp(const CELTMode *m, int start, int end,
-      celt_ener *eBands, const opus_val16 *oldEBands, int C);
+      celt_ener *eBands, const celt_glog *oldEBands, int C);
 
 void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
-      const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget,
-      opus_val16 *error, ec_enc *enc, int C, int LM,
+      const celt_glog *eBands, celt_glog *oldEBands, opus_uint32 budget,
+      celt_glog *error, ec_enc *enc, int C, int LM,
       int nbAvailableBytes, int force_intra, opus_val32 *delayedIntra,
       int two_pass, int loss_rate, int lfe);
 
-void quant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, ec_enc *enc, int C);
+void quant_fine_energy(const CELTMode *m, int start, int end, celt_glog *oldEBands, celt_glog *error, int *fine_quant, ec_enc *enc, int C);
 
-void quant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc, int C);
+void quant_energy_finalise(const CELTMode *m, int start, int end, celt_glog *oldEBands, celt_glog *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc, int C);
 
-void unquant_coarse_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int intra, ec_dec *dec, int C, int LM);
+void unquant_coarse_energy(const CELTMode *m, int start, int end, celt_glog *oldEBands, int intra, ec_dec *dec, int C, int LM);
 
-void unquant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, ec_dec *dec, int C);
+void unquant_fine_energy(const CELTMode *m, int start, int end, celt_glog *oldEBands, int *fine_quant, ec_dec *dec, int C);
 
-void unquant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, int *fine_priority, int bits_left, ec_dec *dec, int C);
+void unquant_energy_finalise(const CELTMode *m, int start, int end, celt_glog *oldEBands, int *fine_quant, int *fine_priority, int bits_left, ec_dec *dec, int C);
 
 #endif /* QUANT_BANDS */
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -119,7 +119,7 @@
     int          silk_bw_switch;
     /* Sampling rate (at the API level) */
     int          first;
-    opus_val16 * energy_masking;
+    celt_glog * energy_masking;
     StereoWidthState width_mem;
     opus_res     delay_buffer[MAX_ENCODER_BUFFER*2];
 #ifndef DISABLE_FLOAT_API
@@ -3102,7 +3102,7 @@
         break;
         case OPUS_SET_ENERGY_MASK_REQUEST:
         {
-            opus_val16 *value = va_arg(ap, opus_val16*);
+            celt_glog *value = va_arg(ap, celt_glog*);
             st->energy_masking = value;
             ret = celt_encoder_ctl(celt_enc, OPUS_SET_ENERGY_MASK(value));
         }
--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -221,7 +221,7 @@
 }
 #endif
 
-void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *bandLogE, opus_val32 *mem, opus_val32 *preemph_mem,
+void surround_analysis(const CELTMode *celt_mode, const void *pcm, celt_glog *bandLogE, opus_val32 *mem, opus_val32 *preemph_mem,
       int len, int overlap, int channels, int rate, opus_copy_channel_in_func copy_channel_in, int arch
 )
 {
@@ -234,7 +234,7 @@
    int freq_size;
    opus_val16 channel_offset;
    opus_val32 bandE[21];
-   opus_val16 maskLogE[3][21];
+   celt_glog maskLogE[3][21];
    VARDECL(opus_val32, in);
    VARDECL(opus_res, x);
    VARDECL(opus_val32, freq);
@@ -347,7 +347,7 @@
 #endif
    for (c=0;c<channels;c++)
    {
-      opus_val16 *mask;
+      celt_glog *mask;
       if (pos[c]!=0)
       {
          mask = &maskLogE[pos[c]-1][0];
@@ -820,13 +820,13 @@
    char *ptr;
    int tot_size;
    VARDECL(opus_res, buf);
-   VARDECL(opus_val16, bandSMR);
+   VARDECL(celt_glog, bandSMR);
    unsigned char tmp_data[MS_FRAME_TMP];
    OpusRepacketizer rp;
    opus_int32 vbr;
    const CELTMode *celt_mode;
    opus_int32 bitrates[256];
-   opus_val16 bandLogE[42];
+   celt_glog bandLogE[42];
    opus_val32 *mem = NULL;
    opus_val32 *preemph_mem=NULL;
    int frame_size;
@@ -866,7 +866,7 @@
    coupled_size = opus_encoder_get_size(2);
    mono_size = opus_encoder_get_size(1);
 
-   ALLOC(bandSMR, 21*st->layout.nb_channels, opus_val16);
+   ALLOC(bandSMR, 21*st->layout.nb_channels, celt_glog);
    if (st->mapping_type == MAPPING_TYPE_SURROUND)
    {
       surround_analysis(celt_mode, pcm, bandSMR, mem, preemph_mem, frame_size, 120, st->layout.nb_channels, Fs, copy_channel_in, st->arch);
--