📄 mpeg3dec.c
字号:
static const ST_TYPE pow_io0[2][MAX_POS2] = { 0x4000, 0x35D1, 0x4000, 0x2D41, 0x4000, 0x260D, 0x4000, 0x2000, 0x4000, 0x1AE8, 0x4000, 0x16A0, 0x4000, 0x1306, 0x4000, 0x1000, 0x4000, 0x0D74, 0x4000, 0x0B50, 0x4000, 0x0983, 0x4000, 0x0800, 0x4000, 0x06BA, 0x4000, 0x05A8, 0x4000, 0x04C1, 0x4000, 0x0400, 0x4000, 0x2D41, 0x4000, 0x2000, 0x4000, 0x16A0, 0x4000, 0x1000, 0x4000, 0x0B50, 0x4000, 0x0800, 0x4000, 0x05A8, 0x4000, 0x0400, 0x4000, 0x02D4, 0x4000, 0x0200, 0x4000, 0x016A, 0x4000, 0x0100, 0x4000, 0x00B5, 0x4000, 0x0080, 0x4000, 0x005A, 0x4000, 0x0040};static const ST_TYPE pow_io1[2][MAX_POS2] = { 0x4000, 0x4000, 0x35D1, 0x4000, 0x2D41, 0x4000, 0x260D, 0x4000, 0x2000, 0x4000, 0x1AE8, 0x4000, 0x16A0, 0x4000, 0x1306, 0x4000, 0x1000, 0x4000, 0x0D74, 0x4000, 0x0B50, 0x4000, 0x0983, 0x4000, 0x0800, 0x4000, 0x06BA, 0x4000, 0x05A8, 0x4000, 0x04C1, 0x4000, 0x4000, 0x4000, 0x2D41, 0x4000, 0x2000, 0x4000, 0x16A0, 0x4000, 0x1000, 0x4000, 0x0B50, 0x4000, 0x0800, 0x4000, 0x05A8, 0x4000, 0x0400, 0x4000, 0x02D4, 0x4000, 0x0200, 0x4000, 0x016A, 0x4000, 0x0100, 0x4000, 0x00B5, 0x4000, 0x0080, 0x4000, 0x005A, 0x4000};#elseextern ST_TYPE *tan_pos0;extern ST_TYPE *tan_pos1;extern ST_TYPE (*pow_io0)[MAX_POS2];extern ST_TYPE (*pow_io1)[MAX_POS2];#endif //SRAM_OPT_TABLE#else#define ST_TYPE REAL#define ST_MULT(a, b) ((a) * (b))static const ST_TYPE tan_pos0[MAX_POS1] = { 0.0, 0.211324841, 0.366025358, 0.5, 0.633974493, 0.788674951, 1.0};static const ST_TYPE tan_pos1[MAX_POS1] = { 1.0, 0.788674951, 0.633974493, 0.5, 0.366025358, 0.211324841, 0.0};static const ST_TYPE pow_io0[2][MAX_POS2] = { 1.0, 0.840896368, 1.0, 0.707106769, 1.0, 0.594603539, 1.0, 0.500000000, 1.0, 0.420448184, 1.0, 0.353553385, 1.0, 0.297301769, 1.0, 0.250000000, 1.0, 0.210224092, 1.0, 0.176776692, 1.0, 0.148650885, 1.0, 0.125000000, 1.0, 0.105112046, 1.0, 0.088388346, 1.0, 0.074325442, 1.0, 0.062500000, 1.0, 0.707106769, 1.0, 0.500000000, 1.0, 0.353553385, 1.0, 0.250000000, 1.0, 0.176776692, 1.0, 0.125000000, 1.0, 0.088388346, 1.0, 0.062500000, 1.0, 0.044194173, 1.0, 0.031250000, 1.0, 0.022097087, 1.0, 0.015625000, 1.0, 0.011048543, 1.0, 0.007812500, 1.0, 0.005524272, 1.0, 0.003906250,};static const ST_TYPE pow_io1[2][MAX_POS2] = { 1.0, 1.0, 0.840896368, 1.0, 0.707106769, 1.0, 0.594603539, 1.0, 0.500000000, 1.0, 0.420448184, 1.0, 0.353553385, 1.0, 0.297301769, 1.0, 0.250000000, 1.0, 0.210224092, 1.0, 0.176776692, 1.0, 0.148650885, 1.0, 0.125000000, 1.0, 0.105112046, 1.0, 0.088388346, 1.0, 0.074325442, 1.0, 1.0, 1.0, 0.707106769, 1.0, 0.500000000, 1.0, 0.353553385, 1.0, 0.250000000, 1.0, 0.176776692, 1.0, 0.125000000, 1.0, 0.088388346, 1.0, 0.062500000, 1.0, 0.044194173, 1.0, 0.031250000, 1.0, 0.022097087, 1.0, 0.015625000, 1.0, 0.011048543, 1.0, 0.007812500, 1.0, 0.005524272, 1.0,};#endif/****************************************************************************//* * Decode the stereo data of a granule * Return 0 if Ok */#ifdef MOV_FUNCint (*MPEG3_stereo_cp)(MPA_STREAM *mps, MPEGAUD_FRACT_TYPE *xr, INT16 gr);#endifint MPEG3_stereo(MPA_STREAM *mps, MPEGAUD_FRACT_TYPE *xr, INT16 gr){ static int init = 0; static FILE *fquant; const INT16 *band_l = sfBandIndex_l[mps->header.ID][mps->header.sampling_frequency]; const INT16 *band_s = sfBandIndex_s[mps->header.ID][mps->header.sampling_frequency]; MPA_SCALE_FAC3 *sf = &mps->scale_fac3[1]; MPA_GRANULE_INFO *gi = &mps->side_info.ch[0].gr[gr]; BOOL ms_stereo = (mps->header.mode == MPA_MODE_JOINT_STEREO) && (mps->header.mode_extension & 0x2); BOOL i_stereo = (mps->header.mode == MPA_MODE_JOINT_STEREO) && (mps->header.mode_extension & 0x1); INT16 sfb; INT16 i, j, sb, sbmax; BOOL lsf = (mps->header.ID == MPA_ID_2);#define MAX_POS1 7#define MAX_POS2 32 const ST_TYPE *pow_iok0; const ST_TYPE *pow_iok1; MPEGAUD_FRACT_TYPE *xrp0, *xrp1, temp;#ifdef MPEGAUD_INT ST_TYPE sq2 = 0.7071067812 * (1 << ST_BITS);#else REAL sq2 = 0.7071067812;#endif if (lsf) { if (gi->scalefac_compress & 1) { pow_iok0 = pow_io0[1]; pow_iok1 = pow_io1[1]; } else { pow_iok0 = pow_io0[0]; pow_iok1 = pow_io1[0]; } } else { pow_iok0 = tan_pos0; pow_iok1 = tan_pos1; } if ((mps->stereo) && i_stereo) { ST_TYPE k0, k1; INT16 sfb_top; INT16 max_sfb = 0; INT16 ispos; INT16 is_illegal; if (gi->window_switching_flag && (gi->block_type == 2)) { sbmax = mps->sfb_nul_s_top[0]; if (sbmax < mps->sfb_nul_s_top[1]) sbmax = mps->sfb_nul_s_top[1]; sbmax++; if (sbmax > 13) sbmax = 13; for (j = 0; j < 3; j++) { sfb_top = mps->sfb_nul_s[j][1]; if ((gi->mixed_block_flag) && (sfb_top < 3)) sfb_top = 3; // Normaly not !!! if (sfb_top > max_sfb) max_sfb = sfb_top; is_illegal = (lsf) ? mps->is_max_s[j][0] : 7; // Implicit: ispos == is_illegal here (not nul bands) ispos = is_illegal; for (sfb = 0; sfb < sfb_top; sfb++) { sb = band_s[sfb + 1] - band_s[sfb]; i = 3 * band_s[sfb] + j * sb; xrp0 = &xr[i]; xrp1 = &xr[MPA_GRANULE_SIZE + i]; if (ms_stereo) while (sb--) { temp = ST_MULT((*xrp0 + *xrp1), sq2); *xrp1 = ST_MULT((*xrp0 - *xrp1), sq2); *xrp0++ = temp; xrp1++; } } while (sfb < sbmax) { // #9: sbmax instead of 13 sb = band_s[sfb + 1] - band_s[sfb]; i = 3 * band_s[sfb] + j * sb; xrp0 = &xr[i]; xrp1 = &xr[MPA_GRANULE_SIZE + i]; if (sfb < 12) { // keep previous ispos for // last sfb ispos = sf->s[j][sfb]; is_illegal = (lsf) ? mps-> is_max_s[j][sfb] : 7; } if (ispos == is_illegal) { if (ms_stereo) while (sb--) { temp = ST_MULT((*xrp0 + *xrp1), sq2); *xrp1 = ST_MULT((*xrp0 - *xrp1), sq2); *xrp0++ = temp; xrp1++; } } else { // ispos != is_illegal k0 = pow_iok0[ispos]; k1 = pow_iok1[ispos]; while (sb--) { temp = ST_MULT(*xrp0, k0); *xrp1 = ST_MULT(*xrp0, k1); *xrp0++ = temp; xrp1++; } } sfb++; } } if (gi->mixed_block_flag) { INT16 sfb_max = (lsf) ? 6 : 8; xrp0 = xr; xrp1 = &xr[MPA_GRANULE_SIZE]; if (max_sfb <= 3) { // Top of nul bands in long blocks sfb = mps->sfb_nul_l[1]; // Begin of nul bands } else { sfb = sfb_max; // Begin of nul band not in long blocks } sb = band_l[sfb]; // Implicit: ispos == is_illegal here (not nul bands) if (ms_stereo) while (sb--) { temp = ST_MULT((*xrp0 + *xrp1), sq2); *xrp1 = ST_MULT((*xrp0 - *xrp1), sq2); *xrp0++ = temp; xrp1++; } else { xrp0 += sb; xrp1 += sb; } for (; sfb < sfb_max; sfb++) { sb = band_l[sfb + 1] - band_l[sfb]; ispos = sf->l[sfb]; is_illegal = (lsf) ? mps-> is_max_l[sfb] : 7; if (ispos == is_illegal) { if (ms_stereo) while (sb--) { temp = ST_MULT((*xrp0 + *xrp1), sq2); *xrp1 = ST_MULT((*xrp0 - *xrp1), sq2); *xrp0++ = temp; xrp1++; } else { xrp0 += sb; xrp1 += sb; } } else { // ispos != is_illegal k0 = pow_iok0[ispos]; k1 = pow_iok1[ispos]; while (sb--) { temp = ST_MULT(*xrp0, k0); *xrp1 = ST_MULT(*xrp0, k1); *xrp0++ = temp; xrp1++; } } } } } else { // Long blocks, intensity stereo sbmax = mps->sfb_nul_l[0]; if (sbmax < mps->sfb_nul_l[1]) sbmax = mps->sfb_nul_l[1]; sbmax++; if (sbmax > 22) sbmax = 22; xrp0 = xr; xrp1 = &xr[MPA_GRANULE_SIZE]; sfb = mps->sfb_nul_l[1]; // Begin of nul bands sb = band_l[sfb]; is_illegal = (lsf) ? mps->is_max_l[0] : 7; // Implicit: ispos == is_illegal here (not nul bands) ispos = is_illegal; if (ms_stereo) while (sb--) { temp = ST_MULT((*xrp0 + *xrp1), sq2); *xrp1 = ST_MULT((*xrp0 - *xrp1), sq2); *xrp0++ = temp; xrp1++; } else { xrp0 += sb; xrp1 += sb; } for (; sfb < sbmax; sfb++) { // sbmax instead of 22 sb = band_l[sfb + 1] - band_l[sfb]; if (sfb < 21) { // keep previous ispos for last sfb ispos = sf->l[sfb]; is_illegal = (lsf) ? mps-> is_max_l[sfb] : 7; } if (ispos == is_illegal) { if (ms_stereo) while (sb--) { temp = ST_MULT((*xrp0 + *xrp1), sq2); *xrp1 = ST_MULT((*xrp0 - *xrp1), sq2); *xrp0++ = temp; xrp1++; } else { xrp0 += sb; xrp1 += sb; } } else { // ispos != is_illegal k0 = pow_iok0[ispos]; k1 = pow_iok1[ispos]; while (sb--) { temp = ST_MULT(*xrp0, k0); *xrp1 = ST_MULT(*xrp0, k1); *xrp0++ = temp; xrp1++; } } } } } else if ((mps->stereo) && ms_stereo) { // MS stereo xrp0 = xr; xrp1 = &xr[MPA_GRANULE_SIZE]; sb = mps->imdct_max[0]; if (sb < mps->imdct_max[1]) sb = mps->imdct_max[1]; sb = (INT16) (sb + 1) * MPA_SSLIMIT; if (sb > MPA_GRANULE_SIZE) sb = MPA_GRANULE_SIZE; while (sb--) { temp = ST_MULT((*xrp0 + *xrp1), sq2); *xrp1 = ST_MULT((*xrp0 - *xrp1), sq2); *xrp0++ = temp; xrp1++; } } else { //Normal stereo or mono -> nothing to do ! } return(MPEGDEC_ERR_NONE);}/****************************************************************************//* * Decode the stereo data -> mono of a granule * Return 0 if Ok */static int MPEG3_stereo_mono(MPA_STREAM *mps, MPEGAUD_FRACT_TYPE *xr, INT16 gr){ const INT16 *band_l = sfBandIndex_l[mps->header.ID][mps->header.sampling_frequency]; const INT16 *band_s = sfBandIndex_s[mps->header.ID][mps->header.sampling_frequency]; MPA_SCALE_FAC3 *sf = &mps->scale_fac3[1]; MPA_GRANULE_INFO *gi = &mps->side_info.ch[0].gr[gr]; BOOL ms_stereo = (mps->header.mode == MPA_MODE_JOINT_STEREO) && (mps->header.mode_extension & 0x2); BOOL i_stereo = (mps->header.mode == MPA_MODE_JOINT_STEREO) && (mps->header.mode_extension & 0x1); INT16 sfb; INT16 i, j, sb, sbmax; BOOL lsf = (mps->header.ID == MPA_ID_2);#define MAX_POS1 7#define MAX_POS2 32 const ST_TYPE *pow_iok0; MPEGAUD_FRACT_TYPE *xrp0, *xrp1;#ifdef MPEGAUD_INT ST_TYPE sq2 = 0.7071067812 * (1 << ST_BITS);#else REAL sq2 = 0.7071067812;#endif if (lsf) { if (gi->scalefac_compress & 1) pow_iok0 = pow_io0[1]; else pow_iok0 = pow_io0[0]; } else { pow_iok0 = tan_pos0; } if ((mps->stereo) && i_stereo) { ST_TYPE k0; INT16 sfb_top; INT16 max_sfb = 0; INT16 ispos; INT16 is_illegal; if (gi->window_switching_flag && (gi->block_type == 2)) { sbmax = mps->sfb_nul_s_top[0]; if (sbmax < mps->sfb_nul_s_top[1]) sbmax = mps->sfb_nul_s_top[1]; sbmax++; if (sbmax > 13) sbmax = 13; for (j = 0; j < 3; j++) { sfb_top = mps->sfb_nul_s[j][1]; if ((gi->mixed_block_flag) && (sfb_top < 3)) sfb_top = 3; // Normaly not !!! if (sfb_top > max_sfb) max_sfb = sfb_top; is_illegal = (lsf) ? mps->is_max_s[j][0] : 7; // Implicit: ispos == is_illegal here (not nul bands) ispos = is_illegal; for (sfb = 0; sfb < sfb_top; sfb++) { sb = band_s[sfb + 1] - band_s[sfb]; i = 3 * band_s[sfb] + j * sb; xrp0 = &xr[i]; xrp1 = &xr[MPA_GRANULE_SIZE + i]; if (ms_stereo) while (sb--) { *xrp0 = ST_MULT((*xrp0 + *xrp1), sq2); xrp0++; xrp1++; } } while (sfb < sbmax) { // #9: sbmax instead of 13 sb = band_s[sfb + 1] - band_s[sfb]; i = 3 * band_s[sfb] + j * sb; xrp0 = &xr[i]; xrp1 = &xr[MPA_GRANULE_SIZE + i]; if (sfb < 12) { // keep previous ispos for // last sfb ispos = sf->s[j][sfb]; is_illegal = (lsf) ? mps-> is_max_s[j][sfb] : 7; } if (ispos == is_illegal) { if (ms_stereo) while (sb--) { *xrp0 = ST_MULT((*xrp0 + *xrp1), sq2); xrp0++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -