Take the PLC out of the stack size critical path
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 23 Oct 2012 20:14:49 +0000 (16:14 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 23 Oct 2012 20:15:23 +0000 (16:15 -0400)
celt/celt.c

index 4ddba9e..06cc4cc 100644 (file)
@@ -2448,6 +2448,8 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
       compute_inv_mdcts(st->mode, 0, freq, out_syn, overlap_mem, C, LM);
    } else {
       /* Pitch-based PLC */
+      VARDECL(opus_val32, e);
+
       if (st->loss_count == 0)
       {
          opus_val16 pitch_buf[DECODE_BUFFER_SIZE>>1];
@@ -2465,16 +2467,14 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
          fade = QCONST16(.8f,15);
       }
 
+      ALLOC(e, MAX_PERIOD+2*st->mode->overlap, opus_val32);
       c=0; do {
-         VARDECL(opus_val32, e);
          opus_val16 exc[MAX_PERIOD];
          opus_val32 ac[LPC_ORDER+1];
          opus_val16 decay = 1;
          opus_val32 S1=0;
          opus_val16 mem[LPC_ORDER]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 
-         ALLOC(e, MAX_PERIOD+2*st->mode->overlap, opus_val32);
-
          offset = MAX_PERIOD-pitch_index;
          for (i=0;i<MAX_PERIOD;i++)
             exc[i] = ROUND16(out_mem[c][i], SIG_SHIFT);
@@ -2708,6 +2708,13 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
    if (effEnd > st->mode->effEBands)
       effEnd = st->mode->effEBands;
 
+   if (data == NULL || len<=1)
+   {
+      celt_decode_lost(st, pcm, N, LM);
+      RESTORE_STACK;
+      return frame_size/st->downsample;
+   }
+
    ALLOC(freq, IMAX(CC,C)*N, celt_sig); /**< Interleaved signal MDCTs */
    ALLOC(X, C*N, celt_norm);   /**< Interleaved normalised MDCTs */
    ALLOC(bandE, st->mode->nbEBands*C, celt_ener);
@@ -2720,13 +2727,6 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
          X[c*N+i] = 0;
    while (++c<C);
 
-   if (data == NULL || len<=1)
-   {
-      celt_decode_lost(st, pcm, N, LM);
-      RESTORE_STACK;
-      return frame_size/st->downsample;
-   }
-
    if (dec == NULL)
    {
       ec_dec_init(&_dec,(unsigned char*)data,len);