📄 dtxgsmamr.c
字号:
short logEnergyE, logEnergyM;
short level;
short predErr, predInit_ma;
short logPredE, logPredM, logPred;
int negative;
short lsfMean;
int lsfMean_long;
short lsfIndex, lsfFactor;
short ptr;
short tmpLength;
IPP_ALIGNED_ARRAY(16, short, pLspBuf, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, short, pCoef_A, LP_ORDER_SIZE + 1);
IPP_ALIGNED_ARRAY(16, short, pCoef_Refl, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, short, pExt, SUBFR_SIZE_GSMAMR);
IPP_ALIGNED_ARRAY(16, short, pLsfBuf, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, short, pLsfVarBuf, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, short, pLspVarBuf, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, short, pCoeffABuf, LP_ORDER_SIZE + 1);
IPP_ALIGNED_ARRAY(16, short, pLsf, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, int, pLsf_long, LP_ORDER_SIZE);
if ((dtxState->vDTXHangAdd != 0) && (dtxState->vFlagSidFrame != 0)) {
dtxState->vLogEnergyCorrect = dtx_log_en_adjust[rate];
ptr = dtxState->vLogEnergyHistory + 1;
if (ptr == DTX_HIST_SIZE)
ptr = 0;
ippsCopy_16s(&dtxState->a_LSFHistory[dtxState->vLogEnergyHistory*LP_ORDER_SIZE],
&dtxState->a_LSFHistory[ptr*LP_ORDER_SIZE], LP_ORDER_SIZE);
dtxState->a_LogEnergyHistory[ptr] = dtxState->a_LogEnergyHistory[dtxState->vLogEnergyHistory];
dtxState->vLogEnergy = 0;
ippsSet_32s(0, pLsf_long, LP_ORDER_SIZE);
/* average energy and lsp */
for (i = 0; i < DTX_HIST_SIZE; i++) {
dtxState->vLogEnergy += (dtxState->a_LogEnergyHistory[i] >> 3);
for (j = 0; j < LP_ORDER_SIZE; j++)
pLsf_long[j] += dtxState->a_LSFHistory[i * LP_ORDER_SIZE + j];
}
for (j = 0; j < LP_ORDER_SIZE; j++)
pLsf[j] = (short)(pLsf_long[j] >> 3); /* divide by 8 */
ippsLSFToLSP_GSMAMR_16s(pLsf, dtxState->a_LSP);
dtxState->vLogEnergy -= dtxState->vLogEnergyCorrect;
ippsCopy_16s(dtxState->a_LSFHistory, dtxState->a_LSFHistoryMean, 80);
for (i = 0; i < LP_ORDER_SIZE; i++) {
lsfMean_long = 0;
/* compute mean pLsf */
for (j = 0; j < 8; j++)
lsfMean_long += dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE];
lsfMean = (short)(lsfMean_long >> 3);
for (j = 0; j < 8; j++) {
dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] -= lsfMean;
dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] = (short)((dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] *
lsf_hist_mean_scale[i]) >> 15);
if(dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] < 0) negative = 1;
else negative = 0;
dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] = Abs_16s(dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE]);
if (dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] > 655)
dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] = 655 + ((dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] - 655) >> 2);
if (dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] > 1310)
dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] = 1310;
if (negative != 0)
dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE] = -dtxState->a_LSFHistoryMean[i+j*LP_ORDER_SIZE];
}
}
}
if (dtxState->vFlagSidFrame != 0 ) {
ippsCopy_16s(dtxState->a_LSP, dtxState->a_LSP_Old, LP_ORDER_SIZE);
dtxState->vLogEnergyOld = dtxState->vLogEnergy;
if (dtxState->vFlagValidData != 0 )
{
/* Compute interpolation factor */
tmpLength = dtxState->vLastSidFrame;
dtxState->vLastSidFrame = 0;
if (tmpLength > 32) tmpLength = 32;
if (tmpLength >= 2)
dtxState->vSidPeriodInv = (1 << 25)/Cnvrt_32s16s(tmpLength << 10);
else
dtxState->vSidPeriodInv = 1 << 14;
ippsCopy_16s(&TablePastLSFQnt[pParmVec[0] * LP_ORDER_SIZE], a_PastQntPredErr, LP_ORDER_SIZE);
ownDecLSPQuantDTX_GSMAMR(a_PastQntPredErr, a_PastLSFQnt, 0, &pParmVec[1], dtxState->a_LSP);
ippsZero_16s(a_PastQntPredErr, LP_ORDER_SIZE); /* reset for next speech frame */
logEnergyIdx = pParmVec[4];
dtxState->vLogEnergy = Cnvrt_32s16s(logEnergyIdx << (11 - 2));
dtxState->vLogEnergy -= (2560 * 2);
if (logEnergyIdx == 0) dtxState->vLogEnergy = IPP_MIN_16S;
if ((dtxState->vFlagDataUpdate == 0) || (dtxState->eDTXPrevState == SPEECH)) {
ippsCopy_16s(dtxState->a_LSP, dtxState->a_LSP_Old, LP_ORDER_SIZE);
dtxState->vLogEnergyOld = dtxState->vLogEnergy;
}
}
predInit_ma = (dtxState->vLogEnergy >> 1) - 9000;
if (predInit_ma > 0) predInit_ma = 0;
if (predInit_ma < -14436) predInit_ma = -14436;
a_PastQntEnergy[0] = predInit_ma;
a_PastQntEnergy[1] = predInit_ma;
a_PastQntEnergy[2] = predInit_ma;
a_PastQntEnergy[3] = predInit_ma;
predInit_ma = (short)((5443 * predInit_ma) >> 15);
a_PastQntEnergy_M122[0] = predInit_ma;
a_PastQntEnergy_M122[1] = predInit_ma;
a_PastQntEnergy_M122[2] = predInit_ma;
a_PastQntEnergy_M122[3] = predInit_ma;
}
/* CNG */
dtxState->vLogEnergyCorrect = ((short)((dtxState->vLogEnergyCorrect * 29491) >> 15) +
((short)((Cnvrt_32s16s(dtx_log_en_adjust[rate] << 5) * 3277)>>15) >> 5));
/* Interpolate SID info */
int_fac = Cnvrt_32s16s((1 + dtxState->vLastSidFrame) << 10);
int_fac = (short)((int_fac * dtxState->vSidPeriodInv) >> 15);
if (int_fac > 1024) int_fac = 1024;
int_fac <<= 4;
logEnergy_long = 2 * int_fac * dtxState->vLogEnergy;
for(i = 0; i < LP_ORDER_SIZE; i++)
pLspBuf[i] = (short)((int_fac * dtxState->a_LSP[i]) >> 15);
int_fac = 16384 - int_fac;
logEnergy_long += (int_fac * dtxState->vLogEnergyOld) << 1;
for(i = 0; i < LP_ORDER_SIZE; i++) {
pLspBuf[i] += (short)((int_fac * dtxState->a_LSP_Old[i]) >> 15);
pLspBuf[i] = Cnvrt_32s16s(pLspBuf[i] << 1); /* Q14 -> Q15 */
}
lsfFactor = dtxState->vLogMean - 2457;
lsfFactor = 4096 - (short)((lsfFactor * 9830) >> 15);
/* limit to values between 0..1 in Q12 */
if (lsfFactor > 4096) lsfFactor = 4096;
if (lsfFactor < 0) lsfFactor = 0;
lsfFactor = Cnvrt_32s16s(lsfFactor << 3); /* -> Q15 */
lsfIndex = ownGenNoise_GSMAMR(&dtxState->vPerfSeedDTX_long, 3);
ippsLSPToLSF_Norm_G729_16s(pLspBuf,pLsfBuf);
ippsCopy_16s(pLsfBuf, pLsfVarBuf, LP_ORDER_SIZE);
for(i = 0; i < LP_ORDER_SIZE; i++)
pLsfVarBuf[i] += (short)((lsfFactor * dtxState->a_LSFHistoryMean[i+lsfIndex*LP_ORDER_SIZE]) >> 15);
ownReorderLSFVec_GSMAMR(pLsfBuf, LSF_GAP, LP_ORDER_SIZE);
ownReorderLSFVec_GSMAMR(pLsfVarBuf, LSF_GAP, LP_ORDER_SIZE);
/* copy pLsf to speech decoders pLsf state */
ippsCopy_16s(pLsfBuf, a_PastLSFQnt, LP_ORDER_SIZE);
ippsLSFToLSP_GSMAMR_16s(pLsfBuf, pLspBuf);
ippsLSFToLSP_GSMAMR_16s(pLsfVarBuf, pLspVarBuf);
ippsLSPToLPC_GSMAMR_16s(pLspBuf, pCoef_A);
ippsLSPToLPC_GSMAMR_16s(pLspVarBuf, pCoeffABuf);
ippsCopy_16s(pCoef_A, &pA_LP[0], LP_ORDER_SIZE + 1);
ippsCopy_16s(pCoef_A, &pA_LP[LP_ORDER_SIZE + 1], LP_ORDER_SIZE + 1);
ippsCopy_16s(pCoef_A, &pA_LP[2 * (LP_ORDER_SIZE + 1)], LP_ORDER_SIZE + 1);
ippsCopy_16s(pCoef_A, &pA_LP[3 * (LP_ORDER_SIZE + 1)], LP_ORDER_SIZE + 1);
ownConvertDirectCoeffToReflCoeff_GSMAMR(&pCoef_A[1], pCoef_Refl);
predErr = IPP_MAX_16S;
for (i = 0; i < LP_ORDER_SIZE; i++)
predErr = (short)((predErr * (IPP_MAX_16S - (short)((pCoef_Refl[i] * pCoef_Refl[i]) >> 15))) >> 15);
ownLog2_GSMAMR(predErr, &logPredE, &logPredM);
logPred = Cnvrt_32s16s((logPredE -15) << 12); /* Q12 */
logPred = (short)((-(logPred + (logPredM >> (15-12)))) >> 1);
dtxState->vLogMean = ((short)((29491 * dtxState->vLogMean) >> 15) + (short)((3277 * logPred) >> 15));
logEnergy_long >>= 10;
logEnergy_long += 4 * 65536L;
logEnergy_long -= ShiftL_32s(logPred, 4);
logEnergy_long += ShiftL_32s(dtxState->vLogEnergyCorrect, 5);
logEnergyE = (short)(logEnergy_long >> 16);
logEnergyM = (short)((logEnergy_long - (logEnergyE << 16)) >> 1);
level = (short)(ownPow2_GSMAMR(logEnergyE, logEnergyM)); /* Q4 */
for (i = 0; i < 4; i++) {
ownBuildCNCode_GSMAMR(&dtxState->vPerfSeedDTX_long, pExt);
for (j = 0; j < SUBFR_SIZE_GSMAMR; j++)
pExt[j] = (short)((level * pExt[j]) >> 15);
ippsSynthesisFilter_NR_16s_Sfs(pCoeffABuf, pExt, &pSynthSpeechVec[i * SUBFR_SIZE_GSMAMR], SUBFR_SIZE_GSMAMR, 12, a_MemorySyn);
ippsCopy_16s(&pSynthSpeechVec[i * SUBFR_SIZE_GSMAMR + SUBFR_SIZE_GSMAMR - LP_ORDER_SIZE], a_MemorySyn, LP_ORDER_SIZE);
}
/* reset codebook averaging variables */
*vHgAverageVar = 20;
*vHgAverageCount = 0;
if (newState == DTX_MUTE) {
tmpLength = dtxState->vLastSidFrame;
if (tmpLength > 32) tmpLength = 32;
else if(tmpLength <= 0) tmpLength = 8; /* avoid division by zero */
dtxState->vSidPeriodInv = (1 << 20)/Cnvrt_32s16s(tmpLength << 10); /* div: den # 0*/
dtxState->vLastSidFrame = 0;
ippsCopy_16s(dtxState->a_LSP, dtxState->a_LSP_Old, LP_ORDER_SIZE);
dtxState->vLogEnergyOld = dtxState->vLogEnergy;
dtxState->vLogEnergy -= 256;
}
/* reset interpolation length timer if data has been updated. */
if ((dtxState->vFlagSidFrame != 0) && ((dtxState->vFlagValidData != 0) ||
((dtxState->vFlagValidData == 0) && (dtxState->vDTXHangAdd) != 0)))
{
dtxState->vLastSidFrame = 0;
dtxState->vFlagDataUpdate = 1;
}
return 0;
}
/***************************************************************************
* Function : ownRX_DTX_Handler_GSMAMR
***************************************************************************/
enum enDTXStateType ownRX_DTX_Handler_GSMAMR(GSMAMRDecoder_Obj* decoderObj, RXFrameType frame_type)
{
sDTXDecoderSt *dtxState = &decoderObj->stDecState.dtxDecoderState;
enum enDTXStateType newDTXState = ownDecSidSync(&decoderObj->stDecState.dtxDecoderState, frame_type);
if (newDTXState != SPEECH) {
dtxState->vSidUpdateCt--;
if (dtxState->eDTXPrevState == SPEECH) dtxState->vSidUpdateCt = 3;
dtxState->vLastSidFrame++;
} else dtxState->vLastSidFrame = 0;
if (dtxState->vDecExpireCt != 32767) dtxState->vDecExpireCt++;
dtxState->vDTXHangAdd = 0;
if (newDTXState == SPEECH)
dtxState->vDTXHangoverCt = DTX_HANG_PERIOD;
else {
if (dtxState->vDecExpireCt > DTX_ELAPSED_FRAMES_THRESH) {
dtxState->vDTXHangAdd = 1;
dtxState->vDecExpireCt = 0;
dtxState->vDTXHangoverCt = 0;
} else if (dtxState->vDTXHangoverCt == 0) {
dtxState->vDecExpireCt = 0;
} else {
dtxState->vDTXHangoverCt--;
}
}
if (newDTXState != SPEECH) {
dtxState->vFlagSidFrame = 0;
dtxState->vFlagValidData = 0;
if (newDTXState == DTX) dtxState->vFlagSidFrame = 1;
if (dtxState->vSidUpdateCt == 0 && newDTXState != DTX_NODATA) {
dtxState->vSidUpdateCt = 8;
dtxState->vFlagSidFrame = 1;
dtxState->vFlagValidData = 1;
}
}
return newDTXState;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -