annotate fft-test.c @ 822:21d400c67fc5 libavcodec

fixing msmpeg4v3 with mb_height % slice_height != 0
author michaelni
date Fri, 01 Nov 2002 18:55:03 +0000
parents 6f5e87957bcb
children d12d0c93d1e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
1 /* FFT and MDCT tests */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
2 #include "dsputil.h"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
3 #include <math.h>
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
4 #include <getopt.h>
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
5 #include <sys/time.h>
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
6
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
7 int mm_flags;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
8
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
9 void *av_malloc(int size)
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 void *ptr;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
12 ptr = malloc(size);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
13 return ptr;
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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
16 void av_free(void *ptr)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
17 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
18 /* XXX: this test should not be needed on most libcs */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
19 if (ptr)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
20 free(ptr);
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 /* cannot call it directly because of 'void **' casting is not automatic */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
24 void __av_freep(void **ptr)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
25 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
26 av_free(*ptr);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
27 *ptr = NULL;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
28 }
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 /* reference fft */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
31
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
32 #define MUL16(a,b) ((a) * (b))
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
33
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
34 #define CMAC(pre, pim, are, aim, bre, bim) \
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
35 {\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
36 pre += (MUL16(are, bre) - MUL16(aim, bim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
37 pim += (MUL16(are, bim) + MUL16(bre, aim));\
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
38 }
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 FFTComplex *exptab;
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 void fft_ref_init(int nbits, int inverse)
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 int n, i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
45 float c1, s1, alpha;
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 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
48 exptab = av_malloc((n / 2) * sizeof(FFTComplex));
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 for(i=0;i<(n/2);i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
51 alpha = 2 * M_PI * (float)i / (float)n;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
52 c1 = cos(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
53 s1 = sin(alpha);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
54 if (!inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
55 s1 = -s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
56 exptab[i].re = c1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
57 exptab[i].im = s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
58 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
59 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
60
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
61 void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
62 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
63 int n, i, j, k, n2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
64 float tmp_re, tmp_im, s, c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
65 FFTComplex *q;
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 n = 1 << nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
68 n2 = n >> 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
69 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
70 tmp_re = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
71 tmp_im = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
72 q = tab;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
73 for(j=0;j<n;j++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
74 k = (i * j) & (n - 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
75 if (k >= n2) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
76 c = -exptab[k - n2].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
77 s = -exptab[k - n2].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
78 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
79 c = exptab[k].re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
80 s = exptab[k].im;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
81 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
82 CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
83 q++;
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 tabr[i].re = tmp_re;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
86 tabr[i].im = tmp_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 }
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 void imdct_ref(float *out, float *in, 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, a;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
93 float sum, f;
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 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
96 sum = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
97 for(k=0;k<n/2;k++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
98 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
99 f = cos(M_PI * a / (double)(2 * n));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
100 sum += f * in[k];
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 out[i] = -sum;
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 /* NOTE: no normalisation by 1 / N is done */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
107 void mdct_ref(float *output, float *input, int n)
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 int k, i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
110 float a, s;
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 /* do it by hand */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
113 for(k=0;k<n/2;k++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
114 s = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
115 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
116 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
117 s += input[i] * cos(a);
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 output[k] = s;
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 }
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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
124 float frandom(void)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
125 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
126 return (float)((random() & 0xffff) - 32768) / 32768.0;
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 INT64 gettime(void)
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 struct timeval tv;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
132 gettimeofday(&tv,NULL);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
133 return (INT64)tv.tv_sec * 1000000 + tv.tv_usec;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
134 }
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 void check_diff(float *tab1, float *tab2, int n)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
137 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
138 int i;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
139
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
140 for(i=0;i<n;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
141 if (fabsf(tab1[i] - tab2[i]) >= 1e-3) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
142 printf("ERROR %d: %f %f\n",
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
143 i, tab1[i], tab2[i]);
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 }
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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
149 void help(void)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
150 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
151 printf("usage: fft-test [-h] [-s] [-i] [-n b]\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
152 "-h print this help\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
153 "-s speed test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
154 "-m (I)MDCT test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
155 "-i inverse transform test\n"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
156 "-n b set the transform size to 2^b\n"
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 exit(1);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
159 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
160
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
161
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
162
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
163 int main(int argc, char **argv)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
164 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
165 FFTComplex *tab, *tab1, *tab_ref;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
166 FFTSample *tabtmp, *tab2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
167 int it, i, c;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
168 int do_speed = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
169 int do_mdct = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
170 int do_inverse = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
171 FFTContext s1, *s = &s1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
172 MDCTContext m1, *m = &m1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
173 int fft_nbits, fft_size;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
174
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
175 mm_flags = 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
176 fft_nbits = 9;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
177 for(;;) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
178 c = getopt(argc, argv, "hsimn:");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
179 if (c == -1)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
180 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
181 switch(c) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
182 case 'h':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
183 help();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
184 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
185 case 's':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
186 do_speed = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
187 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
188 case 'i':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
189 do_inverse = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
190 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
191 case 'm':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
192 do_mdct = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
193 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
194 case 'n':
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
195 fft_nbits = atoi(optarg);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
196 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
197 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
198 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
199
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
200 fft_size = 1 << fft_nbits;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
201 tab = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
202 tab1 = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
203 tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
204 tabtmp = av_malloc(fft_size / 2 * sizeof(FFTSample));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
205 tab2 = av_malloc(fft_size * sizeof(FFTSample));
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 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
208 if (do_inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
209 printf("IMDCT");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
210 else
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
211 printf("MDCT");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
212 mdct_init(m, fft_nbits, do_inverse);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
213 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
214 if (do_inverse)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
215 printf("IFFT");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
216 else
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
217 printf("FFT");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
218 fft_init(s, fft_nbits, do_inverse);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
219 fft_ref_init(fft_nbits, do_inverse);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
220 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
221 printf(" %d test\n", fft_size);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
222
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
223 /* generate random data */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
224
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
225 for(i=0;i<fft_size;i++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
226 tab1[i].re = frandom();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
227 tab1[i].im = frandom();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
228 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
229
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
230 /* checking result */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
231 printf("Checking...\n");
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 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
234 if (do_inverse) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
235 imdct_ref((float *)tab_ref, (float *)tab1, fft_size);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
236 imdct_calc(m, tab2, (float *)tab1, tabtmp);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
237 check_diff((float *)tab_ref, tab2, fft_size);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
238 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
239 mdct_ref((float *)tab_ref, (float *)tab1, fft_size);
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 mdct_calc(m, tab2, (float *)tab1, tabtmp);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
242
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
243 check_diff((float *)tab_ref, tab2, fft_size / 2);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
244 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
245 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
246 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
247 fft_permute(s, tab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
248 fft_calc(s, tab);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
249
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
250 fft_ref(tab_ref, tab1, fft_nbits);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
251 check_diff((float *)tab_ref, (float *)tab, 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
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
254 /* do a speed test */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
255
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
256 if (do_speed) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
257 INT64 time_start, duration;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
258 int nb_its;
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 printf("Speed test...\n");
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
261 /* we measure during about 1 seconds */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
262 nb_its = 1;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
263 for(;;) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
264 time_start = gettime();
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
265 for(it=0;it<nb_its;it++) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
266 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
267 if (do_inverse) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
268 imdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
269 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
270 mdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
271 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
272 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
273 memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
274 fft_calc(s, tab);
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 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
277 duration = gettime() - time_start;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
278 if (duration >= 1000000)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
279 break;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
280 nb_its *= 2;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
281 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
282 printf("time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
283 (double)duration / nb_its,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
284 (double)duration / 1000000.0,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
285 nb_its);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
286 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
287
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
288 if (do_mdct) {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
289 mdct_end(m);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
290 } else {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
291 fft_end(s);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
292 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
293 return 0;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
294 }