shithub: opus

Download patch

ref: 073d0bc9254d9425585b6614fc9e1b01f3764f0f
parent: 0475267e6284a09257988a4529da51a8ed22c2cd
author: Jean-Marc Valin <[email protected]>
date: Wed May 5 17:37:53 EDT 2010

Yet another step towards variable frame size

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -472,7 +472,7 @@
       int curr_balance, curr_bits;
       
       N = M*eBands[i+1]-M*eBands[i];
-      BPbits = m->bits;
+      BPbits = m->bits[FULL_FRAME(m)];
 
       if (encode)
          tell = ec_enc_tell(enc_dec, BITRES);
@@ -552,7 +552,7 @@
       
       X = _X+M*eBands[i];
       Y = X+M*eBands[m->nbEBands+1];
-      BPbits = m->bits;
+      BPbits = m->bits[FULL_FRAME(m)];
 
       N = M*eBands[i+1]-M*eBands[i];
       tell = ec_enc_tell(enc, BITRES);
@@ -789,7 +789,7 @@
       
       X = _X+M*eBands[i];
       Y = X+M*eBands[m->nbEBands+1];
-      BPbits = m->bits;
+      BPbits = m->bits[FULL_FRAME(m)];
 
       N = M*eBands[i+1]-M*eBands[i];
       tell = ec_dec_tell(dec, BITRES);
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -328,11 +328,11 @@
    const int C = CHANNELS(_C);
    if (C==1 && !shortBlocks)
    {
-      const mdct_lookup *lookup = MDCT(mode);
+      const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
       const int overlap = OVERLAP(mode);
       clt_mdct_forward(lookup, in, out, mode->window, overlap);
    } else {
-      const mdct_lookup *lookup = MDCT(mode);
+      const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
       const int overlap = OVERLAP(mode);
       int N = FRAMESIZE(mode);
       int B = 1;
@@ -342,7 +342,7 @@
       SAVE_STACK;
       if (shortBlocks)
       {
-         lookup = &mode->shortMdct;
+         lookup = &mode->mdct[0];
          N = mode->shortMdctSize;
          B = shortBlocks;
       }
@@ -378,7 +378,7 @@
    {
       int j;
       if (transient_shift==0 && C==1 && !shortBlocks) {
-         const mdct_lookup *lookup = MDCT(mode);
+         const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
          clt_mdct_backward(lookup, X, out_mem+C*(MAX_PERIOD-N-N4), mode->window, overlap);
       } else {
          VARDECL(celt_word32, x);
@@ -387,7 +387,7 @@
          int N2 = N;
          int B = 1;
          int n4offset=0;
-         const mdct_lookup *lookup = MDCT(mode);
+         const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
          SAVE_STACK;
          
          ALLOC(x, 2*N, celt_word32);
@@ -395,7 +395,7 @@
 
          if (shortBlocks)
          {
-            lookup = &mode->shortMdct;
+            lookup = &mode->mdct[0];
             N2 = mode->shortMdctSize;
             B = shortBlocks;
             n4offset = N4;
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -325,27 +325,15 @@
    mode->mdctSize = frame_size;
    mode->ePredCoef = QCONST16(.8f,15);
 
-   if (frame_size > 640 && (frame_size%16)==0)
+   if (frame_size >= 640 && (frame_size%16)==0)
    {
      mode->nbShortMdcts = 8;
-   } else if (frame_size > 384 && (frame_size%8)==0)
+   } else if (frame_size >= 320 && (frame_size%8)==0)
    {
      mode->nbShortMdcts = 4;
-   } else if (frame_size > 384 && (frame_size%10)==0)
+   } else if (frame_size >= 120 && (frame_size%4)==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 = 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;
@@ -384,7 +372,12 @@
 #endif
    mode->window = window;
 
-   mode->bits = (const celt_int16 **)compute_alloc_cache(mode, 1, mode->nbShortMdcts);
+   for (i=0;(1<<i)<=mode->nbShortMdcts;i++)
+   {
+      /* FIXME: Do something for i==0 */
+      if (i!=0)
+         mode->bits[i] = (const celt_int16 **)compute_alloc_cache(mode, 1, 1<<i);
+   }
    if (mode->bits==NULL)
       goto failure;
 
@@ -397,16 +390,18 @@
    mode->logN = logN;
 #endif /* !STATIC_MODES */
 
-   clt_mdct_init(&mode->mdct, 2*mode->mdctSize);
-
-   clt_mdct_init(&mode->shortMdct, 2*mode->shortMdctSize);
-
-   mode->prob = quant_prob_alloc(mode);
-   if ((mode->mdct.trig==NULL) || (mode->shortMdct.trig==NULL)
+   for (i=0;(1<<i)<=mode->nbShortMdcts;i++)
+   {
+      clt_mdct_init(&mode->mdct[i], 2*mode->shortMdctSize<<i);
+      if ((mode->mdct[i].trig==NULL)
 #ifndef ENABLE_TI_DSPLIB55
-        || (mode->mdct.kfft==NULL) || (mode->shortMdct.kfft==NULL)
+           || (mode->mdct[i].kfft==NULL)
 #endif
-        || (mode->prob==NULL))
+      )
+        goto failure;
+   }
+   mode->prob = quant_prob_alloc(mode);
+   if (mode->prob==NULL)
      goto failure;
 
    mode->marker_start = MODEVALID;
@@ -424,7 +419,7 @@
 
 void celt_mode_destroy(CELTMode *mode)
 {
-   int i;
+   int i, m;
    const celt_int16 *prevPtr = NULL;
    if (mode == NULL)
    {
@@ -445,18 +440,24 @@
    }
    mode->marker_start = MODEFREED;
 #ifndef STATIC_MODES
-   if (mode->bits!=NULL)
+   for (m=0;(1<<m)<=mode->nbShortMdcts;m++)
    {
-      for (i=0;i<mode->nbEBands;i++)
+      /* FIXME: Do something for i==0 */
+      if (m==0)
+         continue;
+      if (mode->bits[m]!=NULL)
       {
-         if (mode->bits[i] != prevPtr)
+         for (i=0;i<mode->nbEBands;i++)
          {
-            prevPtr = mode->bits[i];
-            celt_free((int*)mode->bits[i]);
-          }
+            if (mode->bits[m][i] != prevPtr)
+            {
+               prevPtr = mode->bits[m][i];
+               celt_free((int*)mode->bits[m][i]);
+            }
+         }
       }
-   }   
-   celt_free((celt_int16**)mode->bits);
+      celt_free((celt_int16**)mode->bits[m]);
+   }
    celt_free((celt_int16*)mode->eBands);
    celt_free((celt_int16*)mode->allocVectors);
    
@@ -464,8 +465,9 @@
    celt_free((celt_int16*)mode->logN);
 
 #endif
-   clt_mdct_clear(&mode->mdct);
-   clt_mdct_clear(&mode->shortMdct);
+   for (i=0;(1<<i)<=mode->nbShortMdcts;i++)
+      clt_mdct_clear(&mode->mdct[i]);
+
    quant_prob_free(mode->prob);
    mode->marker_end = MODEFREED;
    celt_free((CELTMode *)mode);
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -40,6 +40,8 @@
 #include "mdct.h"
 #include "pitch.h"
 
+#define MAX_CONFIG_SIZES 4
+
 #define CELT_BITSTREAM_VERSION 0x8000000c
 
 #ifdef STATIC_MODES
@@ -64,8 +66,6 @@
 # endif
 #endif
 
-#define MDCT(mode) (&(mode)->mdct)
-
 #ifndef OVERLAP
 #define OVERLAP(mode) ((mode)->overlap)
 #endif
@@ -93,21 +93,28 @@
    int          nbAllocVectors; /**< Number of lines in the matrix below */
    const celt_int16   *allocVectors;   /**< Number of bits in each band for several rates */
    
-   const celt_int16 * const *bits; /**< Cache for pulses->bits mapping in each band */
+   const celt_int16 * const *(bits[MAX_CONFIG_SIZES]); /**< Cache for pulses->bits mapping in each band */
 
    /* Stuff that could go in the {en,de}coder, but we save space this way */
-   mdct_lookup mdct;
+   mdct_lookup mdct[MAX_CONFIG_SIZES];
 
    const celt_word16 *window;
 
    int         nbShortMdcts;
    int         shortMdctSize;
-   mdct_lookup shortMdct;
 
    int *prob;
    const celt_int16 *logN;
    celt_uint32 marker_end;
 };
+
+static inline int FULL_FRAME(const CELTMode *m)
+{
+   int i=0;
+   while (1<<i < m->nbShortMdcts)
+      i++;
+   return i;
+}
 
 int check_mode(const CELTMode *mode);