Revision c460833d libavcodec/ffttest.c
libavcodec/ffttest.c  

176  176 
enum tf_transform { 
177  177 
TRANSFORM_FFT, 
178  178 
TRANSFORM_MDCT, 
179 
TRANSFORM_RDFT, 

179  180 
}; 
180  181  
181  182 
int main(int argc, char **argv) 
...  ...  
188  189 
int do_inverse = 0; 
189  190 
FFTContext s1, *s = &s1; 
190  191 
FFTContext m1, *m = &m1; 
191 
int fft_nbits, fft_size; 

192 
RDFTContext r1, *r = &r1; 

193 
int fft_nbits, fft_size, fft_size_2; 

192  194 
double scale = 1.0; 
193  195 
AVLFG prng; 
194  196 
av_lfg_init(&prng, 1); 
195  197  
196  198 
fft_nbits = 9; 
197  199 
for(;;) { 
198 
c = getopt(argc, argv, "hsimn:f:"); 

200 
c = getopt(argc, argv, "hsimrn:f:");


199  201 
if (c == 1) 
200  202 
break; 
201  203 
switch(c) { 
...  ...  
211  213 
case 'm': 
212  214 
transform = TRANSFORM_MDCT; 
213  215 
break; 
216 
case 'r': 

217 
transform = TRANSFORM_RDFT; 

218 
break; 

214  219 
case 'n': 
215  220 
fft_nbits = atoi(optarg); 
216  221 
break; 
...  ...  
221  226 
} 
222  227  
223  228 
fft_size = 1 << fft_nbits; 
229 
fft_size_2 = fft_size >> 1; 

224  230 
tab = av_malloc(fft_size * sizeof(FFTComplex)); 
225  231 
tab1 = av_malloc(fft_size * sizeof(FFTComplex)); 
226  232 
tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); 
...  ...  
243  249 
ff_fft_init(s, fft_nbits, do_inverse); 
244  250 
fft_ref_init(fft_nbits, do_inverse); 
245  251 
break; 
252 
case TRANSFORM_RDFT: 

253 
if (do_inverse) 

254 
av_log(NULL, AV_LOG_INFO,"IRDFT"); 

255 
else 

256 
av_log(NULL, AV_LOG_INFO,"RDFT"); 

257 
ff_rdft_init(r, fft_nbits, do_inverse ? IRDFT : RDFT); 

258 
fft_ref_init(fft_nbits, do_inverse); 

259 
break; 

246  260 
} 
247  261 
av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); 
248  262  
...  ...  
278  292 
fft_ref(tab_ref, tab1, fft_nbits); 
279  293 
check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 1.0); 
280  294 
break; 
295 
case TRANSFORM_RDFT: 

296 
if (do_inverse) { 

297 
tab1[ 0].im = 0; 

298 
tab1[fft_size_2].im = 0; 

299 
for (i = 1; i < fft_size_2; i++) { 

300 
tab1[fft_size_2+i].re = tab1[fft_size_2i].re; 

301 
tab1[fft_size_2+i].im = tab1[fft_size_2i].im; 

302 
} 

303  
304 
memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); 

305 
tab2[1] = tab1[fft_size_2].re; 

306  
307 
ff_rdft_calc(r, tab2); 

308 
fft_ref(tab_ref, tab1, fft_nbits); 

309 
for (i = 0; i < fft_size; i++) { 

310 
tab[i].re = tab2[i]; 

311 
tab[i].im = 0; 

312 
} 

313 
check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 0.5); 

314 
} else { 

315 
for (i = 0; i < fft_size; i++) { 

316 
tab2[i] = tab1[i].re; 

317 
tab1[i].im = 0; 

318 
} 

319 
ff_rdft_calc(r, tab2); 

320 
fft_ref(tab_ref, tab1, fft_nbits); 

321 
tab_ref[0].im = tab_ref[fft_size_2].re; 

322 
check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0); 

323 
} 

281  324 
} 
282  325  
283  326 
/* do a speed test */ 
...  ...  
304  347 
memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); 
305  348 
ff_fft_calc(s, tab); 
306  349 
break; 
350 
case TRANSFORM_RDFT: 

351 
memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); 

352 
ff_rdft_calc(r, tab2); 

353 
break; 

307  354 
} 
308  355 
} 
309  356 
duration = gettime()  time_start; 
...  ...  
324  371 
case TRANSFORM_FFT: 
325  372 
ff_fft_end(s); 
326  373 
break; 
374 
case TRANSFORM_RDFT: 

375 
ff_rdft_end(r); 

376 
break; 

327  377 
} 
328  378 
return 0; 
329  379 
} 
Also available in: Unified diff