Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <stdint.h>
34 : #include "options.h"
35 : #include "prot_fx.h"
36 : #include "oper_32b.h"
37 : #include "move.h"
38 :
39 : /*--------------------------------------------------------------------------*
40 : * hq2_noise_inject()
41 : *
42 : * HQ2 noise injection for WB signals
43 : *--------------------------------------------------------------------------*/
44 78 : void hq2_noise_inject_fx(
45 : Word32 L_y2[], /* Q12 */
46 : const Word16 band_start[], /* Q0 */
47 : const Word16 band_end[], /* Q0 */
48 : const Word16 band_width[], /* Q0 */
49 : Word32 Ep_fx[], /* Q-6 */
50 : Word32 Rk_fx[], /* QRk (Q16) */
51 : const Word16 npulses[], /* Q0 */
52 : Word16 ni_seed, /* Q0 */
53 : const Word16 bands, /* Q0 */
54 : const Word16 ni_start_band, /* Q0 */
55 : const Word16 bw_low, /* Q0 */
56 : const Word16 bw_high, /* Q0 */
57 : const Word32 enerL_fx, /* Q0 */
58 : const Word32 enerH_fx, /* Q0 */
59 : Word32 last_ni_gain_fx[], /* Q17 */
60 : Word16 last_env_fx[], /* Q1 */
61 : Word16 *last_max_pos_pulse, /* Q0 */
62 : Word16 *p2a_flags, /* Q0 */
63 : Word16 p2a_bands, /* Q0 */
64 : const Word16 hqswb_clas, /* Q0 */
65 : const Word16 bwidth, /* Q0 */
66 : const Word32 bwe_br /* Q0 */
67 : )
68 : {
69 : Word32 L_tmp, L_tmp2, L_tmp2x, L_tmp3, L_tmp1;
70 : Word16 exp, exp2, Q_speech;
71 : Word16 pd_fx[BANDS_MAX], rand_fx, peak_fx[BANDS_MAX], fac_fx;
72 :
73 : Word16 tmp, tmpx, tmp1, tmp2, tmp3, tmp4, Q_env_fx[BANDS_MAX], Q_Ep_fx[BANDS_MAX];
74 :
75 78 : Word16 Qs = SWB_BWE_LR_Qs;
76 : Word32 env_fx[BANDS_MAX];
77 : Word16 env_fx2[BANDS_MAX];
78 : Word32 ni_gain_fx[BANDS_MAX];
79 : Word16 y2hat_fx[L_FRAME48k];
80 :
81 : Word16 i, j, k, ni_end_band, satur, count[BANDS_MAX], max_pos_pulse, pos;
82 78 : Word16 sb = bands;
83 : #ifndef ISSUE_1836_replace_overflow_libcom
84 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
85 : Flag Overflow = 0;
86 : move16();
87 : #endif
88 : #endif
89 :
90 78 : satur = 0;
91 78 : move16();
92 :
93 1814 : FOR( i = 0; i < bands; i++ )
94 : {
95 : #ifdef ISSUE_1836_replace_overflow_libcom
96 1736 : Ep_fx[i] = L_shl_sat( Ep_fx[i], 6 ); /* Q-6 -> Q0 */
97 : #else
98 : Ep_fx[i] = L_shl_o( Ep_fx[i], 6, &Overflow ); /* Q-6 -> Q0 */
99 : #endif
100 1736 : move32();
101 : }
102 :
103 78 : tmp = add( band_end[bands - 1], 1 );
104 44382 : FOR( k = 0; k < tmp; k++ )
105 : {
106 44304 : y2hat_fx[k] = (Word16) L_min( L_max( L_shr( L_y2[k], Qs ), -32768 ), 32767 );
107 44304 : move16(); /* Extract_l or something else is missing here */
108 : }
109 :
110 78 : test();
111 78 : test();
112 78 : test();
113 78 : test();
114 78 : IF( ( EQ_16( hqswb_clas, HQ_HARMONIC ) || hqswb_clas == HQ_NORMAL ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) && EQ_16( bwidth, SWB ) )
115 : {
116 76 : sb = 17;
117 76 : move16();
118 76 : if ( EQ_32( bwe_br, HQ_16k40 ) )
119 : {
120 0 : sb = 19;
121 0 : move16();
122 : }
123 : }
124 :
125 : /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */
126 78 : ni_end_band = bands;
127 78 : max_pos_pulse = bands;
128 1814 : FOR( k = ni_start_band; k < ni_end_band; k++ )
129 : {
130 1736 : tmp = div_s( 1, band_width[k] ); /*Q15 */
131 1736 : L_tmp = Mult_32_16( Rk_fx[k], tmp ); /*Q(16+15-15=16) */
132 1736 : pd_fx[k] = extract_h( L_shl( L_tmp, 10 ) ); /*16+10-16 =Q10 */
133 :
134 1736 : L_tmp2 = Ep_fx[k]; /*Q0 */
135 1736 : move32();
136 1736 : L_tmp = L_max( 1, L_tmp2 );
137 1736 : exp = norm_l( L_tmp );
138 1736 : tmp = extract_h( L_shl( L_tmp, exp ) );
139 :
140 1736 : L_tmp3 = (Word32) band_width[k]; /* Q0 */
141 1736 : move32();
142 1736 : exp2 = norm_l( L_tmp3 );
143 1736 : tmp2 = extract_h( L_shl( L_tmp3, exp2 ) );
144 :
145 1736 : exp2 = sub( exp, exp2 ); /* Denormalize and substract */
146 :
147 1736 : tmp3 = sub( tmp2, tmp );
148 1736 : if ( tmp3 > 0 )
149 : {
150 780 : tmp2 = shr( tmp2, 1 );
151 : }
152 1736 : if ( tmp3 > 0 )
153 : {
154 780 : exp2 = add( exp2, 1 );
155 : }
156 1736 : tmp = div_s( tmp2, tmp ); /* Q15 */
157 1736 : L_tmp = L_deposit_h( tmp ); /* Q31 */
158 1736 : L_tmp = Isqrt_lc( L_tmp, &exp2 );
159 1736 : env_fx[k] = L_tmp;
160 1736 : move32(); /*Q(31-exp2) move32(); */
161 1736 : Q_env_fx[k] = sub( 31, exp2 );
162 1736 : move16();
163 1736 : tmp = sub( 17, Q_env_fx[k] );
164 : #ifdef ISSUE_1836_replace_overflow_libcom
165 1736 : env_fx2[k] = extract_h( L_shl_sat( env_fx[k], tmp ) ); /*Q1 */
166 : #else
167 : env_fx2[k] = extract_h( L_shl_o( env_fx[k], tmp, &Overflow ) ); /*Q1 */
168 : #endif
169 1736 : peak_fx[k] = 0;
170 1736 : move16();
171 1736 : count[k] = 0;
172 1736 : move16();
173 :
174 1736 : IF( npulses[k] != 0 )
175 : {
176 18356 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
177 : {
178 17134 : L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /* Q0 */
179 : #ifdef ISSUE_1836_replace_overflow_libcom
180 17134 : Ep_fx[k] = L_sub_sat( Ep_fx[k], L_tmp );
181 : #else
182 : Ep_fx[k] = L_sub_o( Ep_fx[k], L_tmp, &Overflow );
183 : #endif
184 17134 : move32(); /* Q0 */
185 17134 : IF( GT_16( abs_s( y2hat_fx[i] ), peak_fx[k] ) )
186 : {
187 1476 : peak_fx[k] = abs_s( y2hat_fx[i] );
188 1476 : move16(); /* Q0 */
189 : }
190 :
191 17134 : IF( y2hat_fx[i] != 0 )
192 : {
193 2182 : count[k] = add( count[k], 1 ); /* Q0 */
194 2182 : move16();
195 : }
196 : }
197 :
198 1222 : max_pos_pulse = k; /* Q0 */
199 1222 : move16();
200 1222 : L_tmp2 = Ep_fx[k]; /* Q0 */
201 1222 : move32();
202 1222 : L_tmp = L_max( 1, L_tmp2 );
203 1222 : exp = norm_l( L_tmp );
204 1222 : tmp = extract_h( L_shl( L_tmp, exp ) );
205 :
206 1222 : L_tmp3 = (Word32) band_width[k]; /* Q0 */
207 1222 : exp2 = norm_l( L_tmp3 );
208 1222 : tmp2 = extract_h( L_shl( L_tmp3, exp2 ) );
209 :
210 1222 : exp2 = sub( exp, exp2 ); /* Denormalize and substract */
211 :
212 1222 : tmp3 = sub( tmp2, tmp );
213 1222 : if ( tmp3 > 0 )
214 : {
215 720 : tmp2 = shr( tmp2, 1 );
216 : }
217 1222 : if ( tmp3 > 0 )
218 : {
219 720 : exp2 = add( exp2, 1 );
220 : }
221 1222 : tmp = div_s( tmp2, tmp ); /* Q15 */
222 1222 : L_tmp = L_deposit_h( tmp ); /* Q31 */
223 1222 : L_tmp = Isqrt_lc( L_tmp, &exp2 );
224 1222 : Ep_fx[k] = L_tmp;
225 1222 : move32(); /*Q(31-exp2) */
226 1222 : Q_Ep_fx[k] = sub( 31, exp2 );
227 1222 : move16();
228 : }
229 : ELSE
230 : {
231 514 : Ep_fx[k] = env_fx[k];
232 514 : move32(); /*Q(Q_env_fx[k]) */
233 514 : Q_Ep_fx[k] = Q_env_fx[k];
234 514 : move16(); /*31-exp2 */
235 : }
236 : }
237 :
238 1814 : FOR( k = ni_start_band; k < ni_end_band; k++ )
239 : {
240 : /* calculate the noise gain */
241 1736 : satur = 0;
242 1736 : move16();
243 1736 : if ( GE_16( pd_fx[k], 819 /* 0.8 in Q10 */ ) )
244 : {
245 578 : satur = 1; /* Q0 */
246 578 : move16();
247 : }
248 :
249 1736 : test();
250 1736 : IF( satur == 0 && Ep_fx[k] > 0 )
251 : {
252 1158 : IF( npulses[k] != 0 )
253 : {
254 644 : IF( EQ_16( bwidth, SWB ) )
255 : {
256 644 : IF( NE_16( hqswb_clas, HQ_TRANSIENT ) )
257 : {
258 628 : IF( peak_fx[k] != 0 )
259 : {
260 608 : Q_speech = norm_s( peak_fx[k] );
261 608 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
262 608 : tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */
263 : }
264 : ELSE
265 : {
266 20 : tmp = 0x7fff; /* 1 in Q15 */
267 20 : move16();
268 20 : Q_speech = 0;
269 20 : move16();
270 : }
271 628 : L_tmp2x = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */
272 628 : tmp = sub( Q_Ep_fx[k], Q_speech );
273 628 : tmpx = add( tmp, 1 );
274 628 : tmp2 = extract_l( L_shr( L_tmp2x, s_min( tmpx, 31 ) ) ); /*Q13 Ep[k]/peak[k] */
275 :
276 628 : IF( EQ_16( hqswb_clas, HQ_HARMONIC ) )
277 : {
278 0 : tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */
279 0 : tmp3 = shl( tmp, 4 ); /*Q14 */
280 0 : L_tmp = Mult_32_16( env_fx[k], tmp3 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */
281 0 : L_tmp = Mult_32_16( L_tmp, 6144 /* 6.0f in Q10 */ ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */
282 :
283 0 : IF( peak_fx[k] != 0 )
284 : {
285 0 : Q_speech = norm_s( peak_fx[k] );
286 0 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
287 0 : tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */
288 : }
289 : ELSE
290 : {
291 0 : tmp = 0x7fff; /* 1 in Q15 */
292 0 : move16();
293 0 : Q_speech = 0;
294 0 : move16();
295 : }
296 :
297 0 : L_tmp2 = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */
298 0 : L_tmp3 = Mult_32_16( L_tmp, tmp ); /* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */
299 0 : L_tmp = Mult_32_32( L_tmp2, L_tmp3 ); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */
300 :
301 0 : tmp = add( Q_Ep_fx[k], Q_env_fx[k] );
302 0 : tmp = sub( tmp, Q_speech );
303 0 : tmp = sub( tmp, Q_speech );
304 0 : tmp = sub( 37, tmp );
305 0 : tmp1 = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 //6.0f*(1.5f - pd[k])*env[k]*Ep[k]/(peak[k]*peak[k]) */
306 :
307 0 : fac_fx = tmp1;
308 0 : move16(); /*Q12 */
309 0 : if ( GT_16( k, sb ) )
310 : {
311 0 : fac_fx = mult( 24576 /* 1.5 in Q14 */, tmp2 ); /*//Q(14+13-15=12) */
312 : }
313 : }
314 : ELSE
315 : {
316 628 : IF( LE_16( k, sb ) )
317 : {
318 606 : tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */
319 606 : tmp3 = shl( tmp, 4 ); /*Q14 */
320 606 : L_tmp = Mult_32_16( L_tmp2x, tmp3 ); /*Q(Q_Ep_fx[k]-Q_speech+14+14-15 = Q_Ep_fx[k]-Q_speech+13) */
321 606 : L_tmp = Mult_32_16( L_tmp, 20480 /* 5 in Q12 */ ); /*Q(Q_Ep_fx[k]-Q_speech+13+12-15 = Q_Ep_fx[k]-Q_speech+10) */
322 606 : fac_fx = extract_h( L_shl( L_tmp, sub( add( 18, Q_speech ), Q_Ep_fx[k] ) ) ); /*Q_Ep_fx[k]-Q_speech+10 +18+Q_speech-Q_Ep_fx[k] -16 =12 */
323 : }
324 : ELSE
325 : {
326 22 : fac_fx = shl( mult( 32767 /* 4.0f in Q13 */, tmp2 ), 1 ); /*//Q(13+13-15+1=12) */
327 : }
328 : }
329 : }
330 : ELSE
331 : {
332 16 : fac_fx = 4505;
333 16 : move16(); /* 1.1 in Q12 */
334 : }
335 : }
336 : ELSE
337 : {
338 0 : tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */
339 0 : tmp2 = s_min( 1024 /* 1 in Q10 */, tmp ); /*q10 */
340 0 : tmp2 = shl( tmp2, 4 ); /*Q14 */
341 0 : L_tmp = Mult_32_16( env_fx[k], tmp2 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */
342 0 : L_tmp = Mult_32_16( L_tmp, 20480 /* 20 in Q10 */ ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */
343 :
344 0 : IF( peak_fx[k] != 0 )
345 : {
346 0 : Q_speech = norm_s( peak_fx[k] );
347 0 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
348 0 : tmp = div_s( 16384 /* 0.5f in Q15 */, tmp ); /*Q(15+14-Q_speech) */
349 : }
350 : ELSE
351 : {
352 0 : tmp = 0x7fff; /* 1 in Q15 */
353 0 : move16();
354 0 : Q_speech = 0;
355 0 : move16();
356 : }
357 :
358 0 : L_tmp2 = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */
359 0 : L_tmp3 = Mult_32_16( L_tmp, tmp ); /* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */
360 0 : L_tmp = Mult_32_32( L_tmp2, L_tmp3 ); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */
361 :
362 0 : tmp = add( Q_Ep_fx[k], Q_env_fx[k] );
363 0 : tmp = sub( tmp, Q_speech );
364 0 : tmp = sub( tmp, Q_speech );
365 0 : tmp = sub( 37, tmp );
366 :
367 0 : fac_fx = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 */
368 :
369 0 : test();
370 0 : IF( GT_16( k, 1 ) && LT_16( k, sub( ni_end_band, 1 ) ) )
371 : {
372 0 : IF( env_fx2[k] != 0 )
373 : {
374 0 : Q_speech = norm_s( env_fx2[k] );
375 0 : tmp = shl( env_fx2[k], Q_speech ); /*Q(Q_speech+1) */
376 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech-1=28-Q_speech) */
377 0 : Q_speech = sub( 28, Q_speech );
378 : }
379 : ELSE
380 : {
381 0 : tmp = 0x7fff; /* 1/0 in Q15 */
382 0 : move16();
383 0 : Q_speech = 0;
384 0 : move16();
385 : }
386 0 : tmp1 = mult( env_fx2[k + 1], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
387 0 : tmp2 = sub( env_fx2[k], tmp1 );
388 0 : tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
389 0 : tmp3 = sub( tmp1, env_fx2[k - 1] );
390 0 : tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(0+15-15=0) Q0 */
391 0 : tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) );
392 0 : test();
393 0 : test();
394 0 : test();
395 0 : IF( count[k + 1] == 0 && tmp2 > 0 && tmp3 < 0 )
396 : {
397 0 : L_tmp = L_mult( env_fx2[k + 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */
398 0 : L_tmp = Mult_32_16( L_tmp, 24576 /* 1.5 in Q14 */ ); /*Q(Q_speech+2+14-15=Q_speech+1) */
399 0 : fac_fx = extract_h( L_shl( L_tmp, sub( 27, Q_speech ) ) ); /*Q12 */
400 : }
401 0 : ELSE IF( count[k - 1] == 0 && tmp4 > 0 )
402 : {
403 0 : L_tmp = L_mult( env_fx2[k - 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */
404 : #ifdef ISSUE_1836_replace_overflow_libcom
405 0 : fac_fx = extract_h( L_shl_sat( L_tmp, sub( 26, Q_speech ) ) ); /*Q12 */
406 : #else
407 : fac_fx = extract_h( L_shl_o( L_tmp, sub( 26, Q_speech ), &Overflow ) ); /*Q12 */
408 : #endif
409 : }
410 : }
411 :
412 0 : test();
413 0 : IF( GE_16( k, sub( ni_end_band, p2a_bands ) ) && EQ_16( bwidth, WB ) )
414 : {
415 0 : L_tmp = Mult_32_16( enerH_fx, bw_low );
416 0 : L_tmp2 = Mult_32_16( enerL_fx, bw_high );
417 0 : L_tmp = L_sub( L_tmp, L_tmp2 );
418 0 : tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(0+15-15=0) Q0 */
419 0 : tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) );
420 0 : test();
421 0 : IF( L_tmp > 0 && tmp4 < 0 )
422 : {
423 0 : IF( peak_fx[k] != 0 )
424 : {
425 0 : Q_speech = norm_s( peak_fx[k] );
426 0 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
427 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */
428 : }
429 : ELSE
430 : {
431 0 : tmp = 0x7fff; /* 1.0f in Q15 */
432 0 : move16();
433 0 : Q_speech = 0;
434 0 : move16();
435 : }
436 0 : L_tmp2 = Mult_32_16( Ep_fx[k], tmp ); /* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */
437 0 : tmp = sub( Q_Ep_fx[k], Q_speech );
438 0 : tmp = add( tmp, 1 );
439 0 : tmp = extract_l( L_shr( L_tmp2, tmp ) ); /*Q13 */
440 0 : tmp = sub( 16384 /* 2 in Q13 */, tmp ); /*Q13 */
441 0 : fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 2 ) ); /*Q12*/
442 : }
443 :
444 0 : IF( p2a_flags[k] == 0 )
445 : {
446 0 : L_tmp2 = Mult_32_16( Ep_fx[k], fac_fx ); /*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */
447 0 : Q_speech = norm_l( L_tmp2 );
448 0 : tmp = extract_h( L_shl( L_tmp2, Q_speech ) ); /*Q(Q_Ep_fx[k]-3+Q_speech-16 = Q_Ep_fx[k]+Q_speech-19) */
449 0 : IF( tmp != 0 )
450 : {
451 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_Ep_fx[k]-Q_speech+19 = 48-Q_Ep_fx[k]-Q_speech) */
452 0 : L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+48-Q_Ep_fx[k]-Q_speech-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33) */
453 0 : L_tmp2 = Mult_32_16( L_tmp2, 20480 /* 1.25 in Q14 */ ); /*Q(Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33+14-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+32) */
454 0 : tmp = sub( Q_env_fx[k], Q_Ep_fx[k] );
455 0 : tmp = sub( tmp, Q_speech );
456 0 : tmp = add( tmp, 25 );
457 0 : L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */
458 0 : tmp = extract_l( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ); /* */
459 0 : fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */
460 : }
461 : ELSE
462 : {
463 0 : tmp = 0x7fff; /*Q0 */
464 0 : L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */
465 0 : L_tmp2 = Mult_32_16( L_tmp2, 20480 /* 1.25 in Q14 */ ); /*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */
466 0 : tmp = sub( Q_env_fx[k], 23 );
467 0 : L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */
468 0 : tmp = extract_l( ( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ) ); /* Q7 */
469 0 : fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */
470 : }
471 : }
472 : }
473 : }
474 : }
475 : ELSE
476 : {
477 514 : fac_fx = 4505; /* 1.1 in Q12 */
478 514 : move16();
479 514 : test();
480 514 : if ( EQ_16( hqswb_clas, HQ_HARMONIC ) && EQ_16( bwidth, SWB ) )
481 : {
482 0 : fac_fx = 3277; /* 0.8 in Q12 */
483 0 : move16();
484 : }
485 : }
486 :
487 1158 : L_tmp = Mult_32_16( Ep_fx[k], fac_fx ); /*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */
488 : #ifdef ISSUE_1836_replace_overflow_libcom
489 1158 : ni_gain_fx[k] = L_shr_sat( L_tmp, sub( Q_Ep_fx[k], 20 ) );
490 : #else
491 : ni_gain_fx[k] = L_shr_o( L_tmp, sub( Q_Ep_fx[k], 20 ), &Overflow );
492 : #endif
493 1158 : move32(); /*Q17 */
494 : }
495 : ELSE
496 : {
497 578 : ni_gain_fx[k] = L_deposit_l( 0 );
498 : }
499 :
500 : /* smooth the noise gain between the current frame and the previous frame */
501 1736 : pos = s_max( max_pos_pulse, *last_max_pos_pulse ); /* Q0 */
502 1736 : move16();
503 1736 : if ( EQ_16( bwidth, SWB ) )
504 : {
505 1736 : pos = sub( ni_end_band, 1 ); /* Q0 */
506 1736 : move16();
507 : }
508 :
509 1736 : IF( LE_16( k, pos ) )
510 : {
511 1736 : test();
512 1736 : IF( k > 0 && LT_16( sub( k, ni_end_band ), -1 ) )
513 : {
514 1580 : tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
515 1580 : tmp2 = sub( env_fx2[k], tmp1 ); /* Q1 */
516 1580 : tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
517 1580 : tmp3 = sub( tmp1, last_env_fx[k] ); /* Q1 */
518 1580 : L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /* Q1 */
519 1580 : L_tmp = L_add( L_tmp, (Word32) env_fx2[k + 1] ); /*Q1 */
520 1580 : L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /* Q1 */
521 1580 : L_tmp1 = L_add( L_tmp1, (Word32) last_env_fx[k + 1] ); /*Q1 */
522 1580 : L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
523 1580 : L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */
524 1580 : L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
525 1580 : L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */
526 1580 : test();
527 1580 : test();
528 1580 : test();
529 1580 : IF( ( tmp2 > 0 && tmp3 < 0 ) || ( L_tmp2 > 0 && L_tmp3 < 0 ) )
530 : {
531 738 : IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) )
532 : {
533 188 : L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */
534 188 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */
535 188 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
536 188 : move32();
537 : }
538 : ELSE
539 : {
540 550 : L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */
541 550 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */
542 550 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
543 550 : move32();
544 : }
545 : }
546 : }
547 156 : ELSE IF( add( sub( k, ni_end_band ), 1 ) == 0 )
548 : {
549 78 : tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
550 78 : tmp2 = sub( env_fx2[k], tmp1 ); /*Q1 */
551 78 : tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
552 78 : tmp3 = sub( tmp1, last_env_fx[k] ); /*Q1 */
553 78 : L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /*Q1 */
554 78 : L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /*Q1 */
555 78 : L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
556 78 : L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */
557 78 : L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
558 78 : L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */
559 :
560 78 : test();
561 78 : test();
562 78 : test();
563 78 : IF( ( tmp2 > 0 && tmp3 < 0 ) || ( L_tmp2 > 0 && L_tmp3 < 0 ) )
564 : {
565 22 : IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) )
566 : {
567 10 : L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */
568 10 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */
569 10 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
570 10 : move32();
571 : }
572 : ELSE
573 : {
574 12 : L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */
575 12 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */
576 12 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
577 12 : move32();
578 : }
579 : }
580 : }
581 : }
582 :
583 : /* inject noise into the non-decoded coeffs */
584 1736 : test();
585 1736 : test();
586 1736 : IF( add( sub( k, ni_end_band ), p2a_bands ) >= 0 && p2a_flags[k] == 0 && NE_16( bwidth, SWB ) )
587 : {
588 0 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
589 : {
590 0 : IF( L_y2[i] != 0 )
591 : {
592 0 : L_y2[i] = Mult_32_16( L_y2[i], 26215 /* 0.8 in Q15 */ );
593 0 : move32(); /*Q(12+15-15=12) */
594 : }
595 : }
596 : }
597 :
598 1736 : test();
599 1736 : test();
600 1736 : test();
601 1736 : IF( EQ_16( k, max_pos_pulse ) && add( sub( k, bands ), p2a_bands ) < 0 && NE_16( satur, 1 ) && NE_16( bwidth, SWB ) )
602 : {
603 0 : j = 0;
604 0 : move16();
605 :
606 0 : Q_speech = norm_l( ni_gain_fx[k] );
607 0 : tmp = extract_h( L_shl( ni_gain_fx[k], Q_speech ) ); /*Q(Q_speech+1) */
608 0 : IF( tmp != 0 )
609 : {
610 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech-1 = 28-Q_speech) */
611 0 : L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */
612 0 : tmp = sub( Q_Ep_fx[k], Q_speech );
613 0 : tmp = sub( 15, tmp );
614 : #ifdef ISSUE_1836_replace_overflow_libcom
615 0 : tmp = extract_h( L_shl_sat( L_tmp, tmp ) ); /*Q12 */
616 : #else
617 : tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */
618 : #endif
619 : }
620 : ELSE
621 : {
622 0 : tmp = 0x7fff; /*Q0 */
623 0 : L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+0-15 = Q_Ep_fx[k]-15) */
624 0 : tmp = sub( 43, Q_Ep_fx[k] );
625 : #ifdef ISSUE_1836_replace_overflow_libcom
626 0 : tmp = extract_h( L_shl_sat( L_tmp, tmp ) ); /*Q12 */
627 : #else
628 : tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */
629 : #endif
630 : }
631 0 : fac_fx = s_max( tmp, 4096 /* 1 in Q12 */ ); /*Q12 */
632 :
633 0 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
634 : {
635 0 : IF( L_y2[i] == 0 )
636 : {
637 0 : rand_fx = Random( &ni_seed ); /*Q15 */
638 0 : IF( band_width[k] != 0 )
639 : {
640 0 : Q_speech = norm_s( band_width[k] );
641 : #ifdef ISSUE_1836_replace_overflow_libcom
642 0 : tmp = shl_sat( band_width[k], Q_speech ); /*Q(Q_speech) */
643 : #else
644 : tmp = shl_o( band_width[k], Q_speech, &Overflow ); /*Q(Q_speech) */
645 : #endif
646 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */
647 : }
648 : ELSE
649 : {
650 0 : tmp = 0x7fff;
651 0 : Q_speech = 0;
652 0 : move16();
653 0 : move16();
654 : }
655 0 : tmp1 = sub( fac_fx, 4096 /* 1 in Q12 */ ); /*Q12 */
656 0 : L_tmp = L_mult( tmp1, j ); /*Q13 */
657 0 : L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(13+29-Q_speech-15 = 27-Q_speech) */
658 : #ifdef ISSUE_1836_replace_overflow_libcom
659 0 : tmp = extract_h( L_shl_sat( L_tmp, add( 1, Q_speech ) ) ); /*Q12 */
660 : #else
661 : tmp = extract_h( L_shl_o( L_tmp, add( 1, Q_speech ), &Overflow ) ); /*Q12 */
662 : #endif
663 0 : tmp = sub( fac_fx, tmp ); /*Q12 */
664 0 : L_tmp = Mult_32_16( ni_gain_fx[k], tmp ); /*Q(17+12-15=14) */
665 0 : L_y2[i] = L_add( L_y2[i], L_shr( Mult_32_16( L_tmp, rand_fx ), 2 ) );
666 0 : move32(); /*Q12 */
667 : }
668 0 : j = add( j, 1 );
669 : }
670 : }
671 : ELSE
672 : {
673 46040 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
674 : {
675 44304 : IF( L_y2[i] == 0 )
676 : {
677 42024 : rand_fx = Random( &ni_seed ); /*Q15 */
678 42024 : L_tmp = Mult_32_16( ni_gain_fx[k], rand_fx ); /*Q(17+15-15=17) */
679 42024 : L_y2[i] = L_add( L_y2[i], L_shr( L_tmp, 5 ) );
680 42024 : move32(); /*Q12 */
681 : }
682 : }
683 : }
684 : }
685 :
686 78 : Copy( env_fx2, last_env_fx, ni_end_band );
687 78 : Copy32( ni_gain_fx, last_ni_gain_fx, ni_end_band ); /* Q17 */
688 78 : *last_max_pos_pulse = max_pos_pulse;
689 78 : move16();
690 78 : return;
691 : }
|