comparison fft-test.c @ 10807:4578f774a775 libavcodec

fft-test: whitespace cosmetics
author alexc
date Fri, 08 Jan 2010 06:11:56 +0000
parents 38ab367d4231
children 8dbceaa5fa2f
comparison
equal deleted inserted replaced
10806:e58e93f04279 10807:4578f774a775
51 double c1, s1, alpha; 51 double c1, s1, alpha;
52 52
53 n = 1 << nbits; 53 n = 1 << nbits;
54 exptab = av_malloc((n / 2) * sizeof(FFTComplex)); 54 exptab = av_malloc((n / 2) * sizeof(FFTComplex));
55 55
56 for(i=0;i<(n/2);i++) { 56 for (i = 0; i < (n/2); i++) {
57 alpha = 2 * M_PI * (float)i / (float)n; 57 alpha = 2 * M_PI * (float)i / (float)n;
58 c1 = cos(alpha); 58 c1 = cos(alpha);
59 s1 = sin(alpha); 59 s1 = sin(alpha);
60 if (!inverse) 60 if (!inverse)
61 s1 = -s1; 61 s1 = -s1;
70 double tmp_re, tmp_im, s, c; 70 double tmp_re, tmp_im, s, c;
71 FFTComplex *q; 71 FFTComplex *q;
72 72
73 n = 1 << nbits; 73 n = 1 << nbits;
74 n2 = n >> 1; 74 n2 = n >> 1;
75 for(i=0;i<n;i++) { 75 for (i = 0; i < n; i++) {
76 tmp_re = 0; 76 tmp_re = 0;
77 tmp_im = 0; 77 tmp_im = 0;
78 q = tab; 78 q = tab;
79 for(j=0;j<n;j++) { 79 for (j = 0; j < n; j++) {
80 k = (i * j) & (n - 1); 80 k = (i * j) & (n - 1);
81 if (k >= n2) { 81 if (k >= n2) {
82 c = -exptab[k - n2].re; 82 c = -exptab[k - n2].re;
83 s = -exptab[k - n2].im; 83 s = -exptab[k - n2].im;
84 } else { 84 } else {
97 { 97 {
98 int n = 1<<nbits; 98 int n = 1<<nbits;
99 int k, i, a; 99 int k, i, a;
100 double sum, f; 100 double sum, f;
101 101
102 for(i=0;i<n;i++) { 102 for (i = 0; i < n; i++) {
103 sum = 0; 103 sum = 0;
104 for(k=0;k<n/2;k++) { 104 for (k = 0; k < n/2; k++) {
105 a = (2 * i + 1 + (n / 2)) * (2 * k + 1); 105 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
106 f = cos(M_PI * a / (double)(2 * n)); 106 f = cos(M_PI * a / (double)(2 * n));
107 sum += f * in[k]; 107 sum += f * in[k];
108 } 108 }
109 out[i] = -sum; 109 out[i] = -sum;
116 int n = 1<<nbits; 116 int n = 1<<nbits;
117 int k, i; 117 int k, i;
118 double a, s; 118 double a, s;
119 119
120 /* do it by hand */ 120 /* do it by hand */
121 for(k=0;k<n/2;k++) { 121 for (k = 0; k < n/2; k++) {
122 s = 0; 122 s = 0;
123 for(i=0;i<n;i++) { 123 for (i = 0; i < n; i++) {
124 a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n)); 124 a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n));
125 s += input[i] * cos(a); 125 s += input[i] * cos(a);
126 } 126 }
127 output[k] = s; 127 output[k] = s;
128 } 128 }
145 { 145 {
146 int i; 146 int i;
147 double max= 0; 147 double max= 0;
148 double error= 0; 148 double error= 0;
149 149
150 for(i=0;i<n;i++) { 150 for (i = 0; i < n; i++) {
151 double e= fabsf(tab1[i] - (tab2[i] / scale)); 151 double e= fabsf(tab1[i] - (tab2[i] / scale));
152 if (e >= 1e-3) { 152 if (e >= 1e-3) {
153 av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n", 153 av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n",
154 i, tab1[i], tab2[i]); 154 i, tab1[i], tab2[i]);
155 } 155 }
240 } 240 }
241 av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); 241 av_log(NULL, AV_LOG_INFO," %d test\n", fft_size);
242 242
243 /* generate random data */ 243 /* generate random data */
244 244
245 for(i=0;i<fft_size;i++) { 245 for (i = 0; i < fft_size; i++) {
246 tab1[i].re = frandom(&prng); 246 tab1[i].re = frandom(&prng);
247 tab1[i].im = frandom(&prng); 247 tab1[i].im = frandom(&prng);
248 } 248 }
249 249
250 /* checking result */ 250 /* checking result */
280 av_log(NULL, AV_LOG_INFO,"Speed test...\n"); 280 av_log(NULL, AV_LOG_INFO,"Speed test...\n");
281 /* we measure during about 1 seconds */ 281 /* we measure during about 1 seconds */
282 nb_its = 1; 282 nb_its = 1;
283 for(;;) { 283 for(;;) {
284 time_start = gettime(); 284 time_start = gettime();
285 for(it=0;it<nb_its;it++) { 285 for (it = 0; it < nb_its; it++) {
286 if (do_mdct) { 286 if (do_mdct) {
287 if (do_inverse) { 287 if (do_inverse) {
288 ff_imdct_calc(m, (float *)tab, (float *)tab1); 288 ff_imdct_calc(m, (float *)tab, (float *)tab1);
289 } else { 289 } else {
290 ff_mdct_calc(m, (float *)tab, (float *)tab1); 290 ff_mdct_calc(m, (float *)tab, (float *)tab1);