46 #define MUL16(a,b) ((a) * (b))
48 #define CMAC(pre, pim, are, aim, bre, bim) \
50 pre += (MUL16(are, bre) - MUL16(aim, bim));\
51 pim += (MUL16(are, bim) + MUL16(bre, aim));\
56 # define REF_SCALE(x, bits) (x)
59 # define RANGE 8388608
60 # define REF_SCALE(x, bits) (x)
64 # define REF_SCALE(x, bits) ((x) / (1<<(bits)))
80 for (i = 0; i < (n/2); i++) {
81 alpha = 2 *
M_PI * (float)i / (
float)
n;
94 double tmp_re, tmp_im,
s,
c;
99 for (i = 0; i <
n; i++) {
103 for (j = 0; j <
n; j++) {
104 k = (i * j) & (n - 1);
112 CMAC(tmp_re, tmp_im, c, s, q->
re, q->
im);
127 for (i = 0; i <
n; i++) {
129 for (k = 0; k < n/2; k++) {
130 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
131 f = cos(
M_PI * a / (
double)(2 * n));
146 for (k = 0; k < n/2; k++) {
148 for (i = 0; i <
n; i++) {
149 a = (2*
M_PI*(2*i+1+n/2)*(2*k+1) / (4 *
n));
150 s += input[i] * cos(a);
166 for (i = 0; i <
n; i++) {
168 for (k = 1; k <
n; k++) {
169 a =
M_PI*k*(i+0.5) /
n;
170 s += input[k] * cos(a);
172 output[i] = 2 * s /
n;
182 for (k = 0; k <
n; k++) {
184 for (i = 0; i <
n; i++) {
185 a =
M_PI*k*(i+0.5) /
n;
186 s += input[i] * cos(a);
207 for (i = 0; i <
n; i++) {
208 double e = fabsf(tab1[i] - (tab2[i] / scale)) /
RANGE;
211 i, tab1[i], tab2[i]);
225 "-h print this help\n"
230 "-i inverse transform test\n"
231 "-n b set the transform size to 2^b\n"
232 "-f x set scale factor for output data of (I)MDCT to x\n"
247 int main(
int argc,
char **argv)
264 int fft_nbits, fft_size;
271 c =
getopt(argc, argv,
"hsimrdn:f:c:");
310 fft_size = 1 << fft_nbits;
364 for (i = 0; i < fft_size; i++) {
389 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
393 fft_ref(tab_ref, tab1, fft_nbits);
399 fft_size_2 = fft_size >> 1;
402 tab1[fft_size_2].
im = 0;
403 for (i = 1; i < fft_size_2; i++) {
404 tab1[fft_size_2+i].
re = tab1[fft_size_2-i].
re;
405 tab1[fft_size_2+i].
im = -tab1[fft_size_2-i].
im;
408 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
409 tab2[1] = tab1[fft_size_2].
re;
412 fft_ref(tab_ref, tab1, fft_nbits);
413 for (i = 0; i < fft_size; i++) {
417 err =
check_diff((
float *)tab_ref, (
float *)tab, fft_size * 2, 0.5);
419 for (i = 0; i < fft_size; i++) {
420 tab2[i] = tab1[i].
re;
424 fft_ref(tab_ref, tab1, fft_nbits);
425 tab_ref[0].
im = tab_ref[fft_size_2].
re;
426 err =
check_diff((
float *)tab_ref, (
float *)tab2, fft_size, 1.0);
432 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
439 err =
check_diff((
float *)tab_ref, (
float *)tab, fft_size, 1.0);
456 for (it = 0; it < nb_its; it++) {
466 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
471 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
475 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
482 if (duration >= 1000000)
486 av_log(NULL,
AV_LOG_INFO,
"time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
487 (
double)duration / nb_its,
488 (
double)duration / 1000000.0,
522 printf(
"Error: %d.\n", err);