Eliminate the ec_int32 and ec_uint32 typedefs.
[opus.git] / libcelt / celt.c
index 1ffe6e3..47697c0 100644 (file)
@@ -113,7 +113,7 @@ struct CELTEncoder {
    /* Everything beyond this point gets cleared on a reset */
 #define ENCODER_RESET_START rng
 
-   ec_uint32 rng;
+   celt_uint32 rng;
    int spread_decision;
    int delayedIntra;
    int tonal_average;
@@ -317,9 +317,9 @@ static int transient_analysis(const celt_word32 * restrict in, int len, int C,
    for (i=0;i<N;i++)
    {
       int j;
-      float max_abs=0;
+      celt_word16 max_abs=0;
       for (j=0;j<block;j++)
-         max_abs = MAX32(max_abs, tmp[i*block+j]);
+         max_abs = MAX16(max_abs, ABS16(tmp[i*block+j]));
       bins[i] = max_abs;
    }
    for (i=0;i<N;i++)
@@ -687,8 +687,8 @@ static void tf_encode(int start, int end, int isTransient, int *tf_res, int LM,
    int tf_select_rsv;
    int tf_changed;
    int logp;
-   ec_uint32 budget;
-   ec_uint32 tell;
+   celt_uint32 budget;
+   celt_uint32 tell;
    budget = enc->storage*8;
    tell = ec_tell(enc);
    logp = isTransient ? 2 : 4;
@@ -727,8 +727,8 @@ static void tf_decode(int start, int end, int isTransient, int *tf_res, int LM,
    int tf_select_rsv;
    int tf_changed;
    int logp;
-   ec_uint32 budget;
-   ec_uint32 tell;
+   celt_uint32 budget;
+   celt_uint32 tell;
 
    budget = dec->storage*8;
    tell = ec_tell(dec);
@@ -952,7 +952,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
    {
       celt_int32 den=st->mode->Fs>>BITRES;
       vbr_rate=(st->bitrate*frame_size+(den>>1))/den;
-      effectiveBytes = vbr_rate>>3;
+      effectiveBytes = vbr_rate>>(3+BITRES);
    } else {
       celt_int32 tmp;
       vbr_rate = 0;
@@ -1148,11 +1148,17 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
 #endif /* ENABLE_POSTFILTER */
 
       c=0; do {
+         int offset = st->mode->shortMdctSize-st->mode->overlap;
          st->prefilter_period=IMAX(st->prefilter_period, COMBFILTER_MINPERIOD);
          CELT_COPY(in+c*(N+st->overlap), st->in_mem+c*(st->overlap), st->overlap);
 #ifdef ENABLE_POSTFILTER
-         comb_filter(in+c*(N+st->overlap)+st->overlap, pre[c]+COMBFILTER_MAXPERIOD,
-               st->prefilter_period, pitch_index, N, -st->prefilter_gain, -gain1,
+         if (offset)
+            comb_filter(in+c*(N+st->overlap)+st->overlap, pre[c]+COMBFILTER_MAXPERIOD,
+                  st->prefilter_period, st->prefilter_period, offset, -st->prefilter_gain, -st->prefilter_gain,
+                  st->prefilter_tapset, st->prefilter_tapset, NULL, 0);
+
+         comb_filter(in+c*(N+st->overlap)+st->overlap+offset, pre[c]+COMBFILTER_MAXPERIOD+offset,
+               st->prefilter_period, pitch_index, N-offset, -st->prefilter_gain, -gain1,
                st->prefilter_tapset, prefilter_tapset, st->mode->window, st->mode->overlap);
 #endif /* ENABLE_POSTFILTER */
          CELT_COPY(st->in_mem+c*(st->overlap), in+c*(N+st->overlap)+N, st->overlap);
@@ -1535,19 +1541,13 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
       c=0; do {
          st->prefilter_period=IMAX(st->prefilter_period, COMBFILTER_MINPERIOD);
          st->prefilter_period_old=IMAX(st->prefilter_period_old, COMBFILTER_MINPERIOD);
+         comb_filter(out_mem[c], out_mem[c], st->prefilter_period_old, st->prefilter_period, st->mode->shortMdctSize,
+               st->prefilter_gain_old, st->prefilter_gain, st->prefilter_tapset_old, st->prefilter_tapset,
+               st->mode->window, st->overlap);
          if (LM!=0)
-         {
-            comb_filter(out_mem[c], out_mem[c], st->prefilter_period, st->prefilter_period, st->overlap,
-                  st->prefilter_gain, st->prefilter_gain, st->prefilter_tapset, st->prefilter_tapset,
-                  NULL, 0);
-            comb_filter(out_mem[c]+st->overlap, out_mem[c]+st->overlap, st->prefilter_period, pitch_index, N-st->overlap,
+            comb_filter(out_mem[c]+st->mode->shortMdctSize, out_mem[c]+st->mode->shortMdctSize, st->prefilter_period, pitch_index, N-st->mode->shortMdctSize,
                   st->prefilter_gain, gain1, st->prefilter_tapset, prefilter_tapset,
                   st->mode->window, st->mode->overlap);
-         } else {
-            comb_filter(out_mem[c], out_mem[c], st->prefilter_period_old, st->prefilter_period, N,
-                  st->prefilter_gain_old, st->prefilter_gain, st->prefilter_tapset_old, st->prefilter_tapset,
-                  st->mode->window, st->mode->overlap);
-         }
       } while (++c<CC);
 #endif /* ENABLE_POSTFILTER */
 
@@ -1561,6 +1561,14 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
    st->prefilter_period = pitch_index;
    st->prefilter_gain = gain1;
    st->prefilter_tapset = prefilter_tapset;
+#ifdef RESYNTH
+   if (LM!=0)
+   {
+      st->prefilter_period_old = st->prefilter_period;
+      st->prefilter_gain_old = st->prefilter_gain;
+      st->prefilter_tapset_old = st->prefilter_tapset;
+   }
+#endif
 
    if (CC==2&&C==1) {
       for (i=0;i<st->mode->nbEBands;i++)
@@ -1802,7 +1810,7 @@ struct CELTDecoder {
    /* Everything beyond this point gets cleared on a reset */
 #define DECODER_RESET_START rng
 
-   ec_uint32 rng;
+   celt_uint32 rng;
    int last_pitch_index;
    int loss_count;
    int postfilter_period;
@@ -1959,17 +1967,26 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p
       log2Amp(st->mode, st->start, st->end, bandE, backgroundLogE, C);
 
       seed = st->rng;
-      for (i=0;i<C*N;i++)
+      for (c=0;c<C;c++)
       {
-            seed = lcg_rand(seed);
-            X[i] = (celt_int32)(seed)>>20;
+         for (i=0;i<st->mode->effEBands;i++)
+         {
+            int j;
+            int boffs;
+            int blen;
+            boffs = N*c+(st->mode->eBands[i]<<LM);
+            blen = (st->mode->eBands[i+1]-st->mode->eBands[i])<<LM;
+            for (j=0;j<blen;j++)
+            {
+               seed = lcg_rand(seed);
+               X[boffs+j] = (celt_int32)(seed)>>20;
+            }
+            renormalise_vector(X+boffs, blen, Q15ONE);
+         }
       }
       st->rng = seed;
-      for (c=0;c<C;c++)
-         for (i=0;i<st->mode->nbEBands;i++)
-            renormalise_vector(X+N*c+(st->mode->eBands[i]<<LM), (st->mode->eBands[i+1]-st->mode->eBands[i])<<LM, Q15ONE);
 
-      denormalise_bands(st->mode, X, freq, bandE, st->mode->nbEBands, C, 1<<LM);
+      denormalise_bands(st->mode, X, freq, bandE, st->mode->effEBands, C, 1<<LM);
 
       compute_inv_mdcts(st->mode, 0, freq, out_syn, overlap_mem, C, LM);
       plc = 0;
@@ -2436,19 +2453,14 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
    c=0; do {
       st->postfilter_period=IMAX(st->postfilter_period, COMBFILTER_MINPERIOD);
       st->postfilter_period_old=IMAX(st->postfilter_period_old, COMBFILTER_MINPERIOD);
+      comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfilter_period, st->mode->shortMdctSize,
+            st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_old, st->postfilter_tapset,
+            st->mode->window, st->overlap);
       if (LM!=0)
-      {
-         comb_filter(out_syn[c], out_syn[c], st->postfilter_period, st->postfilter_period, st->overlap,
-               st->postfilter_gain, st->postfilter_gain, st->postfilter_tapset, st->postfilter_tapset,
-               NULL, 0);
-         comb_filter(out_syn[c]+st->overlap, out_syn[c]+st->overlap, st->postfilter_period, postfilter_pitch, N-st->overlap,
+         comb_filter(out_syn[c]+st->mode->shortMdctSize, out_syn[c]+st->mode->shortMdctSize, st->postfilter_period, postfilter_pitch, N-st->mode->shortMdctSize,
                st->postfilter_gain, postfilter_gain, st->postfilter_tapset, postfilter_tapset,
                st->mode->window, st->mode->overlap);
-      } else {
-         comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfilter_period, N-st->overlap,
-               st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_old, st->postfilter_tapset,
-               st->mode->window, st->mode->overlap);
-      }
+
    } while (++c<CC);
    st->postfilter_period_old = st->postfilter_period;
    st->postfilter_gain_old = st->postfilter_gain;
@@ -2456,6 +2468,12 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
    st->postfilter_period = postfilter_pitch;
    st->postfilter_gain = postfilter_gain;
    st->postfilter_tapset = postfilter_tapset;
+   if (LM!=0)
+   {
+      st->postfilter_period_old = st->postfilter_period;
+      st->postfilter_gain_old = st->postfilter_gain;
+      st->postfilter_tapset_old = st->postfilter_tapset;
+   }
 #endif /* ENABLE_POSTFILTER */
 
    if (CC==2&&C==1) {