comparison libgsmefr/pstfilt2.c @ 53:49dd1ac8e75b

libgsmefr: import most *.c files from ETSI source
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 16:18:21 +0000
parents
children 41d8e8f4058d
comparison
equal deleted inserted replaced
52:988fd7ff514f 53:49dd1ac8e75b
1 /*************************************************************************
2 *
3 * FILE NAME: pstfilt2.c
4 *
5 * Performs adaptive postfiltering on the synthesis speech
6 *
7 * FUNCTIONS INCLUDED: Init_Post_Filter() and Post_Filter()
8 *
9 *************************************************************************/
10
11 #include "typedef.h"
12 #include "basic_op.h"
13 #include "sig_proc.h"
14 #include "count.h"
15 #include "codec.h"
16 #include "cnst.h"
17
18 /*---------------------------------------------------------------*
19 * Postfilter constant parameters (defined in "cnst.h") *
20 *---------------------------------------------------------------*
21 * L_FRAME : Frame size. *
22 * L_SUBFR : Sub-frame size. *
23 * M : LPC order. *
24 * MP1 : LPC order+1 *
25 * MU : Factor for tilt compensation filter *
26 * AGC_FAC : Factor for automatic gain control *
27 *---------------------------------------------------------------*/
28
29 #define L_H 22 /* size of truncated impulse response of A(z/g1)/A(z/g2) */
30
31 /*------------------------------------------------------------*
32 * static vectors *
33 *------------------------------------------------------------*/
34
35 /* inverse filtered synthesis */
36
37 static Word16 res2[L_SUBFR];
38
39 /* memory of filter 1/A(z/0.75) */
40
41 static Word16 mem_syn_pst[M];
42
43 /* Spectral expansion factors */
44
45 const Word16 F_gamma3[M] =
46 {
47 22938, 16057, 11240, 7868, 5508,
48 3856, 2699, 1889, 1322, 925
49 };
50 const Word16 F_gamma4[M] =
51 {
52 24576, 18432, 13824, 10368, 7776,
53 5832, 4374, 3281, 2461, 1846
54 };
55
56 /*************************************************************************
57 *
58 * FUNCTION: Init_Post_Filter
59 *
60 * PURPOSE: Initializes the postfilter parameters.
61 *
62 *************************************************************************/
63
64 void Init_Post_Filter (void)
65 {
66 Set_zero (mem_syn_pst, M);
67
68 Set_zero (res2, L_SUBFR);
69
70 return;
71 }
72
73 /*************************************************************************
74 * FUNCTION: Post_Filter()
75 *
76 * PURPOSE: postfiltering of synthesis speech.
77 *
78 * DESCRIPTION:
79 * The postfiltering process is described as follows:
80 *
81 * - inverse filtering of syn[] through A(z/0.7) to get res2[]
82 * - tilt compensation filtering; 1 - MU*k*z^-1
83 * - synthesis filtering through 1/A(z/0.75)
84 * - adaptive gain control
85 *
86 *************************************************************************/
87
88 void Post_Filter (
89 Word16 *syn, /* in/out: synthesis speech (postfiltered is output) */
90 Word16 *Az_4 /* input: interpolated LPC parameters in all subframes */
91 )
92 {
93 /*-------------------------------------------------------------------*
94 * Declaration of parameters *
95 *-------------------------------------------------------------------*/
96
97 Word16 syn_pst[L_FRAME]; /* post filtered synthesis speech */
98 Word16 Ap3[MP1], Ap4[MP1]; /* bandwidth expanded LP parameters */
99 Word16 *Az; /* pointer to Az_4: */
100 /* LPC parameters in each subframe */
101 Word16 i_subfr; /* index for beginning of subframe */
102 Word16 h[L_H];
103
104 Word16 i;
105 Word16 temp1, temp2;
106 Word32 L_tmp;
107
108 /*-----------------------------------------------------*
109 * Post filtering *
110 *-----------------------------------------------------*/
111
112 Az = Az_4;
113
114 for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
115 {
116 /* Find weighted filter coefficients Ap3[] and ap[4] */
117
118 Weight_Ai (Az, F_gamma3, Ap3);
119 Weight_Ai (Az, F_gamma4, Ap4);
120
121 /* filtering of synthesis speech by A(z/0.7) to find res2[] */
122
123 Residu (Ap3, &syn[i_subfr], res2, L_SUBFR);
124
125 /* tilt compensation filter */
126
127 /* impulse response of A(z/0.7)/A(z/0.75) */
128
129 Copy (Ap3, h, M + 1);
130 Set_zero (&h[M + 1], L_H - M - 1);
131 Syn_filt (Ap4, h, h, L_H, &h[M + 1], 0);
132
133 /* 1st correlation of h[] */
134
135 L_tmp = L_mult (h[0], h[0]);
136 for (i = 1; i < L_H; i++)
137 {
138 L_tmp = L_mac (L_tmp, h[i], h[i]);
139 }
140 temp1 = extract_h (L_tmp);
141
142 L_tmp = L_mult (h[0], h[1]);
143 for (i = 1; i < L_H - 1; i++)
144 {
145 L_tmp = L_mac (L_tmp, h[i], h[i + 1]);
146 }
147 temp2 = extract_h (L_tmp);
148
149 test ();
150 if (temp2 <= 0)
151 {
152 temp2 = 0; move16 ();
153 }
154 else
155 {
156 temp2 = mult (temp2, MU);
157 temp2 = div_s (temp2, temp1);
158 }
159
160 preemphasis (res2, temp2, L_SUBFR);
161
162 /* filtering through 1/A(z/0.75) */
163
164 Syn_filt (Ap4, res2, &syn_pst[i_subfr], L_SUBFR, mem_syn_pst, 1);
165
166 /* scale output to input */
167
168 agc (&syn[i_subfr], &syn_pst[i_subfr], AGC_FAC, L_SUBFR);
169
170 Az += MP1;
171 }
172
173 /* update syn[] buffer */
174
175 Copy (&syn[L_FRAME - M], &syn[-M], M);
176
177 /* overwrite synthesis speech by postfiltered synthesis speech */
178
179 Copy (syn_pst, syn, L_FRAME);
180
181 return;
182 }