Mercurial > libavcodec.hg
annotate fft-test.c @ 11677:ed3d232c9d31 libavcodec
10l: The SBR refactor requires the use of 2 independent output X buffers.
author | alexc |
---|---|
date | Mon, 03 May 2010 19:21:35 +0000 |
parents | 7dd2a45249a9 |
children | 2e96cab6ecde |
rev | line source |
---|---|
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
1 /* |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
2 * (c) 2002 Fabrice Bellard |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
3 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
4 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
5 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
8 * 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:
3699
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
10 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
14 * Lesser General Public License for more details. |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
15 * |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
16 * 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:
3699
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
19 */ |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
20 |
1106 | 21 /** |
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11583
diff
changeset
|
22 * @file |
1106 | 23 * FFT and MDCT tests. |
24 */ | |
25 | |
11390 | 26 #include "libavutil/mathematics.h" |
9199
ea0e5e9a520f
Replace random() usage in test programs by av_lfg_*().
diego
parents:
8718
diff
changeset
|
27 #include "libavutil/lfg.h" |
11390 | 28 #include "libavutil/log.h" |
29 #include "fft.h" | |
781 | 30 #include <math.h> |
980 | 31 #include <unistd.h> |
781 | 32 #include <sys/time.h> |
5118
3b190bc34546
Add some #includes to allow compilation without HAVE_AV_CONFIG_H.
diego
parents:
4760
diff
changeset
|
33 #include <stdlib.h> |
3b190bc34546
Add some #includes to allow compilation without HAVE_AV_CONFIG_H.
diego
parents:
4760
diff
changeset
|
34 #include <string.h> |
781 | 35 |
4760 | 36 #undef exit |
37 | |
781 | 38 /* reference fft */ |
39 | |
40 #define MUL16(a,b) ((a) * (b)) | |
41 | |
42 #define CMAC(pre, pim, are, aim, bre, bim) \ | |
43 {\ | |
44 pre += (MUL16(are, bre) - MUL16(aim, bim));\ | |
45 pim += (MUL16(are, bim) + MUL16(bre, aim));\ | |
46 } | |
47 | |
48 FFTComplex *exptab; | |
49 | |
9295
b225f51903af
Mark non-exported functions in test and example programs as static.
diego
parents:
9199
diff
changeset
|
50 static void fft_ref_init(int nbits, int inverse) |
781 | 51 { |
52 int n, i; | |
5418
95234f2e0bdd
make the reference code use double instead of float where it is easy
michael
parents:
5417
diff
changeset
|
53 double c1, s1, alpha; |
781 | 54 |
55 n = 1 << nbits; | |
56 exptab = av_malloc((n / 2) * sizeof(FFTComplex)); | |
57 | |
10807 | 58 for (i = 0; i < (n/2); i++) { |
781 | 59 alpha = 2 * M_PI * (float)i / (float)n; |
60 c1 = cos(alpha); | |
61 s1 = sin(alpha); | |
62 if (!inverse) | |
63 s1 = -s1; | |
64 exptab[i].re = c1; | |
65 exptab[i].im = s1; | |
66 } | |
67 } | |
68 | |
9295
b225f51903af
Mark non-exported functions in test and example programs as static.
diego
parents:
9199
diff
changeset
|
69 static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) |
781 | 70 { |
71 int n, i, j, k, n2; | |
5418
95234f2e0bdd
make the reference code use double instead of float where it is easy
michael
parents:
5417
diff
changeset
|
72 double tmp_re, tmp_im, s, c; |
781 | 73 FFTComplex *q; |
74 | |
75 n = 1 << nbits; | |
76 n2 = n >> 1; | |
10807 | 77 for (i = 0; i < n; i++) { |
781 | 78 tmp_re = 0; |
79 tmp_im = 0; | |
80 q = tab; | |
10807 | 81 for (j = 0; j < n; j++) { |
781 | 82 k = (i * j) & (n - 1); |
83 if (k >= n2) { | |
84 c = -exptab[k - n2].re; | |
85 s = -exptab[k - n2].im; | |
86 } else { | |
87 c = exptab[k].re; | |
88 s = exptab[k].im; | |
89 } | |
90 CMAC(tmp_re, tmp_im, c, s, q->re, q->im); | |
91 q++; | |
92 } | |
93 tabr[i].re = tmp_re; | |
94 tabr[i].im = tmp_im; | |
95 } | |
96 } | |
97 | |
9295
b225f51903af
Mark non-exported functions in test and example programs as static.
diego
parents:
9199
diff
changeset
|
98 static void imdct_ref(float *out, float *in, int nbits) |
781 | 99 { |
5442 | 100 int n = 1<<nbits; |
781 | 101 int k, i, a; |
5418
95234f2e0bdd
make the reference code use double instead of float where it is easy
michael
parents:
5417
diff
changeset
|
102 double sum, f; |
781 | 103 |
10807 | 104 for (i = 0; i < n; i++) { |
781 | 105 sum = 0; |
10807 | 106 for (k = 0; k < n/2; k++) { |
781 | 107 a = (2 * i + 1 + (n / 2)) * (2 * k + 1); |
108 f = cos(M_PI * a / (double)(2 * n)); | |
109 sum += f * in[k]; | |
110 } | |
111 out[i] = -sum; | |
112 } | |
113 } | |
114 | |
115 /* NOTE: no normalisation by 1 / N is done */ | |
9295
b225f51903af
Mark non-exported functions in test and example programs as static.
diego
parents:
9199
diff
changeset
|
116 static void mdct_ref(float *output, float *input, int nbits) |
781 | 117 { |
5442 | 118 int n = 1<<nbits; |
781 | 119 int k, i; |
5418
95234f2e0bdd
make the reference code use double instead of float where it is easy
michael
parents:
5417
diff
changeset
|
120 double a, s; |
781 | 121 |
122 /* do it by hand */ | |
10807 | 123 for (k = 0; k < n/2; k++) { |
781 | 124 s = 0; |
10807 | 125 for (i = 0; i < n; i++) { |
781 | 126 a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n)); |
127 s += input[i] * cos(a); | |
128 } | |
129 output[k] = s; | |
130 } | |
131 } | |
132 | |
10944 | 133 static void idct_ref(float *output, float *input, int nbits) |
134 { | |
135 int n = 1<<nbits; | |
136 int k, i; | |
137 double a, s; | |
138 | |
139 /* do it by hand */ | |
140 for (i = 0; i < n; i++) { | |
141 s = 0.5 * input[0]; | |
142 for (k = 1; k < n; k++) { | |
143 a = M_PI*k*(i+0.5) / n; | |
144 s += input[k] * cos(a); | |
145 } | |
146 output[i] = 2 * s / n; | |
147 } | |
148 } | |
149 static void dct_ref(float *output, float *input, int nbits) | |
150 { | |
151 int n = 1<<nbits; | |
152 int k, i; | |
153 double a, s; | |
154 | |
155 /* do it by hand */ | |
156 for (k = 0; k < n; k++) { | |
157 s = 0; | |
158 for (i = 0; i < n; i++) { | |
159 a = M_PI*k*(i+0.5) / n; | |
160 s += input[i] * cos(a); | |
161 } | |
162 output[k] = s; | |
163 } | |
164 } | |
165 | |
781 | 166 |
10074
c4a83f3a5c9f
bring back some randomness in fft-test. (regression in r18070)
lorenm
parents:
9674
diff
changeset
|
167 static float frandom(AVLFG *prng) |
781 | 168 { |
10074
c4a83f3a5c9f
bring back some randomness in fft-test. (regression in r18070)
lorenm
parents:
9674
diff
changeset
|
169 return (int16_t)av_lfg_get(prng) / 32768.0; |
781 | 170 } |
171 | |
9295
b225f51903af
Mark non-exported functions in test and example programs as static.
diego
parents:
9199
diff
changeset
|
172 static int64_t gettime(void) |
781 | 173 { |
174 struct timeval tv; | |
175 gettimeofday(&tv,NULL); | |
1064 | 176 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; |
781 | 177 } |
178 | |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
179 static void check_diff(float *tab1, float *tab2, int n, double scale) |
781 | 180 { |
181 int i; | |
5417 | 182 double max= 0; |
183 double error= 0; | |
781 | 184 |
10807 | 185 for (i = 0; i < n; i++) { |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
186 double e= fabsf(tab1[i] - (tab2[i] / scale)); |
5417 | 187 if (e >= 1e-3) { |
2967 | 188 av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n", |
781 | 189 i, tab1[i], tab2[i]); |
190 } | |
5417 | 191 error+= e*e; |
192 if(e>max) max= e; | |
781 | 193 } |
5417 | 194 av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error)/n); |
781 | 195 } |
196 | |
197 | |
9295
b225f51903af
Mark non-exported functions in test and example programs as static.
diego
parents:
9199
diff
changeset
|
198 static void help(void) |
781 | 199 { |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
200 av_log(NULL, AV_LOG_INFO,"usage: fft-test [-h] [-s] [-i] [-n b]\n" |
781 | 201 "-h print this help\n" |
202 "-s speed test\n" | |
203 "-m (I)MDCT test\n" | |
10944 | 204 "-d (I)DCT test\n" |
11583 | 205 "-r (I)RDFT test\n" |
781 | 206 "-i inverse transform test\n" |
207 "-n b set the transform size to 2^b\n" | |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
208 "-f x set scale factor for output data of (I)MDCT to x\n" |
781 | 209 ); |
210 exit(1); | |
211 } | |
212 | |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
213 enum tf_transform { |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
214 TRANSFORM_FFT, |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
215 TRANSFORM_MDCT, |
10847 | 216 TRANSFORM_RDFT, |
10944 | 217 TRANSFORM_DCT, |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
218 }; |
781 | 219 |
220 int main(int argc, char **argv) | |
221 { | |
222 FFTComplex *tab, *tab1, *tab_ref; | |
7546 | 223 FFTSample *tab2; |
781 | 224 int it, i, c; |
225 int do_speed = 0; | |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
226 enum tf_transform transform = TRANSFORM_FFT; |
781 | 227 int do_inverse = 0; |
228 FFTContext s1, *s = &s1; | |
10199 | 229 FFTContext m1, *m = &m1; |
10847 | 230 RDFTContext r1, *r = &r1; |
10944 | 231 DCTContext d1, *d = &d1; |
10847 | 232 int fft_nbits, fft_size, fft_size_2; |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
233 double scale = 1.0; |
10074
c4a83f3a5c9f
bring back some randomness in fft-test. (regression in r18070)
lorenm
parents:
9674
diff
changeset
|
234 AVLFG prng; |
c4a83f3a5c9f
bring back some randomness in fft-test. (regression in r18070)
lorenm
parents:
9674
diff
changeset
|
235 av_lfg_init(&prng, 1); |
781 | 236 |
237 fft_nbits = 9; | |
238 for(;;) { | |
10944 | 239 c = getopt(argc, argv, "hsimrdn:f:"); |
781 | 240 if (c == -1) |
241 break; | |
242 switch(c) { | |
243 case 'h': | |
244 help(); | |
245 break; | |
246 case 's': | |
247 do_speed = 1; | |
248 break; | |
249 case 'i': | |
250 do_inverse = 1; | |
251 break; | |
252 case 'm': | |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
253 transform = TRANSFORM_MDCT; |
781 | 254 break; |
10847 | 255 case 'r': |
256 transform = TRANSFORM_RDFT; | |
257 break; | |
10944 | 258 case 'd': |
259 transform = TRANSFORM_DCT; | |
260 break; | |
781 | 261 case 'n': |
262 fft_nbits = atoi(optarg); | |
263 break; | |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
264 case 'f': |
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
265 scale = atof(optarg); |
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
266 break; |
781 | 267 } |
268 } | |
269 | |
270 fft_size = 1 << fft_nbits; | |
10847 | 271 fft_size_2 = fft_size >> 1; |
781 | 272 tab = av_malloc(fft_size * sizeof(FFTComplex)); |
273 tab1 = av_malloc(fft_size * sizeof(FFTComplex)); | |
274 tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); | |
275 tab2 = av_malloc(fft_size * sizeof(FFTSample)); | |
276 | |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
277 switch (transform) { |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
278 case TRANSFORM_MDCT: |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
279 av_log(NULL, AV_LOG_INFO,"Scale factor is set to %f\n", scale); |
781 | 280 if (do_inverse) |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
281 av_log(NULL, AV_LOG_INFO,"IMDCT"); |
781 | 282 else |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
283 av_log(NULL, AV_LOG_INFO,"MDCT"); |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
284 ff_mdct_init(m, fft_nbits, do_inverse, scale); |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
285 break; |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
286 case TRANSFORM_FFT: |
781 | 287 if (do_inverse) |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
288 av_log(NULL, AV_LOG_INFO,"IFFT"); |
781 | 289 else |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
290 av_log(NULL, AV_LOG_INFO,"FFT"); |
1879
dd63cb7e5080
fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
1106
diff
changeset
|
291 ff_fft_init(s, fft_nbits, do_inverse); |
781 | 292 fft_ref_init(fft_nbits, do_inverse); |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
293 break; |
10847 | 294 case TRANSFORM_RDFT: |
295 if (do_inverse) | |
11391 | 296 av_log(NULL, AV_LOG_INFO,"IDFT_C2R"); |
10847 | 297 else |
11391 | 298 av_log(NULL, AV_LOG_INFO,"DFT_R2C"); |
299 ff_rdft_init(r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C); | |
10847 | 300 fft_ref_init(fft_nbits, do_inverse); |
301 break; | |
10944 | 302 case TRANSFORM_DCT: |
303 if (do_inverse) | |
11582
23cad4157bfb
Make code using 1d-DCT consistent with the API change
vitor
parents:
11391
diff
changeset
|
304 av_log(NULL, AV_LOG_INFO,"DCT_III"); |
10944 | 305 else |
11582
23cad4157bfb
Make code using 1d-DCT consistent with the API change
vitor
parents:
11391
diff
changeset
|
306 av_log(NULL, AV_LOG_INFO,"DCT_II"); |
23cad4157bfb
Make code using 1d-DCT consistent with the API change
vitor
parents:
11391
diff
changeset
|
307 ff_dct_init(d, fft_nbits, do_inverse ? DCT_III : DCT_II); |
10944 | 308 break; |
781 | 309 } |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
310 av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); |
781 | 311 |
312 /* generate random data */ | |
313 | |
10807 | 314 for (i = 0; i < fft_size; i++) { |
10074
c4a83f3a5c9f
bring back some randomness in fft-test. (regression in r18070)
lorenm
parents:
9674
diff
changeset
|
315 tab1[i].re = frandom(&prng); |
c4a83f3a5c9f
bring back some randomness in fft-test. (regression in r18070)
lorenm
parents:
9674
diff
changeset
|
316 tab1[i].im = frandom(&prng); |
781 | 317 } |
318 | |
319 /* checking result */ | |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
320 av_log(NULL, AV_LOG_INFO,"Checking...\n"); |
781 | 321 |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
322 switch (transform) { |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
323 case TRANSFORM_MDCT: |
781 | 324 if (do_inverse) { |
5442 | 325 imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); |
7546 | 326 ff_imdct_calc(m, tab2, (float *)tab1); |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
327 check_diff((float *)tab_ref, tab2, fft_size, scale); |
781 | 328 } else { |
5442 | 329 mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); |
2967 | 330 |
7546 | 331 ff_mdct_calc(m, tab2, (float *)tab1); |
781 | 332 |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
333 check_diff((float *)tab_ref, tab2, fft_size / 2, scale); |
781 | 334 } |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
335 break; |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
336 case TRANSFORM_FFT: |
781 | 337 memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); |
1879
dd63cb7e5080
fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
1106
diff
changeset
|
338 ff_fft_permute(s, tab); |
dd63cb7e5080
fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
1106
diff
changeset
|
339 ff_fft_calc(s, tab); |
2967 | 340 |
781 | 341 fft_ref(tab_ref, tab1, fft_nbits); |
9674
dac20d8df581
Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents:
9658
diff
changeset
|
342 check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 1.0); |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
343 break; |
10847 | 344 case TRANSFORM_RDFT: |
345 if (do_inverse) { | |
346 tab1[ 0].im = 0; | |
347 tab1[fft_size_2].im = 0; | |
348 for (i = 1; i < fft_size_2; i++) { | |
349 tab1[fft_size_2+i].re = tab1[fft_size_2-i].re; | |
350 tab1[fft_size_2+i].im = -tab1[fft_size_2-i].im; | |
351 } | |
352 | |
353 memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); | |
354 tab2[1] = tab1[fft_size_2].re; | |
355 | |
356 ff_rdft_calc(r, tab2); | |
357 fft_ref(tab_ref, tab1, fft_nbits); | |
358 for (i = 0; i < fft_size; i++) { | |
359 tab[i].re = tab2[i]; | |
360 tab[i].im = 0; | |
361 } | |
362 check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 0.5); | |
363 } else { | |
364 for (i = 0; i < fft_size; i++) { | |
365 tab2[i] = tab1[i].re; | |
366 tab1[i].im = 0; | |
367 } | |
368 ff_rdft_calc(r, tab2); | |
369 fft_ref(tab_ref, tab1, fft_nbits); | |
370 tab_ref[0].im = tab_ref[fft_size_2].re; | |
371 check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0); | |
372 } | |
10944 | 373 break; |
374 case TRANSFORM_DCT: | |
375 memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); | |
376 ff_dct_calc(d, tab); | |
377 if (do_inverse) { | |
378 idct_ref(tab_ref, tab1, fft_nbits); | |
379 } else { | |
380 dct_ref(tab_ref, tab1, fft_nbits); | |
381 } | |
382 check_diff((float *)tab_ref, (float *)tab, fft_size, 1.0); | |
383 break; | |
781 | 384 } |
385 | |
386 /* do a speed test */ | |
387 | |
388 if (do_speed) { | |
1064 | 389 int64_t time_start, duration; |
781 | 390 int nb_its; |
391 | |
2593
786ccf72ccd5
printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents:
1879
diff
changeset
|
392 av_log(NULL, AV_LOG_INFO,"Speed test...\n"); |
781 | 393 /* we measure during about 1 seconds */ |
394 nb_its = 1; | |
395 for(;;) { | |
396 time_start = gettime(); | |
10807 | 397 for (it = 0; it < nb_its; it++) { |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
398 switch (transform) { |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
399 case TRANSFORM_MDCT: |
781 | 400 if (do_inverse) { |
7546 | 401 ff_imdct_calc(m, (float *)tab, (float *)tab1); |
781 | 402 } else { |
7546 | 403 ff_mdct_calc(m, (float *)tab, (float *)tab1); |
781 | 404 } |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
405 break; |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
406 case TRANSFORM_FFT: |
781 | 407 memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); |
1879
dd63cb7e5080
fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
1106
diff
changeset
|
408 ff_fft_calc(s, tab); |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
409 break; |
10847 | 410 case TRANSFORM_RDFT: |
411 memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); | |
412 ff_rdft_calc(r, tab2); | |
413 break; | |
10944 | 414 case TRANSFORM_DCT: |
415 memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); | |
416 ff_dct_calc(d, tab2); | |
417 break; | |
781 | 418 } |
419 } | |
420 duration = gettime() - time_start; | |
421 if (duration >= 1000000) | |
422 break; | |
423 nb_its *= 2; | |
424 } | |
2967 | 425 av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n", |
426 (double)duration / nb_its, | |
781 | 427 (double)duration / 1000000.0, |
428 nb_its); | |
429 } | |
2967 | 430 |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
431 switch (transform) { |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
432 case TRANSFORM_MDCT: |
969 | 433 ff_mdct_end(m); |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
434 break; |
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
435 case TRANSFORM_FFT: |
1879
dd63cb7e5080
fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
1106
diff
changeset
|
436 ff_fft_end(s); |
10846
8dbceaa5fa2f
fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents:
10807
diff
changeset
|
437 break; |
10847 | 438 case TRANSFORM_RDFT: |
439 ff_rdft_end(r); | |
440 break; | |
10944 | 441 case TRANSFORM_DCT: |
442 ff_dct_end(d); | |
443 break; | |
781 | 444 } |
445 return 0; | |
446 } |