41 #if !CONFIG_HARDCODED_TABLES
61 double freq = 2*
M_PI/m;
64 tab[
i] = FIX15(cos(
i*freq));
74 #define INIT_FF_COS_TABS_FUNC(index, size) \
75 static av_cold void init_ff_cos_tabs_ ## size (void)\
77 init_ff_cos_tabs(index); \
147 if(n <= 2)
return i&1;
157 0, 4, 1, 5, 8, 12, 9, 13, 2, 6, 3, 7, 10, 14, 11, 15
175 int n = 1 <<
s->nbits;
177 for (
i = 0;
i < n;
i += 16) {
180 for (k = 0; k < 16; k++)
185 for (k = 0; k < 16; k++) {
187 j = (j & ~7) | ((j >> 1) & 3) | ((j << 2) & 4);
201 if (nbits < 2 || nbits > 17)
211 s->revtab32 =
av_malloc(n *
sizeof(uint32_t));
235 for(j=4; j<=nbits; j++) {
246 #define PROCESS_FFT_PERM_SWAP_LSBS(num) do {\
247 for(i = 0; i < n; i++) {\
250 j = (j & ~3) | ((j >> 1) & 1) | ((j << 1) & 2);\
251 k = -split_radix_permutation(i, n, s->inverse) & (n - 1);\
252 s->revtab##num[k] = j;\
256 #define PROCESS_FFT_PERM_DEFAULT(num) do {\
257 for(i = 0; i < n; i++) {\
260 k = -split_radix_permutation(i, n, s->inverse) & (n - 1);\
261 s->revtab##num[k] = j;\
265 #define SPLIT_RADIX_PERMUTATION(num) do { \
266 if (s->fft_permutation == FF_FFT_PERM_SWAP_LSBS) {\
267 PROCESS_FFT_PERM_SWAP_LSBS(num) \
269 PROCESS_FFT_PERM_DEFAULT(num) \
278 #undef PROCESS_FFT_PERM_DEFAULT
279 #undef PROCESS_FFT_PERM_SWAP_LSBS
280 #undef SPLIT_RADIX_PERMUTATION
294 const uint16_t *revtab =
s->revtab;
295 const uint32_t *revtab32 =
s->revtab32;
299 for(j=0;j<np;j++)
s->tmp_buf[revtab[j]] = z[j];
301 for(j=0;j<np;j++)
s->tmp_buf[revtab32[j]] = z[j];
319 unsigned tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
321 const int fft_size = (1 <<
s->nbits);
324 num_transforms = (0x2aab >> (16 -
s->nbits)) | 1;
326 for (n=0; n<num_transforms; n++){
330 tmp1 = tmpz[0].
re + (unsigned)tmpz[1].
re;
331 tmp5 = tmpz[2].
re + (unsigned)tmpz[3].
re;
332 tmp2 = tmpz[0].
im + (unsigned)tmpz[1].
im;
333 tmp6 = tmpz[2].
im + (unsigned)tmpz[3].
im;
334 tmp3 = tmpz[0].
re - (unsigned)tmpz[1].
re;
335 tmp8 = tmpz[2].
im - (unsigned)tmpz[3].
im;
336 tmp4 = tmpz[0].
im - (unsigned)tmpz[1].
im;
337 tmp7 = tmpz[2].
re - (unsigned)tmpz[3].
re;
339 tmpz[0].
re = tmp1 + tmp5;
340 tmpz[2].
re = tmp1 - tmp5;
341 tmpz[0].
im = tmp2 + tmp6;
342 tmpz[2].
im = tmp2 - tmp6;
343 tmpz[1].
re = tmp3 + tmp8;
344 tmpz[3].
re = tmp3 - tmp8;
345 tmpz[1].
im = tmp4 - tmp7;
346 tmpz[3].
im = tmp4 + tmp7;
352 num_transforms = (num_transforms >> 1) | 1;
354 for (n=0; n<num_transforms; n++){
358 tmp1 = tmpz[4].
re + (unsigned)tmpz[5].
re;
359 tmp3 = tmpz[6].
re + (unsigned)tmpz[7].
re;
360 tmp2 = tmpz[4].
im + (unsigned)tmpz[5].
im;
361 tmp4 = tmpz[6].
im + (unsigned)tmpz[7].
im;
367 tmp1 = tmpz[4].
re - (unsigned)tmpz[5].
re;
368 tmp2 = tmpz[4].
im - (unsigned)tmpz[5].
im;
369 tmp3 = tmpz[6].
re - (unsigned)tmpz[7].
re;
370 tmp4 = tmpz[6].
im - (unsigned)tmpz[7].
im;
372 tmpz[4].
re = tmpz[0].
re - tmp5;
373 tmpz[0].
re = tmpz[0].
re + tmp5;
374 tmpz[4].
im = tmpz[0].
im - tmp6;
375 tmpz[0].
im = tmpz[0].
im + tmp6;
376 tmpz[6].
re = tmpz[2].
re - tmp8;
377 tmpz[2].
re = tmpz[2].
re + tmp8;
378 tmpz[6].
im = tmpz[2].
im + tmp7;
379 tmpz[2].
im = tmpz[2].
im - tmp7;
382 tmp5 = (
int32_t)((accu + 0x40000000) >> 31);
384 tmp7 = (
int32_t)((accu + 0x40000000) >> 31);
386 tmp6 = (
int32_t)((accu + 0x40000000) >> 31);
388 tmp8 = (
int32_t)((accu + 0x40000000) >> 31);
394 tmpz[5].
re = tmpz[1].
re - tmp1;
395 tmpz[1].
re = tmpz[1].
re + tmp1;
396 tmpz[5].
im = tmpz[1].
im - tmp2;
397 tmpz[1].
im = tmpz[1].
im + tmp2;
398 tmpz[7].
re = tmpz[3].
re - tmp4;
399 tmpz[3].
re = tmpz[3].
re + tmp4;
400 tmpz[7].
im = tmpz[3].
im + tmp3;
401 tmpz[3].
im = tmpz[3].
im - tmp3;
407 for (nbits=4; nbits<=
s->nbits; nbits++){
410 num_transforms = (num_transforms >> 1) | 1;
412 for (n=0; n<num_transforms; n++){
418 tmp5 = tmpz[ n2].
re + (unsigned)tmpz[n34].
re;
419 tmp1 = tmpz[ n2].
re - (unsigned)tmpz[n34].
re;
420 tmp6 = tmpz[ n2].
im + (unsigned)tmpz[n34].
im;
421 tmp2 = tmpz[ n2].
im - (unsigned)tmpz[n34].
im;
423 tmpz[ n2].
re = tmpz[ 0].
re - tmp5;
424 tmpz[ 0].
re = tmpz[ 0].
re + tmp5;
425 tmpz[ n2].
im = tmpz[ 0].
im - tmp6;
426 tmpz[ 0].
im = tmpz[ 0].
im + tmp6;
427 tmpz[n34].
re = tmpz[n4].
re - tmp2;
428 tmpz[ n4].
re = tmpz[n4].
re + tmp2;
429 tmpz[n34].
im = tmpz[n4].
im + tmp1;
430 tmpz[ n4].
im = tmpz[n4].
im - tmp1;
432 for (
i=1;
i<n4;
i++){
435 accu = (int64_t)w_re*tmpz[ n2+
i].
re;
436 accu += (int64_t)w_im*tmpz[ n2+
i].
im;
437 tmp1 = (
int32_t)((accu + 0x40000000) >> 31);
438 accu = (int64_t)w_re*tmpz[ n2+
i].
im;
439 accu -= (int64_t)w_im*tmpz[ n2+
i].
re;
440 tmp2 = (
int32_t)((accu + 0x40000000) >> 31);
441 accu = (int64_t)w_re*tmpz[n34+
i].
re;
442 accu -= (int64_t)w_im*tmpz[n34+
i].
im;
443 tmp3 = (
int32_t)((accu + 0x40000000) >> 31);
444 accu = (int64_t)w_re*tmpz[n34+
i].
im;
445 accu += (int64_t)w_im*tmpz[n34+
i].
re;
446 tmp4 = (
int32_t)((accu + 0x40000000) >> 31);
453 tmpz[ n2+
i].
re = tmpz[
i].
re - tmp5;
454 tmpz[
i].
re = tmpz[
i].
re + tmp5;
455 tmpz[ n2+
i].
im = tmpz[
i].
im - tmp6;
456 tmpz[
i].
im = tmpz[
i].
im + tmp6;
457 tmpz[n34+
i].
re = tmpz[n4+
i].
re - tmp2;
458 tmpz[ n4+
i].
re = tmpz[n4+
i].
re + tmp2;
459 tmpz[n34+
i].
im = tmpz[n4+
i].
im + tmp1;
460 tmpz[ n4+
i].
im = tmpz[n4+
i].
im - tmp1;
473 #define BUTTERFLIES(a0,a1,a2,a3) {\
475 BF(a2.re, a0.re, a0.re, t5);\
476 BF(a3.im, a1.im, a1.im, t3);\
478 BF(a3.re, a1.re, a1.re, t4);\
479 BF(a2.im, a0.im, a0.im, t6);\
485 #define BUTTERFLIES_BIG(a0,a1,a2,a3) {\
486 FFTSample r0=a0.re, i0=a0.im, r1=a1.re, i1=a1.im;\
488 BF(a2.re, a0.re, r0, t5);\
489 BF(a3.im, a1.im, i1, t3);\
491 BF(a3.re, a1.re, r1, t4);\
492 BF(a2.im, a0.im, i0, t6);\
495 #define TRANSFORM(a0,a1,a2,a3,wre,wim) {\
496 CMUL(t1, t2, a2.re, a2.im, wre, -wim);\
497 CMUL(t5, t6, a3.re, a3.im, wre, wim);\
498 BUTTERFLIES(a0,a1,a2,a3)\
501 #define TRANSFORM_ZERO(a0,a1,a2,a3) {\
506 BUTTERFLIES(a0,a1,a2,a3)\
511 static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\
513 FFTDouble t1, t2, t3, t4, t5, t6;\
517 const FFTSample *wim = wre+o1;\
520 TRANSFORM_ZERO(z[0],z[o1],z[o2],z[o3]);\
521 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
526 TRANSFORM(z[0],z[o1],z[o2],z[o3],wre[0],wim[0]);\
527 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
534 #define BUTTERFLIES BUTTERFLIES_BIG
538 #define DECL_FFT(n,n2,n4)\
539 static void fft##n(FFTComplex *z)\
544 pass(z,FFT_NAME(ff_cos_##n),n4/2);\
573 TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf);
588 TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf);
589 TRANSFORM(z[1],z[5],z[9],z[13],cos_16_1,cos_16_3);
590 TRANSFORM(z[3],z[7],z[11],z[15],cos_16_3,cos_16_1);
601 #define pass pass_big
613 fft4,
fft8,
fft16, fft32, fft64, fft128, fft256, fft512, fft1024,
614 fft2048, fft4096, fft8192, fft16384, fft32768, fft65536, fft131072