FFmpeg
fft.c
Go to the documentation of this file.
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 
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
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
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 {
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 
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;
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':
423  break;
424  case 'r':
426  break;
427  case 'd':
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  }
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 
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
ff_fft_init
#define ff_fft_init
Definition: fft.h:136
av_force_cpu_flags
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition: cpu.c:75
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
r
const char * r
Definition: vf_curves.c:126
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_dct_calc
void av_dct_calc(DCTContext *s, FFTSample *data)
Definition: avfft.c:229
out
FILE * out
Definition: movenc.c:54
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
imdct_calc
static void imdct_calc(DBEDecodeContext *s1, DBEGroup *g, float *result, float *values)
Definition: dolby_e.c:991
inverse
inverse
Definition: af_crystalizer.c:121
av_fft_calc
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
Definition: avfft.c:68
rdft.h
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
TRANSFORM_DCT
@ TRANSFORM_DCT
Definition: fft.c:372
im
float im
Definition: fft.c:83
cleanup
static av_cold void cleanup(FlashSV2Context *s)
Definition: flashsv2enc.c:130
data
const char data[16]
Definition: mxf.c:148
ff_mdct_init
#define ff_mdct_init
Definition: fft.h:154
max
#define max(a, b)
Definition: cuda_runtime.h:33
mathematics.h
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:103
c1
static const uint64_t c1
Definition: murmur3.c:52
CMAC
#define CMAC(pre, pim, are, aim, bre, bim)
Definition: fft.c:66
DCT_III
@ DCT_III
Definition: avfft.h:120
av_parse_cpu_caps
int av_parse_cpu_caps(unsigned *flags, const char *s)
Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
Definition: cpu.c:113
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
IDFT_C2R
@ IDFT_C2R
Definition: avfft.h:93
ff_rdft_end
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:117
REF_SCALE
#define REF_SCALE(x, bits)
Definition: fft.c:78
tab2
const int16_t * tab2
Definition: mace.c:145
TRANSFORM_FFT
@ TRANSFORM_FFT
Definition: fft.c:369
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
frandom
static FFTSample frandom(AVLFG *prng)
Definition: fft.c:199
tab1
const int16_t * tab1
Definition: mace.c:145
main
int main(int argc, char **argv)
Definition: fft.c:379
av_mdct_end
av_cold void av_mdct_end(FFTContext *s)
Definition: avfft.c:129
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
dct.h
getopt
static int getopt(int argc, char *argv[], char *opts)
Definition: getopt.c:41
duration
int64_t duration
Definition: movenc.c:64
float
float
Definition: af_crystalizer.c:121
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
help
static void help(void)
Definition: fft.c:354
s1
#define s1
Definition: regdef.h:38
fft_end
static void fft_end(FFTContext *s)
Definition: fft.c:289
lfg.h
ff_fft_end
#define ff_fft_end
Definition: fft.h:137
av_mdct_calc
void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: avfft.c:123
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
TRANSFORM_MDCT
@ TRANSFORM_MDCT
Definition: fft.c:370
av_fft_init
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:45
transform
static const int8_t transform[32][32]
Definition: hevcdsp.c:27
tf_transform
tf_transform
Definition: fft.c:368
DFT_R2C
@ DFT_R2C
Definition: avfft.h:92
time.h
FFTSample
float FFTSample
Definition: avfft.h:39
avfft.h
fft_calc
static void fft_calc(FFTContext *s, FFTComplex *z)
Definition: fft.c:271
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
error.h
av_rdft_end
av_cold void av_rdft_end(RDFTContext *s)
Definition: avfft.c:177
fft_permute
static void fft_permute(FFTContext *s, FFTComplex *z)
Definition: fft.c:262
av_mdct_init
FFTContext * av_mdct_init(int nbits, int inverse, double scale)
Definition: avfft.c:84
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
f
f
Definition: af_crystalizer.c:121
cpu.h
exptab
static struct @156 * exptab
ff_mdct_end
#define ff_mdct_end
Definition: fft.h:155
FFTComplex::im
FFTSample im
Definition: avfft.h:42
printf
printf("static const uint8_t my_array[100] = {\n")
FFTComplex::re
FFTSample re
Definition: avfft.h:42
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_dct_end
av_cold void ff_dct_end(DCTContext *s)
Definition: dct.c:224
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
M_PI
#define M_PI
Definition: mathematics.h:67
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
av_imdct_calc
void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: avfft.c:111
ff_rdft_init
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
Definition: rdft.c:89
FFTContext
Definition: fft.h:76
ff_dct_init
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
Definition: dct.c:179
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:244
internal.h
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
RDFTContext
Definition: rdft.h:28
RDFTransformType
RDFTransformType
Definition: avfft.h:91
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
fft_ref_init
static int fft_ref_init(int nbits, int inverse)
Definition: fft.c:86
DCTContext
Definition: dct.h:32
fft_init
static void fft_init(FFTContext **s, int nbits, int inverse)
Definition: fft.c:224
av_dct_init
DCTContext * av_dct_init(int nbits, enum DCTTransformType inverse)
Set up DCT.
Definition: avfft.c:186
mdct_end
static void mdct_end(FFTContext *s)
Definition: fft.c:280
dct_init
static av_cold int dct_init(MpegEncContext *s)
Definition: mpegvideo.c:274
getopt.c
fft.h
check_diff
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
Definition: fft.c:204
FMT
#define FMT
Definition: fft.c:79
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
optarg
static char * optarg
Definition: getopt.c:39
av_rdft_calc
void av_rdft_calc(RDFTContext *s, FFTSample *data)
Definition: avfft.c:167
it
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s it
Definition: writing_filters.txt:31
RANGE
#define RANGE
Definition: fft.c:77
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
fft_ref
static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
Definition: fft.c:105
av_dct_end
av_cold void av_dct_end(DCTContext *s)
Definition: avfft.c:240
TRANSFORM_RDFT
@ TRANSFORM_RDFT
Definition: fft.c:371
d
d
Definition: ffmpeg_filter.c:331
DCT_II
@ DCT_II
Definition: avfft.h:119
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_fft_end
av_cold void av_fft_end(FFTContext *s)
Definition: avfft.c:74
DCTTransformType
DCTTransformType
Definition: avfft.h:118
av_rdft_init
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
Definition: avfft.c:138
av_fft_permute
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
Definition: avfft.c:63
FFTComplex
Definition: avfft.h:41
re
float re
Definition: fft.c:83