FFmpeg coverage


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