📄 dec_main.c
字号:
else
{
index = *prms++;
if(index < ((PIT_FR2 - PIT_MIN) * 4))
{
T0 = PIT_MIN + (index >> 2);
T0_frac = index - ((T0 - PIT_MIN) << 2);
}
else if(index <
((((PIT_FR2 - PIT_MIN) * 4) + ((PIT_FR1_9b - PIT_FR2) * 2))))
{
index = (Word16)((index - ((PIT_FR2 - PIT_MIN) * 4)));
T0 = PIT_FR2 + (index >> 1);
T0_frac = index - ((T0 - PIT_FR2) << 1);
T0_frac = T0_frac << 1;
}
else
{
T0 = index + (PIT_FR1_9b - ((PIT_FR2 - PIT_MIN) * 4) -
((PIT_FR1_9b - PIT_FR2) * 2));
T0_frac = 0;
}
}
/* 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 */
if(mode <= MODE_9k)
{
index = *prms++;
T0 = T0_min + (index >> 1);
T0_frac = index - ((T0 - T0_min) << 1);
T0_frac = T0_frac << 1;
}
else
{
index = *prms++;
T0 = T0_min + (index >> 2);
T0_frac = index - ((T0 - T0_min) << 2);
}
}
/* check BFI after pitch lag decoding */
if(bfi != 0) /* if frame erasure */
{
D_GAIN_lag_concealment(&(st->mem_gain[17]), st->mem_lag, &T0,
&(st->mem_T0), &(st->mem_seed3), unusable_frame);
T0_frac = 0;
}
/*
* Find the pitch gain, the interpolation filter
* and the adaptive codebook vector.
*/
D_GAIN_adaptive_codebook_excitation(&exc[i_subfr], T0, T0_frac);
if(unusable_frame)
{
select = 1;
}
else
{
if(mode <= MODE_9k)
{
select = 0;
}
else
{
select = *prms++;
}
}
if(select == 0)
{
/* find pitch excitation with lp filter */
for(i = 0; i < L_SUBFR; i++)
{
L_tmp = 2949 * exc[i - 1 + i_subfr];
L_tmp = L_tmp + (10486 * exc[i + i_subfr]);
L_tmp = L_tmp + (2949 * exc[i + 1 + i_subfr]);
code[i] = (Word16)((L_tmp + 0x2000) >> 14);
}
memcpy(&exc[i_subfr], code, L_SUBFR * sizeof(Word16));
}
/*
* Decode innovative codebook.
* Add the fixed-gain pitch contribution to code[].
*/
if(unusable_frame != 0)
{
/* the innovative code doesn't need to be scaled (see Q_gain2) */
for(i = 0; i < L_SUBFR; i++)
{
code[i] = (Word16)(D_UTIL_random(&(st->mem_seed)) >> 3);
}
}
else if(mode <= MODE_7k)
{
ind[0] = *prms++;
D_ACELP_decode_2t(ind[0], code);
}
else if(mode <= MODE_9k)
{
memcpy(ind, prms, 4 * sizeof(Word16));
prms += 4;
D_ACELP_decode_4t(ind, 20, code);
}
else if(mode <= MODE_12k)
{
memcpy(ind, prms, 4 * sizeof(Word16));
prms += 4;
D_ACELP_decode_4t(ind, 36, code);
}
else if(mode <= MODE_14k)
{
memcpy(ind, prms, 4 * sizeof(Word16));
prms += 4;
D_ACELP_decode_4t(ind, 44, code);
}
else if(mode <= MODE_16k)
{
memcpy(ind, prms, 4 * sizeof(Word16));
prms += 4;
D_ACELP_decode_4t(ind, 52, code);
}
else if(mode <= MODE_18k)
{
memcpy(ind, prms, 8 * sizeof(Word16));
prms += 8;
D_ACELP_decode_4t(ind, 64, code);
}
else if(mode <= MODE_20k)
{
memcpy(ind, prms, 8 * sizeof(Word16));
prms += 8;
D_ACELP_decode_4t(ind, 72, code);
}
else
{
memcpy(ind, prms, 8 * sizeof(Word16));
prms += 8;
D_ACELP_decode_4t(ind, 88, code);
}
tmp = 0;
D_UTIL_preemph(code, st->mem_tilt_code, L_SUBFR, &tmp);
L_tmp = T0;
if(T0_frac > 2)
{
L_tmp = L_tmp + 1;
}
D_GAIN_pitch_sharpening(code, L_tmp, PIT_SHARP);
/*
* Decode codebooks gains.
*/
index = *prms++; /* codebook gain index */
if(mode <= MODE_9k)
{
D_GAIN_decode(index, 6, code, &gain_pit, &L_gain_code, bfi,
st->mem_bfi, st->mem_state, unusable_frame, st->mem_vad_hist,
st->mem_gain);
}
else
{
D_GAIN_decode(index, 7, code, &gain_pit, &L_gain_code, bfi,
st->mem_bfi, st->mem_state, unusable_frame, st->mem_vad_hist,
st->mem_gain);
}
/* find best scaling to perform on excitation (Q_new) */
tmp = st->mem_subfr_q[0];
for(i = 1; i < 4; i++)
{
if(st->mem_subfr_q[i] < tmp)
{
tmp = st->mem_subfr_q[i];
}
}
/* limit scaling (Q_new) to Q_MAX */
if(tmp > Q_MAX)
{
tmp = Q_MAX;
}
Q_new = 0;
L_tmp = L_gain_code; /* L_gain_code in Q16 */
while((L_tmp < 0x08000000L) && (Q_new < tmp))
{
L_tmp = (L_tmp << 1);
Q_new = (Word16)((Q_new + 1));
}
if(L_tmp < 0x7FFF7FFF)
{
gain_code = (Word16)((L_tmp + 0x8000) >> 16);
/* scaled gain_code with Qnew */
}
else
{
gain_code = 32767;
}
if(Q_new > st->mem_q)
{
D_UTIL_signal_up_scale(exc + i_subfr - (PIT_MAX + L_INTERPOL),
PIT_MAX + L_INTERPOL + L_SUBFR, (Word16)(Q_new - st->mem_q));
}
else
{
D_UTIL_signal_down_scale(exc + i_subfr - (PIT_MAX + L_INTERPOL),
PIT_MAX + L_INTERPOL + L_SUBFR, (Word16)(st->mem_q - Q_new));
}
st->mem_q = Q_new;
/*
* Update parameters for the next subframe.
* - tilt of code: 0.0 (unvoiced) to 0.5 (voiced)
*/
if(bfi == 0)
{
/* LTP-Lag history update */
for(i = 4; i > 0; i--)
{
st->mem_lag[i] = st->mem_lag[i - 1];
}
st->mem_lag[0] = (Word16)T0;
st->mem_T0 = (Word16)T0;
st->mem_T0_frac = 0; /* Remove fraction in case of BFI */
}
/* find voice factor in Q15 (1=voiced, -1=unvoiced) */
memcpy(exc2, &exc[i_subfr], L_SUBFR * sizeof(Word16));
D_UTIL_signal_down_scale(exc2, L_SUBFR, 3);
/* post processing of excitation elements */
if(mode <= MODE_9k)
{
pit_sharp = (Word16)(gain_pit << 1);
if(pit_sharp > 16384)
{
if(pit_sharp > 32767)
{
pit_sharp = 32767;
}
for(i = 0; i < L_SUBFR; i++)
{
L_tmp = (exc2[i] * pit_sharp) >> 15;
L_tmp = L_tmp * gain_pit;
excp[i] = (Word16)((L_tmp + 0x8000) >> 16);
}
}
}
voice_fac = D_GAIN_find_voice_factor(exc2, -3, gain_pit, code, gain_code,
L_SUBFR);
/* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */
st->mem_tilt_code = (Word16)((voice_fac >> 2) + 8192);
/*
* Find the total excitation.
* Find synthesis speech corresponding to exc[].
* Find maximum value of excitation for next scaling
*/
memcpy(exc2, &exc[i_subfr], L_SUBFR * sizeof(Word16));
max = 1;
for(i = 0; i < L_SUBFR; i++)
{
L_tmp = (code[i] * gain_code) << 5;
L_tmp = L_tmp + (exc[i + i_subfr] * gain_pit);
L_tmp = (L_tmp + 0x2000) >> 14;
if((L_tmp > MIN_16) & (L_tmp < 32768))
{
exc[i + i_subfr] = (Word16)L_tmp;
tmp = (Word16)(abs(L_tmp));
if(tmp > max)
{
max = tmp;
}
}
else if(L_tmp > MAX_16)
{
exc[i + i_subfr] = MAX_16;
max = MAX_16;
}
else
{
exc[i + i_subfr] = MIN_16;
max = MAX_16;
}
}
/* tmp = scaling possible according to max value of excitation */
tmp = (Word16)((D_UTIL_norm_s(max) + Q_new) - 1);
st->mem_subfr_q[3] = st->mem_subfr_q[2];
st->mem_subfr_q[2] = st->mem_subfr_q[1];
st->mem_subfr_q[1] = st->mem_subfr_q[0];
st->mem_subfr_q[0] = tmp;
/*
* phase dispersion to enhance noise in low bit rate
*/
/* L_gain_code in Q16 */
D_UTIL_l_extract(L_gain_code, &gain_code, &gain_code_lo);
if(mode <= MODE_7k)
{
j = 0; /* high dispersion for rate <= 7.5 kbit/s */
}
else if(mode <= MODE_9k)
{
j = 1; /* low dispersion for rate <= 9.6 kbit/s */
}
else
{
j = 2; /* no dispersion for rate > 9.6 kbit/s */
}
D_ACELP_phase_dispersion(gain_code, gain_pit, code, (Word16)j,
st->mem_ph_disp);
/*
* noise enhancer
* - Enhance excitation on noise. (modify gain of code)
* If signal is noisy and LPC filter is stable, move gain
* of code 1.5 dB toward gain of code threshold.
* This decrease by 3 dB noise energy variation.
*/
L_tmp = 16384 - (voice_fac >> 1); /* 1=unvoiced, 0=voiced */
fac = (Word16)((L_stab_fac * L_tmp) >> 15);
L_tmp = L_gain_code;
if(L_tmp < st->mem_gc_thres)
{
L_tmp = (L_tmp + D_UTIL_mpy_32_16(gain_code, gain_code_lo, 6226));
if(L_tmp > st->mem_gc_thres)
{
L_tmp = st->mem_gc_thres;
}
}
else
{
L_tmp = D_UTIL_mpy_32_16(gain_code, gain_code_lo, 27536);
if(L_tmp < st->mem_gc_thres)
{
L_tmp = st->mem_gc_thres;
}
}
st->mem_gc_thres = L_tmp;
L_gain_code =
D_UTIL_mpy_32_16(gain_code, gain_code_lo, (Word16)(32767 - fac));
D_UTIL_l_extract(L_tmp, &gain_code, &gain_code_lo);
L_gain_code =
L_gain_code + D_UTIL_mpy_32_16(gain_code, gain_code_lo, fac);
/*
* pitch enhancer
* - Enhance excitation on voice. (HP filtering of code)
* On voiced signal, filtering of code by a smooth fir HP
* filter to decrease energy of code in low frequency.
*/
L_tmp2 = (voice_fac >> 3) + 4096; /* 0.25=voiced, 0=unvoiced */
L_tmp = (code[0] << 15) - (code[1] * L_tmp2);
code2[0] = (L_tmp + 0x4000) >> 15;
for(i = 1; i < L_SUBFR - 1; i++)
{
L_tmp = code[i] << 15;
L_tmp = L_tmp - (code[i + 1] * L_tmp2);
L_tmp = L_tmp - (code[i - 1] * L_tmp2);
code2[i] = (L_tmp + 0x4000) >> 15;
}
L_tmp = code[L_SUBFR - 1] << 15;
L_tmp = L_tmp - (code[L_SUBFR - 2] * L_tmp2);
code2[L_SUBFR - 1] = (L_tmp + 0x4000) >> 15;
/* build excitation */
gain_code = (Word16)(((L_gain_code << Q_new) + 0x8000) >> 16);
for(i = 0; i < L_SUBFR; i++)
{
L_tmp = (code2[i] * gain_code) << 5;
L_tmp = L_tmp + (exc2[i] * gain_pit);
L_tmp = (L_tmp + 0x2000) >> 14;
exc2[i] = D_UTIL_saturate(L_tmp);
}
if(mode <= MODE_9k)
{
if(pit_sharp > 16384)
{
for(i = 0; i < L_SUBFR; i++)
{
L_tmp = (excp[i] + exc2[i]);
excp[i] = D_UTIL_saturate(L_tmp);
}
D_GAIN_adaptive_control(exc2, excp, L_SUBFR);
memcpy(exc2, excp, L_SUBFR * sizeof(Word16));
}
}
if(mode <= MODE_7k)
{
j = (i_subfr >> 6);
for(i = 0; i < M; i++)
{
L_tmp = isf_tmp[i] * (32767 - D_ROM_interpol_frac[j]);
L_tmp = L_tmp + (isf[i] * D_ROM_interpol_frac[j]);
HfIsf[i] = (Word16)((L_tmp + 0x4000) >> 15);
}
}
else
{
memset(st->mem_syn_hf, 0, (M16k - M) * sizeof(Word16));
}
if(mode >= MODE_24k)
{
corr_gain = *prms++;
D_UTIL_dec_synthesis(p_Aq, exc2, Q_new, &synth16k[i_subfr * 5 / 4],
corr_gain, HfIsf, mode, newDTXState, bfi, st);
}
else
{
D_UTIL_dec_synthesis(p_Aq, exc2, Q_new, &synth16k[i_subfr * 5 / 4], 0,
HfIsf, mode, newDTXState, bfi, st);
}
p_Aq += (M + 1); /* interpolated LPC parameters for next subframe */
}
/*
* Update signal for next frame
* -> save past of exc[]
* -> save pitch parameters.
*/
memmove(st->mem_exc, &st->mem_exc[L_FRAME], (PIT_MAX + L_INTERPOL) * sizeof(Word16));
D_UTIL_signal_down_scale(exc, L_FRAME, Q_new);
D_DTX_activity_update(st->dtx_decSt, isf, exc);
st->dtx_decSt->mem_dtx_global_state = (UWord8)newDTXState;
st->mem_bfi = bfi;
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -