📄 mp3dec_layer3_int.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_int.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}
}
};
/* Q30 */
static const Ipp32s mpeg1_intensity[7] = {
0, 226908352, 393016800, 536870912,
680725056, 846833472, 1073741824,
};
/* Q30 */
static const Ipp32s mpeg2_intensity[2][16] =
{
{
1073741824, 902905664, 759250112, 638450688,
536870912, 451452832, 379625056, 319225344,
268435456, 225726416, 189812528, 159612672,
134217728, 112863208, 94906264, 79806336,
},
{
1073741824, 759250112, 536870912, 379625056,
268435456, 189812528, 134217728, 94906264,
67108864, 47453132, 33554432, 23726566,
16777216, 11863283, 8388608, 5931642,
}
};
/* 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)*/
/* Q31 */
static Ipp32s aa_cs[8] = {
1841452032,
1893526528,
2039312000,
2111651968,
2137858176,
2145681024,
2147267200,
2147468928,
};
/* Q31 */
static Ipp32s aa_ca[8] = {
-1104871168,
-1013036672,
-672972928,
-390655616,
-203096528,
-87972920,
-30491194,
-7945636,
};
/******************************************************************************
// 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 mp3idec_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 (mp3idec_VLCBooks[i]) {
ippsVLCDecodeUTupleGetSize_32s(mp3idec_VLCBooks[i], mp3idec_VLCTableSizes[i],
mp3idec_VLCSubTablesSizes[i],
mp3idec_VLCNumSubTables[i],
2, mp3idec_VLCShifts[i], &ts);
size += ts;
if (mem) {
huff_table[i].phuftable = (IppsVLCDecodeSpec_32s *)mem;
mem += ts;
ippsVLCDecodeUTupleInit_32s(mp3idec_VLCBooks[i], mp3idec_VLCTableSizes[i],
mp3idec_VLCSubTablesSizes[i],
mp3idec_VLCNumSubTables[i],
2, mp3idec_VLCShifts[i],
(IppsVLCDecodeUTupleSpec_32s *) (huff_table[i].
phuftable));
}
}
}
if (huff_table) {
for (i = 17; i < 24; i++) {
huff_table[i].phuftable = huff_table[16].phuftable;
}
}
ippsVLCDecodeUTupleGetSize_32s(mp3idec_VLCBooks[24], mp3idec_VLCTableSizes[24],
mp3idec_VLCSubTablesSizes[24], mp3idec_VLCNumSubTables[24],
2, mp3idec_VLCShifts[24], &ts);
size += ts;
if (mem) {
huff_table[24].phuftable = (IppsVLCDecodeSpec_32s *)mem;
mem += ts;
ippsVLCDecodeUTupleInit_32s(mp3idec_VLCBooks[24], mp3idec_VLCTableSizes[24],
mp3idec_VLCSubTablesSizes[24], mp3idec_VLCNumSubTables[24],
2, mp3idec_VLCShifts[24],
(IppsVLCDecodeUTupleSpec_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 (mp3idec_VLCBooks[i]) {
ippsVLCDecodeUTupleGetSize_32s(mp3idec_VLCBooks[i], mp3idec_VLCTableSizes[i],
mp3idec_VLCSubTablesSizes[i],
mp3idec_VLCNumSubTables[i],
4, mp3idec_VLCShifts[i], &ts);
size += ts;
if (mem) {
huff_table[i].phuftable = (IppsVLCDecodeSpec_32s *)mem;
mem += ts;
ippsVLCDecodeUTupleInit_32s(mp3idec_VLCBooks[i], mp3idec_VLCTableSizes[i],
mp3idec_VLCSubTablesSizes[i],
mp3idec_VLCNumSubTables[i],
4, mp3idec_VLCShifts[i],
(IppsVLCDecodeUTupleSpec_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 mp3idec_Huffmancodebits(MP3Dec_com *state, Ipp32s gr, Ipp32s ch)
{
Ipp32s j, i, idx, nbits;
Ipp32s reg[3];
IppsVLCDecodeUTupleSpec_32s *pVLCDecSpec;
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
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];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -