📄 mpegaudalloc.c
字号:
/* <LIC_AMD_STD> * Copyright (c) 2005 Advanced Micro Devices, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * The full GNU General Public License is included in this distribution in the * file called COPYING * </LIC_AMD_STD> *//* <CTL_AMD_STD> * </CTL_AMD_STD> *//* <DOC_AMD_STD> * </DOC_AMD_STD> */#include <stdio.h>#include <string.h>#if defined(WIN32) || defined(UNDER_CE) #include <memory.h> #include <stdlib.h>#endif#include "mpegaudiodec.h"/* memory */static int init_vlc(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size);#if GENERATE_STATIC_TABLES/* { */ #include <math.h> #define POW_FRAC_BITS 24 #define POW_FRAC_ONE (1 << POW_FRAC_BITS) #define POW_FIX(a) ((int)((a) * POW_FRAC_ONE)) #define POW_MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> POW_FRAC_BITS) /* table for alias reduction (XXX: store it as integer !) */ const float ci_table[8] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037, }; static int pow_mult3[3] = { POW_FIX(1.0), POW_FIX(1.25992104989487316476), POW_FIX(1.58740105196819947474), }; static int dev_4_3_coefs[DEV_ORDER]; /* return the mantissa and the binary exponent */ static int int_pow(int i, int *exp_ptr) { int e, er, eq, j; int a, a1; /* renormalize */ a = i; e = POW_FRAC_BITS; while (a < (1 << (POW_FRAC_BITS - 1))) { a = a << 1; e--; } a -= (1 << POW_FRAC_BITS); a1 = 0; for (j = DEV_ORDER - 1; j >= 0; j--) a1 = POW_MULL(a, dev_4_3_coefs[j] + a1); a = (1 << POW_FRAC_BITS) + a1; /* exponent compute (exact) */ e = e * 4; er = e % 3; eq = e / 3; a = POW_MULL(a, pow_mult3[er]); while (a >= 2 * POW_FRAC_ONE) { a = a >> 1; eq++; } /* convert to float */ while (a < POW_FRAC_ONE) { a = a << 1; eq--; } /* now POW_FRAC_ONE <= a < 2 * POW_FRAC_ONE */ #if POW_FRAC_BITS > FRAC_BITS a = (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS); /* correct overflow */ if (a >= 2 * (1 << FRAC_BITS)) { a = a >> 1; eq++; } #endif *exp_ptr = eq; return a; } static void int_pow_init(void) { int i, a; a = POW_FIX(1.0); for (i=0;i<DEV_ORDER;i++) { a = POW_MULL(a, POW_FIX(4.0 / 3.0) - i * POW_FIX(1.0)) / (i + 1); dev_4_3_coefs[i] = a; } } static MPA_INT window[512]; /* intensity stereo coef table */ static int32_t is_table[2][16]; static int32_t is_table_lsf[2][2][16]; static int32_t csa_table[8][2]; static int32_t mdct_win[8][36]; static int8_t *table_4_3_exp; #if FRAC_BITS <= 15 static uint16_t *table_4_3_value; #else static uint32_t *table_4_3_value; #endif /* computed from band_size_long */ static uint16_t band_index_long[9][23]; /* lower 2 bits: modulo 3, higher bits: shift */ static uint16_t scale_factor_modshift[64]; /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */ static int32_t scale_factor_mult[15][3]; /* mult table for layer 2 group quantization */ /* allocation of static arrays - do not use for normal allocation */ static unsigned int last_static = 0; static char*** array_static = NULL; static const unsigned int grow_static = 64; // ^2 static int decode_init(MPEG_codecContext * avctx) { MPADecodeContext *s = avctx->priv_data; static int init=0; int i, j, k; if (!init && !avctx->parse_only) { /* huffman decode tables */ huff_code_table[0] = NULL; for (i=1;i<16;i++) { const HuffTable *h = &mpa_huff_tables[i]; int xsize, x, y; unsigned int n; uint8_t *code_table; xsize = h->xsize; n = xsize * xsize; /* XXX: fail test */ init_vlc(&huff_vlc[i], 8, n, h->bits, 1, 1, h->codes, 2, 2); code_table = mallocz(n); j = 0; for (x=0;x<xsize;x++) { for (y=0;y<xsize;y++) code_table[j++] = (x << 4) | y; } huff_code_table[i] = code_table; } for (i=0;i<2;i++) { init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16, mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1); } printf("static uint16_t scale_factor_modshift[64] =\n{"); /* scale factors table for layer 1/2 */ for (i=0;i<64;i++) { int shift, mod; /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */ shift = (i / 3); mod = i % 3; scale_factor_modshift[i] = mod | (shift << 2); if (i %16 == 0) printf("\n "); printf("%d, ", scale_factor_modshift[i]); } printf("\n};\n\n"); /* scale factor multiply for layer 1 */ printf("static int32_t scale_factor_mult[15][3] =\n{\n"); for (i=0;i<15;i++) { int n, norm; n = i + 2; norm = ((int64_t_C(1) << n) * FRAC_ONE) / ((1 << n) - 1); scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm); scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm); scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm); dprintf("%d: norm=%x s=%x %x %x\n", i, norm, scale_factor_mult[i][0], scale_factor_mult[i][1], scale_factor_mult[i][2]); printf(" { %d, %d, %d},\n", scale_factor_mult[i][0], scale_factor_mult[i][1], scale_factor_mult[i][2]); } printf("};\n\n"); /* window */ /* max = 18760, max sum over all 16 coefs : 44736 */ for (i=0;i<257;i++) { int v; v = mpa_enwindow[i]; #if WFRAC_BITS < 16 v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); #endif window[i] = v; if ((i & 63) != 0) v = -v; if (i != 0) window[512 - i] = v; } printf("MPA_INT window[512] =\n{"); for (i=0;i<512;i++) { if (i %16 == 0) printf("\n "); printf("%d, ", window[i]); } printf("\n};\n\n"); printf("static uint16_t band_index_long[9][23] =\n{"); for (i=0;i<9;i++) { k = 0; printf(" { "); for (j=0;j<22;j++) { band_index_long[i][j] = k; k += band_size_long[i][j]; printf("%d, ", band_index_long[i][j]); } band_index_long[i][22] = k; printf("%d, }, \n", band_index_long[i][22]); } printf("};\n\n"); /* compute n ^ (4/3) and store it in mantissa/exp format */ if (!av_mallocz_static(&table_4_3_exp, TABLE_4_3_SIZE * sizeof(table_4_3_exp[0]))) return -1; if (!av_mallocz_static(&table_4_3_value, TABLE_4_3_SIZE * sizeof(table_4_3_value[0]))) return -1; int_pow_init(); for (i=1;i<TABLE_4_3_SIZE;i++) { int e, m; m = int_pow(i, &e); /* normalized to FRAC_BITS */ table_4_3_value[i] = m; table_4_3_exp[i] = e; } printf("static int8_t table_4_3_exp[TABLE_4_3_SIZE] =\n{"); for (i=0;i<TABLE_4_3_SIZE;i++) { if (i %16 == 0) printf("\n "); printf("%d, ", table_4_3_exp[i]); } printf("\n};\n\n"); printf("static int table_4_3_value[TABLE_4_3_SIZE] =\n{\n"); for (i=0;i<TABLE_4_3_SIZE;i++) { if (i %16 == 0) printf("\n "); printf("%d, ", table_4_3_value[i]); } printf("\n};\n\n"); for (i=0;i<7;i++) { float f; int v; if (i != 6) { f = tan((double)i * M_PI / 12.0); v = FIXR(f / (1.0 + f)); } else { v = FIXR(1.0); } is_table[0][i] = v; is_table[1][6 - i] = v; } /* invalid values */ for (i=7;i<16;i++) is_table[0][i] = is_table[1][i] = 0; printf("static int32_t is_table[2][16] =\n{"); for (i=0;i<2;i++) { printf("\n {\n "); for (j=0;j<16;j++) { printf("%d, ", is_table[i][j]); } printf("\n },"); } printf("\n};\n\n"); for (i=0;i<16;i++) { double f; int e, k; for (j=0;j<2;j++) { e = -(j + 1) * ((i + 1) >> 1); f = pow(2.0, e / 4.0); k = i & 1; is_table_lsf[j][k ^ 1][i] = FIXR(f); is_table_lsf[j][k][i] = FIXR(1.0); dprintf("is_table_lsf %d %d: %x %x\n", i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]); } } printf("static int32_t is_table_lsf[2][2][16] =\n{"); for (i=0;i<2;i++) { printf("\n { "); for (j=0;j<2;j++) { printf("\n {\n "); for (k=0;k<16;k++) { printf("%d, ", is_table_lsf[i][j][k]); } printf("\n },"); } printf("\n },"); } printf("\n};\n\n"); for (i=0;i<8;i++) { float ci, cs, ca;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -