annotate fft-test.c @ 3096:966b3f321af0 libavcodec

10l (x86_64)
author lorenm
date Tue, 07 Feb 2006 16:10:48 +0000
parents ef2149182f1c
children c537a97eec66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
1 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
2 * @file fft-test.c
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
3 * FFT and MDCT tests.
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
4 */
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
5
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
6 #include "dsputil.h"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
7 #include <math.h>
980
0c32f81b42b2 suppressed getopt.h
bellard
parents: 969
diff changeset
8 #include <unistd.h>
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
9 #include <sys/time.h>
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
10
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
11 int mm_flags;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
12
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
13 /* reference fft */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
14
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
15 #define MUL16(a,b) ((a) * (b))
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
16
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
17 #define CMAC(pre, pim, are, aim, bre, bim) \
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
18 {\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
19 pre += (MUL16(are, bre) - MUL16(aim, bim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
20 pim += (MUL16(are, bim) + MUL16(bre, aim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
21 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
22
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
23 FFTComplex *exptab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
24
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
25 void fft_ref_init(int nbits, int inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
26 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
27 int n, i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
28 float c1, s1, alpha;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
29
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
30 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
31 exptab = av_malloc((n / 2) * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
32
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
33 for(i=0;i<(n/2);i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
34 alpha = 2 * M_PI * (float)i / (float)n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
35 c1 = cos(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
36 s1 = sin(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
37 if (!inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
38 s1 = -s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
39 exptab[i].re = c1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
40 exptab[i].im = s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
41 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
42 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
43
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
44 void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
45 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
46 int n, i, j, k, n2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
47 float tmp_re, tmp_im, s, c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
48 FFTComplex *q;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
49
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
50 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
51 n2 = n >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
52 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
53 tmp_re = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
54 tmp_im = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
55 q = tab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
56 for(j=0;j<n;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
57 k = (i * j) & (n - 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
58 if (k >= n2) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
59 c = -exptab[k - n2].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
60 s = -exptab[k - n2].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
61 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
62 c = exptab[k].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
63 s = exptab[k].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
64 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
65 CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
66 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
67 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
68 tabr[i].re = tmp_re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
69 tabr[i].im = tmp_im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
70 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
71 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
72
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
73 void imdct_ref(float *out, float *in, int n)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
74 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
75 int k, i, a;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
76 float sum, f;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
77
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
78 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
79 sum = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
80 for(k=0;k<n/2;k++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
81 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
82 f = cos(M_PI * a / (double)(2 * n));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
83 sum += f * in[k];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
84 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
85 out[i] = -sum;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
86 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
87 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
88
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
89 /* NOTE: no normalisation by 1 / N is done */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
90 void mdct_ref(float *output, float *input, int n)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
91 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
92 int k, i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
93 float a, s;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
94
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
95 /* do it by hand */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
96 for(k=0;k<n/2;k++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
97 s = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
98 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
99 a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
100 s += input[i] * cos(a);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
101 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
102 output[k] = s;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
103 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
104 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
105
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
106
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
107 float frandom(void)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
108 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
109 return (float)((random() & 0xffff) - 32768) / 32768.0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
110 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
111
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
112 int64_t gettime(void)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
113 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
114 struct timeval tv;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
115 gettimeofday(&tv,NULL);
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
116 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
117 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
118
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
119 void check_diff(float *tab1, float *tab2, int n)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
120 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
121 int i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
122
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
123 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
124 if (fabsf(tab1[i] - tab2[i]) >= 1e-3) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
125 av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n",
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
126 i, tab1[i], tab2[i]);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
127 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
128 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
129 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
130
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
131
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
132 void help(void)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
133 {
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
134 av_log(NULL, AV_LOG_INFO,"usage: fft-test [-h] [-s] [-i] [-n b]\n"
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
135 "-h print this help\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
136 "-s speed test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
137 "-m (I)MDCT test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
138 "-i inverse transform test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
139 "-n b set the transform size to 2^b\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
140 );
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
141 exit(1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
142 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
143
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
144
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
145
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
146 int main(int argc, char **argv)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
147 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
148 FFTComplex *tab, *tab1, *tab_ref;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
149 FFTSample *tabtmp, *tab2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
150 int it, i, c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
151 int do_speed = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
152 int do_mdct = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
153 int do_inverse = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
154 FFTContext s1, *s = &s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
155 MDCTContext m1, *m = &m1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
156 int fft_nbits, fft_size;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
157
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
158 mm_flags = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
159 fft_nbits = 9;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
160 for(;;) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
161 c = getopt(argc, argv, "hsimn:");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
162 if (c == -1)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
163 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
164 switch(c) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
165 case 'h':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
166 help();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
167 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
168 case 's':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
169 do_speed = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
170 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
171 case 'i':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
172 do_inverse = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
173 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
174 case 'm':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
175 do_mdct = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
176 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
177 case 'n':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
178 fft_nbits = atoi(optarg);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
179 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
180 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
181 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
182
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
183 fft_size = 1 << fft_nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
184 tab = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
185 tab1 = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
186 tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
187 tabtmp = av_malloc(fft_size / 2 * sizeof(FFTSample));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
188 tab2 = av_malloc(fft_size * sizeof(FFTSample));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
189
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
190 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
191 if (do_inverse)
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
192 av_log(NULL, AV_LOG_INFO,"IMDCT");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
193 else
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
194 av_log(NULL, AV_LOG_INFO,"MDCT");
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
195 ff_mdct_init(m, fft_nbits, do_inverse);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
196 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
197 if (do_inverse)
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
198 av_log(NULL, AV_LOG_INFO,"IFFT");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
199 else
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
200 av_log(NULL, AV_LOG_INFO,"FFT");
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
201 ff_fft_init(s, fft_nbits, do_inverse);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
202 fft_ref_init(fft_nbits, do_inverse);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
203 }
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
204 av_log(NULL, AV_LOG_INFO," %d test\n", fft_size);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
205
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
206 /* generate random data */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
207
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
208 for(i=0;i<fft_size;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
209 tab1[i].re = frandom();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
210 tab1[i].im = frandom();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
211 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
212
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
213 /* checking result */
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
214 av_log(NULL, AV_LOG_INFO,"Checking...\n");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
215
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
216 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
217 if (do_inverse) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
218 imdct_ref((float *)tab_ref, (float *)tab1, fft_size);
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
219 ff_imdct_calc(m, tab2, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
220 check_diff((float *)tab_ref, tab2, fft_size);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
221 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
222 mdct_ref((float *)tab_ref, (float *)tab1, fft_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
223
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
224 ff_mdct_calc(m, tab2, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
225
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
226 check_diff((float *)tab_ref, tab2, fft_size / 2);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
227 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
228 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
229 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
230 ff_fft_permute(s, tab);
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
231 ff_fft_calc(s, tab);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
232
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
233 fft_ref(tab_ref, tab1, fft_nbits);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
234 check_diff((float *)tab_ref, (float *)tab, fft_size * 2);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
235 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
236
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
237 /* do a speed test */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
238
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
239 if (do_speed) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
240 int64_t time_start, duration;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
241 int nb_its;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
242
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
243 av_log(NULL, AV_LOG_INFO,"Speed test...\n");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
244 /* we measure during about 1 seconds */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
245 nb_its = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
246 for(;;) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
247 time_start = gettime();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
248 for(it=0;it<nb_its;it++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
249 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
250 if (do_inverse) {
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
251 ff_imdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
252 } else {
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
253 ff_mdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
254 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
255 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
256 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
257 ff_fft_calc(s, tab);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
258 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
259 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
260 duration = gettime() - time_start;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
261 if (duration >= 1000000)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
262 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
263 nb_its *= 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
264 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
265 av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
266 (double)duration / nb_its,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
267 (double)duration / 1000000.0,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
268 nb_its);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
269 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
270
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
271 if (do_mdct) {
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
272 ff_mdct_end(m);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
273 } else {
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
274 ff_fft_end(s);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
275 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
276 return 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
277 }