📄 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-2006 Intel Corporation. All Rights Reserved.
//
*/
#include "mp3dec_own_fp.h"
static struct {
Ipp32s l[22];
Ipp32s s[39];
Ipp32s 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 Ipp32s sfBandNum[2][3][2] =
{
{ /* MPEG 2 */
{22, 0}, {0, 13}, {6, 10}
},
{ /* MPEG 1 */
{22, 0}, {0, 13}, {8, 10}
}
};
static const Ipp32f mpeg1_intensity[7] = {
0.000000000f, 0.211324865f, 0.366025404f, 0.500000000f,
0.633974596f, 0.788675135f, 1.000000000f
};
static const Ipp32f 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 Ipp16s 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 Ipp32f cs[8] = {
0.857492926f, 0.881741997f, 0.949628649f, 0.983314592f,
0.995517816f, 0.999160558f, 0.999899195f, 0.999993155f,
};
static Ipp32f ca[8] = {
-0.514495755f, -0.471731969f, -0.313377454f, -0.181913200f,
-0.094574193f, -0.040965583f, -0.014198569f, -0.003699975f,
};
static Ipp32f 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:
// initialize_huffman
//
// Description:
// initialize huffman tables by using ippAC functionality
//
// Input Arguments:
// huff_table - point to array of Huff_table structures.
// huff_table[i]->ptable is the table in user format.
//
// Output Arguments:
// huff_table - point to array of Huff_table structures.
// huff_table[i]->phuftable is the table in internal format.
//
// Returns:
// -
//
******************************************************************************/
Ipp32s mp3dec_initialize_huffman(sHuffmanTable *huff_table, Ipp8u *mem, Ipp32s *size_all)
{
Ipp32s i, ts, size = 0;
if (huff_table) {
for(i = 0; i < 16; i++)
huff_table[i].linbits = 0;
huff_table[16].linbits = 1;
huff_table[17].linbits = 2;
huff_table[18].linbits = 3;
huff_table[19].linbits = 4;
huff_table[20].linbits = 6;
huff_table[21].linbits = 8;
huff_table[22].linbits = 10;
huff_table[23].linbits = 13;
huff_table[24].linbits = 4;
huff_table[25].linbits = 5;
huff_table[26].linbits = 6;
huff_table[27].linbits = 7;
huff_table[28].linbits = 8;
huff_table[29].linbits = 9;
huff_table[30].linbits = 11;
huff_table[31].linbits = 13;
huff_table[32].linbits = 0;
huff_table[33].linbits = 0;
}
for (i = 1; i <= 16; i++) {
if (mp3dec_VLCBooks[i]) {
ippsVLCDecodeGetSize_32s(mp3dec_VLCBooks[i], mp3dec_VLCTableSizes[i],
mp3dec_VLCSubTablesSizes[i],
mp3dec_VLCNumSubTables[i], &ts);
size += ts;
if (mem) {
huff_table[i].phuftable = (IppsVLCDecodeSpec_32s *)mem;
mem += ts;
ippsVLCDecodeInit_32s(mp3dec_VLCBooks[i], mp3dec_VLCTableSizes[i],
mp3dec_VLCSubTablesSizes[i],
mp3dec_VLCNumSubTables[i],
(IppsVLCDecodeSpec_32s *) (huff_table[i].
phuftable));
}
}
}
if (huff_table) {
for (i = 17; i < 24; i++) {
huff_table[i].phuftable = huff_table[16].phuftable;
}
}
ippsVLCDecodeGetSize_32s(mp3dec_VLCBooks[24], mp3dec_VLCTableSizes[24],
mp3dec_VLCSubTablesSizes[24], mp3dec_VLCNumSubTables[24], &ts);
size += ts;
if (mem) {
huff_table[24].phuftable = (IppsVLCDecodeSpec_32s *)mem;
mem += ts;
ippsVLCDecodeInit_32s(mp3dec_VLCBooks[24], mp3dec_VLCTableSizes[24],
mp3dec_VLCSubTablesSizes[24], mp3dec_VLCNumSubTables[24],
(IppsVLCDecodeSpec_32s *) (huff_table[24].
phuftable));
}
if (huff_table) {
for (i = 25; i < 32; i++) {
huff_table[i].phuftable = huff_table[24].phuftable;
}
}
for (i = 32; i <= 33; i++) {
if (mp3dec_VLCBooks[i]) {
ippsVLCDecodeGetSize_32s(mp3dec_VLCBooks[i], mp3dec_VLCTableSizes[i],
mp3dec_VLCSubTablesSizes[i],
mp3dec_VLCNumSubTables[i], &ts);
size += ts;
if (mem) {
huff_table[i].phuftable = (IppsVLCDecodeSpec_32s *)mem;
mem += ts;
ippsVLCDecodeInit_32s(mp3dec_VLCBooks[i], mp3dec_VLCTableSizes[i],
mp3dec_VLCSubTablesSizes[i],
mp3dec_VLCNumSubTables[i],
(IppsVLCDecodeSpec_32s *) (huff_table[i].
phuftable));
}
}
}
if (size_all)
*size_all = size;
return 1;
}
/******************************************************************************
// Name:
// Huffmancodebits
//
// Description:
// Huffman decoding of spectral samples
//
// Input Arguments:
// DC - point to sDecoderContext structure
// gr - number of granule
// ch - number of channel
//
// Output Arguments:
// smpl_xs[ch] - array of decoded samples
//
// Returns:
// 1 - all ok
//
******************************************************************************/
Ipp32s mp3dec_Huffmancodebits(MP3Dec_com *state, Ipp32s gr, Ipp32s ch) {
Ipp32s j, i, idx, nbits;
Ipp16s pDst[576];
Ipp32s reg[3];
IppsVLCDecodeSpec_32s *pVLCDecSpec;
Ipp32s shift, offset, mask;
sBitsreamBuffer *BS = &(state->m_MainData);
Ipp8u *pSrc;
Ipp32s bitoffset;
IppMP3FrameHeader *header = &(state->header);
sHuffmanTable *huff_table = state->huff_table;
Ipp32s *non_zero = state->non_zero;
Ipp32s part2_start = state->part2_start;
Ipp32u (*si_part23Len)[2] = state->si_part23Len;
Ipp32u (*si_bigVals)[2] = state->si_bigVals;
Ipp32u (*si_winSwitch)[2] = state->si_winSwitch;
Ipp32u (*si_blockType)[2] = state->si_blockType;
Ipp32u (*si_pTableSelect)[2][3] = state->si_pTableSelect;
Ipp32u (*si_reg0Cnt)[2] = state->si_reg0Cnt;
Ipp32u (*si_reg1Cnt)[2] = state->si_reg1Cnt;
Ipp32u (*si_cnt1TabSel)[2] = state->si_cnt1TabSel;
sampleshort *smpl_xs = state->smpl_xs; // out of huffman
// the block_type is only used if the window_switching_flag is set to 1.
if (!si_winSwitch[gr][ch] || (si_blockType[gr][ch] != 2 &&
!(state->mpg25 == 2 && header->samplingFreq == 2))) {
reg[0] =
mp3dec_sfBandIndex_l[header->id + state->mpg25][header->samplingFreq][si_reg0Cnt[gr][ch] + 1];
reg[1] =
mp3dec_sfBandIndex_l[header->id + state->mpg25][header->samplingFreq][si_reg0Cnt[gr][ch] +
si_reg1Cnt[gr][ch] + 2];
} else {
if (si_blockType[gr][ch] == 2) {
if (state->mpg25 == 2 && header->samplingFreq == 2)
reg[0] = 72;
else
reg[0] = 36;
} else
reg[0] = 108;
reg[1] = 576;
}
reg[2] = si_bigVals[gr][ch] * 2;
if (reg[2] > 576) // reg[2] upper-bounded by 576
reg[2] = 576;
if (reg[0] > 576) // reg[0] upper-bounded by 576
reg[0] = 576;
if (reg[1] > reg[2]) // reg[1] upper-bounded by reg[2]
reg[1] = reg[2];
if (reg[0] > reg[2]) // reg[0] upper-bounded by reg[2]
reg[0] = reg[2];
pSrc = (Ipp8u *)BS->pCurrent_dword + ((32 - BS->nBit_offset) >> 3);
bitoffset = (32 - BS->nBit_offset) & 0x7;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -