📄 mp3dec_layer3.c
字号:
// 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)) { reg[0] = 36; reg[1] = 576; } else { reg[0] = mp3dec_sfBandIndex[header->id][header->samplingFreq].l[si_reg0Cnt[gr][ch] + 1]; reg[1] = mp3dec_sfBandIndex[header->id][header->samplingFreq].l[si_reg0Cnt[gr][ch] + si_reg1Cnt[gr][ch] + 2]; } reg[2] = si_bigVals[gr][ch] * 2; 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; i = 0; for (j = 0; j < 3; j++) { int linbits, ii; short *qp; idx = si_pTableSelect[gr][ch][j]; pVLCDecSpec = (IppsVLCDecodeSpec_32s *) huff_table[idx].phuftable; linbits = huff_table[idx].linbits; shift = mp3dec_VLCShifts[idx]; offset = mp3dec_VLCOffsets[idx]; mask = (1 << (shift)) - 1; if (idx) { if (linbits == 0) { ippsVLCDecodeBlock_1u16s(&pSrc, &bitoffset, pDst, (reg[j] - i) >> 1, pVLCDecSpec); qp = &(*smpl_xs)[ch][i]; for (ii = 0; ii < (reg[j] - i) >> 1; ii++) { int tmp = pDst[ii]; qp[0] = (short)(tmp >> shift); qp[1] = (short)((tmp & mask) - offset); qp += 2; } } else { ippsVLCDecodeEscBlock_MP3_1u16s(&pSrc, &bitoffset, linbits, &(*smpl_xs)[ch][i], (reg[j] - i), pVLCDecSpec); } i = reg[j]; } else { for (; i < reg[j]; i += 2) { (*smpl_xs)[ch][i] = 0; (*smpl_xs)[ch][i + 1] = 0; } } } // for BS->pCurrent_dword = (Ipp32u *)(pSrc - (((Ipp32s)(pSrc) & 3) - ((Ipp32s)(BS->pCurrent_dword) & 3))); BS->dword = BSWAP(BS->pCurrent_dword[0]); BS->nBit_offset = 32 - ((pSrc - (Ipp8u *)BS->pCurrent_dword) << 3) - bitoffset; idx = si_cnt1TabSel[gr][ch] + 32; nbits = si_part23Len[gr][ch] - (((BS->pCurrent_dword - BS->pBuffer) * 32 + 32 - BS->nBit_offset) - part2_start); if (nbits < 0) { vm_debug_trace(-1, VM_STRING ("Frame %d, granule %d, channel %d, error: nbits %d < 0 before zero-one part\n"), state->m_frame_num, gr, ch, nbits); } pVLCDecSpec = (IppsVLCDecodeSpec_32s *) huff_table[idx].phuftable; shift = mp3dec_VLCShifts[idx]; offset = mp3dec_VLCOffsets[idx]; mask = (1 << (shift)) - 1; // decoding continues until all huffman bits have been decoded or until 576 // frequency lines have been decoded while ((nbits > 0) && ((i + 4) <= 576)) { Ipp8u *saved_pSrc; int saved_bitoffset; int decoded_bits; int tmp; saved_pSrc = pSrc; saved_bitoffset = bitoffset; ippsVLCDecodeOne_1u16s(&pSrc, &bitoffset, pDst, pVLCDecSpec); decoded_bits = ((pSrc - saved_pSrc) << 3) + (bitoffset - saved_bitoffset); nbits -= decoded_bits; tmp = pDst[0]; (*smpl_xs)[ch][i] = (short)(tmp >> (3 * shift)); (*smpl_xs)[ch][i + 1] = (short)(((tmp >> (2 * shift)) & mask) - offset); (*smpl_xs)[ch][i + 2] = (short)(((tmp >> (shift)) & mask) - offset); (*smpl_xs)[ch][i + 3] = (short)((tmp & mask) - offset); i += 4; } if (nbits < 0) { vm_debug_trace(-1, VM_STRING ("Frame %d, granule %d, channel %d, error: nbits %d < 0 before zero-one part\n"), state->m_frame_num, gr, ch, nbits); i -= 4; (*smpl_xs)[ch][i] = 0; (*smpl_xs)[ch][i + 1] = 0; (*smpl_xs)[ch][i + 2] = 0; (*smpl_xs)[ch][i + 3] = 0; } j = i; for (; i < 576; i++) (*smpl_xs)[ch][i] = 0; while(j > 0 && (*smpl_xs)[ch][j - 1] == 0) j--; non_zero[ch] = j; BS->pCurrent_dword = (Ipp32u *)(pSrc - (((Ipp32s)(pSrc) & 3) - ((Ipp32s)(BS->pCurrent_dword) & 3))); BS->dword = BSWAP(BS->pCurrent_dword[0]); BS->nBit_offset = 32 - ((pSrc - (Ipp8u *)BS->pCurrent_dword) << 3) - bitoffset; return 1;}/******************************************************************************// Name:// audio_data_LSF_LayerIII//// Description:// read side information for LSF case//// Input Arguments:// DC - point to sDecoderContext structure//// Output Arguments:// DC - point to sDecoderContext structure, side info//// Returns:// 1 - all ok// -2 - wrong block type//******************************************************************************/int mp3dec_audio_data_LSF_LayerIII(MP3Dec_com *state) { int gr = 0, ch; int tmp; sBitsreamBuffer *BS = &(state->m_StreamData); unsigned int (*si_part23Len)[2] = state->si_part23Len; unsigned int (*si_bigVals)[2] = state->si_bigVals; short (*si_globGain)[2] = state->si_globGain; unsigned int (*si_sfCompress)[2] = state->si_sfCompress; unsigned int (*si_winSwitch)[2] = state->si_winSwitch; unsigned int (*si_blockType)[2] = state->si_blockType; unsigned int (*si_mixedBlock)[2] = state->si_mixedBlock; unsigned int (*si_pTableSelect)[2][3] = state->si_pTableSelect; short (*si_pSubBlkGain)[2][3] = state->si_pSubBlkGain; unsigned int (*si_reg0Cnt)[2] = state->si_reg0Cnt; unsigned int (*si_reg1Cnt)[2] = state->si_reg1Cnt; unsigned int (*si_sfScale)[2] = state->si_sfScale; unsigned int (*si_cnt1TabSel)[2] = state->si_cnt1TabSel; int stereo = state->stereo; GET_BITS(BS, state->si_main_data_begin, 8); if (stereo == 1) GET_BITS(BS, state->si_private_bits, 1) else GET_BITS(BS, state->si_private_bits, 2) for (ch = 0; ch < stereo; ch++) { GET_BITS(BS, si_part23Len[gr][ch], 12); GET_BITS(BS, si_bigVals[gr][ch], 9); GET_BITS(BS, si_globGain[gr][ch], 8); GET_BITS(BS, si_sfCompress[gr][ch], 9); GET_BITS(BS, si_winSwitch[gr][ch], 1); if (si_winSwitch[gr][ch]) { GET_BITS(BS, si_blockType[gr][ch], 2); GET_BITS(BS, si_mixedBlock[gr][ch], 1); GET_BITS(BS, si_pTableSelect[gr][ch][0], 5); GET_BITS(BS, si_pTableSelect[gr][ch][1], 5); GET_BITS(BS, tmp, 3); si_pSubBlkGain[gr][ch][0] = (short)(-8 * tmp); GET_BITS(BS, tmp, 3); si_pSubBlkGain[gr][ch][1] = (short)(-8 * tmp); GET_BITS(BS, tmp, 3); si_pSubBlkGain[gr][ch][2] = (short)(-8 * tmp); if (si_blockType[gr][ch] == 0) return -2; // wrong block type si_reg0Cnt[gr][ch] = 7 + (si_blockType[gr][ch] == 2 && si_mixedBlock[gr][ch] == 0); si_reg1Cnt[gr][ch] = 20 - si_reg0Cnt[gr][ch]; } else { GET_BITS(BS, si_pTableSelect[gr][ch][0], 5); GET_BITS(BS, si_pTableSelect[gr][ch][1], 5); GET_BITS(BS, si_pTableSelect[gr][ch][2], 5); GET_BITS(BS, si_reg0Cnt[gr][ch], 4); GET_BITS(BS, si_reg1Cnt[gr][ch], 3); si_blockType[gr][ch] = 0; } GET_BITS(BS, si_sfScale[gr][ch], 1); GET_BITS(BS, si_cnt1TabSel[gr][ch], 1); } return 1;}/******************************************************************************// Name:// GetScaleFactors_LSF//// Description:// read scalefactors for LSF case//// Input Arguments:// DC - point to sDecoderContext structure// ch - current channel//// Output Arguments:// DC - point to sDecoderContext structure, side info//// Returns://******************************************************************************/int mp3dec_GetScaleFactorsL3_LSF(MP3Dec_com *state, int ch) { int i, j, k, sfb; unsigned scale_fact, int_scale_fact; short scale_buffer[36]; unsigned char *ptr; IppMP3FrameHeader *header = &(state->header); sBitsreamBuffer *BS = &(state->m_MainData); sScaleFactors *ScaleFactors = state->ScaleFactors; unsigned int (*si_blockType)[2] = state->si_blockType; unsigned int (*si_mixedBlock)[2] = state->si_mixedBlock; unsigned int (*si_sfCompress)[2] = state->si_sfCompress; unsigned int (*si_winSwitch)[2] = state->si_winSwitch; unsigned int (*si_preFlag)[2] = state->si_preFlag; int blocknumber = 0; int blocktypenumber; int *s_len = state->s_len; memset(scale_buffer, 0, sizeof(short) * 36); scale_fact = si_sfCompress[0][ch]; blocktypenumber = 0; if ((si_blockType[0][ch] == 2) && (si_mixedBlock[0][ch] == 0)) blocktypenumber = 1; if ((si_blockType[0][ch] == 2) && (si_mixedBlock[0][ch] == 1)) blocktypenumber = 2; if (!(((header->modeExt == 1) || (header->modeExt == 3)) && (ch == 1))) { if (scale_fact < 400) { s_len[0] = (scale_fact >> 4) / 5; s_len[1] = (scale_fact >> 4) % 5; s_len[2] = (scale_fact % 16) >> 2; s_len[3] = (scale_fact % 4); si_preFlag[0][ch] = 0; blocknumber = 0; } else if (scale_fact < 500) { s_len[0] = ((scale_fact - 400) >> 2) / 5; s_len[1] = ((scale_fact - 400) >> 2) % 5; s_len[2] = (scale_fact - 400) % 4; s_len[3] = 0; si_preFlag[0][ch] = 0; blocknumber = 1; } else if (scale_fact < 512) { s_len[0] = (scale_fact - 500) / 3; s_len[1] = (scale_fact - 500) % 3; s_len[2] = 0; s_len[3] = 0; si_preFlag[0][ch] = 0; blocknumber = 2; } } else { int_scale_fact = scale_fact >> 1; if (int_scale_fact < 180) { s_len[0] = int_scale_fact / 36; s_len[1] = (int_scale_fact % 36) / 6; s_len[2] = (int_scale_fact % 36) % 6; s_len[3] = 0; si_preFlag[0][ch] = 0; blocknumber = 3; } else if (int_scale_fact < 244) { s_len[0] = ((int_scale_fact - 180) % 64) >> 4; s_len[1] = ((int_scale_fact - 180) % 16) >> 2; s_len[2] = (int_scale_fact - 180) % 4; s_len[3] = 0; si_preFlag[0][ch] = 0; blocknumber = 4; } else if (int_scale_fact < 255) { s_len[0] = (int_scale_fact - 244) / 3; s_len[1] = (int_scale_fact - 244) % 3; s_len[2] = 0; s_len[3] = 0; si_preFlag[0][ch] = 0; blocknumber = 5; } } k = 0; ptr = mp3dec_nr_of_sfb[blocknumber][blocktypenumber]; for (i = 0; i < 4; i++) { int num = ptr[i]; int len = s_len[i]; if (len) { for (j = 0; j < num; j++) { GET_BITS(BS, scale_buffer[k++], len); } } else { for (j = 0; j < num; j++) { scale_buffer[k++] = 0; } } } k = 0; if (si_winSwitch[0][ch] && (si_blockType[0][ch] == 2)) { if (si_mixedBlock[0][ch]) { for (sfb = 0; sfb < 8; sfb++) { ScaleFactors[ch].l[sfb] = scale_buffer[k]; k++; } for (sfb = 3; sfb < 12; sfb++) for (i = 0; i < 3; i++) { ScaleFactors[ch].s[i][sfb] = scale_buffer[k]; k++; } } else { for (k = 0, sfb = 0; sfb < 12; sfb++) for (i = 0; i < 3; i++) { ScaleFactors[ch].s[i][sfb] = scale_buffer[k]; k++; } } } else { for (sfb = 0; sfb < 21; sfb++) { ScaleFactors[ch].l[sfb] = scale_buffer[sfb]; } } state->blocknumber = blocknumber; state->blocktypenumber = blocktypenumber; return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -