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