1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
diff --git a/lib/rbcodec/codecs/libopus/celt/celt.c b/lib/rbcodec/codecs/libopus/celt/celt.c
index 74ebee9..b19cdec 100644
--- a/lib/rbcodec/codecs/libopus/celt/celt.c
+++ b/lib/rbcodec/codecs/libopus/celt/celt.c
@@ -448,12 +448,16 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X
          clt_mdct_backward(&mode->mdct, &X[b+c*N2*B], x+N2*b, mode->window, overlap, shortBlocks ? mode->maxLM : mode->maxLM-LM, B);
       }
 
-      for (j=0;j<overlap;j++)
-         out_mem[c][j] = x[j] + overlap_mem[c][j];
-      for (;j<N;j++)
-         out_mem[c][j] = x[j];
-      for (j=0;j<overlap;j++)
-         overlap_mem[c][j] = x[N+j];
+       /* overlap can be divided by 4 */
+      for (j=0;j<overlap;j+=4)
+    {
+    out_mem[c][j  ] = x[j  ] + overlap_mem[c][j  ];
+    out_mem[c][j+1] = x[j+1] + overlap_mem[c][j+1];
+    out_mem[c][j+2] = x[j+2] + overlap_mem[c][j+2];
+    out_mem[c][j+3] = x[j+3] + overlap_mem[c][j+3];
+    }
+    OPUS_COPY(out_mem[c]+overlap, x+overlap, N-overlap);
+    OPUS_COPY(overlap_mem[c]    , x+N      ,   overlap);
    } while (++c<C);
    RESTORE_STACK;
 }
@@ -466,16 +470,21 @@ static void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, /* int dow
       int j;
       celt_sig * OPUS_RESTRICT x;
       opus_val16  * OPUS_RESTRICT y;
+      opus_val16 coef0 = coef[0];
+#ifdef CUSTOM_MODES
+      opus_val16 coef1 = coef[1];
+      opus_val16 coef3 = coef[3];
+#endif
       celt_sig m = mem[c];
       x =in[c];
       y = pcm+c;
       for (j=0;j<N;j++)
       {
          celt_sig tmp = *x + m;
-         m = MULT16_32_Q15(coef[0], tmp);
+         m = MULT16_32_Q15(coef0, tmp);
 #ifdef CUSTOM_MODES
-         m -= MULT16_32_Q15(coef[1], *x);
-         tmp = SHL32(MULT16_32_Q15(coef[3], tmp), 2);
+         m -= MULT16_32_Q15(coef1, *x);
+         tmp = SHL32(MULT16_32_Q15(coef3, tmp), 2);
 #endif
          x++;
          /* Technically the store could be moved outside of the if because
@@ -497,43 +506,69 @@ static void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
       opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
       const opus_val16 *window, int overlap)
 {
-   int i;
-   /* printf ("%d %d %f %f\n", T0, T1, g0, g1); */
-   opus_val16 g00, g01, g02, g10, g11, g12;
-   static const opus_val16 gains[3][3] = {
-         {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1296386719f, 15)},
-         {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f, 15)},
-         {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f, 15)}};
-   g00 = MULT16_16_Q15(g0, gains[tapset0][0]);
-   g01 = MULT16_16_Q15(g0, gains[tapset0][1]);
-   g02 = MULT16_16_Q15(g0, gains[tapset0][2]);
-   g10 = MULT16_16_Q15(g1, gains[tapset1][0]);
-   g11 = MULT16_16_Q15(g1, gains[tapset1][1]);
-   g12 = MULT16_16_Q15(g1, gains[tapset1][2]);
-   for (i=0;i<overlap;i++)
-   {
-      opus_val16 f;
-      f = MULT16_16_Q15(window[i],window[i]);
-      y[i] = x[i]
-               + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g00),x[i-T0])
-               + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g01),x[i-T0-1])
-               + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g01),x[i-T0+1])
-               + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g02),x[i-T0-2])
-               + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g02),x[i-T0+2])
-               + MULT16_32_Q15(MULT16_16_Q15(f,g10),x[i-T1])
-               + MULT16_32_Q15(MULT16_16_Q15(f,g11),x[i-T1-1])
-               + MULT16_32_Q15(MULT16_16_Q15(f,g11),x[i-T1+1])
-               + MULT16_32_Q15(MULT16_16_Q15(f,g12),x[i-T1-2])
-               + MULT16_32_Q15(MULT16_16_Q15(f,g12),x[i-T1+2]);
-
-   }
-   for (i=overlap;i<N;i++)
-      y[i] = x[i]
-               + MULT16_32_Q15(g10,x[i-T1])
-               + MULT16_32_Q15(g11,x[i-T1-1])
-               + MULT16_32_Q15(g11,x[i-T1+1])
-               + MULT16_32_Q15(g12,x[i-T1-2])
-               + MULT16_32_Q15(g12,x[i-T1+2]);
+    /* Multiply-adds are only needed if g0 or g1 are non-zero. In all other cases a simple
+     * copy of vector x to y is possible. */
+    if (g0!=0 || g1!=0)
+    {
+     int i;
+     opus_val16 g00, g01, g02, g10, g11, g12, idx0, idx1;
+     static const opus_val16 gains[3][3] = {
+       {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1296386719f, 15)},
+       {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f, 15)},
+       {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f, 15)}};
+     g00 = MULT16_16_Q15(g0, gains[tapset0][0]);
+     g01 = MULT16_16_Q15(g0, gains[tapset0][1]);
+     g02 = MULT16_16_Q15(g0, gains[tapset0][2]);
+     g10 = MULT16_16_Q15(g1, gains[tapset1][0]);
+     g11 = MULT16_16_Q15(g1, gains[tapset1][1]);
+     g12 = MULT16_16_Q15(g1, gains[tapset1][2]);
+     /* printf("g0 %d g1 %d\n", g0,g1); */
+     idx0 = -T0;
+     idx1 = -T1;
+     for (i=0;i<overlap;i++,idx0++,idx1++)
+     {
+      opus_val16 f0, f1;
+      f1 = MULT16_16_Q15(window[i],window[i]);
+      f0 = Q15ONE - f1;
+      y[i] = x[i]
+             + MULT16_32_Q15(MULT16_16_Q15(f0,g02), x[idx0-2])
+               + MULT16_32_Q15(MULT16_16_Q15(f0,g01), x[idx0-1])
+           + MULT16_32_Q15(MULT16_16_Q15(f0,g00), x[idx0  ])
+           + MULT16_32_Q15(MULT16_16_Q15(f0,g01), x[idx0+1])
+           + MULT16_32_Q15(MULT16_16_Q15(f0,g02), x[idx0+2])
+           + MULT16_32_Q15(MULT16_16_Q15(f1,g12), x[idx1-2])
+           + MULT16_32_Q15(MULT16_16_Q15(f1,g11), x[idx1-1])
+           + MULT16_32_Q15(MULT16_16_Q15(f1,g10), x[idx1  ])
+           + MULT16_32_Q15(MULT16_16_Q15(f1,g11), x[idx1+1])
+           + MULT16_32_Q15(MULT16_16_Q15(f1,g12), x[idx1+2]);
+     }
+     /* No multiply-add required if g1=0 as all multiplicants are =0. */
+     if (g1!=0)
+     {
+       idx1 = overlap-T1;
+       for (i=overlap;i<N;i++,idx1++)
+       {
+        y[i] = x[i]
+             + MULT16_32_Q15(g12, x[idx1-2])
+             + MULT16_32_Q15(g11, x[idx1-1])
+             + MULT16_32_Q15(g10, x[idx1  ])
+             + MULT16_32_Q15(g11, x[idx1+1])
+             + MULT16_32_Q15(g12, x[idx1+2]);
+       }
+     }
+     /* Only perform vector copy if source and destination are not same. */
+     else if (x != y)
+     {
+      /* Copy part of vector from x[overlap..N] to y[overlap..N] */
+      OPUS_COPY(y+overlap, x+overlap, N-overlap);
+     }
+    }
+    /* Only perform vector copy if source and destination are not same. */
+    else if (x != y)
+    {
+    /* Copy full vector from x[0..N] to y[0..N] */
+    OPUS_COPY(y, x, N);
+    }
 }
 
 static const signed char tf_select_table[4][8] = {
diff --git a/lib/rbcodec/codecs/libopus/celt/fixed_generic.h b/lib/rbcodec/codecs/libopus/celt/fixed_generic.h
index 5682a67..0de6760 100644
--- a/lib/rbcodec/codecs/libopus/celt/fixed_generic.h
+++ b/lib/rbcodec/codecs/libopus/celt/fixed_generic.h
@@ -71,8 +71,21 @@ static inline int32_t MULT16_32_Q15(int32_t a, int32_t b)
 #define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),((b)&0x0000ffff)),15))
 #endif
 
+#if defined(CPU_ARM)
+static inline int32_t MULT32_32_Q31(int32_t a, int32_t b)
+{
+  int32_t lo, hi;
+  asm volatile("smull %[lo], %[hi], %[a], %[b] \n\t"
+               "mov %[lo], %[lo], lsr #31 \n\t"
+               "orr %[hi], %[lo], %[hi], lsl #1 \n\t"
+               : [lo] "=&r" (lo), [hi] "=&r" (hi)
+               : [a] "r" (a), [b] "r" (b) );
+  return(hi);
+}
+#else
 /** 32x32 multiplication, followed by a 31-bit shift right. Results fits in 32 bits */
-#define MULT32_32_Q31(a,b) ADD32(ADD32(SHL(MULT16_16(SHR((a),16),SHR((b),16)),1), SHR(MULT16_16SU(SHR((a),16),((b)&0x0000ffff)),15)), SHR(MULT16_16SU(SHR((b),16),((a)&0x0000ffff)),15))
+#define MULT32_32_Q31(a,b) (opus_val32)((((int64_t)(a)) * ((int64_t)(b)))>>31)
+#endif
 
 /** Compile-time conversion of float constant to 16-bit value */
 #define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits))))
diff --git a/lib/rbcodec/codecs/libopus/celt/kiss_fft.c b/lib/rbcodec/codecs/libopus/celt/kiss_fft.c
index 01049d5..890ef6d 100644
--- a/lib/rbcodec/codecs/libopus/celt/kiss_fft.c
+++ b/lib/rbcodec/codecs/libopus/celt/kiss_fft.c
@@ -47,7 +47,7 @@
 */
 
 #if 0
-static void kf_bfly2(
+void kf_bfly2(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -81,7 +81,7 @@ static void kf_bfly2(
 }
 #endif
 
-static void ki_bfly2(
+void ki_bfly2(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -113,7 +113,7 @@ static void ki_bfly2(
 }
 
 #if 0
-static void kf_bfly4(
+void kf_bfly4(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -163,7 +163,7 @@ static void kf_bfly4(
 }
 #endif
 
-static void ki_bfly4(
+void ki_bfly4(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -211,7 +211,7 @@ static void ki_bfly4(
 #ifndef RADIX_TWO_ONLY
 
 #if 0
-static void kf_bfly3(
+void kf_bfly3(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -264,7 +264,7 @@ static void kf_bfly3(
 }
 #endif
 
-static void ki_bfly3(
+void ki_bfly3(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -315,7 +315,7 @@ static void ki_bfly3(
 }
 
 #if 0
-static void kf_bfly5(
+void kf_bfly5(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -385,7 +385,7 @@ static void kf_bfly5(
 }
 #endif
 
-static void ki_bfly5(
+void ki_bfly5(
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
@@ -398,13 +398,12 @@ static void ki_bfly5(
    int i, u;
    kiss_fft_cpx scratch[13];
    const kiss_twiddle_cpx * twiddles = st->twiddles;
-   const kiss_twiddle_cpx *tw;
+   const kiss_twiddle_cpx *tw1,*tw2, *tw3, *tw4;
    kiss_twiddle_cpx ya,yb;
    kiss_fft_cpx * Fout_beg = Fout;
 
    ya = twiddles[fstride*m];
    yb = twiddles[fstride*2*m];
-   tw=st->twiddles;
 
    for (i=0;i<N;i++)
    {
@@ -415,13 +414,15 @@ static void ki_bfly5(
       Fout3=Fout0+3*m;
       Fout4=Fout0+4*m;
 
-      for ( u=0; u<m; ++u ) {
+    tw1 = tw2 = tw3 = tw4 = st->twiddles;
+    
+      for ( u=0; u<m; ++u) {
          scratch[0] = *Fout0;
 
-         C_MULC(scratch[1] ,*Fout1, tw[u*fstride]);
-         C_MULC(scratch[2] ,*Fout2, tw[2*u*fstride]);
-         C_MULC(scratch[3] ,*Fout3, tw[3*u*fstride]);
-         C_MULC(scratch[4] ,*Fout4, tw[4*u*fstride]);
+     C_MULC(scratch[1] ,*Fout1, *tw1);
+     C_MULC(scratch[2] ,*Fout2, *tw2);
+     C_MULC(scratch[3] ,*Fout3, *tw3);
+     C_MULC(scratch[4] ,*Fout4, *tw4);
 
          C_ADD( scratch[7],scratch[1],scratch[4]);
          C_SUB( scratch[10],scratch[1],scratch[4]);
@@ -449,6 +450,10 @@ static void ki_bfly5(
          C_SUB(*Fout3,scratch[11],scratch[12]);
 
          ++Fout0;++Fout1;++Fout2;++Fout3;++Fout4;
+     tw1 +=   fstride;
+     tw2 += 2*fstride;
+     tw3 += 3*fstride;
+     tw4 += 4*fstride;
       }
    }
 }
diff --git a/lib/rbcodec/codecs/libopus/celt/mdct.c b/lib/rbcodec/codecs/libopus/celt/mdct.c
index 8fc1b54..42ff1c8 100644
--- a/lib/rbcodec/codecs/libopus/celt/mdct.c
+++ b/lib/rbcodec/codecs/libopus/celt/mdct.c
@@ -208,43 +208,17 @@ void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar
 }
 #endif
 
-#define S_F_BUF_SIZE (1920>>1) /* N = 1920 for static modes */
-static kiss_fft_scalar s_f2[S_F_BUF_SIZE] IBSS_ATTR MEM_ALIGN_ATTR;
-void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * OPUS_RESTRICT out,
-      const opus_val16 * OPUS_RESTRICT window, int overlap, int shift, int stride)
+void pre_rot(const mdct_lookup *l, kiss_fft_scalar *in, int stride, int N, int N2, int N4, kiss_fft_scalar *f2, int shift)
 {
-   int i;
-   int N, N2, N4;
-   kiss_twiddle_scalar sine;
-   VARDECL(kiss_fft_scalar, f);
-   VARDECL(kiss_fft_scalar, f2);
-   SAVE_STACK;
-   N = l->n;
-   N >>= shift;
-   N2 = N>>1;
-   N4 = N>>2;
-   kiss_fft_scalar s_f[S_F_BUF_SIZE];
-
-   if (S_F_BUF_SIZE >= N2)
-   {
-      f  = s_f;
-      f2 = s_f2;
-   }
-   else
-   {
-      ALLOC(f , N2, kiss_fft_scalar);
-      ALLOC(f2, N2, kiss_fft_scalar);
-   }
-
+    int i;
+  kiss_twiddle_scalar sine;
    /* sin(x) ~= x here */
 #ifdef FIXED_POINT
    sine = TRIG_UPSCALE*(QCONST16(0.7853981f, 15)+N2)/N;
 #else
    sine = (kiss_twiddle_scalar)2*PI*(.125f)/N;
 #endif
-
-   /* Pre-rotate */
-   {
+  {
       /* Temp pointers to make it really clear to the compiler what we're doing */
       const kiss_fft_scalar * OPUS_RESTRICT xp1 = in;
       const kiss_fft_scalar * OPUS_RESTRICT xp2 = in+stride*(N2-1);
@@ -253,8 +227,11 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
       for(i=0;i<N4;i++)
       {
          kiss_fft_scalar yr, yi;
-         yr = -S_MUL(*xp2, t[i<<shift]) + S_MUL(*xp1,t[(N4-i)<<shift]);
-         yi =  -S_MUL(*xp2, t[(N4-i)<<shift]) - S_MUL(*xp1,t[i<<shift]);
+     kiss_twiddle_scalar t0, t1;
+         t0 = t[i<<shift];
+         t1 = t[(N4-i)<<shift];
+         yr = -S_MUL(*xp2, t0) + S_MUL(*xp1,t1);
+         yi = -S_MUL(*xp2, t1) - S_MUL(*xp1,t0);
          /* works because the cos is nearly one */
          *yp++ = yr - S_MUL(yi,sine);
          *yp++ = yi + S_MUL(yr,sine);
@@ -262,30 +239,44 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
          xp2-=2*stride;
       }
    }
+}
 
-   /* Inverse N/4 complex FFT. This one should *not* downscale even in fixed-point */
-   opus_ifft(l->kfft[shift], (kiss_fft_cpx *)f2, (kiss_fft_cpx *)f);
-
-   /* Post-rotate */
-   {
+void post_rot(const mdct_lookup *l, kiss_fft_scalar *in, int stride, int N, int N2, int N4, kiss_fft_scalar *f, int shift)
+{
+  int i;
+  kiss_twiddle_scalar sine;
+   /* sin(x) ~= x here */
+#ifdef FIXED_POINT
+   sine = TRIG_UPSCALE*(QCONST16(0.7853981f, 15)+N2)/N;
+#else
+   sine = (kiss_twiddle_scalar)2*PI*(.125f)/N;
+#endif
+  {
       kiss_fft_scalar * OPUS_RESTRICT fp = f;
       const kiss_twiddle_scalar *t = &l->trig[0];
 
       for(i=0;i<N4;i++)
       {
          kiss_fft_scalar re, im, yr, yi;
+     kiss_twiddle_scalar t0, t1;
+         t0 = t[i<<shift];
+         t1 = t[(N4-i)<<shift];
          re = fp[0];
          im = fp[1];
          /* We'd scale up by 2 here, but instead it's done when mixing the windows */
-         yr = S_MUL(re,t[i<<shift]) - S_MUL(im,t[(N4-i)<<shift]);
-         yi = S_MUL(im,t[i<<shift]) + S_MUL(re,t[(N4-i)<<shift]);
+         yr = S_MUL(re,t0) - S_MUL(im,t1);
+         yi = S_MUL(im,t0) + S_MUL(re,t1);
          /* works because the cos is nearly one */
          *fp++ = yr - S_MUL(yi,sine);
          *fp++ = yi + S_MUL(yr,sine);
       }
    }
-   /* De-shuffle the components for the middle of the window only */
-   {
+}
+
+void deshuffle(int N2, int N4, kiss_fft_scalar *f, kiss_fft_scalar *f2)
+{
+  int i;
+  {
       const kiss_fft_scalar * OPUS_RESTRICT fp1 = f;
       const kiss_fft_scalar * OPUS_RESTRICT fp2 = f+N2-1;
       kiss_fft_scalar * OPUS_RESTRICT yp = f2;
@@ -297,20 +288,22 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
          fp2 -= 2;
       }
    }
-   out -= (N2-overlap)>>1;
-   /* Mirror on both sides for TDAC */
-   {
+}
+
+void mirror_1(int overlap, int N2, int N4, kiss_fft_scalar *f2, kiss_fft_scalar *out, const opus_val16 *window)
+{
+  int i;
+  {
       kiss_fft_scalar * OPUS_RESTRICT fp1 = f2+N4-1;
       kiss_fft_scalar * OPUS_RESTRICT xp1 = out+N2-1;
       kiss_fft_scalar * OPUS_RESTRICT yp1 = out+N4-overlap/2;
       const opus_val16 * OPUS_RESTRICT wp1 = window;
       const opus_val16 * OPUS_RESTRICT wp2 = window+overlap-1;
-      for(i = 0; i< N4-overlap/2; i++)
-      {
-         *xp1 = *fp1;
-         xp1--;
-         fp1--;
-      }
+
+    i = N4-overlap/2;
+    xp1 -= N4-overlap/2;
+    fp1 -= N4-overlap/2;
+    OPUS_COPY(xp1+1, fp1+1, N4-overlap/2);
       for(; i < N4; i++)
       {
          kiss_fft_scalar x1;
@@ -321,18 +314,22 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
          wp2--;
       }
    }
-   {
+}
+
+void mirror_2(int overlap, int N, int N2, int N4, kiss_fft_scalar *f2, kiss_fft_scalar *out, const opus_val16 *window)
+{
+  int i;
+  {
       kiss_fft_scalar * OPUS_RESTRICT fp2 = f2+N4;
       kiss_fft_scalar * OPUS_RESTRICT xp2 = out+N2;
       kiss_fft_scalar * OPUS_RESTRICT yp2 = out+N-1-(N4-overlap/2);
       const opus_val16 * OPUS_RESTRICT wp1 = window;
       const opus_val16 * OPUS_RESTRICT wp2 = window+overlap-1;
-      for(i = 0; i< N4-overlap/2; i++)
-      {
-         *xp2 = *fp2;
-         xp2++;
-         fp2++;
-      }
+
+    i = N4-overlap/2;
+    OPUS_COPY(xp2, fp2, N4-overlap/2);
+    xp2 += N4-overlap/2;
+    fp2 += N4-overlap/2;
       for(; i < N4; i++)
       {
          kiss_fft_scalar x2;
@@ -343,5 +340,55 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
          wp2--;
       }
    }
+}
+
+#define S_F_BUF_SIZE (1920>>1) /* N = 1920 for static modes */
+static kiss_fft_scalar s_f2[S_F_BUF_SIZE] IBSS_ATTR MEM_ALIGN_ATTR;
+void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * OPUS_RESTRICT out,
+      const opus_val16 * OPUS_RESTRICT window, int overlap, int shift, int stride)
+{
+   int i;
+   int N, N2, N4;
+   VARDECL(kiss_fft_scalar, f);
+   VARDECL(kiss_fft_scalar, f2);
+   SAVE_STACK;
+   N = l->n;
+   N >>= shift;
+   N2 = N>>1;
+   N4 = N>>2;
+   kiss_fft_scalar s_f[S_F_BUF_SIZE];
+
+   if (S_F_BUF_SIZE >= N2)
+   {
+      f  = s_f;
+      f2 = s_f2;
+   }
+   else
+   {
+      ALLOC(f , N2, kiss_fft_scalar);
+      ALLOC(f2, N2, kiss_fft_scalar);
+   }
+
+   /* Pre-rotate */
+   //pre_rot(const mdct_lookup *l, kiss_fft_scalar *in, int stride, int N, int N2, int N4, kiss_fft_scalar *f2, int shift)
+   pre_rot(l, in, stride, N, N2, N4, f2, shift);
+
+   /* Inverse N/4 complex FFT. This one should *not* downscale even in fixed-point */
+   opus_ifft(l->kfft[shift], (kiss_fft_cpx *)f2, (kiss_fft_cpx *)f);
+
+   /* Post-rotate */
+   //post_rot(const mdct_lookup *l, kiss_fft_scalar *in, int stride, int N, int N2, int N4, kiss_fft_scalar *f, int shift)
+   post_rot(l, in, stride, N, N2, N4, f, shift);
+   
+   /* De-shuffle the components for the middle of the window only */
+   //deshuffle(int N2, int N4, kiss_fft_scalar *f, kiss_fft_scalar *f2)
+   deshuffle(N2, N4, f, f2);
+   out -= (N2-overlap)>>1;
+   /* Mirror on both sides for TDAC */
+   //mirror_1(int overlap, int N2, int N4, kiss_fft_scalar *f2, kiss_fft_scalar *out, const opus_val16 *window)
+   mirror_1(overlap, N2, N4, f2, out, window);
+   //mirror_2(int overlap, int N, int N2, int N4, kiss_fft_scalar *f2, kiss_fft_scalar *out, const opus_val16 *window)
+   mirror_2(overlap, N, N2, N4, f2, out, window);
+   
    RESTORE_STACK;
 }