annotate fft.c @ 823:5344ecb2c677 libavcodec

put MIN/MAX under ifndef MAX/MIN
author michaelni
date Fri, 01 Nov 2002 20:37:10 +0000
parents 6f5e87957bcb
children 6d8b45263d6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
1 /*
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
2 * FFT/IFFT transforms
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
4 *
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
9 *
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
14 *
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
18 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
19 #include "dsputil.h"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
20
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
21 /**
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
22 * The size of the FFT is 2^nbits. If inverse is TRUE, inverse FFT is
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
23 * done
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
24 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
25 int fft_init(FFTContext *s, int nbits, int inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
26 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
27 int i, j, m, n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
28 float alpha, c1, s1, s2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
29
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
30 s->nbits = nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
31 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
32
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
33 s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
34 if (!s->exptab)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
35 goto fail;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
36 s->revtab = av_malloc(n * sizeof(uint16_t));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
37 if (!s->revtab)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
38 goto fail;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
39 s->inverse = inverse;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
40
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
41 s2 = inverse ? 1.0 : -1.0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
42
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
43 for(i=0;i<(n/2);i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
44 alpha = 2 * M_PI * (float)i / (float)n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
45 c1 = cos(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
46 s1 = sin(alpha) * s2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
47 s->exptab[i].re = c1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
48 s->exptab[i].im = s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
49 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
50 s->fft_calc = fft_calc_c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
51 s->exptab1 = NULL;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
52
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
53 /* compute constant table for HAVE_SSE version */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
54 #if defined(HAVE_MMX) && 0
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
55 if (mm_flags & MM_SSE) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
56 int np, nblocks, np2, l;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
57 FFTComplex *q;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
58
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
59 np = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
60 nblocks = np >> 3;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
61 np2 = np >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
62 s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
63 if (!s->exptab1)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
64 goto fail;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
65 q = s->exptab1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
66 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
67 for(l = 0; l < np2; l += 2 * nblocks) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
68 *q++ = s->exptab[l];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
69 *q++ = s->exptab[l + nblocks];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
70
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
71 q->re = -s->exptab[l].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
72 q->im = s->exptab[l].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
73 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
74 q->re = -s->exptab[l + nblocks].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
75 q->im = s->exptab[l + nblocks].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
76 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
77 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
78 nblocks = nblocks >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
79 } while (nblocks != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
80 av_freep(&s->exptab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
81 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
82 #endif
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
83
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
84 /* compute bit reverse table */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
85
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
86 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
87 m=0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
88 for(j=0;j<nbits;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
89 m |= ((i >> j) & 1) << (nbits-j-1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
90 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
91 s->revtab[i]=m;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
92 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
93 return 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
94 fail:
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
95 av_freep(&s->revtab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
96 av_freep(&s->exptab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
97 av_freep(&s->exptab1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
98 return -1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
99 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
100
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
101 /* butter fly op */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
102 #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
103 {\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
104 FFTSample ax, ay, bx, by;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
105 bx=pre1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
106 by=pim1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
107 ax=qre1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
108 ay=qim1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
109 pre = (bx + ax);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
110 pim = (by + ay);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
111 qre = (bx - ax);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
112 qim = (by - ay);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
113 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
114
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
115 #define MUL16(a,b) ((a) * (b))
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
116
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
117 #define CMUL(pre, pim, are, aim, bre, bim) \
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
118 {\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
119 pre = (MUL16(are, bre) - MUL16(aim, bim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
120 pim = (MUL16(are, bim) + MUL16(bre, aim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
121 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
122
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
123 /**
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
124 * Do a complex FFT with the parameters defined in fft_init(). The
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
125 * input data must be permuted before with s->revtab table. No
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
126 * 1.0/sqrt(n) normalization is done.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
127 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
128 void fft_calc_c(FFTContext *s, FFTComplex *z)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
129 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
130 int ln = s->nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
131 int j, np, np2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
132 int nblocks, nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
133 register FFTComplex *p, *q;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
134 FFTComplex *exptab = s->exptab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
135 int l;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
136 FFTSample tmp_re, tmp_im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
137
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
138 np = 1 << ln;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
139
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
140 /* pass 0 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
141
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
142 p=&z[0];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
143 j=(np >> 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
144 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
145 BF(p[0].re, p[0].im, p[1].re, p[1].im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
146 p[0].re, p[0].im, p[1].re, p[1].im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
147 p+=2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
148 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
149
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
150 /* pass 1 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
151
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
152
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
153 p=&z[0];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
154 j=np >> 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
155 if (s->inverse) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
156 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
157 BF(p[0].re, p[0].im, p[2].re, p[2].im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
158 p[0].re, p[0].im, p[2].re, p[2].im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
159 BF(p[1].re, p[1].im, p[3].re, p[3].im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
160 p[1].re, p[1].im, -p[3].im, p[3].re);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
161 p+=4;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
162 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
163 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
164 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
165 BF(p[0].re, p[0].im, p[2].re, p[2].im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
166 p[0].re, p[0].im, p[2].re, p[2].im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
167 BF(p[1].re, p[1].im, p[3].re, p[3].im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
168 p[1].re, p[1].im, p[3].im, -p[3].re);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
169 p+=4;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
170 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
171 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
172 /* pass 2 .. ln-1 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
173
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
174 nblocks = np >> 3;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
175 nloops = 1 << 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
176 np2 = np >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
177 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
178 p = z;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
179 q = z + nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
180 for (j = 0; j < nblocks; ++j) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
181 BF(p->re, p->im, q->re, q->im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
182 p->re, p->im, q->re, q->im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
183
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
184 p++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
185 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
186 for(l = nblocks; l < np2; l += nblocks) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
187 CMUL(tmp_re, tmp_im, exptab[l].re, exptab[l].im, q->re, q->im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
188 BF(p->re, p->im, q->re, q->im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
189 p->re, p->im, tmp_re, tmp_im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
190 p++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
191 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
192 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
193
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
194 p += nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
195 q += nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
196 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
197 nblocks = nblocks >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
198 nloops = nloops << 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
199 } while (nblocks != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
200 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
201
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
202 /**
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
203 * Do the permutation needed BEFORE calling fft_calc()
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
204 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
205 void fft_permute(FFTContext *s, FFTComplex *z)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
206 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
207 int j, k, np;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
208 FFTComplex tmp;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
209 const uint16_t *revtab = s->revtab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
210
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
211 /* reverse */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
212 np = 1 << s->nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
213 for(j=0;j<np;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
214 k = revtab[j];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
215 if (k < j) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
216 tmp = z[k];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
217 z[k] = z[j];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
218 z[j] = tmp;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
219 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
220 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
221 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
222
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
223 void fft_end(FFTContext *s)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
224 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
225 av_freep(&s->revtab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
226 av_freep(&s->exptab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
227 av_freep(&s->exptab1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
228 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
229