Coverage Report

Created: 2025-07-11 06:39

/proc/self/cwd/libfaad/cfft.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4
**
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
**
19
** Any non-GPL usage of this software or parts of this software is strictly
20
** forbidden.
21
**
22
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24
**
25
** Commercial non-GPL licensing of this software is possible.
26
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27
**
28
** $Id: cfft.c,v 1.35 2007/11/01 12:33:29 menno Exp $
29
**/
30
31
/*
32
 * Algorithmically based on Fortran-77 FFTPACK
33
 * by Paul N. Swarztrauber(Version 4, 1985).
34
 *
35
 * Does even sized fft only
36
 */
37
38
/* isign is +1 for backward and -1 for forward transforms */
39
40
#include "common.h"
41
#include "structs.h"
42
43
#include <stdlib.h>
44
45
#include "cfft.h"
46
#include "cfft_tab.h"
47
48
49
/* static function declarations */
50
static void passf2pos(const uint16_t ido, const uint16_t l1, const complex_t *cc,
51
                      complex_t *ch, const complex_t *wa);
52
static void passf2neg(const uint16_t ido, const uint16_t l1, const complex_t *cc,
53
                      complex_t *ch, const complex_t *wa);
54
static void passf3(const uint16_t ido, const uint16_t l1, const complex_t *cc,
55
                   complex_t *ch, const complex_t *wa1, const complex_t *wa2, const int8_t isign);
56
static void passf4pos(const uint16_t ido, const uint16_t l1, const complex_t *cc, complex_t *ch,
57
                      const complex_t *wa1, const complex_t *wa2, const complex_t *wa3);
58
static void passf4neg(const uint16_t ido, const uint16_t l1, const complex_t *cc, complex_t *ch,
59
                      const complex_t *wa1, const complex_t *wa2, const complex_t *wa3);
60
static void passf5(const uint16_t ido, const uint16_t l1, const complex_t *cc, complex_t *ch,
61
                   const complex_t *wa1, const complex_t *wa2, const complex_t *wa3,
62
                   const complex_t *wa4, const int8_t isign);
63
static void cffti1(uint16_t n, complex_t *wa, uint16_t *ifac);
64
65
66
/*----------------------------------------------------------------------
67
   passf2, passf3, passf4, passf5. Complex FFT passes fwd and bwd.
68
  ----------------------------------------------------------------------*/
69
70
static void passf2pos(const uint16_t ido, const uint16_t l1, const complex_t *cc,
71
                      complex_t *ch, const complex_t *wa)
72
0
{
73
0
    uint16_t i, k, ah, ac;
74
75
0
    if (ido == 1)
76
0
    {
77
0
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
78
        // TODO: remove this code once fuzzer proves it is totally unreahable
79
        // For supported frame lengths that have odd number of factor 2 it is
80
        // never the last factor; consequently `ido` should never be 1.
81
0
        __builtin_trap();
82
        /*
83
#endif
84
        for (k = 0; k < l1; k++)
85
        {
86
            ah = 2*k;
87
            ac = 4*k;
88
89
            RE(ch[ah])    = RE(cc[ac]) + RE(cc[ac+1]);
90
            RE(ch[ah+l1]) = RE(cc[ac]) - RE(cc[ac+1]);
91
            IM(ch[ah])    = IM(cc[ac]) + IM(cc[ac+1]);
92
            IM(ch[ah+l1]) = IM(cc[ac]) - IM(cc[ac+1]);
93
        }
94
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
95
        */
96
0
#endif
97
0
    } else {
98
0
        for (k = 0; k < l1; k++)
99
0
        {
100
0
            ah = k*ido;
101
0
            ac = 2*k*ido;
102
103
0
            for (i = 0; i < ido; i++)
104
0
            {
105
0
                complex_t t2;
106
107
0
                RE(ch[ah+i]) = RE(cc[ac+i]) + RE(cc[ac+i+ido]);
108
0
                RE(t2)       = RE(cc[ac+i]) - RE(cc[ac+i+ido]);
109
110
0
                IM(ch[ah+i]) = IM(cc[ac+i]) + IM(cc[ac+i+ido]);
111
0
                IM(t2)       = IM(cc[ac+i]) - IM(cc[ac+i+ido]);
112
113
0
#if 1
114
0
                ComplexMult(&IM(ch[ah+i+l1*ido]), &RE(ch[ah+i+l1*ido]),
115
0
                    IM(t2), RE(t2), RE(wa[i]), IM(wa[i]));
116
#else
117
                ComplexMult(&RE(ch[ah+i+l1*ido]), &IM(ch[ah+i+l1*ido]),
118
                    RE(t2), IM(t2), RE(wa[i]), IM(wa[i]));
119
#endif
120
0
            }
121
0
        }
122
0
    }
123
0
}
124
125
static void passf2neg(const uint16_t ido, const uint16_t l1, const complex_t *cc,
126
                      complex_t *ch, const complex_t *wa)
127
0
{
128
0
    uint16_t i, k, ah, ac;
129
130
0
    if (ido == 1)
131
0
    {
132
0
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
133
        // TODO: remove this code once fuzzer proves it is totally unreahable
134
        // For supported frame lengths that have odd number of factor 2 it is
135
        // never the last factor; consequently `ido` should never be 1.
136
0
        __builtin_trap();
137
        /*
138
#endif
139
        for (k = 0; k < l1; k++)
140
        {
141
            ah = 2*k;
142
            ac = 4*k;
143
144
            RE(ch[ah])    = RE(cc[ac]) + RE(cc[ac+1]);
145
            RE(ch[ah+l1]) = RE(cc[ac]) - RE(cc[ac+1]);
146
            IM(ch[ah])    = IM(cc[ac]) + IM(cc[ac+1]);
147
            IM(ch[ah+l1]) = IM(cc[ac]) - IM(cc[ac+1]);
148
        }
149
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
150
        */
151
0
#endif
152
0
    } else {
153
0
        for (k = 0; k < l1; k++)
154
0
        {
155
0
            ah = k*ido;
156
0
            ac = 2*k*ido;
157
158
0
            for (i = 0; i < ido; i++)
159
0
            {
160
0
                complex_t t2;
161
162
0
                RE(ch[ah+i]) = RE(cc[ac+i]) + RE(cc[ac+i+ido]);
163
0
                RE(t2)       = RE(cc[ac+i]) - RE(cc[ac+i+ido]);
164
165
0
                IM(ch[ah+i]) = IM(cc[ac+i]) + IM(cc[ac+i+ido]);
166
0
                IM(t2)       = IM(cc[ac+i]) - IM(cc[ac+i+ido]);
167
168
0
#if 1
169
0
                ComplexMult(&RE(ch[ah+i+l1*ido]), &IM(ch[ah+i+l1*ido]),
170
0
                    RE(t2), IM(t2), RE(wa[i]), IM(wa[i]));
171
#else
172
                ComplexMult(&IM(ch[ah+i+l1*ido]), &RE(ch[ah+i+l1*ido]),
173
                    IM(t2), RE(t2), RE(wa[i]), IM(wa[i]));
174
#endif
175
0
            }
176
0
        }
177
0
    }
178
0
}
179
180
181
static void passf3(const uint16_t ido, const uint16_t l1, const complex_t *cc,
182
                   complex_t *ch, const complex_t *wa1, const complex_t *wa2,
183
                   const int8_t isign)
184
0
{
185
0
    static real_t taur = FRAC_CONST(-0.5);
186
0
    static real_t taui = FRAC_CONST(0.866025403784439);
187
0
    uint16_t i, k, ac, ah;
188
0
    complex_t c2, c3, d2, d3, t2;
189
190
0
    if (ido == 1)
191
0
    {
192
0
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
193
        // TODO: remove this code once fuzzer proves it is totally unreahable
194
        // 3 is never the the biggest factor for supported frame lengths;
195
        // consequently `ido` should never be 1.
196
0
        __builtin_trap();
197
        /*
198
#endif
199
        if (isign == 1)
200
        {
201
            for (k = 0; k < l1; k++)
202
            {
203
                ac = 3*k+1;
204
                ah = k;
205
206
                RE(t2) = RE(cc[ac]) + RE(cc[ac+1]);
207
                IM(t2) = IM(cc[ac]) + IM(cc[ac+1]);
208
                RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),taur);
209
                IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),taur);
210
211
                RE(ch[ah]) = RE(cc[ac-1]) + RE(t2);
212
                IM(ch[ah]) = IM(cc[ac-1]) + IM(t2);
213
214
                RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+1])), taui);
215
                IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+1])), taui);
216
217
                RE(ch[ah+l1]) = RE(c2) - IM(c3);
218
                IM(ch[ah+l1]) = IM(c2) + RE(c3);
219
                RE(ch[ah+2*l1]) = RE(c2) + IM(c3);
220
                IM(ch[ah+2*l1]) = IM(c2) - RE(c3);
221
            }
222
        } else {
223
            for (k = 0; k < l1; k++)
224
            {
225
                ac = 3*k+1;
226
                ah = k;
227
228
                RE(t2) = RE(cc[ac]) + RE(cc[ac+1]);
229
                IM(t2) = IM(cc[ac]) + IM(cc[ac+1]);
230
                RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),taur);
231
                IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),taur);
232
233
                RE(ch[ah]) = RE(cc[ac-1]) + RE(t2);
234
                IM(ch[ah]) = IM(cc[ac-1]) + IM(t2);
235
236
                RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+1])), taui);
237
                IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+1])), taui);
238
239
                RE(ch[ah+l1]) = RE(c2) + IM(c3);
240
                IM(ch[ah+l1]) = IM(c2) - RE(c3);
241
                RE(ch[ah+2*l1]) = RE(c2) - IM(c3);
242
                IM(ch[ah+2*l1]) = IM(c2) + RE(c3);
243
            }
244
        }
245
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
246
        */
247
0
#endif
248
0
    } else {
249
0
        if (isign == 1)
250
0
        {
251
0
            for (k = 0; k < l1; k++)
252
0
            {
253
0
                for (i = 0; i < ido; i++)
254
0
                {
255
0
                    ac = i + (3*k+1)*ido;
256
0
                    ah = i + k * ido;
257
258
0
                    RE(t2) = RE(cc[ac]) + RE(cc[ac+ido]);
259
0
                    RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),taur);
260
0
                    IM(t2) = IM(cc[ac]) + IM(cc[ac+ido]);
261
0
                    IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),taur);
262
263
0
                    RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2);
264
0
                    IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2);
265
266
0
                    RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+ido])), taui);
267
0
                    IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+ido])), taui);
268
269
0
                    RE(d2) = RE(c2) - IM(c3);
270
0
                    IM(d3) = IM(c2) - RE(c3);
271
0
                    RE(d3) = RE(c2) + IM(c3);
272
0
                    IM(d2) = IM(c2) + RE(c3);
273
274
0
#if 1
275
0
                    ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]),
276
0
                        IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i]));
277
0
                    ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]),
278
0
                        IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i]));
279
#else
280
                    ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]),
281
                        RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i]));
282
                    ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]),
283
                        RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i]));
284
#endif
285
0
                }
286
0
            }
287
0
        } else {
288
0
            for (k = 0; k < l1; k++)
289
0
            {
290
0
                for (i = 0; i < ido; i++)
291
0
                {
292
0
                    ac = i + (3*k+1)*ido;
293
0
                    ah = i + k * ido;
294
295
0
                    RE(t2) = RE(cc[ac]) + RE(cc[ac+ido]);
296
0
                    RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),taur);
297
0
                    IM(t2) = IM(cc[ac]) + IM(cc[ac+ido]);
298
0
                    IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),taur);
299
300
0
                    RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2);
301
0
                    IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2);
302
303
0
                    RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+ido])), taui);
304
0
                    IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+ido])), taui);
305
306
0
                    RE(d2) = RE(c2) + IM(c3);
307
0
                    IM(d3) = IM(c2) + RE(c3);
308
0
                    RE(d3) = RE(c2) - IM(c3);
309
0
                    IM(d2) = IM(c2) - RE(c3);
310
311
0
#if 1
312
0
                    ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]),
313
0
                        RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i]));
314
0
                    ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]),
315
0
                        RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i]));
316
#else
317
                    ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]),
318
                        IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i]));
319
                    ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]),
320
                        IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i]));
321
#endif
322
0
                }
323
0
            }
324
0
        }
325
0
    }
326
0
}
327
328
329
static void passf4pos(const uint16_t ido, const uint16_t l1, const complex_t *cc,
330
                      complex_t *ch, const complex_t *wa1, const complex_t *wa2,
331
                      const complex_t *wa3)
332
0
{
333
0
    uint16_t i, k, ac, ah;
334
335
0
    if (ido == 1)
336
0
    {
337
0
        for (k = 0; k < l1; k++)
338
0
        {
339
0
            complex_t t1, t2, t3, t4;
340
341
0
            ac = 4*k;
342
0
            ah = k;
343
344
0
            RE(t2) = RE(cc[ac])   + RE(cc[ac+2]);
345
0
            RE(t1) = RE(cc[ac])   - RE(cc[ac+2]);
346
0
            IM(t2) = IM(cc[ac])   + IM(cc[ac+2]);
347
0
            IM(t1) = IM(cc[ac])   - IM(cc[ac+2]);
348
0
            RE(t3) = RE(cc[ac+1]) + RE(cc[ac+3]);
349
0
            IM(t4) = RE(cc[ac+1]) - RE(cc[ac+3]);
350
0
            IM(t3) = IM(cc[ac+3]) + IM(cc[ac+1]);
351
0
            RE(t4) = IM(cc[ac+3]) - IM(cc[ac+1]);
352
353
0
            RE(ch[ah])      = RE(t2) + RE(t3);
354
0
            RE(ch[ah+2*l1]) = RE(t2) - RE(t3);
355
356
0
            IM(ch[ah])      = IM(t2) + IM(t3);
357
0
            IM(ch[ah+2*l1]) = IM(t2) - IM(t3);
358
359
0
            RE(ch[ah+l1])   = RE(t1) + RE(t4);
360
0
            RE(ch[ah+3*l1]) = RE(t1) - RE(t4);
361
362
0
            IM(ch[ah+l1])   = IM(t1) + IM(t4);
363
0
            IM(ch[ah+3*l1]) = IM(t1) - IM(t4);
364
0
        }
365
0
    } else {
366
0
        for (k = 0; k < l1; k++)
367
0
        {
368
0
            ac = 4*k*ido;
369
0
            ah = k*ido;
370
371
0
            for (i = 0; i < ido; i++)
372
0
            {
373
0
                complex_t c2, c3, c4, t1, t2, t3, t4;
374
375
0
                RE(t2) = RE(cc[ac+i]) + RE(cc[ac+i+2*ido]);
376
0
                RE(t1) = RE(cc[ac+i]) - RE(cc[ac+i+2*ido]);
377
0
                IM(t2) = IM(cc[ac+i]) + IM(cc[ac+i+2*ido]);
378
0
                IM(t1) = IM(cc[ac+i]) - IM(cc[ac+i+2*ido]);
379
0
                RE(t3) = RE(cc[ac+i+ido]) + RE(cc[ac+i+3*ido]);
380
0
                IM(t4) = RE(cc[ac+i+ido]) - RE(cc[ac+i+3*ido]);
381
0
                IM(t3) = IM(cc[ac+i+3*ido]) + IM(cc[ac+i+ido]);
382
0
                RE(t4) = IM(cc[ac+i+3*ido]) - IM(cc[ac+i+ido]);
383
384
0
                RE(c2) = RE(t1) + RE(t4);
385
0
                RE(c4) = RE(t1) - RE(t4);
386
387
0
                IM(c2) = IM(t1) + IM(t4);
388
0
                IM(c4) = IM(t1) - IM(t4);
389
390
0
                RE(ch[ah+i]) = RE(t2) + RE(t3);
391
0
                RE(c3)       = RE(t2) - RE(t3);
392
393
0
                IM(ch[ah+i]) = IM(t2) + IM(t3);
394
0
                IM(c3)       = IM(t2) - IM(t3);
395
396
0
#if 1
397
0
                ComplexMult(&IM(ch[ah+i+l1*ido]), &RE(ch[ah+i+l1*ido]),
398
0
                    IM(c2), RE(c2), RE(wa1[i]), IM(wa1[i]));
399
0
                ComplexMult(&IM(ch[ah+i+2*l1*ido]), &RE(ch[ah+i+2*l1*ido]),
400
0
                    IM(c3), RE(c3), RE(wa2[i]), IM(wa2[i]));
401
0
                ComplexMult(&IM(ch[ah+i+3*l1*ido]), &RE(ch[ah+i+3*l1*ido]),
402
0
                    IM(c4), RE(c4), RE(wa3[i]), IM(wa3[i]));
403
#else
404
                ComplexMult(&RE(ch[ah+i+l1*ido]), &IM(ch[ah+i+l1*ido]),
405
                    RE(c2), IM(c2), RE(wa1[i]), IM(wa1[i]));
406
                ComplexMult(&RE(ch[ah+i+2*l1*ido]), &IM(ch[ah+i+2*l1*ido]),
407
                    RE(c3), IM(c3), RE(wa2[i]), IM(wa2[i]));
408
                ComplexMult(&RE(ch[ah+i+3*l1*ido]), &IM(ch[ah+i+3*l1*ido]),
409
                    RE(c4), IM(c4), RE(wa3[i]), IM(wa3[i]));
410
#endif
411
0
            }
412
0
        }
413
0
    }
414
0
}
415
416
static void passf4neg(const uint16_t ido, const uint16_t l1, const complex_t *cc,
417
                      complex_t *ch, const complex_t *wa1, const complex_t *wa2,
418
                      const complex_t *wa3)
419
0
{
420
0
    uint16_t i, k, ac, ah;
421
422
0
    if (ido == 1)
423
0
    {
424
0
        for (k = 0; k < l1; k++)
425
0
        {
426
0
            complex_t t1, t2, t3, t4;
427
428
0
            ac = 4*k;
429
0
            ah = k;
430
431
0
            RE(t2) = RE(cc[ac])   + RE(cc[ac+2]);
432
0
            RE(t1) = RE(cc[ac])   - RE(cc[ac+2]);
433
0
            IM(t2) = IM(cc[ac])   + IM(cc[ac+2]);
434
0
            IM(t1) = IM(cc[ac])   - IM(cc[ac+2]);
435
0
            RE(t3) = RE(cc[ac+1]) + RE(cc[ac+3]);
436
0
            IM(t4) = RE(cc[ac+1]) - RE(cc[ac+3]);
437
0
            IM(t3) = IM(cc[ac+3]) + IM(cc[ac+1]);
438
0
            RE(t4) = IM(cc[ac+3]) - IM(cc[ac+1]);
439
440
0
            RE(ch[ah])      = RE(t2) + RE(t3);
441
0
            RE(ch[ah+2*l1]) = RE(t2) - RE(t3);
442
443
0
            IM(ch[ah])      = IM(t2) + IM(t3);
444
0
            IM(ch[ah+2*l1]) = IM(t2) - IM(t3);
445
446
0
            RE(ch[ah+l1])   = RE(t1) - RE(t4);
447
0
            RE(ch[ah+3*l1]) = RE(t1) + RE(t4);
448
449
0
            IM(ch[ah+l1])   = IM(t1) - IM(t4);
450
0
            IM(ch[ah+3*l1]) = IM(t1) + IM(t4);
451
0
        }
452
0
    } else {
453
0
        for (k = 0; k < l1; k++)
454
0
        {
455
0
            ac = 4*k*ido;
456
0
            ah = k*ido;
457
458
0
            for (i = 0; i < ido; i++)
459
0
            {
460
0
                complex_t c2, c3, c4, t1, t2, t3, t4;
461
462
0
                RE(t2) = RE(cc[ac+i]) + RE(cc[ac+i+2*ido]);
463
0
                RE(t1) = RE(cc[ac+i]) - RE(cc[ac+i+2*ido]);
464
0
                IM(t2) = IM(cc[ac+i]) + IM(cc[ac+i+2*ido]);
465
0
                IM(t1) = IM(cc[ac+i]) - IM(cc[ac+i+2*ido]);
466
0
                RE(t3) = RE(cc[ac+i+ido]) + RE(cc[ac+i+3*ido]);
467
0
                IM(t4) = RE(cc[ac+i+ido]) - RE(cc[ac+i+3*ido]);
468
0
                IM(t3) = IM(cc[ac+i+3*ido]) + IM(cc[ac+i+ido]);
469
0
                RE(t4) = IM(cc[ac+i+3*ido]) - IM(cc[ac+i+ido]);
470
471
0
                RE(c2) = RE(t1) - RE(t4);
472
0
                RE(c4) = RE(t1) + RE(t4);
473
474
0
                IM(c2) = IM(t1) - IM(t4);
475
0
                IM(c4) = IM(t1) + IM(t4);
476
477
0
                RE(ch[ah+i]) = RE(t2) + RE(t3);
478
0
                RE(c3)       = RE(t2) - RE(t3);
479
480
0
                IM(ch[ah+i]) = IM(t2) + IM(t3);
481
0
                IM(c3)       = IM(t2) - IM(t3);
482
483
0
#if 1
484
0
                ComplexMult(&RE(ch[ah+i+l1*ido]), &IM(ch[ah+i+l1*ido]),
485
0
                    RE(c2), IM(c2), RE(wa1[i]), IM(wa1[i]));
486
0
                ComplexMult(&RE(ch[ah+i+2*l1*ido]), &IM(ch[ah+i+2*l1*ido]),
487
0
                    RE(c3), IM(c3), RE(wa2[i]), IM(wa2[i]));
488
0
                ComplexMult(&RE(ch[ah+i+3*l1*ido]), &IM(ch[ah+i+3*l1*ido]),
489
0
                    RE(c4), IM(c4), RE(wa3[i]), IM(wa3[i]));
490
#else
491
                ComplexMult(&IM(ch[ah+i+l1*ido]), &RE(ch[ah+i+l1*ido]),
492
                    IM(c2), RE(c2), RE(wa1[i]), IM(wa1[i]));
493
                ComplexMult(&IM(ch[ah+i+2*l1*ido]), &RE(ch[ah+i+2*l1*ido]),
494
                    IM(c3), RE(c3), RE(wa2[i]), IM(wa2[i]));
495
                ComplexMult(&IM(ch[ah+i+3*l1*ido]), &RE(ch[ah+i+3*l1*ido]),
496
                    IM(c4), RE(c4), RE(wa3[i]), IM(wa3[i]));
497
#endif
498
0
            }
499
0
        }
500
0
    }
501
0
}
502
503
static void passf5(const uint16_t ido, const uint16_t l1, const complex_t *cc,
504
                   complex_t *ch, const complex_t *wa1, const complex_t *wa2, const complex_t *wa3,
505
                   const complex_t *wa4, const int8_t isign)
506
0
{
507
0
    static real_t tr11 = FRAC_CONST(0.309016994374947);
508
0
    static real_t ti11 = FRAC_CONST(0.951056516295154);
509
0
    static real_t tr12 = FRAC_CONST(-0.809016994374947);
510
0
    static real_t ti12 = FRAC_CONST(0.587785252292473);
511
0
    uint16_t k, ac, ah;
512
0
    complex_t c2, c3, c4, c5, t2, t3, t4, t5;
513
0
    (void)wa1;
514
0
    (void)wa2;
515
0
    (void)wa3;
516
0
    (void)wa4;
517
518
0
    if (ido == 1)
519
0
    {
520
0
        if (isign == 1)
521
0
        {
522
0
            for (k = 0; k < l1; k++)
523
0
            {
524
0
                ac = 5*k + 1;
525
0
                ah = k;
526
527
0
                RE(t2) = RE(cc[ac]) + RE(cc[ac+3]);
528
0
                IM(t2) = IM(cc[ac]) + IM(cc[ac+3]);
529
0
                RE(t3) = RE(cc[ac+1]) + RE(cc[ac+2]);
530
0
                IM(t3) = IM(cc[ac+1]) + IM(cc[ac+2]);
531
0
                RE(t4) = RE(cc[ac+1]) - RE(cc[ac+2]);
532
0
                IM(t4) = IM(cc[ac+1]) - IM(cc[ac+2]);
533
0
                RE(t5) = RE(cc[ac]) - RE(cc[ac+3]);
534
0
                IM(t5) = IM(cc[ac]) - IM(cc[ac+3]);
535
536
0
                RE(ch[ah]) = RE(cc[ac-1]) + RE(t2) + RE(t3);
537
0
                IM(ch[ah]) = IM(cc[ac-1]) + IM(t2) + IM(t3);
538
539
0
                RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),tr11) + MUL_F(RE(t3),tr12);
540
0
                IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),tr11) + MUL_F(IM(t3),tr12);
541
0
                RE(c3) = RE(cc[ac-1]) + MUL_F(RE(t2),tr12) + MUL_F(RE(t3),tr11);
542
0
                IM(c3) = IM(cc[ac-1]) + MUL_F(IM(t2),tr12) + MUL_F(IM(t3),tr11);
543
544
0
                ComplexMult(&RE(c5), &RE(c4),
545
0
                    ti11, ti12, RE(t5), RE(t4));
546
0
                ComplexMult(&IM(c5), &IM(c4),
547
0
                    ti11, ti12, IM(t5), IM(t4));
548
549
0
                RE(ch[ah+l1]) = RE(c2) - IM(c5);
550
0
                IM(ch[ah+l1]) = IM(c2) + RE(c5);
551
0
                RE(ch[ah+2*l1]) = RE(c3) - IM(c4);
552
0
                IM(ch[ah+2*l1]) = IM(c3) + RE(c4);
553
0
                RE(ch[ah+3*l1]) = RE(c3) + IM(c4);
554
0
                IM(ch[ah+3*l1]) = IM(c3) - RE(c4);
555
0
                RE(ch[ah+4*l1]) = RE(c2) + IM(c5);
556
0
                IM(ch[ah+4*l1]) = IM(c2) - RE(c5);
557
0
            }
558
0
        } else {
559
0
            for (k = 0; k < l1; k++)
560
0
            {
561
0
                ac = 5*k + 1;
562
0
                ah = k;
563
564
0
                RE(t2) = RE(cc[ac]) + RE(cc[ac+3]);
565
0
                IM(t2) = IM(cc[ac]) + IM(cc[ac+3]);
566
0
                RE(t3) = RE(cc[ac+1]) + RE(cc[ac+2]);
567
0
                IM(t3) = IM(cc[ac+1]) + IM(cc[ac+2]);
568
0
                RE(t4) = RE(cc[ac+1]) - RE(cc[ac+2]);
569
0
                IM(t4) = IM(cc[ac+1]) - IM(cc[ac+2]);
570
0
                RE(t5) = RE(cc[ac]) - RE(cc[ac+3]);
571
0
                IM(t5) = IM(cc[ac]) - IM(cc[ac+3]);
572
573
0
                RE(ch[ah]) = RE(cc[ac-1]) + RE(t2) + RE(t3);
574
0
                IM(ch[ah]) = IM(cc[ac-1]) + IM(t2) + IM(t3);
575
576
0
                RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),tr11) + MUL_F(RE(t3),tr12);
577
0
                IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),tr11) + MUL_F(IM(t3),tr12);
578
0
                RE(c3) = RE(cc[ac-1]) + MUL_F(RE(t2),tr12) + MUL_F(RE(t3),tr11);
579
0
                IM(c3) = IM(cc[ac-1]) + MUL_F(IM(t2),tr12) + MUL_F(IM(t3),tr11);
580
581
0
                ComplexMult(&RE(c4), &RE(c5),
582
0
                    ti12, ti11, RE(t5), RE(t4));
583
0
                ComplexMult(&IM(c4), &IM(c5),
584
0
                    ti12, ti11, IM(t5), IM(t4));
585
586
0
                RE(ch[ah+l1]) = RE(c2) + IM(c5);
587
0
                IM(ch[ah+l1]) = IM(c2) - RE(c5);
588
0
                RE(ch[ah+2*l1]) = RE(c3) + IM(c4);
589
0
                IM(ch[ah+2*l1]) = IM(c3) - RE(c4);
590
0
                RE(ch[ah+3*l1]) = RE(c3) - IM(c4);
591
0
                IM(ch[ah+3*l1]) = IM(c3) + RE(c4);
592
0
                RE(ch[ah+4*l1]) = RE(c2) - IM(c5);
593
0
                IM(ch[ah+4*l1]) = IM(c2) + RE(c5);
594
0
            }
595
0
        }
596
0
    } else {
597
0
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
598
        // TODO: remove this code once fuzzer proves it is totally unreahable
599
        // 5 if the biggest factor and it never repeated for supported frame
600
        // lengths; consequently `ido` should always be 1.
601
0
        __builtin_trap();
602
        /*
603
#else
604
        uint16_t i;
605
        complex_t d3, d4, d5, d2;
606
#endif
607
        if (isign == 1)
608
        {
609
            for (k = 0; k < l1; k++)
610
            {
611
                for (i = 0; i < ido; i++)
612
                {
613
                    ac = i + (k*5 + 1) * ido;
614
                    ah = i + k * ido;
615
616
                    RE(t2) = RE(cc[ac]) + RE(cc[ac+3*ido]);
617
                    IM(t2) = IM(cc[ac]) + IM(cc[ac+3*ido]);
618
                    RE(t3) = RE(cc[ac+ido]) + RE(cc[ac+2*ido]);
619
                    IM(t3) = IM(cc[ac+ido]) + IM(cc[ac+2*ido]);
620
                    RE(t4) = RE(cc[ac+ido]) - RE(cc[ac+2*ido]);
621
                    IM(t4) = IM(cc[ac+ido]) - IM(cc[ac+2*ido]);
622
                    RE(t5) = RE(cc[ac]) - RE(cc[ac+3*ido]);
623
                    IM(t5) = IM(cc[ac]) - IM(cc[ac+3*ido]);
624
625
                    RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2) + RE(t3);
626
                    IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2) + IM(t3);
627
628
                    RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),tr11) + MUL_F(RE(t3),tr12);
629
                    IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),tr11) + MUL_F(IM(t3),tr12);
630
                    RE(c3) = RE(cc[ac-ido]) + MUL_F(RE(t2),tr12) + MUL_F(RE(t3),tr11);
631
                    IM(c3) = IM(cc[ac-ido]) + MUL_F(IM(t2),tr12) + MUL_F(IM(t3),tr11);
632
633
                    ComplexMult(&RE(c5), &RE(c4),
634
                        ti11, ti12, RE(t5), RE(t4));
635
                    ComplexMult(&IM(c5), &IM(c4),
636
                        ti11, ti12, IM(t5), IM(t4));
637
638
                    IM(d2) = IM(c2) + RE(c5);
639
                    IM(d3) = IM(c3) + RE(c4);
640
                    RE(d4) = RE(c3) + IM(c4);
641
                    RE(d5) = RE(c2) + IM(c5);
642
                    RE(d2) = RE(c2) - IM(c5);
643
                    IM(d5) = IM(c2) - RE(c5);
644
                    RE(d3) = RE(c3) - IM(c4);
645
                    IM(d4) = IM(c3) - RE(c4);
646
647
#if 1
648
                    ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]),
649
                        IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i]));
650
                    ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]),
651
                        IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i]));
652
                    ComplexMult(&IM(ch[ah+3*l1*ido]), &RE(ch[ah+3*l1*ido]),
653
                        IM(d4), RE(d4), RE(wa3[i]), IM(wa3[i]));
654
                    ComplexMult(&IM(ch[ah+4*l1*ido]), &RE(ch[ah+4*l1*ido]),
655
                        IM(d5), RE(d5), RE(wa4[i]), IM(wa4[i]));
656
#else
657
                    ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]),
658
                        RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i]));
659
                    ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]),
660
                        RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i]));
661
                    ComplexMult(&RE(ch[ah+3*l1*ido]), &IM(ch[ah+3*l1*ido]),
662
                        RE(d4), IM(d4), RE(wa3[i]), IM(wa3[i]));
663
                    ComplexMult(&RE(ch[ah+4*l1*ido]), &IM(ch[ah+4*l1*ido]),
664
                        RE(d5), IM(d5), RE(wa4[i]), IM(wa4[i]));
665
#endif
666
                }
667
            }
668
        } else {
669
            for (k = 0; k < l1; k++)
670
            {
671
                for (i = 0; i < ido; i++)
672
                {
673
                    ac = i + (k*5 + 1) * ido;
674
                    ah = i + k * ido;
675
676
                    RE(t2) = RE(cc[ac]) + RE(cc[ac+3*ido]);
677
                    IM(t2) = IM(cc[ac]) + IM(cc[ac+3*ido]);
678
                    RE(t3) = RE(cc[ac+ido]) + RE(cc[ac+2*ido]);
679
                    IM(t3) = IM(cc[ac+ido]) + IM(cc[ac+2*ido]);
680
                    RE(t4) = RE(cc[ac+ido]) - RE(cc[ac+2*ido]);
681
                    IM(t4) = IM(cc[ac+ido]) - IM(cc[ac+2*ido]);
682
                    RE(t5) = RE(cc[ac]) - RE(cc[ac+3*ido]);
683
                    IM(t5) = IM(cc[ac]) - IM(cc[ac+3*ido]);
684
685
                    RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2) + RE(t3);
686
                    IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2) + IM(t3);
687
688
                    RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),tr11) + MUL_F(RE(t3),tr12);
689
                    IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),tr11) + MUL_F(IM(t3),tr12);
690
                    RE(c3) = RE(cc[ac-ido]) + MUL_F(RE(t2),tr12) + MUL_F(RE(t3),tr11);
691
                    IM(c3) = IM(cc[ac-ido]) + MUL_F(IM(t2),tr12) + MUL_F(IM(t3),tr11);
692
693
                    ComplexMult(&RE(c4), &RE(c5),
694
                        ti12, ti11, RE(t5), RE(t4));
695
                    ComplexMult(&IM(c4), &IM(c5),
696
                        ti12, ti11, IM(t5), IM(t4));
697
698
                    IM(d2) = IM(c2) - RE(c5);
699
                    IM(d3) = IM(c3) - RE(c4);
700
                    RE(d4) = RE(c3) - IM(c4);
701
                    RE(d5) = RE(c2) - IM(c5);
702
                    RE(d2) = RE(c2) + IM(c5);
703
                    IM(d5) = IM(c2) + RE(c5);
704
                    RE(d3) = RE(c3) + IM(c4);
705
                    IM(d4) = IM(c3) + RE(c4);
706
707
#if 1
708
                    ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]),
709
                        RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i]));
710
                    ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]),
711
                        RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i]));
712
                    ComplexMult(&RE(ch[ah+3*l1*ido]), &IM(ch[ah+3*l1*ido]),
713
                        RE(d4), IM(d4), RE(wa3[i]), IM(wa3[i]));
714
                    ComplexMult(&RE(ch[ah+4*l1*ido]), &IM(ch[ah+4*l1*ido]),
715
                        RE(d5), IM(d5), RE(wa4[i]), IM(wa4[i]));
716
#else
717
                    ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]),
718
                        IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i]));
719
                    ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]),
720
                        IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i]));
721
                    ComplexMult(&IM(ch[ah+3*l1*ido]), &RE(ch[ah+3*l1*ido]),
722
                        IM(d4), RE(d4), RE(wa3[i]), IM(wa3[i]));
723
                    ComplexMult(&IM(ch[ah+4*l1*ido]), &RE(ch[ah+4*l1*ido]),
724
                        IM(d5), RE(d5), RE(wa4[i]), IM(wa4[i]));
725
#endif
726
                }
727
            }
728
        }
729
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
730
        */
731
0
#endif
732
0
    }
733
0
}
734
735
736
/*----------------------------------------------------------------------
737
   cfftf1, cfftf, cfftb, cffti1, cffti. Complex FFTs.
738
  ----------------------------------------------------------------------*/
739
740
static INLINE void cfftf1pos(uint16_t n, complex_t *c, complex_t *ch,
741
                             const uint16_t *ifac, const complex_t *wa,
742
                             const int8_t isign)
743
0
{
744
0
    uint16_t i;
745
0
    uint16_t k1, l1, l2;
746
0
    uint16_t na, nf, ip, iw, ix2, ix3, ix4, ido;
747
748
0
    nf = ifac[1];
749
0
    na = 0;
750
0
    l1 = 1;
751
0
    iw = 0;
752
753
0
    for (k1 = 2; k1 <= nf+1; k1++)
754
0
    {
755
0
        ip = ifac[k1];
756
0
        l2 = ip*l1;
757
0
        ido = n / l2;
758
759
0
        switch (ip)
760
0
        {
761
0
        case 4:
762
0
            ix2 = iw + ido;
763
0
            ix3 = ix2 + ido;
764
765
0
            if (na == 0)
766
0
                passf4pos((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw], &wa[ix2], &wa[ix3]);
767
0
            else
768
0
                passf4pos((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw], &wa[ix2], &wa[ix3]);
769
770
0
            na = 1 - na;
771
0
            break;
772
0
        case 2:
773
0
            if (na == 0)
774
0
                passf2pos((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw]);
775
0
            else
776
0
                passf2pos((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw]);
777
778
0
            na = 1 - na;
779
0
            break;
780
0
        case 3:
781
0
            ix2 = iw + ido;
782
783
0
            if (na == 0)
784
0
                passf3((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw], &wa[ix2], isign);
785
0
            else
786
0
                passf3((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw], &wa[ix2], isign);
787
788
0
            na = 1 - na;
789
0
            break;
790
0
        case 5:
791
0
            ix2 = iw + ido;
792
0
            ix3 = ix2 + ido;
793
0
            ix4 = ix3 + ido;
794
795
0
            if (na == 0)
796
0
                passf5((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4], isign);
797
0
            else
798
0
                passf5((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4], isign);
799
800
0
            na = 1 - na;
801
0
            break;
802
0
        }
803
804
0
        l1 = l2;
805
0
        iw += (ip-1) * ido;
806
0
    }
807
808
0
    if (na == 0)
809
0
        return;
810
811
0
    for (i = 0; i < n; i++)
812
0
    {
813
0
        RE(c[i]) = RE(ch[i]);
814
0
        IM(c[i]) = IM(ch[i]);
815
0
    }
816
0
}
817
818
static INLINE void cfftf1neg(uint16_t n, complex_t *c, complex_t *ch,
819
                             const uint16_t *ifac, const complex_t *wa,
820
                             const int8_t isign)
821
0
{
822
0
    uint16_t i;
823
0
    uint16_t k1, l1, l2;
824
0
    uint16_t na, nf, ip, iw, ix2, ix3, ix4, ido;
825
826
0
    nf = ifac[1];
827
0
    na = 0;
828
0
    l1 = 1;
829
0
    iw = 0;
830
831
0
    for (k1 = 2; k1 <= nf+1; k1++)
832
0
    {
833
0
        ip = ifac[k1];
834
0
        l2 = ip*l1;
835
0
        ido = n / l2;
836
837
0
        switch (ip)
838
0
        {
839
0
        case 4:
840
0
            ix2 = iw + ido;
841
0
            ix3 = ix2 + ido;
842
843
0
            if (na == 0)
844
0
                passf4neg((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw], &wa[ix2], &wa[ix3]);
845
0
            else
846
0
                passf4neg((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw], &wa[ix2], &wa[ix3]);
847
848
0
            na = 1 - na;
849
0
            break;
850
0
        case 2:
851
0
            if (na == 0)
852
0
                passf2neg((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw]);
853
0
            else
854
0
                passf2neg((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw]);
855
856
0
            na = 1 - na;
857
0
            break;
858
0
        case 3:
859
0
            ix2 = iw + ido;
860
861
0
            if (na == 0)
862
0
                passf3((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw], &wa[ix2], isign);
863
0
            else
864
0
                passf3((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw], &wa[ix2], isign);
865
866
0
            na = 1 - na;
867
0
            break;
868
0
        case 5:
869
0
            ix2 = iw + ido;
870
0
            ix3 = ix2 + ido;
871
0
            ix4 = ix3 + ido;
872
873
0
            if (na == 0)
874
0
                passf5((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)c, ch, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4], isign);
875
0
            else
876
0
                passf5((const uint16_t)ido, (const uint16_t)l1, (const complex_t*)ch, c, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4], isign);
877
878
0
            na = 1 - na;
879
0
            break;
880
0
        }
881
882
0
        l1 = l2;
883
0
        iw += (ip-1) * ido;
884
0
    }
885
886
0
    if (na == 0)
887
0
        return;
888
889
0
    for (i = 0; i < n; i++)
890
0
    {
891
0
        RE(c[i]) = RE(ch[i]);
892
0
        IM(c[i]) = IM(ch[i]);
893
0
    }
894
0
}
895
896
void cfftf(cfft_info *cfft, complex_t *c)
897
0
{
898
0
    cfftf1neg(cfft->n, c, cfft->work, (const uint16_t*)cfft->ifac, (const complex_t*)cfft->tab, -1);
899
0
}
900
901
void cfftb(cfft_info *cfft, complex_t *c)
902
0
{
903
0
    cfftf1pos(cfft->n, c, cfft->work, (const uint16_t*)cfft->ifac, (const complex_t*)cfft->tab, +1);
904
0
}
905
906
static void cffti1(uint16_t n, complex_t *wa, uint16_t *ifac)
907
0
{
908
0
    static uint16_t ntryh[4] = {3, 4, 2, 5};
909
0
#ifndef FIXED_POINT
910
0
    real_t arg, argh, argld, fi;
911
0
    uint16_t ido, ipm;
912
0
    uint16_t i1, k1, l1, l2;
913
0
    uint16_t ld, ii, ip;
914
0
#endif
915
0
    uint16_t ntry = 0, i, j;
916
0
    uint16_t ib;
917
0
    uint16_t nf, nl, nq, nr;
918
919
0
    nl = n;
920
0
    nf = 0;
921
0
    j = 0;
922
923
0
startloop:
924
0
    j++;
925
926
0
    if (j <= 4)
927
0
        ntry = ntryh[j-1];
928
0
    else
929
0
        ntry += 2;
930
931
0
    do
932
0
    {
933
0
        nq = nl / ntry;
934
0
        nr = nl - ntry*nq;
935
936
0
        if (nr != 0)
937
0
            goto startloop;
938
939
0
        nf++;
940
0
        ifac[nf+1] = ntry;
941
0
        nl = nq;
942
943
0
        if (ntry == 2 && nf != 1)
944
0
        {
945
0
            for (i = 2; i <= nf; i++)
946
0
            {
947
0
                ib = nf - i + 2;
948
0
                ifac[ib+1] = ifac[ib];
949
0
            }
950
0
            ifac[2] = 2;
951
0
        }
952
0
    } while (nl != 1);
953
954
0
    ifac[0] = n;
955
0
    ifac[1] = nf;
956
957
0
#ifndef FIXED_POINT
958
0
    argh = (real_t)2.0*(real_t)M_PI / (real_t)n;
959
0
    i = 0;
960
0
    l1 = 1;
961
962
0
    for (k1 = 1; k1 <= nf; k1++)
963
0
    {
964
0
        ip = ifac[k1+1];
965
0
        ld = 0;
966
0
        l2 = l1*ip;
967
0
        ido = n / l2;
968
0
        ipm = ip - 1;
969
970
0
        for (j = 0; j < ipm; j++)
971
0
        {
972
0
            i1 = i;
973
0
            RE(wa[i]) = 1.0;
974
0
            IM(wa[i]) = 0.0;
975
0
            ld += l1;
976
0
            fi = 0;
977
0
            argld = ld*argh;
978
979
0
            for (ii = 0; ii < ido; ii++)
980
0
            {
981
0
                i++;
982
0
                fi++;
983
0
                arg = fi * argld;
984
0
                RE(wa[i]) = (real_t)cos(arg);
985
0
#if 1
986
0
                IM(wa[i]) = (real_t)sin(arg);
987
#else
988
                IM(wa[i]) = (real_t)-sin(arg);
989
#endif
990
0
            }
991
992
0
            if (ip > 5)
993
0
            {
994
0
                RE(wa[i1]) = RE(wa[i]);
995
0
                IM(wa[i1]) = IM(wa[i]);
996
0
            }
997
0
        }
998
0
        l1 = l2;
999
0
    }
1000
#else  // FIXED_POINT
1001
    (void)wa;  /* whoa! does it work for FIXED_POINT? */
1002
#endif
1003
0
}
1004
1005
cfft_info *cffti(uint16_t n)
1006
0
{
1007
0
    cfft_info *cfft = (cfft_info*)faad_malloc(sizeof(cfft_info));
1008
1009
0
    cfft->n = n;
1010
0
    cfft->work = (complex_t*)faad_malloc(n*sizeof(complex_t));
1011
1012
0
#ifndef FIXED_POINT
1013
0
    cfft->tab = (complex_t*)faad_malloc(n*sizeof(complex_t));
1014
1015
0
    cffti1(n, cfft->tab, cfft->ifac);
1016
#else
1017
    cffti1(n, NULL, cfft->ifac);
1018
1019
    switch (n)
1020
    {
1021
    case 64: cfft->tab = (complex_t*)cfft_tab_64; break;
1022
    case 512: cfft->tab = (complex_t*)cfft_tab_512; break;
1023
#ifdef LD_DEC
1024
    case 256: cfft->tab = (complex_t*)cfft_tab_256; break;
1025
#endif
1026
1027
#ifdef ALLOW_SMALL_FRAMELENGTH
1028
    case 60: cfft->tab = (complex_t*)cfft_tab_60; break;
1029
    case 480: cfft->tab = (complex_t*)cfft_tab_480; break;
1030
#ifdef LD_DEC
1031
    case 240: cfft->tab = (complex_t*)cfft_tab_240; break;
1032
#endif
1033
#endif
1034
    case 128: cfft->tab = (complex_t*)cfft_tab_128; break;
1035
    }
1036
#endif
1037
1038
0
    return cfft;
1039
0
}
1040
1041
void cfftu(cfft_info *cfft)
1042
0
{
1043
0
    if (cfft->work) faad_free(cfft->work);
1044
0
#ifndef FIXED_POINT
1045
0
    if (cfft->tab) faad_free(cfft->tab);
1046
0
#endif
1047
1048
0
    if (cfft) faad_free(cfft);
1049
0
}
1050