shithub: opus

Download patch

ref: e4c05a4d744a3d9600dcb87d7102b279ba1292a4
parent: 18c1c22e160a3f5f6073d276c006301355fa6aee
author: Jean-Marc Valin <[email protected]>
date: Sat May 30 06:09:06 EDT 2009

Making the modified transient code work with stereo as well

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -547,15 +547,18 @@
    compute_mdcts(st->mode, shortBlocks, in, freq);
    if (shortBlocks && !transient_shift) 
    {
-      celt_word32_t sum[4];
-      int m=0;
-      do {
-         sum[m] = 1;
-         celt_word32_t tmp=0;
-         for (i=m;i<N;i+=st->mode->nbShortMdcts)
-            tmp += ABS32(freq[i]);
-         sum[m++] = tmp;
-      } while (m<st->mode->nbShortMdcts);
+      celt_word32_t sum[4]={1,1,1,1};
+      int m;
+      for (c=0;c<C;c++)
+      {
+         m=0;
+         do {
+            celt_word32_t tmp=0;
+            for (i=m*C+c;i<N;i+=C*st->mode->nbShortMdcts)
+               tmp += ABS32(freq[i]);
+            sum[m++] += tmp;
+         } while (m<st->mode->nbShortMdcts);
+      }
       m=0;
 #ifdef FIXED_POINT
       do {
@@ -570,8 +573,13 @@
          }
          m++;
       } while (m<st->mode->nbShortMdcts-1);
-      for (i=1;i<N;i+=2)
-         freq[i] = SHR32(freq[i],mdct_weight_shift);
+      if (mdct_weight_shift)
+      {
+         for (c=0;c<C;c++)
+            for (m=mdct_weight_pos+1;m<st->mode->nbShortMdcts;m++)
+               for (i=m*C+c;i<N;i+=C*st->mode->nbShortMdcts)
+                  freq[i] = SHR32(freq[i],mdct_weight_shift);
+      }
 #else
       do {
          if (sum[m+1] > 8*sum[m])
@@ -587,9 +595,10 @@
       } while (m<st->mode->nbShortMdcts-1);
       if (mdct_weight_shift)
       {
-         for (m=mdct_weight_pos+1;m<st->mode->nbShortMdcts;m++)
-            for (i=m;i<N;i+=st->mode->nbShortMdcts)
-               freq[i] = (1./(1<<mdct_weight_shift))*freq[i];
+         for (c=0;c<C;c++)
+            for (m=mdct_weight_pos+1;m<st->mode->nbShortMdcts;m++)
+               for (i=m*C+c;i<N;i+=C*st->mode->nbShortMdcts)
+                  freq[i] = (1./(1<<mdct_weight_shift))*freq[i];
       }
 #endif
       /*printf ("%f\n", short_ratio);*/
@@ -793,12 +802,13 @@
       if (mdct_weight_shift)
       {
          int m;
-         for (m=mdct_weight_pos+1;m<st->mode->nbShortMdcts;m++)
-            for (i=m;i<N;i+=st->mode->nbShortMdcts)
+         for (c=0;c<C;c++)
+            for (m=mdct_weight_pos+1;m<st->mode->nbShortMdcts;m++)
+               for (i=m*C+c;i<N;i+=C*st->mode->nbShortMdcts)
 #ifdef FIXED_POINT
-               freq[i] = SHL32(freq[i], mdct_weight_shift);
+                  freq[i] = SHL32(freq[i], mdct_weight_shift);
 #else
-               freq[i] = (1<<mdct_weight_shift)*freq[i];
+                  freq[i] = (1<<mdct_weight_shift)*freq[i];
 #endif
       }
       compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem);
@@ -1251,12 +1261,13 @@
    if (mdct_weight_shift)
    {
       int m;
-      for (m=mdct_weight_pos+1;m<st->mode->nbShortMdcts;m++)
-         for (i=m;i<N;i+=st->mode->nbShortMdcts)
+      for (c=0;c<C;c++)
+         for (m=mdct_weight_pos+1;m<st->mode->nbShortMdcts;m++)
+            for (i=m*C+c;i<N;i+=C*st->mode->nbShortMdcts)
 #ifdef FIXED_POINT
-            freq[i] = SHL32(freq[i], mdct_weight_shift);
+               freq[i] = SHL32(freq[i], mdct_weight_shift);
 #else
-            freq[i] = (1<<mdct_weight_shift)*freq[i];
+               freq[i] = (1<<mdct_weight_shift)*freq[i];
 #endif
    }
    /* Compute inverse MDCTs */