📄 gain_util.c
字号:
11963, 1562, 7279, 1128, 16859, 1532, 15762, 5381,
14708, 2065, 20105, 2155, 17158, 8245, 17911, 6318,
5467, 1504, 4100, 2574, 17421, 6810, 5673, 2888,
16636, 3382, 8975, 1831, 20159, 4737, 19550, 7294,
6658, 2781, 11472, 3321, 19397, 5054, 18878, 4722,
16439, 2373, 20430, 4386, 11353, 26526, 11593, 3068,
2866, 1566, 5108, 1070, 9614, 4915, 4939, 3536,
7541, 878, 20717, 851, 6938, 4395, 16799, 7733,
10137, 1019, 9845, 964, 15494, 3955, 15459, 3430,
18863, 982, 20120, 963, 16876, 12887, 14334, 4200,
6599, 1220, 9222, 814, 16942, 5134, 5661, 4898,
5488, 1798, 20258, 3962, 17005, 6178, 17929, 5929,
9365, 3420, 7474, 1971, 19537, 5177, 19003, 3006,
16454, 3788, 16070, 2367, 8664, 2743, 9445, 26358,
10856, 1287, 3555, 1009, 5606, 3622, 19453, 5512,
12453, 797, 20634, 911, 15427, 3066, 17037, 10275,
18883, 2633, 3913, 1268, 19519, 3371, 18052, 5230,
19291, 1678, 19508, 3172, 18072, 10754, 16625, 6845,
3134, 2298, 10869, 2437, 15580, 6913, 12597, 3381,
11116, 3297, 16762, 2424, 18853, 6715, 17171, 9887,
12743, 2605, 8937, 3140, 19033, 7764, 18347, 3880,
20475, 3682, 19602, 3380, 13044, 19373, 10526, 23124
};
/*********************************************************************************
* Quantization of pitch and codebook gains for MR475.
*********************************************************************************/
static void ownQntStoreResults_M475(Ipp16s *a_PastQntEnergy, Ipp16s *a_PastQntEnergy_M122, const Ipp16s *p,
Ipp16s predGainCB, Ipp16s expGainCodeCB, Ipp16s *pitchGainVar, Ipp16s *codeGainVar)
{
Ipp32s i;
Ipp16s g_code, exp, frac, tmp;
Ipp32s TmpCode;
Ipp16s qntEnergyErr_M122;
Ipp16s qntEnergyErr;
*pitchGainVar = *p++;
g_code = *p++;
TmpCode = 2 * g_code * predGainCB;
if(expGainCodeCB > 10) TmpCode <<= (expGainCodeCB - 10);
else TmpCode >>= (10 - expGainCodeCB);
*codeGainVar = (Ipp16s)(TmpCode >> 16);
ownLog2_GSMAMR (g_code, &exp, &frac);
exp -= 12;
tmp = (Ipp16s)(frac >> 5);
qntEnergyErr_M122 = (Ipp16s)(tmp + (exp << 10));
TmpCode = Mpy_32_16(exp, frac, 24660);
qntEnergyErr = Cnvrt_NR_32s16s(TmpCode << 13);
for (i = 3; i > 0; i--) {
a_PastQntEnergy[i] = a_PastQntEnergy[i - 1];
a_PastQntEnergy_M122[i] = a_PastQntEnergy_M122[i - 1];
}
a_PastQntEnergy_M122[0] = qntEnergyErr_M122;
a_PastQntEnergy[0] = qntEnergyErr;
}
/*************************************************************************
* Function: ownUpdateUnQntPred_M475()
*************************************************************************/
void ownUpdateUnQntPred_M475(Ipp16s *a_PastQntEnergy, Ipp16s *a_PastQntEnergy_M122, Ipp16s expGainCodeCB,
Ipp16s fracGainCodeCB, Ipp16s codGainExp, Ipp16s codGainFrac)
{
Ipp32s i;
Ipp16s tmp, exp, frac;
Ipp16s qntEnergyErr, qntEnergyErr_M122;
Ipp32s TmpQnt, tmpEnergyErr_M122;
if (codGainFrac <= 0) {
qntEnergyErr = MIN_QUA_ENER;
qntEnergyErr_M122 = MIN_QUA_ENER_MR122;
} else {
fracGainCodeCB = (Ipp16s)(ownPow2_GSMAMR (14, fracGainCodeCB));
if(codGainFrac >= fracGainCodeCB) {
codGainFrac >>= 1;
codGainExp++;
}
frac = (Ipp16s)((codGainFrac << 15)/fracGainCodeCB);
tmp = (Ipp16s)(codGainExp - expGainCodeCB - 1);
ownLog2_GSMAMR (frac, &exp, &frac);
exp = (Ipp16s)(exp + tmp);
tmpEnergyErr_M122 = (Ipp32s)((frac >> 5) + (exp << 10));
if (tmpEnergyErr_M122 < MIN_QUA_ENER_MR122) {
qntEnergyErr = MIN_QUA_ENER;
qntEnergyErr_M122 = MIN_QUA_ENER_MR122;
} else if (tmpEnergyErr_M122 > MAX_QUA_ENER_MR122) {
qntEnergyErr = MAX_QUA_ENER;
qntEnergyErr_M122 = MAX_QUA_ENER_MR122;
} else {
qntEnergyErr_M122 = (Ipp16s)tmpEnergyErr_M122;
TmpQnt = Mpy_32_16(exp, frac, 24660);
qntEnergyErr = Cnvrt_NR_32s16s(ShiftL_32s(TmpQnt, 13));
}
}
for (i = 3; i > 0; i--) {
a_PastQntEnergy[i] = a_PastQntEnergy[i - 1];
a_PastQntEnergy_M122[i] = a_PastQntEnergy_M122[i - 1];
}
a_PastQntEnergy_M122[0] = qntEnergyErr_M122;
a_PastQntEnergy[0] = qntEnergyErr;
}
/*************************************************************************
* Function: ownGainQnt_M475()
*************************************************************************/
Ipp16s ownGainQnt_M475(Ipp16s *a_PastQntEnergy, Ipp16s *a_PastQntEnergy_M122, Ipp16s vExpPredCBGain,
Ipp16s vFracPredCBGain, Ipp16s *a_ExpEnCoeff, Ipp16s *a_FracEnCoeff,
Ipp16s vExpTargetEnergy, Ipp16s vFracTargetEnergy, Ipp16s *codeNoSharpSF1,
Ipp16s expGainCodeSF1, Ipp16s fracGainCodeSF1, Ipp16s *expCoeffSF1, Ipp16s *fracCoeffSF1,
Ipp16s expTargetEnergySF1, Ipp16s fracTargetEnergySF1, Ipp16s gainPitchLimit,
Ipp16s *gainPitSF0, Ipp16s *gainCodeSF0, Ipp16s *gainPitSF1, Ipp16s *gainCodeSF1)
{
const Ipp16s *p;
Ipp16s i, index = 0;
Ipp16s tmp;
Ipp16s exp;
Ipp16s sf0_gcode0, sf1_gcode0;
Ipp16s g_pitch, g2_pitch, g_code, g2_code, g_pit_cod;
Ipp16s coeff[10], coeff_lo[10], exp_max[10]; /* 0..4: sf0; 5..9: sf1 */
Ipp32s TmpVal, dist_min;
sf0_gcode0 = (Ipp16s)(ownPow2_GSMAMR(14, vFracPredCBGain));
sf1_gcode0 = (Ipp16s)(ownPow2_GSMAMR(14, fracGainCodeSF1));
exp = (Ipp16s)(vExpPredCBGain - 11);
exp_max[0] = (Ipp16s)(a_ExpEnCoeff[0] - 13);
exp_max[1] = (Ipp16s)(a_ExpEnCoeff[1] - 14);
exp_max[2] = (Ipp16s)(a_ExpEnCoeff[2] + 15 + (exp << 1));
exp_max[3] = (Ipp16s)(a_ExpEnCoeff[3] + exp);
exp_max[4] = (Ipp16s)(a_ExpEnCoeff[4] + 1 + exp);
exp = (Ipp16s)(expGainCodeSF1 - 11);
exp_max[5] = (Ipp16s)(expCoeffSF1[0] - 13);
exp_max[6] = (Ipp16s)(expCoeffSF1[1] - 14);
exp_max[7] = (Ipp16s)(expCoeffSF1[2] +15 + (exp << 1));
exp_max[8] = (Ipp16s)(expCoeffSF1[3] + exp);
exp_max[9] = (Ipp16s)(expCoeffSF1[4] + 1 + exp);
exp = (Ipp16s)(vExpTargetEnergy - expTargetEnergySF1);
if (exp > 0) fracTargetEnergySF1 >>= exp;
else vFracTargetEnergy >>= -exp;
exp = 0;
tmp = (Ipp16s)(fracTargetEnergySF1 >> 1);
if (fracTargetEnergySF1 & 1) tmp++;
if (tmp > vFracTargetEnergy) exp = 1;
else {
tmp = (Ipp16s)((vFracTargetEnergy + 3) >> 2);
if(tmp > fracTargetEnergySF1) exp = -1;
}
for (i = 0; i < 5; i++)
exp_max[i] = (Ipp16s)(exp_max[i] + exp);
exp = exp_max[0];
for (i = 1; i < 10; i++) {
if(exp_max[i] > exp) exp = exp_max[i];
}
exp += 1;
p = &a_FracEnCoeff[0];
for (i = 0; i < 5; i++) {
tmp = (Ipp16s)(exp - exp_max[i]);
TmpVal = *p++ << 16;
if (tmp >= (Ipp16s)31) TmpVal = (TmpVal < 0) ? -1 : 0;
else TmpVal >>= tmp;
Unpack_32s(TmpVal, &coeff[i], &coeff_lo[i]);
}
p = &fracCoeffSF1[0];
for (; i < 10; i++) {
tmp = (Ipp16s)(exp - exp_max[i]);
TmpVal = *p++ << 16;
if (tmp >= (Ipp16s)31) TmpVal = (TmpVal < 0) ? -1 : 0;
else TmpVal >>= tmp;
Unpack_32s(TmpVal, &coeff[i], &coeff_lo[i]);
}
/* start with "infinite" MSE */
dist_min = IPP_MAX_32S;
p = &table_gain_MR475[0];
for (i = 0; i < VEC_QNT_M475_SIZE; i++) {
g_pitch = *p++;
g_code = *p++;
g_code = (Ipp16s)((g_code * sf0_gcode0) >> 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 = AddProduct16s_32s(TmpVal, coeff[1], coeff_lo[1], g_pitch);
TmpVal = AddProduct16s_32s(TmpVal, coeff[2], coeff_lo[2], g2_code);
TmpVal = AddProduct16s_32s(TmpVal, coeff[3], coeff_lo[3], g_code);
TmpVal = AddProduct16s_32s(TmpVal, coeff[4], coeff_lo[4], g_pit_cod);
tmp = (Ipp16s)(g_pitch - gainPitchLimit);
g_pitch = *p++;
g_code = *p++;
if(tmp <= 0 && g_pitch <= gainPitchLimit) {
g_code = (Ipp16s)((g_code * sf1_gcode0) >> 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 = AddProduct16s_32s(TmpVal, coeff[5], coeff_lo[5], g2_pitch);
TmpVal = AddProduct16s_32s(TmpVal, coeff[6], coeff_lo[6], g_pitch);
TmpVal = AddProduct16s_32s(TmpVal, coeff[7], coeff_lo[7], g2_code);
TmpVal = AddProduct16s_32s(TmpVal, coeff[8], coeff_lo[8], g_code);
TmpVal = AddProduct16s_32s(TmpVal, coeff[9], coeff_lo[9], g_pit_cod);
if(TmpVal < dist_min) {
dist_min = TmpVal;
index = i;
}
}
}
tmp = (Ipp16s)(index << 2);
ownQntStoreResults_M475(a_PastQntEnergy, a_PastQntEnergy_M122, &table_gain_MR475[tmp],
sf0_gcode0, vExpPredCBGain, gainPitSF0, gainCodeSF0);
ownPredEnergyMA_GSMAMR(a_PastQntEnergy,a_PastQntEnergy_M122, IPP_SPCHBR_4750, codeNoSharpSF1,
&expGainCodeSF1, &fracGainCodeSF1, &vExpPredCBGain, &sf0_gcode0);
sf1_gcode0 = (Ipp16s)(ownPow2_GSMAMR(14, fracGainCodeSF1));
tmp += 2;
ownQntStoreResults_M475(a_PastQntEnergy, a_PastQntEnergy_M122, &table_gain_MR475[tmp],
sf1_gcode0, expGainCodeSF1, gainPitSF1, gainCodeSF1);
return index;
}
/*************************************************************************
* Function: ownPreQnt3CodebookGain_M795
*************************************************************************/
static void ownPreQnt3CodebookGain_M795(Ipp16s expGainCodeCB, Ipp16s predGainCB, Ipp16s *pitchGainCand,
Ipp16s *pitchGainCandIdx, Ipp16s *fracCoeff, Ipp16s *expCoeff,
Ipp16s *pitchGainVar, Ipp16s *pitchGainIdx, Ipp16s *codeGainVar,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -