annotate fft-test.c @ 5382:7f96f6e16f81 libavcodec

Return AVERROR(ENOMEM) on memory allocation failure of avcodec_open.
author takis
date Fri, 20 Jul 2007 15:08:10 +0000
parents e9f8a337c5ce
children 3eca9008175b
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 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
22 * @file fft-test.c
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
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
26 #include "dsputil.h"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
27 #include <math.h>
980
0c32f81b42b2 suppressed getopt.h
bellard
parents: 969
diff changeset
28 #include <unistd.h>
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
29 #include <sys/time.h>
5118
3b190bc34546 Add some #includes to allow compilation without HAVE_AV_CONFIG_H.
diego
parents: 4760
diff changeset
30 #include <stdlib.h>
3b190bc34546 Add some #includes to allow compilation without HAVE_AV_CONFIG_H.
diego
parents: 4760
diff changeset
31 #include <string.h>
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
32
4760
e82ceaa9c386 Add '#undef exit', the function is now forbidden.
diego
parents: 3947
diff changeset
33 #undef exit
5379
e9f8a337c5ce Fix the compilation of dct-test, fft-test and motion-test which are using
takis
parents: 5118
diff changeset
34 #undef random
4760
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 int mm_flags;
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 /* reference fft */
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 MUL16(a,b) ((a) * (b))
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 #define CMAC(pre, pim, are, aim, bre, bim) \
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 pre += (MUL16(are, bre) - MUL16(aim, bim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
45 pim += (MUL16(are, bim) + MUL16(bre, aim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
46 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
47
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
48 FFTComplex *exptab;
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 void fft_ref_init(int nbits, int inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
51 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
52 int n, i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
53 float c1, s1, alpha;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
54
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
55 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
56 exptab = av_malloc((n / 2) * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
57
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
58 for(i=0;i<(n/2);i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
59 alpha = 2 * M_PI * (float)i / (float)n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
60 c1 = cos(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
61 s1 = sin(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
62 if (!inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
63 s1 = -s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
64 exptab[i].re = c1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
65 exptab[i].im = s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
66 }
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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
69 void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
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 int n, i, j, k, n2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
72 float tmp_re, tmp_im, s, c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
73 FFTComplex *q;
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 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
76 n2 = n >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
77 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
78 tmp_re = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
79 tmp_im = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
80 q = tab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
81 for(j=0;j<n;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
82 k = (i * j) & (n - 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
83 if (k >= n2) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
84 c = -exptab[k - n2].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
85 s = -exptab[k - n2].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
86 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
87 c = exptab[k].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
88 s = exptab[k].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
89 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
90 CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
91 q++;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
92 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
93 tabr[i].re = tmp_re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
94 tabr[i].im = tmp_im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
95 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
96 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
97
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
98 void imdct_ref(float *out, float *in, int n)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
99 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
100 int k, i, a;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
101 float sum, f;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
102
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
103 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
104 sum = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
105 for(k=0;k<n/2;k++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
106 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
107 f = cos(M_PI * a / (double)(2 * n));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
108 sum += f * in[k];
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
109 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
110 out[i] = -sum;
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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
114 /* NOTE: no normalisation by 1 / N is done */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
115 void mdct_ref(float *output, float *input, int n)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
116 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
117 int k, i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
118 float a, s;
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 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
121 for(k=0;k<n/2;k++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
122 s = 0;
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 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
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 float frandom(void)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
133 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
134 return (float)((random() & 0xffff) - 32768) / 32768.0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
135 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
136
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
137 int64_t gettime(void)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
138 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
139 struct timeval tv;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
140 gettimeofday(&tv,NULL);
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
141 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
781
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 void check_diff(float *tab1, float *tab2, int n)
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 i;
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 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
149 if (fabsf(tab1[i] - tab2[i]) >= 1e-3) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
150 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
151 i, tab1[i], tab2[i]);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
152 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
153 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
154 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
155
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
156
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
157 void help(void)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
158 {
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
159 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
160 "-h print this help\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
161 "-s speed test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
162 "-m (I)MDCT test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
163 "-i inverse transform test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
164 "-n b set the transform size to 2^b\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
165 );
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
166 exit(1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
167 }
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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
170
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
171 int main(int argc, char **argv)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
172 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
173 FFTComplex *tab, *tab1, *tab_ref;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
174 FFTSample *tabtmp, *tab2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
175 int it, i, c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
176 int do_speed = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
177 int do_mdct = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
178 int do_inverse = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
179 FFTContext s1, *s = &s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
180 MDCTContext m1, *m = &m1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
181 int fft_nbits, fft_size;
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 mm_flags = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
184 fft_nbits = 9;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
185 for(;;) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
186 c = getopt(argc, argv, "hsimn:");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
187 if (c == -1)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
188 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
189 switch(c) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
190 case 'h':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
191 help();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
192 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
193 case 's':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
194 do_speed = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
195 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
196 case 'i':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
197 do_inverse = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
198 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
199 case 'm':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
200 do_mdct = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
201 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
202 case 'n':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
203 fft_nbits = atoi(optarg);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
204 break;
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 }
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 fft_size = 1 << fft_nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
209 tab = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
210 tab1 = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
211 tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
212 tabtmp = av_malloc(fft_size / 2 * sizeof(FFTSample));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
213 tab2 = av_malloc(fft_size * sizeof(FFTSample));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
214
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
215 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
216 if (do_inverse)
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
217 av_log(NULL, AV_LOG_INFO,"IMDCT");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
218 else
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
219 av_log(NULL, AV_LOG_INFO,"MDCT");
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
220 ff_mdct_init(m, fft_nbits, do_inverse);
781
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 if (do_inverse)
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
223 av_log(NULL, AV_LOG_INFO,"IFFT");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
224 else
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
225 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
226 ff_fft_init(s, fft_nbits, do_inverse);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
227 fft_ref_init(fft_nbits, do_inverse);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
228 }
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
229 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
230
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
231 /* generate random data */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
232
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
233 for(i=0;i<fft_size;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
234 tab1[i].re = frandom();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
235 tab1[i].im = frandom();
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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
238 /* checking result */
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
239 av_log(NULL, AV_LOG_INFO,"Checking...\n");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
240
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
241 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
242 if (do_inverse) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
243 imdct_ref((float *)tab_ref, (float *)tab1, fft_size);
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
244 ff_imdct_calc(m, tab2, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
245 check_diff((float *)tab_ref, tab2, fft_size);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
246 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
247 mdct_ref((float *)tab_ref, (float *)tab1, fft_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
248
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
249 ff_mdct_calc(m, tab2, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
250
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
251 check_diff((float *)tab_ref, tab2, fft_size / 2);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
252 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
253 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
254 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
255 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
256 ff_fft_calc(s, tab);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
257
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
258 fft_ref(tab_ref, tab1, fft_nbits);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
259 check_diff((float *)tab_ref, (float *)tab, fft_size * 2);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
260 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
261
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
262 /* do a speed test */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
263
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
264 if (do_speed) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 980
diff changeset
265 int64_t time_start, duration;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
266 int nb_its;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
267
2593
786ccf72ccd5 printf -> av_log patch by (Benjamin Larsson <>banan student.ltu se)
michael
parents: 1879
diff changeset
268 av_log(NULL, AV_LOG_INFO,"Speed test...\n");
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
269 /* we measure during about 1 seconds */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
270 nb_its = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
271 for(;;) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
272 time_start = gettime();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
273 for(it=0;it<nb_its;it++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
274 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
275 if (do_inverse) {
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
276 ff_imdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
277 } else {
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
278 ff_mdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
279 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
280 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
281 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
282 ff_fft_calc(s, tab);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
283 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
284 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
285 duration = gettime() - time_start;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
286 if (duration >= 1000000)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
287 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
288 nb_its *= 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
289 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
290 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
291 (double)duration / nb_its,
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
292 (double)duration / 1000000.0,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
293 nb_its);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
294 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2593
diff changeset
295
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
296 if (do_mdct) {
969
d12d0c93d1e2 compile fixes
bellard
parents: 781
diff changeset
297 ff_mdct_end(m);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
298 } else {
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 1106
diff changeset
299 ff_fft_end(s);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
300 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
301 return 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
302 }