📄 encg729fp.c
字号:
if( LPCMode == 0) {
ippsCopy_32f(CurrQntLSP, encoderObj->OldQuantLSP, LPC_ORDER);
ippsMove_32f(encoderObj->PrevFreq[0], encoderObj->PrevFreq[1], 3*LPC_ORDER);
ippsCopy_32f(CurrFreq, encoderObj->PrevFreq[0], LPC_ORDER);
*anau++ = code_lsp[0];
*anau++ = code_lsp[1];
}
/* Find the weighted input speech w_sp[] for the whole speech frame */
if(LPCMode == 0) {
apLen = LPC_ORDER;
aqLen = LPC_ORDER;
if (encoderObj->isBWDDominant == 0) pUnQLPC = forwardLPC;
else pUnQLPC = forwardQntLPC;
pQLPC = forwardQntLPC;
if(codecType==G729A_CODEC) {
/* Compute A(z/gamma) */
WeightLPCCoeff_G729(&forwardQntLPC[0], GAMMA1_G729A, LPC_ORDER, &forwardLPC[0]);
WeightLPCCoeff_G729(&forwardQntLPC[LPC_ORDERP1], GAMMA1_G729A, LPC_ORDER, &forwardLPC[LPC_ORDERP1]);
} else {
PWGammaFactor_G729(gamma1, gamma2, InterpolatedLSF, CurrLSF, forwardReflectCoeff,&encoderObj->isSmooth, encoderObj->LogAreaRatioCoeff);
/* update previous filter for next frame */
ippsCopy_32f(&pQLPC[LPC_ORDERP1], encoderObj->PrevFlt, LPC_ORDERP1);
for(i=LPC_ORDERP1; i <BWD_LPC_ORDERP1; i++) encoderObj->PrevFlt[i] = 0.f;
for(j=LPC_ORDERP1; j<BWD_LPC_ORDERP1; j++) encoderObj->UnitImpulse[j] = 0.f;
}
} else {
if (encoderObj->isBWDDominant == 0) {
apLen = LPC_ORDER;
pUnQLPC = forwardLPC;
} else {
apLen = BWD_LPC_ORDER;
pUnQLPC = backwardLPC;
}
aqLen = BWD_LPC_ORDER;
pQLPC = backwardLPC;
/* ADAPTIVE BANDWIDTH EXPANSION FOR THE PERCEPTUAL WEIGHTING FILTER */
if (encoderObj->isBWDDominant == 0) {
gamma1[0] = 0.9f;
gamma1[1] = 0.9f;
gamma2[0] = 0.4f;
gamma2[1] = 0.4f;
} else {
gamma1[0] = 0.98f;
gamma1[1] = 0.98f;
gamma2[0] = 0.4f;
gamma2[1] = 0.4f;
}
if (encoderObj->isBWDDominant == 0) {
for(j=LPC_ORDERP1; j<BWD_LPC_ORDERP1; j++) encoderObj->UnitImpulse[j] = 0.f;
}
/* update previous filter for next frame */
ippsCopy_32f(&pQLPC[BWD_LPC_ORDERP1], encoderObj->PrevFlt, BWD_LPC_ORDERP1);
}
/* 3.3 Compute weighted input speech for the whole speech frame. */
if(codecType!=G729A_CODEC){
pLPC = pUnQLPC;
for (i=0; i<2; i++) {
WeightLPCCoeff_G729(pLPC, gamma1[i], apLen, WeightedLPC1);
WeightLPCCoeff_G729(pLPC, gamma2[i], apLen, WeightedLPC2);
ippsConvBiased_32f(WeightedLPC1,apLen+1,&SpeechWnd[i*SUBFR_LEN],SUBFR_LEN+apLen,&WeightedSpeech[i*SUBFR_LEN],SUBFR_LEN,apLen);
ippsSynthesisFilter_G729_32f(WeightedLPC2, apLen, &WeightedSpeech[i*SUBFR_LEN], &WeightedSpeech[i*SUBFR_LEN], SUBFR_LEN, &encoderObj->FltMem[BWD_LPC_ORDER-apLen]);
for(j=0; j<BWD_LPC_ORDER; j++) encoderObj->FltMem[j] = WeightedSpeech[i*SUBFR_LEN+SUBFR_LEN-BWD_LPC_ORDER+j];
pLPC += apLen+1;
}
/* 3.4 Open-loop analysis. */
OpenLoopPitchSearch_G729_32f(WeightedSpeech, &openLoopPitch);
for (i= 0; i< 4; i++)
encoderObj->LagBuffer[i] = encoderObj->LagBuffer[i+1];
avg_lag = AVG(encoderObj->LagBuffer[0],encoderObj->LagBuffer[1],encoderObj->LagBuffer[2],encoderObj->LagBuffer[3]);
if( abs( (int) (openLoopPitch/2.0) - avg_lag)<=2)
encoderObj->LagBuffer[4] = (int) (openLoopPitch/2.0);
else if( abs((int) (openLoopPitch/3.0) - avg_lag)<=2)
encoderObj->LagBuffer[4] = (int) (openLoopPitch/3.0);
else
encoderObj->LagBuffer[4] = openLoopPitch;
} else {
ippsConvBiased_32f(&forwardQntLPC[0],LPC_ORDER+1,SpeechWnd,SUBFR_LEN+LPC_ORDER,Excitation,SUBFR_LEN,LPC_ORDER);
ippsConvBiased_32f(&forwardQntLPC[LPC_ORDERP1],LPC_ORDER+1,&SpeechWnd[SUBFR_LEN],SUBFR_LEN+LPC_ORDER,&Excitation[SUBFR_LEN],SUBFR_LEN,LPC_ORDER);
{
WeightedLPC1[0] = 1.0f;
for(i=1; i<=LPC_ORDER; i++)
WeightedLPC1[i] = forwardLPC[i] - 0.7f * forwardLPC[i-1];
ippsSynthesisFilter_G729_32f(WeightedLPC1, LPC_ORDER, &Excitation[0], &WeightedSpeech[0], SUBFR_LEN, encoderObj->FltMem);
for (i = 0; i < LPC_ORDER; i++) CLIP_DENORMAL(WeightedSpeech[(SUBFR_LEN-LPC_ORDER)+i],encoderObj->FltMem[i]);
for(i=1; i<=LPC_ORDER; i++)
WeightedLPC1[i] = forwardLPC[i+LPC_ORDERP1] - 0.7f * forwardLPC[i-1+LPC_ORDERP1];
ippsSynthesisFilter_G729_32f(WeightedLPC1, LPC_ORDER, &Excitation[SUBFR_LEN], &WeightedSpeech[SUBFR_LEN], SUBFR_LEN, encoderObj->FltMem);
for (i = 0; i < LPC_ORDER; i++) CLIP_DENORMAL(WeightedSpeech[SUBFR_LEN+(SUBFR_LEN-LPC_ORDER)+i],encoderObj->FltMem[i]);
}
/* Annex A.3.4 Open-loop analysis */
ippsOpenLoopPitchSearch_G729A_32f(WeightedSpeech, &openLoopPitch);
}
/* Range for closed loop pitch search in 1st subframe */
minPitchDelay = openLoopPitch - 3;
if (minPitchDelay < PITCH_LAG_MIN) minPitchDelay = PITCH_LAG_MIN;
maxPitchDelay = minPitchDelay + 6;
if (maxPitchDelay > PITCH_LAG_MAX) {
maxPitchDelay = PITCH_LAG_MAX;
minPitchDelay = maxPitchDelay - 6;
}
pLPC = pUnQLPC; /* pointer to interpolated "unquantized"LPC parameters */
pQntLPC = pQLPC; /* pointer to interpolated "quantized" LPC parameters */
for (NSbfr = 0, NGamma = 0; NSbfr < FRM_LEN; NSbfr += SUBFR_LEN, NGamma++) {
if(codecType!=G729A_CODEC){
/* LPC computing: weights of filter */
WeightLPCCoeff_G729(pLPC, gamma1[NGamma], apLen, WeightedLPC1);
WeightLPCCoeff_G729(pLPC, gamma2[NGamma], apLen, WeightedLPC2);
/* Clause 3.5 Computation of impulse response */
for (i = 0; i <=apLen; i++) encoderObj->UnitImpulse[i] = WeightedLPC1[i];
ippsSynthesisFilter_G729_32f(pQntLPC, aqLen, encoderObj->UnitImpulse, ImpulseResponse, SUBFR_LEN, pZero);
ippsSynthesisFilter_G729_32f(WeightedLPC2, apLen, ImpulseResponse, ImpulseResponse, SUBFR_LEN, pZero);
/* pass the resudual r(n) through 1/A(z) */
ippsConvBiased_32f(pQntLPC,aqLen+1,&SpeechWnd[NSbfr],SUBFR_LEN+aqLen,&Excitation[NSbfr],SUBFR_LEN,aqLen);
for (i=0; i<SUBFR_LEN; i++) PitchPredResidual[i] = Excitation[NSbfr+i];
ippsSynthesisFilter_G729_32f(pQntLPC, aqLen, &Excitation[NSbfr], pError, SUBFR_LEN, &encoderObj->ErrFltMemory[BWD_LPC_ORDER-aqLen]);
/* then through the weighting filter W(z) where TargetVector is a target signal*/
ippsConvBiased_32f(WeightedLPC1,aqLen+1,pError,SUBFR_LEN+aqLen,TargetVector,SUBFR_LEN,aqLen);
ippsSynthesisFilter_G729_32f(WeightedLPC2, apLen, TargetVector, TargetVector, SUBFR_LEN, &encoderObj->WeightedFilterMemory[BWD_LPC_ORDER-apLen]);
pitchDelay = AdaptiveCodebookSearch_G729_32f(&Excitation[NSbfr], TargetVector, ImpulseResponse, SUBFR_LEN, minPitchDelay, maxPitchDelay,
NSbfr, &fracPartPitchDelay, codecType,TmpAlignVec);
} else {
/* Computation of impulse response */
ImpulseResponse[0] = 1.0f;
ippsZero_32f(&ImpulseResponse[1], SUBFR_LEN-1);
ippsSynthesisFilter_G729_32f(pLPC, LPC_ORDER, ImpulseResponse, ImpulseResponse, SUBFR_LEN, &ImpulseResponse[1]);
/* Annex A.3.6 Computation of target signal */
ippsSynthesisFilter_G729_32f(pLPC, LPC_ORDER, &Excitation[NSbfr], TargetVector, SUBFR_LEN, encoderObj->WeightedFilterMemory);
/* Annex A.3.7 Adaptive-codebook search */
pitchDelay = ownAdaptiveCodebookSearch_G729A_32f(&Excitation[NSbfr], TargetVector, ImpulseResponse, minPitchDelay, maxPitchDelay,
NSbfr, &fracPartPitchDelay,TmpAlignVec);
}
if (NSbfr == 0) { /* if 1st subframe */
/* encode pitch delay (with fraction) */
if (pitchDelay <= 85)
index = pitchDelay*3 - 58 + fracPartPitchDelay;
else
index = pitchDelay + 112;
/* find T0_min and T0_max for second subframe */
minPitchDelay = pitchDelay - 5;
if (minPitchDelay < PITCH_LAG_MIN) minPitchDelay = PITCH_LAG_MIN;
maxPitchDelay = minPitchDelay + 9;
if (maxPitchDelay > PITCH_LAG_MAX) {
maxPitchDelay = PITCH_LAG_MAX;
minPitchDelay = maxPitchDelay - 9;
}
} else { /* second subframe */
if (codecType == G729D_CODEC) { /* 4 bits in 2nd subframe (6.4 kbps) */
if (pitchDelay < minPitchDelay + 3)
index = pitchDelay - minPitchDelay;
else if (pitchDelay < minPitchDelay + 7)
index = (pitchDelay - (minPitchDelay + 3)) * 3 + fracPartPitchDelay + 3;
else
index = (pitchDelay - (minPitchDelay + 7)) + 13;
} else {
index = pitchDelay - minPitchDelay;
index = index*3 + 2 + fracPartPitchDelay;
}
}
*anau++ = index;
if ( (NSbfr == 0) && (codecType != G729D_CODEC) ) {
*anau = Parity(index);
if( codecType == G729E_CODEC) {
*anau ^= ((index >> 1) & 0x0001);
}
anau++;
}
if(codecType!=G729A_CODEC){
delayLine[0] = pitchDelay;
delayLine[1] = fracPartPitchDelay;
ippsDecodeAdaptiveVector_G729_32f_I(delayLine, &Excitation[NSbfr]);
ippsConvBiased_32f( &Excitation[NSbfr], SUBFR_LEN , ImpulseResponse, SUBFR_LEN , FltAdaptExc, SUBFR_LEN ,0);
} else {
ippsSynthesisFilter_G729_32f(pLPC, LPC_ORDER, &Excitation[NSbfr], FltAdaptExc, SUBFR_LEN, encoderObj->ZeroMemory);
}
/* clause 3.7.3 Computation of the adaptive-codebook gain */
pitchGain = ownAdaptiveCodebookGainCoeff_G729_32f(TargetVector, FltAdaptExc, g_coeff, SUBFR_LEN);
/* clip pitch gain if taming is necessary */
taming = TestErrorContribution_G729(pitchDelay, fracPartPitchDelay, encoderObj->ExcitationError);
if( taming == 1){
CLIP_TO_UPLEVEL(pitchGain,MAX_GAIN_TIMING);
}
/* Annex A3.8.1 */
/* clause 3.8.1 Equ 50 */
ippsAdaptiveCodebookContribution_G729_32f(pitchGain, FltAdaptExc, TargetVector, FltTargetVector);
/* Fixed codebook search. */
{
LOCAL_ALIGN_ARRAY(32, float, dn, SUBFR_LEN,encoderObj);
LOCAL_ALIGN_ARRAY(32, float, rr, TOEPLIZ_MATRIX_SIZE,encoderObj);
/* pitch contribution to ImpulseResponse */
if(pitchDelay < SUBFR_LEN) {
ippsHarmonicFilter_32f_I(encoderObj->fBetaPreFilter,pitchDelay,&ImpulseResponse[pitchDelay],SUBFR_LEN-pitchDelay);
}
ippsCrossCorr_32f(ImpulseResponse, SUBFR_LEN, FltTargetVector, SUBFR_LEN, dn, SUBFR_LEN, 0);
switch (codecType) {
case G729_CODEC: /* 8 kbit/s */
{
ippsToeplizMatrix_G729_32f(ImpulseResponse, rr);
ippsFixedCodebookSearch_G729_32f(dn, rr, FixedCodebookExc, anau, &encoderObj->sSearchTimes, NSbfr);
CodewordImpConv_G729_32f(anau[0],FixedCodebookExc,ImpulseResponse,FltFixedCodebookExc );
anau += 2;
break;
}
case G729A_CODEC: /* 8 kbit/s */
{
ippsToeplizMatrix_G729_32f(ImpulseResponse, rr);
ippsFixedCodebookSearch_G729A_32f(dn, rr, FixedCodebookExc, anau);
CodewordImpConv_G729_32f(anau[0],FixedCodebookExc,ImpulseResponse,FltFixedCodebookExc );
anau += 2;
break;
}
case G729D_CODEC: /* 6.4 kbit/s */
{
ippsToeplizMatrix_G729D_32f(ImpulseResponse, rr);
ippsFixedCodebookSearch_G729D_32f(dn, rr, ImpulseResponse, FixedCodebookExc, FltFixedCodebookExc, anau);
anau += 2;
break;
}
case G729E_CODEC: /* 11.8 kbit/s */
{
/* calculate residual after long term prediction */
ippsAdaptiveCodebookContribution_G729_32f(pitchGain, &Excitation[NSbfr], PitchPredResidual, PitchPredResidual);
ippsFixedCodebookSearch_G729E_32f(LPCMode, dn, PitchPredResidual, ImpulseResponse, FixedCodebookExc, FltFixedCodebookExc, anau);
anau += 5;
break;
}
} /* end of switch */
/* Include fixed-gain pitch contribution into FixedCodebookExc. */
if(pitchDelay < SUBFR_LEN) {
ippsHarmonicFilter_32f_I(encoderObj->fBetaPreFilter,pitchDelay,&FixedCodebookExc[pitchDelay],SUBFR_LEN-pitchDelay);
}
LOCAL_ALIGN_ARRAY_FREE(32, float, rr, TOEPLIZ_MATRIX_SIZE,encoderObj);
LOCAL_ALIGN_ARRAY_FREE(32, float, dn, SUBFR_LEN,encoderObj);
}
/* Annex A3.9 Quantization of gains */
/* + Clause 3.9*/
AdaptiveCodebookGainCoeff_G729_32f( TargetVector, FltAdaptExc, FltFixedCodebookExc, g_coeff);
index = GainQuant_G729(FixedCodebookExc, g_coeff, SUBFR_LEN, &pitchGain, &codeGain, taming,encoderObj->PastQuantEnergy,codecType,(char *)TmpAlignVec);
*anau++ = index;
/* Update and bound pre filter factor with quantized adaptive codebook gain */
for (i= 0; i< 4; i++)
encoderObj->PitchGainBuffer[i] = encoderObj->PitchGainBuffer[i+1];
encoderObj->PitchGainBuffer[4] = pitchGain;
encoderObj->fBetaPreFilter = pitchGain;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -