Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Formula computing twiddle factors in FAAD (Read 2518 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Formula computing twiddle factors in FAAD

In Libfaad in file mdct_tab.h are predefined twiddle factor, for example:
Code: [Select]
/* 256 (N/4) complex twiddle factors */
ALIGN static const complex_t mdct_tab_2048[] =
{
    { FRAC_CONST(0.031249997702054), FRAC_CONST(0.000011984224612) },
    { FRAC_CONST(0.031249813866531), FRAC_CONST(0.000107857810004) },
    { FRAC_CONST(0.031249335895858), FRAC_CONST(0.000203730380198) },


this constants after multiply by 32 is
Code: [Select]
    { FRAC_CONST(0.999999926465728), FRAC_CONST(0.000383495187584) },
    { FRAC_CONST(0.999994043728992), FRAC_CONST(0.003451449920128) },
    { FRAC_CONST(0.999978748667456), FRAC_CONST(0.006519372166336) },


But angles for sinus and cosinus are odd.
What is formula?

Formula computing twiddle factors in FAAD

Reply #1
Code: [Select]
    omega = 2.0f * M_PI / N;
    alpha = 2.0f * M_PI / (8.0f * N);
    
    for(n = 0; n < (N >> 2); ++n)
    {    
        twiddle[2*n] = (float) cos(omega * n + alpha);
        twiddle[2*n+1] = (float) sin(omega * n + alpha);
    }


Might need a scaling factor.
These are used pre and post fft (mdct implemented using fft).
"I hear it when I see it."

Formula computing twiddle factors in FAAD

Reply #2
I also found in mdct.c :
Quote
/* RE(mdct->sincos[k]) = scale*(real_t)(cos(2.0*M_PI*(k+1./8.) / (real_t)N));
    * IM(mdct->sincos[k]) = scale*(real_t)(sin(2.0*M_PI*(k+1./8.) / (real_t)N)); */
    /* scale is 1 for fixed point, sqrt(N) for floating point */

I correct sqrt(N) to sqrt(N/2) to be compatible with mdct_tab.h