[Ffmpeg-devel] AAC decoder

Daniel Serpell daniel_serpell
Wed Mar 22 01:23:10 CET 2006


Hi!

At Tue, Mar 21, 2006, Mike Melanson wrote:
> 
> I decided to put my code where my mouth is. What follows is a 
> program to generate the sine tables, and also validates them against the 
> tables in your aac.h file. This will eliminate the hard-coding of 
> sine_long_1024[] and sine_short_128[]. I will see if I can figure out an 
> algorithm for the KBD stuff as well.
> 

Here you have a better version without sin/cos functions (should
be a lot faster, if it matters):

-------------------------------------------------------------------
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int i;
    const double sinA = 0.00153398018628476561230369715026407907995;
    const double cosA = 0.99999882345170190992902571017152601904827;
    double x = 0.00076699031874270452693856835794857664314;
    double y = 0.99999970586288221916022821773876567711626;

    for (i = 0; i < 1024; i++) {
        float sinTrue = sin((i * 2 + 1) * M_PI / 4096);
        float sinIter = x;
        double nx = x * cosA + y * sinA;
        double ny = - x * sinA + y * cosA;
        x = nx;
        y = ny;
        if ( fabs(sinTrue - sinIter) > 0.00000000001)
            printf ("%d: calculated = %f, original = %f\n", i,
            sinIter, sinTrue);
    }

    return 0;
}
-------------------------------------------------------------------

Also, if you don't want doubles, you can use (with lower
precision):

-------------------------------------------------------------------
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int i;
    const long long sinA = 6588396LL;
    const long long cosA = 4294962244LL;
    int x = 1647006;
    int y = 2147483010;
    
    for (i = 0; i < 1024; i++) {
        float sinTrue = sin((i * 2 + 1) * M_PI / 4096);
        float sinIter = x * 0.0000000004656612873077392578125;
        int nx = (int)((x * cosA + y * sinA)>>32);
        int ny = (int)((-x * sinA + y * cosA)>>32);
        x = nx;
        y = ny;
        if ( fabs(sinTrue - sinIter) > 0.0000001)
            printf ("%d: calculated = %.9f, original = %.9f \n", i,
            sinIter, sinTrue);
    }

    return 0;
}
-------------------------------------------------------------------


        Daniel.





More information about the ffmpeg-devel mailing list