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

📄 mp3dec_layer3_fp.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 3 页
字号:
    i = 0;
    for (j = 0; j < 3; j++) {
        Ipp32s  linbits, ii;
        Ipp16s *qp;

        idx = si_pTableSelect[gr][ch][j];
        if (idx == 4 || idx == 14) {
          return 1;
        }

        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++) {
                    Ipp32s  tmp = pDst[ii];

                    qp[0] = (Ipp16s)(tmp >> shift);
                    qp[1] = (Ipp16s)((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_trace2(VM_DEBUG_ALL, VM_STRING("Frame %d, granule %d,"), state->m_frame_num, gr);
        vm_debug_trace2(VM_DEBUG_ALL, VM_STRING(" channel %d, error: nbits %d < 0 before zero-one part\n"), 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;
        Ipp32s  saved_bitoffset;
        Ipp32s  decoded_bits;
        Ipp32s  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] = (Ipp16s)(tmp >> (3 * shift));
        (*smpl_xs)[ch][i + 1] = (Ipp16s)(((tmp >> (2 * shift)) & mask) - offset);
        (*smpl_xs)[ch][i + 2] = (Ipp16s)(((tmp >> (shift)) & mask) - offset);
        (*smpl_xs)[ch][i + 3] = (Ipp16s)((tmp & mask) - offset);

        i += 4;
    }

    if (nbits < 0) {
        vm_debug_trace2(VM_DEBUG_ALL, VM_STRING("Frame %d, granule %d,"), state->m_frame_num, gr);
        vm_debug_trace2(VM_DEBUG_ALL, VM_STRING(" channel %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 mp3dec_Dequant(MP3Dec *state, Ipp32s gr, Ipp32s ch)
{
    Ipp32f  xx;    // xx it is recalculated global gain
    Ipp16s  scl;
    Ipp32s  sfb, j, last_sb;

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

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

    Ipp32f  (*GlobalScaleFactor)[2] = state->GlobalScaleFactor;
    Ipp32s  *non_zero = state->com.non_zero;
    Ipp32s  count = non_zero[ch];
    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;
    samplefloat *smpl_xr = state->smpl_xr;       /* out of dequantizer */
    sampleshort *smpl_xs = state->com.smpl_xs;       // out of huffman

    scl = -2 - 2 * (Ipp16s)si_sfScale[gr][ch];
    xx = GlobalScaleFactor[gr][ch];

    ippsPow43_16s32f((*smpl_xs)[ch], (*smpl_xr)[ch], state->com.non_zero[ch]);
    ippsZero_32f((*smpl_xr)[ch] + state->com.non_zero[ch], 576 - state->com.non_zero[ch]);

    if (si_blockType[gr][ch] != 2) {
        Ipp32f  tmp22[22];
        Ipp16s  sf_tmp[21];

        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);
        }

        last_sb = 22;
        for (j = 1; j <= 22; j++) {
          if (sfb_long[j] >= state->com.non_zero[ch]) {
            last_sb = j;
            break;
          }
        }

        ippsCalcSF_16s32f(sf_tmp, 0, tmp22, last_sb > 21 ? 21 : last_sb);
        tmp22[21] = 1;
        ippsMulC_32f_I(xx, tmp22, last_sb);
        ippsScale_32f_I((*smpl_xr)[ch], tmp22, sfb_long, last_sb);
    } else {
        Ipp32f  tmpSF[3], tmp13[3][13];
        Ipp16s  sf_tmp[13];
        Ipp32s  n, j, 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);

            ippsCalcSF_16s32f(sf_tmp, 0, tmp13[0], sfbEnd);
            ippsMulC_32f_I(xx, tmp13[0], sfbEnd);
            ippsScale_32f_I((*smpl_xr)[ch], tmp13[0], sfb_long, sfbEnd);
        }

        ippsCalcSF_16s32f(si_pSubBlkGain[gr][ch], 0, tmpSF, 3);

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

            ippsCalcSF_16s32f(&sf_tmp[sfbStart], 0, &tmp13[wnd][sfbStart], 13 - sfbStart);
            ippsMulC_32f_I(xx * tmpSF[wnd], &tmp13[wnd][sfbStart], 13 - sfbStart);
        }

        j = sfb_long[sfbEnd];
        for (sfb = sfbStart; sfb <= 12; sfb++) {
            n = sfb_short[sfb + 1] - sfb_short[sfb];
            for (wnd = 0; wnd < 3; wnd++) {
                ippsScale_32f_I(&((*smpl_xr)[ch][j]) - sfb_short[sfb], &tmp13[wnd][sfb], sfb_short + sfb, 1);
                j += n;
            }
        } // for
    }

    while(count > 0 && ((Ipp32s *)((*smpl_xr)[ch]))[count - 1] == 0)
        count --;
    state->com.non_zero[ch] = count;

    ippsMulC_32f_I(32768, (*smpl_xr)[ch], count);

    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 mp3dec_Reordering(MP3Dec *state, Ipp32s gr, Ipp32s ch)
{
    Ipp32f  tmp_buf[576];
    Ipp32f  *dstPtr, *srcPtr;
    Ipp32s  i, sfb, shift, startSfb, wl = 0;
    Ipp32s  nz = state->com.non_zero[ch];

    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;
    samplefloat *smpl_xr = state->smpl_xr;       /* out of dequantizer */

    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_32f(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 mp3dec_Antialiasing(MP3Dec *state, Ipp32s gr, Ipp32s ch)
{
    Ipp32s sblim, freqline, i, idx1, idx2;
    Ipp32f 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;
    samplefloat *smpl_re = state->smpl_re;       // out of huffman
    samplefloat *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];
            bd = (*smpl_ro)[ch][idx2];

            (*smpl_re)[ch][idx1] = (bu * cs[i]) - (bd * ca[i]);
            (*smpl_re)[ch][idx2] = (bd * cs[i]) + (bu * 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 mp3dec_JointStereo(MP3Dec *state, Ipp32s gr)
{
    const Ipp32f mult = 0.7071067811865475244f;
    Ipp32s isPos[39], found[3];
    Ipp32s *width;
    Ipp32s *scalefPtr, *widthPtr;
    Ipp32f *ptrL, *ptrR;
    Ipp32f li, ri;
    Ipp32f 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;
    samplefloat *smpl_xr = state->smpl_xr; /* out of dequantizer */
    Ipp32s nz = state->com.non_zero[0];
    Ipp32s f20 = 0, f11 = 0;

⌨️ 快捷键说明

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