Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdint.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "prot_fx.h"
8 : #include "wmc_auto.h"
9 :
10 : /*-------------------------------------------------------------*
11 : * preemph_copy_fx()
12 : *
13 : * Preemphasis: filtering through 1 - mu z^-1
14 : *-------------------------------------------------------------*/
15 :
16 3773199 : void preemph_copy_fx(
17 : const Word16 x[], /* i : input signal Qx */
18 : Word16 y[], /* o : output signal Qx */
19 : const Word16 mu, /* i : preemphasis coefficient Q15 */
20 : const Word16 lg, /* i : vector size Q0 */
21 : Word16 *mem /* i/o: memory (x[-1]) Qx */
22 : )
23 : {
24 : Word16 i, temp;
25 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
26 3773199 : Flag Overflow = 0;
27 3773199 : move32();
28 : #endif
29 3773199 : temp = x[lg - 1]; /* Qx */
30 3773199 : move16();
31 344782078 : FOR( i = lg - 1; i > 0; i-- )
32 : {
33 341008879 : y[i] = msu_ro( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); /* Qx */
34 341008879 : move16();
35 : }
36 3773199 : y[0] = msu_ro( L_deposit_h( x[0] ), *mem, mu, &Overflow ); /* Qx */
37 3773199 : move16();
38 :
39 3773199 : *mem = temp; /* Qx */
40 3773199 : move16();
41 3773199 : }
42 :
43 2840432 : void preemph_copy_32fx(
44 : const Word16 x[], /* i : input signal Qx */
45 : Word32 y[], /* o : output signal Qx */
46 : const Word16 mu, /* i : preemphasis coefficient Q15 */
47 : const Word16 lg, /* i : vector size Q0 */
48 : Word16 *mem /* i/o: memory (x[-1]) Qx */
49 : )
50 : {
51 : Word16 i, temp;
52 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
53 2840432 : Flag Overflow = 0;
54 2840432 : move32();
55 : #endif
56 2840432 : temp = x[lg - 1]; /* Qx */
57 2840432 : move16();
58 482713655 : FOR( i = lg - 1; i > 0; i-- )
59 : {
60 479873223 : y[i] = L_msu_o( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); /* Qx+16 */
61 479873223 : move16();
62 : }
63 2840432 : y[0] = L_msu_o( L_deposit_h( x[0] ), *mem, mu, &Overflow ); /* Qx+16 */
64 2840432 : move16();
65 :
66 2840432 : *mem = temp; /* Qx */
67 2840432 : move16();
68 2840432 : }
69 :
70 : /*-------------------------------------------------------------*
71 : * preemph_ivas_fx()
72 : *
73 : * Preemphasis: filtering through 1 - mu z^-1
74 : *-------------------------------------------------------------*/
75 :
76 63461 : void preemph_ivas_fx(
77 : Word32 *signal, /* i/o: signal Qx*/
78 : const Word16 mu, /* i : preemphasis factor Q15*/
79 : const Word16 L, /* i : vector size Q0*/
80 : Word32 *mem /* i/o: memory (x[-1]) Qx*/
81 : )
82 : {
83 : Word16 i;
84 : Word32 temp;
85 :
86 63461 : temp = signal[L - 1]; /* Qx */
87 63461 : move32();
88 19183312 : FOR( i = L - 1; i > 0; i-- )
89 : {
90 19119851 : signal[i] = L_sub( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); /* Qx */
91 19119851 : move32();
92 : }
93 :
94 63461 : signal[0] = L_sub( signal[0], Mpy_32_16_1( *mem, mu ) ); /* Qx */
95 63461 : move32();
96 63461 : *mem = temp; /* Qx */
97 63461 : move32();
98 :
99 63461 : return;
100 : }
101 :
102 : /*
103 : * E_UTIL_f_preemph2
104 : *
105 : * Parameters:
106 : * shift I: scale output
107 : * signal I/O: signal Qx/Qx+shift
108 : * mu I: preemphasis factor Q15
109 : * L I: vector size
110 : * mem I/O: memory (x[-1])
111 : *
112 : * Function:
113 : * Filtering through 1 - mu z^-1
114 : *
115 : * Returns:
116 : * void
117 : */
118 902715 : void E_UTIL_f_preemph2(
119 : Word16 shift, /* Q0 */
120 : Word16 *signal, /* Qx */
121 : const Word16 mu, /* Q15 */
122 : const Word16 lg, /* Q0 */
123 : Word16 *mem /* Qx */
124 : )
125 : {
126 : Word16 i, temp;
127 : Word32 L_tmp;
128 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
129 902715 : Flag Overflow = 0;
130 902715 : move32();
131 : #endif
132 902715 : temp = signal[lg - 1]; /* Qx */
133 902715 : move16();
134 :
135 483405488 : FOR( i = lg - 1; i > 0; i-- )
136 : {
137 482502773 : L_tmp = L_mult( signal[i], 16384 ); /* Qx + 15 */
138 482502773 : L_tmp = L_msu0_o( L_tmp, signal[i - 1], mu, &Overflow ); /* Qx + 15 */
139 482502773 : L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); /* Qx + shift + 16 */
140 482502773 : signal[i] = round_fx_o( L_tmp, &Overflow ); /* Qx + shift */
141 482502773 : move16();
142 : }
143 :
144 902715 : L_tmp = L_mult( signal[0], 16384 ); /* Qx + 15 */
145 902715 : L_tmp = L_msu0_o( L_tmp, *mem, mu, &Overflow ); /* Qx + 15 */
146 902715 : L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); /* Qx + shift + 16 */
147 902715 : signal[0] = round_fx_o( L_tmp, &Overflow ); /* Qx + shift */
148 902715 : move16();
149 :
150 902715 : *mem = temp; /* Qx */
151 902715 : move16();
152 :
153 902715 : return;
154 : }
155 :
156 :
157 215889 : Word16 E_UTIL_f_preemph3(
158 : Word16 *signal, /* Qx */
159 : const Word16 mu, /* Q15 */
160 : const Word16 lg, /* Q0 */
161 : Word16 *mem, /* Qx */
162 : Word16 bits /* Q0 */
163 : )
164 : {
165 : Word16 i, QVal, mus, tmp_fixed, Q_new;
166 : Word32 L_tmp, L_maxloc;
167 :
168 :
169 215889 : QVal = shl( 1, sub( 15, bits ) ); /* Q15 - bits */
170 215889 : mus = shr( mu, bits ); /* Q15 - bits */
171 :
172 215889 : L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
173 215889 : L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
174 215889 : L_maxloc = L_abs( L_tmp );
175 :
176 101749497 : FOR( i = 1; i < lg; i++ )
177 : {
178 101533608 : L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */
179 101533608 : L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
180 101533608 : L_tmp = L_abs( L_tmp );
181 101533608 : L_maxloc = L_max( L_tmp, L_maxloc );
182 : }
183 :
184 215889 : tmp_fixed = extract_h( L_maxloc ); /* Qx - bits */
185 :
186 215889 : Q_new = Q_MAX;
187 215889 : move16();
188 215889 : IF( tmp_fixed != 0 )
189 : {
190 215122 : Q_new = sub( norm_s( tmp_fixed ), bits );
191 215122 : Q_new = s_max( Q_new, 0 );
192 215122 : Q_new = s_min( Q_new, Q_MAX );
193 : }
194 :
195 215889 : tmp_fixed = signal[lg - 1]; /* Qx */
196 215889 : move16();
197 :
198 101749497 : FOR( i = lg - 1; i > 0; i-- )
199 : {
200 101533608 : L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */
201 101533608 : L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
202 101533608 : L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q16 + Q_new - bits */
203 101533608 : signal[i] = round_fx( L_tmp ); /* Qx + Q_new - bits */
204 101533608 : move16();
205 : }
206 :
207 215889 : L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
208 215889 : L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
209 215889 : L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q16 + Q_new - bits */
210 215889 : signal[0] = round_fx( L_tmp ); /* Qx + Q_new - bits */
211 215889 : move16();
212 215889 : *mem = tmp_fixed;
213 215889 : move16();
214 :
215 215889 : return Q_new;
216 : }
217 :
218 3434 : Word16 E_UTIL_f_preemph3_ivas_fx(
219 : Word16 *signal, /* Qx */
220 : const Word16 mu, /* Q15 */
221 : const Word16 lg, /* Q0 */
222 : Word16 *mem, /* Qx */
223 : Word16 bits /* Q0 */
224 : )
225 : {
226 : Word16 i, QVal, mus, tmp_fixed, Q_new;
227 : Word32 L_tmp, L_maxloc;
228 :
229 :
230 3434 : QVal = shl( 1, sub( 15, bits ) ); /* Q15 - bits */
231 3434 : mus = shr( mu, bits ); /* Q15 - bits */
232 :
233 3434 : L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
234 3434 : L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
235 3434 : L_maxloc = L_abs( L_tmp );
236 :
237 2794047 : FOR( i = 1; i < lg; i++ )
238 : {
239 2790613 : L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */
240 2790613 : L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
241 2790613 : L_tmp = L_abs( L_tmp );
242 2790613 : L_maxloc = L_max( L_tmp, L_maxloc );
243 : }
244 :
245 3434 : tmp_fixed = extract_h( L_maxloc ); /* Qx - bits */
246 :
247 3434 : Q_new = Q_MAX;
248 3434 : move16();
249 3434 : IF( tmp_fixed != 0 )
250 : {
251 2755 : Q_new = sub( norm_s( tmp_fixed ), bits );
252 2755 : Q_new = s_max( Q_new, 0 );
253 2755 : Q_new = sub( s_min( Q_new, Q_MAX ), 1 );
254 : }
255 :
256 3434 : tmp_fixed = signal[lg - 1];
257 3434 : move16();
258 :
259 2794047 : FOR( i = sub( lg, 1 ); i > 0; i-- )
260 : {
261 2790613 : L_tmp = L_mult( signal[i], QVal ); /* Qx + Q16 - bits */
262 2790613 : L_tmp = L_msu( L_tmp, signal[i - 1], mus ); /* Qx + Q16 - bits */
263 2790613 : L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q16 + Q_new - bits */
264 2790613 : signal[i] = round_fx( L_tmp ); /* Qx + Q_new - bits */
265 2790613 : move16();
266 : }
267 :
268 3434 : L_tmp = L_mult( signal[0], QVal ); /* Qx + Q16 - bits */
269 3434 : L_tmp = L_msu( L_tmp, *mem, mus ); /* Qx + Q16 - bits */
270 3434 : L_tmp = L_shl( L_tmp, Q_new ); /* Qx + Q_new + Q16 - bits */
271 3434 : signal[0] = round_fx( L_tmp ); /* Qx + Q_new - bits */
272 3434 : move16();
273 3434 : *mem = tmp_fixed;
274 3434 : move16();
275 :
276 3434 : return Q_new;
277 : }
|