shithub: opus

Download patch

ref: 70d30ffc099eb6dad8aa08546251f0723138ff5e
parent: 546dfa19597a5177785869bb8ea7e8ac239cea87
author: Jean-Marc Valin <[email protected]>
date: Mon Dec 13 08:50:29 EST 2010

Using overlap=shortMdctSize even for 2.5 ms frames.

And fixed a post-filter bug for that special case.

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -84,6 +84,10 @@
 
    int prefilter_period;
    celt_word16 prefilter_gain;
+#ifdef RESYNTH
+   int prefilter_period_old;
+   celt_word16 prefilter_gain_old;
+#endif
 
    /* VBR-related parameters */
    celt_int32 vbr_reservoir;
@@ -863,6 +867,7 @@
 #endif /* ENABLE_POSTFILTER */
 
       c=0; do {
+         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,
@@ -1179,14 +1184,24 @@
 
 #ifdef ENABLE_POSTFILTER
       c=0; do {
-         comb_filter(out_mem[c], out_mem[c], st->prefilter_period, st->prefilter_period, st->overlap, C,
-               st->prefilter_gain, st->prefilter_gain, NULL, 0);
-         comb_filter(out_mem[c]+st->overlap, out_mem[c]+st->overlap, st->prefilter_period, pitch_index, N-st->overlap, C,
-               st->prefilter_gain, gain1, st->mode->window, st->mode->overlap);
+         st->prefilter_period=IMAX(st->prefilter_period, COMBFILTER_MINPERIOD);
+         st->prefilter_period_old=IMAX(st->prefilter_period_old, COMBFILTER_MINPERIOD);
+         if (LM!=0)
+         {
+            comb_filter(out_mem[c], out_mem[c], st->prefilter_period, st->prefilter_period, st->overlap, C,
+                  st->prefilter_gain, st->prefilter_gain, NULL, 0);
+            comb_filter(out_mem[c]+st->overlap, out_mem[c]+st->overlap, st->prefilter_period, pitch_index, N-st->overlap, C,
+                  st->prefilter_gain, gain1, st->mode->window, st->mode->overlap);
+         } else {
+            comb_filter(out_mem[c], out_mem[c], st->prefilter_period_old, st->prefilter_period, N, C,
+                  st->prefilter_gain_old, st->prefilter_gain, st->mode->window, st->mode->overlap);
+         }
       } while (++c<C);
 #endif /* ENABLE_POSTFILTER */
 
       deemphasis(out_mem, (celt_word16*)pcm, N, C, st->mode->preemph, st->preemph_memD);
+      st->prefilter_period_old = st->prefilter_period;
+      st->prefilter_gain_old = st->prefilter_gain;
    }
 #endif
 
@@ -1407,7 +1422,9 @@
    int last_pitch_index;
    int loss_count;
    int postfilter_period;
+   int postfilter_period_old;
    celt_word16 postfilter_gain;
+   celt_word16 postfilter_gain_old;
 
    celt_sig preemph_memD[2];
    
@@ -1889,11 +1906,21 @@
 
 #ifdef ENABLE_POSTFILTER
    c=0; do {
-      comb_filter(out_syn[c], out_syn[c], st->postfilter_period, st->postfilter_period, st->overlap, C,
-            st->postfilter_gain, st->postfilter_gain, NULL, 0);
-      comb_filter(out_syn[c]+st->overlap, out_syn[c]+st->overlap, st->postfilter_period, postfilter_pitch, N-st->overlap, C,
-            st->postfilter_gain, postfilter_gain, st->mode->window, st->mode->overlap);
+      st->postfilter_period=IMAX(st->postfilter_period, COMBFILTER_MINPERIOD);
+      st->postfilter_period_old=IMAX(st->postfilter_period_old, COMBFILTER_MINPERIOD);
+      if (LM!=0)
+      {
+         comb_filter(out_syn[c], out_syn[c], st->postfilter_period, st->postfilter_period, st->overlap, C,
+               st->postfilter_gain, st->postfilter_gain, NULL, 0);
+         comb_filter(out_syn[c]+st->overlap, out_syn[c]+st->overlap, st->postfilter_period, postfilter_pitch, N-st->overlap, C,
+               st->postfilter_gain, postfilter_gain, 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, C,
+               st->postfilter_gain_old, st->postfilter_gain, st->mode->window, st->mode->overlap);
+      }
    } while (++c<C);
+   st->postfilter_period_old = st->postfilter_period;
+   st->postfilter_gain_old = st->postfilter_gain;
    st->postfilter_period = postfilter_pitch;
    st->postfilter_gain = postfilter_gain;
 #endif /* ENABLE_POSTFILTER */
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -365,11 +365,7 @@
       mode->effEBands--;
    
    /* Overlap must be divisible by 4 */
-   if (mode->nbShortMdcts > 1)
-      mode->overlap = (mode->shortMdctSize>>2)<<2;
-   else
-      mode->overlap = (frame_size>>3)<<2;
-
+   mode->overlap = ((mode->shortMdctSize>>2)<<2);
 
    compute_allocation_table(mode, res);
    if (mode->allocVectors==NULL)