📄 pstfilt.cpp
字号:
This function performs the post-filtering on the synthesized speech. The post-filtering process is described as follows: (1) inverse filtering of syn[] through A(z/0.7) to get res2[] (2) tilt compensation filtering; 1 - MU*k*z^-1 (3) synthesis filtering through 1/A(z/0.75) (4) adaptive gain control------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pstfilt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint 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]; *-----------------------------------------------------* * 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] 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); if (temp2 <= 0) { temp2 = 0; } 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;}------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/void 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. */ Flag *pOverflow){ Word16 Ap3[MP1]; Word16 Ap4[MP1]; /* bandwidth expanded LP parameters */ Word16 *Az; /* pointer to Az_4: */ /* LPC parameters in each subframe */ register Word16 i_subfr; /* index for beginning of subframe */ Word16 h[L_H]; register Word16 i; Word16 temp1; Word16 temp2; Word32 L_tmp; Word32 L_tmp2; Word16 *syn_work = &st->synth_buf[M]; /*-----------------------------------------------------* * 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] */ if (mode == MR122 || mode == MR102) { 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); oscl_memset(&h[M + 1], 0, sizeof(Word16)*(L_H - M - 1)); Syn_filt(Ap4, h, h, L_H, &h[M + 1], 0); /* 1st correlation of h[] */ L_tmp = 0; for (i = L_H - 1; i >= 0; i--) { L_tmp2 = ((Word32) h[i]) * h[i]; if (L_tmp2 != (Word32) 0x40000000L) { L_tmp2 = L_tmp2 << 1; } else { *pOverflow = 1; L_tmp2 = MAX_32; break; } L_tmp = L_add(L_tmp, L_tmp2, pOverflow); } temp1 = (Word16)(L_tmp >> 16); L_tmp = 0; for (i = L_H - 2; i >= 0; i--) { L_tmp2 = ((Word32) h[i]) * h[i + 1]; if (L_tmp2 != (Word32) 0x40000000L) { L_tmp2 = L_tmp2 << 1; } else { *pOverflow = 1; L_tmp2 = MAX_32; break; } L_tmp = L_add(L_tmp, L_tmp2, pOverflow); } temp2 = (Word16)(L_tmp >> 16); if (temp2 <= 0) { temp2 = 0; } else { L_tmp = (((Word32) temp2) * MU) >> 15; /* Sign-extend product */ if (L_tmp & (Word32) 0x00010000L) { L_tmp = L_tmp | (Word32) 0xffff0000L; } temp2 = (Word16) L_tmp; temp2 = div_s(temp2, temp1); } preemphasis(&(st->preemph_state), st->res2, temp2, L_SUBFR, pOverflow); /* 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, pOverflow); Az += MP1; } /* update syn_work[] buffer */ Copy(&syn_work[L_FRAME - M], &syn_work[-M], M); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -