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