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

📄 mp3dec_layer3.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*//////////////////////////////////////////////////////////////////////////////////                  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-2005 Intel Corporation. All Rights Reserved.//*/#include "mp3dec_own.h"/* scfsi_band  scalefactor bands (p.24 ISO/IEC 11172-3 )*/static struct {    int     l[5];    int     s[3];} sfbtable = {    {        0, 6, 11, 16, 21}, {            0, 6, 12}};static int slen[2][16] = {    {0x0, 0x0, 0x0, 0x0, 0x3, 0x1, 0x1, 0x1, 0x2, 0x2, 0x2, 0x3, 0x3, 0x3, 0x4, 0x4},    {0x0, 0x1, 0x2, 0x3, 0x0, 0x1, 0x2, 0x3, 0x1, 0x2, 0x3, 0x1, 0x2, 0x3, 0x2, 0x3}};/* Table 3-B.8. Layer III scalefactor bands (p.33 Annex_AB ISO/IEC 11172-3)*/ssfBandIndex mp3dec_sfBandIndex[2][3] = {    {        {            {                0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238,                    284, 336, 396, 464, 522, 576}, {                        0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192}        }, {            {                0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232,                    278, 330, 394, 464, 540, 576}, {                        0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192}        }, {            {                0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238,                    284, 336, 396, 464, 522, 576}, {                        0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192}        },}, {            {                {                    0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162,                        196, 238, 288, 342, 418, 576}, {                            0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192}            },        /* Table 3-B.8b */            {                {                    0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156,                        190, 230, 276, 330, 384, 576}, {                            0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192}            },        /* Table 3-B.8c */            {                {                    0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194,                        240, 296, 364, 448, 550, 576}, {                            0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192}            } /* Table 3-B.8a */        }};unsigned char mp3dec_nr_of_sfb[6][3][4] ={    {{0x6, 0x5, 0x5, 0x5}, { 0x9,  0x9, 0x9, 0x9}, {0x6,  0x9, 0x9, 0x9}},    {{0x6, 0x5, 0x7, 0x3}, { 0x9,  0x9, 0xc, 0x6}, {0x6,  0x9, 0xc, 0x6}},    {{0xb, 0xa, 0x0, 0x0}, {0x12, 0x12, 0x0, 0x0}, {0xf, 0x12, 0x0, 0x0}},    {{0x7, 0x7, 0x7, 0x0}, { 0xc,  0xc, 0xc, 0x0}, {0x6,  0xf, 0xc, 0x0}},    {{0x6, 0x6, 0x6, 0x3}, { 0xc,  0x9, 0x9, 0x6}, {0x6,  0xc, 0x9, 0x6}},    {{0x8, 0x8, 0x5, 0x0}, { 0xf,  0xc, 0x9, 0x0}, {0x6, 0x12, 0x9, 0x0}}};/******************************************************************************//  Name://    GetScaleFactors////  Description://    read scalefactors for one granule of channel////  Input Arguments://    state - point to MP3Dec structure//    gr - number of granule//    ch - number of channel////  Output Arguments://    ScaleFactors - array of scalefactors////  Returns://    1 - all ok//******************************************************************************/int mp3dec_GetScaleFactorsL3(MP3Dec_com *state, int gr, int ch) {    int     sfb, window, i;    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_scfsi = state->si_scfsi;    unsigned int (*si_sfCompress)[2] = state->si_sfCompress;    unsigned int (*si_winSwitch)[2] = state->si_winSwitch;    if (si_winSwitch[gr][ch] && (si_blockType[gr][ch] == 2)) {        if (si_mixedBlock[gr][ch]) {            for (sfb = 0; sfb < 8; sfb++)                if (slen[0][si_sfCompress[gr][ch]] != 0)                    GET_BITS(BS, ScaleFactors[ch].l[sfb],                        slen[0][si_sfCompress[gr][ch]])                else                    ScaleFactors[ch].l[sfb] = 0;            for (sfb = 3; sfb < 6; sfb++)                for (window = 0; window < 3; window++)                    if (slen[0][si_sfCompress[gr][ch]] != 0)                        GET_BITS(BS, ScaleFactors[ch].s[window][sfb],                            slen[0][si_sfCompress[gr][ch]])                    else                        ScaleFactors[ch].s[window][sfb] = 0;            for (sfb = 6; sfb < 12; sfb++)                for (window = 0; window < 3; window++)                    if (slen[1][si_sfCompress[gr][ch]] != 0)                        GET_BITS(BS, ScaleFactors[ch].s[window][sfb],                            slen[1][si_sfCompress[gr][ch]])                    else                        ScaleFactors[ch].s[window][sfb] = 0;        } else {  /* SHORT */            for (i = 0; i < 2; i++)                for (sfb = sfbtable.s[i]; sfb < sfbtable.s[i + 1]; sfb++)                    for (window = 0; window < 3; window++)                        if (slen[i][si_sfCompress[gr][ch]] != 0)                            GET_BITS(BS, ScaleFactors[ch].s[window][sfb],                                slen[i][si_sfCompress[gr][ch]])                        else                            ScaleFactors[ch].s[window][sfb] = 0;        }        ScaleFactors[ch].s[0][12] = 0;        ScaleFactors[ch].s[1][12] = 0;        ScaleFactors[ch].s[2][12] = 0;    } else {    /* LONG types 0,1,3 */        for (i = 0; i < 4; i++) {            if ((((si_scfsi[ch] >> (3 - i)) & 1) == 0) || (gr == 0)) {                for (sfb = sfbtable.l[i]; sfb < sfbtable.l[i + 1]; sfb++) {                    if (slen[(i < 2) ? 0 : 1][si_sfCompress[gr][ch]] != 0) {                        GET_BITS(BS, ScaleFactors[ch].l[sfb],                            slen[(i < 2) ? 0 : 1][si_sfCompress[gr][ch]]);                    } else {                        ScaleFactors[ch].l[sfb] = 0;                    }                }            }        }    }    return 1;}/******************************************************************************//  Name://    audio_data_LayerIII////  Description://    read side information////  Input Arguments://    state - point to MP3Dec structure////  Output Arguments://    state - point to MP3Dec structure, side info////  Returns://    1 - all ok//   -2 - wrong block type//******************************************************************************/int mp3dec_audio_data_LayerIII(MP3Dec_com *state) {    int     gr, ch;    int     tmp;    sBitsreamBuffer *BS = &(state->m_StreamData);    unsigned int si_main_data_begin;    unsigned int si_private_bits;    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_preFlag)[2] = state->si_preFlag;    unsigned int (*si_sfScale)[2] = state->si_sfScale;    unsigned int (*si_cnt1TabSel)[2] = state->si_cnt1TabSel;    unsigned int *si_scfsi = state->si_scfsi;    int stereo = state->stereo;    GET_BITS(BS, si_main_data_begin, 9);    if (stereo == 1)        GET_BITS(BS, si_private_bits, 5)    else        GET_BITS(BS, si_private_bits, 3)    state->si_main_data_begin = si_main_data_begin;    state->si_private_bits = si_private_bits;    for (ch = 0; ch < stereo; ch++)        GET_BITS(BS, si_scfsi[ch], 4);    for (gr = 0; gr < 2; gr++) {        for (ch = 0; ch < stereo; ch++) {            GET_BITS(BS, tmp, 12 + 9);            si_part23Len[gr][ch] = tmp >> 9;            si_bigVals[gr][ch] = tmp & 0x01ff;            GET_BITS(BS, tmp, 8 + 4 + 1);            si_globGain[gr][ch] = (short)(tmp >> 5);            si_sfCompress[gr][ch] = (tmp >> 1) & 0x0f;            si_winSwitch[gr][ch] = tmp & 1;            GET_BITS(BS, tmp, 22);            if (si_winSwitch[gr][ch]) {                si_blockType[gr][ch] = tmp >> 20;                si_mixedBlock[gr][ch] = (tmp >> 19) & 1;                si_pTableSelect[gr][ch][0] = (tmp >> 14) & 0x01f;                si_pTableSelect[gr][ch][1] = (tmp >> 9) & 0x01f;                si_pSubBlkGain[gr][ch][0] = (short)(-8 * (int)((tmp >> 6) & 0x07));                si_pSubBlkGain[gr][ch][1] = (short)(-8 * (int)((tmp >> 3) & 0x07));                si_pSubBlkGain[gr][ch][2] = (short)(-8 * (int)(tmp & 0x07));                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 {                si_pTableSelect[gr][ch][0] = tmp >> 17;                si_pTableSelect[gr][ch][1] = (tmp >> 12) & 0x01f;                si_pTableSelect[gr][ch][2] = (tmp >> 7) & 0x01f;                si_reg0Cnt[gr][ch] = (tmp >> 3) & 0x0f;                si_reg1Cnt[gr][ch] = tmp & 7;                si_blockType[gr][ch] = 0;            }            GET_BITS(BS, tmp, 3);            si_preFlag[gr][ch] = tmp >> 2;            si_sfScale[gr][ch] = (tmp >> 1) & 1;            si_cnt1TabSel[gr][ch] = tmp & 1;        }    }    return 1;}/******************************************************************************//  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://    -//******************************************************************************/int mp3dec_initialize_huffman(sHuffmanTable *huff_table){    int     i;    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;    for (i = 1; i < 16; i++) {        if (mp3dec_VLCBooks[i]) {            ippsVLCDecodeInitAlloc_32s(mp3dec_VLCBooks[i], mp3dec_VLCTableSizes[i],                mp3dec_VLCSubTablesSizes[i],                mp3dec_VLCNumSubTables[i],                (IppsVLCDecodeSpec_32s **) (&huff_table[i].                phuftable));        }    }    ippsVLCDecodeInitAlloc_32s(mp3dec_VLCBooks[16], mp3dec_VLCTableSizes[16],        mp3dec_VLCSubTablesSizes[16], mp3dec_VLCNumSubTables[16],        (IppsVLCDecodeSpec_32s **) (&huff_table[16].        phuftable));    for (i = 17; i < 24; i++) {        huff_table[i].phuftable = huff_table[16].phuftable;    }    ippsVLCDecodeInitAlloc_32s(mp3dec_VLCBooks[24], mp3dec_VLCTableSizes[24],        mp3dec_VLCSubTablesSizes[24], mp3dec_VLCNumSubTables[24],        (IppsVLCDecodeSpec_32s **) (&huff_table[24].        phuftable));    for (i = 25; i < 32; i++) {        huff_table[i].phuftable = huff_table[24].phuftable;    }    ippsVLCDecodeInitAlloc_32s(mp3dec_VLCBooks[32], mp3dec_VLCTableSizes[32],        mp3dec_VLCSubTablesSizes[32], mp3dec_VLCNumSubTables[32],        (IppsVLCDecodeSpec_32s **) (&huff_table[32].        phuftable));    ippsVLCDecodeInitAlloc_32s(mp3dec_VLCBooks[33], mp3dec_VLCTableSizes[33],        mp3dec_VLCSubTablesSizes[33], mp3dec_VLCNumSubTables[33],        (IppsVLCDecodeSpec_32s **) (&huff_table[33].        phuftable));    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//******************************************************************************/int mp3dec_Huffmancodebits(MP3Dec_com *state, int gr, int ch) {    int     j, i, idx, nbits;    Ipp16s  pDst[576];    int     reg[3];    IppsVLCDecodeSpec_32s *pVLCDecSpec;    int     shift, offset, mask;    sBitsreamBuffer *BS = &(state->m_MainData);    Ipp8u  *pSrc;    int     bitoffset;    IppMP3FrameHeader *header = &(state->header);    sHuffmanTable *huff_table = state->huff_table;    int   *non_zero = state->non_zero;    int     part2_start = state->part2_start;    unsigned int (*si_part23Len)[2] = state->si_part23Len;    unsigned int (*si_bigVals)[2] = state->si_bigVals;    unsigned int (*si_winSwitch)[2] = state->si_winSwitch;    unsigned int (*si_blockType)[2] = state->si_blockType;    unsigned int (*si_pTableSelect)[2][3] = state->si_pTableSelect;    unsigned int (*si_reg0Cnt)[2] = state->si_reg0Cnt;    unsigned int (*si_reg1Cnt)[2] = state->si_reg1Cnt;    unsigned int (*si_cnt1TabSel)[2] = state->si_cnt1TabSel;    sampleshort *smpl_xs = state->smpl_xs;       // out of huffman

⌨️ 快捷键说明

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