FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/fft.c
Date: 2021-09-16 08:47:15
Exec Total Coverage
Lines: 286 338 84.6%
Branches: 83 112 74.1%

Line Branch Exec Source
1 /*
2 * (c) 2002 Fabrice Bellard
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * FFT and MDCT tests.
24 */
25
26 #include "config.h"
27
28 #ifndef AVFFT
29 #define AVFFT 0
30 #endif
31
32 #include <math.h>
33 #if HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "libavutil/cpu.h"
41 #include "libavutil/lfg.h"
42 #include "libavutil/log.h"
43 #include "libavutil/mathematics.h"
44 #include "libavutil/time.h"
45
46 #if AVFFT
47 #include "libavcodec/avfft.h"
48 #else
49 #include "libavcodec/fft.h"
50 #endif
51
52 #if FFT_FLOAT
53 #include "libavcodec/dct.h"
54 #include "libavcodec/rdft.h"
55 #endif
56
57 /* reference fft */
58
59 #define MUL16(a, b) ((a) * (b))
60
61 #define CMAC(pre, pim, are, aim, bre, bim) \
62 { \
63 pre += (MUL16(are, bre) - MUL16(aim, bim)); \
64 pim += (MUL16(are, bim) + MUL16(bre, aim)); \
65 }
66
67 #if FFT_FLOAT || AVFFT
68 #define RANGE 1.0
69 #define REF_SCALE(x, bits) (x)
70 #define FMT "%10.6f"
71 #else
72 #define RANGE 8388608
73 #define REF_SCALE(x, bits) (x)
74 #define FMT "%6d"
75 #endif
76
77 static struct {
78 float re, im;
79 } *exptab;
80
81 99 static int fft_ref_init(int nbits, int inverse)
82 {
83 99 int i, n = 1 << nbits;
84
85 99 exptab = av_malloc_array((n / 2), sizeof(*exptab));
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
99 if (!exptab)
87 return AVERROR(ENOMEM);
88
89
2/2
✓ Branch 0 taken 43184 times.
✓ Branch 1 taken 99 times.
43283 for (i = 0; i < (n / 2); i++) {
90 43184 double alpha = 2 * M_PI * (float) i / (float) n;
91 43184 double c1 = cos(alpha), s1 = sin(alpha);
92
2/2
✓ Branch 0 taken 22744 times.
✓ Branch 1 taken 20440 times.
43184 if (!inverse)
93 22744 s1 = -s1;
94 43184 exptab[i].re = c1;
95 43184 exptab[i].im = s1;
96 }
97 99 return 0;
98 }
99
100 99 static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
101 {
102 int i, j;
103 99 int n = 1 << nbits;
104 99 int n2 = n >> 1;
105
106
2/2
✓ Branch 0 taken 86368 times.
✓ Branch 1 taken 99 times.
86467 for (i = 0; i < n; i++) {
107 86368 double tmp_re = 0, tmp_im = 0;
108 86368 FFTComplex *q = tab;
109
2/2
✓ Branch 0 taken 226054656 times.
✓ Branch 1 taken 86368 times.
226141024 for (j = 0; j < n; j++) {
110 double s, c;
111 226054656 int k = (i * j) & (n - 1);
112
2/2
✓ Branch 0 taken 112984144 times.
✓ Branch 1 taken 113070512 times.
226054656 if (k >= n2) {
113 112984144 c = -exptab[k - n2].re;
114 112984144 s = -exptab[k - n2].im;
115 } else {
116 113070512 c = exptab[k].re;
117 113070512 s = exptab[k].im;
118 }
119 226054656 CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
120 226054656 q++;
121 }
122 86368 tabr[i].re = REF_SCALE(tmp_re, nbits);
123 86368 tabr[i].im = REF_SCALE(tmp_im, nbits);
124 }
125 99 }
126
127 #if CONFIG_MDCT
128 27 static void imdct_ref(FFTSample *out, FFTSample *in, int nbits)
129 {
130 27 int i, k, n = 1 << nbits;
131
132
2/2
✓ Branch 0 taken 24528 times.
✓ Branch 1 taken 27 times.
24555 for (i = 0; i < n; i++) {
133 24528 double sum = 0;
134
2/2
✓ Branch 0 taken 33554304 times.
✓ Branch 1 taken 24528 times.
33578832 for (k = 0; k < n / 2; k++) {
135 33554304 int a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
136 33554304 double f = cos(M_PI * a / (double) (2 * n));
137 33554304 sum += f * in[k];
138 }
139 24528 out[i] = REF_SCALE(-sum, nbits - 2);
140 }
141 27 }
142
143 /* NOTE: no normalisation by 1 / N is done */
144 18 static void mdct_ref(FFTSample *output, FFTSample *input, int nbits)
145 {
146 18 int i, k, n = 1 << nbits;
147
148 /* do it by hand */
149
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 18 times.
8194 for (k = 0; k < n / 2; k++) {
150 8176 double s = 0;
151
2/2
✓ Branch 0 taken 22369536 times.
✓ Branch 1 taken 8176 times.
22377712 for (i = 0; i < n; i++) {
152 22369536 double a = (2 * M_PI * (2 * i + 1 + n / 2) * (2 * k + 1) / (4 * n));
153 22369536 s += input[i] * cos(a);
154 }
155 8176 output[k] = REF_SCALE(s, nbits - 1);
156 }
157 18 }
158 #endif /* CONFIG_MDCT */
159
160 #if FFT_FLOAT
161 #if CONFIG_DCT
162 18 static void idct_ref(FFTSample *output, FFTSample *input, int nbits)
163 {
164 18 int i, k, n = 1 << nbits;
165
166 /* do it by hand */
167
2/2
✓ Branch 0 taken 16352 times.
✓ Branch 1 taken 18 times.
16370 for (i = 0; i < n; i++) {
168 16352 double s = 0.5 * input[0];
169
2/2
✓ Branch 0 taken 44722720 times.
✓ Branch 1 taken 16352 times.
44739072 for (k = 1; k < n; k++) {
170 44722720 double a = M_PI * k * (i + 0.5) / n;
171 44722720 s += input[k] * cos(a);
172 }
173 16352 output[i] = 2 * s / n;
174 }
175 18 }
176
177 18 static void dct_ref(FFTSample *output, FFTSample *input, int nbits)
178 {
179 18 int i, k, n = 1 << nbits;
180
181 /* do it by hand */
182
2/2
✓ Branch 0 taken 16352 times.
✓ Branch 1 taken 18 times.
16370 for (k = 0; k < n; k++) {
183 16352 double s = 0;
184
2/2
✓ Branch 0 taken 44739072 times.
✓ Branch 1 taken 16352 times.
44755424 for (i = 0; i < n; i++) {
185 44739072 double a = M_PI * k * (i + 0.5) / n;
186 44739072 s += input[i] * cos(a);
187 }
188 16352 output[k] = s;
189 }
190 18 }
191 #endif /* CONFIG_DCT */
192 #endif /* FFT_FLOAT */
193
194 319904 static FFTSample frandom(AVLFG *prng)
195 {
196 319904 return (int16_t) av_lfg_get(prng) / 32768.0 * RANGE;
197 }
198
199 180 static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
200 {
201 180 int i, err = 0;
202 180 double error = 0, max = 0;
203
204
2/2
✓ Branch 0 taken 221792 times.
✓ Branch 1 taken 180 times.
221972 for (i = 0; i < n; i++) {
205 221792 double e = fabs(tab1[i] - (tab2[i] / scale)) / RANGE;
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 221792 times.
221792 if (e >= 1e-3) {
207 av_log(NULL, AV_LOG_ERROR, "ERROR %5d: "FMT" "FMT"\n",
208 i, tab1[i], tab2[i]);
209 err = 1;
210 }
211 221792 error += e * e;
212
2/2
✓ Branch 0 taken 834 times.
✓ Branch 1 taken 220958 times.
221792 if (e > max)
213 834 max = e;
214 }
215 180 av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error / n));
216 180 return err;
217 }
218
219 63 static inline void fft_init(FFTContext **s, int nbits, int inverse)
220 {
221 #if AVFFT
222 18 *s = av_fft_init(nbits, inverse);
223 #else
224 45 ff_fft_init(*s, nbits, inverse);
225 #endif
226 63 }
227
228 45 static inline void mdct_init(FFTContext **s, int nbits, int inverse, double scale)
229 {
230 #if AVFFT
231 18 *s = av_mdct_init(nbits, inverse, scale);
232 #else
233 27 ff_mdct_init(*s, nbits, inverse, scale);
234 #endif
235 45 }
236
237 18 static inline void mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
238 {
239 #if AVFFT
240 9 av_mdct_calc(s, output, input);
241 #else
242 9 s->mdct_calc(s, output, input);
243 #endif
244 18 }
245
246 27 static inline void imdct_calc(struct FFTContext *s, FFTSample *output, const FFTSample *input)
247 {
248 #if AVFFT
249 9 av_imdct_calc(s, output, input);
250 #else
251 18 s->imdct_calc(s, output, input);
252 #endif
253 27 }
254
255 63 static inline void fft_permute(FFTContext *s, FFTComplex *z)
256 {
257 #if AVFFT
258 18 av_fft_permute(s, z);
259 #else
260 45 s->fft_permute(s, z);
261 #endif
262 63 }
263
264 63 static inline void fft_calc(FFTContext *s, FFTComplex *z)
265 {
266 #if AVFFT
267 18 av_fft_calc(s, z);
268 #else
269 45 s->fft_calc(s, z);
270 #endif
271 63 }
272
273 45 static inline void mdct_end(FFTContext *s)
274 {
275 #if AVFFT
276 18 av_mdct_end(s);
277 #else
278 27 ff_mdct_end(s);
279 #endif
280 45 }
281
282 63 static inline void fft_end(FFTContext *s)
283 {
284 #if AVFFT
285 18 av_fft_end(s);
286 #else
287 45 ff_fft_end(s);
288 #endif
289 63 }
290
291 #if FFT_FLOAT
292 36 static inline void rdft_init(RDFTContext **r, int nbits, enum RDFTransformType trans)
293 {
294 #if AVFFT
295 18 *r = av_rdft_init(nbits, trans);
296 #else
297 18 ff_rdft_init(*r, nbits, trans);
298 #endif
299 36 }
300
301 36 static inline void dct_init(DCTContext **d, int nbits, enum DCTTransformType trans)
302 {
303 #if AVFFT
304 18 *d = av_dct_init(nbits, trans);
305 #else
306 18 ff_dct_init(*d, nbits, trans);
307 #endif
308 36 }
309
310 36 static inline void rdft_calc(RDFTContext *r, FFTSample *tab)
311 {
312 #if AVFFT
313 18 av_rdft_calc(r, tab);
314 #else
315 18 r->rdft_calc(r, tab);
316 #endif
317 36 }
318
319 36 static inline void dct_calc(DCTContext *d, FFTSample *data)
320 {
321 #if AVFFT
322 18 av_dct_calc(d, data);
323 #else
324 18 d->dct_calc(d, data);
325 #endif
326 36 }
327
328 36 static inline void rdft_end(RDFTContext *r)
329 {
330 #if AVFFT
331 18 av_rdft_end(r);
332 #else
333 18 ff_rdft_end(r);
334 #endif
335 36 }
336
337 36 static inline void dct_end(DCTContext *d)
338 {
339 #if AVFFT
340 18 av_dct_end(d);
341 #else
342 18 ff_dct_end(d);
343 #endif
344 36 }
345 #endif /* FFT_FLOAT */
346
347 static void help(void)
348 {
349 av_log(NULL, AV_LOG_INFO,
350 "usage: fft-test [-h] [-s] [-i] [-n b]\n"
351 "-h print this help\n"
352 "-s speed test\n"
353 "-m (I)MDCT test\n"
354 "-d (I)DCT test\n"
355 "-r (I)RDFT test\n"
356 "-i inverse transform test\n"
357 "-n b set the transform size to 2^b\n"
358 "-f x set scale factor for output data of (I)MDCT to x\n");
359 }
360
361 enum tf_transform {
362 TRANSFORM_FFT,
363 TRANSFORM_MDCT,
364 TRANSFORM_RDFT,
365 TRANSFORM_DCT,
366 };
367
368 #if !HAVE_GETOPT
369 #include "compat/getopt.c"
370 #endif
371
372 180 int main(int argc, char **argv)
373 {
374 FFTComplex *tab, *tab1, *tab_ref;
375 FFTSample *tab2;
376 180 enum tf_transform transform = TRANSFORM_FFT;
377 FFTContext *m, *s;
378 #if FFT_FLOAT
379 RDFTContext *r;
380 DCTContext *d;
381 #endif /* FFT_FLOAT */
382 180 int it, i, err = 1;
383 180 int do_speed = 0, do_inverse = 0;
384 180 int fft_nbits = 9, fft_size;
385 180 double scale = 1.0;
386 AVLFG prng;
387
388 #if !AVFFT
389 108 s = av_mallocz(sizeof(*s));
390 108 m = av_mallocz(sizeof(*m));
391 #endif
392
393 #if !AVFFT && FFT_FLOAT
394 72 r = av_mallocz(sizeof(*r));
395 72 d = av_mallocz(sizeof(*d));
396 #endif
397
398 180 av_lfg_init(&prng, 1);
399
400 558 for (;;) {
401 738 int c = getopt(argc, argv, "hsimrdn:f:c:");
402
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 558 times.
738 if (c == -1)
403 180 break;
404
6/10
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 171 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 180 times.
✗ Branch 9 not taken.
558 switch (c) {
405 case 'h':
406 help();
407 return 1;
408 case 's':
409 do_speed = 1;
410 break;
411 90 case 'i':
412 90 do_inverse = 1;
413 90 break;
414 45 case 'm':
415 45 transform = TRANSFORM_MDCT;
416 45 break;
417 36 case 'r':
418 36 transform = TRANSFORM_RDFT;
419 36 break;
420 36 case 'd':
421 36 transform = TRANSFORM_DCT;
422 36 break;
423 171 case 'n':
424 171 fft_nbits = atoi(optarg);
425 171 break;
426 case 'f':
427 scale = atof(optarg);
428 break;
429 180 case 'c':
430 {
431 180 unsigned cpuflags = av_get_cpu_flags();
432
433
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
180 if (av_parse_cpu_caps(&cpuflags, optarg) < 0)
434 return 1;
435
436 180 av_force_cpu_flags(cpuflags);
437 180 break;
438 }
439 }
440 }
441
442 180 fft_size = 1 << fft_nbits;
443 180 tab = av_malloc_array(fft_size, sizeof(FFTComplex));
444 180 tab1 = av_malloc_array(fft_size, sizeof(FFTComplex));
445 180 tab_ref = av_malloc_array(fft_size, sizeof(FFTComplex));
446 180 tab2 = av_malloc_array(fft_size, sizeof(FFTSample));
447
448
4/8
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 180 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
180 if (!(tab && tab1 && tab_ref && tab2))
449 goto cleanup;
450
451
4/5
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
180 switch (transform) {
452 #if CONFIG_MDCT
453 45 case TRANSFORM_MDCT:
454 45 av_log(NULL, AV_LOG_INFO, "Scale factor is set to %f\n", scale);
455
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 18 times.
45 if (do_inverse)
456 27 av_log(NULL, AV_LOG_INFO, "IMDCT");
457 else
458 18 av_log(NULL, AV_LOG_INFO, "MDCT");
459 45 mdct_init(&m, fft_nbits, do_inverse, scale);
460 45 break;
461 #endif /* CONFIG_MDCT */
462 63 case TRANSFORM_FFT:
463
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 36 times.
63 if (do_inverse)
464 27 av_log(NULL, AV_LOG_INFO, "IFFT");
465 else
466 36 av_log(NULL, AV_LOG_INFO, "FFT");
467 63 fft_init(&s, fft_nbits, do_inverse);
468
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
63 if ((err = fft_ref_init(fft_nbits, do_inverse)) < 0)
469 goto cleanup;
470 63 break;
471 #if FFT_FLOAT
472 # if CONFIG_RDFT
473 36 case TRANSFORM_RDFT:
474
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (do_inverse)
475 18 av_log(NULL, AV_LOG_INFO, "IDFT_C2R");
476 else
477 18 av_log(NULL, AV_LOG_INFO, "DFT_R2C");
478 36 rdft_init(&r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C);
479
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
36 if ((err = fft_ref_init(fft_nbits, do_inverse)) < 0)
480 goto cleanup;
481 36 break;
482 # endif /* CONFIG_RDFT */
483 # if CONFIG_DCT
484 36 case TRANSFORM_DCT:
485
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (do_inverse)
486 18 av_log(NULL, AV_LOG_INFO, "DCT_III");
487 else
488 18 av_log(NULL, AV_LOG_INFO, "DCT_II");
489 36 dct_init(&d, fft_nbits, do_inverse ? DCT_III : DCT_II);
490 36 break;
491 # endif /* CONFIG_DCT */
492 #endif /* FFT_FLOAT */
493 default:
494 av_log(NULL, AV_LOG_ERROR, "Requested transform not supported\n");
495 goto cleanup;
496 }
497 180 av_log(NULL, AV_LOG_INFO, " %d test\n", fft_size);
498
499 /* generate random data */
500
501
2/2
✓ Branch 0 taken 159952 times.
✓ Branch 1 taken 180 times.
160132 for (i = 0; i < fft_size; i++) {
502 159952 tab1[i].re = frandom(&prng);
503 159952 tab1[i].im = frandom(&prng);
504 }
505
506 /* checking result */
507 180 av_log(NULL, AV_LOG_INFO, "Checking...\n");
508
509
4/5
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
180 switch (transform) {
510 #if CONFIG_MDCT
511 45 case TRANSFORM_MDCT:
512
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 18 times.
45 if (do_inverse) {
513 27 imdct_ref(&tab_ref->re, &tab1->re, fft_nbits);
514 27 imdct_calc(m, tab2, &tab1->re);
515 27 err = check_diff(&tab_ref->re, tab2, fft_size, scale);
516 } else {
517 18 mdct_ref(&tab_ref->re, &tab1->re, fft_nbits);
518 18 mdct_calc(m, tab2, &tab1->re);
519 18 err = check_diff(&tab_ref->re, tab2, fft_size / 2, scale);
520 }
521 45 break;
522 #endif /* CONFIG_MDCT */
523 63 case TRANSFORM_FFT:
524 63 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
525 63 fft_permute(s, tab);
526 63 fft_calc(s, tab);
527
528 63 fft_ref(tab_ref, tab1, fft_nbits);
529 63 err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 1.0);
530 63 break;
531 #if FFT_FLOAT
532 #if CONFIG_RDFT
533 36 case TRANSFORM_RDFT:
534 {
535 36 int fft_size_2 = fft_size >> 1;
536
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (do_inverse) {
537 18 tab1[0].im = 0;
538 18 tab1[fft_size_2].im = 0;
539
2/2
✓ Branch 0 taken 8158 times.
✓ Branch 1 taken 18 times.
8176 for (i = 1; i < fft_size_2; i++) {
540 8158 tab1[fft_size_2 + i].re = tab1[fft_size_2 - i].re;
541 8158 tab1[fft_size_2 + i].im = -tab1[fft_size_2 - i].im;
542 }
543
544 18 memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
545 18 tab2[1] = tab1[fft_size_2].re;
546
547 18 rdft_calc(r, tab2);
548 18 fft_ref(tab_ref, tab1, fft_nbits);
549
2/2
✓ Branch 0 taken 16352 times.
✓ Branch 1 taken 18 times.
16370 for (i = 0; i < fft_size; i++) {
550 16352 tab[i].re = tab2[i];
551 16352 tab[i].im = 0;
552 }
553 18 err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 0.5);
554 } else {
555
2/2
✓ Branch 0 taken 16352 times.
✓ Branch 1 taken 18 times.
16370 for (i = 0; i < fft_size; i++) {
556 16352 tab2[i] = tab1[i].re;
557 16352 tab1[i].im = 0;
558 }
559 18 rdft_calc(r, tab2);
560 18 fft_ref(tab_ref, tab1, fft_nbits);
561 18 tab_ref[0].im = tab_ref[fft_size_2].re;
562 18 err = check_diff(&tab_ref->re, tab2, fft_size, 1.0);
563 }
564 36 break;
565 }
566 #endif /* CONFIG_RDFT */
567 #if CONFIG_DCT
568 36 case TRANSFORM_DCT:
569 36 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
570 36 dct_calc(d, &tab->re);
571
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (do_inverse)
572 18 idct_ref(&tab_ref->re, &tab1->re, fft_nbits);
573 else
574 18 dct_ref(&tab_ref->re, &tab1->re, fft_nbits);
575 36 err = check_diff(&tab_ref->re, &tab->re, fft_size, 1.0);
576 36 break;
577 #endif /* CONFIG_DCT */
578 #endif /* FFT_FLOAT */
579 }
580
581 /* do a speed test */
582
583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180 times.
180 if (do_speed) {
584 int64_t time_start, duration;
585 int nb_its;
586
587 av_log(NULL, AV_LOG_INFO, "Speed test...\n");
588 /* we measure during about 1 seconds */
589 nb_its = 1;
590 for (;;) {
591 time_start = av_gettime_relative();
592 for (it = 0; it < nb_its; it++) {
593 switch (transform) {
594 case TRANSFORM_MDCT:
595 if (do_inverse)
596 imdct_calc(m, &tab->re, &tab1->re);
597 else
598 mdct_calc(m, &tab->re, &tab1->re);
599 break;
600 case TRANSFORM_FFT:
601 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
602 fft_calc(s, tab);
603 break;
604 #if FFT_FLOAT
605 case TRANSFORM_RDFT:
606 memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
607 rdft_calc(r, tab2);
608 break;
609 case TRANSFORM_DCT:
610 memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
611 dct_calc(d, tab2);
612 break;
613 #endif /* FFT_FLOAT */
614 }
615 }
616 duration = av_gettime_relative() - time_start;
617 if (duration >= 1000000)
618 break;
619 nb_its *= 2;
620 }
621 av_log(NULL, AV_LOG_INFO,
622 "time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
623 (double) duration / nb_its,
624 (double) duration / 1000000.0,
625 nb_its);
626 }
627
628
4/5
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
180 switch (transform) {
629 #if CONFIG_MDCT
630 45 case TRANSFORM_MDCT:
631 45 mdct_end(m);
632 45 break;
633 #endif /* CONFIG_MDCT */
634 63 case TRANSFORM_FFT:
635 63 fft_end(s);
636 63 break;
637 #if FFT_FLOAT
638 # if CONFIG_RDFT
639 36 case TRANSFORM_RDFT:
640 36 rdft_end(r);
641 36 break;
642 # endif /* CONFIG_RDFT */
643 # if CONFIG_DCT
644 36 case TRANSFORM_DCT:
645 36 dct_end(d);
646 36 break;
647 # endif /* CONFIG_DCT */
648 #endif /* FFT_FLOAT */
649 }
650
651 180 cleanup:
652 180 av_free(tab);
653 180 av_free(tab1);
654 180 av_free(tab2);
655 180 av_free(tab_ref);
656 180 av_free(exptab);
657
658 #if !AVFFT
659 108 av_free(s);
660 108 av_free(m);
661 #endif
662
663 #if !AVFFT && FFT_FLOAT
664 72 av_free(r);
665 72 av_free(d);
666 #endif
667
668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180 times.
180 if (err)
669 printf("Error: %d.\n", err);
670
671 180 return !!err;
672 }
673