📄 g729ev_fec_ferenc.c
字号:
/* ITU-T G.729EV Optimization/Characterization Candidate *//* Version: 1.0.a *//* Revision Date: June 28, 2006 *//* ITU-T G.729EV Optimization/Characterization Candidate ANSI-C Source Code Copyright (c) 2006 France Telecom, Matsushita Electric, Mindspeed, Siemens AG, ETRI, VoiceAge Corp. All rights reserved*/#include <stdlib.h>#include <stdio.h>#include <time.h>#include "G729EV_MAIN_defines.h"#include "G729EV_MAIN_filt.h"#include "G729EV_G729_defines.h"#include "G729EV_FEC_fer.h"#include "G729EV_MAIN_OPER_32B.h"#include "G729EV_MAIN_DSPFUNC.h"#include "G729EV_TDAC_util.h"#include "G729EV_FEC_tools.h"#include "stl.h"/*---------------------------------------------------------------------** Prototypes *---------------------------------------------------------------------*/static Word16 G729EV_FEC_clas_enc(const Word16 clas);static Word16 G729EV_FEC_sig_clas(const Word16 old_clas, const Word16 voicing[6], const Word16 * speech, const Word16 pit[3], const Word16 * ee, const Word16 * sync_sp, const Word16 * synth, Word16 * lp_speech, Word16 * rel_hist, Word16 * rel_var);/******************************************************************************//* G729EV_FEC_encod : Decode FER informatio *//* - Find signal classification *//* - Find signal energy *//* - Find last glotal pulse postion *//******************************************************************************/void G729EV_FEC_encod(const Word16 old_clas, /* i: signal classification result from previous frames */ const Word16 * voicing, /* i: normalized correlation for 3 half-frames Q15 */ const Word16 * speech, /* i: pointer to denoised speech signal Q_new */ const Word16 * synth, /* i: pointer to synthesized speech for E computation Q_new */ const Word16 * T_op, /* i: close loop pitch values for 3 half-frames */ const Word16 * ee, /* i: lf/hf E ration for 2 half-frames Q14 */ const Word16 * sync_sp, /* i: time syncronised input speech Q_new */ Word16 * clas, /* o: signal clas for current frame */ Word16 * coder_parameters, /* o: coder_parameters */ const Word16 T0, /* i: close loop integer pitch */ const Word16 T0_frac, /* i: close loop fractional part of the pitch */ const Word16 * res, /* i: LP residual signal frame Q_new */ Word16 * lp_speech, /* i/o: LP speech energu Q8 */ Word16 * rel_hist, /* i/o: relative energy memory */ Word16 * rel_var, /* i/o: relative erergy variation */ Word16 * old_pos /* i/o: Position of the last pulse */ ){ Word16 tmpS; Word16 maxi, FER_pitch; Word16 index[3]; Word16 sign, exp_enrq, enr_lg_ent, enr_lg_frac; Word32 enr_q, Ltmp; Word16 *coder_param_ptr; coder_param_ptr = coder_parameters; sign = 0; enr_q = 0; FER_pitch = T_op[3];#if(WMOPS) move16(); move16(); move16(); move32();#endif /*------------------------------------------------------------------------* * Signal classification *-----------------------------------------------------------------*/ *clas = G729EV_FEC_sig_clas(old_clas, voicing, speech, T_op, ee, sync_sp, synth, lp_speech, rel_hist, rel_var); /*-----------------------------------------------------------------* * Speech energy information * - Maximum of energy per pitch period for G729EV_FEC_VOICED frames * - mean energy per sample over 2nd half of the frame for other * frames *-----------------------------------------------------------------*/ exp_enrq = G729EV_FEC_energy(*clas, synth, shr(add(shl(T0, G729EV_FEC_SQPIT), mult_r(shl(T0_frac, G729EV_FEC_SQPIT), 10922)), G729EV_FEC_SQPIT), &enr_q, G729EV_FEC_L_FRAME_FER); /*tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / 1.55 ); */ Log2(enr_q, &enr_lg_ent, &enr_lg_frac); enr_lg_ent = sub(enr_lg_ent, exp_enrq); IF(sub(*clas, G729EV_FEC_VOICED) < 0) /* Voiced current frame */ { Ltmp = L_sub(Mpy_32_16(enr_lg_ent, enr_lg_frac, G729EV_FEC_LG10_s1_55), G729EV_FEC_LG10_LFRAME_155); } ELSE { Ltmp = Mpy_32_16(enr_lg_ent, enr_lg_frac, G729EV_FEC_LG10_s1_55); } tmpS = extract_h(Ltmp); if (sub(tmpS, 31) >= 0) { tmpS = 31;#if(WMOPS) move16();#endif } if (tmpS < 0) { tmpS = (Word16) 0;#if(WMOPS) move16();#endif }#if(WMOPS) move16(); move16(); move16();#endif index[1] = tmpS; /*-----------------------------------------------------------------* * Signal classification encoding *-----------------------------------------------------------------*/ index[0] = G729EV_FEC_clas_enc(*clas); /*-----------------------------------------------------------------* * First pitch pulse position encoding * - Find first pitch pulse of current frame * - Encode first pitch pulse position *-----------------------------------------------------------------*/ maxi = (Word16) 0; IF(sub(*clas, G729EV_FEC_UNVOICED) > 0) { maxi = G729EV_FEC_findpulse(res, FER_pitch, 1); } if (sub(maxi, 160) > 0) { maxi = sub(maxi, 256); sign = (Word16) 1;#if(WMOPS) move16();#endif } if (sub(FER_pitch, 64) >= 0) { maxi = shr(maxi, 1); } if (sub(FER_pitch, 128) >= 0) { maxi = shr(maxi, 1); } if (sub(maxi, 64) > 0) { maxi = (Word16) 63; /* This should never happen... */#if(WMOPS) move16();#endif } if (sign) { maxi = add(maxi, 64); }#if(WMOPS) move16(); move16(); move16(); move16(); move16(); move16(); move16();#endif /* delay puls pos parameter */ tmpS = maxi; maxi = *old_pos; *old_pos = tmpS; index[2] = maxi;#if(WMOPS) move16(); move16(); move16();#endif *coder_param_ptr++ = index[2]; *coder_param_ptr++ = index[0]; *coder_param_ptr++ = index[1];}/******************************************************************************//* G729EV_FEC_sig_clas : Do signal classification *//* - Find realtive signal energy *//* - Find signal to noise ratio *//* - Find average voicing *//* - Compute the zero crossing rate *//* - Compute pitch stability *//* - Compute function of merit *//* - Find signal classification *//******************************************************************************/static Word16 G729EV_FEC_sig_clas( /* o: classification for current frames */ const Word16 old_clas, /* i: signal classification result from previous frames */ const Word16 voicing[], /* i: normalized correlation for 3 half-frames */ const Word16 * speech, /* i: pointer to speech signal for E computation */ const Word16 pit[], /* i: open loop pitch values for 3 half-frames */ const Word16 * ee, /* i: lf/hf E ration for 2 half-frames */ const Word16 * wsp, /* i: weighted speech */ const Word16 * wsyn, /* i: weighted synthesized signal */ Word16 * lp_speech, /* i/o: LP speech energu Q8 */ Word16 * last_relE, /* i/o: relative energy memory */ Word16 * relE_var /* i/o: relative erergy variation */ ){ Word16 i, pc, zc; Word16 clas, *pt_windfx, exp_et, frac_et, relE, Etot, tmp_mean, fmerit_fac; Word32 Ltmp, Ltmp1, Letot; Word32 Lsegen, Lnoiseen; Word16 tmp16, snr_val, exp_snr; Word16 mean_voi2, een, corn, zcn, relEn, pcn, snrn, fmerit1; Word16 exp_wsp, exp_noise, mant_noise, mant_wsp; Word16 var1, var2, var3; Word16 wsyn_scl[G729EV_FEC_L_FRAME_FER], wsp_scl[G729EV_FEC_L_FRAME_FER]; /*-----------------------------------------------------------------* * Signal classification preprocessing *-----------------------------------------------------------------*/#if(WMOPS) move16(); move32(); move32(); move32(); move32(); move32();#endif clas = (Word16) 0; /* Etot is the total energy over all the bandwith in dB */ Letot = 1; Ltmp1 = (Word32) 0; pt_windfx = (Word16 *) Sqrt_han_wind8k; /*Q13 */ FOR(i = 0; i < G729EV_FEC_L_FRAME_FER / 4; i++) { tmp16 = mult_r(speech[i], *pt_windfx++); /*Q14*Q13 ->Q12 */ Ltmp1 = L_mac(Ltmp1, tmp16, tmp16); /*Q12+Q12+6 */ } Letot = L_add(L_shr(Ltmp1, 2), Letot); Ltmp1 = (Word32) 0; FOR(; i < G729EV_FEC_L_FRAME_FER / 2; i++) { tmp16 = mult_r(speech[i], *pt_windfx++); Ltmp1 = L_mac(Ltmp1, tmp16, tmp16); } Letot = L_add(L_shr(Ltmp1, 2), Letot); Ltmp1 = (Word32) 0; FOR(; i < 3 * G729EV_FEC_L_FRAME_FER / 4; i++) { tmp16 = mult_r(speech[i], *pt_windfx--); Ltmp1 = L_mac(Ltmp1, tmp16, tmp16); } Letot = L_add(L_shr(Ltmp1, 2), Letot); Ltmp1 = (Word32) 0; FOR(; i < G729EV_FEC_L_FRAME_FER; i++) { tmp16 = mult_r(speech[i], *pt_windfx--); Ltmp1 = L_mac(Ltmp1, tmp16, tmp16); } Letot = L_add(L_shr(Ltmp1, 2), Letot); /* Q_speech - 6 */#if(WMOSP) move16(); move16();#endif Log2(Letot, &exp_et, &frac_et); exp_et = sub(exp_et, -7); /*sub(shl(-1,1),5) */ Ltmp = L_sub(Mpy_32_16(exp_et, frac_et, G729EV_FEC_LG10), G729EV_FEC_LG10_LFRAME); /*Ltmp Q14 */ Etot = round(L_shl(Ltmp, 10)); relE = sub(Etot, *lp_speech); /* Q8 */ /*-----------------------------------------------------------------* * Signal classification preprocessing *-----------------------------------------------------------------*/ /* Compute the SNR */ Ltmp = (Word32) 0; Overflow = 0;#if(WMOPS) move32(); move16();#endif FOR(i = 0; i < G729EV_FEC_L_FRAME_FER; i++) { Ltmp = L_mac(Ltmp, wsp[i], wsp[i]); } IF(Overflow) { FOR(i = 0; i < G729EV_FEC_L_FRAME_FER; i++) { wsyn_scl[i] = shr(wsyn[i], 2); wsp_scl[i] = shr(wsp[i], 2);#if(WMOPS) move16(); move16();#endif } } ELSE { FOR(i = 0; i < G729EV_FEC_L_FRAME_FER; i++) { wsyn_scl[i] = wsyn[i]; wsp_scl[i] = wsp[i];#if(WMOPS) move16(); move16();#endif } }#if(WMOPS) move32(); move32();#endif Lsegen = (Word32) 0; Lnoiseen = (Word32) 0; FOR(i = 0; i < G729EV_FEC_L_FRAME_FER; i++) { Lsegen = L_mac(Lsegen, wsp_scl[i], wsp_scl[i]); tmp16 = sub(wsp_scl[i], wsyn_scl[i]); /* ajust scaling between signals */ Lnoiseen = L_mac(Lnoiseen, tmp16, tmp16); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -