FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/pstfilt.c @ 555:62943a1ad64e
doc/FR1-Rx-DTX-detail: grammar fix
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 11 Oct 2024 00:22:47 +0000 |
parents | 59655481e45b |
children |
rev | line source |
---|---|
401
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /************************************************************************* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * R99 Version 3.3.0 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * REL-4 Version 4.1.0 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * File : pstfilt.c |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * Purpose : Performs adaptive postfiltering on the synthesis |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * : speech |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * MODULE INCLUDE FILE AND VERSION ID |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "namespace.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "pstfilt.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 /* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 * INCLUDE FILES |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "tw_amr.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "typedef.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "basic_op.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "memops.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "weight_a.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "residu.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "syn_filt.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #include "preemph.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "no_count.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #include "cnst.h" |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 /* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 * LOCAL VARIABLES AND TABLES |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 /*---------------------------------------------------------------* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * Postfilter constant parameters (defined in "cnst.h") * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 *---------------------------------------------------------------* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 * L_FRAME : Frame size. * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * L_SUBFR : Sub-frame size. * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * M : LPC order. * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * MP1 : LPC order+1 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 * MU : Factor for tilt compensation filter * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 * AGC_FAC : Factor for automatic gain control * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 *---------------------------------------------------------------*/ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 #define L_H 22 /* size of truncated impulse response of A(z/g1)/A(z/g2) */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* Spectral expansion factors */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 static const Word16 gamma3_MR122[M] = { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 22938, 16057, 11240, 7868, 5508, |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 3856, 2699, 1889, 1322, 925 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 }; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 static const Word16 gamma3[M] = { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 18022, 9912, 5451, 2998, 1649, 907, 499, 274, 151, 83 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 }; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 static const Word16 gamma4_MR122[M] = { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 24576, 18432, 13824, 10368, 7776, |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 5832, 4374, 3281, 2461, 1846 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 }; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 static const Word16 gamma4[M] = { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 22938, 16057, 11240, 7868, 5508, 3856, 2699, 1889, 1322, 925 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 }; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 /* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 * PUBLIC PROGRAM CODE |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 ******************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 /************************************************************************* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 * Function: Post_Filter_reset |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 * Purpose: Initializes state memory to zero |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 ************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 void Post_Filter_reset (Post_FilterState *state) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 Set_zero (state->mem_syn_pst, M); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 Set_zero (state->res2, L_SUBFR); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 Set_zero (state->synth_buf, L_FRAME + M); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 agc_reset(&state->agc_state); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 preemphasis_reset(&state->preemph_state); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 /* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 ************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 * Function: Post_Filter |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 * Purpose: postfiltering of synthesis speech. |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 * Description: |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 * The postfiltering process is described as follows: |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 * - inverse filtering of syn[] through A(z/0.7) to get res2[] |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 * - tilt compensation filtering; 1 - MU*k*z^-1 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 * - synthesis filtering through 1/A(z/0.75) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 * - adaptive gain control |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 ************************************************************************** |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 int Post_Filter ( |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 Post_FilterState *st, /* i/o : post filter states */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 enum Mode mode, /* i : AMR mode */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 Word16 *syn, /* i/o : synthesis speech (postfiltered is output) */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 Word16 *Az_4 /* i : interpolated LPC parameters in all subfr. */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 ) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 /*-------------------------------------------------------------------* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 * Declaration of parameters * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 *-------------------------------------------------------------------*/ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 Word16 Ap3[MP1], Ap4[MP1]; /* bandwidth expanded LP parameters */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 Word16 *Az; /* pointer to Az_4: */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 /* LPC parameters in each subframe */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 Word16 i_subfr; /* index for beginning of subframe */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 Word16 h[L_H]; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 Word16 i; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 Word16 temp1, temp2; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 Word32 L_tmp; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 Word16 *syn_work = &st->synth_buf[M]; move16 (); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 /*-----------------------------------------------------* |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 * Post filtering * |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 *-----------------------------------------------------*/ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 Copy (syn, syn_work , L_FRAME); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 Az = Az_4; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 /* Find weighted filter coefficients Ap3[] and ap[4] */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 test (); test (); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 if (sub(mode, MR122) == 0 || sub(mode, MR102) == 0) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 Weight_Ai (Az, gamma3_MR122, Ap3); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 Weight_Ai (Az, gamma4_MR122, Ap4); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 else |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 Weight_Ai (Az, gamma3, Ap3); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 Weight_Ai (Az, gamma4, Ap4); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 /* filtering of synthesis speech by A(z/0.7) to find res2[] */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 Residu (Ap3, &syn_work[i_subfr], st->res2, L_SUBFR); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 /* tilt compensation filter */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 /* impulse response of A(z/0.7)/A(z/0.75) */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 Copy (Ap3, h, M + 1); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 Set_zero (&h[M + 1], L_H - M - 1); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 Syn_filt (Ap4, h, h, L_H, &h[M + 1], 0); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 /* 1st correlation of h[] */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 L_tmp = L_mult (h[0], h[0]); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 for (i = 1; i < L_H; i++) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 L_tmp = L_mac (L_tmp, h[i], h[i]); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 temp1 = extract_h (L_tmp); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 L_tmp = L_mult (h[0], h[1]); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 for (i = 1; i < L_H - 1; i++) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 L_tmp = L_mac (L_tmp, h[i], h[i + 1]); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 temp2 = extract_h (L_tmp); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 test (); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 if (temp2 <= 0) |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 temp2 = 0; move16 (); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 else |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 { |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 temp2 = mult (temp2, MU); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 temp2 = div_s (temp2, temp1); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 preemphasis (&st->preemph_state, st->res2, temp2, L_SUBFR); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 /* filtering through 1/A(z/0.75) */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 Syn_filt (Ap4, st->res2, &syn[i_subfr], L_SUBFR, st->mem_syn_pst, 1); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 /* scale output to input */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 agc (&st->agc_state, &syn_work[i_subfr], &syn[i_subfr], |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 AGC_FAC, L_SUBFR); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 Az += MP1; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 } |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 /* update syn_work[] buffer */ |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 Copy (&syn_work[L_FRAME - M], &syn_work[-M], M); |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 return 0; |
59655481e45b
libtwamr: integrate pstfilt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 } |