Libav
fft-test.c
Go to the documentation of this file.
1 /*
2  * (c) 2002 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
26 #include "libavutil/cpu.h"
27 #include "libavutil/mathematics.h"
28 #include "libavutil/lfg.h"
29 #include "libavutil/log.h"
30 #include "libavutil/time.h"
31 #include "fft.h"
32 #if FFT_FLOAT
33 #include "dct.h"
34 #include "rdft.h"
35 #endif
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 /* reference fft */
45 
46 #define MUL16(a,b) ((a) * (b))
47 
48 #define CMAC(pre, pim, are, aim, bre, bim) \
49 {\
50  pre += (MUL16(are, bre) - MUL16(aim, bim));\
51  pim += (MUL16(are, bim) + MUL16(bre, aim));\
52 }
53 
54 #if FFT_FLOAT
55 # define RANGE 1.0
56 # define REF_SCALE(x, bits) (x)
57 # define FMT "%10.6f"
58 #else
59 # define RANGE 16384
60 # define REF_SCALE(x, bits) ((x) / (1<<(bits)))
61 # define FMT "%6d"
62 #endif
63 
64 struct {
65  float re, im;
66 } *exptab;
67 
68 static void fft_ref_init(int nbits, int inverse)
69 {
70  int n, i;
71  double c1, s1, alpha;
72 
73  n = 1 << nbits;
74  exptab = av_malloc((n / 2) * sizeof(*exptab));
75 
76  for (i = 0; i < (n/2); i++) {
77  alpha = 2 * M_PI * (float)i / (float)n;
78  c1 = cos(alpha);
79  s1 = sin(alpha);
80  if (!inverse)
81  s1 = -s1;
82  exptab[i].re = c1;
83  exptab[i].im = s1;
84  }
85 }
86 
87 static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
88 {
89  int n, i, j, k, n2;
90  double tmp_re, tmp_im, s, c;
91  FFTComplex *q;
92 
93  n = 1 << nbits;
94  n2 = n >> 1;
95  for (i = 0; i < n; i++) {
96  tmp_re = 0;
97  tmp_im = 0;
98  q = tab;
99  for (j = 0; j < n; j++) {
100  k = (i * j) & (n - 1);
101  if (k >= n2) {
102  c = -exptab[k - n2].re;
103  s = -exptab[k - n2].im;
104  } else {
105  c = exptab[k].re;
106  s = exptab[k].im;
107  }
108  CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
109  q++;
110  }
111  tabr[i].re = REF_SCALE(tmp_re, nbits);
112  tabr[i].im = REF_SCALE(tmp_im, nbits);
113  }
114 }
115 
116 #if CONFIG_MDCT
117 static void imdct_ref(FFTSample *out, FFTSample *in, int nbits)
118 {
119  int n = 1<<nbits;
120  int k, i, a;
121  double sum, f;
122 
123  for (i = 0; i < n; i++) {
124  sum = 0;
125  for (k = 0; k < n/2; k++) {
126  a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
127  f = cos(M_PI * a / (double)(2 * n));
128  sum += f * in[k];
129  }
130  out[i] = REF_SCALE(-sum, nbits - 2);
131  }
132 }
133 
134 /* NOTE: no normalisation by 1 / N is done */
135 static void mdct_ref(FFTSample *output, FFTSample *input, int nbits)
136 {
137  int n = 1<<nbits;
138  int k, i;
139  double a, s;
140 
141  /* do it by hand */
142  for (k = 0; k < n/2; k++) {
143  s = 0;
144  for (i = 0; i < n; i++) {
145  a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n));
146  s += input[i] * cos(a);
147  }
148  output[k] = REF_SCALE(s, nbits - 1);
149  }
150 }
151 #endif /* CONFIG_MDCT */
152 
153 #if FFT_FLOAT
154 #if CONFIG_DCT
155 static void idct_ref(float *output, float *input, int nbits)
156 {
157  int n = 1<<nbits;
158  int k, i;
159  double a, s;
160 
161  /* do it by hand */
162  for (i = 0; i < n; i++) {
163  s = 0.5 * input[0];
164  for (k = 1; k < n; k++) {
165  a = M_PI*k*(i+0.5) / n;
166  s += input[k] * cos(a);
167  }
168  output[i] = 2 * s / n;
169  }
170 }
171 static void dct_ref(float *output, float *input, int nbits)
172 {
173  int n = 1<<nbits;
174  int k, i;
175  double a, s;
176 
177  /* do it by hand */
178  for (k = 0; k < n; k++) {
179  s = 0;
180  for (i = 0; i < n; i++) {
181  a = M_PI*k*(i+0.5) / n;
182  s += input[i] * cos(a);
183  }
184  output[k] = s;
185  }
186 }
187 #endif /* CONFIG_DCT */
188 #endif
189 
190 
191 static FFTSample frandom(AVLFG *prng)
192 {
193  return (int16_t)av_lfg_get(prng) / 32768.0 * RANGE;
194 }
195 
196 static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
197 {
198  int i;
199  double max= 0;
200  double error= 0;
201  int err = 0;
202 
203  for (i = 0; i < n; i++) {
204  double e = fabsf(tab1[i] - (tab2[i] / scale)) / RANGE;
205  if (e >= 1e-3) {
206  av_log(NULL, AV_LOG_ERROR, "ERROR %5d: "FMT" "FMT"\n",
207  i, tab1[i], tab2[i]);
208  err = 1;
209  }
210  error+= e*e;
211  if(e>max) max= e;
212  }
213  av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error)/n);
214  return err;
215 }
216 
217 
218 static void help(void)
219 {
220  av_log(NULL, AV_LOG_INFO,"usage: fft-test [-h] [-s] [-i] [-n b]\n"
221  "-h print this help\n"
222  "-s speed test\n"
223  "-m (I)MDCT test\n"
224  "-d (I)DCT test\n"
225  "-r (I)RDFT test\n"
226  "-i inverse transform test\n"
227  "-n b set the transform size to 2^b\n"
228  "-f x set scale factor for output data of (I)MDCT to x\n"
229  );
230 }
231 
237 };
238 
239 #if !HAVE_GETOPT
240 #include "compat/getopt.c"
241 #endif
242 
243 int main(int argc, char **argv)
244 {
245  FFTComplex *tab, *tab1, *tab_ref;
246  FFTSample *tab2;
247  int it, i, c;
248  int cpuflags;
249  int do_speed = 0;
250  int err = 1;
252  int do_inverse = 0;
253  FFTContext s1, *s = &s1;
254  FFTContext m1, *m = &m1;
255 #if FFT_FLOAT
256  RDFTContext r1, *r = &r1;
257  DCTContext d1, *d = &d1;
258  int fft_size_2;
259 #endif
260  int fft_nbits, fft_size;
261  double scale = 1.0;
262  AVLFG prng;
263  av_lfg_init(&prng, 1);
264 
265  fft_nbits = 9;
266  for(;;) {
267  c = getopt(argc, argv, "hsimrdn:f:c:");
268  if (c == -1)
269  break;
270  switch(c) {
271  case 'h':
272  help();
273  return 1;
274  case 's':
275  do_speed = 1;
276  break;
277  case 'i':
278  do_inverse = 1;
279  break;
280  case 'm':
281  transform = TRANSFORM_MDCT;
282  break;
283  case 'r':
284  transform = TRANSFORM_RDFT;
285  break;
286  case 'd':
287  transform = TRANSFORM_DCT;
288  break;
289  case 'n':
290  fft_nbits = atoi(optarg);
291  break;
292  case 'f':
293  scale = atof(optarg);
294  break;
295  case 'c':
296  cpuflags = av_parse_cpu_flags(optarg);
297  if (cpuflags < 0)
298  return 1;
299  av_set_cpu_flags_mask(cpuflags);
300  break;
301  }
302  }
303 
304  fft_size = 1 << fft_nbits;
305  tab = av_malloc(fft_size * sizeof(FFTComplex));
306  tab1 = av_malloc(fft_size * sizeof(FFTComplex));
307  tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
308  tab2 = av_malloc(fft_size * sizeof(FFTSample));
309 
310  switch (transform) {
311 #if CONFIG_MDCT
312  case TRANSFORM_MDCT:
313  av_log(NULL, AV_LOG_INFO,"Scale factor is set to %f\n", scale);
314  if (do_inverse)
315  av_log(NULL, AV_LOG_INFO,"IMDCT");
316  else
317  av_log(NULL, AV_LOG_INFO,"MDCT");
318  ff_mdct_init(m, fft_nbits, do_inverse, scale);
319  break;
320 #endif /* CONFIG_MDCT */
321  case TRANSFORM_FFT:
322  if (do_inverse)
323  av_log(NULL, AV_LOG_INFO,"IFFT");
324  else
325  av_log(NULL, AV_LOG_INFO,"FFT");
326  ff_fft_init(s, fft_nbits, do_inverse);
327  fft_ref_init(fft_nbits, do_inverse);
328  break;
329 #if FFT_FLOAT
330 #if CONFIG_RDFT
331  case TRANSFORM_RDFT:
332  if (do_inverse)
333  av_log(NULL, AV_LOG_INFO,"IDFT_C2R");
334  else
335  av_log(NULL, AV_LOG_INFO,"DFT_R2C");
336  ff_rdft_init(r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C);
337  fft_ref_init(fft_nbits, do_inverse);
338  break;
339 #endif /* CONFIG_RDFT */
340 #if CONFIG_DCT
341  case TRANSFORM_DCT:
342  if (do_inverse)
343  av_log(NULL, AV_LOG_INFO,"DCT_III");
344  else
345  av_log(NULL, AV_LOG_INFO,"DCT_II");
346  ff_dct_init(d, fft_nbits, do_inverse ? DCT_III : DCT_II);
347  break;
348 #endif /* CONFIG_DCT */
349 #endif
350  default:
351  av_log(NULL, AV_LOG_ERROR, "Requested transform not supported\n");
352  return 1;
353  }
354  av_log(NULL, AV_LOG_INFO," %d test\n", fft_size);
355 
356  /* generate random data */
357 
358  for (i = 0; i < fft_size; i++) {
359  tab1[i].re = frandom(&prng);
360  tab1[i].im = frandom(&prng);
361  }
362 
363  /* checking result */
364  av_log(NULL, AV_LOG_INFO,"Checking...\n");
365 
366  switch (transform) {
367 #if CONFIG_MDCT
368  case TRANSFORM_MDCT:
369  if (do_inverse) {
370  imdct_ref((FFTSample *)tab_ref, (FFTSample *)tab1, fft_nbits);
371  m->imdct_calc(m, tab2, (FFTSample *)tab1);
372  err = check_diff((FFTSample *)tab_ref, tab2, fft_size, scale);
373  } else {
374  mdct_ref((FFTSample *)tab_ref, (FFTSample *)tab1, fft_nbits);
375 
376  m->mdct_calc(m, tab2, (FFTSample *)tab1);
377 
378  err = check_diff((FFTSample *)tab_ref, tab2, fft_size / 2, scale);
379  }
380  break;
381 #endif /* CONFIG_MDCT */
382  case TRANSFORM_FFT:
383  memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
384  s->fft_permute(s, tab);
385  s->fft_calc(s, tab);
386 
387  fft_ref(tab_ref, tab1, fft_nbits);
388  err = check_diff((FFTSample *)tab_ref, (FFTSample *)tab, fft_size * 2, 1.0);
389  break;
390 #if FFT_FLOAT
391 #if CONFIG_RDFT
392  case TRANSFORM_RDFT:
393  fft_size_2 = fft_size >> 1;
394  if (do_inverse) {
395  tab1[ 0].im = 0;
396  tab1[fft_size_2].im = 0;
397  for (i = 1; i < fft_size_2; i++) {
398  tab1[fft_size_2+i].re = tab1[fft_size_2-i].re;
399  tab1[fft_size_2+i].im = -tab1[fft_size_2-i].im;
400  }
401 
402  memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
403  tab2[1] = tab1[fft_size_2].re;
404 
405  r->rdft_calc(r, tab2);
406  fft_ref(tab_ref, tab1, fft_nbits);
407  for (i = 0; i < fft_size; i++) {
408  tab[i].re = tab2[i];
409  tab[i].im = 0;
410  }
411  err = check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 0.5);
412  } else {
413  for (i = 0; i < fft_size; i++) {
414  tab2[i] = tab1[i].re;
415  tab1[i].im = 0;
416  }
417  r->rdft_calc(r, tab2);
418  fft_ref(tab_ref, tab1, fft_nbits);
419  tab_ref[0].im = tab_ref[fft_size_2].re;
420  err = check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0);
421  }
422  break;
423 #endif /* CONFIG_RDFT */
424 #if CONFIG_DCT
425  case TRANSFORM_DCT:
426  memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
427  d->dct_calc(d, tab);
428  if (do_inverse) {
429  idct_ref(tab_ref, tab1, fft_nbits);
430  } else {
431  dct_ref(tab_ref, tab1, fft_nbits);
432  }
433  err = check_diff((float *)tab_ref, (float *)tab, fft_size, 1.0);
434  break;
435 #endif /* CONFIG_DCT */
436 #endif
437  }
438 
439  /* do a speed test */
440 
441  if (do_speed) {
442  int64_t time_start, duration;
443  int nb_its;
444 
445  av_log(NULL, AV_LOG_INFO,"Speed test...\n");
446  /* we measure during about 1 seconds */
447  nb_its = 1;
448  for(;;) {
449  time_start = av_gettime();
450  for (it = 0; it < nb_its; it++) {
451  switch (transform) {
452  case TRANSFORM_MDCT:
453  if (do_inverse) {
454  m->imdct_calc(m, (FFTSample *)tab, (FFTSample *)tab1);
455  } else {
456  m->mdct_calc(m, (FFTSample *)tab, (FFTSample *)tab1);
457  }
458  break;
459  case TRANSFORM_FFT:
460  memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
461  s->fft_calc(s, tab);
462  break;
463 #if FFT_FLOAT
464  case TRANSFORM_RDFT:
465  memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
466  r->rdft_calc(r, tab2);
467  break;
468  case TRANSFORM_DCT:
469  memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
470  d->dct_calc(d, tab2);
471  break;
472 #endif
473  }
474  }
475  duration = av_gettime() - time_start;
476  if (duration >= 1000000)
477  break;
478  nb_its *= 2;
479  }
480  av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
481  (double)duration / nb_its,
482  (double)duration / 1000000.0,
483  nb_its);
484  }
485 
486  switch (transform) {
487 #if CONFIG_MDCT
488  case TRANSFORM_MDCT:
489  ff_mdct_end(m);
490  break;
491 #endif /* CONFIG_MDCT */
492  case TRANSFORM_FFT:
493  ff_fft_end(s);
494  break;
495 #if FFT_FLOAT
496 #if CONFIG_RDFT
497  case TRANSFORM_RDFT:
498  ff_rdft_end(r);
499  break;
500 #endif /* CONFIG_RDFT */
501 #if CONFIG_DCT
502  case TRANSFORM_DCT:
503  ff_dct_end(d);
504  break;
505 #endif /* CONFIG_DCT */
506 #endif
507  }
508 
509  av_free(tab);
510  av_free(tab1);
511  av_free(tab2);
512  av_free(tab_ref);
513  av_free(exptab);
514 
515  if (err)
516  printf("Error: %d.\n", err);
517 
518  return !!err;
519 }
Definition: lfg.h:25
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:130
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
Definition: dct.h:37
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:83
Definition: avfft.h:95
void av_set_cpu_flags_mask(int mask)
Set a mask on flags returned by av_get_cpu_flags().
Definition: cpu.c:69
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
Definition: fft.h:75
FFTSample re
Definition: avfft.h:38
static int64_t duration
Definition: avplay.c:246
tf_transform
Definition: fft-test.c:232
static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
Definition: fft-test.c:87
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int av_parse_cpu_flags(const char *s)
Parse CPU flags from a string.
Definition: cpu.c:75
static void help(void)
Definition: fft-test.c:218
#define r
Definition: input.c:51
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
struct @17 * exptab
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static FFTSample frandom(AVLFG *prng)
Definition: fft-test.c:191
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
Definition: avfft.h:73
#define ff_mdct_init
Definition: fft.h:144
float FFTSample
Definition: avfft.h:35
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
Definition: rdft.h:60
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:81
Definition: fft.h:62
static void fft_ref_init(int nbits, int inverse)
Definition: fft-test.c:68
#define CMAC(pre, pim, are, aim, bre, bim)
Definition: fft-test.c:48
#define ff_fft_init
Definition: fft.h:126
Definition: dct.h:31
Definition: avfft.h:72
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:37
#define REF_SCALE(x, bits)
Definition: fft-test.c:56
static const int8_t transform[32][32]
Definition: hevcdsp.c:25
NULL
Definition: eval.c:55
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
float im
Definition: fft-test.c:65
static int getopt(int argc, char *argv[], char *opts)
Definition: getopt.c:41
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:38
const int16_t * tab1
Definition: mace.c:144
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
Definition: dct.c:177
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:30
#define FMT
Definition: fft-test.c:57
static const uint16_t scale[4]
#define RANGE
Definition: fft-test.c:55
int main(int argc, char **argv)
Definition: fft-test.c:243
FFTSample im
Definition: avfft.h:38
#define ff_mdct_end
Definition: fft.h:145
#define ff_fft_end
Definition: fft.h:127
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
Definition: fft.h:80
Definition: avfft.h:94
static char * optarg
Definition: getopt.c:39
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
Definition: fft-test.c:196
float re
Definition: fft-test.c:65
av_cold void ff_dct_end(DCTContext *s)
Definition: dct.c:218
static const struct twinvq_data tab
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
Definition: asfcrypt.c:35
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
Definition: rdft.c:99
const int16_t * tab2
Definition: mace.c:144
#define c1
Definition: idct_sh4.c:26