shithub: opus

Download patch

ref: 23e654ff82b6e6c4a0cabf0fd64dd590891f9ea4
parent: 0527f3735209a70494a1d6894d8bf5a0597a37d8
author: Gregory Maxwell <[email protected]>
date: Sat Sep 27 12:20:03 EDT 2008

Allow all even frame sizes, change the selection of number of short MDCTs per frame to be more intelligent.

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -261,7 +261,7 @@
       RESTORE_STACK;
    } else {
       const mdct_lookup *lookup = &mode->shortMdct;
-      const int overlap = mode->shortMdctSize;
+      const int overlap = mode->overlap;
       const int N = mode->shortMdctSize;
       int b, c;
       VARDECL(celt_word32_t, x);
@@ -312,7 +312,7 @@
          for (j=0;j<N;j++)
             tmp[j] = X[C*j+c];
          /* Prevents problems from the imdct doing the overlap-add */
-         CELT_MEMSET(x+N4, 0, overlap);
+         CELT_MEMSET(x+N4, 0, N);
          mdct_backward(lookup, tmp, x, mode->window, overlap);
          celt_assert(transient_shift == 0);
          /* The first and last part would need to be set to zero if we actually
@@ -335,7 +335,7 @@
          ALLOC(x, 2*N, celt_word32_t);
          ALLOC(tmp, N, celt_word32_t);
          /* Prevents problems from the imdct doing the overlap-add */
-         CELT_MEMSET(x+N4, 0, overlap);
+         CELT_MEMSET(x+N4, 0, N2);
          for (b=0;b<B;b++)
          {
             /* De-interleaving the sub-frames */
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -338,24 +338,35 @@
    mode->eBands = compute_ebands(Fs, frame_size, &mode->nbEBands);
    compute_pbands(mode, res);
    mode->ePredCoef = QCONST16(.8f,15);
-   
-   if (frame_size <= 64)
+
+   if (frame_size > 384 && (frame_size%8)==0)
    {
-      mode->nbShortMdcts = 1;
-   } else if (frame_size <= 256)
+     mode->nbShortMdcts = 4;
+   } else if (frame_size > 384 && (frame_size%10)==0)
    {
-      mode->nbShortMdcts = 2;
-   } else if (frame_size <= 384)
+     mode->nbShortMdcts = 5;
+   } else if (frame_size > 256 && (frame_size%6)==0)
    {
-      mode->nbShortMdcts = 3;
-   } else {
-      mode->nbShortMdcts = 4;
+     mode->nbShortMdcts = 3;
+   } else if (frame_size > 256 && (frame_size%8)==0)
+   {
+     mode->nbShortMdcts = 4;
+   } else if (frame_size > 64 && (frame_size%4)==0)
+   {
+     mode->nbShortMdcts = 2;
+   } else if (frame_size > 128 && (frame_size%6)==0)
+   {
+     mode->nbShortMdcts = 3;
+   } else
+   {
+     mode->nbShortMdcts = 1;
    }
+
    if (mode->nbShortMdcts > 1)
-      mode->overlap = frame_size/mode->nbShortMdcts;
+      mode->overlap = ((frame_size/mode->nbShortMdcts)>>2)<<2; /* Overlap must be divisible by 4 */
    else
-      mode->overlap = frame_size/2;
-   
+      mode->overlap = (frame_size>>3)<<2;
+
    compute_allocation_table(mode, res);
    /*printf ("%d bands\n", mode->nbEBands);*/