/* calctables: compute fixed decoder table values copyright ?-2021 by the mpg123 project - free software under the terms of the LGPL 2.1 see COPYING and AUTHORS files in distribution or http://mpg123.org initially written by Michael Hipp (as tabinit.c, and parts of layer2.c and layer3.c), then printout added by Thomas Orgis This is supposed to compute the supposedly fixed tables that used to be computed live on library startup in mpg123_init(). */ #define CALCTABLES #include "mpg123lib_intern.h" #include "../common/debug.h" #define ASIZE(a) (sizeof(a)/sizeof(*a)) // The variable definitions here are redundant with the runtime part of // the init_* headers, but that is fine, as those headers are generated // by this very program. static double cos64[16],cos32[8],cos16[4],cos8[2],cos4[1]; #include "init_costabs.h" // layer I+II tables static double layer12_table[27][64]; // Storing only values 0 to 26, so char is fine. // The size of those might be reduced ... static unsigned char grp_3tab[32 * 3] = { 0, }; /* used: 27 */ static unsigned char grp_5tab[128 * 3] = { 0, }; /* used: 125 */ static unsigned char grp_9tab[1024 * 3] = { 0, }; /* used: 729 */ #include "init_layer12.h" // layer III static double ispow[8207]; // scale with SCALE_POW43 static double aa_ca[8],aa_cs[8]; static double win[4][36]; static double win1[4][36]; double INT123_COS9[9]; /* INT123_dct36_3dnow wants to use that */ static double COS6_1,COS6_2; double INT123_tfcos36[9]; /* INT123_dct36_3dnow wants to use that */ static double tfcos12[3]; static double cos9[3],cos18[3]; // scale with SCALE_15 static double tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16]; // This used to be [2][32] initially, but already Taihei noticed that // _apparently_ only [2][16] is used for the integer tables. But // this is misleading: Accesses beyond that happen, at least in pathologic // cases. Taihei's fixed-point decoding introduced read-only buffer // overflows:-/ Those are rather harmless, though, as only bad numbers // enter calculation. Nothing about pointers or code. static double pow1_1[2][32],pow2_1[2][32],pow1_2[2][32],pow2_2[2][32]; // That needs special handling for storing the pointers // in map and mapend. // map[j][N] = mapbufN[j]; // mapend[j][N] = ... varies let's use // mapbufN[j]+(mapend[j][N]-map[j][N]) static short mapbuf0[9][152]; static short mapbuf1[9][156]; static short mapbuf2[9][44]; static short *map[9][3]; static short *mapend[9][3]; static unsigned short n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ static unsigned short i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ static real gainpow2[256+118+4]; #include "l3bandgain.h" #include "init_layer3.h" // helpers static void print_char_array( const char *indent, const char *name , size_t count, unsigned char tab[], int calc ) { if(calc) { if(name) printf("static unsigned char %s[%zu];\n", name, count); return; } size_t block = 72/4; size_t i = 0; if(name) printf("static const unsigned char %s[%zu] = \n", name, count); printf("%s{\n", indent); while(i count-i ? count-i : block; printf("%s", indent); for(size_t j=0; j 1e38) return 1e38; if(val < -1e38) return -1e38; return val; } static void print_array( int statick, int fixed, double fixed_scale , const char *indent, const char *name , size_t count, double tab[], int calc ) { if(calc) { if(!fixed && name) printf( "%sALIGNED(16) real %s[%zu];\n" , statick ? "static " : "", name, count ); return; } size_t block = 72/18; size_t i = 0; if(name) printf( "%sconst%s real %s[%zu] = \n", statick ? "static " : "" , fixed ? "" : " ALIGNED(16)", name, count ); printf("%s{\n", indent); while(i count-i ? count-i : block; printf("%s", indent); if(fixed) for(size_t j=0; j count-i ? count-i : block; printf("%s", indent); for(size_t j=0; j count-i ? count-i : block; printf("%s", indent); for(size_t j=0; j count-i ? count-i : block; printf("%s", indent); for(size_t j=0; j\n\n", argv[0]); return 1; } printf("// %s MPEG decoding tables\n", argv[1]); printf("// output of:\n// %s", argv[0]); for(int i=1; i