📄 mp3dec_layer3_fp.c
字号:
/*////////////////////////////////////////////////////////////////////////////////// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright(c) 2003-2005 Intel Corporation. All Rights Reserved.//*/#include "mp3dec_own_fp.h"static struct { int l[22]; int s[39]; int m[38];} sfBandWidths[2][3] = { { /* MPEG 2 */ { /* sampling frequency = 22.05 kHz */ /* long bloks */ { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54 }, /* short bloks */ { 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18, 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18 }, /* mixed bloks */ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18, 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18, 0, 0 } }, { /* sampling frequency = 24 kHz */ /* long bloks */ { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36 }, /* short bloks */ { 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12 }, /* mixed bloks */ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12, 0, 0 } }, { /* sampling frequency = 16 kHz */ /* long bloks */ { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54 }, /* short bloks */ { 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18 }, /* mixed bloks */ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18, 0, 0 } } }, { /* MPEG 1 */ { /* sampling frequency = 44.1 kHz */ /* long bloks */ { 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10, 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158 }, /* short bloks */ { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56 }, /* mixed bloks */ { 4, 4, 4, 4, 4, 4, 6, 6, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56 } }, { /* sampling frequency = 48 kHz */ /* long bloks */ { 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10, 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192 }, /* short bloks */ { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14, 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66 }, /* mixed bloks */ { 4, 4, 4, 4, 4, 4, 6, 6, 4, 4, 4, 6, 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14, 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66 } }, { /* sampling frequency = 32 kHz */ /* long bloks */ { 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12, 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26 }, /* short bloks */ { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20, 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12 }, /* mixed bloks */ { 4, 4, 4, 4, 4, 4, 6, 6, 4, 4, 4, 6, 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20, 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12 } } }};static const int sfBandNum[2][3][2] ={ { /* MPEG 2 */ {22, 0}, {0, 13}, {6, 10} }, { /* MPEG 1 */ {22, 0}, {0, 13}, {8, 10} }};static const float mpeg1_intensity[7] = { 0.000000000f, 0.211324865f, 0.366025404f, 0.500000000f, 0.633974596f, 0.788675135f, 1.000000000f};static const float mpeg2_intensity[2][16] ={ { 1.000000000f, 0.840896415f, 0.707106781f, 0.594603558f, 0.500000000f, 0.420448208f, 0.353553391f, 0.297301779f, 0.250000000f, 0.210224104f, 0.176776695f, 0.148650889f, 0.125000000f, 0.105112052f, 0.088388348f, 0.074325445f }, { 1.000000000f, 0.707106781f, 0.500000000f, 0.353553391f, 0.250000000f, 0.176776695f, 0.125000000f, 0.088388348f, 0.062500000f, 0.044194174f, 0.031250000f, 0.022097087f, 0.015625000f, 0.011048543f, 0.007812500f, 0.005524272f }};/* Table 3-B.6. Layer III Preemphasis (p.14 Annex_AB ISO/IEC 11172-3 )*/static short pretab[22] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0};/* Table 3-B.9 Layer III coefficients for aliasing reduction (p.36 Annex_AB ISO/IEC 11172-3)*/static float cs[8] = { 0.857492926f, 0.881741997f, 0.949628649f, 0.983314592f, 0.995517816f, 0.999160558f, 0.999899195f, 0.999993155f,};static float ca[8] = { -0.514495755f, -0.471731969f, -0.313377454f, -0.181913200f, -0.094574193f, -0.040965583f, -0.014198569f, -0.003699975f,};static float mp3dec_imdct_table[4][36] = { { +7.85148978e-01f, +2.34947157e+00f, +3.89591312e+00f, +5.41270494e+00f, +6.88830233e+00f, +8.31147575e+00f, +9.67139339e+00f, +1.09577055e+01f, +1.21606236e+01f, +1.32709923e+01f, +1.42803612e+01f, +1.51810465e+01f, +1.59661961e+01f, +1.66298313e+01f, +1.71669044e+01f, +1.75733280e+01f, +1.78460083e+01f, +1.79828682e+01f, +1.79828682e+01f, +1.78460064e+01f, +1.75733280e+01f, +1.71669044e+01f, +1.66298313e+01f, +1.59661942e+01f, +1.51810455e+01f, +1.42803593e+01f, +1.32709904e+01f, +1.21606226e+01f, +1.09577045e+01f, +9.67139244e+00f, +8.31147385e+00f, +6.88830042e+00f, +5.41270304e+00f, +3.89591146e+00f, +2.34946990e+00f, +7.85147429e-01f, }, { +7.85148978e-01f, +2.34947157e+00f, +3.89591312e+00f, +5.41270494e+00f, +6.88830233e+00f, +8.31147575e+00f, +9.67139339e+00f, +1.09577055e+01f, +1.21606236e+01f, +1.32709923e+01f, +1.42803612e+01f, +1.51810465e+01f, +1.59661961e+01f, +1.66298313e+01f, +1.71669044e+01f, +1.75733280e+01f, +1.78460083e+01f, +1.79828682e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.78460064e+01f, +1.66298313e+01f, +1.42803593e+01f, +1.09577045e+01f, +6.88830042e+00f, +2.34946990e+00f, +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, }, { +7.83157229e-01f, +2.29610062e+00f, +3.65256858e+00f, +4.76012039e+00f, +5.54327726e+00f, +5.94866943e+00f, +5.94866896e+00f, +5.54327679e+00f, +4.76011992e+00f, +3.65256834e+00f, +2.29610014e+00f, +7.83156633e-01f, +7.83157229e-01f, +2.29610062e+00f, +3.65256858e+00f, +4.76012039e+00f, +5.54327726e+00f, +5.94866943e+00f, +5.94866896e+00f, +5.54327679e+00f, +4.76011992e+00f, +3.65256834e+00f, +2.29610014e+00f, +7.83156633e-01f, +7.83157229e-01f, +2.29610062e+00f, +3.65256858e+00f, +4.76012039e+00f, +5.54327726e+00f, +5.94866943e+00f, +5.94866896e+00f, +5.54327679e+00f, +4.76011992e+00f, +3.65256834e+00f, +2.29610014e+00f, +7.83156633e-01f, }, { +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, +0.00000000e+00f, +2.34947157e+00f, +6.88830233e+00f, +1.09577055e+01f, +1.42803612e+01f, +1.66298313e+01f, +1.78460083e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.80000000e+01f, +1.79828682e+01f, +1.78460064e+01f, +1.75733280e+01f, +1.71669044e+01f, +1.66298313e+01f, +1.59661942e+01f, +1.51810455e+01f, +1.42803593e+01f, +1.32709904e+01f, +1.21606226e+01f, +1.09577045e+01f, +9.67139244e+00f, +8.31147385e+00f, +6.88830042e+00f, +5.41270304e+00f, +3.89591146e+00f, +2.34946990e+00f, +7.85147429e-01f, }};/******************************************************************************// Name:// Dequant//// Description:// Decoding of coded subband samples in order to recover the original// quantized values//// Input Arguments:// DC - point to sDecoderContext structure// gr - number of granule// ch - number of channel//// Output Arguments:// smpl_xr[ch] - array of recovered samples//// Returns:// 1 - all ok//******************************************************************************/static int mp3dec_Dequant(MP3Dec *state, int gr, int ch){ float xx; // xx it is recalculated global gain short scl; int sfb; IppMP3FrameHeader *header = &(state->com.header); int *sfb_long = mp3dec_sfBandIndex[header->id][header->samplingFreq].l; float (*GlobalScaleFactor)[2] = state->GlobalScaleFactor; int *non_zero = state->com.non_zero; int count = non_zero[ch]; sScaleFactors *ScaleFactors = state->com.ScaleFactors; unsigned int (*si_blockType)[2] = state->com.si_blockType; unsigned int (*si_mixedBlock)[2] = state->com.si_mixedBlock; short (*si_pSubBlkGain)[2][3] = state->com.si_pSubBlkGain; unsigned int (*si_preFlag)[2] = state->com.si_preFlag; unsigned int (*si_sfScale)[2] = state->com.si_sfScale; samplefloat *smpl_xr = state->smpl_xr; /* out of dequantizer */ sampleshort *smpl_xs = state->com.smpl_xs; // out of huffman scl = -2 - 2 * (short)si_sfScale[gr][ch]; xx = GlobalScaleFactor[gr][ch]; ippsPow43_16s32f((*smpl_xs)[ch], (*smpl_xr)[ch], 576); if (si_blockType[gr][ch] != 2) { float tmp22[22]; short sf_tmp[21]; if (si_preFlag[gr][ch] == 0) { for (sfb = 0; sfb < 21; sfb++) sf_tmp[sfb] = scl * ScaleFactors[ch].l[sfb]; } else { for (sfb = 0; sfb < 21; sfb++) sf_tmp[sfb] = scl * (ScaleFactors[ch].l[sfb] + pretab[sfb]); } ippsCalcSF_16s32f(sf_tmp, 0, tmp22, 21); tmp22[21] = 1; ippsMulC_32f_I(xx, tmp22, 22); ippsScale_32f_I((*smpl_xr)[ch], tmp22, sfb_long, 22); } else { float tmpSF[3], tmp13[3][13]; short sf_tmp[13]; int n, j, wnd; int sfbStart, sfbEnd; int *sfb_short = mp3dec_sfBandIndex[header->id][header->samplingFreq].s; sfbEnd = 0; sfbStart = 0; if (si_mixedBlock[gr][ch]) { if (header->id == 1) { sfbEnd = 8; } else { sfbEnd = 6; } sfbStart = 3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -