annotate fft.c @ 6608:29a73b30ded0 libavcodec

normalize signs
author michael
date Wed, 16 Apr 2008 14:46:25 +0000
parents 978911ca654f
children fc843d00867c
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 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3746
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3746
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3746
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3746
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3746
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
16 *
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3746
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
20 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
21
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
22 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
23 * @file fft.c
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
24 * FFT/IFFT transforms.
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
25 */
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
26
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
27 #include "dsputil.h"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
28
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 * The size of the FFT is 2^nbits. If inverse is TRUE, inverse FFT is
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
31 * done
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
32 */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
33 int ff_fft_init(FFTContext *s, int nbits, int inverse)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
34 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
35 int i, j, m, n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
36 float alpha, c1, s1, s2;
6503
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
37 int shuffle = 0;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
38 int av_unused has_vectors;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
39
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
40 s->nbits = nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
41 n = 1 << nbits;
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 s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
44 if (!s->exptab)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
45 goto fail;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
46 s->revtab = av_malloc(n * sizeof(uint16_t));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
47 if (!s->revtab)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
48 goto fail;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
49 s->inverse = inverse;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
50
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
51 s2 = inverse ? 1.0 : -1.0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
52
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
53 for(i=0;i<(n/2);i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
54 alpha = 2 * M_PI * (float)i / (float)n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
55 c1 = cos(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
56 s1 = sin(alpha) * s2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
57 s->exptab[i].re = c1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
58 s->exptab[i].im = s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
59 }
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
60 s->fft_calc = ff_fft_calc_c;
3555
5ea82888103e 3dnow2 implementation of imdct.
lorenm
parents: 3383
diff changeset
61 s->imdct_calc = ff_imdct_calc;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
62 s->exptab1 = NULL;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
63
6503
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
64 #ifdef HAVE_MMX
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
65 has_vectors = mm_support();
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
66 shuffle = 1;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
67 if (has_vectors & MM_3DNOWEXT) {
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
68 /* 3DNowEx for K7/K8 */
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
69 s->imdct_calc = ff_imdct_calc_3dn2;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
70 s->fft_calc = ff_fft_calc_3dn2;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
71 } else if (has_vectors & MM_3DNOW) {
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
72 /* 3DNow! for K6-2/3 */
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
73 s->fft_calc = ff_fft_calc_3dn;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
74 } else if (has_vectors & MM_SSE) {
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
75 /* SSE for P3/P4 */
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
76 s->imdct_calc = ff_imdct_calc_sse;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
77 s->fft_calc = ff_fft_calc_sse;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
78 } else {
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
79 shuffle = 0;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
80 }
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
81 #elif defined HAVE_ALTIVEC && !defined ALTIVEC_USE_REFERENCE_C_CODE
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
82 has_vectors = mm_support();
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
83 if (has_vectors & MM_ALTIVEC) {
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
84 s->fft_calc = ff_fft_calc_altivec;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
85 shuffle = 1;
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
86 }
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
87 #endif
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
88
6503
311c95dddb16 clean up FFT SIMD selection
mru
parents: 3947
diff changeset
89 /* compute constant table for HAVE_SSE version */
6504
978911ca654f indentation
mru
parents: 6503
diff changeset
90 if (shuffle) {
978911ca654f indentation
mru
parents: 6503
diff changeset
91 int np, nblocks, np2, l;
978911ca654f indentation
mru
parents: 6503
diff changeset
92 FFTComplex *q;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
93
6504
978911ca654f indentation
mru
parents: 6503
diff changeset
94 np = 1 << nbits;
978911ca654f indentation
mru
parents: 6503
diff changeset
95 nblocks = np >> 3;
978911ca654f indentation
mru
parents: 6503
diff changeset
96 np2 = np >> 1;
978911ca654f indentation
mru
parents: 6503
diff changeset
97 s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
978911ca654f indentation
mru
parents: 6503
diff changeset
98 if (!s->exptab1)
978911ca654f indentation
mru
parents: 6503
diff changeset
99 goto fail;
978911ca654f indentation
mru
parents: 6503
diff changeset
100 q = s->exptab1;
978911ca654f indentation
mru
parents: 6503
diff changeset
101 do {
978911ca654f indentation
mru
parents: 6503
diff changeset
102 for(l = 0; l < np2; l += 2 * nblocks) {
978911ca654f indentation
mru
parents: 6503
diff changeset
103 *q++ = s->exptab[l];
978911ca654f indentation
mru
parents: 6503
diff changeset
104 *q++ = s->exptab[l + nblocks];
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
105
6504
978911ca654f indentation
mru
parents: 6503
diff changeset
106 q->re = -s->exptab[l].im;
978911ca654f indentation
mru
parents: 6503
diff changeset
107 q->im = s->exptab[l].re;
978911ca654f indentation
mru
parents: 6503
diff changeset
108 q++;
978911ca654f indentation
mru
parents: 6503
diff changeset
109 q->re = -s->exptab[l + nblocks].im;
978911ca654f indentation
mru
parents: 6503
diff changeset
110 q->im = s->exptab[l + nblocks].re;
978911ca654f indentation
mru
parents: 6503
diff changeset
111 q++;
978911ca654f indentation
mru
parents: 6503
diff changeset
112 }
978911ca654f indentation
mru
parents: 6503
diff changeset
113 nblocks = nblocks >> 1;
978911ca654f indentation
mru
parents: 6503
diff changeset
114 } while (nblocks != 0);
978911ca654f indentation
mru
parents: 6503
diff changeset
115 av_freep(&s->exptab);
978911ca654f indentation
mru
parents: 6503
diff changeset
116 }
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
117
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
118 /* compute bit reverse table */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
119
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
120 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
121 m=0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
122 for(j=0;j<nbits;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
123 m |= ((i >> j) & 1) << (nbits-j-1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
124 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
125 s->revtab[i]=m;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
126 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
127 return 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
128 fail:
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
129 av_freep(&s->revtab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
130 av_freep(&s->exptab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
131 av_freep(&s->exptab1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
132 return -1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
133 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
134
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
135 /* butter fly op */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
136 #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
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 FFTSample ax, ay, bx, by;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
139 bx=pre1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
140 by=pim1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
141 ax=qre1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
142 ay=qim1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
143 pre = (bx + ax);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
144 pim = (by + ay);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
145 qre = (bx - ax);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
146 qim = (by - ay);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
147 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
148
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
149 #define MUL16(a,b) ((a) * (b))
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
150
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
151 #define CMUL(pre, pim, are, aim, bre, bim) \
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 pre = (MUL16(are, bre) - MUL16(aim, bim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
154 pim = (MUL16(are, bim) + MUL16(bre, aim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
155 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
156
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
157 /**
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
158 * Do a complex FFT with the parameters defined in ff_fft_init(). The
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
159 * input data must be permuted before with s->revtab table. No
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
160 * 1.0/sqrt(n) normalization is done.
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
161 */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
162 void ff_fft_calc_c(FFTContext *s, FFTComplex *z)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
163 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
164 int ln = s->nbits;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
165 int j, np, np2;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
166 int nblocks, nloops;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
167 register FFTComplex *p, *q;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
168 FFTComplex *exptab = s->exptab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
169 int l;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
170 FFTSample tmp_re, tmp_im;
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 np = 1 << ln;
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 /* pass 0 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
175
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
176 p=&z[0];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
177 j=(np >> 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
178 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
179 BF(p[0].re, p[0].im, p[1].re, p[1].im,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
180 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
181 p+=2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
182 } while (--j != 0);
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 /* pass 1 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
185
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
186
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
187 p=&z[0];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
188 j=np >> 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
189 if (s->inverse) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
190 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
191 BF(p[0].re, p[0].im, p[2].re, p[2].im,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
192 p[0].re, p[0].im, p[2].re, p[2].im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
193 BF(p[1].re, p[1].im, p[3].re, p[3].im,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
194 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
195 p+=4;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
196 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
197 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
198 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
199 BF(p[0].re, p[0].im, p[2].re, p[2].im,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
200 p[0].re, p[0].im, p[2].re, p[2].im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
201 BF(p[1].re, p[1].im, p[3].re, p[3].im,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
202 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
203 p+=4;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
204 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
205 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
206 /* pass 2 .. ln-1 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
207
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
208 nblocks = np >> 3;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
209 nloops = 1 << 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
210 np2 = np >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
211 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
212 p = z;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
213 q = z + nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
214 for (j = 0; j < nblocks; ++j) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
215 BF(p->re, p->im, q->re, q->im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
216 p->re, p->im, q->re, q->im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
217
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
218 p++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
219 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
220 for(l = nblocks; l < np2; l += nblocks) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
221 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
222 BF(p->re, p->im, q->re, q->im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
223 p->re, p->im, tmp_re, tmp_im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
224 p++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
225 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
226 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
227
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
228 p += nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
229 q += nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
230 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
231 nblocks = nblocks >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
232 nloops = nloops << 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
233 } while (nblocks != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
234 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
235
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
236 /**
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
237 * Do the permutation needed BEFORE calling ff_fft_calc()
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
238 */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
239 void ff_fft_permute(FFTContext *s, FFTComplex *z)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
240 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
241 int j, k, np;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
242 FFTComplex tmp;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
243 const uint16_t *revtab = s->revtab;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
244
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
245 /* reverse */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
246 np = 1 << s->nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
247 for(j=0;j<np;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
248 k = revtab[j];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
249 if (k < j) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
250 tmp = z[k];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
251 z[k] = z[j];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
252 z[j] = tmp;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
253 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
254 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
255 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
256
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
257 void ff_fft_end(FFTContext *s)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
258 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
259 av_freep(&s->revtab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
260 av_freep(&s->exptab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
261 av_freep(&s->exptab1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
262 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
263