annotate fft.c @ 3554:ce5554dd79ce libavcodec

Cosmetics: 2->4 spaces and some braces
author lu_zero
date Sun, 06 Aug 2006 23:15:32 +0000
parents 769d68b12d26
children 5ea82888103e
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
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
17 * 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
18 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
19
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
20 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
21 * @file fft.c
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
22 * FFT/IFFT transforms.
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
23 */
1e39f273ecd6 per file doxy
michaelni
parents: 1009
diff changeset
24
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
25 #include "dsputil.h"
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 /**
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
28 * 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
29 * done
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
30 */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
31 int ff_fft_init(FFTContext *s, int nbits, int inverse)
781
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 int i, j, m, n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
34 float alpha, c1, s1, s2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
35
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
36 s->nbits = nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
37 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
38
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
39 s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
40 if (!s->exptab)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
41 goto fail;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
42 s->revtab = av_malloc(n * sizeof(uint16_t));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
43 if (!s->revtab)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
44 goto fail;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
45 s->inverse = inverse;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
46
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
47 s2 = inverse ? 1.0 : -1.0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
48
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
49 for(i=0;i<(n/2);i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
50 alpha = 2 * M_PI * (float)i / (float)n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
51 c1 = cos(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
52 s1 = sin(alpha) * s2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
53 s->exptab[i].re = c1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
54 s->exptab[i].im = s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
55 }
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
56 s->fft_calc = ff_fft_calc_c;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
57 s->exptab1 = NULL;
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 /* compute constant table for HAVE_SSE version */
3175
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
60 #if (defined(HAVE_MMX) && (defined(HAVE_BUILTIN_VECTOR) || defined(HAVE_MM3DNOW))) || defined(HAVE_ALTIVEC)
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
61 {
1009
3b7cc8e4b83f AltiVec perf (take 2), plus a couple AltiVec functions by (Romain Dolbeau <dolbeau at irisa dot fr>)
michaelni
parents: 995
diff changeset
62 int has_vectors = 0;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
63
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
64 #if defined(HAVE_MMX)
3383
769d68b12d26 ff_fft_init now double checks that the system has mm3dnow.h before
banan
parents: 3175
diff changeset
65 #ifdef HAVE_MM3DNOW
3175
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
66 has_vectors = mm_support() & (MM_3DNOW | MM_3DNOWEXT | MM_SSE | MM_SSE2);
3383
769d68b12d26 ff_fft_init now double checks that the system has mm3dnow.h before
banan
parents: 3175
diff changeset
67 #else
769d68b12d26 ff_fft_init now double checks that the system has mm3dnow.h before
banan
parents: 3175
diff changeset
68 has_vectors = mm_support() & (MM_SSE | MM_SSE2);
769d68b12d26 ff_fft_init now double checks that the system has mm3dnow.h before
banan
parents: 3175
diff changeset
69 #endif
995
edc10966b081 altivec jumbo patch by (Romain Dolbeau <dolbeaur at club-internet dot fr>)
michaelni
parents: 975
diff changeset
70 #endif
1009
3b7cc8e4b83f AltiVec perf (take 2), plus a couple AltiVec functions by (Romain Dolbeau <dolbeau at irisa dot fr>)
michaelni
parents: 995
diff changeset
71 #if defined(HAVE_ALTIVEC) && !defined(ALTIVEC_USE_REFERENCE_C_CODE)
995
edc10966b081 altivec jumbo patch by (Romain Dolbeau <dolbeaur at club-internet dot fr>)
michaelni
parents: 975
diff changeset
72 has_vectors = mm_support() & MM_ALTIVEC;
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
73 #endif
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
74 if (has_vectors) {
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
75 int np, nblocks, np2, l;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
76 FFTComplex *q;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
77
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
78 np = 1 << nbits;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
79 nblocks = np >> 3;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
80 np2 = np >> 1;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
81 s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
82 if (!s->exptab1)
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
83 goto fail;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
84 q = s->exptab1;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
85 do {
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
86 for(l = 0; l < np2; l += 2 * nblocks) {
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
87 *q++ = s->exptab[l];
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
88 *q++ = s->exptab[l + nblocks];
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
89
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
90 q->re = -s->exptab[l].im;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
91 q->im = s->exptab[l].re;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
92 q++;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
93 q->re = -s->exptab[l + nblocks].im;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
94 q->im = s->exptab[l + nblocks].re;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
95 q++;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
96 }
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
97 nblocks = nblocks >> 1;
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
98 } while (nblocks != 0);
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
99 av_freep(&s->exptab);
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
100 #if defined(HAVE_MMX)
3175
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
101 #ifdef HAVE_MM3DNOW
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
102 if (has_vectors & MM_3DNOWEXT)
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
103 /* 3DNowEx for Athlon(XP) */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
104 s->fft_calc = ff_fft_calc_3dn2;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
105 else if (has_vectors & MM_3DNOW)
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
106 /* 3DNow! for K6-2/3 */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
107 s->fft_calc = ff_fft_calc_3dn;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
108 #endif
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
109 #ifdef HAVE_BUILTIN_VECTOR
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
110 if (has_vectors & MM_SSE2)
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
111 /* SSE for P4/K8 */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
112 s->fft_calc = ff_fft_calc_sse;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
113 else if ((has_vectors & MM_SSE) &&
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
114 s->fft_calc == ff_fft_calc_c)
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
115 /* SSE for P3 */
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
116 s->fft_calc = ff_fft_calc_sse;
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
117 #endif
c20c181e0eca 3DNow! & Extended 3DNow! versions of FFT
corey
parents: 3036
diff changeset
118 #else /* HAVE_MMX */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
119 s->fft_calc = ff_fft_calc_altivec;
975
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
120 #endif
e05d525505c5 fft altivec by Romain Dolbeau - simplified patch, test it on PPC with fft-test and wma decoding
bellard
parents: 971
diff changeset
121 }
781
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 #endif
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 /* compute bit reverse table */
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 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
128 m=0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
129 for(j=0;j<nbits;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
130 m |= ((i >> j) & 1) << (nbits-j-1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
131 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
132 s->revtab[i]=m;
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 return 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
135 fail:
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
136 av_freep(&s->revtab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
137 av_freep(&s->exptab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
138 av_freep(&s->exptab1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
139 return -1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
140 }
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 /* butter fly op */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
143 #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
144 {\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
145 FFTSample ax, ay, bx, by;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
146 bx=pre1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
147 by=pim1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
148 ax=qre1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
149 ay=qim1;\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
150 pre = (bx + ax);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
151 pim = (by + ay);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
152 qre = (bx - ax);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
153 qim = (by - ay);\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
154 }
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 #define MUL16(a,b) ((a) * (b))
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
157
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
158 #define CMUL(pre, pim, are, aim, bre, bim) \
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
159 {\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
160 pre = (MUL16(are, bre) - MUL16(aim, bim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
161 pim = (MUL16(are, bim) + MUL16(bre, aim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
162 }
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 /**
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
165 * 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
166 * input data must be permuted before with s->revtab table. No
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
167 * 1.0/sqrt(n) normalization is done.
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
168 */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
169 void ff_fft_calc_c(FFTContext *s, FFTComplex *z)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
170 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
171 int ln = s->nbits;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
172 int j, np, np2;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
173 int nblocks, nloops;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
174 register FFTComplex *p, *q;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
175 FFTComplex *exptab = s->exptab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
176 int l;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
177 FFTSample tmp_re, tmp_im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
178
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
179 np = 1 << ln;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
180
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
181 /* pass 0 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
182
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
183 p=&z[0];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
184 j=(np >> 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
185 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
186 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
187 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
188 p+=2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
189 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
190
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
191 /* pass 1 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
192
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
193
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
194 p=&z[0];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
195 j=np >> 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
196 if (s->inverse) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
197 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
198 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
199 p[0].re, p[0].im, p[2].re, p[2].im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
200 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
201 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
202 p+=4;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
203 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
204 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
205 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
206 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
207 p[0].re, p[0].im, p[2].re, p[2].im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
208 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
209 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
210 p+=4;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
211 } while (--j != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
212 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
213 /* pass 2 .. ln-1 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
214
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
215 nblocks = np >> 3;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
216 nloops = 1 << 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
217 np2 = np >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
218 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
219 p = z;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
220 q = z + nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
221 for (j = 0; j < nblocks; ++j) {
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, q->re, q->im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
224
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
225 p++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
226 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
227 for(l = nblocks; l < np2; l += nblocks) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
228 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
229 BF(p->re, p->im, q->re, q->im,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
230 p->re, p->im, tmp_re, tmp_im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
231 p++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
232 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
233 }
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 p += nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
236 q += nloops;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
237 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
238 nblocks = nblocks >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
239 nloops = nloops << 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
240 } while (nblocks != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
241 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
242
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
243 /**
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
244 * Do the permutation needed BEFORE calling ff_fft_calc()
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
245 */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
246 void ff_fft_permute(FFTContext *s, FFTComplex *z)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
247 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
248 int j, k, np;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
249 FFTComplex tmp;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
250 const uint16_t *revtab = s->revtab;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1879
diff changeset
251
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
252 /* reverse */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
253 np = 1 << s->nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
254 for(j=0;j<np;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
255 k = revtab[j];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
256 if (k < j) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
257 tmp = z[k];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
258 z[k] = z[j];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
259 z[j] = tmp;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
260 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
261 }
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
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
264 void ff_fft_end(FFTContext *s)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
265 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
266 av_freep(&s->revtab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
267 av_freep(&s->exptab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
268 av_freep(&s->exptab1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
269 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
270