Allow all even frame sizes, change the selection of number of short MDCTs per frame...
authorGregory Maxwell <greg@xiph.org>
Sat, 27 Sep 2008 20:20:03 +0000 (16:20 -0400)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Sun, 28 Sep 2008 01:23:54 +0000 (21:23 -0400)
libcelt/celt.c
libcelt/modes.c

index 0433c62..3095d33 100644 (file)
@@ -261,7 +261,7 @@ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig_t * re
       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 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig_t
          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 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig_t
          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 */
index a2eb973..72ae883 100644 (file)
@@ -338,24 +338,35 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int *e
    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 = 4;
+   } else if (frame_size > 384 && (frame_size%10)==0)
+   {
+     mode->nbShortMdcts = 5;
+   } else if (frame_size > 256 && (frame_size%6)==0)
+   {
+     mode->nbShortMdcts = 3;
+   } else if (frame_size > 256 && (frame_size%8)==0)
    {
-      mode->nbShortMdcts = 1;
-   } else if (frame_size <= 256)
+     mode->nbShortMdcts = 4;
+   } else if (frame_size > 64 && (frame_size%4)==0)
    {
-      mode->nbShortMdcts = 2;
-   } else if (frame_size <= 384)
+     mode->nbShortMdcts = 2;
+   } else if (frame_size > 128 && (frame_size%6)==0)
    {
-      mode->nbShortMdcts = 3;
-   } else {
-      mode->nbShortMdcts = 4;
+     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);*/