/* ************************************************************************** * Function: Post_Filter * Purpose: postfiltering of synthesis speech. * Description: * The postfiltering process is described as follows: * * - inverse filtering of syn[] through A(z/0.7) to get res2[] * - tilt compensation filtering; 1 - MU*k*z^-1 * - synthesis filtering through 1/A(z/0.75) * - adaptive gain control * ************************************************************************** */ int Post_Filter ( Post_FilterState *st, /* i/o : post filter states */ enum Mode mode, /* i : AMR mode */ Word16 *syn, /* i/o : synthesis speech (postfiltered is output) */ Word16 *Az_4 /* i : interpolated LPC parameters in all subfr. */ ) { /*-------------------------------------------------------------------* * Declaration of parameters * *-------------------------------------------------------------------*/ Word16 Ap3[MP1], Ap4[MP1]; /* bandwidth expanded LP parameters */ Word16 *Az; /* pointer to Az_4: */ /* LPC parameters in each subframe */ Word16 i_subfr; /* index for beginning of subframe */ Word16 h[L_H]; Word16 i; Word16 temp1, temp2; Word32 L_tmp; Word16 *syn_work = &st->synth_buf[M]; move16 (); /*-----------------------------------------------------* * Post filtering * *-----------------------------------------------------*/ Copy (syn, syn_work , L_FRAME); Az = Az_4; for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) { /* Find weighted filter coefficients Ap3[] and ap[4] */ test (); test (); if (sub(mode, MR122) == 0 || sub(mode, MR102) == 0) { Weight_Ai (Az, gamma3_MR122, Ap3); Weight_Ai (Az, gamma4_MR122, Ap4); } else { Weight_Ai (Az, gamma3, Ap3); Weight_Ai (Az, gamma4, Ap4); } /* filtering of synthesis speech by A(z/0.7) to find res2[] */ Residu (Ap3, &syn_work[i_subfr], st->res2, L_SUBFR); /* tilt compensation filter */ /* impulse response of A(z/0.7)/A(z/0.75) */ Copy (Ap3, h, M + 1); Set_zero (&h[M + 1], L_H - M - 1); Syn_filt (Ap4, h, h, L_H, &h[M + 1], 0); /* 1st correlation of h[] */ L_tmp = L_mult (h[0], h[0]); for (i = 1; i < L_H; i++) { L_tmp = L_mac (L_tmp, h[i], h[i]); } temp1 = extract_h (L_tmp); L_tmp = L_mult (h[0], h[1]); for (i = 1; i < L_H - 1; i++) { L_tmp = L_mac (L_tmp, h[i], h[i + 1]); } temp2 = extract_h (L_tmp); test (); if (temp2 <= 0) { temp2 = 0; move16 (); } else { temp2 = mult (temp2, MU); temp2 = div_s (temp2, temp1); } preemphasis (st->preemph_state, st->res2, temp2, L_SUBFR); /* filtering through 1/A(z/0.75) */ Syn_filt (Ap4, st->res2, &syn[i_subfr], L_SUBFR, st->mem_syn_pst, 1); /* scale output to input */ agc (st->agc_state, &syn_work[i_subfr], &syn[i_subfr], AGC_FAC, L_SUBFR); Az += MP1; } /* update syn_work[] buffer */ Copy (&syn_work[L_FRAME - M], &syn_work[-M], M); return 0; }
void Post_Filter( Word16 *syn, /* in/out: synthesis speech (postfiltered is output) */ Word16 *Az_4, /* input : interpolated LPC parameters in all subframes */ Word16 *T, /* input : decoded pitch lags in all subframes */ Word16 Vad ) { /*-------------------------------------------------------------------* * Declaration of parameters * *-------------------------------------------------------------------*/ Word16 res2_pst[L_SUBFR]; /* res2[] after pitch postfiltering */ Word16 syn_pst[L_FRAME]; /* post filtered synthesis speech */ Word16 Ap3[MP1], Ap4[MP1]; /* bandwidth expanded LP parameters */ Word16 *Az; /* pointer to Az_4: */ /* LPC parameters in each subframe */ Word16 t0_max, t0_min; /* closed-loop pitch search range */ Word16 i_subfr; /* index for beginning of subframe */ Word16 h[L_H]; Word16 i, j; Word16 temp1, temp2; Word32 L_tmp; postfilt_type* ppost_filt = pg729dec->ppost_filt; /*-----------------------------------------------------* * Post filtering * *-----------------------------------------------------*/ Az = Az_4; for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) { /* Find pitch range t0_min - t0_max */ t0_min = sub(*T++, 3); t0_max = add(t0_min, 6); if (sub(t0_max, PIT_MAX) > 0) { t0_max = PIT_MAX; t0_min = sub(t0_max, 6); } /* Find weighted filter coefficients Ap3[] and ap[4] */ Weight_Az(Az, GAMMA2_PST, M, Ap3); Weight_Az(Az, GAMMA1_PST, M, Ap4); /* filtering of synthesis speech by A(z/GAMMA2_PST) to find res2[] */ Residu(Ap3, &syn[i_subfr], ppost_filt->res2, L_SUBFR); /* scaling of "res2[]" to avoid energy overflow */ for (j=0; j<L_SUBFR; j++) { ppost_filt->scal_res2[j] = shr(ppost_filt->res2[j], 2); } /* pitch postfiltering */ if (sub(Vad, 1) == 0) pit_pst_filt(ppost_filt->res2, ppost_filt->scal_res2, t0_min, t0_max, L_SUBFR, res2_pst); else for (j=0; j<L_SUBFR; j++) res2_pst[j] = ppost_filt->res2[j]; /* tilt compensation filter */ /* impulse response of A(z/GAMMA2_PST)/A(z/GAMMA1_PST) */ Copy(Ap3, h, M+1); Set_zero(&h[M+1], L_H-M-1); Syn_filt(Ap4, h, h, L_H, &h[M+1], 0); /* 1st correlation of h[] */ L_tmp = L_mult(h[0], h[0]); for (i=1; i<L_H; i++) L_tmp = L_mac(L_tmp, h[i], h[i]); temp1 = extract_h(L_tmp); L_tmp = L_mult(h[0], h[1]); for (i=1; i<L_H-1; i++) L_tmp = L_mac(L_tmp, h[i], h[i+1]); temp2 = extract_h(L_tmp); if(temp2 <= 0) { temp2 = 0; } else { temp2 = mult(temp2, MU); temp2 = div_s(temp2, temp1); } preemphasis(res2_pst, temp2, L_SUBFR); /* filtering through 1/A(z/GAMMA1_PST) */ Syn_filt(Ap4, res2_pst, &syn_pst[i_subfr], L_SUBFR, ppost_filt->mem_syn_pst, 1); /* scale output to input */ agc(&syn[i_subfr], &syn_pst[i_subfr], L_SUBFR); /* update res2[] buffer; shift by L_SUBFR */ Copy(&ppost_filt->res2[L_SUBFR-PIT_MAX], &ppost_filt->res2[-PIT_MAX], PIT_MAX); Copy(&ppost_filt->scal_res2[L_SUBFR-PIT_MAX], &ppost_filt->scal_res2[-PIT_MAX], PIT_MAX); Az += MP1; } /* update syn[] buffer */ Copy(&syn[L_FRAME-M], &syn[-M], M); /* overwrite synthesis speech by postfiltered synthesis speech */ Copy(syn_pst, syn, L_FRAME); return; }
void Post_Filter ( INT16 *syn, /* in/out: synthesis speech (postfiltered is output) */ INT16 *Az_4 /* input: interpolated LPC parameters in all subframes */ ) { /*-------------------------------------------------------------------* * Declaration of parameters * *-------------------------------------------------------------------*/ INT16 syn_pst[L_FRAME]; /* post filtered synthesis speech */ INT16 Ap3[MP1], Ap4[MP1]; /* bandwidth expanded LP parameters */ INT16 *Az; /* pointer to Az_4: */ /* LPC parameters in each subframe */ INT16 i_subfr; /* index for beginning of subframe */ INT16 h[L_H]; INT16 i; INT16 temp1, temp2; //INT32 L_tmp; register INT32 tmp_hi=0; register UINT32 tmp_lo=0; VPP_EFR_PROFILE_FUNCTION_ENTER(Post_Filter); /*-----------------------------------------------------* * Post filtering * *-----------------------------------------------------*/ Az = Az_4; for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) { /* Find weighted filter coefficients Ap3[] and ap[4] */ Weight_Ai (Az, F_gamma3, Ap3); Weight_Ai (Az, F_gamma4, Ap4); /* filtering of synthesis speech by A(z/0.7) to find res2[] */ Residu (Ap3, &syn[i_subfr], res2, L_SUBFR); /* tilt compensation filter */ /* impulse response of A(z/0.7)/A(z/0.75) */ Copy (Ap3, h, M + 1); //Set_zero (&h[M + 1], L_H - M - 1); memset ((INT8*)&h[M + 1], 0, (L_H - M - 1)<<1); Syn_filt (Ap4, h, h, L_H, &h[M + 1], 0); /* 1st correlation of h[] */ //L_tmp = L_MULT(h[0], h[0]); VPP_MLX16(tmp_hi,tmp_lo, h[0], h[0]); for (i = 1; i < L_H; i++) { //L_tmp = L_MAC(L_tmp, h[i], h[i]); VPP_MLA16(tmp_hi,tmp_lo, h[i], h[i]); } //temp1 = extract_h (L_tmp); //temp1 = EXTRACT_H(VPP_SCALE64_TO_16(tmp_hi,tmp_lo)); temp1 = L_SHR_D((INT32)tmp_lo, 15); //L_tmp = L_MULT(h[0], h[1]); VPP_MLX16(tmp_hi,tmp_lo, h[0], h[1]); for (i = 1; i < L_H - 1; i++) { //L_tmp = L_MAC(L_tmp, h[i], h[i + 1]); VPP_MLA16(tmp_hi,tmp_lo, h[i], h[i + 1]); } //temp2 = extract_h (L_tmp); //temp2 = EXTRACT_H(VPP_SCALE64_TO_16(tmp_hi,tmp_lo)); temp2 = L_SHR_D((INT32)tmp_lo, 15); if (temp2 <= 0) { temp2 = 0; } else { //temp2 = mult (temp2, MU); temp2 = MULT(temp2, MU); temp2 = div_s (temp2, temp1); } preemphasis (res2, temp2, L_SUBFR); /* filtering through 1/A(z/0.75) */ Syn_filt (Ap4, res2, &syn_pst[i_subfr], L_SUBFR, mem_syn_pst, 1); /* scale output to input */ agc (&syn[i_subfr], &syn_pst[i_subfr], AGC_FAC, L_SUBFR); Az += MP1; } /* update syn[] buffer */ Copy (&syn[L_FRAME - M], &syn[-M], M); /* overwrite synthesis speech by postfiltered synthesis speech */ Copy (syn_pst, syn, L_FRAME); VPP_EFR_PROFILE_FUNCTION_EXIT(Post_Filter); return; }