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

📄 mp3dec_layer3.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 2 页
字号:
                si_reg0Cnt[gr][ch] = (tmp >> 3) & 0x0f;
                si_reg1Cnt[gr][ch] = tmp & 7;

                si_blockType[gr][ch] = 0;
            }

            GET_BITS(BS, tmp, 3, Ipp32s);
            si_preFlag[gr][ch] = tmp >> 2;
            si_sfScale[gr][ch] = (tmp >> 1) & 1;
            si_cnt1TabSel[gr][ch] = tmp & 1;
        }
    }

    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
//
******************************************************************************/

Ipp32s mp3dec_audio_data_LSF_LayerIII(MP3Dec_com *state) {
    Ipp32s gr = 0, ch;
    Ipp32s tmp;

    sBitsreamBuffer *BS = &(state->m_StreamData);

    Ipp32u (*si_part23Len)[2] = state->si_part23Len;
    Ipp32u (*si_bigVals)[2] = state->si_bigVals;
    Ipp16s (*si_globGain)[2] = state->si_globGain;
    Ipp32u (*si_sfCompress)[2] = state->si_sfCompress;
    Ipp32u (*si_winSwitch)[2] = state->si_winSwitch;
    Ipp32u (*si_blockType)[2] = state->si_blockType;
    Ipp32u (*si_mixedBlock)[2] = state->si_mixedBlock;
    Ipp32u (*si_pTableSelect)[2][3] = state->si_pTableSelect;
    Ipp16s (*si_pSubBlkGain)[2][3] = state->si_pSubBlkGain;
    Ipp32u (*si_reg0Cnt)[2] = state->si_reg0Cnt;
    Ipp32u (*si_reg1Cnt)[2] = state->si_reg1Cnt;
    Ipp32u (*si_sfScale)[2] = state->si_sfScale;
    Ipp32u (*si_cnt1TabSel)[2] = state->si_cnt1TabSel;

    Ipp32s stereo = state->stereo;

    GET_BITS(BS, state->si_main_data_begin, 8, Ipp32s);

    if (stereo == 1)
        GET_BITS(BS, state->si_private_bits, 1, Ipp32s)
    else
        GET_BITS(BS, state->si_private_bits, 2, Ipp32s)

    for (ch = 0; ch < stereo; ch++) {
        GET_BITS(BS, si_part23Len[gr][ch], 12, Ipp32s);
        GET_BITS(BS, si_bigVals[gr][ch], 9, Ipp32s);
        GET_BITS(BS, si_globGain[gr][ch], 8, Ipp16s);
        GET_BITS(BS, si_sfCompress[gr][ch], 9, Ipp32s);
        GET_BITS(BS, si_winSwitch[gr][ch], 1, Ipp32s);

        if (si_winSwitch[gr][ch]) {
            GET_BITS(BS, si_blockType[gr][ch], 2, Ipp32s);
            GET_BITS(BS, si_mixedBlock[gr][ch], 1, Ipp32s);
            GET_BITS(BS, si_pTableSelect[gr][ch][0], 5, Ipp32s);
            GET_BITS(BS, si_pTableSelect[gr][ch][1], 5, Ipp32s);
            GET_BITS(BS, tmp, 3, Ipp32s);
            si_pSubBlkGain[gr][ch][0] = (Ipp16s)(-8 * tmp);
            GET_BITS(BS, tmp, 3, Ipp32s);
            si_pSubBlkGain[gr][ch][1] = (Ipp16s)(-8 * tmp);
            GET_BITS(BS, tmp, 3, Ipp32s);
            si_pSubBlkGain[gr][ch][2] = (Ipp16s)(-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, Ipp32s);
            GET_BITS(BS, si_pTableSelect[gr][ch][1], 5, Ipp32s);
            GET_BITS(BS, si_pTableSelect[gr][ch][2], 5, Ipp32s);
            GET_BITS(BS, si_reg0Cnt[gr][ch], 4, Ipp32s);
            GET_BITS(BS, si_reg1Cnt[gr][ch], 3, Ipp32s);

            si_blockType[gr][ch] = 0;
        }

        GET_BITS(BS, si_sfScale[gr][ch], 1, Ipp32s);
        GET_BITS(BS, si_cnt1TabSel[gr][ch], 1, Ipp32s);
    }

    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:
//
******************************************************************************/

Ipp32s mp3dec_GetScaleFactorsL3_LSF(MP3Dec_com *state, Ipp32s ch) {
    Ipp32s i, j, k, sfb;
    Ipp32u scale_fact, int_scale_fact;
    Ipp16s scale_buffer[36];
    Ipp8u *ptr;

    IppMP3FrameHeader *header = &(state->header);
    sBitsreamBuffer *BS = &(state->m_MainData);
    sScaleFactors *ScaleFactors = state->ScaleFactors;
    Ipp32u (*si_blockType)[2] = state->si_blockType;
    Ipp32u (*si_mixedBlock)[2] = state->si_mixedBlock;
    Ipp32u (*si_sfCompress)[2] = state->si_sfCompress;
    Ipp32u (*si_winSwitch)[2] = state->si_winSwitch;
    Ipp32u (*si_preFlag)[2] = state->si_preFlag;

    Ipp32s blocknumber = 0;
    Ipp32s blocktypenumber;
    Ipp32s *s_len = state->s_len;

    memset(scale_buffer, 0, sizeof(Ipp16s) * 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] = 1;
            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++) {
        Ipp32s num = ptr[i];
        Ipp32s len = s_len[i];
        if (len) {
            for (j = 0; j < num; j++) {
                GET_BITS(BS, scale_buffer[k++], len, Ipp16s);
            }
        } 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 + -