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

📄 gain_util.c

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


static __ALIGN32 CONST Ipp16s TableGainHighRates[VEC_QNT_HIGHRATES_SIZE*4] = {
    577,      662,     -2692,   -16214,      806,     1836,     -1185,    -7135,
   3109,     1052,     -2008,   -12086,     4181,     1387,     -1600,    -9629,
   2373,     1425,     -1560,    -9394,     3248,     1985,     -1070,    -6442,
   1827,     2320,      -840,    -5056,      941,     3314,      -313,    -1885,
   2351,     2977,      -471,    -2838,     3616,     2420,      -777,    -4681,
   3451,     3096,      -414,    -2490,     2955,     4301,        72,      434,
   1848,     4500,       139,      836,     3884,     5416,       413,     2484,
   1187,     7210,       835,     5030,     3083,     9000,      1163,     7002,
   7384,      883,     -2267,   -13647,     5962,     1506,     -1478,    -8900,
   5155,     2134,      -963,    -5800,     7944,     2009,     -1052,    -6335,
   6507,     2250,      -885,    -5327,     7670,     2752,      -588,    -3537,
   5952,     3016,      -452,    -2724,     4898,     3764,      -125,     -751,
   6989,     3588,      -196,    -1177,     8174,     3978,       -43,     -260,
   6064,     4404,       107,      645,     7709,     5087,       320,     1928,
   5523,     6021,       569,     3426,     7769,     7126,       818,     4926,
   6060,     7938,       977,     5885,     5594,    11487,      1523,     9172,
  10581,     1356,     -1633,    -9831,     9049,     1597,     -1391,    -8380,
   9794,     2035,     -1033,    -6220,     8946,     2415,      -780,    -4700,
  10296,     2584,      -681,    -4099,     9407,     2734,      -597,    -3595,
   8700,     3218,      -356,    -2144,     9757,     3395,      -277,    -1669,
  10177,     3892,       -75,     -454,     9170,     4528,       148,      891,
  10152,     5004,       296,     1781,     9114,     5735,       497,     2993,
  10500,     6266,       628,     3782,    10110,     7631,       919,     5534,
   8844,     8727,      1117,     6728,     8956,    12496,      1648,     9921,
  12924,      976,     -2119,   -12753,    11435,     1755,     -1252,    -7539,
  12138,     2328,      -835,    -5024,    11388,     2368,      -810,    -4872,
  10700,     3064,      -429,    -2580,    12332,     2861,      -530,    -3192,
  11722,     3327,      -307,    -1848,    11270,     3700,      -150,     -904,
  10861,     4413,       110,      663,    12082,     4533,       150,      902,
  11283,     5205,       354,     2132,    11960,     6305,       637,     3837,
  11167,     7534,       900,     5420,    12128,     8329,      1049,     6312,
  10969,    10777,      1429,     8604,    10300,    17376,      2135,    12853,
  13899,     1681,     -1316,    -7921,    12580,     2045,     -1026,    -6179,
  13265,     2439,      -766,    -4610,    14033,     2989,      -465,    -2802,
  13452,     3098,      -413,    -2482,    12396,     3658,      -167,    -1006,
  13510,     3780,      -119,     -713,    12880,     4272,        62,      374,
  13533,     4861,       253,     1523,    12667,     5457,       424,     2552,
  13854,     6106,       590,     3551,    13031,     6483,       678,     4084,
  13557,     7721,       937,     5639,    12957,     9311,      1213,     7304,
  13714,    11551,      1532,     9221,    12591,    15206,      1938,    11667,
  15113,     1540,     -1445,    -8700,    15072,     2333,      -832,    -5007,
  14527,     2511,      -723,    -4352,    14692,     3199,      -365,    -2197,
  15382,     3560,      -207,    -1247,    14133,     3960,       -50,     -300,
  15102,     4236,        50,      298,    14332,     4824,       242,     1454,
  14846,     5451,       422,     2542,    15306,     6083,       584,     3518,
  14329,     6888,       768,     4623,    15060,     7689,       930,     5602,
  14406,     9426,      1231,     7413,    15387,     9741,      1280,     7706,
  14824,    14271,      1844,    11102,    13600,    24939,      2669,    16067,
  16396,     1969,     -1082,    -6517,    16817,     2832,      -545,    -3283,
  15713,     2843,      -539,    -3248,    16104,     3336,      -303,    -1825,
  16384,     3963,       -49,     -294,    16940,     4579,       165,      992,
  15711,     4599,       171,     1030,    16222,     5448,       421,     2537,
  16832,     6382,       655,     3945,    15745,     7141,       821,     4944,
  16326,     7469,       888,     5343,    16611,     8624,      1100,     6622,
  17028,    10418,      1379,     8303,    15905,    11817,      1565,     9423,
  16878,    14690,      1887,    11360,    16515,    20870,      2406,    14483,
  18142,     2083,      -999,    -6013,    19401,     3178,      -375,    -2257,
  17508,     3426,      -264,    -1589,    20054,     4027,       -25,     -151,
  18069,     4249,        54,      326,    18952,     5066,       314,     1890,
  17711,     5402,       409,     2461,    19835,     6192,       610,     3676,
  17950,     7014,       795,     4784,    21318,     7877,       966,     5816,
  17910,     9289,      1210,     7283,    19144,     9290,      1210,     7284,
  20517,    11381,      1510,     9089,    18075,    14485,      1866,    11234,
  19999,    17882,      2177,    13108,    18842,    32764,      3072,    18494
};

static __ALIGN32 CONST Ipp16s TableGainLowRates[VEC_QNT_LOWRATES_SIZE*4] = {
  10813,    28753,      2879,    17333,    20480,     2785,      -570,    -3431,
  18841,     6594,       703,     4235,     6225,     7413,       876,     5276,
  17203,    10444,      1383,     8325,    21626,     1269,     -1731,   -10422,
  21135,     4423,       113,      683,    11304,     1556,     -1430,    -8609,
  19005,    12820,      1686,    10148,    17367,     2498,      -731,    -4398,
  17858,     4833,       244,     1472,     9994,     2498,      -731,    -4398,
  17530,     7864,       964,     5802,    14254,     1884,     -1147,    -6907,
  15892,     3153,      -387,    -2327,     6717,     1802,     -1213,    -7303,
  18186,    20193,      2357,    14189,    18022,     3031,      -445,    -2678,
  16711,     5857,       528,     3181,     8847,     4014,       -30,     -180,
  15892,     8970,      1158,     6972,    18022,     1392,     -1594,    -9599,
  16711,     4096,         0,        0,     8192,      655,     -2708,   -16305,
  15237,    13926,      1808,    10884,    14254,     3112,      -406,    -2444,
  14090,     4669,       193,     1165,     5406,     2703,      -614,    -3697,
  13434,     6553,       694,     4180,    12451,      901,     -2237,   -13468,
  12451,     2662,      -637,    -3833,     3768,      655,     -2708,   -16305,
  14745,    23511,      2582,    15543,    19169,     2457,      -755,    -4546,
  20152,     5079,       318,     1913,     6881,     4096,         0,        0,
  20480,     8560,      1089,     6556,    19660,      737,     -2534,   -15255,
  19005,     4259,        58,      347,     7864,     2088,      -995,    -5993,
  11468,    12288,      1623,     9771,    15892,     1474,     -1510,    -9090,
  15728,     4628,       180,     1086,     9175,     1433,     -1552,    -9341,
  16056,     7004,       793,     4772,    14827,      737,     -2534,   -15255,
  15073,     2252,      -884,    -5321,     5079,     1228,     -1780,   -10714,
  13271,    17326,      2131,    12827,    16547,     2334,      -831,    -5002,
  15073,     5816,       518,     3118,     3932,     3686,      -156,     -938,
  14254,     8601,      1096,     6598,    16875,      778,     -2454,   -14774,
  15073,     3809,      -107,     -646,     6062,      614,     -2804,   -16879,
   9338,     9256,      1204,     7251,    13271,     1761,     -1247,    -7508,
  13271,     3522,      -223,    -1343,     2457,     1966,     -1084,    -6529,
  11468,     5529,       443,     2668,    10485,      737,     -2534,   -15255,
  11632,     3194,      -367,    -2212,     1474,      778,     -2454,   -14774
};
/*************************************************************************
 * Function: ownGainQntInward_GSMAMR()
 *************************************************************************/
Ipp16s ownGainQntInward_GSMAMR(IppSpchBitRate rate, Ipp16s expGainCodeCB, Ipp16s fracGainCodeCB,
                              Ipp16s *fracCoeff, Ipp16s *expCoeff, Ipp16s gainPitchLimit, Ipp16s *pitchGainVar,
                              Ipp16s *codeGainVar, Ipp16s *qntEnergyErr_M122, Ipp16s *qntEnergyErr)
{
    const Ipp16s *p;
    Ipp16s i, j, index = 0;
    Ipp16s predGainCB, e_max, exp_code;
    Ipp16s g_pitch, g2_pitch, g_code, g2_code, g_pit_cod;
    Ipp16s coeff[5], coeff_lo[5];
    Ipp16s exp_max[5];
    Ipp32s TmpVal, dist_min;
    const Ipp16s *table_gain;
    Ipp16s table_len;

    if (rate == IPP_SPCHBR_10200 || rate == IPP_SPCHBR_7400 || rate == IPP_SPCHBR_6700) {
       table_len = VEC_QNT_HIGHRATES_SIZE;
       table_gain = TableGainHighRates;
    } else {
       table_len = VEC_QNT_LOWRATES_SIZE;
       table_gain = TableGainLowRates;
    }

    predGainCB = (Ipp16s)(ownPow2_GSMAMR(14, fracGainCodeCB));
    exp_code = (Ipp16s)(expGainCodeCB - 11);

    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] + 1 + exp_code);

    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;
    p = &table_gain[0];

    for (i = 0; i < table_len; i++) {
        g_pitch = *p++;
        g_code = *p++;
        p+=2;

        if (g_pitch <= gainPitchLimit) {
            g_code = (Ipp16s)((g_code * predGainCB) >> 15);
            g2_pitch = (Ipp16s)((g_pitch * g_pitch) >> 15);
            g2_code = (Ipp16s)((g_code * g_code) >> 15);
            g_pit_cod = (Ipp16s)((g_code * g_pitch) >> 15);

            TmpVal = Mpy_32_16(coeff[0], coeff_lo[0], g2_pitch);
            TmpVal += Mpy_32_16(coeff[1], coeff_lo[1], g_pitch);
            TmpVal += Mpy_32_16(coeff[2], coeff_lo[2], g2_code);
            TmpVal += Mpy_32_16(coeff[3], coeff_lo[3], g_code);
            TmpVal += Mpy_32_16(coeff[4], coeff_lo[4], g_pit_cod);

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

    p = &table_gain[index << 2];
    *pitchGainVar = *p++;
    g_code = *p++;
    *qntEnergyErr_M122 = *p++;
    *qntEnergyErr = *p;

    TmpVal = 2 * g_code * predGainCB;
    if (expGainCodeCB > 10) TmpVal = ShiftL_32s(TmpVal, (Ipp16u)(expGainCodeCB - 10));
    else                    TmpVal >>= (10 - expGainCodeCB);
    *codeGainVar = (Ipp16s)(TmpVal >> 16);

    return index;
}


/********************************************************************************
*  Function: ownGainQuant_GSMAMR:    Quantization of gains
*********************************************************************************/
Ipp32s ownGainQuant_GSMAMR(sGainQuantSt *st, IppSpchBitRate rate, Ipp16s *pLTPRes, Ipp16s *pLTPExc,
                        Ipp16s *code, Ipp16s *pTargetVec, Ipp16s *pTargetVec2, Ipp16s *pAdaptCode,
                        Ipp16s *pFltVector, Ipp16s even_subframe, Ipp16s gainPitchLimit, Ipp16s *gainPitSF0,
                        Ipp16s *gainCodeSF0, Ipp16s *pitchGainVar, Ipp16s *codeGainVar, Ipp16s **ppAnalysisParam)
{
    Ipp32s i;
    Ipp16s expGainCodeCB;
    Ipp16s fracGainCodeCB;
    Ipp16s qntEnergyErr_M122;
    Ipp16s qntEnergyErr;
    Ipp16s fracCoeff[5];
    Ipp16s expCoeff[5];
    Ipp16s expEnergyCoeff, fracEnergyCoeff;
    Ipp16s codGainExp, codGainFrac;

    if (rate == IPP_SPCHBR_4750) {
        if (even_subframe != 0) {

            st->pGainPtr = (*ppAnalysisParam)++;
            ippsCopy_16s(st->a_PastQntEnergy, st->a_PastUnQntEnergy, NUM_PRED_TAPS);
            ippsCopy_16s(st->a_PastQntEnergy_M122, st->a_PastUnQntEnergy_M122, NUM_PRED_TAPS);

            ownPredEnergyMA_GSMAMR(st->a_PastUnQntEnergy,st->a_PastUnQntEnergy_M122, rate, code,
                    &st->vExpPredCBGain, &st->vFracPredCBGain, &expEnergyCoeff, &fracEnergyCoeff);

            ownCalcFiltEnergy_GSMAMR(rate, pTargetVec, pTargetVec2, pAdaptCode, pFltVector, st->a_FracEnCoeff, st->a_ExpEnCoeff,
                                     &codGainFrac, &codGainExp);

            if ((codGainExp + 1) > 0)
                *codeGainVar = Cnvrt_32s16s(codGainFrac << (codGainExp + 1));
            else
                *codeGainVar = Cnvrt_32s16s(codGainFrac >> -(codGainExp + 1));

            ownCalcTargetEnergy_GSMAMR(pTargetVec, &st->vExpTargetEnergy, &st->vFracTargetEnergy);

            ownUpdateUnQntPred_M475(st->a_PastUnQntEnergy,st->a_PastUnQntEnergy_M122,
                                  st->vExpPredCBGain, st->vFracPredCBGain,
                                  codGainExp, codGainFrac);

        } else {

            ownPredEnergyMA_GSMAMR(st->a_PastUnQntEnergy,st->a_PastUnQntEnergy_M122, rate, code,
                    &expGainCodeCB, &fracGainCodeCB, &expEnergyCoeff, &fracEnergyCoeff);

            ownCalcFiltEnergy_GSMAMR(rate, pTargetVec, pTargetVec2, pAdaptCode, pFltVector,
                               fracCoeff, expCoeff, &codGainFrac, &codGainExp);

            ownCalcTargetEnergy_GSMAMR(pTargetVec, &expEnergyCoeff, &fracEnergyCoeff);

            *st->pGainPtr = ownGainQnt_M475(st->a_PastQntEnergy, st->a_PastQntEnergy_M122, st->vExpPredCBGain,
                                            st->vFracPredCBGain, st->a_ExpEnCoeff,  st->a_FracEnCoeff,
                                            st->vExpTargetEnergy, st->vFracTargetEnergy, code, expGainCodeCB,
                                            fracGainCodeCB, expCoeff, fracCoeff, expEnergyCoeff, fracEnergyCoeff,

⌨️ 快捷键说明

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