45 #define MUL16(a,b) ((a) * (b))
47 #define CMAC(pre, pim, are, aim, bre, bim) \
49 pre += (MUL16(are, bre) - MUL16(aim, bim));\
50 pim += (MUL16(are, bim) + MUL16(bre, aim));\
55 # define REF_SCALE(x, bits) (x)
59 # define REF_SCALE(x, bits) ((x) / (1<<(bits)))
75 for (i = 0; i < (n/2); i++) {
76 alpha = 2 *
M_PI * (float)i / (
float)
n;
89 double tmp_re, tmp_im,
s,
c;
94 for (i = 0; i <
n; i++) {
98 for (j = 0; j <
n; j++) {
99 k = (i * j) & (n - 1);
107 CMAC(tmp_re, tmp_im, c, s, q->
re, q->
im);
121 for (i = 0; i <
n; i++) {
123 for (k = 0; k < n/2; k++) {
124 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
125 f = cos(
M_PI * a / (
double)(2 * n));
140 for (k = 0; k < n/2; k++) {
142 for (i = 0; i <
n; i++) {
143 a = (2*
M_PI*(2*i+1+n/2)*(2*k+1) / (4 *
n));
144 s += input[i] * cos(a);
158 for (i = 0; i <
n; i++) {
160 for (k = 1; k <
n; k++) {
161 a =
M_PI*k*(i+0.5) /
n;
162 s += input[k] * cos(a);
164 output[i] = 2 * s /
n;
174 for (k = 0; k <
n; k++) {
176 for (i = 0; i <
n; i++) {
177 a =
M_PI*k*(i+0.5) /
n;
178 s += input[i] * cos(a);
198 for (i = 0; i <
n; i++) {
199 double e = fabsf(tab1[i] - (tab2[i] / scale)) /
RANGE;
202 i, tab1[i], tab2[i]);
216 "-h print this help\n"
221 "-i inverse transform test\n"
222 "-n b set the transform size to 2^b\n"
223 "-f x set scale factor for output data of (I)MDCT to x\n"
238 int main(
int argc,
char **argv)
255 int fft_nbits, fft_size;
262 c =
getopt(argc, argv,
"hsimrdn:f:c:");
301 fft_size = 1 << fft_nbits;
349 for (i = 0; i < fft_size; i++) {
372 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
376 fft_ref(tab_ref, tab1, fft_nbits);
381 fft_size_2 = fft_size >> 1;
384 tab1[fft_size_2].
im = 0;
385 for (i = 1; i < fft_size_2; i++) {
386 tab1[fft_size_2+i].
re = tab1[fft_size_2-i].
re;
387 tab1[fft_size_2+i].
im = -tab1[fft_size_2-i].
im;
390 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
391 tab2[1] = tab1[fft_size_2].
re;
394 fft_ref(tab_ref, tab1, fft_nbits);
395 for (i = 0; i < fft_size; i++) {
399 err =
check_diff((
float *)tab_ref, (
float *)tab, fft_size * 2, 0.5);
401 for (i = 0; i < fft_size; i++) {
402 tab2[i] = tab1[i].
re;
406 fft_ref(tab_ref, tab1, fft_nbits);
407 tab_ref[0].
im = tab_ref[fft_size_2].
re;
408 err =
check_diff((
float *)tab_ref, (
float *)tab2, fft_size, 1.0);
412 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
419 err =
check_diff((
float *)tab_ref, (
float *)tab, fft_size, 1.0);
435 for (it = 0; it < nb_its; it++) {
445 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
450 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
454 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
461 if (duration >= 1000000)
465 av_log(NULL,
AV_LOG_INFO,
"time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
466 (
double)duration / nb_its,
467 (
double)duration / 1000000.0,