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

📄 gain_util.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 5 页
字号:
                                        Ipp16s *codeGainIdx, Ipp16s *qntEnergyErr_M122, Ipp16s *qntEnergyErr)
{
    const Ipp16s *p;
    Ipp16s i, j, cod_ind, pit_ind;
    Ipp16s e_max, exp_code;
    Ipp16s g_pitch, g2_pitch, g_code, g2_code_h, g2_code_l;
    Ipp16s g_pit_cod_h, g_pit_cod_l;
    Ipp16s coeff[5], coeff_lo[5];
    Ipp16s exp_max[5];
    Ipp32s TmpVal, TmpVal0, dist_min;

    exp_code = (Ipp16s)(expGainCodeCB - 10);
    exp_max[0] = (Ipp16s)(expCoeff[0] - 13);
    exp_max[1] = (Ipp16s)(expCoeff[1] - 14);
    exp_max[2] = (Ipp16s)(expCoeff[2] + 15 + (exp_code << 1));
    exp_max[3] = (Ipp16s)(expCoeff[3] + exp_code);
    exp_max[4] = (Ipp16s)(expCoeff[4] + exp_code + 1);

    e_max = exp_max[0];
    for(i = 1; i < 5; i++) {
       if (exp_max[i] > e_max) e_max = exp_max[i];
    }

    e_max++;
    for (i = 0; i < 5; i++) {
        j = (Ipp16s)(e_max - exp_max[i]);
        TmpVal = fracCoeff[i] << 16;
        if (j >= (Ipp16s)31) TmpVal = (TmpVal < 0) ? -1 : 0;
        else                TmpVal >>= j;
        Unpack_32s(TmpVal, &coeff[i], &coeff_lo[i]);
    }

    dist_min = IPP_MAX_32S;
    cod_ind = 0;
    pit_ind = 0;

    for (j = 0; j < 3; j++) {
        g_pitch = pitchGainCand[j];
        g2_pitch = (Ipp16s)((g_pitch * g_pitch) >> 15);
        TmpVal0 = Mpy_32_16(coeff[0], coeff_lo[0], g2_pitch);
        TmpVal0 = AddProduct16s_32s(TmpVal0, coeff[1], coeff_lo[1], g_pitch);

        p = &pTblQntGainCode[0];
        for (i = 0; i < LEN_QNT_GAIN; i++)  {
            g_code = *p++;
            p++;
            p++;

            g_code = (Ipp16s)((g_code * predGainCB) >> 15);

            TmpVal = 2 * g_code * g_code;
            Unpack_32s (TmpVal, &g2_code_h, &g2_code_l);

            TmpVal = 2 * g_code * g_pitch;
            Unpack_32s (TmpVal, &g_pit_cod_h, &g_pit_cod_l);

            TmpVal = AddProduct_32s(TmpVal0, coeff[2], coeff_lo[2], g2_code_h, g2_code_l);
            TmpVal = AddProduct16s_32s(TmpVal, coeff[3], coeff_lo[3], g_code);
            TmpVal = AddProduct_32s(TmpVal, coeff[4], coeff_lo[4], g_pit_cod_h, g_pit_cod_l);

            if (TmpVal < dist_min) {
                dist_min = TmpVal;
                cod_ind = i;
                pit_ind = j;
            }
        }
    }

    p = &pTblQntGainCode[3* cod_ind];
    g_code = *p++;
    *qntEnergyErr_M122 = *p++;
    *qntEnergyErr = *p;

    TmpVal = 2 * g_code * predGainCB;
    if (expGainCodeCB > 9) TmpVal <<= (expGainCodeCB - 9);
    else                   TmpVal >>= (9 - expGainCodeCB);
    *codeGainVar = (Ipp16s)(TmpVal >> 16);
    *codeGainIdx = cod_ind;
    *pitchGainVar = pitchGainCand[pit_ind];
    *pitchGainIdx = pitchGainCandIdx[pit_ind];
}


/*************************************************************************
 * Function:  ownGainCodebookQnt_M795
 *************************************************************************/
static Ipp16s ownGainCodebookQnt_M795(Ipp16s pitchGainVar, Ipp16s expGainCodeCB, Ipp16s predGainCB,
                                     Ipp16s *fracEnergyCoeff, Ipp16s *expEnergyCoeff, Ipp16s alpha,
                                     Ipp16s gainCodeUnQnt, Ipp16s *codeGainVar, Ipp16s *qntEnergyErr_M122,
                                     Ipp16s *qntEnergyErr)
{
    const Ipp16s *p;
    Ipp16s i, index, tmp;
    Ipp16s one_alpha;
    Ipp16s exp, e_max;
    Ipp16s g2_pitch, g_code;
    Ipp16s g2_code_h, g2_code_l;
    Ipp16s d2_code_h, d2_code_l;
    Ipp16s coeff[5], coeff_lo[5], expCoeff[5];
    Ipp32s TmpVal, Time0, Time1, dist_min;
    Ipp16s decGainCode;


    /* calculate scalings of the constant terms */
    if (expGainCodeCB > 10)
        decGainCode = Cnvrt_32s16s(*codeGainVar >> (expGainCodeCB - 10));
    else
        decGainCode = Cnvrt_32s16s(*codeGainVar << (10 - expGainCodeCB));
    g2_pitch = (Ipp16s)((pitchGainVar * pitchGainVar) >> 15);
    one_alpha = (Ipp16s)(32767 - alpha + 1);

    tmp = (Ipp16s)((alpha * fracEnergyCoeff[1]) >> 14);
    Time1 = 2 * tmp * g2_pitch;
    expCoeff[1] = (Ipp16s)(expEnergyCoeff[1] - 15);


    tmp = (Ipp16s)((alpha * fracEnergyCoeff[2]) >> 14);
    coeff[2] = (Ipp16s)((tmp * pitchGainVar) >> 15);
    exp = (Ipp16s)(expGainCodeCB - 10);
    expCoeff[2] = (Ipp16s)(expEnergyCoeff[2] + exp);

    coeff[3] = (Ipp16s)((alpha * fracEnergyCoeff[3]) >> 14);
    exp = (Ipp16s)((expGainCodeCB << 1) - 7);
    expCoeff[3] = (Ipp16s)(expEnergyCoeff[3] + exp);

    coeff[4] = (Ipp16s)((one_alpha * fracEnergyCoeff[3]) >> 15);
    expCoeff[4] = (Ipp16s)(expCoeff[3] + 1);


    TmpVal = 2 * alpha * fracEnergyCoeff[0];
    Time0 = ownSqrt_Exp_GSMAMR(TmpVal, &exp);
    exp += 47;
    expCoeff[0] = (Ipp16s)(expEnergyCoeff[0] - exp);

    e_max = (Ipp16s)(expCoeff[0] + 31);
    for (i = 1; i <= 4; i++)  {
        if (expCoeff[i] > e_max) e_max = expCoeff[i];
    }

    tmp = (Ipp16s)(e_max - expCoeff[1]);
    Time1 >>= tmp;

    for (i = 2; i <= 4; i++) {
        tmp = (Ipp16s)(e_max - expCoeff[i]);
        TmpVal = coeff[i] << 16;
        TmpVal >>= tmp;
        Unpack_32s(TmpVal, &coeff[i], &coeff_lo[i]);
    }

    exp = (Ipp16s)(e_max - 31);             /* new exponent */
    tmp = (Ipp16s)(exp - expCoeff[0]);
    Time0 >>= (tmp >> 1);

    if((tmp & 0x1) != 0) {
        Unpack_32s(Time0, &coeff[0], &coeff_lo[0]);
        Time0 = Mpy_32_16(coeff[0], coeff_lo[0], 23170);
    }

    dist_min = IPP_MAX_32S;
    index = 0;
    p = &pTblQntGainCode[0];

    for (i = 0; i < LEN_QNT_GAIN; i++) {
        g_code = *p;
        p+=3;
        g_code = (Ipp16s)((g_code * predGainCB) >> 15);

        if(g_code >= decGainCode) break;

        TmpVal = 2 * g_code * g_code;
        Unpack_32s (TmpVal, &g2_code_h, &g2_code_l);

        tmp = (Ipp16s)(g_code - gainCodeUnQnt);
        TmpVal = 2 * tmp * tmp;
        Unpack_32s (TmpVal, &d2_code_h, &d2_code_l);

        TmpVal = AddProduct16s_32s (Time1, coeff[2], coeff_lo[2], g_code);
        TmpVal = AddProduct_32s(TmpVal, coeff[3], coeff_lo[3], g2_code_h, g2_code_l);

        TmpVal = ownSqrt_Exp_GSMAMR(TmpVal, &exp);
        TmpVal >>= (exp >> 1);

        tmp = Cnvrt_NR_32s16s(TmpVal - Time0);
        TmpVal = 2 * tmp * tmp;

        TmpVal = AddProduct_32s(TmpVal, coeff[4], coeff_lo[4], d2_code_h, d2_code_l);

        if (TmpVal < dist_min) {
            dist_min = TmpVal;
            index = i;
        }
    }

    p = &pTblQntGainCode[3 * index];
    g_code = *p++;
    *qntEnergyErr_M122 = *p++;
    *qntEnergyErr = *p;

    TmpVal = 2 * g_code * predGainCB;
    if (expGainCodeCB > 9) TmpVal <<= (expGainCodeCB - 9);
    else                   TmpVal >>= (9 - expGainCodeCB);
    *codeGainVar = (Ipp16s)(TmpVal >> 16);

    return index;
}

/*************************************************************************
 * Function:  ownGainQuant_M795_GSMAMR
 *************************************************************************/
void ownGainQuant_M795_GSMAMR(Ipp16s *vOnSetQntGain, Ipp16s *vPrevAdaptOut, Ipp16s *vPrevGainZero, Ipp16s *a_LTPHistoryGain,
                              Ipp16s *pLTPRes, Ipp16s *pLTPExc, Ipp16s *code, Ipp16s *fracCoeff, Ipp16s *expCoeff, Ipp16s expCodeEnergy,
                              Ipp16s fracCodeEnergy, Ipp16s expGainCodeCB, Ipp16s fracGainCodeCB,  Ipp16s L_subfr, Ipp16s codGainFrac,
                              Ipp16s codGainExp, Ipp16s gainPitchLimit, Ipp16s *pitchGainVar, Ipp16s *codeGainVar,
                              Ipp16s *qntEnergyErr_M122, Ipp16s *qntEnergyErr, Ipp16s **ppAnalysisParam)
{
    Ipp16s fracEnergyCoeff[4];
    Ipp16s expEnergyCoeff[4];
    Ipp16s ltpg, alpha, predGainCB;
    Ipp16s pitchGainCand[3];
    Ipp16s pitchGainCandIdx[3];
    Ipp16s gain_pit_index;
    Ipp16s gain_cod_index;
    Ipp16s exp;
    Ipp16s gainCodeUnQnt;

    gain_pit_index = ownQntGainPitch_M7950_GSMAMR (gainPitchLimit, pitchGainVar,pitchGainCand, pitchGainCandIdx);
    predGainCB = (Ipp16s)(ownPow2_GSMAMR(14, fracGainCodeCB));          /* Q14 */

    ownPreQnt3CodebookGain_M795(expGainCodeCB, predGainCB, pitchGainCand, pitchGainCandIdx,
                                fracCoeff, expCoeff, pitchGainVar, &gain_pit_index, codeGainVar,
                                &gain_cod_index, qntEnergyErr_M122, qntEnergyErr);

    ownCalcUnFiltEnergy_GSMAMR(pLTPRes, pLTPExc, code, *pitchGainVar, L_subfr, fracEnergyCoeff, expEnergyCoeff, &ltpg);

    ownGainAdaptAlpha_GSMAMR(vOnSetQntGain,vPrevAdaptOut,vPrevGainZero,a_LTPHistoryGain, ltpg, *codeGainVar, &alpha);

    if (fracEnergyCoeff[0] != 0 && alpha > 0)  {
        fracEnergyCoeff[3] = fracCodeEnergy;
        expEnergyCoeff[3] = expCodeEnergy;

        exp = (Ipp16s)(codGainExp - expGainCodeCB + 10);
        if (exp < 0) gainCodeUnQnt = (Ipp16s)(codGainFrac >> -exp);
        else         gainCodeUnQnt = ShiftL_16s(codGainFrac, exp);

        gain_cod_index = ownGainCodebookQnt_M795(*pitchGainVar, expGainCodeCB, predGainCB,
                                                 fracEnergyCoeff, expEnergyCoeff, alpha, gainCodeUnQnt,
                                                 codeGainVar, qntEnergyErr_M122, qntEnergyErr);
    }

    *(*ppAnalysisParam)++ = gain_pit_index;
    *(*ppAnalysisParam)++ = gain_cod_index;

⌨️ 快捷键说明

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