📄 decg729fp.c
字号:
CodeGain = 0.;
}
} else {
PitchGain = decoderObj->fPitchGain;
CodeGain = decoderObj->fCodeGain;
}
ippsInterpolateC_G729_32f(&Excitation[NSbfr], PitchGain, ACELPCodeVec, CodeGain, &Excitation[NSbfr], SUBFR_LEN);
if (rate == G729D_MODE) {
PhaseDispersion_G729D(&Excitation[NSbfr], PhaseDispExc, decoderObj->fCodeGain, decoderObj->fPitchGain, ACELPCodeVec,decoderObj->phdMem,(char *)TmpAlignVec);
ippsSynthesisFilter_G729_32f(pLPC, aqLen, PhaseDispExc, &pSynth[NSbfr], SUBFR_LEN, &decoderObj->SynFltMemory[BWD_LPC_ORDER-aqLen]);
} else {
ippsSynthesisFilter_G729_32f(pLPC, aqLen, &Excitation[NSbfr], &pSynth[NSbfr], SUBFR_LEN, &decoderObj->SynFltMemory[BWD_LPC_ORDER-aqLen]);
/* Updates state machine for phase dispersion in
6.4 kbps mode, if running at other rate */
PhaseDispersionUpdate_G729D(decoderObj->fPitchGain, decoderObj->fCodeGain,decoderObj->phdMem);
}
ippsCopy_32f(&pSynth[NSbfr+SUBFR_LEN-BWD_LPC_ORDER], decoderObj->SynFltMemory, BWD_LPC_ORDER);
} else {
ippsInterpolateC_G729_32f(&Excitation[NSbfr], decoderObj->fPitchGain, ACELPCodeVec, decoderObj->fCodeGain, &Excitation[NSbfr], SUBFR_LEN);
ippsSynthesisFilter_G729_32f(pLPC, LPC_ORDER, &Excitation[NSbfr], &flDst[NSbfr], SUBFR_LEN, decoderObj->SynFltMemory);
for (i = 0; i < LPC_ORDER; i++) decoderObj->SynFltMemory[i] =flDst[NSbfr+(SUBFR_LEN-LPC_ORDER)+i];
}
pLPC += aqLen+1; /* interpolated LPC parameters for next subframe */
}
}
if(bfi == 0) {
double tmp;
ippsDotProd_32f64f(Excitation, Excitation, FRM_LEN, &tmp);
decoderObj->SID = (Ipp32f)tmp;
}
decoderObj->prevFrameType = FrameType;
ippsCopy_32f(&decoderObj->OldExcitationBuffer[FRM_LEN], &decoderObj->OldExcitationBuffer[0], PITCH_LAG_MAX+INTERPOL_LEN);
if(decoderObj->objPrm.codecType!=G729A_CODEC) {
energy = CalcEnergy_dB_G729(pSynth, FRM_LEN);
if (energy >= 40.) isBackwardModeDominant_G729(&isBWDDominant, LPCMode, &decoderObj->sBWDFrmCounter,&decoderObj->sFWDFrmCounter);
decoderObj->lPrevBFI = bfi;
decoderObj->prevLPCMode = LPCMode;
decoderObj->lPrevVoicing = decoderObj->lVoicing;
if (bfi != 0) decoderObj->fFEInterpolationCoeff = 1.;
else {
if (LPCMode == 0) decoderObj->fFEInterpolationCoeff = 0;
else {
if (isBWDDominant == 1) decoderObj->fFEInterpolationCoeff -= 0.1f;
else decoderObj->fFEInterpolationCoeff -= 0.5f;
if (decoderObj->fFEInterpolationCoeff < 0) decoderObj->fFEInterpolationCoeff= 0;
}
}
}
if(decoderObj->objPrm.codecType!=G729A_CODEC) {
/* Control adaptive parameters for postfiltering */
if( LPCMode == 0) {
pLPC = forwardLPC;
pstLPCOrder = LPC_ORDER;
} else {
pLPC = backwardLPC;
pstLPCOrder = BWD_LPC_ORDER;
}
post_filter_I(decoderObj, pSynth, pLPC, T2[0], ((parm2 == 1) && (isBWDDominant == 1)), Vad, pstLPCOrder, flDst,rate);
} else {
Post_G729A(decoderObj,flDst, forwardLPC, T2, Vad);
}
/* Highpass filter */
ippsIIR_32f_I(flDst,FRM_LEN,decoderObj->iirstate);
/* Round to nearest and convert to short*/
{
for(i=0;i<FRM_LEN;i++) {
fTmp = flDst[i];
if (fTmp >= 0.0)
fTmp += 0.5;
else fTmp -= 0.5;
if (fTmp > 32767.0 ) fTmp = 32767.0;
if (fTmp < -32768.0 ) fTmp = -32768.0;
dst[i] = (short) fTmp;
}
}
//ippsConvert_32f16s_Sfs(flDst,dst,FRM_LEN,ippRndNear,0); /*A few difference between original code*/
CLEAR_SCRATCH_MEMORY(decoderObj);
return APIG729_StsNoErr;
}
static void post_filter_I(G729FPDecoder_Obj* decoderObj, float *pSynth, float *pLPC, int pitchDelay, int dominant,
int Vad, int pstLPCOrder, float *dst,int rate)
{
int i, lSFVoice, len;
if (rate != G729E_MODE) {
len = SHORTTERM_POSTFLT_LEN;
decoderObj->g1PST = GAMMA1_POSTFLT;
decoderObj->g2PST = GAMMA2_POSTFLT;
decoderObj->gHarmPST = GAMMA_HARM_POSTFLT;
} else {
len = SHORTTERM_POSTFLT_LEN_E;
/* If backward mode is dominant => progressively reduce postfiltering */
if (dominant) {
decoderObj->gHarmPST -= 0.0125f;
CLIP_TO_LOWLEVEL(decoderObj->gHarmPST,0);
decoderObj->g1PST -= 0.035f;
CLIP_TO_LOWLEVEL(decoderObj->g1PST,0);
decoderObj->g2PST -= 0.0325f;
CLIP_TO_LOWLEVEL(decoderObj->g2PST,0);
} else {
decoderObj->gHarmPST += 0.0125f;
CLIP_TO_UPLEVEL(decoderObj->gHarmPST,GAMMA_HARM_POSTFLT_E);
decoderObj->g1PST += 0.035f;
CLIP_TO_UPLEVEL(decoderObj->g1PST,GAMMA1_POSTFLT_E);
decoderObj->g2PST += 0.0325f;
CLIP_TO_UPLEVEL(decoderObj->g2PST,GAMMA2_POSTFLT_E);
}
}
decoderObj->lVoicing = 0;
for(i=0; i<FRM_LEN; i+=SUBFR_LEN) {
Post_G729E(decoderObj, pitchDelay, &pSynth[i], pLPC, &dst[i], &lSFVoice, len, pstLPCOrder, Vad);
if (lSFVoice != 0) decoderObj->lVoicing = lSFVoice;
pLPC += pstLPCOrder+1;
}
return;
}
static void Post_G729A(G729FPDecoder_Obj *decoderObj, float *pSrcDstSynthSpeech, float *pSrcLPC,
int *pSrcDecodedPitch, int Vad)
{
LOCAL_ALIGN_ARRAY(32, float, SynthBuffer, (FRM_LEN+LPC_ORDER),decoderObj); /* Synthesis */
LOCAL_ALIGN_ARRAY(32, float, pResidual, SUBFR_LEN,decoderObj); /* ResidualMemory after pitch postfiltering */
LOCAL_ALIGN_ARRAY(32, float, pSynthPST, FRM_LEN,decoderObj); /* post filtered synthesis speech */
LOCAL_ARRAY(float, LPCGama2, LPC_ORDERP1,decoderObj); /* bandwidth expanded LP parameters */
LOCAL_ARRAY(float, LPCGama1, LPC_ORDERP1,decoderObj);
LOCAL_ARRAY(float, ImpRespPST, PST_IMPRESP_LEN,decoderObj);
float *pLPC;
int PitchDelay, pitchMaxBound, pitchMinBound; /* closed-loop pitch search range */
int i, NSbfr; /* index for beginning of subframe */
float fTmp, fTmp1, fTmp2;
float *pSynth;
Ipp64f sum, sum1;
Ipp64f dGain,dg0;
float fMaxCorr;
float gainM1, gain;
float fEnergy, fEnergy0;
pLPC = pSrcLPC;
pSynth = &SynthBuffer[LPC_ORDER];
ippsCopy_32f(decoderObj->PstFltMemoryA,SynthBuffer,LPC_ORDER);
ippsCopy_32f(pSrcDstSynthSpeech,pSynth,FRM_LEN);
for (NSbfr = 0; NSbfr < FRM_LEN; NSbfr += SUBFR_LEN) {
/* Find pitch range t0_min - t0_max */
pitchMinBound = *pSrcDecodedPitch++ - 3;
pitchMaxBound = pitchMinBound+6;
if (pitchMaxBound > PITCH_LAG_MAX) {
pitchMaxBound = PITCH_LAG_MAX;
pitchMinBound = pitchMaxBound-6;
}
/* Find weighted filter coefficients LPCGama2 and LPCGama1 */
WeightLPCCoeff_G729(pLPC, GAMMA2_POSTFLT, LPC_ORDER, LPCGama2);
WeightLPCCoeff_G729(pLPC, GAMMA1_POSTFLT, LPC_ORDER, LPCGama1 );
/* filtering of synthesis speech by A(z/GAMMA2_POSTFLT) to find ResidualMemory */
ippsConvBiased_32f(LPCGama2,LPC_ORDER+1,&pSynth[NSbfr],SUBFR_LEN+LPC_ORDER,decoderObj->ResidualMemory,SUBFR_LEN,LPC_ORDER);
/* pitch postfiltering */
if (Vad > 1) {
ippsCrossCorrLagMax_32f64f(decoderObj->ResidualMemory, &decoderObj->ResidualMemory[-pitchMaxBound], SUBFR_LEN, pitchMaxBound-pitchMinBound, &sum, &PitchDelay);
PitchDelay = (pitchMaxBound-pitchMinBound-PitchDelay) + pitchMinBound;
fMaxCorr = (Ipp32f)sum;
/* Compute the energy of the signal delayed by PitchDelay */
ippsDotProd_32f64f(&decoderObj->ResidualMemory[-PitchDelay], &decoderObj->ResidualMemory[-PitchDelay], SUBFR_LEN, &sum);
fEnergy = (Ipp32f)(sum+0.5);
/* Compute the signal energy in the present subframe */
ippsDotProd_32f64f(decoderObj->ResidualMemory, decoderObj->ResidualMemory, SUBFR_LEN, &sum);
fEnergy0 = (Ipp32f)(sum+0.5);
if (fMaxCorr < 0.0) fMaxCorr = 0.0;
/* prediction gain (dB)= -10 log(1-fMaxCorr*fMaxCorr/(fEnergy*fEnergy0)) */
fTmp = fMaxCorr*fMaxCorr;
if (fTmp < fEnergy*fEnergy0*0.5) { /* if prediction gain < 3 dB */
ippsCopy_32f(decoderObj->ResidualMemory, pResidual, SUBFR_LEN);
} else {
if (fMaxCorr > fEnergy) { /* if pitch gain > 1 */
gainM1 = INV_GAMMA_POSTFLT_G729A;
gain = GAMMA2_POSTFLT_G729A;
} else {
fMaxCorr *= GAMMA_POSTFLT_G729A;
gain = 1.0f/(fMaxCorr+fEnergy) * fMaxCorr;
gainM1 = 1.0f - gain;
}
ippsInterpolateC_G729_32f(decoderObj->ResidualMemory, gainM1, &decoderObj->ResidualMemory[-PitchDelay], gain, pResidual, SUBFR_LEN);
}
} else
ippsCopy_32f(decoderObj->ResidualMemory,pResidual,SUBFR_LEN);
/* impulse response of A(z/GAMMA2_POSTFLT)/A(z/GAMMA1_POSTFLT) */
ippsCopy_32f(LPCGama2, ImpRespPST, LPC_ORDERP1);
ippsZero_32f(&ImpRespPST[LPC_ORDERP1],PST_IMPRESP_LEN-LPC_ORDERP1);
ippsSynthesisFilter_G729_32f(LPCGama1, LPC_ORDER, ImpRespPST, ImpRespPST, PST_IMPRESP_LEN, &ImpRespPST[LPC_ORDER+1]);
/* 1st correlation of impulse response */
ippsDotProd_32f64f(ImpRespPST, ImpRespPST, PST_IMPRESP_LEN, &sum);
ippsDotProd_32f64f(ImpRespPST, &ImpRespPST[1], PST_IMPRESP_LEN-1, &sum1);
if(sum1 <= 0.0) {
fTmp2 = 0.0;
} else {
fTmp1 = (Ipp32f)sum;
fTmp2 = (Ipp32f)sum1;
fTmp2 = fTmp2*TILT_FLT_FACTOR/fTmp1;
}
ippsPreemphasize_32f_I(fTmp2, pResidual, SUBFR_LEN,&decoderObj->fPreemphMemoryA);
/* filtering through 1/A(z/GAMMA1_POSTFLT) */
ippsSynthesisFilter_G729_32f(LPCGama1, LPC_ORDER, pResidual, &pSynthPST[NSbfr], SUBFR_LEN, decoderObj->PstSynMemoryA);
for (i = 0; i < LPC_ORDER; i++) decoderObj->PstSynMemoryA[i] =pSynthPST[NSbfr+(SUBFR_LEN-LPC_ORDER)+i];
/* scale output to input */
ippsDotProd_32f64f(&pSynthPST[NSbfr], &pSynthPST[NSbfr], SUBFR_LEN, &dGain);
if(dGain == 0.) {
decoderObj->fPastGain = 0.f;
} else {
ippsDotProd_32f64f(&pSynth[NSbfr], &pSynth[NSbfr], SUBFR_LEN, &dg0);
if(dg0 > 0) {
dg0 = sqrt(dg0/ dGain);
dg0 *= AGC_FACTOR_1M_G729A;
}
/* compute gain(n) = AGC_FACTOR gain(n-1) + (1-AGC_FACTOR)gain_in/dGain */
ippsGainControl_G729_32f_I((float)dg0, AGC_FACTOR_G729A, &pSynthPST[NSbfr], &decoderObj->fPastGain);
}
/* update residual memory */
ippsCopy_32f(&decoderObj->ResidualMemory[SUBFR_LEN-PITCH_LAG_MAX], &decoderObj->ResidualMemory[-PITCH_LAG_MAX], PITCH_LAG_MAX);
pLPC += LPC_ORDERP1;
}
/* update pSynth[] buffer */
ippsCopy_32f(&pSynth[FRM_LEN-LPC_ORDER], decoderObj->PstFltMemoryA, LPC_ORDER);
/* overwrite synthesis speech by postfiltered synthesis speech */
ippsCopy_32f(pSynthPST, pSrcDstSynthSpeech, FRM_LEN);
LOCAL_ARRAY_FREE(float, ImpRespPST, PST_IMPRESP_LEN,decoderObj);
LOCAL_ARRAY_FREE(float, LPCGama1, LPC_ORDERP1,decoderObj);
LOCAL_ARRAY_FREE(float, LPCGama2, LPC_ORDERP1,decoderObj);
LOCAL_ALIGN_ARRAY_FREE(32, float, pSynthPST, FRM_LEN,decoderObj); /* post filtered synthesis speech */
LOCAL_ALIGN_ARRAY_FREE(32, float, pResidual, SUBFR_LEN,decoderObj); /* ResidualMemory after pitch postfiltering */
LOCAL_ALIGN_ARRAY_FREE(32, float, SynthBuffer, (FRM_LEN+LPC_ORDER),decoderObj); /* Synthesis */
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -