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 69 : 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 69 : 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 69 : Word16 sb = bands;
83 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
84 69 : Flag Overflow = 0;
85 69 : move16();
86 : #endif
87 :
88 69 : satur = 0;
89 69 : move16();
90 :
91 1617 : FOR( i = 0; i < bands; i++ )
92 : {
93 1548 : Ep_fx[i] = L_shl_o( Ep_fx[i], 6, &Overflow ); /* Q-6 -> Q0 */
94 1548 : move32();
95 : }
96 :
97 69 : tmp = add( band_end[bands - 1], 1 );
98 39261 : FOR( k = 0; k < tmp; k++ )
99 : {
100 39192 : y2hat_fx[k] = (Word16) L_min( L_max( L_shr( L_y2[k], Qs ), -32768 ), 32767 );
101 39192 : move16(); /* Extract_l or something else is missing here */
102 : }
103 :
104 69 : test();
105 69 : test();
106 69 : test();
107 69 : test();
108 69 : 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 ) )
109 : {
110 66 : sb = 17;
111 66 : move16();
112 66 : if ( EQ_32( bwe_br, HQ_16k40 ) )
113 : {
114 0 : sb = 19;
115 0 : move16();
116 : }
117 : }
118 :
119 : /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */
120 69 : ni_end_band = bands;
121 69 : max_pos_pulse = bands;
122 1617 : FOR( k = ni_start_band; k < ni_end_band; k++ )
123 : {
124 1548 : tmp = div_s( 1, band_width[k] ); /*Q15 */
125 1548 : L_tmp = Mult_32_16( Rk_fx[k], tmp ); /*Q(16+15-15=16) */
126 1548 : pd_fx[k] = extract_h( L_shl( L_tmp, 10 ) ); /*16+10-16 =Q10 */
127 :
128 1548 : L_tmp2 = Ep_fx[k]; /*Q0 */
129 1548 : move32();
130 1548 : L_tmp = L_max( 1, L_tmp2 );
131 1548 : exp = norm_l( L_tmp );
132 1548 : tmp = extract_h( L_shl( L_tmp, exp ) );
133 :
134 1548 : L_tmp3 = (Word32) band_width[k]; /* Q0 */
135 1548 : move32();
136 1548 : exp2 = norm_l( L_tmp3 );
137 1548 : tmp2 = extract_h( L_shl( L_tmp3, exp2 ) );
138 :
139 1548 : exp2 = sub( exp, exp2 ); /* Denormalize and substract */
140 :
141 1548 : tmp3 = sub( tmp2, tmp );
142 1548 : if ( tmp3 > 0 )
143 : {
144 665 : tmp2 = shr( tmp2, 1 );
145 : }
146 1548 : if ( tmp3 > 0 )
147 : {
148 665 : exp2 = add( exp2, 1 );
149 : }
150 1548 : tmp = div_s( tmp2, tmp ); /* Q15 */
151 1548 : L_tmp = L_deposit_h( tmp ); /* Q31 */
152 1548 : L_tmp = Isqrt_lc( L_tmp, &exp2 );
153 1548 : env_fx[k] = L_tmp;
154 1548 : move32(); /*Q(31-exp2) move32(); */
155 1548 : Q_env_fx[k] = sub( 31, exp2 );
156 1548 : move16();
157 1548 : tmp = sub( 17, Q_env_fx[k] );
158 1548 : env_fx2[k] = extract_h( L_shl_o( env_fx[k], tmp, &Overflow ) ); /*Q1 */
159 1548 : peak_fx[k] = 0;
160 1548 : move16();
161 1548 : count[k] = 0;
162 1548 : move16();
163 :
164 1548 : IF( npulses[k] != 0 )
165 : {
166 16118 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
167 : {
168 15034 : L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /* Q0 */
169 15034 : Ep_fx[k] = L_sub_o( Ep_fx[k], L_tmp, &Overflow );
170 15034 : move32(); /* Q0 */
171 15034 : IF( GT_16( abs_s( y2hat_fx[i] ), peak_fx[k] ) )
172 : {
173 1337 : peak_fx[k] = abs_s( y2hat_fx[i] );
174 1337 : move16(); /* Q0 */
175 : }
176 :
177 15034 : IF( y2hat_fx[i] != 0 )
178 : {
179 1984 : count[k] = add( count[k], 1 ); /* Q0 */
180 1984 : move16();
181 : }
182 : }
183 :
184 1084 : max_pos_pulse = k; /* Q0 */
185 1084 : move16();
186 1084 : L_tmp2 = Ep_fx[k]; /* Q0 */
187 1084 : move32();
188 1084 : L_tmp = L_max( 1, L_tmp2 );
189 1084 : exp = norm_l( L_tmp );
190 1084 : tmp = extract_h( L_shl( L_tmp, exp ) );
191 :
192 1084 : L_tmp3 = (Word32) band_width[k]; /* Q0 */
193 1084 : exp2 = norm_l( L_tmp3 );
194 1084 : tmp2 = extract_h( L_shl( L_tmp3, exp2 ) );
195 :
196 1084 : exp2 = sub( exp, exp2 ); /* Denormalize and substract */
197 :
198 1084 : tmp3 = sub( tmp2, tmp );
199 1084 : if ( tmp3 > 0 )
200 : {
201 607 : tmp2 = shr( tmp2, 1 );
202 : }
203 1084 : if ( tmp3 > 0 )
204 : {
205 607 : exp2 = add( exp2, 1 );
206 : }
207 1084 : tmp = div_s( tmp2, tmp ); /* Q15 */
208 1084 : L_tmp = L_deposit_h( tmp ); /* Q31 */
209 1084 : L_tmp = Isqrt_lc( L_tmp, &exp2 );
210 1084 : Ep_fx[k] = L_tmp;
211 1084 : move32(); /*Q(31-exp2) */
212 1084 : Q_Ep_fx[k] = sub( 31, exp2 );
213 1084 : move16();
214 : }
215 : ELSE
216 : {
217 464 : Ep_fx[k] = env_fx[k];
218 464 : move32(); /*Q(Q_env_fx[k]) */
219 464 : Q_Ep_fx[k] = Q_env_fx[k];
220 464 : move16(); /*31-exp2 */
221 : }
222 : }
223 :
224 1617 : FOR( k = ni_start_band; k < ni_end_band; k++ )
225 : {
226 : /* calculate the noise gain */
227 1548 : satur = 0;
228 1548 : move16();
229 1548 : if ( GE_16( pd_fx[k], 819 /* 0.8 in Q10 */ ) )
230 : {
231 502 : satur = 1; /* Q0 */
232 502 : move16();
233 : }
234 :
235 1548 : test();
236 1548 : IF( satur == 0 && Ep_fx[k] > 0 )
237 : {
238 1046 : IF( npulses[k] != 0 )
239 : {
240 582 : IF( EQ_16( bwidth, SWB ) )
241 : {
242 582 : IF( NE_16( hqswb_clas, HQ_TRANSIENT ) )
243 : {
244 561 : IF( peak_fx[k] != 0 )
245 : {
246 548 : Q_speech = norm_s( peak_fx[k] );
247 548 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
248 548 : tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */
249 : }
250 : ELSE
251 : {
252 13 : tmp = 0x7fff; /* 1 in Q15 */
253 13 : move16();
254 13 : Q_speech = 0;
255 13 : move16();
256 : }
257 561 : 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) */
258 561 : tmp = sub( Q_Ep_fx[k], Q_speech );
259 561 : tmpx = add( tmp, 1 );
260 561 : tmp2 = extract_l( L_shr( L_tmp2x, s_min( tmpx, 31 ) ) ); /*Q13 Ep[k]/peak[k] */
261 :
262 561 : IF( EQ_16( hqswb_clas, HQ_HARMONIC ) )
263 : {
264 0 : tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */
265 0 : tmp3 = shl( tmp, 4 ); /*Q14 */
266 0 : L_tmp = Mult_32_16( env_fx[k], tmp3 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */
267 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) */
268 :
269 0 : IF( peak_fx[k] != 0 )
270 : {
271 0 : Q_speech = norm_s( peak_fx[k] );
272 0 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
273 0 : tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */
274 : }
275 : ELSE
276 : {
277 0 : tmp = 0x7fff; /* 1 in Q15 */
278 0 : move16();
279 0 : Q_speech = 0;
280 0 : move16();
281 : }
282 :
283 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) */
284 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) */
285 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) */
286 :
287 0 : tmp = add( Q_Ep_fx[k], Q_env_fx[k] );
288 0 : tmp = sub( tmp, Q_speech );
289 0 : tmp = sub( tmp, Q_speech );
290 0 : tmp = sub( 37, tmp );
291 0 : tmp1 = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 //6.0f*(1.5f - pd[k])*env[k]*Ep[k]/(peak[k]*peak[k]) */
292 :
293 0 : fac_fx = tmp1;
294 0 : move16(); /*Q12 */
295 0 : if ( GT_16( k, sb ) )
296 : {
297 0 : fac_fx = mult( 24576 /* 1.5 in Q14 */, tmp2 ); /*//Q(14+13-15=12) */
298 : }
299 : }
300 : ELSE
301 : {
302 561 : IF( LE_16( k, sb ) )
303 : {
304 543 : tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */
305 543 : tmp3 = shl( tmp, 4 ); /*Q14 */
306 543 : 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) */
307 543 : 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) */
308 543 : 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 */
309 : }
310 : ELSE
311 : {
312 18 : fac_fx = shl( mult( 32767 /* 4.0f in Q13 */, tmp2 ), 1 ); /*//Q(13+13-15+1=12) */
313 : }
314 : }
315 : }
316 : ELSE
317 : {
318 21 : fac_fx = 4505;
319 21 : move16(); /* 1.1 in Q12 */
320 : }
321 : }
322 : ELSE
323 : {
324 0 : tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */
325 0 : tmp2 = s_min( 1024 /* 1 in Q10 */, tmp ); /*q10 */
326 0 : tmp2 = shl( tmp2, 4 ); /*Q14 */
327 0 : L_tmp = Mult_32_16( env_fx[k], tmp2 ); /*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */
328 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) */
329 :
330 0 : IF( peak_fx[k] != 0 )
331 : {
332 0 : Q_speech = norm_s( peak_fx[k] );
333 0 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
334 0 : tmp = div_s( 16384 /* 0.5f in Q15 */, tmp ); /*Q(15+14-Q_speech) */
335 : }
336 : ELSE
337 : {
338 0 : tmp = 0x7fff; /* 1 in Q15 */
339 0 : move16();
340 0 : Q_speech = 0;
341 0 : move16();
342 : }
343 :
344 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) */
345 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) */
346 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) */
347 :
348 0 : tmp = add( Q_Ep_fx[k], Q_env_fx[k] );
349 0 : tmp = sub( tmp, Q_speech );
350 0 : tmp = sub( tmp, Q_speech );
351 0 : tmp = sub( 37, tmp );
352 :
353 0 : fac_fx = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 */
354 :
355 0 : test();
356 0 : IF( GT_16( k, 1 ) && LT_16( k, sub( ni_end_band, 1 ) ) )
357 : {
358 0 : IF( env_fx2[k] != 0 )
359 : {
360 0 : Q_speech = norm_s( env_fx2[k] );
361 0 : tmp = shl( env_fx2[k], Q_speech ); /*Q(Q_speech+1) */
362 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech-1=28-Q_speech) */
363 0 : Q_speech = sub( 28, Q_speech );
364 : }
365 : ELSE
366 : {
367 0 : tmp = 0x7fff; /* 1/0 in Q15 */
368 0 : move16();
369 0 : Q_speech = 0;
370 0 : move16();
371 : }
372 0 : tmp1 = mult( env_fx2[k + 1], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
373 0 : tmp2 = sub( env_fx2[k], tmp1 );
374 0 : tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
375 0 : tmp3 = sub( tmp1, env_fx2[k - 1] );
376 0 : tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(0+15-15=0) Q0 */
377 0 : tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) );
378 0 : test();
379 0 : test();
380 0 : test();
381 0 : IF( count[k + 1] == 0 && tmp2 > 0 && tmp3 < 0 )
382 : {
383 0 : L_tmp = L_mult( env_fx2[k + 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */
384 0 : L_tmp = Mult_32_16( L_tmp, 24576 /* 1.5 in Q14 */ ); /*Q(Q_speech+2+14-15=Q_speech+1) */
385 0 : fac_fx = extract_h( L_shl( L_tmp, sub( 27, Q_speech ) ) ); /*Q12 */
386 : }
387 0 : ELSE IF( count[k - 1] == 0 && tmp4 > 0 )
388 : {
389 0 : L_tmp = L_mult( env_fx2[k - 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */
390 0 : fac_fx = extract_h( L_shl_o( L_tmp, sub( 26, Q_speech ), &Overflow ) ); /*Q12 */
391 : }
392 : }
393 :
394 0 : test();
395 0 : IF( GE_16( k, sub( ni_end_band, p2a_bands ) ) && EQ_16( bwidth, WB ) )
396 : {
397 0 : L_tmp = Mult_32_16( enerH_fx, bw_low );
398 0 : L_tmp2 = Mult_32_16( enerL_fx, bw_high );
399 0 : L_tmp = L_sub( L_tmp, L_tmp2 );
400 0 : tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(0+15-15=0) Q0 */
401 0 : tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) );
402 0 : test();
403 0 : IF( L_tmp > 0 && tmp4 < 0 )
404 : {
405 0 : IF( peak_fx[k] != 0 )
406 : {
407 0 : Q_speech = norm_s( peak_fx[k] );
408 0 : tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */
409 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */
410 : }
411 : ELSE
412 : {
413 0 : tmp = 0x7fff; /* 1.0f in Q15 */
414 0 : move16();
415 0 : Q_speech = 0;
416 0 : move16();
417 : }
418 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) */
419 0 : tmp = sub( Q_Ep_fx[k], Q_speech );
420 0 : tmp = add( tmp, 1 );
421 0 : tmp = extract_l( L_shr( L_tmp2, tmp ) ); /*Q13 */
422 0 : tmp = sub( 16384 /* 2 in Q13 */, tmp ); /*Q13 */
423 0 : fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 2 ) ); /*Q12*/
424 : }
425 :
426 0 : IF( p2a_flags[k] == 0 )
427 : {
428 0 : L_tmp2 = Mult_32_16( Ep_fx[k], fac_fx ); /*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */
429 0 : Q_speech = norm_l( L_tmp2 );
430 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) */
431 0 : IF( tmp != 0 )
432 : {
433 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) */
434 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) */
435 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) */
436 0 : tmp = sub( Q_env_fx[k], Q_Ep_fx[k] );
437 0 : tmp = sub( tmp, Q_speech );
438 0 : tmp = add( tmp, 25 );
439 0 : L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */
440 0 : tmp = extract_l( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ); /* */
441 0 : fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */
442 : }
443 : ELSE
444 : {
445 0 : tmp = 0x7fff; /*Q0 */
446 0 : L_tmp2 = Mult_32_16( env_fx[k], tmp ); /*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */
447 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) */
448 0 : tmp = sub( Q_env_fx[k], 23 );
449 0 : L_tmp = L_shr_sat( L_tmp2, tmp ); /*Q7 */
450 0 : tmp = extract_l( ( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ) ); /* Q7 */
451 0 : fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */
452 : }
453 : }
454 : }
455 : }
456 : }
457 : ELSE
458 : {
459 464 : fac_fx = 4505; /* 1.1 in Q12 */
460 464 : move16();
461 464 : test();
462 464 : if ( EQ_16( hqswb_clas, HQ_HARMONIC ) && EQ_16( bwidth, SWB ) )
463 : {
464 0 : fac_fx = 3277; /* 0.8 in Q12 */
465 0 : move16();
466 : }
467 : }
468 :
469 1046 : L_tmp = Mult_32_16( Ep_fx[k], fac_fx ); /*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */
470 1046 : ni_gain_fx[k] = L_shr_o( L_tmp, sub( Q_Ep_fx[k], 20 ), &Overflow );
471 1046 : move32(); /*Q17 */
472 : }
473 : ELSE
474 : {
475 502 : ni_gain_fx[k] = L_deposit_l( 0 );
476 : }
477 :
478 : /* smooth the noise gain between the current frame and the previous frame */
479 1548 : pos = s_max( max_pos_pulse, *last_max_pos_pulse ); /* Q0 */
480 1548 : move16();
481 1548 : if ( EQ_16( bwidth, SWB ) )
482 : {
483 1548 : pos = sub( ni_end_band, 1 ); /* Q0 */
484 1548 : move16();
485 : }
486 :
487 1548 : IF( LE_16( k, pos ) )
488 : {
489 1548 : test();
490 1548 : IF( k > 0 && LT_16( sub( k, ni_end_band ), -1 ) )
491 : {
492 1410 : tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
493 1410 : tmp2 = sub( env_fx2[k], tmp1 ); /* Q1 */
494 1410 : tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
495 1410 : tmp3 = sub( tmp1, last_env_fx[k] ); /* Q1 */
496 1410 : L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /* Q1 */
497 1410 : L_tmp = L_add( L_tmp, (Word32) env_fx2[k + 1] ); /*Q1 */
498 1410 : L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /* Q1 */
499 1410 : L_tmp1 = L_add( L_tmp1, (Word32) last_env_fx[k + 1] ); /*Q1 */
500 1410 : L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
501 1410 : L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */
502 1410 : L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
503 1410 : L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */
504 1410 : test();
505 1410 : test();
506 1410 : test();
507 1410 : IF( ( tmp2 > 0 && tmp3 < 0 ) || ( L_tmp2 > 0 && L_tmp3 < 0 ) )
508 : {
509 678 : IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) )
510 : {
511 178 : L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */
512 178 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */
513 178 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
514 178 : move32();
515 : }
516 : ELSE
517 : {
518 500 : L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */
519 500 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */
520 500 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
521 500 : move32();
522 : }
523 : }
524 : }
525 138 : ELSE IF( add( sub( k, ni_end_band ), 1 ) == 0 )
526 : {
527 69 : tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
528 69 : tmp2 = sub( env_fx2[k], tmp1 ); /*Q1 */
529 69 : tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */
530 69 : tmp3 = sub( tmp1, last_env_fx[k] ); /*Q1 */
531 69 : L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /*Q1 */
532 69 : L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /*Q1 */
533 69 : L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
534 69 : L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */
535 69 : L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */
536 69 : L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */
537 :
538 69 : test();
539 69 : test();
540 69 : test();
541 69 : IF( ( tmp2 > 0 && tmp3 < 0 ) || ( L_tmp2 > 0 && L_tmp3 < 0 ) )
542 : {
543 19 : IF( GT_32( ni_gain_fx[k], last_ni_gain_fx[k] ) )
544 : {
545 6 : L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */
546 6 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */
547 6 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
548 6 : move32();
549 : }
550 : ELSE
551 : {
552 13 : L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */
553 13 : L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */
554 13 : ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */
555 13 : move32();
556 : }
557 : }
558 : }
559 : }
560 :
561 : /* inject noise into the non-decoded coeffs */
562 1548 : test();
563 1548 : test();
564 1548 : IF( add( sub( k, ni_end_band ), p2a_bands ) >= 0 && p2a_flags[k] == 0 && NE_16( bwidth, SWB ) )
565 : {
566 0 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
567 : {
568 0 : IF( L_y2[i] != 0 )
569 : {
570 0 : L_y2[i] = Mult_32_16( L_y2[i], 26215 /* 0.8 in Q15 */ );
571 0 : move32(); /*Q(12+15-15=12) */
572 : }
573 : }
574 : }
575 :
576 1548 : test();
577 1548 : test();
578 1548 : test();
579 1548 : IF( EQ_16( k, max_pos_pulse ) && add( sub( k, bands ), p2a_bands ) < 0 && NE_16( satur, 1 ) && NE_16( bwidth, SWB ) )
580 : {
581 0 : j = 0;
582 0 : move16();
583 :
584 0 : Q_speech = norm_l( ni_gain_fx[k] );
585 0 : tmp = extract_h( L_shl( ni_gain_fx[k], Q_speech ) ); /*Q(Q_speech+1) */
586 0 : IF( tmp != 0 )
587 : {
588 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech-1 = 28-Q_speech) */
589 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) */
590 0 : tmp = sub( Q_Ep_fx[k], Q_speech );
591 0 : tmp = sub( 15, tmp );
592 0 : tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */
593 : }
594 : ELSE
595 : {
596 0 : tmp = 0x7fff; /*Q0 */
597 0 : L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+0-15 = Q_Ep_fx[k]-15) */
598 0 : tmp = sub( 43, Q_Ep_fx[k] );
599 0 : tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */
600 : }
601 0 : fac_fx = s_max( tmp, 4096 /* 1 in Q12 */ ); /*Q12 */
602 :
603 0 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
604 : {
605 0 : IF( L_y2[i] == 0 )
606 : {
607 0 : rand_fx = Random( &ni_seed ); /*Q15 */
608 0 : IF( band_width[k] != 0 )
609 : {
610 0 : Q_speech = norm_s( band_width[k] );
611 0 : tmp = shl_o( band_width[k], Q_speech, &Overflow ); /*Q(Q_speech) */
612 0 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */
613 : }
614 : ELSE
615 : {
616 0 : tmp = 0x7fff;
617 0 : Q_speech = 0;
618 0 : move16();
619 0 : move16();
620 : }
621 0 : tmp1 = sub( fac_fx, 4096 /* 1 in Q12 */ ); /*Q12 */
622 0 : L_tmp = L_mult( tmp1, j ); /*Q13 */
623 0 : L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(13+29-Q_speech-15 = 27-Q_speech) */
624 0 : tmp = extract_h( L_shl_o( L_tmp, add( 1, Q_speech ), &Overflow ) ); /*Q12 */
625 0 : tmp = sub( fac_fx, tmp ); /*Q12 */
626 0 : L_tmp = Mult_32_16( ni_gain_fx[k], tmp ); /*Q(17+12-15=14) */
627 0 : L_y2[i] = L_add( L_y2[i], L_shr( Mult_32_16( L_tmp, rand_fx ), 2 ) );
628 0 : move32(); /*Q12 */
629 : }
630 0 : j = add( j, 1 );
631 : }
632 : }
633 : ELSE
634 : {
635 40740 : FOR( i = band_start[k]; i <= band_end[k]; i++ )
636 : {
637 39192 : IF( L_y2[i] == 0 )
638 : {
639 37161 : rand_fx = Random( &ni_seed ); /*Q15 */
640 37161 : L_tmp = Mult_32_16( ni_gain_fx[k], rand_fx ); /*Q(17+15-15=17) */
641 37161 : L_y2[i] = L_add( L_y2[i], L_shr( L_tmp, 5 ) );
642 37161 : move32(); /*Q12 */
643 : }
644 : }
645 : }
646 : }
647 :
648 69 : Copy( env_fx2, last_env_fx, ni_end_band );
649 69 : Copy32( ni_gain_fx, last_ni_gain_fx, ni_end_band ); /* Q17 */
650 69 : *last_max_pos_pulse = max_pos_pulse;
651 69 : move16();
652 69 : return;
653 : }
|