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);
126 for (i = 0; i <
n; i++) {
128 for (k = 0; k < n/2; k++) {
129 a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
130 f = cos(
M_PI * a / (
double)(2 * n));
145 for (k = 0; k < n/2; k++) {
147 for (i = 0; i <
n; i++) {
148 a = (2*
M_PI*(2*i+1+n/2)*(2*k+1) / (4 *
n));
149 s += input[i] * cos(a);
163 for (i = 0; i <
n; i++) {
165 for (k = 1; k <
n; k++) {
166 a =
M_PI*k*(i+0.5) /
n;
167 s += input[k] * cos(a);
169 output[i] = 2 * s /
n;
179 for (k = 0; k <
n; k++) {
181 for (i = 0; i <
n; i++) {
182 a =
M_PI*k*(i+0.5) /
n;
183 s += input[i] * cos(a);
203 for (i = 0; i <
n; i++) {
204 double e = fabsf(tab1[i] - (tab2[i] / scale)) /
RANGE;
207 i, tab1[i], tab2[i]);
221 "-h print this help\n"
226 "-i inverse transform test\n"
227 "-n b set the transform size to 2^b\n"
228 "-f x set scale factor for output data of (I)MDCT to x\n"
243 int main(
int argc,
char **argv)
260 int fft_nbits, fft_size;
267 c =
getopt(argc, argv,
"hsimrdn:f:c:");
306 fft_size = 1 << fft_nbits;
356 for (i = 0; i < fft_size; i++) {
379 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
383 fft_ref(tab_ref, tab1, fft_nbits);
388 fft_size_2 = fft_size >> 1;
391 tab1[fft_size_2].
im = 0;
392 for (i = 1; i < fft_size_2; i++) {
393 tab1[fft_size_2+i].
re = tab1[fft_size_2-i].
re;
394 tab1[fft_size_2+i].
im = -tab1[fft_size_2-i].
im;
397 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
398 tab2[1] = tab1[fft_size_2].
re;
401 fft_ref(tab_ref, tab1, fft_nbits);
402 for (i = 0; i < fft_size; i++) {
406 err =
check_diff((
float *)tab_ref, (
float *)tab, fft_size * 2, 0.5);
408 for (i = 0; i < fft_size; i++) {
409 tab2[i] = tab1[i].
re;
413 fft_ref(tab_ref, tab1, fft_nbits);
414 tab_ref[0].
im = tab_ref[fft_size_2].
re;
415 err =
check_diff((
float *)tab_ref, (
float *)tab2, fft_size, 1.0);
419 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
426 err =
check_diff((
float *)tab_ref, (
float *)tab, fft_size, 1.0);
442 for (it = 0; it < nb_its; it++) {
452 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
457 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
461 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
468 if (duration >= 1000000)
472 av_log(NULL,
AV_LOG_INFO,
"time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
473 (
double)duration / nb_its,
474 (
double)duration / 1000000.0,
504 printf(
"Error: %d.\n", err);