annotate fft-test.c @ 11209:8173c059f769 libavcodec

Do sequential bit reading outside of []-operators.
author thilo.borgmann
date Fri, 19 Feb 2010 08:07:02 +0000
parents 0985f1f7ab72
children 4a8900c06c67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
1 /*
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
2 * (c) 2002 Fabrice Bellard
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
3 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
4 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
5 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
8 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
10 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
14 * Lesser General Public License for more details.
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
15 *
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
19 */
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2967
diff changeset
20
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
21 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 7546
diff changeset
22 * @file libavcodec/fft-test.c
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
23 * FFT and MDCT tests.
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
24 */
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
25
9199
ea0e5e9a520f Replace random() usage in test programs by av_lfg_*().
diego
parents: 8718
diff changeset
26 #include "libavutil/lfg.h"
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
27 #include "dsputil.h"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
28 #include <math.h>
980
0c32f81b42b2 suppressed getopt.h
bellard
parents: 969
diff changeset
29 #include <unistd.h>
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
30 #include <sys/time.h>
5118
3b190bc34546 Add some #includes to allow compilation without HAVE_AV_CONFIG_H.
diego
parents: 4760
diff changeset
31 #include <stdlib.h>
3b190bc34546 Add some #includes to allow compilation without HAVE_AV_CONFIG_H.
diego
parents: 4760
diff changeset
32 #include <string.h>
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
33
4760
e82ceaa9c386 Add '#undef exit', the function is now forbidden.
diego
parents: 3947
diff changeset
34 #undef exit
e82ceaa9c386 Add '#undef exit', the function is now forbidden.
diego
parents: 3947
diff changeset
35
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
36 /* reference fft */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
37
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
38 #define MUL16(a,b) ((a) * (b))
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
39
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
40 #define CMAC(pre, pim, are, aim, bre, bim) \
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 pre += (MUL16(are, bre) - MUL16(aim, bim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
43 pim += (MUL16(are, bim) + MUL16(bre, aim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
44 }
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 FFTComplex *exptab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
47
9295
b225f51903af Mark non-exported functions in test and example programs as static.
diego
parents: 9199
diff changeset
48 static void fft_ref_init(int nbits, int inverse)
781
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 int n, i;
5418
95234f2e0bdd make the reference code use double instead of float where it is easy
michael
parents: 5417
diff changeset
51 double c1, s1, alpha;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
52
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
53 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
54 exptab = av_malloc((n / 2) * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
55
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
56 for (i = 0; i < (n/2); i++) {
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
57 alpha = 2 * M_PI * (float)i / (float)n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
58 c1 = cos(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
59 s1 = sin(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
60 if (!inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
61 s1 = -s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
62 exptab[i].re = c1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
63 exptab[i].im = s1;
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 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
66
9295
b225f51903af Mark non-exported functions in test and example programs as static.
diego
parents: 9199
diff changeset
67 static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
68 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
69 int n, i, j, k, n2;
5418
95234f2e0bdd make the reference code use double instead of float where it is easy
michael
parents: 5417
diff changeset
70 double tmp_re, tmp_im, s, c;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
71 FFTComplex *q;
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 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
74 n2 = n >> 1;
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
75 for (i = 0; i < n; i++) {
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
76 tmp_re = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
77 tmp_im = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
78 q = tab;
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
79 for (j = 0; j < n; j++) {
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
80 k = (i * j) & (n - 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
81 if (k >= n2) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
82 c = -exptab[k - n2].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
83 s = -exptab[k - n2].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
84 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
85 c = exptab[k].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
86 s = exptab[k].im;
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 CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
89 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
90 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
91 tabr[i].re = tmp_re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
92 tabr[i].im = tmp_im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
93 }
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
9295
b225f51903af Mark non-exported functions in test and example programs as static.
diego
parents: 9199
diff changeset
96 static void imdct_ref(float *out, float *in, int nbits)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
97 {
5442
f5d2349dccd7 making reference models have the same API
mhoffman
parents: 5418
diff changeset
98 int n = 1<<nbits;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
99 int k, i, a;
5418
95234f2e0bdd make the reference code use double instead of float where it is easy
michael
parents: 5417
diff changeset
100 double sum, f;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
101
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
102 for (i = 0; i < n; i++) {
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
103 sum = 0;
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
104 for (k = 0; k < n/2; k++) {
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
105 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
106 f = cos(M_PI * a / (double)(2 * n));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
107 sum += f * in[k];
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 out[i] = -sum;
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 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
112
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
113 /* NOTE: no normalisation by 1 / N is done */
9295
b225f51903af Mark non-exported functions in test and example programs as static.
diego
parents: 9199
diff changeset
114 static void mdct_ref(float *output, float *input, int nbits)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
115 {
5442
f5d2349dccd7 making reference models have the same API
mhoffman
parents: 5418
diff changeset
116 int n = 1<<nbits;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
117 int k, i;
5418
95234f2e0bdd make the reference code use double instead of float where it is easy
michael
parents: 5417
diff changeset
118 double a, s;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
119
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
120 /* do it by hand */
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
121 for (k = 0; k < n/2; k++) {
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
122 s = 0;
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
123 for (i = 0; i < n; i++) {
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
124 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
125 s += input[i] * cos(a);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
126 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
127 output[k] = s;
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
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
131 static void idct_ref(float *output, float *input, int nbits)
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
132 {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
133 int n = 1<<nbits;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
134 int k, i;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
135 double a, s;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
136
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
137 /* do it by hand */
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
138 for (i = 0; i < n; i++) {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
139 s = 0.5 * input[0];
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
140 for (k = 1; k < n; k++) {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
141 a = M_PI*k*(i+0.5) / n;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
142 s += input[k] * cos(a);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
143 }
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
144 output[i] = 2 * s / n;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
145 }
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
146 }
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
147 static void dct_ref(float *output, float *input, int nbits)
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
148 {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
149 int n = 1<<nbits;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
150 int k, i;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
151 double a, s;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
152
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
153 /* do it by hand */
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
154 for (k = 0; k < n; k++) {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
155 s = 0;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
156 for (i = 0; i < n; i++) {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
157 a = M_PI*k*(i+0.5) / n;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
158 s += input[i] * cos(a);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
159 }
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
160 output[k] = s;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
161 }
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
162 }
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
163
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
164
10074
c4a83f3a5c9f bring back some randomness in fft-test. (regression in r18070)
lorenm
parents: 9674
diff changeset
165 static float frandom(AVLFG *prng)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
166 {
10074
c4a83f3a5c9f bring back some randomness in fft-test. (regression in r18070)
lorenm
parents: 9674
diff changeset
167 return (int16_t)av_lfg_get(prng) / 32768.0;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
168 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
169
9295
b225f51903af Mark non-exported functions in test and example programs as static.
diego
parents: 9199
diff changeset
170 static int64_t gettime(void)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
171 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
172 struct timeval tv;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
173 gettimeofday(&tv,NULL);
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
174 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
175 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
176
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
177 static void check_diff(float *tab1, float *tab2, int n, double scale)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
178 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
179 int i;
5417
3eca9008175b print max and mse
michael
parents: 5379
diff changeset
180 double max= 0;
3eca9008175b print max and mse
michael
parents: 5379
diff changeset
181 double error= 0;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
182
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
183 for (i = 0; i < n; i++) {
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
184 double e= fabsf(tab1[i] - (tab2[i] / scale));
5417
3eca9008175b print max and mse
michael
parents: 5379
diff changeset
185 if (e >= 1e-3) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
186 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
187 i, tab1[i], tab2[i]);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
188 }
5417
3eca9008175b print max and mse
michael
parents: 5379
diff changeset
189 error+= e*e;
3eca9008175b print max and mse
michael
parents: 5379
diff changeset
190 if(e>max) max= e;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
191 }
5417
3eca9008175b print max and mse
michael
parents: 5379
diff changeset
192 av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error)/n);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
193 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
194
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
195
9295
b225f51903af Mark non-exported functions in test and example programs as static.
diego
parents: 9199
diff changeset
196 static void help(void)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
197 {
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,"usage: fft-test [-h] [-s] [-i] [-n b]\n"
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
199 "-h print this help\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
200 "-s speed test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
201 "-m (I)MDCT test\n"
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
202 "-d (I)DCT test\n"
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
203 "-i inverse transform test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
204 "-n b set the transform size to 2^b\n"
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
205 "-f x set scale factor for output data of (I)MDCT to x\n"
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
206 );
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
207 exit(1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
208 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
209
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
210 enum tf_transform {
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
211 TRANSFORM_FFT,
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
212 TRANSFORM_MDCT,
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
213 TRANSFORM_RDFT,
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
214 TRANSFORM_DCT,
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
215 };
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
216
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
217 int main(int argc, char **argv)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
218 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
219 FFTComplex *tab, *tab1, *tab_ref;
7546
97383e012cb9 remove mdct tmp buffer
lorenm
parents: 7141
diff changeset
220 FFTSample *tab2;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
221 int it, i, c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
222 int do_speed = 0;
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
223 enum tf_transform transform = TRANSFORM_FFT;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
224 int do_inverse = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
225 FFTContext s1, *s = &s1;
10199
38ab367d4231 Merge FFTContext and MDCTContext
mru
parents: 10074
diff changeset
226 FFTContext m1, *m = &m1;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
227 RDFTContext r1, *r = &r1;
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
228 DCTContext d1, *d = &d1;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
229 int fft_nbits, fft_size, fft_size_2;
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
230 double scale = 1.0;
10074
c4a83f3a5c9f bring back some randomness in fft-test. (regression in r18070)
lorenm
parents: 9674
diff changeset
231 AVLFG prng;
c4a83f3a5c9f bring back some randomness in fft-test. (regression in r18070)
lorenm
parents: 9674
diff changeset
232 av_lfg_init(&prng, 1);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
233
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
234 fft_nbits = 9;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
235 for(;;) {
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
236 c = getopt(argc, argv, "hsimrdn:f:");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
237 if (c == -1)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
238 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
239 switch(c) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
240 case 'h':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
241 help();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
242 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
243 case 's':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
244 do_speed = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
245 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
246 case 'i':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
247 do_inverse = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
248 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
249 case 'm':
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
250 transform = TRANSFORM_MDCT;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
251 break;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
252 case 'r':
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
253 transform = TRANSFORM_RDFT;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
254 break;
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
255 case 'd':
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
256 transform = TRANSFORM_DCT;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
257 break;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
258 case 'n':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
259 fft_nbits = atoi(optarg);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
260 break;
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
261 case 'f':
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
262 scale = atof(optarg);
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
263 break;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
264 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
265 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
266
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
267 fft_size = 1 << fft_nbits;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
268 fft_size_2 = fft_size >> 1;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
269 tab = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
270 tab1 = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
271 tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
272 tab2 = av_malloc(fft_size * sizeof(FFTSample));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
273
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
274 switch (transform) {
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
275 case TRANSFORM_MDCT:
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
276 av_log(NULL, AV_LOG_INFO,"Scale factor is set to %f\n", scale);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
277 if (do_inverse)
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
278 av_log(NULL, AV_LOG_INFO,"IMDCT");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
279 else
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
280 av_log(NULL, AV_LOG_INFO,"MDCT");
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
281 ff_mdct_init(m, fft_nbits, do_inverse, scale);
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
282 break;
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
283 case TRANSFORM_FFT:
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
284 if (do_inverse)
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
285 av_log(NULL, AV_LOG_INFO,"IFFT");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
286 else
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
287 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
288 ff_fft_init(s, fft_nbits, do_inverse);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
289 fft_ref_init(fft_nbits, do_inverse);
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
290 break;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
291 case TRANSFORM_RDFT:
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
292 if (do_inverse)
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
293 av_log(NULL, AV_LOG_INFO,"IRDFT");
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
294 else
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
295 av_log(NULL, AV_LOG_INFO,"RDFT");
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
296 ff_rdft_init(r, fft_nbits, do_inverse ? IRDFT : RDFT);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
297 fft_ref_init(fft_nbits, do_inverse);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
298 break;
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
299 case TRANSFORM_DCT:
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
300 if (do_inverse)
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
301 av_log(NULL, AV_LOG_INFO,"IDCT");
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
302 else
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
303 av_log(NULL, AV_LOG_INFO,"DCT");
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
304 ff_dct_init(d, fft_nbits, do_inverse);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
305 break;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
306 }
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
307 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
308
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
309 /* generate random data */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
310
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
311 for (i = 0; i < fft_size; i++) {
10074
c4a83f3a5c9f bring back some randomness in fft-test. (regression in r18070)
lorenm
parents: 9674
diff changeset
312 tab1[i].re = frandom(&prng);
c4a83f3a5c9f bring back some randomness in fft-test. (regression in r18070)
lorenm
parents: 9674
diff changeset
313 tab1[i].im = frandom(&prng);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
314 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
315
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
316 /* checking result */
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
317 av_log(NULL, AV_LOG_INFO,"Checking...\n");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
318
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
319 switch (transform) {
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
320 case TRANSFORM_MDCT:
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
321 if (do_inverse) {
5442
f5d2349dccd7 making reference models have the same API
mhoffman
parents: 5418
diff changeset
322 imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits);
7546
97383e012cb9 remove mdct tmp buffer
lorenm
parents: 7141
diff changeset
323 ff_imdct_calc(m, tab2, (float *)tab1);
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
324 check_diff((float *)tab_ref, tab2, fft_size, scale);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
325 } else {
5442
f5d2349dccd7 making reference models have the same API
mhoffman
parents: 5418
diff changeset
326 mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
327
7546
97383e012cb9 remove mdct tmp buffer
lorenm
parents: 7141
diff changeset
328 ff_mdct_calc(m, tab2, (float *)tab1);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
329
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
330 check_diff((float *)tab_ref, tab2, fft_size / 2, scale);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
331 }
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
332 break;
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
333 case TRANSFORM_FFT:
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
334 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
335 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
336 ff_fft_calc(s, tab);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
337
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
338 fft_ref(tab_ref, tab1, fft_nbits);
9674
dac20d8df581 Support for testing (i)MDCT output scale factor in fft-test tool.
serge
parents: 9658
diff changeset
339 check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 1.0);
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
340 break;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
341 case TRANSFORM_RDFT:
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
342 if (do_inverse) {
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
343 tab1[ 0].im = 0;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
344 tab1[fft_size_2].im = 0;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
345 for (i = 1; i < fft_size_2; i++) {
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
346 tab1[fft_size_2+i].re = tab1[fft_size_2-i].re;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
347 tab1[fft_size_2+i].im = -tab1[fft_size_2-i].im;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
348 }
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
349
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
350 memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
351 tab2[1] = tab1[fft_size_2].re;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
352
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
353 ff_rdft_calc(r, tab2);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
354 fft_ref(tab_ref, tab1, fft_nbits);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
355 for (i = 0; i < fft_size; i++) {
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
356 tab[i].re = tab2[i];
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
357 tab[i].im = 0;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
358 }
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
359 check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 0.5);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
360 } else {
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
361 for (i = 0; i < fft_size; i++) {
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
362 tab2[i] = tab1[i].re;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
363 tab1[i].im = 0;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
364 }
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
365 ff_rdft_calc(r, tab2);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
366 fft_ref(tab_ref, tab1, fft_nbits);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
367 tab_ref[0].im = tab_ref[fft_size_2].re;
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
368 check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
369 }
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
370 break;
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
371 case TRANSFORM_DCT:
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
372 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
373 ff_dct_calc(d, tab);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
374 if (do_inverse) {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
375 idct_ref(tab_ref, tab1, fft_nbits);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
376 } else {
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
377 dct_ref(tab_ref, tab1, fft_nbits);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
378 }
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
379 check_diff((float *)tab_ref, (float *)tab, fft_size, 1.0);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
380 break;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
381 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
382
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
383 /* do a speed test */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
384
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
385 if (do_speed) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
386 int64_t time_start, duration;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
387 int nb_its;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
388
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
389 av_log(NULL, AV_LOG_INFO,"Speed test...\n");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
390 /* we measure during about 1 seconds */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
391 nb_its = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
392 for(;;) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
393 time_start = gettime();
10807
4578f774a775 fft-test: whitespace cosmetics
alexc
parents: 10199
diff changeset
394 for (it = 0; it < nb_its; it++) {
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
395 switch (transform) {
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
396 case TRANSFORM_MDCT:
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
397 if (do_inverse) {
7546
97383e012cb9 remove mdct tmp buffer
lorenm
parents: 7141
diff changeset
398 ff_imdct_calc(m, (float *)tab, (float *)tab1);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
399 } else {
7546
97383e012cb9 remove mdct tmp buffer
lorenm
parents: 7141
diff changeset
400 ff_mdct_calc(m, (float *)tab, (float *)tab1);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
401 }
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
402 break;
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
403 case TRANSFORM_FFT:
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
404 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
405 ff_fft_calc(s, tab);
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
406 break;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
407 case TRANSFORM_RDFT:
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
408 memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
409 ff_rdft_calc(r, tab2);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
410 break;
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
411 case TRANSFORM_DCT:
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
412 memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
413 ff_dct_calc(d, tab2);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
414 break;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
415 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
416 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
417 duration = gettime() - time_start;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
418 if (duration >= 1000000)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
419 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
420 nb_its *= 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
421 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
422 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
423 (double)duration / nb_its,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
424 (double)duration / 1000000.0,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
425 nb_its);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
426 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
427
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
428 switch (transform) {
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
429 case TRANSFORM_MDCT:
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
430 ff_mdct_end(m);
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
431 break;
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
432 case TRANSFORM_FFT:
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
433 ff_fft_end(s);
10846
8dbceaa5fa2f fft-test: Replace do_mdct with a tf_transform enum and switch on it.
alexc
parents: 10807
diff changeset
434 break;
10847
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
435 case TRANSFORM_RDFT:
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
436 ff_rdft_end(r);
177ebc61c3d6 fft-test: Add RDFT/IRDFT support.
alexc
parents: 10846
diff changeset
437 break;
10944
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
438 case TRANSFORM_DCT:
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
439 ff_dct_end(d);
0985f1f7ab72 Floating point discrete cosine transform
vitor
parents: 10847
diff changeset
440 break;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
441 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
442 return 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
443 }