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 const FLOAT32 ixheaacd_twiddle_table_fft_float[514];
39 extern const FLOAT32 ixheaacd_twidle_tbl_48[64];
40 extern 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 tmp = (FLOAT32)(((FLOAT32)x1r * W4) - ((FLOAT32)x1i * W1));
526 x1i = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
527 x1r = tmp;
528
529 *ptr_y = (x0r) - (x1r);
530 *(ptr_y + 1) = (x0i) - (x1i);
531 ptr_y -= (del << 1);
532
533 *ptr_y = (x0r) + (x1r);
534 *(ptr_y + 1) = (x0i) + (x1i);
535 ptr_y += 2;
536 }
537 }
538 }
539
ixheaacd_cmplx_anal_fft_p2(FLOAT32 * ptr_x,FLOAT32 * ptr_y,WORD32 npoints)540 void ixheaacd_cmplx_anal_fft_p2(FLOAT32 *ptr_x, FLOAT32 *ptr_y,
541 WORD32 npoints) {
542 WORD32 i, j, k, n_stages, h2;
543 FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
544 WORD32 del, nodespacing, in_loop_cnt;
545 WORD32 not_power_4;
546 WORD32 dig_rev_shift;
547 const FLOAT32 *ptr_w;
548
549 dig_rev_shift = ixheaacd_norm32(npoints) + 1 - 16;
550 n_stages = 30 - ixheaacd_norm32(npoints);
551 not_power_4 = n_stages & 1;
552
553 n_stages = n_stages >> 1;
554
555 ptr_w = ixheaacd_twiddle_table_fft_float;
556
557 for (i = 0; i < npoints; i += 4) {
558 FLOAT32 *inp = ptr_x;
559
560 DIG_REV(i, dig_rev_shift, h2);
561 if (not_power_4) {
562 h2 += 1;
563 h2 &= ~1;
564 }
565 inp += (h2);
566
567 x0r = *inp;
568 x0i = *(inp + 1);
569 inp += (npoints >> 1);
570
571 x1r = *inp;
572 x1i = *(inp + 1);
573 inp += (npoints >> 1);
574
575 x2r = *inp;
576 x2i = *(inp + 1);
577 inp += (npoints >> 1);
578
579 x3r = *inp;
580 x3i = *(inp + 1);
581
582 x0r = x0r + x2r;
583 x0i = x0i + x2i;
584 x2r = x0r - (x2r * 2);
585 x2i = x0i - (x2i * 2);
586 x1r = x1r + x3r;
587 x1i = x1i + x3i;
588 x3r = x1r - (x3r * 2);
589 x3i = x1i - (x3i * 2);
590
591 x0r = x0r + x1r;
592 x0i = x0i + x1i;
593 x1r = x0r - (x1r * 2);
594 x1i = x0i - (x1i * 2);
595 x2r = x2r - x3i;
596 x2i = x2i + x3r;
597 x3i = x2r + (x3i * 2);
598 x3r = x2i - (x3r * 2);
599
600 *ptr_y++ = x0r;
601 *ptr_y++ = x0i;
602 *ptr_y++ = x2r;
603 *ptr_y++ = x2i;
604 *ptr_y++ = x1r;
605 *ptr_y++ = x1i;
606 *ptr_y++ = x3i;
607 *ptr_y++ = x3r;
608 }
609 ptr_y -= 2 * npoints;
610 del = 4;
611 nodespacing = 64;
612 in_loop_cnt = npoints >> 4;
613 for (i = n_stages - 1; i > 0; i--) {
614 const FLOAT32 *twiddles = ptr_w;
615 FLOAT32 *data = ptr_y;
616 FLOAT32 W1, W2, W3, W4, W5, W6;
617 WORD32 sec_loop_cnt;
618
619 for (k = in_loop_cnt; k != 0; k--) {
620 x0r = (*data);
621 x0i = (*(data + 1));
622 data += (del << 1);
623
624 x1r = (*data);
625 x1i = (*(data + 1));
626 data += (del << 1);
627
628 x2r = (*data);
629 x2i = (*(data + 1));
630 data += (del << 1);
631
632 x3r = (*data);
633 x3i = (*(data + 1));
634 data -= 3 * (del << 1);
635
636 x0r = x0r + x2r;
637 x0i = x0i + x2i;
638 x2r = x0r - (x2r * 2);
639 x2i = x0i - (x2i * 2);
640 x1r = x1r + x3r;
641 x1i = x1i + x3i;
642 x3r = x1r - (x3r * 2);
643 x3i = x1i - (x3i * 2);
644
645 x0r = x0r + x1r;
646 x0i = x0i + x1i;
647 x1r = x0r - (x1r * 2);
648 x1i = x0i - (x1i * 2);
649 x2r = x2r - x3i;
650 x2i = x2i + x3r;
651 x3i = x2r + (x3i * 2);
652 x3r = x2i - (x3r * 2);
653
654 *data = x0r;
655 *(data + 1) = x0i;
656 data += (del << 1);
657
658 *data = x2r;
659 *(data + 1) = x2i;
660 data += (del << 1);
661
662 *data = x1r;
663 *(data + 1) = x1i;
664 data += (del << 1);
665
666 *data = x3i;
667 *(data + 1) = x3r;
668 data += (del << 1);
669 }
670 data = ptr_y + 2;
671
672 sec_loop_cnt = (nodespacing * del);
673 sec_loop_cnt = (sec_loop_cnt / 4) + (sec_loop_cnt / 8) -
674 (sec_loop_cnt / 16) + (sec_loop_cnt / 32) -
675 (sec_loop_cnt / 64) + (sec_loop_cnt / 128) -
676 (sec_loop_cnt / 256);
677 j = nodespacing;
678
679 for (j = nodespacing; j <= sec_loop_cnt; j += nodespacing) {
680 W1 = *(twiddles + j);
681 W4 = *(twiddles + j + 257);
682 W2 = *(twiddles + (j << 1));
683 W5 = *(twiddles + (j << 1) + 257);
684 W3 = *(twiddles + j + (j << 1));
685 W6 = *(twiddles + j + (j << 1) + 257);
686
687 for (k = in_loop_cnt; k != 0; k--) {
688 FLOAT32 tmp;
689 FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
690
691 data += (del << 1);
692
693 x1r = *data;
694 x1i = *(data + 1);
695 data += (del << 1);
696
697 x2r = *data;
698 x2i = *(data + 1);
699 data += (del << 1);
700
701 x3r = *data;
702 x3i = *(data + 1);
703 data -= 3 * (del << 1);
704
705 tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
706 x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
707 x1r = tmp;
708
709 tmp = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
710 x2i = (FLOAT32)(-((FLOAT32)x2r * W5) + (FLOAT32)x2i * W2);
711 x2r = tmp;
712
713 tmp = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
714 x3i = (FLOAT32)(-((FLOAT32)x3r * W6) + (FLOAT32)x3i * W3);
715 x3r = tmp;
716
717 x0r = (*data);
718 x0i = (*(data + 1));
719
720 x0r = x0r + (x2r);
721 x0i = x0i + (x2i);
722 x2r = x0r - (x2r * 2);
723 x2i = x0i - (x2i * 2);
724 x1r = x1r + x3r;
725 x1i = x1i + x3i;
726 x3r = x1r - (x3r * 2);
727 x3i = x1i - (x3i * 2);
728
729 x0r = x0r + (x1r);
730 x0i = x0i + (x1i);
731 x1r = x0r - (x1r * 2);
732 x1i = x0i - (x1i * 2);
733 x2r = x2r - (x3i);
734 x2i = x2i + (x3r);
735 x3i = x2r + (x3i * 2);
736 x3r = x2i - (x3r * 2);
737
738 *data = x0r;
739 *(data + 1) = x0i;
740 data += (del << 1);
741
742 *data = x2r;
743 *(data + 1) = x2i;
744 data += (del << 1);
745
746 *data = x1r;
747 *(data + 1) = x1i;
748 data += (del << 1);
749
750 *data = x3i;
751 *(data + 1) = x3r;
752 data += (del << 1);
753 }
754 data -= 2 * npoints;
755 data += 2;
756 }
757 for (; j <= (nodespacing * del) >> 1; j += nodespacing) {
758 W1 = *(twiddles + j);
759 W4 = *(twiddles + j + 257);
760 W2 = *(twiddles + (j << 1));
761 W5 = *(twiddles + (j << 1) + 257);
762 W3 = *(twiddles + j + (j << 1) - 256);
763 W6 = *(twiddles + j + (j << 1) + 1);
764
765 for (k = in_loop_cnt; k != 0; k--) {
766 FLOAT32 tmp;
767 FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
768
769 data += (del << 1);
770
771 x1r = *data;
772 x1i = *(data + 1);
773 data += (del << 1);
774
775 x2r = *data;
776 x2i = *(data + 1);
777 data += (del << 1);
778
779 x3r = *data;
780 x3i = *(data + 1);
781 data -= 3 * (del << 1);
782
783 tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
784 x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
785 x1r = tmp;
786
787 tmp = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
788 x2i = (FLOAT32)(-((FLOAT32)x2r * W5) + (FLOAT32)x2i * W2);
789 x2r = tmp;
790
791 tmp = (FLOAT32)(((FLOAT32)x3r * W6) - ((FLOAT32)x3i * W3));
792 x3i = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
793 x3r = tmp;
794
795 x0r = (*data);
796 x0i = (*(data + 1));
797
798 x0r = x0r + (x2r);
799 x0i = x0i + (x2i);
800 x2r = x0r - (x2r * 2);
801 x2i = x0i - (x2i * 2);
802 x1r = x1r + x3r;
803 x1i = x1i + x3i;
804 x3r = x1r - (x3r * 2);
805 x3i = x1i - (x3i * 2);
806
807 x0r = x0r + (x1r);
808 x0i = x0i + (x1i);
809 x1r = x0r - (x1r * 2);
810 x1i = x0i - (x1i * 2);
811 x2r = x2r - (x3i);
812 x2i = x2i + (x3r);
813 x3i = x2r + (x3i * 2);
814 x3r = x2i - (x3r * 2);
815
816 *data = x0r;
817 *(data + 1) = x0i;
818 data += (del << 1);
819
820 *data = x2r;
821 *(data + 1) = x2i;
822 data += (del << 1);
823
824 *data = x1r;
825 *(data + 1) = x1i;
826 data += (del << 1);
827
828 *data = x3i;
829 *(data + 1) = x3r;
830 data += (del << 1);
831 }
832 data -= 2 * npoints;
833 data += 2;
834 }
835 for (; j <= sec_loop_cnt * 2; j += nodespacing) {
836 W1 = *(twiddles + j);
837 W4 = *(twiddles + j + 257);
838 W2 = *(twiddles + (j << 1) - 256);
839 W5 = *(twiddles + (j << 1) + 1);
840 W3 = *(twiddles + j + (j << 1) - 256);
841 W6 = *(twiddles + j + (j << 1) + 1);
842
843 for (k = in_loop_cnt; k != 0; k--) {
844 FLOAT32 tmp;
845 FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
846
847 data += (del << 1);
848
849 x1r = *data;
850 x1i = *(data + 1);
851 data += (del << 1);
852
853 x2r = *data;
854 x2i = *(data + 1);
855 data += (del << 1);
856
857 x3r = *data;
858 x3i = *(data + 1);
859 data -= 3 * (del << 1);
860
861 tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
862 x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
863 x1r = tmp;
864
865 tmp = (FLOAT32)(((FLOAT32)x2r * W5) - ((FLOAT32)x2i * W2));
866 x2i = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
867 x2r = tmp;
868
869 tmp = (FLOAT32)(((FLOAT32)x3r * W6) - ((FLOAT32)x3i * W3));
870 x3i = (FLOAT32)(((FLOAT32)x3r * W3) + ((FLOAT32)x3i * W6));
871 x3r = tmp;
872
873 x0r = (*data);
874 x0i = (*(data + 1));
875
876 x0r = x0r + (x2r);
877 x0i = x0i + (x2i);
878 x2r = x0r - (x2r * 2);
879 x2i = x0i - (x2i * 2);
880 x1r = x1r + x3r;
881 x1i = x1i + x3i;
882 x3r = x1r - (x3r * 2);
883 x3i = x1i - (x3i * 2);
884
885 x0r = x0r + (x1r);
886 x0i = x0i + (x1i);
887 x1r = x0r - (x1r * 2);
888 x1i = x0i - (x1i * 2);
889 x2r = x2r - (x3i);
890 x2i = x2i + (x3r);
891 x3i = x2r + (x3i * 2);
892 x3r = x2i - (x3r * 2);
893
894 *data = x0r;
895 *(data + 1) = x0i;
896 data += (del << 1);
897
898 *data = x2r;
899 *(data + 1) = x2i;
900 data += (del << 1);
901
902 *data = x1r;
903 *(data + 1) = x1i;
904 data += (del << 1);
905
906 *data = x3i;
907 *(data + 1) = x3r;
908 data += (del << 1);
909 }
910 data -= 2 * npoints;
911 data += 2;
912 }
913 for (; j < nodespacing * del; j += nodespacing) {
914 W1 = *(twiddles + j);
915 W4 = *(twiddles + j + 257);
916 W2 = *(twiddles + (j << 1) - 256);
917 W5 = *(twiddles + (j << 1) + 1);
918 W3 = *(twiddles + j + (j << 1) - 512);
919 W6 = *(twiddles + j + (j << 1) - 512 + 257);
920
921 for (k = in_loop_cnt; k != 0; k--) {
922 FLOAT32 tmp;
923 FLOAT32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
924
925 data += (del << 1);
926
927 x1r = *data;
928 x1i = *(data + 1);
929 data += (del << 1);
930
931 x2r = *data;
932 x2i = *(data + 1);
933 data += (del << 1);
934
935 x3r = *data;
936 x3i = *(data + 1);
937 data -= 3 * (del << 1);
938
939 tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
940 x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
941 x1r = tmp;
942
943 tmp = (FLOAT32)(((FLOAT32)x2r * W5) - ((FLOAT32)x2i * W2));
944 x2i = (FLOAT32)(((FLOAT32)x2r * W2) + ((FLOAT32)x2i * W5));
945 x2r = tmp;
946
947 tmp = (FLOAT32)(-((FLOAT32)x3r * W3) - ((FLOAT32)x3i * W6));
948 x3i = (FLOAT32)(-((FLOAT32)x3r * W6) + (FLOAT32)x3i * W3);
949 x3r = tmp;
950
951 x0r = (*data);
952 x0i = (*(data + 1));
953
954 x0r = x0r + (x2r);
955 x0i = x0i + (x2i);
956 x2r = x0r - (x2r * 2);
957 x2i = x0i - (x2i * 2);
958 x1r = x1r + x3r;
959 x1i = x1i - x3i;
960 x3r = x1r - (x3r * 2);
961 x3i = x1i + (x3i * 2);
962
963 x0r = x0r + (x1r);
964 x0i = x0i + (x1i);
965 x1r = x0r - (x1r * 2);
966 x1i = x0i - (x1i * 2);
967 x2r = x2r - (x3i);
968 x2i = x2i + (x3r);
969 x3i = x2r + (x3i * 2);
970 x3r = x2i - (x3r * 2);
971
972 *data = x0r;
973 *(data + 1) = x0i;
974 data += (del << 1);
975
976 *data = x2r;
977 *(data + 1) = x2i;
978 data += (del << 1);
979
980 *data = x1r;
981 *(data + 1) = x1i;
982 data += (del << 1);
983
984 *data = x3i;
985 *(data + 1) = x3r;
986 data += (del << 1);
987 }
988 data -= 2 * npoints;
989 data += 2;
990 }
991 nodespacing >>= 2;
992 del <<= 2;
993 in_loop_cnt >>= 2;
994 }
995
996 if (not_power_4) {
997 const FLOAT32 *twiddles = ptr_w;
998 nodespacing <<= 1;
999
1000 for (j = del / 2; j != 0; j--) {
1001 FLOAT32 W1 = *twiddles;
1002 FLOAT32 W4 = *(twiddles + 257);
1003 FLOAT32 tmp;
1004 twiddles += nodespacing;
1005
1006 x0r = *ptr_y;
1007 x0i = *(ptr_y + 1);
1008 ptr_y += (del << 1);
1009
1010 x1r = *ptr_y;
1011 x1i = *(ptr_y + 1);
1012
1013 tmp = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
1014 x1i = (FLOAT32)(-((FLOAT32)x1r * W4) + (FLOAT32)x1i * W1);
1015 x1r = tmp;
1016
1017 *ptr_y = (x0r) - (x1r);
1018 *(ptr_y + 1) = (x0i) - (x1i);
1019 ptr_y -= (del << 1);
1020
1021 *ptr_y = (x0r) + (x1r);
1022 *(ptr_y + 1) = (x0i) + (x1i);
1023 ptr_y += 2;
1024 }
1025 twiddles = ptr_w;
1026 for (j = del / 2; j != 0; j--) {
1027 FLOAT32 W1 = *twiddles;
1028 FLOAT32 W4 = *(twiddles + 257);
1029 FLOAT32 tmp;
1030 twiddles += nodespacing;
1031
1032 x0r = *ptr_y;
1033 x0i = *(ptr_y + 1);
1034 ptr_y += (del << 1);
1035
1036 x1r = *ptr_y;
1037 x1i = *(ptr_y + 1);
1038
1039 tmp = (FLOAT32)(((FLOAT32)x1r * W4) - ((FLOAT32)x1i * W1));
1040 x1i = (FLOAT32)(((FLOAT32)x1r * W1) + ((FLOAT32)x1i * W4));
1041 x1r = tmp;
1042
1043 *ptr_y = (x0r) - (x1r);
1044 *(ptr_y + 1) = (x0i) - (x1i);
1045 ptr_y -= (del << 1);
1046
1047 *ptr_y = (x0r) + (x1r);
1048 *(ptr_y + 1) = (x0i) + (x1i);
1049 ptr_y += 2;
1050 }
1051 }
1052 }
1053
ixheaacd_aac_ld_dec_fft_3_float(FLOAT32 * inp,FLOAT32 * op)1054 static PLATFORM_INLINE void ixheaacd_aac_ld_dec_fft_3_float(FLOAT32 *inp,
1055 FLOAT32 *op) {
1056 FLOAT32 add_r, sub_r;
1057 FLOAT32 add_i, sub_i;
1058 FLOAT32 temp_real, temp_imag, temp;
1059
1060 FLOAT32 p1, p2, p3, p4;
1061
1062 FLOAT32 sinmu;
1063 sinmu = -0.866025403784439f;
1064
1065 temp_real = inp[0] + inp[2];
1066 temp_imag = inp[1] + inp[3];
1067
1068 add_r = inp[2] + inp[4];
1069 add_i = inp[3] + inp[5];
1070
1071 sub_r = inp[2] - inp[4];
1072 sub_i = inp[3] - inp[5];
1073
1074 p1 = add_r / 2.0f;
1075 p4 = add_i / 2.0f;
1076 p2 = sub_i * sinmu;
1077 p3 = sub_r * sinmu;
1078
1079 temp = inp[0] - p1;
1080
1081 op[0] = temp_real + inp[4];
1082 op[1] = temp_imag + inp[5];
1083 op[2] = temp + p2;
1084 op[3] = (inp[1] - p3) - p4;
1085 op[4] = temp - p2;
1086 op[5] = (inp[1] + p3) - p4;
1087
1088 return;
1089 }
1090
ixheaacd_real_synth_fft_p3(FLOAT32 * x_in,FLOAT32 * x_out,WORD32 npoints)1091 void ixheaacd_real_synth_fft_p3(FLOAT32 *x_in, FLOAT32 *x_out, WORD32 npoints) {
1092 WORD32 i, j;
1093 FLOAT32 x_3[8];
1094 FLOAT32 y_3[16];
1095 FLOAT32 y[48];
1096 FLOAT32 x[48];
1097 FLOAT32 *ptr_y = y;
1098 FLOAT32 *y_p3 = y;
1099 FLOAT32 *x_p3 = x;
1100
1101 for (i = 0; i < 3; i += 1) {
1102 for (j = 0; j < (npoints / 3); j++) {
1103 x_3[j] = x_in[3 * j + i];
1104 }
1105
1106 ixheaacd_real_synth_fft_p2(x_3, y_3, 8);
1107
1108 for (j = 0; j < 16; j += 2) {
1109 x[3 * j + 2 * i] = y_3[j];
1110 x[3 * j + 2 * i + 1] = y_3[j + 1];
1111 }
1112 }
1113
1114 {
1115 FLOAT32 *wr;
1116 FLOAT32 tmp;
1117 FLOAT32 *x_tw = x;
1118 wr = (FLOAT32 *)ixheaacd_twidle_tbl_24;
1119 x_tw += 2;
1120
1121 for (i = 0; i < (npoints / 3); i++) {
1122 tmp = ((*x_tw) * (*wr) + (*(x_tw + 1)) * (*(wr + 1)));
1123 *(x_tw + 1) = (-(*x_tw) * (*(wr + 1)) + (*(x_tw + 1)) * (*wr));
1124 *x_tw = tmp;
1125
1126 wr += 2;
1127 x_tw += 2;
1128
1129 tmp = ((*x_tw) * (*wr) + (*(x_tw + 1)) * (*(wr + 1)));
1130 *(x_tw + 1) = (-(*x_tw) * (*(wr + 1)) + (*(x_tw + 1)) * (*wr));
1131 *x_tw = tmp;
1132
1133 wr += 2;
1134 x_tw += 4;
1135 }
1136 }
1137
1138 for (i = 0; i < (npoints / 3); i++) {
1139 ixheaacd_aac_ld_dec_fft_3_float(x_p3, y_p3);
1140
1141 x_p3 = x_p3 + 6;
1142 y_p3 = y_p3 + 6;
1143 }
1144
1145 for (i = 0; i < 16; i += 2) {
1146 x_out[i] = *ptr_y++;
1147 x_out[i + 1] = *ptr_y++;
1148 x_out[16 + i] = *ptr_y++;
1149 x_out[16 + i + 1] = *ptr_y++;
1150 x_out[32 + i] = *ptr_y++;
1151 x_out[32 + i + 1] = *ptr_y++;
1152 }
1153 }
1154
ixheaacd_cmplx_anal_fft_p3(FLOAT32 * x_in,FLOAT32 * x_out,WORD32 npoints)1155 void ixheaacd_cmplx_anal_fft_p3(FLOAT32 *x_in, FLOAT32 *x_out, WORD32 npoints) {
1156 WORD32 i, j;
1157 FLOAT32 x_3[32];
1158 FLOAT32 y_3[32];
1159 FLOAT32 y[96];
1160 FLOAT32 *ptr_x = x_in;
1161 FLOAT32 *ptr_y = y;
1162 FLOAT32 *y_p3 = y;
1163
1164 for (i = 0; i < 6; i += 2) {
1165 for (j = 0; j < 32; j += 2) {
1166 x_3[j] = x_in[3 * j + i];
1167 x_3[j + 1] = x_in[3 * j + i + 1];
1168 }
1169
1170 ixheaacd_cmplx_anal_fft_p2(x_3, y_3, 16);
1171
1172 for (j = 0; j < 32; j += 2) {
1173 x_in[3 * j + i] = y_3[j];
1174 x_in[3 * j + i + 1] = y_3[j + 1];
1175 }
1176 }
1177
1178 {
1179 FLOAT32 *wr;
1180 FLOAT32 tmp;
1181 wr = (FLOAT32 *)ixheaacd_twidle_tbl_48;
1182 x_in += 2;
1183
1184 for (i = 0; i < (npoints / 3); i++) {
1185 tmp = ((*x_in) * (*wr) + (*(x_in + 1)) * (*(wr + 1)));
1186 *(x_in + 1) = (-(*x_in) * (*(wr + 1)) + (*(x_in + 1)) * (*wr));
1187 *x_in = tmp;
1188
1189 wr += 2;
1190 x_in += 2;
1191
1192 tmp = ((*x_in) * (*wr) + (*(x_in + 1)) * (*(wr + 1)));
1193 *(x_in + 1) = (-(*x_in) * (*(wr + 1)) + (*(x_in + 1)) * (*wr));
1194 *x_in = tmp;
1195
1196 wr += 2;
1197 x_in += 4;
1198 }
1199 }
1200
1201 for (i = 0; i < (npoints / 3); i++) {
1202 ixheaacd_aac_ld_dec_fft_3_float(ptr_x, ptr_y);
1203
1204 ptr_x = ptr_x + 6;
1205 ptr_y = ptr_y + 6;
1206 }
1207
1208 for (i = 0; i < 32; i += 2) {
1209 x_out[i] = *y_p3++;
1210 x_out[i + 1] = *y_p3++;
1211 x_out[32 + i] = *y_p3++;
1212 x_out[32 + i + 1] = *y_p3++;
1213 x_out[64 + i] = *y_p3++;
1214 x_out[64 + i + 1] = *y_p3++;
1215 }
1216 }