⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3dec_layer3_int.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 3 页
字号:

    pSrc = (Ipp8u *)BS->pCurrent_dword + ((32 - BS->nBit_offset) >> 3);
    bitoffset = (32 - BS->nBit_offset) & 0x7;

    i = 0;
    for (j = 0; j < 3; j++) {
        Ipp32s linbits;

        idx = si_pTableSelect[gr][ch][j];
        pVLCDecSpec = (IppsVLCDecodeUTupleSpec_32s *) huff_table[idx].phuftable;
        linbits = huff_table[idx].linbits;

        if (idx == 4 || idx == 14) {
          return 1;
        }
        if (idx) {
            if (linbits == 0) {
                ippsVLCDecodeUTupleBlock_1u16s(&pSrc, &bitoffset, &(*smpl_xs)[ch][i], (reg[j] - i),
                    pVLCDecSpec);
            } else {
                ippsVLCDecodeUTupleEscBlock_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_trace2(VM_DEBUG_ALL,VM_STRING("Frame %d, granule %d, channel "),state->m_frame_num, gr);
        vm_debug_trace2(VM_DEBUG_ALL,VM_STRING("%d, error: nbits %d < 0 before zero-one part\n"), ch, nbits);
    }

    pVLCDecSpec = (IppsVLCDecodeUTupleSpec_32s *) huff_table[idx].phuftable;

    // 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;
        Ipp32s saved_bitoffset;
        Ipp32s decoded_bits;

        saved_pSrc = pSrc;
        saved_bitoffset = bitoffset;

        ippsVLCDecodeUTupleOne_1u16s(&pSrc, &bitoffset, &(*smpl_xs)[ch][i], pVLCDecSpec);
        decoded_bits = ((pSrc - saved_pSrc) << 3) + (bitoffset - saved_bitoffset);
        nbits -= decoded_bits;

        i += 4;
    }

    if (nbits < 0) {
        vm_debug_trace2(VM_DEBUG_ALL,VM_STRING("Frame %d, granule %d, channel "),state->m_frame_num, gr);
        vm_debug_trace2(VM_DEBUG_ALL,VM_STRING("%d, error: nbits %d < 0 before zero-one part\n"), 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 0;
}

/******************************************************************************
//  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 Ipp32s mp3idec_Dequant(MP3Dec *state, Ipp32s gr, Ipp32s ch)
{
    Ipp16s scl;
    Ipp32s sfb;
    Ipp32s nz;

    IppMP3FrameHeader *header = &(state->com.header);

    Ipp32s *sfb_long = mp3dec_sfBandIndex_l[header->id + state->com.mpg25][header->samplingFreq];

    sScaleFactors *ScaleFactors = state->com.ScaleFactors;
    Ipp32u (*si_blockType)[2] = state->com.si_blockType;
    Ipp32u (*si_mixedBlock)[2] = state->com.si_mixedBlock;
    Ipp16s (*si_pSubBlkGain)[2][3] = state->com.si_pSubBlkGain;
    Ipp32u (*si_preFlag)[2] = state->com.si_preFlag;
    Ipp32u (*si_sfScale)[2] = state->com.si_sfScale;
    sampleint *smpl_xr = state->smpl_xr;       /* out of dequantizer */
    sampleshort *smpl_xs = state->com.smpl_xs;       // out of huffman
    Ipp16s (*si_globGain)[2] = state->com.si_globGain;
    Ipp32s globalGain210  = 106 - si_globGain[gr][ch];
    Ipp16s sf_tmp[22];
    Ipp16s sf_tmp_n[3][13];
    Ipp32s j, last_sb;

    scl = -2 - 2 * (Ipp16s)si_sfScale[gr][ch];
    ippsZero_32s((*smpl_xr)[ch], 576);

    if (si_blockType[gr][ch] != 2) {
        if (si_preFlag[gr][ch] == 0) {
            ippsMulC_16s_Sfs(&(ScaleFactors[ch].l[0]), scl, sf_tmp, 21, 0);
        } else {
            ippsAdd_16s_Sfs(&(ScaleFactors[ch].l[0]), pretab, sf_tmp, 21, 0);
            ippsMulC_16s_ISfs(scl, sf_tmp, 21, 0);
        }
        sf_tmp[21] = 0;

        last_sb = 22;
        for (j = 1; j <= 22; j++) {
          if (sfb_long[j] >= state->com.non_zero[ch]) {
            last_sb = j;
            break;
          }
        }
        ippsPow43Scale_16s32s_Sf((*smpl_xs)[ch], (*smpl_xr)[ch], sf_tmp, sfb_long, globalGain210, last_sb, 1, 0);
        ippsZero_32s((*smpl_xr)[ch] + state->com.non_zero[ch], 576 - state->com.non_zero[ch]);
    } else {
        Ipp32s  n, wnd;
        Ipp32s  sfbStart, sfbEnd;
        Ipp32s  *sfb_short = mp3dec_sfBandIndex_s[header->id + state->com.mpg25][header->samplingFreq];

        sfbEnd = 0; sfbStart = 0;
        if (si_mixedBlock[gr][ch]) {
            if (header->id == 1) {
                sfbEnd = 8;
            } else {
                sfbEnd = 6;
            }
            sfbStart = 3;

            ippsMulC_16s_Sfs(&ScaleFactors[ch].l[0], scl, &sf_tmp[0], sfbEnd, 0);

            ippsPow43Scale_16s32s_Sf((*smpl_xs)[ch], (*smpl_xr)[ch], sf_tmp, sfb_long,globalGain210,sfbEnd,1,0);
        }

        for (wnd = 0; wnd < 3; wnd++) {
            ippsMulC_16s_Sfs(&ScaleFactors[ch].s[wnd][sfbStart], scl, &sf_tmp_n[wnd][sfbStart], 13 - sfbStart, 0);
        }

        j = sfb_long[sfbEnd];
        for (sfb = sfbStart; sfb <= 12; sfb++) {
            n = sfb_short[sfb + 1] - sfb_short[sfb];
            for (wnd = 0; wnd < 3; wnd++) {
                ippsPow43Scale_16s32s_Sf(&((*smpl_xs)[ch][j]) - sfb_short[sfb], &((*smpl_xr)[ch][j]) - sfb_short[sfb],
                  &sf_tmp_n[wnd][sfb], sfb_short + sfb,globalGain210,1,1,-si_pSubBlkGain[gr][ch][wnd]>>2);
                j += n;
            }
        } // for
    }

    nz = state->com.non_zero[ch];
    while(nz > 0 && ((*smpl_xr)[ch])[nz - 1] == 0)
        nz --;
    state->com.non_zero[ch] = nz;
    return 1;
}

/******************************************************************************
//  Name:
//    Reordering
//
//  Description:
//
//
//
//  Input Arguments:
//    DC - point to sDecoderContext structure
//    gr - number of granule
//    ch - number of channel
//
//  Output Arguments:
//    smpl_ro - array of reordered samples
//
//  Returns:
//    1 - all ok
//
******************************************************************************/

static Ipp32s mp3idec_Reordering(MP3Dec *state, Ipp32s gr, Ipp32s ch)
{
    Ipp32s tmp_buf[576];
    Ipp32s *dstPtr, *srcPtr;
    Ipp32s i, sfb, shift, startSfb;

    IppMP3FrameHeader *header = &(state->com.header);
    Ipp32u (*si_blockType)[2] = state->com.si_blockType;
    Ipp32u (*si_mixedBlock)[2] = state->com.si_mixedBlock;
    Ipp32u (*si_winSwitch)[2] = state->com.si_winSwitch;
    sampleint *smpl_xr = state->smpl_xr;       /* out of dequantizer */
    Ipp32s  wl = 0;
    Ipp32s  nz = state->com.non_zero[ch];

    if (si_winSwitch[gr][ch] && (si_blockType[gr][ch] == 2)) {
        Ipp32s *sfbShort = mp3dec_sfBandIndex_s[header->id + state->com.mpg25][header->samplingFreq];
        if (si_mixedBlock[gr][ch]) {
            shift = sfbShort[3] * 3;
            startSfb = 3;
        } else {
            shift = 0;
            startSfb = 0;
        }
        srcPtr = (*smpl_xr)[ch] + shift;
        dstPtr = tmp_buf;
        for (sfb = startSfb; sfb < 13; sfb++) {
            Ipp32s w = sfbShort[sfb + 1] - sfbShort[sfb];
            for (i = 0; i < w; i++) {
                dstPtr[0] = srcPtr[0];
                dstPtr[1] = srcPtr[w];
                dstPtr[2] = srcPtr[2*w];
                dstPtr += 3; srcPtr++;
            }
            srcPtr += 2*w;
            if (sfbShort[sfb] <= nz)
              wl = w;
        }
        ippsCopy_32s(tmp_buf, (*smpl_xr)[ch] + shift, 576 - shift);

        state->com.non_zero[ch] += wl*3;
        if (state->com.non_zero[ch] > 576)
          state->com.non_zero[ch] = 576;
    }

    return 1;
}

/******************************************************************************
//  Name:
//    Antialiasing
//
//  Description:
//
//
//
//  Input Arguments:
//    DC - point to sDecoderContext structure
//    gr - number of granule
//    ch - number of channel
//
//  Output Arguments:
//    smpl_re - array of spectrum samples
//
//  Returns:
//    1 - all ok
//
******************************************************************************/

static Ipp32s mp3idec_Antialiasing(MP3Dec *state, Ipp32s gr, Ipp32s ch)
{
    Ipp32s sblim, freqline, i, idx1, idx2;
    Ipp32s bu, bd;

    Ipp32u (*si_blockType)[2] = state->com.si_blockType;
    Ipp32u (*si_mixedBlock)[2] = state->com.si_mixedBlock;
    Ipp32u (*si_winSwitch)[2] = state->com.si_winSwitch;
    sampleint *smpl_re = state->smpl_re;       // out of huffman
    sampleint *smpl_ro = state->smpl_ro;       // out of huffman
    Ipp32s nz, freqline_end;

    if (si_winSwitch[gr][ch] && (si_blockType[gr][ch] == 2) &&
        !si_mixedBlock[gr][ch])
        return 1;
    if (si_winSwitch[gr][ch] && (si_blockType[gr][ch] == 2) &&
        si_mixedBlock[gr][ch])
        return 1;
    else
        sblim = 31;

    freqline_end = sblim * 18;
    nz = state->com.non_zero[ch] - 10;
    if (freqline_end > nz)
        freqline_end = nz;

    for (freqline = 0; freqline < freqline_end; freqline += 18) {
        for (i = 0; i < 8; i++) {
            idx1 = freqline + 17 - i;
            idx2 = freqline + 18 + i;

            bu = (*smpl_ro)[ch][idx1] << 1;
            bd = (*smpl_ro)[ch][idx2] << 1;

            *(Ipp32s*)&(*smpl_re)[ch][idx1] =
                MUL32_MP3_32S(bu, aa_cs[i]) -
                MUL32_MP3_32S(bd, aa_ca[i]);

            *(Ipp32s*)&(*smpl_re)[ch][idx2] =
                MUL32_MP3_32S(bd, aa_cs[i]) +
                MUL32_MP3_32S(bu, aa_ca[i]);
        }
    }

    state->com.non_zero[ch] += 14;
    if (state->com.non_zero[ch] > 576)
      state->com.non_zero[ch] = 576;

    return 1;
}

/******************************************************************************
//  Name:
//    Joint stereo
//
//  Description:
//    MS stereo & intensity streo implementation//
//
//  Input Arguments:
//
//
//  Output Arguments:
//
//
//  Returns:
//    1 - all ok
//
******************************************************************************/

static Ipp32s mp3idec_JointStereo(MP3Dec *state, Ipp32s gr)
{
    const Ipp32s mult = 1518500249; /* Q31 */
    Ipp32s isPos[39], found[3];
    Ipp32s *width;
    Ipp32s *scalefPtr, *widthPtr;
    Ipp32s *ptrL, *ptrR;
    Ipp32s li, ri;
    Ipp32s k[2];
    Ipp32s illegal;
    Ipp32s numSfbLong, numSfbShort, numSfb;
    Ipp32s sfbStart, sfbEnd, numBlock;
    Ipp32s i, j, sfb, w;

    Ipp32s blocknumber = state->com.blocknumber;
    Ipp32s blocktypenumber = state->com.blocktypenumber;
    IppMP3FrameHeader *header = &(state->com.header);
    Ipp32s intensity = state->com.intensity;
    Ipp32s ms_stereo = state->com.ms_stereo;
    Ipp32s *s_len = state->com.s_len;
    Ipp32u (*si_blockType)[2] = state->com.si_blockType;
    Ipp32u (*si_mixedBlock)[2] = state->com.si_mixedBlock;
    Ipp32u (*si_sfCompress)[2] = state->com.si_sfCompress;
    sScaleFactors *ScaleFactors = state->com.ScaleFactors;
    sampleint *smpl_xr = state->smpl_xr; /* out of dequantizer */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -