• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <ixheaacd_type_def.h>
24 #include "ixheaacd_constants.h"
25 #include <ixheaacd_basic_ops32.h>
26 
27 #define PLATFORM_INLINE __inline
28 
29 #define DIG_REV(i, m, j)                                    \
30   do {                                                      \
31     unsigned _ = (i);                                       \
32     _ = ((_ & 0x33333333) << 2) | ((_ & ~0x33333333) >> 2); \
33     _ = ((_ & 0x0F0F0F0F) << 4) | ((_ & ~0x0F0F0F0F) >> 4); \
34     _ = ((_ & 0x00FF00FF) << 8) | ((_ & ~0x00FF00FF) >> 8); \
35     (j) = _ >> (m);                                         \
36   } while (0)
37 
38 extern FLOAT32 ixheaacd_twiddle_table_fft_float[514];
39 const FLOAT32 ixheaacd_twidle_tbl_48[64];
40 const FLOAT32 ixheaacd_twidle_tbl_24[32];
41 
ixheaacd_real_synth_fft_p2(FLOAT32 * ptr_x,FLOAT32 * ptr_y,WORD32 npoints)42 void ixheaacd_real_synth_fft_p2(FLOAT32 *ptr_x, FLOAT32 *ptr_y,
43                                 WORD32 npoints) {
44   WORD32 i, j, k, n_stages, h2;
45   FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
46   WORD32 del, nodespacing, in_loop_cnt;
47   WORD32 not_power_4;
48   WORD32 dig_rev_shift;
49   const FLOAT32 *ptr_w;
50 
51   dig_rev_shift = ixheaacd_norm32(npoints) + 1 - 16;
52   n_stages = 30 - ixheaacd_norm32(npoints);
53   not_power_4 = n_stages & 1;
54 
55   n_stages = n_stages >> 1;
56 
57   ptr_w = ixheaacd_twiddle_table_fft_float;
58 
59   for (i = 0; i < npoints; i += 4) {
60     FLOAT32 *inp = ptr_x;
61 
62     DIG_REV(i, dig_rev_shift, h2);
63     if (not_power_4) {
64       h2 += 1;
65       h2 &= ~1;
66     }
67     inp += (h2 >> 1);
68 
69     x0r = *inp;
70     inp += (npoints >> 2);
71 
72     x1r = *inp;
73     inp += (npoints >> 2);
74 
75     x2r = *inp;
76     inp += (npoints >> 2);
77 
78     x3r = *inp;
79 
80     x0r = x0r + x2r;
81     x2r = x0r - (x2r * 2);
82     x1r = x1r + x3r;
83     x3r = x1r - (x3r * 2);
84     x0r = x0r + x1r;
85     x1r = x0r - (x1r * 2);
86 
87     *ptr_y++ = x0r;
88     *ptr_y++ = 0;
89     *ptr_y++ = x2r;
90     *ptr_y++ = x3r;
91     *ptr_y++ = x1r;
92     *ptr_y++ = 0;
93     *ptr_y++ = x2r;
94     *ptr_y++ = -x3r;
95   }
96   ptr_y -= 2 * npoints;
97   del = 4;
98   nodespacing = 64;
99   in_loop_cnt = npoints >> 4;
100   for (i = n_stages - 1; i > 0; i--) {
101     const FLOAT32 *twiddles = ptr_w;
102     FLOAT32 *data = ptr_y;
103     FLOAT32 W1, W2, W3, W4, W5, W6;
104     WORD32 sec_loop_cnt;
105 
106     for (k = in_loop_cnt; k != 0; k--) {
107       x0r = (*data);
108       x0i = (*(data + 1));
109       data += (del << 1);
110 
111       x1r = (*data);
112       x1i = (*(data + 1));
113       data += (del << 1);
114 
115       x2r = (*data);
116       x2i = (*(data + 1));
117       data += (del << 1);
118 
119       x3r = (*data);
120       x3i = (*(data + 1));
121       data -= 3 * (del << 1);
122 
123       x0r = x0r + x2r;
124       x0i = x0i + x2i;
125       x2r = x0r - (x2r * 2);
126       x2i = x0i - (x2i * 2);
127       x1r = x1r + x3r;
128       x1i = x1i + x3i;
129       x3r = x1r - (x3r * 2);
130       x3i = x1i - (x3i * 2);
131 
132       x0r = x0r + x1r;
133       x0i = x0i + x1i;
134       x1r = x0r - (x1r * 2);
135       x1i = x0i - (x1i * 2);
136       x2r = x2r - x3i;
137       x2i = x2i + x3r;
138       x3i = x2r + (x3i * 2);
139       x3r = x2i - (x3r * 2);
140 
141       *data = x0r;
142       *(data + 1) = x0i;
143       data += (del << 1);
144 
145       *data = x2r;
146       *(data + 1) = x2i;
147       data += (del << 1);
148 
149       *data = x1r;
150       *(data + 1) = x1i;
151       data += (del << 1);
152 
153       *data = x3i;
154       *(data + 1) = x3r;
155       data += (del << 1);
156     }
157     data = ptr_y + 2;
158 
159     sec_loop_cnt = (nodespacing * del);
160     sec_loop_cnt = (sec_loop_cnt / 4) + (sec_loop_cnt / 8) -
161                    (sec_loop_cnt / 16) + (sec_loop_cnt / 32) -
162                    (sec_loop_cnt / 64) + (sec_loop_cnt / 128) -
163                    (sec_loop_cnt / 256);
164     j = nodespacing;
165 
166     for (j = nodespacing; j <= sec_loop_cnt; j += nodespacing) {
167       W1 = *(twiddles + j);
168       W4 = *(twiddles + j + 257);
169       W2 = *(twiddles + (j << 1));
170       W5 = *(twiddles + (j << 1) + 257);
171       W3 = *(twiddles + j + (j << 1));
172       W6 = *(twiddles + j + (j << 1) + 257);
173 
174       for (k = in_loop_cnt; k != 0; k--) {
175         FLOAT32 tmp;
176         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
177 
178         data += (del << 1);
179 
180         x1r = *data;
181         x1i = *(data + 1);
182         data += (del << 1);
183 
184         x2r = *data;
185         x2i = *(data + 1);
186         data += (del << 1);
187 
188         x3r = *data;
189         x3i = *(data + 1);
190         data -= 3 * (del << 1);
191 
192         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
193         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
194         x1r = tmp;
195 
196         tmp = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
197         x2i = (FLOAT32)(-((FLOAT32)x2r * W5) + (FLOAT32)x2i * W2);
198         x2r = tmp;
199 
200         tmp = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
201         x3i = (FLOAT32)(-((FLOAT32)x3r * W6) + (FLOAT32)x3i * W3);
202         x3r = tmp;
203 
204         x0r = (*data);
205         x0i = (*(data + 1));
206 
207         x0r = x0r + (x2r);
208         x0i = x0i + (x2i);
209         x2r = x0r - (x2r * 2);
210         x2i = x0i - (x2i * 2);
211         x1r = x1r + x3r;
212         x1i = x1i + x3i;
213         x3r = x1r - (x3r * 2);
214         x3i = x1i - (x3i * 2);
215 
216         x0r = x0r + (x1r);
217         x0i = x0i + (x1i);
218         x1r = x0r - (x1r * 2);
219         x1i = x0i - (x1i * 2);
220         x2r = x2r - (x3i);
221         x2i = x2i + (x3r);
222         x3i = x2r + (x3i * 2);
223         x3r = x2i - (x3r * 2);
224 
225         *data = x0r;
226         *(data + 1) = x0i;
227         data += (del << 1);
228 
229         *data = x2r;
230         *(data + 1) = x2i;
231         data += (del << 1);
232 
233         *data = x1r;
234         *(data + 1) = x1i;
235         data += (del << 1);
236 
237         *data = x3i;
238         *(data + 1) = x3r;
239         data += (del << 1);
240       }
241       data -= 2 * npoints;
242       data += 2;
243     }
244     for (; j <= (nodespacing * del) >> 1; j += nodespacing) {
245       W1 = *(twiddles + j);
246       W4 = *(twiddles + j + 257);
247       W2 = *(twiddles + (j << 1));
248       W5 = *(twiddles + (j << 1) + 257);
249       W3 = *(twiddles + j + (j << 1) - 256);
250       W6 = *(twiddles + j + (j << 1) + 1);
251 
252       for (k = in_loop_cnt; k != 0; k--) {
253         FLOAT32 tmp;
254         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
255 
256         data += (del << 1);
257 
258         x1r = *data;
259         x1i = *(data + 1);
260         data += (del << 1);
261 
262         x2r = *data;
263         x2i = *(data + 1);
264         data += (del << 1);
265 
266         x3r = *data;
267         x3i = *(data + 1);
268         data -= 3 * (del << 1);
269 
270         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
271         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
272         x1r = tmp;
273 
274         tmp = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
275         x2i = (FLOAT32)(-((FLOAT32)x2r * W5) + (FLOAT32)x2i * W2);
276         x2r = tmp;
277 
278         tmp = (FLOAT32)(((FLOAT32)x3r * W6) - ((FLOAT32)x3i * W3));
279         x3i = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
280         x3r = tmp;
281 
282         x0r = (*data);
283         x0i = (*(data + 1));
284 
285         x0r = x0r + (x2r);
286         x0i = x0i + (x2i);
287         x2r = x0r - (x2r * 2);
288         x2i = x0i - (x2i * 2);
289         x1r = x1r + x3r;
290         x1i = x1i + x3i;
291         x3r = x1r - (x3r * 2);
292         x3i = x1i - (x3i * 2);
293 
294         x0r = x0r + (x1r);
295         x0i = x0i + (x1i);
296         x1r = x0r - (x1r * 2);
297         x1i = x0i - (x1i * 2);
298         x2r = x2r - (x3i);
299         x2i = x2i + (x3r);
300         x3i = x2r + (x3i * 2);
301         x3r = x2i - (x3r * 2);
302 
303         *data = x0r;
304         *(data + 1) = x0i;
305         data += (del << 1);
306 
307         *data = x2r;
308         *(data + 1) = x2i;
309         data += (del << 1);
310 
311         *data = x1r;
312         *(data + 1) = x1i;
313         data += (del << 1);
314 
315         *data = x3i;
316         *(data + 1) = x3r;
317         data += (del << 1);
318       }
319       data -= 2 * npoints;
320       data += 2;
321     }
322     for (; j <= sec_loop_cnt * 2; j += nodespacing) {
323       W1 = *(twiddles + j);
324       W4 = *(twiddles + j + 257);
325       W2 = *(twiddles + (j << 1) - 256);
326       W5 = *(twiddles + (j << 1) + 1);
327       W3 = *(twiddles + j + (j << 1) - 256);
328       W6 = *(twiddles + j + (j << 1) + 1);
329 
330       for (k = in_loop_cnt; k != 0; k--) {
331         FLOAT32 tmp;
332         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
333 
334         data += (del << 1);
335 
336         x1r = *data;
337         x1i = *(data + 1);
338         data += (del << 1);
339 
340         x2r = *data;
341         x2i = *(data + 1);
342         data += (del << 1);
343 
344         x3r = *data;
345         x3i = *(data + 1);
346         data -= 3 * (del << 1);
347 
348         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
349         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
350         x1r = tmp;
351 
352         tmp = (FLOAT32)(((FLOAT32)x2r * W5) - ((FLOAT32)x2i * W2));
353         x2i = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
354         x2r = tmp;
355 
356         tmp = (FLOAT32)(((FLOAT32)x3r * W6) - ((FLOAT32)x3i * W3));
357         x3i = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
358         x3r = tmp;
359 
360         x0r = (*data);
361         x0i = (*(data + 1));
362 
363         x0r = x0r + (x2r);
364         x0i = x0i + (x2i);
365         x2r = x0r - (x2r * 2);
366         x2i = x0i - (x2i * 2);
367         x1r = x1r + x3r;
368         x1i = x1i + x3i;
369         x3r = x1r - (x3r * 2);
370         x3i = x1i - (x3i * 2);
371 
372         x0r = x0r + (x1r);
373         x0i = x0i + (x1i);
374         x1r = x0r - (x1r * 2);
375         x1i = x0i - (x1i * 2);
376         x2r = x2r - (x3i);
377         x2i = x2i + (x3r);
378         x3i = x2r + (x3i * 2);
379         x3r = x2i - (x3r * 2);
380 
381         *data = x0r;
382         *(data + 1) = x0i;
383         data += (del << 1);
384 
385         *data = x2r;
386         *(data + 1) = x2i;
387         data += (del << 1);
388 
389         *data = x1r;
390         *(data + 1) = x1i;
391         data += (del << 1);
392 
393         *data = x3i;
394         *(data + 1) = x3r;
395         data += (del << 1);
396       }
397       data -= 2 * npoints;
398       data += 2;
399     }
400     for (; j < nodespacing * del; j += nodespacing) {
401       W1 = *(twiddles + j);
402       W4 = *(twiddles + j + 257);
403       W2 = *(twiddles + (j << 1) - 256);
404       W5 = *(twiddles + (j << 1) + 1);
405       W3 = *(twiddles + j + (j << 1) - 512);
406       W6 = *(twiddles + j + (j << 1) - 512 + 257);
407 
408       for (k = in_loop_cnt; k != 0; k--) {
409         FLOAT32 tmp;
410         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
411 
412         data += (del << 1);
413 
414         x1r = *data;
415         x1i = *(data + 1);
416         data += (del << 1);
417 
418         x2r = *data;
419         x2i = *(data + 1);
420         data += (del << 1);
421 
422         x3r = *data;
423         x3i = *(data + 1);
424         data -= 3 * (del << 1);
425 
426         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
427         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
428         x1r = tmp;
429 
430         tmp = (FLOAT32)(((FLOAT32)x2r * W5) - ((FLOAT32)x2i * W2));
431         x2i = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
432         x2r = tmp;
433 
434         tmp = (FLOAT32)(-((FLOAT32)x3r * W3) - ((FLOAT32)x3i * W6));
435         x3i = (FLOAT32)(-((FLOAT32)x3r * W6) + (FLOAT32)x3i * W3);
436         x3r = tmp;
437 
438         x0r = (*data);
439         x0i = (*(data + 1));
440 
441         x0r = x0r + (x2r);
442         x0i = x0i + (x2i);
443         x2r = x0r - (x2r * 2);
444         x2i = x0i - (x2i * 2);
445         x1r = x1r + x3r;
446         x1i = x1i - x3i;
447         x3r = x1r - (x3r * 2);
448         x3i = x1i + (x3i * 2);
449 
450         x0r = x0r + (x1r);
451         x0i = x0i + (x1i);
452         x1r = x0r - (x1r * 2);
453         x1i = x0i - (x1i * 2);
454         x2r = x2r - (x3i);
455         x2i = x2i + (x3r);
456         x3i = x2r + (x3i * 2);
457         x3r = x2i - (x3r * 2);
458 
459         *data = x0r;
460         *(data + 1) = x0i;
461         data += (del << 1);
462 
463         *data = x2r;
464         *(data + 1) = x2i;
465         data += (del << 1);
466 
467         *data = x1r;
468         *(data + 1) = x1i;
469         data += (del << 1);
470 
471         *data = x3i;
472         *(data + 1) = x3r;
473         data += (del << 1);
474       }
475       data -= 2 * npoints;
476       data += 2;
477     }
478     nodespacing >>= 2;
479     del <<= 2;
480     in_loop_cnt >>= 2;
481   }
482 
483   if (not_power_4) {
484     const FLOAT32 *twiddles = ptr_w;
485     nodespacing <<= 1;
486 
487     for (j = del / 2; j != 0; j--) {
488       FLOAT32 W1 = *twiddles;
489       FLOAT32 W4 = *(twiddles + 257);
490       FLOAT32 tmp;
491       twiddles += nodespacing;
492 
493       x0r = *ptr_y;
494       x0i = *(ptr_y + 1);
495       ptr_y += (del << 1);
496 
497       x1r = *ptr_y;
498       x1i = *(ptr_y + 1);
499 
500       tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
501       x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
502       x1r = tmp;
503 
504       *ptr_y = (x0r) - (x1r);
505       *(ptr_y + 1) = (x0i) - (x1i);
506       ptr_y -= (del << 1);
507 
508       *ptr_y = (x0r) + (x1r);
509       *(ptr_y + 1) = (x0i) + (x1i);
510       ptr_y += 2;
511     }
512     twiddles = ptr_w;
513     for (j = del / 2; j != 0; j--) {
514       FLOAT32 W1 = *twiddles;
515       FLOAT32 W4 = *(twiddles + 257);
516       FLOAT32 tmp;
517       twiddles += nodespacing;
518 
519       x0r = *ptr_y;
520       x0i = *(ptr_y + 1);
521       ptr_y += (del << 1);
522 
523       x1r = *ptr_y;
524       x1i = *(ptr_y + 1);
525 
526       tmp = (FLOAT32)(((FLOAT32)x1r * W4) - ((FLOAT32)x1i * W1));
527       x1i = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
528       x1r = tmp;
529 
530       *ptr_y = (x0r) - (x1r);
531       *(ptr_y + 1) = (x0i) - (x1i);
532       ptr_y -= (del << 1);
533 
534       *ptr_y = (x0r) + (x1r);
535       *(ptr_y + 1) = (x0i) + (x1i);
536       ptr_y += 2;
537     }
538   }
539 }
540 
ixheaacd_cmplx_anal_fft_p2(FLOAT32 * ptr_x,FLOAT32 * ptr_y,WORD32 npoints)541 void ixheaacd_cmplx_anal_fft_p2(FLOAT32 *ptr_x, FLOAT32 *ptr_y,
542                                 WORD32 npoints) {
543   WORD32 i, j, k, n_stages, h2;
544   FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
545   WORD32 del, nodespacing, in_loop_cnt;
546   WORD32 not_power_4;
547   WORD32 dig_rev_shift;
548   const FLOAT32 *ptr_w;
549 
550   dig_rev_shift = ixheaacd_norm32(npoints) + 1 - 16;
551   n_stages = 30 - ixheaacd_norm32(npoints);
552   not_power_4 = n_stages & 1;
553 
554   n_stages = n_stages >> 1;
555 
556   ptr_w = ixheaacd_twiddle_table_fft_float;
557 
558   for (i = 0; i < npoints; i += 4) {
559     FLOAT32 *inp = ptr_x;
560 
561     DIG_REV(i, dig_rev_shift, h2);
562     if (not_power_4) {
563       h2 += 1;
564       h2 &= ~1;
565     }
566     inp += (h2);
567 
568     x0r = *inp;
569     x0i = *(inp + 1);
570     inp += (npoints >> 1);
571 
572     x1r = *inp;
573     x1i = *(inp + 1);
574     inp += (npoints >> 1);
575 
576     x2r = *inp;
577     x2i = *(inp + 1);
578     inp += (npoints >> 1);
579 
580     x3r = *inp;
581     x3i = *(inp + 1);
582 
583     x0r = x0r + x2r;
584     x0i = x0i + x2i;
585     x2r = x0r - (x2r * 2);
586     x2i = x0i - (x2i * 2);
587     x1r = x1r + x3r;
588     x1i = x1i + x3i;
589     x3r = x1r - (x3r * 2);
590     x3i = x1i - (x3i * 2);
591 
592     x0r = x0r + x1r;
593     x0i = x0i + x1i;
594     x1r = x0r - (x1r * 2);
595     x1i = x0i - (x1i * 2);
596     x2r = x2r - x3i;
597     x2i = x2i + x3r;
598     x3i = x2r + (x3i * 2);
599     x3r = x2i - (x3r * 2);
600 
601     *ptr_y++ = x0r;
602     *ptr_y++ = x0i;
603     *ptr_y++ = x2r;
604     *ptr_y++ = x2i;
605     *ptr_y++ = x1r;
606     *ptr_y++ = x1i;
607     *ptr_y++ = x3i;
608     *ptr_y++ = x3r;
609   }
610   ptr_y -= 2 * npoints;
611   del = 4;
612   nodespacing = 64;
613   in_loop_cnt = npoints >> 4;
614   for (i = n_stages - 1; i > 0; i--) {
615     const FLOAT32 *twiddles = ptr_w;
616     FLOAT32 *data = ptr_y;
617     FLOAT32 W1, W2, W3, W4, W5, W6;
618     WORD32 sec_loop_cnt;
619 
620     for (k = in_loop_cnt; k != 0; k--) {
621       x0r = (*data);
622       x0i = (*(data + 1));
623       data += (del << 1);
624 
625       x1r = (*data);
626       x1i = (*(data + 1));
627       data += (del << 1);
628 
629       x2r = (*data);
630       x2i = (*(data + 1));
631       data += (del << 1);
632 
633       x3r = (*data);
634       x3i = (*(data + 1));
635       data -= 3 * (del << 1);
636 
637       x0r = x0r + x2r;
638       x0i = x0i + x2i;
639       x2r = x0r - (x2r * 2);
640       x2i = x0i - (x2i * 2);
641       x1r = x1r + x3r;
642       x1i = x1i + x3i;
643       x3r = x1r - (x3r * 2);
644       x3i = x1i - (x3i * 2);
645 
646       x0r = x0r + x1r;
647       x0i = x0i + x1i;
648       x1r = x0r - (x1r * 2);
649       x1i = x0i - (x1i * 2);
650       x2r = x2r - x3i;
651       x2i = x2i + x3r;
652       x3i = x2r + (x3i * 2);
653       x3r = x2i - (x3r * 2);
654 
655       *data = x0r;
656       *(data + 1) = x0i;
657       data += (del << 1);
658 
659       *data = x2r;
660       *(data + 1) = x2i;
661       data += (del << 1);
662 
663       *data = x1r;
664       *(data + 1) = x1i;
665       data += (del << 1);
666 
667       *data = x3i;
668       *(data + 1) = x3r;
669       data += (del << 1);
670     }
671     data = ptr_y + 2;
672 
673     sec_loop_cnt = (nodespacing * del);
674     sec_loop_cnt = (sec_loop_cnt / 4) + (sec_loop_cnt / 8) -
675                    (sec_loop_cnt / 16) + (sec_loop_cnt / 32) -
676                    (sec_loop_cnt / 64) + (sec_loop_cnt / 128) -
677                    (sec_loop_cnt / 256);
678     j = nodespacing;
679 
680     for (j = nodespacing; j <= sec_loop_cnt; j += nodespacing) {
681       W1 = *(twiddles + j);
682       W4 = *(twiddles + j + 257);
683       W2 = *(twiddles + (j << 1));
684       W5 = *(twiddles + (j << 1) + 257);
685       W3 = *(twiddles + j + (j << 1));
686       W6 = *(twiddles + j + (j << 1) + 257);
687 
688       for (k = in_loop_cnt; k != 0; k--) {
689         FLOAT32 tmp;
690         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
691 
692         data += (del << 1);
693 
694         x1r = *data;
695         x1i = *(data + 1);
696         data += (del << 1);
697 
698         x2r = *data;
699         x2i = *(data + 1);
700         data += (del << 1);
701 
702         x3r = *data;
703         x3i = *(data + 1);
704         data -= 3 * (del << 1);
705 
706         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
707         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
708         x1r = tmp;
709 
710         tmp = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
711         x2i = (FLOAT32)(-((FLOAT32)x2r * W5) + (FLOAT32)x2i * W2);
712         x2r = tmp;
713 
714         tmp = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
715         x3i = (FLOAT32)(-((FLOAT32)x3r * W6) + (FLOAT32)x3i * W3);
716         x3r = tmp;
717 
718         x0r = (*data);
719         x0i = (*(data + 1));
720 
721         x0r = x0r + (x2r);
722         x0i = x0i + (x2i);
723         x2r = x0r - (x2r * 2);
724         x2i = x0i - (x2i * 2);
725         x1r = x1r + x3r;
726         x1i = x1i + x3i;
727         x3r = x1r - (x3r * 2);
728         x3i = x1i - (x3i * 2);
729 
730         x0r = x0r + (x1r);
731         x0i = x0i + (x1i);
732         x1r = x0r - (x1r * 2);
733         x1i = x0i - (x1i * 2);
734         x2r = x2r - (x3i);
735         x2i = x2i + (x3r);
736         x3i = x2r + (x3i * 2);
737         x3r = x2i - (x3r * 2);
738 
739         *data = x0r;
740         *(data + 1) = x0i;
741         data += (del << 1);
742 
743         *data = x2r;
744         *(data + 1) = x2i;
745         data += (del << 1);
746 
747         *data = x1r;
748         *(data + 1) = x1i;
749         data += (del << 1);
750 
751         *data = x3i;
752         *(data + 1) = x3r;
753         data += (del << 1);
754       }
755       data -= 2 * npoints;
756       data += 2;
757     }
758     for (; j <= (nodespacing * del) >> 1; j += nodespacing) {
759       W1 = *(twiddles + j);
760       W4 = *(twiddles + j + 257);
761       W2 = *(twiddles + (j << 1));
762       W5 = *(twiddles + (j << 1) + 257);
763       W3 = *(twiddles + j + (j << 1) - 256);
764       W6 = *(twiddles + j + (j << 1) + 1);
765 
766       for (k = in_loop_cnt; k != 0; k--) {
767         FLOAT32 tmp;
768         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
769 
770         data += (del << 1);
771 
772         x1r = *data;
773         x1i = *(data + 1);
774         data += (del << 1);
775 
776         x2r = *data;
777         x2i = *(data + 1);
778         data += (del << 1);
779 
780         x3r = *data;
781         x3i = *(data + 1);
782         data -= 3 * (del << 1);
783 
784         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
785         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
786         x1r = tmp;
787 
788         tmp = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
789         x2i = (FLOAT32)(-((FLOAT32)x2r * W5) + (FLOAT32)x2i * W2);
790         x2r = tmp;
791 
792         tmp = (FLOAT32)(((FLOAT32)x3r * W6) - ((FLOAT32)x3i * W3));
793         x3i = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
794         x3r = tmp;
795 
796         x0r = (*data);
797         x0i = (*(data + 1));
798 
799         x0r = x0r + (x2r);
800         x0i = x0i + (x2i);
801         x2r = x0r - (x2r * 2);
802         x2i = x0i - (x2i * 2);
803         x1r = x1r + x3r;
804         x1i = x1i + x3i;
805         x3r = x1r - (x3r * 2);
806         x3i = x1i - (x3i * 2);
807 
808         x0r = x0r + (x1r);
809         x0i = x0i + (x1i);
810         x1r = x0r - (x1r * 2);
811         x1i = x0i - (x1i * 2);
812         x2r = x2r - (x3i);
813         x2i = x2i + (x3r);
814         x3i = x2r + (x3i * 2);
815         x3r = x2i - (x3r * 2);
816 
817         *data = x0r;
818         *(data + 1) = x0i;
819         data += (del << 1);
820 
821         *data = x2r;
822         *(data + 1) = x2i;
823         data += (del << 1);
824 
825         *data = x1r;
826         *(data + 1) = x1i;
827         data += (del << 1);
828 
829         *data = x3i;
830         *(data + 1) = x3r;
831         data += (del << 1);
832       }
833       data -= 2 * npoints;
834       data += 2;
835     }
836     for (; j <= sec_loop_cnt * 2; j += nodespacing) {
837       W1 = *(twiddles + j);
838       W4 = *(twiddles + j + 257);
839       W2 = *(twiddles + (j << 1) - 256);
840       W5 = *(twiddles + (j << 1) + 1);
841       W3 = *(twiddles + j + (j << 1) - 256);
842       W6 = *(twiddles + j + (j << 1) + 1);
843 
844       for (k = in_loop_cnt; k != 0; k--) {
845         FLOAT32 tmp;
846         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
847 
848         data += (del << 1);
849 
850         x1r = *data;
851         x1i = *(data + 1);
852         data += (del << 1);
853 
854         x2r = *data;
855         x2i = *(data + 1);
856         data += (del << 1);
857 
858         x3r = *data;
859         x3i = *(data + 1);
860         data -= 3 * (del << 1);
861 
862         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
863         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
864         x1r = tmp;
865 
866         tmp = (FLOAT32)(((FLOAT32)x2r * W5) - ((FLOAT32)x2i * W2));
867         x2i = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
868         x2r = tmp;
869 
870         tmp = (FLOAT32)(((FLOAT32)x3r * W6) - ((FLOAT32)x3i * W3));
871         x3i = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
872         x3r = tmp;
873 
874         x0r = (*data);
875         x0i = (*(data + 1));
876 
877         x0r = x0r + (x2r);
878         x0i = x0i + (x2i);
879         x2r = x0r - (x2r * 2);
880         x2i = x0i - (x2i * 2);
881         x1r = x1r + x3r;
882         x1i = x1i + x3i;
883         x3r = x1r - (x3r * 2);
884         x3i = x1i - (x3i * 2);
885 
886         x0r = x0r + (x1r);
887         x0i = x0i + (x1i);
888         x1r = x0r - (x1r * 2);
889         x1i = x0i - (x1i * 2);
890         x2r = x2r - (x3i);
891         x2i = x2i + (x3r);
892         x3i = x2r + (x3i * 2);
893         x3r = x2i - (x3r * 2);
894 
895         *data = x0r;
896         *(data + 1) = x0i;
897         data += (del << 1);
898 
899         *data = x2r;
900         *(data + 1) = x2i;
901         data += (del << 1);
902 
903         *data = x1r;
904         *(data + 1) = x1i;
905         data += (del << 1);
906 
907         *data = x3i;
908         *(data + 1) = x3r;
909         data += (del << 1);
910       }
911       data -= 2 * npoints;
912       data += 2;
913     }
914     for (; j < nodespacing * del; j += nodespacing) {
915       W1 = *(twiddles + j);
916       W4 = *(twiddles + j + 257);
917       W2 = *(twiddles + (j << 1) - 256);
918       W5 = *(twiddles + (j << 1) + 1);
919       W3 = *(twiddles + j + (j << 1) - 512);
920       W6 = *(twiddles + j + (j << 1) - 512 + 257);
921 
922       for (k = in_loop_cnt; k != 0; k--) {
923         FLOAT32 tmp;
924         FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
925 
926         data += (del << 1);
927 
928         x1r = *data;
929         x1i = *(data + 1);
930         data += (del << 1);
931 
932         x2r = *data;
933         x2i = *(data + 1);
934         data += (del << 1);
935 
936         x3r = *data;
937         x3i = *(data + 1);
938         data -= 3 * (del << 1);
939 
940         tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
941         x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
942         x1r = tmp;
943 
944         tmp = (FLOAT32)(((FLOAT32)x2r * W5) - ((FLOAT32)x2i * W2));
945         x2i = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
946         x2r = tmp;
947 
948         tmp = (FLOAT32)(-((FLOAT32)x3r * W3) - ((FLOAT32)x3i * W6));
949         x3i = (FLOAT32)(-((FLOAT32)x3r * W6) + (FLOAT32)x3i * W3);
950         x3r = tmp;
951 
952         x0r = (*data);
953         x0i = (*(data + 1));
954 
955         x0r = x0r + (x2r);
956         x0i = x0i + (x2i);
957         x2r = x0r - (x2r * 2);
958         x2i = x0i - (x2i * 2);
959         x1r = x1r + x3r;
960         x1i = x1i - x3i;
961         x3r = x1r - (x3r * 2);
962         x3i = x1i + (x3i * 2);
963 
964         x0r = x0r + (x1r);
965         x0i = x0i + (x1i);
966         x1r = x0r - (x1r * 2);
967         x1i = x0i - (x1i * 2);
968         x2r = x2r - (x3i);
969         x2i = x2i + (x3r);
970         x3i = x2r + (x3i * 2);
971         x3r = x2i - (x3r * 2);
972 
973         *data = x0r;
974         *(data + 1) = x0i;
975         data += (del << 1);
976 
977         *data = x2r;
978         *(data + 1) = x2i;
979         data += (del << 1);
980 
981         *data = x1r;
982         *(data + 1) = x1i;
983         data += (del << 1);
984 
985         *data = x3i;
986         *(data + 1) = x3r;
987         data += (del << 1);
988       }
989       data -= 2 * npoints;
990       data += 2;
991     }
992     nodespacing >>= 2;
993     del <<= 2;
994     in_loop_cnt >>= 2;
995   }
996 
997   if (not_power_4) {
998     const FLOAT32 *twiddles = ptr_w;
999     nodespacing <<= 1;
1000 
1001     for (j = del / 2; j != 0; j--) {
1002       FLOAT32 W1 = *twiddles;
1003       FLOAT32 W4 = *(twiddles + 257);
1004       FLOAT32 tmp;
1005       twiddles += nodespacing;
1006 
1007       x0r = *ptr_y;
1008       x0i = *(ptr_y + 1);
1009       ptr_y += (del << 1);
1010 
1011       x1r = *ptr_y;
1012       x1i = *(ptr_y + 1);
1013 
1014       tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
1015       x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
1016       x1r = tmp;
1017 
1018       *ptr_y = (x0r) - (x1r);
1019       *(ptr_y + 1) = (x0i) - (x1i);
1020       ptr_y -= (del << 1);
1021 
1022       *ptr_y = (x0r) + (x1r);
1023       *(ptr_y + 1) = (x0i) + (x1i);
1024       ptr_y += 2;
1025     }
1026     twiddles = ptr_w;
1027     for (j = del / 2; j != 0; j--) {
1028       FLOAT32 W1 = *twiddles;
1029       FLOAT32 W4 = *(twiddles + 257);
1030       FLOAT32 tmp;
1031       twiddles += nodespacing;
1032 
1033       x0r = *ptr_y;
1034       x0i = *(ptr_y + 1);
1035       ptr_y += (del << 1);
1036 
1037       x1r = *ptr_y;
1038       x1i = *(ptr_y + 1);
1039 
1040       tmp = (FLOAT32)(((FLOAT32)x1r * W4) - ((FLOAT32)x1i * W1));
1041       x1i = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
1042       x1r = tmp;
1043 
1044       *ptr_y = (x0r) - (x1r);
1045       *(ptr_y + 1) = (x0i) - (x1i);
1046       ptr_y -= (del << 1);
1047 
1048       *ptr_y = (x0r) + (x1r);
1049       *(ptr_y + 1) = (x0i) + (x1i);
1050       ptr_y += 2;
1051     }
1052   }
1053 }
1054 
ixheaacd_aac_ld_dec_fft_3_float(FLOAT32 * inp,FLOAT32 * op)1055 static PLATFORM_INLINE void ixheaacd_aac_ld_dec_fft_3_float(FLOAT32 *inp,
1056                                                             FLOAT32 *op) {
1057   FLOAT32 add_r, sub_r;
1058   FLOAT32 add_i, sub_i;
1059   FLOAT32 temp_real, temp_imag, temp;
1060 
1061   FLOAT32 p1, p2, p3, p4;
1062 
1063   FLOAT32 sinmu;
1064   sinmu = -0.866025403784439f;
1065 
1066   temp_real = inp[0] + inp[2];
1067   temp_imag = inp[1] + inp[3];
1068 
1069   add_r = inp[2] + inp[4];
1070   add_i = inp[3] + inp[5];
1071 
1072   sub_r = inp[2] - inp[4];
1073   sub_i = inp[3] - inp[5];
1074 
1075   p1 = add_r / 2.0f;
1076   p4 = add_i / 2.0f;
1077   p2 = sub_i * sinmu;
1078   p3 = sub_r * sinmu;
1079 
1080   temp = inp[0] - p1;
1081 
1082   op[0] = temp_real + inp[4];
1083   op[1] = temp_imag + inp[5];
1084   op[2] = temp + p2;
1085   op[3] = (inp[1] - p3) - p4;
1086   op[4] = temp - p2;
1087   op[5] = (inp[1] + p3) - p4;
1088 
1089   return;
1090 }
1091 
ixheaacd_real_synth_fft_p3(FLOAT32 * x_in,FLOAT32 * x_out,WORD32 npoints)1092 void ixheaacd_real_synth_fft_p3(FLOAT32 *x_in, FLOAT32 *x_out, WORD32 npoints) {
1093   WORD32 i, j;
1094   FLOAT32 x_3[8];
1095   FLOAT32 y_3[16];
1096   FLOAT32 y[48];
1097   FLOAT32 x[48];
1098   FLOAT32 *ptr_y = y;
1099   FLOAT32 *y_p3 = y;
1100   FLOAT32 *x_p3 = x;
1101 
1102   for (i = 0; i < 3; i += 1) {
1103     for (j = 0; j < (npoints / 3); j++) {
1104       x_3[j] = x_in[3 * j + i];
1105     }
1106 
1107     ixheaacd_real_synth_fft_p2(x_3, y_3, 8);
1108 
1109     for (j = 0; j < 16; j += 2) {
1110       x[3 * j + 2 * i] = y_3[j];
1111       x[3 * j + 2 * i + 1] = y_3[j + 1];
1112     }
1113   }
1114 
1115   {
1116     FLOAT32 *wr;
1117     FLOAT32 tmp;
1118     FLOAT32 *x_tw = x;
1119     wr = (FLOAT32 *)ixheaacd_twidle_tbl_24;
1120     x_tw += 2;
1121 
1122     for (i = 0; i < (npoints / 3); i++) {
1123       tmp = ((*x_tw) * (*wr) + (*(x_tw + 1)) * (*(wr + 1)));
1124       *(x_tw + 1) = (-(*x_tw) * (*(wr + 1)) + (*(x_tw + 1)) * (*wr));
1125       *x_tw = tmp;
1126 
1127       wr += 2;
1128       x_tw += 2;
1129 
1130       tmp = ((*x_tw) * (*wr) + (*(x_tw + 1)) * (*(wr + 1)));
1131       *(x_tw + 1) = (-(*x_tw) * (*(wr + 1)) + (*(x_tw + 1)) * (*wr));
1132       *x_tw = tmp;
1133 
1134       wr += 2;
1135       x_tw += 4;
1136     }
1137   }
1138 
1139   for (i = 0; i < (npoints / 3); i++) {
1140     ixheaacd_aac_ld_dec_fft_3_float(x_p3, y_p3);
1141 
1142     x_p3 = x_p3 + 6;
1143     y_p3 = y_p3 + 6;
1144   }
1145 
1146   for (i = 0; i < 16; i += 2) {
1147     x_out[i] = *ptr_y++;
1148     x_out[i + 1] = *ptr_y++;
1149     x_out[16 + i] = *ptr_y++;
1150     x_out[16 + i + 1] = *ptr_y++;
1151     x_out[32 + i] = *ptr_y++;
1152     x_out[32 + i + 1] = *ptr_y++;
1153   }
1154 }
1155 
ixheaacd_cmplx_anal_fft_p3(FLOAT32 * x_in,FLOAT32 * x_out,WORD32 npoints)1156 void ixheaacd_cmplx_anal_fft_p3(FLOAT32 *x_in, FLOAT32 *x_out, WORD32 npoints) {
1157   WORD32 i, j;
1158   FLOAT32 x_3[32];
1159   FLOAT32 y_3[32];
1160   FLOAT32 y[96];
1161   FLOAT32 *ptr_x = x_in;
1162   FLOAT32 *ptr_y = y;
1163   FLOAT32 *y_p3 = y;
1164 
1165   for (i = 0; i < 6; i += 2) {
1166     for (j = 0; j < 32; j += 2) {
1167       x_3[j] = x_in[3 * j + i];
1168       x_3[j + 1] = x_in[3 * j + i + 1];
1169     }
1170 
1171     ixheaacd_cmplx_anal_fft_p2(x_3, y_3, 16);
1172 
1173     for (j = 0; j < 32; j += 2) {
1174       x_in[3 * j + i] = y_3[j];
1175       x_in[3 * j + i + 1] = y_3[j + 1];
1176     }
1177   }
1178 
1179   {
1180     FLOAT32 *wr;
1181     FLOAT32 tmp;
1182     wr = (FLOAT32 *)ixheaacd_twidle_tbl_48;
1183     x_in += 2;
1184 
1185     for (i = 0; i < (npoints / 3); i++) {
1186       tmp = ((*x_in) * (*wr) + (*(x_in + 1)) * (*(wr + 1)));
1187       *(x_in + 1) = (-(*x_in) * (*(wr + 1)) + (*(x_in + 1)) * (*wr));
1188       *x_in = tmp;
1189 
1190       wr += 2;
1191       x_in += 2;
1192 
1193       tmp = ((*x_in) * (*wr) + (*(x_in + 1)) * (*(wr + 1)));
1194       *(x_in + 1) = (-(*x_in) * (*(wr + 1)) + (*(x_in + 1)) * (*wr));
1195       *x_in = tmp;
1196 
1197       wr += 2;
1198       x_in += 4;
1199     }
1200   }
1201 
1202   for (i = 0; i < (npoints / 3); i++) {
1203     ixheaacd_aac_ld_dec_fft_3_float(ptr_x, ptr_y);
1204 
1205     ptr_x = ptr_x + 6;
1206     ptr_y = ptr_y + 6;
1207   }
1208 
1209   for (i = 0; i < 32; i += 2) {
1210     x_out[i] = *y_p3++;
1211     x_out[i + 1] = *y_p3++;
1212     x_out[32 + i] = *y_p3++;
1213     x_out[32 + i + 1] = *y_p3++;
1214     x_out[64 + i] = *y_p3++;
1215     x_out[64 + i + 1] = *y_p3++;
1216   }
1217 }