📄 cod_ace.c
字号:
if (pit_flag == 0) { /* if 1st/3rd subframe */
/*--------------------------------------------------------------*
* The pitch range for the 1st/3rd subframe is encoded with *
* 9 bits and is divided as follows: *
* PIT_MIN to PIT_FR2-1 resolution 1/4 (frac = 0,1,2 or 3) *
* PIT_FR2 to PIT_FR1-1 resolution 1/2 (frac = 0 or 2) *
* PIT_FR1 to PIT_MAX resolution 1 (frac = 0) *
*--------------------------------------------------------------*/
if (T0 < PIT_FR2) {
index = T0*4 + T0_frac - (PIT_MIN*4);
} else if (T0 < PIT_FR1) {
index = T0*2 + (T0_frac>>1) - (PIT_FR2*2) + ((PIT_FR2-PIT_MIN)*4);
} else {
index = T0 - PIT_FR1 + ((PIT_FR2-PIT_MIN)*4) + ((PIT_FR1-PIT_FR2)*2);
}
/* find T0_min and T0_max for subframe 2 and 4 */
T0_min = T0 - 8;
if (T0_min < PIT_MIN) {
T0_min = PIT_MIN;
}
T0_max = T0_min + 15;
if (T0_max > PIT_MAX) {
T0_max = PIT_MAX;
T0_min = T0_max - 15;
}
} else { /* if subframe 2 or 4 */
/*--------------------------------------------------------------*
* The pitch range for subframe 2 or 4 is encoded with 6 bits: *
* T0_min to T0_max resolution 1/4 (frac = 0,1,2 or 3) *
*--------------------------------------------------------------*/
i = T0 - T0_min;
index = i*4 + T0_frac;
}
/* store pitch-lag for high band coding */
T_out[i_subfr/L_SUBFR] = T0;
*prm = index; prm++;
/*-----------------------------------------------------------------*
* - find unity gain pitch excitation (adaptive codebook entry) *
* with fractional interpolation. *
* - find filtered pitch exc. y1[]=exc[] convolved with h1[]) *
* - compute pitch gain1 *
*-----------------------------------------------------------------*/
/* find pitch exitation */
pred_lt4(&exc[i_subfr], T0, T0_frac, L_SUBFR+1);
E_UTIL_f_convolve(&exc[i_subfr], h1, y1);
gain1 = E_ACELP_xy1_corr(xn, y1, g_corr);
/* find energy of new target xn2[] */
E_ACELP_codebook_target_update(xn, xn2, y1, gain1);
ener = 0.0;
for (i=0; i<L_SUBFR; i++) {
ener += xn2[i]*xn2[i];
}
/*-----------------------------------------------------------------*
* - find pitch excitation filtered by 1st order LP filter. *
* - find filtered pitch exc. y2[]=exc[] convolved with h1[]) *
* - compute pitch gain2 *
*-----------------------------------------------------------------*/
/* find pitch excitation with lp filter */
for (i=0; i<L_SUBFR; i++) {
code[i] = (float)(0.18*exc[i-1+i_subfr] + 0.64*exc[i+i_subfr] + 0.18*exc[i+1+i_subfr]);
}
E_UTIL_f_convolve(code, h1, y2);
gain2 = E_ACELP_xy1_corr(xn, y2, g_corr2);
/* find energy of new target xn2[] */
E_ACELP_codebook_target_update(xn, xn2, y2, gain2);
tmp = 0.0;
for (i=0; i<L_SUBFR; i++) {
tmp += xn2[i]*xn2[i];
}
/*-----------------------------------------------------------------*
* use the best prediction (minimise quadratic error). *
*-----------------------------------------------------------------*/
if (tmp < ener) {
/* use the lp filter for pitch excitation prediction */
select = 0;
mvr2r(code, &exc[i_subfr], L_SUBFR);
mvr2r(y2, y1, L_SUBFR);
gain_pit = gain2;
g_corr[0] = g_corr2[0];
g_corr[1] = g_corr2[1];
} else {
/* no filter used for pitch excitation prediction */
select = 1;
gain_pit = gain1;
}
*prm = select; prm++;
/*-----------------------------------------------------------------*
* - update target vector for codebook search *
*-----------------------------------------------------------------*/
E_ACELP_codebook_target_update(xn, xn2, y1, gain_pit);
E_ACELP_codebook_target_update(cn, cn, &exc[i_subfr], gain_pit);
/*-----------------------------------------------------------------*
* - include fixed-gain pitch contribution into impulse resp. h1[] *
*-----------------------------------------------------------------*/
tmp = 0.0;
E_UTIL_f_preemph(h1, TILT_CODE, L_SUBFR, &tmp);
if (T0_frac > 2) {
T0++;
}
E_GAIN_f_pitch_sharpening(h1, T0);
/*-----------------------------------------------------------------*
* - Correlation between target xn2[] and impulse response h1[] *
* - Innovative codebook search *
*-----------------------------------------------------------------*/
E_ACELP_xh_corr(xn2, dn, h1);
if (codec_mode == MODE_9k6) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 20, 0, (Word32*)prm);
prm += 4;
} else if (codec_mode == MODE_11k2) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 28, 0, (Word32*)prm);
prm += 4;
} else if (codec_mode == MODE_12k8) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 36, 0, (Word32*)prm);
prm += 4;
} else if (codec_mode == MODE_14k4) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 44, 0, (Word32*)prm);
prm += 4;
} else if (codec_mode == MODE_16k) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 52, 0, (Word32*)prm);
prm += 4;
} else if (codec_mode == MODE_18k4) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 64, 0, (Word32*)prm);
prm += 8;
} else if (codec_mode == MODE_20k) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 72, 0, (Word32*)prm);
prm += 8;
} else if (codec_mode == MODE_23k2) {
E_ACELP_4t(dn, cn, h1, code3GPP, y2, 88, 0, (Word32*)prm);
prm += 8;
} else {
printf("invalid mode for acelp frame!\n");
exit(0);
}
{
int g;
for(g=0;g<L_SUBFR;g++) {
code[g] = (float)(code3GPP[g]/512);
}
}
/*-------------------------------------------------------*
* - Add the fixed-gain pitch contribution to code[]. *
*-------------------------------------------------------*/
tmp = 0.0;
E_UTIL_f_preemph(code, TILT_CODE, L_SUBFR, &tmp);
E_GAIN_f_pitch_sharpening(code, T0);
/*----------------------------------------------------------*
* - Compute the fixed codebook gain *
* - quantize fixed codebook gain *
*----------------------------------------------------------*/
E_ACELP_xy2_corr(xn, y1, y2, g_corr);
index = q_gain2_plus(code, L_SUBFR, &gain_pit, &gain_code, g_corr, mean_ener_code, &c_out[i_subfr/L_SUBFR]);
*prm = index; prm++;
/* store pitch-lag for high band coding */
p_out[i_subfr/L_SUBFR] = gain_pit;
/*----------------------------------------------------------*
* - voice factor (for pitch enhancement) *
*----------------------------------------------------------*/
/* energy of pitch excitation */
ener = 0.0;
for (i=0; i<L_SUBFR; i++) {
ener += exc[i+i_subfr]*exc[i+i_subfr];
}
ener *= (gain_pit*gain_pit);
/* energy of innovative code excitation */
tmp = 0.0;
for (i=0; i<L_SUBFR; i++) {
tmp += code[i]*code[i];
}
tmp *= gain_code*gain_code;
/* find voice factor (1=voiced, -1=unvoiced) */
voice_fac = (float)((ener - tmp) / (ener + tmp + 0.01));
/*------------------------------------------------------*
* - Update filter's memory "mem_w0" for finding the *
* target vector in the next subframe. *
* - Find the total excitation *
* - Find synthesis speech to update mem_syn[]. *
*------------------------------------------------------*/
*mem_wsyn += (gain_pit*y1[L_SUBFR-1]) + (gain_code*y2[L_SUBFR-1]);
for (i = 0; i < L_SUBFR; i++) {
exc[i+i_subfr] = gain_pit*exc[i+i_subfr] + gain_code*code[i];
}
for (i=0; i<L_SUBFR; i++) {
code[i] *= gain_code;
}
/*----------------------------------------------------------*
* - compute the synthesis speech *
*----------------------------------------------------------*/
E_UTIL_synthesis(p_Aq, &exc[i_subfr], &synth[i_subfr], L_SUBFR, &synth[i_subfr-M], 0);
p_A += (M+1);
p_Aq += (M+1);
} /* end of subframe loop */
/*----------------------------------------------------------*
* find 10ms ZIR in weighted domain for next tcx frame *
*----------------------------------------------------------*/
E_LPC_a_weight(p_Aq, Ap, GAMMA1, M); /* wAi of tcx is quantized */
mvr2r(&synth[lg-M], error, M);
tmp = *mem_wsyn;
for (i_subfr=0; i_subfr<(2*L_SUBFR); i_subfr+=L_SUBFR) {
set_zero(error+M, L_SUBFR);
E_UTIL_synthesis(p_Aq, error+M, error+M, L_SUBFR, error, 0);
E_UTIL_residu(Ap, error+M, &wovlp[i_subfr], L_SUBFR);
E_UTIL_deemph(&wovlp[i_subfr], TILT_FAC, L_SUBFR, &tmp);
mvr2r(error+L_SUBFR, error, M);
}
for (i=0; i<L_SUBFR; i++) {
wovlp[L_SUBFR+i] *= ((float)(L_SUBFR-i))/((float)L_SUBFR);
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -