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 <assert.h>
7 : #include "options.h"
8 : #include "cnst.h"
9 : #include "rom_com.h"
10 : //#include "prot_fx.h"
11 : #include "prot_fx.h" /* Function prototypes */
12 : #include "prot_fx_enc.h" /* Function prototypes */
13 : #include "basop_util.h"
14 :
15 : /*-----------------------------------------------------------------*
16 : * Local constants
17 : *-----------------------------------------------------------------*/
18 :
19 : #define ALPHA_FX 3277 /*.1 Q15*/
20 : #define ALPHAM1_FX 29491 /*.9 Q15*/
21 :
22 : #define TH_PC_FX 12 /* max sum of pitch differencies */
23 :
24 : #define BCKR_SLOW_UPDATE_SCALE_FX 3277 /*Q15 Step size for slow bckr update */
25 : #define COR_MIN16_FX 17039 /*.52 Q15 */
26 : #define COR_MAX16_FX 27853 /*.85 Q15 */
27 :
28 : /* 10.0e5f causes problems with music - as the noise estimate starts to track the music */
29 : #define TH_STA16_FX ( 350000 << 10 ) /* MODE1: 3.5e5f */
30 :
31 : #define TH_EPS16_FX 3277 /* Q11 (1.6) tuned for speech only, not for music */
32 : #define K_16_FX 25690 /* Q20 (0.0245f) */
33 : #define C_16_FX -1925 /* Q13 (-0.235f) */
34 : #define ALPHA_MAX16_FX 32440 /* Q15 (0.99) */
35 :
36 : #define COR_MIN8_FX 21299 /*.65 Q15 */
37 : #define COR_MAX8_FX 22938 /*.70 Q15 */
38 : #define TH_EPS8_FX 21299 /* 10.4 in Q11 Thresholds for NB processing - ... */
39 : #define TH_STA8_FX ( 500000 << 10 )
40 : #define K_8_FX 9452 /* Q20 (0.0091f) */
41 : #define C_8_FX 2609 /* Q13 (0.0091f) */
42 : #define ALPHA_MAX8_FX 32735 /* Q15 (0.999) */
43 :
44 : #define HC_CNT_SLOW_FX 80 /* limit for harm corr count slow */
45 :
46 : #define HE_LT_CNT_PRE_FX 50
47 : #define HE_LT_CNT_INIT_FX 150
48 : #define HE_LT_CNT_PRE_SHORT_FX 250
49 : #define HE_LT_CNT_FX 30
50 :
51 : #define LN_E_MIN_PLUS_ONE_FX 1 /* max(1, ln(E_MIN+1.0)) = max(1,ln(0.0035f+1f)) in Q8 */
52 : #define COR_MAX_NNE_FX 27853 /* 0.85 Q15 */
53 :
54 : #define HE_LT_THR1_FX 2560 /*10.0 Q8*/
55 : #define HE_LT_THR2_FX 7680 /*30.0 Q8*/
56 : #define HE_LT_THR1_Q24 167772160 /*10.0 Q24 */
57 : #define HE_LT_THR2_Q24 503316480 /*30.0 Q24 */
58 :
59 : /*-----------------------------------------------------------------*
60 : * noise_est_AR1_Qx()
61 : *
62 : * y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx)
63 : *-----------------------------------------------------------------*/
64 :
65 59167 : Word16 noise_est_AR1_Qx( /* o : Qx y(n) */
66 : Word16 x, /* i : Qx x(n) */
67 : Word16 y, /* i : Qx y(n-1) */
68 : Word16 alpha /*i : Q15 scaling of driving x(n) */
69 : )
70 : {
71 : Word16 alpham1;
72 : /*alpham1 = negate(add((Word16)-32768, alpha)); */
73 59167 : alpham1 = sub( 32767, alpha ); /* one cycle less */
74 :
75 59167 : return mac_r( L_mult( y, alpham1 ), x, alpha );
76 : }
77 :
78 1994490 : Word32 noise_est_AR1_Qx_32( /* o : Qx y(n) */
79 : Word32 x, /* i : Qx x(n) */
80 : Word32 y, /* i : Qx y(n-1) */
81 : Word32 alpha /*i : Q15 scaling of driving x(n) */
82 : )
83 : {
84 : Word32 alpham1;
85 : /*alpham1 = negate(add((Word16)-32768, alpha)); */
86 1994490 : alpham1 = L_sub( MAX_32, alpha ); /* one cycle less */
87 1994490 : alpham1++;
88 :
89 1994490 : return Madd_32_32( Mpy_32_32( y, alpham1 ), x, alpha );
90 : }
91 :
92 : /*-----------------------------------------------------------------*
93 : * noise_est_ln_q8_fx()
94 : *
95 : * q8 = (float)log( L_enr[i] + add1po*1.0 );
96 : *-----------------------------------------------------------------*/
97 :
98 231750 : static Word16 noise_est_ln_q8_fx(
99 : Word32 L_enr,
100 : Word16 flag_add1p0, /* flag to add 1.0 */
101 : Word16 q_new_plus_q_scale )
102 : {
103 : Word16 e_ener, f_ener;
104 : Word32 L_tmp;
105 :
106 231750 : L_tmp = L_add_sat( L_enr, L_shl( (Word32) 1L, q_new_plus_q_scale ) ); /* +1.0f */
107 231750 : if ( flag_add1p0 == 0 )
108 : {
109 77250 : L_tmp = L_add( L_enr, 0 ); /* +0 , no offset */
110 : }
111 :
112 231750 : L_tmp = L_max( L_tmp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */
113 :
114 231750 : e_ener = norm_l( L_tmp );
115 231750 : f_ener = Log2_norm_lc( L_shl( L_tmp, e_ener ) );
116 231750 : e_ener = sub( sub( 30, e_ener ), q_new_plus_q_scale );
117 231750 : L_tmp = Mpy_32_16( e_ener, f_ener, 22713 ); /* Q16 (22713 = Ln(2) in Q15)*/
118 :
119 231750 : return round_fx( L_shl( L_tmp, 8 ) ); /* Q8 */
120 : }
121 :
122 :
123 : /*-----------------------------------------------------------------*
124 : * eps_quota_fx()
125 : *
126 : *
127 : *-----------------------------------------------------------------*/
128 :
129 15450 : static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */
130 : Word16 eps_num_h, /* num high ,*/
131 : Word16 eps_num_l, /* num low (signed) ,*/
132 : Word16 eps_den_h, /* den low */
133 : Word16 eps_den_l, /* den low (signed),*/
134 : Word16 q_out /* range 15...0 , tested with 11 and 12 */
135 : )
136 : {
137 : Word32 L_tmp_num, L_tmp_den;
138 : Word16 exp_num, exp_den;
139 : Word16 m_num, m_den;
140 : Word16 num_shift;
141 :
142 :
143 15450 : L_tmp_num = L_Comp( eps_num_h, eps_num_l );
144 15450 : L_tmp_den = L_Comp( eps_den_h, eps_den_l );
145 :
146 15450 : exp_num = sub( norm_l( L_tmp_num ), 1 ); /* make sure m_ num is lower than m_den */
147 15450 : m_num = extract_h( L_shl( L_tmp_num, exp_num ) );
148 15450 : exp_den = norm_l( L_tmp_den );
149 15450 : m_den = extract_h( L_shl( L_tmp_den, exp_den ) );
150 :
151 15450 : exp_num = sub( exp_num, exp_den );
152 15450 : if ( m_den != 0 )
153 : {
154 15450 : assert( m_den >= m_num );
155 15450 : m_num = div_s( m_num, m_den ); /* single basop */
156 : }
157 :
158 15450 : num_shift = add( 15 - q_out, exp_num );
159 15450 : if ( m_den == 0 )
160 : {
161 : /* no division made due to zero denominator */
162 0 : m_num = 0;
163 0 : move16();
164 : }
165 :
166 15450 : return L_shr( m_num, num_shift );
167 : }
168 :
169 : /*-----------------------------------------------------------------*
170 : * noise_est_init_fx()
171 : *
172 : * Initialization of Noise estimator
173 : *-----------------------------------------------------------------*/
174 5 : void noise_est_init_fx(
175 : NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */
176 : )
177 : {
178 : Word16 i;
179 :
180 105 : FOR( i = 0; i < NB_BANDS; i++ )
181 : {
182 100 : hNoiseEst->fr_bands1_fx[i] = 1;
183 100 : move32(); /*1e-5f; */
184 100 : hNoiseEst->fr_bands2_fx[i] = 1;
185 100 : move32(); /*1e-5f; */
186 100 : hNoiseEst->ave_enr2_fx[i] = E_MIN_FX;
187 100 : move32(); /*Q7//E_MIN; */
188 100 : hNoiseEst->enrO_fx[i] = E_MIN_FX;
189 100 : move32();
190 100 : hNoiseEst->bckr_fx[i] = E_MIN_FX;
191 100 : move32();
192 100 : hNoiseEst->ave_enr_fx[i] = E_MIN_FX;
193 100 : move32();
194 : }
195 5 : hNoiseEst->fr_bands_fx_q = 17;
196 5 : move16(); /*1e-5f; */
197 5 : hNoiseEst->q_enrO = Q7;
198 5 : move16();
199 5 : hNoiseEst->q_bckr = Q7;
200 5 : move16();
201 5 : hNoiseEst->ave_enr_q = Q7;
202 5 : move16();
203 :
204 5 : hNoiseEst->totalNoise_fx = 0;
205 5 : move16();
206 5 : hNoiseEst->first_noise_updt = 0;
207 5 : move16();
208 :
209 5 : hNoiseEst->aEn = 6;
210 5 : move16();
211 5 : hNoiseEst->aEn_inac_cnt = 0;
212 5 : move16();
213 :
214 5 : hNoiseEst->harm_cor_cnt = 0;
215 5 : move16();
216 5 : hNoiseEst->bg_cnt = 0;
217 5 : move16();
218 :
219 5 : hNoiseEst->lt_tn_track_fx = 6554; /*.20 in Q15*/
220 5 : move16();
221 5 : hNoiseEst->lt_tn_dist_fx = 0;
222 5 : move16();
223 5 : hNoiseEst->lt_Ellp_dist_fx = 0;
224 5 : move16();
225 5 : hNoiseEst->lt_haco_ev_fx = 13107; /*.40 in Q15*/
226 5 : move16();
227 5 : hNoiseEst->low_tn_track_cnt = 0;
228 5 : move16();
229 :
230 5 : hNoiseEst->Etot_st_est_fx = 5120; /* 20.0f in Q8 */
231 5 : hNoiseEst->Etot_sq_st_est_fx = 1600; /* 400 in Q2 */
232 5 : move16();
233 5 : move16();
234 :
235 5 : hNoiseEst->epsP_0_2_lp_fx = 4096; /*1.0 Q12*/
236 5 : move16();
237 5 : hNoiseEst->epsP_0_2_ad_lp_fx = 0;
238 5 : move16();
239 5 : hNoiseEst->epsP_2_16_lp_fx = 4096;
240 5 : move16();
241 5 : hNoiseEst->epsP_2_16_lp2_fx = 4096;
242 5 : move16();
243 5 : hNoiseEst->epsP_2_16_dlp_lp2_fx = 0;
244 5 : move16();
245 5 : hNoiseEst->lt_aEn_zero_fx = 0;
246 5 : move16();
247 :
248 : /* Tonal detector */
249 645 : FOR( i = 0; i < L_FFT / 2; i++ )
250 : {
251 640 : hNoiseEst->old_S_fx[i] = 1;
252 640 : move16();
253 : }
254 5 : set16_fx( hNoiseEst->cor_map_fx, 0, L_FFT / 2 );
255 5 : hNoiseEst->act_pred_fx = 32767;
256 5 : move16();
257 5 : hNoiseEst->noise_char_fx = 0;
258 5 : move16();
259 5 : hNoiseEst->multi_harm_limit_fx = THR_CORR_INIT_FX;
260 5 : move16();
261 5 : hNoiseEst->Etot_lp_fx = 0;
262 5 : hNoiseEst->Etot_h_fx = 0;
263 5 : hNoiseEst->Etot_l_fx = 0;
264 5 : hNoiseEst->Etot_l_lp_fx = 0;
265 5 : hNoiseEst->Etot_last_fx = 0;
266 5 : hNoiseEst->Etot_v_h2_fx = 0;
267 5 : hNoiseEst->sign_dyn_lp_fx = 0;
268 5 : move16();
269 5 : move16();
270 5 : move16();
271 5 : move16();
272 5 : move16();
273 5 : move16();
274 5 : move16();
275 :
276 5 : return;
277 : }
278 :
279 14718 : void noise_est_init_ivas_fx(
280 : NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */
281 : )
282 : {
283 : Word16 i;
284 :
285 309078 : FOR( i = 0; i < NB_BANDS; i++ )
286 : {
287 294360 : hNoiseEst->fr_bands1_fx[i] = 1;
288 294360 : move32(); /*1e-5f; */
289 294360 : hNoiseEst->fr_bands2_fx[i] = 1;
290 294360 : move32(); /*1e-5f; */
291 294360 : hNoiseEst->ave_enr2_fx[i] = E_MIN_Q11_FX;
292 294360 : move32(); /*Q7//E_MIN; */
293 294360 : hNoiseEst->enrO_fx[i] = E_MIN_Q11_FX;
294 294360 : move32();
295 294360 : hNoiseEst->bckr_fx[i] = E_MIN_Q27_FX;
296 294360 : move32();
297 294360 : hNoiseEst->ave_enr_fx[i] = E_MIN_Q11_FX;
298 294360 : move32();
299 : }
300 14718 : hNoiseEst->fr_bands_fx_q = 17;
301 14718 : move16(); /*1e-5f; */
302 14718 : hNoiseEst->q_enrO = Q11;
303 14718 : move16();
304 14718 : hNoiseEst->q_bckr = Q27;
305 14718 : move16();
306 14718 : hNoiseEst->ave_enr_q = Q11;
307 14718 : move16();
308 :
309 14718 : move16();
310 14718 : hNoiseEst->totalNoise_32fx = 0;
311 14718 : move32();
312 14718 : hNoiseEst->first_noise_updt = 0;
313 14718 : move16();
314 14718 : hNoiseEst->first_noise_updt_cnt = 0;
315 14718 : move16();
316 :
317 14718 : hNoiseEst->aEn = 6;
318 14718 : move16();
319 14718 : hNoiseEst->aEn_inac_cnt = 0;
320 14718 : move16();
321 14718 : hNoiseEst->harm_cor_cnt = 0;
322 14718 : move16();
323 14718 : hNoiseEst->bg_cnt = 0;
324 14718 : move16();
325 :
326 14718 : hNoiseEst->lt_tn_track_fx = 6554; /*.20 in Q15*/
327 14718 : move16();
328 14718 : hNoiseEst->lt_tn_dist_fx = 0;
329 14718 : move16();
330 14718 : hNoiseEst->lt_Ellp_dist_fx = 0;
331 14718 : move16();
332 14718 : hNoiseEst->lt_haco_ev_fx = 13107; /*.40 in Q15*/
333 14718 : move16();
334 14718 : hNoiseEst->low_tn_track_cnt = 0;
335 14718 : move16();
336 :
337 14718 : hNoiseEst->Etot_st_est_fx = 5120; /* 20.0f in Q8 */
338 14718 : hNoiseEst->Etot_sq_st_est_fx = 1600; /* 400 in Q2 */
339 14718 : move16();
340 14718 : move16();
341 14718 : hNoiseEst->L_Etot_st_est_fx = 167772160; /* 20.0f in Q23 */
342 14718 : hNoiseEst->L_Etot_sq_st_est_fx = 26214400; /* 400 in Q16 */
343 14718 : move32();
344 14718 : move32();
345 14718 : hNoiseEst->epsP_0_2_lp_fx = 4096; /*1.0 Q12*/
346 14718 : move16();
347 14718 : hNoiseEst->epsP_0_2_ad_lp_fx = 0;
348 14718 : move16();
349 14718 : hNoiseEst->epsP_2_16_lp_fx = 4096;
350 14718 : move16();
351 14718 : hNoiseEst->epsP_2_16_lp2_fx = 4096;
352 14718 : move16();
353 14718 : hNoiseEst->epsP_2_16_dlp_lp2_fx = 0;
354 14718 : move16();
355 14718 : hNoiseEst->lt_aEn_zero_fx = 0;
356 14718 : move16();
357 :
358 : /* Tonal detector */
359 1898622 : FOR( i = 0; i < L_FFT / 2; i++ )
360 : {
361 1883904 : hNoiseEst->old_S_fx[i] = ONE_IN_Q7;
362 1883904 : move16();
363 : }
364 14718 : set16_fx( hNoiseEst->cor_map_fx, 0, L_FFT / 2 );
365 14718 : hNoiseEst->act_pred_fx = 32767;
366 14718 : move16();
367 14718 : hNoiseEst->noise_char_fx = 0;
368 14718 : move16();
369 14718 : hNoiseEst->multi_harm_limit_fx = THR_CORR_INIT_FX;
370 14718 : move16();
371 14718 : hNoiseEst->Etot_lp_fx = 0;
372 14718 : hNoiseEst->Etot_h_fx = 0;
373 14718 : hNoiseEst->Etot_l_32fx = 0;
374 14718 : hNoiseEst->Etot_l_lp_32fx = 0;
375 14718 : hNoiseEst->Etot_last_32fx = 0;
376 14718 : hNoiseEst->Etot_v_h2_32fx = 0;
377 14718 : hNoiseEst->sign_dyn_lp_fx = 0;
378 14718 : move16();
379 14718 : move16();
380 14718 : move32();
381 14718 : move16();
382 14718 : move32();
383 14718 : move32();
384 14718 : move32();
385 :
386 14718 : return;
387 : }
388 : /*-----------------------------------------------------------------*
389 : * noise_est_pre_fx()
390 : *
391 : * Track energy and signal dynamics
392 : *-----------------------------------------------------------------*/
393 :
394 5150 : void noise_est_pre_fx(
395 : const Word16 Etot, /* i : Energy of current frame */
396 : const Word16 ini_frame_fx, /* i : Frame number (init) */
397 : NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */
398 : const Word16 idchan, /* i : channel ID */
399 : const Word16 element_mode, /* i : element mode */
400 : const Word16 last_element_mode /* i : last element mode */
401 : )
402 : {
403 : Word16 tmp;
404 :
405 5150 : IF( LE_16( ini_frame_fx, 1 ) || ( EQ_16( idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) )
406 : {
407 10 : hNoiseEst->Etot_h_fx = Etot;
408 10 : move16();
409 10 : hNoiseEst->Etot_l_fx = Etot;
410 10 : move16();
411 10 : hNoiseEst->Etot_l_lp_fx = Etot;
412 10 : move16();
413 10 : hNoiseEst->Etot_last_fx = Etot;
414 10 : move16();
415 10 : hNoiseEst->Etot_v_h2_fx = 0;
416 10 : move16();
417 10 : hNoiseEst->Etot_lp_fx = Etot;
418 10 : move16();
419 10 : hNoiseEst->sign_dyn_lp_fx = 0;
420 10 : move16();
421 : }
422 : ELSE
423 : {
424 : /* *Etot_lp = 0.20f*Etot + 0.80f* *Etot_lp; */
425 5140 : hNoiseEst->Etot_lp_fx = mac_r( L_mult( 6554, Etot ), 26214, hNoiseEst->Etot_lp_fx );
426 5140 : move16();
427 :
428 5140 : hNoiseEst->Etot_h_fx = sub( hNoiseEst->Etot_h_fx, 10 );
429 5140 : move16(); /* 10=0.04 in Q8 */
430 5140 : hNoiseEst->Etot_h_fx = s_max( hNoiseEst->Etot_h_fx, Etot );
431 5140 : move16();
432 5140 : hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, 20 );
433 5140 : move16(); /* 20 = .08 in Q8 */
434 :
435 :
436 : /* Could even be higher but it also delays first entry to DTX */
437 5140 : IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) )
438 : {
439 0 : test();
440 0 : IF( ( LT_16( ini_frame_fx, s_min( HE_LT_CNT_INIT_FX, MAX_FRAME_COUNTER - 1 ) ) ) && ( LT_16( sub( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_lp_fx ), (Word16) 3 * 256 ) ) /* 3.0 Q8 */
441 : )
442 : {
443 : /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */
444 0 : tmp = mult_r( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), 3277 ); /* factor in Q15 3277 .1*32768 */
445 0 : tmp = s_min( 512, tmp ); /* 2.0 in Q8 is 512*/
446 0 : hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, tmp );
447 0 : move16(); /* Q8 */
448 : }
449 :
450 : /* Avoids large steps in short active segments */
451 0 : test();
452 0 : IF( ( GT_16( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) /* 30.0f*Q8 */
453 : && ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_SHORT_FX ) ) )
454 : {
455 : /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */
456 0 : hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, mult_r( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), 655 ) );
457 0 : move16(); /* 0.02 = 655 Q8*/
458 : }
459 0 : ELSE IF( GT_16( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR1_FX ) ) /* 10.0 in Q8*/
460 : {
461 0 : hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, 20 );
462 0 : move16(); /* 0.08 is 20 in Q8*/
463 : }
464 : }
465 :
466 5140 : hNoiseEst->Etot_l_fx = s_min( hNoiseEst->Etot_l_fx, Etot );
467 5140 : move16();
468 5140 : test();
469 5140 : IF( LT_16( ini_frame_fx, 100 ) && LT_16( hNoiseEst->Etot_l_fx, hNoiseEst->Etot_l_lp_fx ) )
470 : {
471 : /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */
472 22 : hNoiseEst->Etot_l_lp_fx = mac_r( L_mult( 3277, hNoiseEst->Etot_l_fx ), 29491, hNoiseEst->Etot_l_lp_fx );
473 22 : move16();
474 : }
475 : ELSE
476 : {
477 5118 : test();
478 5118 : test();
479 5118 : test();
480 5118 : test();
481 5118 : IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_16( sub_sat( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_16( sub_sat( hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) )
482 : {
483 : /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */
484 0 : hNoiseEst->Etot_l_lp_fx = mac_r( L_mult( 983, hNoiseEst->Etot_l_fx ), 31785, hNoiseEst->Etot_l_lp_fx );
485 0 : move16();
486 : }
487 : ELSE
488 : {
489 : /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */
490 5118 : hNoiseEst->Etot_l_lp_fx = round_fx( L_mac( L_mult( 655, hNoiseEst->Etot_l_fx ), 32113, hNoiseEst->Etot_l_lp_fx ) );
491 5118 : move16();
492 : }
493 : }
494 : /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/
495 5140 : hNoiseEst->sign_dyn_lp_fx = round_fx( L_mac( L_mult( 3277, sub_sat( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx ) ), 29491, hNoiseEst->sign_dyn_lp_fx ) );
496 5140 : move16();
497 : }
498 :
499 5150 : return;
500 : }
501 :
502 1374528 : void noise_est_pre_32fx(
503 : const Word32 Etot, /* i : Energy of current frame Q24 */
504 : const Word16 ini_frame_fx, /* i : Frame number (init) */
505 : NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */
506 : const Word16 idchan, /* i : channel ID */
507 : const Word16 element_mode, /* i : element mode */
508 : const Word16 last_element_mode /* i : last element mode */
509 : )
510 : {
511 : Word32 tmp;
512 : Word32 Etot_h_32fx;
513 : Word32 Etot_l_32fx;
514 : Word32 Etot_lp_32fx;
515 :
516 1374528 : test();
517 1374528 : test();
518 1374528 : test();
519 1374528 : IF( LE_16( ini_frame_fx, 1 ) || ( EQ_16( idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) )
520 : {
521 25354 : Etot_h_32fx = Etot;
522 25354 : move32();
523 25354 : Etot_l_32fx = Etot;
524 25354 : move32();
525 25354 : hNoiseEst->Etot_l_lp_32fx = Etot; // Q24
526 25354 : move32();
527 25354 : hNoiseEst->Etot_last_32fx = Etot; // Q24
528 25354 : move32();
529 25354 : hNoiseEst->Etot_v_h2_32fx = 0;
530 25354 : move32();
531 25354 : Etot_lp_32fx = Etot;
532 25354 : move32();
533 25354 : hNoiseEst->sign_dyn_lp_fx = 0;
534 25354 : move16();
535 : }
536 : ELSE
537 : {
538 : /* *Etot_lp = 0.20f*Etot + 0.80f* *Etot_lp; */
539 1349174 : Etot_lp_32fx = L_add( Mpy_32_32( 429496730 /* 0.2 in Q31 */, Etot ), Mpy_32_32( 1717986918 /* 0.8 in Q31 */, L_deposit_h( hNoiseEst->Etot_lp_fx ) ) );
540 :
541 1349174 : Etot_h_32fx = L_sub( L_deposit_h( hNoiseEst->Etot_h_fx ), 671089 ); /* 671089=0.04 in Q24 */
542 1349174 : Etot_h_32fx = L_max( Etot_h_32fx, Etot );
543 1349174 : Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, 1342177 ); /* 1342177 = .08 in Q24 */
544 :
545 : /* Could even be higher but it also delays first entry to DTX */
546 1349174 : IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) )
547 : {
548 54252 : test();
549 54252 : IF( ( LT_16( ini_frame_fx, s_min( HE_LT_CNT_INIT_FX, MAX_FRAME_COUNTER - 1 ) ) ) && ( LT_32( L_sub( Etot_h_32fx, Etot_lp_32fx ), (Word32) 3 * ONE_IN_Q24 ) ) /* 3.0 Q24 */
550 : )
551 : {
552 : /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */
553 9132 : tmp = Mpy_32_32( L_sub( ( hNoiseEst->Etot_last_32fx ), Etot_l_32fx ), 214748365 ); /* 0.1f factor in Q31 */
554 9132 : tmp = L_min( 33554432, tmp ); /* 2.0 in Q24 is 33554432 */
555 9132 : Etot_l_32fx = L_add( Etot_l_32fx, tmp ); /* Q24 */
556 : }
557 :
558 : /* Avoids large steps in short active segments */
559 54252 : test();
560 54252 : IF( ( GT_32( L_sub( hNoiseEst->Etot_last_32fx, Etot_l_32fx ), 503316480 ) ) /* 30.0f*Q24 */
561 : && ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_SHORT_FX ) ) )
562 : {
563 : /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */
564 0 : Etot_l_32fx = L_add( Etot_l_32fx, Mpy_32_32( L_sub( hNoiseEst->Etot_last_32fx, Etot_l_32fx ), 42949673 ) ); /* 0.02 in Q24*/
565 : }
566 54252 : ELSE IF( GT_32( L_sub( hNoiseEst->Etot_last_32fx, Etot_l_32fx ), 167772160 ) ) /* 10.0 in Q24*/
567 : {
568 4648 : Etot_l_32fx = L_add( Etot_l_32fx, 1342177 ); /* 0.08 in Q24*/
569 : }
570 : }
571 :
572 1349174 : Etot_l_32fx = L_min( Etot_l_32fx, Etot ); // Q24
573 :
574 1349174 : test();
575 1349174 : IF( LT_16( ini_frame_fx, 100 ) && LT_32( Etot_l_32fx, ( hNoiseEst->Etot_l_lp_32fx ) ) )
576 : {
577 : /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */
578 99129 : hNoiseEst->Etot_l_lp_32fx = W_round64_L( W_add( W_mult_32_32( 214748364 /* 0.1f in Q31*/, Etot_l_32fx ), W_mult_32_32( 1932735283 /* 0.9f in Q31*/, hNoiseEst->Etot_l_lp_32fx ) ) ); // Q8
579 99129 : move16();
580 : }
581 : ELSE
582 : {
583 1250045 : test();
584 1250045 : test();
585 1250045 : test();
586 1250045 : test();
587 1250045 : IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_32( L_sub_sat( hNoiseEst->Etot_last_32fx, Etot_l_32fx ), HE_LT_THR2_Q24 ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_32( L_sub_sat( hNoiseEst->Etot_l_lp_32fx, Etot_l_32fx ), HE_LT_THR2_Q24 ) ) )
588 : {
589 : /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */
590 32238 : hNoiseEst->Etot_l_lp_32fx = W_extract_h( W_add( W_mult_32_32( 64424509 /* 0.03f in Q31*/, Etot_l_32fx ), W_mult_32_32( 2083059139 /* 0.97f in Q31*/, hNoiseEst->Etot_l_lp_32fx ) ) ); // Q24
591 32238 : move16();
592 : }
593 : ELSE
594 : {
595 : /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */
596 1217807 : hNoiseEst->Etot_l_lp_32fx = W_extract_h( W_add( W_mult_32_32( 42949673 /* 0.02f in Q31*/, Etot_l_32fx ), W_mult_32_32( 2104533975 /* 0.98f in Q31*/, hNoiseEst->Etot_l_lp_32fx ) ) ); // Q24
597 1217807 : move16();
598 : }
599 : }
600 : /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/
601 1349174 : hNoiseEst->sign_dyn_lp_fx = extract_h( L_add( Mpy_32_32( 214748365 /* 0.1f in Q31*/, L_sub_sat( Etot_h_32fx, Etot_l_32fx ) ), Mpy_32_32( 1932735283 /*( 1.0f - 0.1f ) in Q31*/, L_deposit_h( hNoiseEst->sign_dyn_lp_fx ) ) ) ); // Q8
602 1349174 : move16();
603 : }
604 :
605 1374528 : hNoiseEst->Etot_l_32fx = Etot_l_32fx; // Q24
606 1374528 : hNoiseEst->Etot_h_fx = extract_h( Etot_h_32fx ); // Q8
607 1374528 : hNoiseEst->Etot_lp_fx = extract_h( Etot_lp_32fx ); // Q8
608 1374528 : move32();
609 1374528 : move16();
610 1374528 : move16();
611 :
612 1374528 : return;
613 : }
614 : /*==================================================================================*/
615 : /* FUNCTION : noise_est_down_fx() */
616 : /*----------------------------------------------------------------------------------*/
617 : /* PURPOSE : Down-ward noise udatation routine */
618 : /*----------------------------------------------------------------------------------*/
619 : /* INPUT ARGUMENTS : */
620 : /* _ (Word32[]) fr_bands : per band input energy Q_new+QSCALE */
621 : /* _ (Word32[]) bckr : per band background noise energy estimate Q_new+QSCALE */
622 : /* _ (Word16 ) min_band : minimum critical band Q0 */
623 : /* _ (Word16 ) max_band : maximum critical band Q0 */
624 : /* _ (Word32[]) bckr_he : per band background noise energy estimate Q_new+QSCALE */
625 : /* _ (Word16 ) Etot : Energy of current frame Q8 */
626 : /* _ (Word16* ) Etot_last : Energy of last frame Q8 */
627 : /* _ (Word16* ) Etot_v_h2 : Energy variaions of noise frames Q8 */
628 : /* _ (Word16 ) Q_new : Qformat */
629 : /*----------------------------------------------------------------------------------*/
630 : /* OUTPUT ARGUMENTS : */
631 : /* _ (Word32[]) bckr : per band background noise energy estimate Q_new+QSCALE */
632 : /* _ (Word32[]) tmpN : temporary noise update Q_new+QSCALE */
633 : /* _ (Word32[]) enr : averaged energy over both subframes Q_new+QSCALE */
634 : /* _ (Word16* ) totalNoise : noise estimate over all critical bands Q8 */
635 : /* _ (Word16 ) Etot : Energy of current frame Q8 */
636 : /* _ (Word16* ) Etot_last : Energy of last frame Q8 */
637 : /* _ (Word16* ) Etot_v_h2 : Energy variaions of noise frames Q8 */
638 : /* _ (Word32[]) tmpN_he1 : temporary noise update 1 Q_new+QSCALE */
639 : /*----------------------------------------------------------------------------------*/
640 :
641 :
642 5150 : void noise_est_down_fx(
643 : const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */
644 : Word32 bckr[], /* i/o: per band background noise energy estimate */
645 : Word32 tmpN[], /* o : temporary noise update */
646 : Word32 enr[], /* o : averaged energy over both subframes */
647 : const Word16 min_band, /* i : minimum critical band */
648 : const Word16 max_band, /* i : maximum critical band */
649 : Word16 *totalNoise, /* o : noise estimate over all critical bands */
650 : Word16 Etot, /* i : Energy of current frame */
651 : Word16 *Etot_last, /* i/o: Energy of last frame Q8 */
652 : Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */
653 : Word16 Q_new,
654 : const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */
655 : )
656 :
657 : {
658 : Word32 Ltmp, L_tmp;
659 : const Word32 *pt1, *pt2;
660 : Word16 i;
661 : Word16 e_Noise, f_Noise;
662 : Word16 scale;
663 : Word32 totalNoise_temp;
664 : Word32 L_Etot, L_Etot_last, L_Etot_v_h2, L_Etot_v;
665 :
666 5150 : L_Etot = L_shl( Etot, 16 ); /*Q24 for later AR1 computations*/
667 5150 : L_Etot_last = L_shl( *Etot_last, 16 );
668 5150 : L_Etot_v_h2 = L_shl( *Etot_v_h2, 16 );
669 5150 : scale = add( Q_new, QSCALE );
670 5150 : move16();
671 :
672 : /*-----------------------------------------------------------------*
673 : * Estimate total noise energy
674 : *-----------------------------------------------------------------*/
675 :
676 5150 : totalNoise_temp = L_deposit_l( 0 );
677 108150 : FOR( i = min_band; i <= max_band; i++ )
678 : {
679 103000 : totalNoise_temp = L_add_sat( totalNoise_temp, bckr[i] ); /*Q_new+QSCALE*/
680 : }
681 5150 : totalNoise_temp = L_max( totalNoise_temp, L_shl( e_min, 4 ) );
682 5150 : totalNoise_temp = L_max( totalNoise_temp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */
683 :
684 : /*totalNoise = 10.0f * (float)log10( *totalNoise );*/
685 5150 : e_Noise = norm_l( totalNoise_temp );
686 5150 : f_Noise = Log2_norm_lc( L_shl( totalNoise_temp, e_Noise ) );
687 5150 : e_Noise = sub( 30, e_Noise );
688 5150 : e_Noise = sub( e_Noise, scale );
689 5150 : Ltmp = Mpy_32_16( e_Noise, f_Noise, LG10 );
690 5150 : *totalNoise = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/
691 5150 : move16();
692 : /*-----------------------------------------------------------------*
693 : * Average energy per frame for each frequency band
694 : *-----------------------------------------------------------------*/
695 :
696 5150 : pt1 = fr_bands; /*Q_new+QSCALE*/
697 5150 : pt2 = fr_bands + NB_BANDS;
698 :
699 108150 : FOR( i = 0; i < NB_BANDS; i++ )
700 : {
701 103000 : Ltmp = L_add_sat( L_shr_r( *pt1, 1 ), L_shr_r( *pt2, 1 ) );
702 : /*Ltmp = L_shr_r(L_add(*pt1,*pt2),1);*/
703 103000 : enr[i] = Ltmp;
704 103000 : move32(); /*Q_new+QSCALE*/
705 103000 : pt1++;
706 103000 : pt2++;
707 : }
708 :
709 : /*-----------------------------------------------------------------*
710 : * Background noise energy update
711 : *-----------------------------------------------------------------*/
712 :
713 108150 : FOR( i = 0; i < NB_BANDS; i++ )
714 : {
715 : /* tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; */
716 103000 : L_tmp = Mult_32_16( enr[i], ALPHA_FX ); /*ALPHA * enr2*/
717 103000 : tmpN[i] = Madd_32_16( L_tmp, bckr[i], ALPHAM1_FX );
718 103000 : move32(); /*Q_new+QSCALE*/
719 103000 : tmpN[i] = L_max( tmpN[i], e_min ); /* handle div by zero in find_tilt_fx */
720 103000 : move32();
721 : /* if( tmpN[i] < bckr[i] ) { bckr[i] = tmpN[i]; }*/
722 : /* Defend to increase noise estimate: keep as it is or decrease */
723 103000 : bckr[i] = L_max( L_min( bckr[i], tmpN[i] ), e_min );
724 103000 : move32(); /*Q_new+QSCALE*/
725 : }
726 :
727 : /*------------------------------------------------------------------*
728 : * Energy variation update
729 : *------------------------------------------------------------------*/
730 : /*Etot_v = (float) fabs(*Etot_last - Etot);*/
731 5150 : L_Etot_v = L_abs( L_sub( L_Etot_last, L_Etot ) ); /* Q24 */
732 :
733 : /* *Etot_v_h2 = (1.0f-0.02f) * *Etot_v_h2 + 0.02f * min(3.0f, Etot_v); */
734 5150 : L_Etot_v_h2 = Mult_32_16( L_Etot_v_h2, 32113 ); /*.98 in Q15 , Q24+Q15+1 -16 => Q24 */
735 5150 : L_Etot_v = L_min( (Word32) ( 3 * ( 1 << 24 ) ), L_Etot_v );
736 5150 : L_tmp = Mult_32_16( L_Etot_v, 655 ); /*.02 in Q15 , Q24+Q15+1 -16 ==> Q24 ) */
737 :
738 5150 : *Etot_v_h2 = round_fx( L_add( L_Etot_v_h2, L_tmp ) ); /*Q24->Q8*/
739 5150 : move16();
740 : /* if (*Etot_v_h2 < 0.1f) { *Etot_v_h2 = 0.1f; } */
741 5150 : *Etot_v_h2 = s_max( *Etot_v_h2, 26 ); /* 0.1 in Q8*/
742 5150 : move16();
743 5150 : return;
744 : }
745 :
746 1374528 : void noise_est_down_ivas_fx(
747 : const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) q_fr_bands */
748 : const Word16 q_fr_bands, /* i : Q of fr_bands */
749 : Word32 bckr[], /* i/o: per band background noise energy estimate q_fr_bands */
750 : Word16 *q_bckr,
751 : Word32 tmpN[], /* o : temporary noise update q_fr_bands */
752 : Word16 *q_tmpN,
753 : Word32 enr[], /* o : averaged energy over both subframes */
754 : Word16 *q_enr,
755 : const Word16 min_band, /* i : minimum critical band */
756 : const Word16 max_band, /* i : maximum critical band */
757 : Word32 *totalNoise, /* o : noise estimate over all critical bands */
758 : Word32 Etot, /* i : Energy of current frame Q24*/
759 : Word32 *Etot_last, /* i/o: Energy of last frame Q24 */
760 : Word32 *Etot_v_h2 /* i/o: Energy variations of noise frames Q24 */
761 : )
762 :
763 : {
764 : Word32 Ltmp, L_tmp;
765 : const Word32 *pt1, *pt2;
766 : Word16 i;
767 : Word16 e_Noise, f_Noise;
768 : Word32 totalNoise_temp;
769 : Word32 L_Etot, L_Etot_last, L_Etot_v_h2, L_Etot_v;
770 : Word64 sum;
771 : Word16 q_sum;
772 : Word32 enr32[NB_BANDS], bckr32[NB_BANDS], tmpN32[NB_BANDS];
773 : Word16 enr_q[NB_BANDS], bckr_q[NB_BANDS], tmpN_q[NB_BANDS];
774 : Word16 shift, shift1, shift2, shift3;
775 : Word64 tmpN64, tmp, enr64;
776 :
777 1374528 : Copy32( bckr, bckr32, NB_BANDS );
778 1374528 : set16_fx( bckr_q, *q_bckr, NB_BANDS );
779 :
780 1374528 : L_Etot = Etot; /*Q24 for later AR1 computations*/
781 1374528 : move32();
782 1374528 : L_Etot_last = *Etot_last;
783 1374528 : L_Etot_v_h2 = *Etot_v_h2;
784 :
785 : /*-----------------------------------------------------------------*
786 : * Estimate total noise energy
787 : *-----------------------------------------------------------------*/
788 :
789 1374528 : totalNoise_temp = L_deposit_l( 0 );
790 1374528 : sum = 0;
791 1374528 : move64();
792 28853004 : FOR( i = min_band; i <= max_band; i++ )
793 : {
794 27478476 : sum = W_mac_32_16( sum, bckr[i], 1 ); // q_fr_bands+1
795 : }
796 1374528 : q_sum = add( *q_bckr, 1 );
797 1374528 : IF( sum == 0 )
798 : {
799 0 : sum = W_mult0_32_32( E_MIN_FXQ31, add( sub( max_band, min_band ), 1 ) ); // Q31
800 0 : q_sum = Q31;
801 0 : move16();
802 : }
803 1374528 : e_Noise = W_norm( sum );
804 1374528 : totalNoise_temp = W_extract_h( W_shl( sum, e_Noise ) ); // q_sum+e_Noise-32
805 1374528 : e_Noise = sub( 63, add( e_Noise, q_sum ) ); // 31-(q_sum+e_Noise-32)
806 :
807 : /*totalNoise = 10.0f * (float)log10( *totalNoise );*/
808 1374528 : f_Noise = Log2_norm_lc( totalNoise_temp ); // exponent of log => 30-0 = 30
809 1374528 : e_Noise = sub( e_Noise, 1 ); // 30-(31-e_Noise) = e_Noise-1
810 1374528 : Ltmp = L_mac( L_deposit_h( e_Noise ), f_Noise, 1 ); // Q16
811 1374528 : Ltmp = Mpy_32_16_1( Ltmp, LG10 ); // Q14 (16+13-15)
812 1374528 : Ltmp = L_shl( Ltmp, 10 ); // Q26
813 1374528 : *totalNoise = ( Ltmp ); /*Q24*/
814 1374528 : move32();
815 :
816 : /*-----------------------------------------------------------------*
817 : * Average energy per frame for each frequency band
818 : *-----------------------------------------------------------------*/
819 :
820 1374528 : pt1 = fr_bands;
821 1374528 : pt2 = fr_bands + NB_BANDS;
822 :
823 28865088 : FOR( i = 0; i < NB_BANDS; i++ )
824 : {
825 : /* enr[i] = 0.5f * ( *pt1++ + *pt2++ ); */
826 27490560 : enr64 = W_mac_32_32( W_mult_32_32( *pt1, ONE_IN_Q29 ), *pt2, ONE_IN_Q29 ); // q_fr_bands + 1 + Q29 + 1 (0.5 handle here)
827 27490560 : shift = W_norm( enr64 );
828 27490560 : enr32[i] = W_extract_h( W_shl( enr64, shift ) );
829 27490560 : move32();
830 27490560 : enr_q[i] = sub( add( q_fr_bands, shift ), 1 );
831 27490560 : move16();
832 27490560 : pt1++;
833 27490560 : pt2++;
834 : }
835 :
836 : /*-----------------------------------------------------------------*
837 : * Background noise energy update
838 : *-----------------------------------------------------------------*/
839 28865088 : FOR( i = 0; i < NB_BANDS; i++ )
840 : {
841 : /* tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; */
842 : /* handle div by zero in find_tilt_fx */
843 :
844 27490560 : tmpN64 = W_mult_32_16( bckr32[i], ALPHAM1_FX );
845 27490560 : tmp = W_mult_32_16( enr32[i], ALPHA_FX );
846 :
847 27490560 : shift = s_min( bckr_q[i], enr_q[i] );
848 27490560 : tmpN64 = W_add( W_shl( tmpN64, sub( shift, bckr_q[i] ) ), W_shl( tmp, sub( shift, enr_q[i] ) ) ); // shift + q16
849 27490560 : shift1 = W_norm( tmpN64 );
850 27490560 : tmpN32[i] = W_extract_h( W_shl( tmpN64, shift1 ) ); // shift + q16 + shift1 - 32
851 27490560 : move32();
852 27490560 : tmpN_q[i] = sub( add( add( Q16, shift ), shift1 ), 32 );
853 27490560 : move16();
854 :
855 27490560 : IF( GT_32( E_MIN_FXQ31, L_shl_sat( tmpN32[i], sub( 31, tmpN_q[i] ) ) ) )
856 : {
857 673859 : tmpN32[i] = E_MIN_FXQ31;
858 673859 : tmpN_q[i] = 31;
859 673859 : move32();
860 673859 : move16();
861 : }
862 :
863 27490560 : IF( GT_32( bckr32[i], L_shl_sat( tmpN32[i], sub( bckr_q[i], tmpN_q[i] ) ) ) )
864 : {
865 1701140 : bckr32[i] = tmpN32[i]; /* Defend to increase noise estimate: keep as it is or decrease */
866 1701140 : bckr_q[i] = tmpN_q[i];
867 1701140 : move32();
868 1701140 : move16();
869 : }
870 : }
871 :
872 : /* Scaling to common Q*/
873 1374528 : shift1 = bckr_q[0], shift2 = enr_q[0], shift3 = tmpN_q[0];
874 1374528 : move16();
875 1374528 : move16();
876 1374528 : move16();
877 :
878 27490560 : FOR( i = 1; i < NB_BANDS; i++ )
879 : {
880 26116032 : shift1 = s_min( shift1, bckr_q[i] );
881 26116032 : shift2 = s_min( shift2, enr_q[i] );
882 26116032 : shift3 = s_min( shift3, tmpN_q[i] );
883 : }
884 28865088 : FOR( i = 0; i < NB_BANDS; i++ )
885 : {
886 27490560 : bckr[i] = L_shl( bckr32[i], sub( shift1, bckr_q[i] ) );
887 27490560 : enr[i] = L_shl( enr32[i], sub( shift2, enr_q[i] ) );
888 27490560 : tmpN[i] = L_shl( tmpN32[i], sub( shift3, tmpN_q[i] ) );
889 27490560 : move32();
890 27490560 : move32();
891 27490560 : move32();
892 : }
893 1374528 : *q_bckr = shift1;
894 1374528 : *q_enr = shift2;
895 1374528 : *q_tmpN = shift3;
896 1374528 : move16();
897 1374528 : move16();
898 1374528 : move16();
899 : /*------------------------------------------------------------------*
900 : * Energy variation update
901 : *------------------------------------------------------------------*/
902 : /*Etot_v = (float) fabs(*Etot_last - Etot);*/
903 1374528 : L_Etot_v = L_abs( L_sub( L_Etot_last, L_Etot ) ); /* Q24 */
904 :
905 : /* *Etot_v_h2 = (1.0f-0.02f) * *Etot_v_h2 + 0.02f * min(3.0f, Etot_v); */
906 1374528 : L_tmp = L_min( 50331648 /* 3.0f in Q24 */, L_Etot_v ); // Q24
907 1374528 : L_tmp = Mult_32_16( L_tmp, 655 /*.02 in Q15 */ ); // Q24
908 1374528 : L_Etot_v_h2 = Madd_32_16( L_tmp, L_Etot_v_h2, 32113 /* 0.98 in Q15 */ ); // Q24
909 :
910 : /* if (*Etot_v_h2 < 0.1f) { *Etot_v_h2 = 0.1f; } */
911 1374528 : *Etot_v_h2 = L_max( L_Etot_v_h2, 1677722 /* 0.1 in Q24*/ ); // Q24
912 1374528 : move16();
913 :
914 1374528 : return;
915 : }
916 :
917 : /*-----------------------------------------------------------------*
918 : * noise_est_fx()
919 : *
920 : * Noise energy estimation (noise energy is updated in case of noise-only frame)
921 : *-----------------------------------------------------------------*/
922 5150 : void noise_est_fx(
923 : Encoder_State *st_fx, /* i/o: state structure */
924 : const Word16 old_pitch1, /* i : previous frame OL pitch[1] */
925 : const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */
926 : const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */
927 : const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */
928 : const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */
929 : const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */
930 : const Word16 corr_shift, /* i : normalized correlation correction Q15 */
931 : const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */
932 : Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */
933 : Word16 *cor_map_sum, /* o : Q8 */
934 : Word16 *ncharX, /* o : IVAS_CODE -> size of ncharX needs validation noise character for sp/mus classifier Qx? */
935 : Word16 *sp_div, /* o : Q_sp_div */
936 : Word16 *Q_sp_div, /* o : Q factor for sp_div */
937 : Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */
938 : Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */
939 : const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */
940 : Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */
941 : const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */
942 : const Word16 Etot_v_h2, /* i : Energy variations Q8 */
943 : Word16 *bg_cnt, /* i : Background burst length timer Q0 */
944 : Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */
945 : Word16 Q_new, /* i : SCaling of current frame */
946 : const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */
947 : Word16 *sp_floor, /* o : noise floor estimate Q7 */
948 : Word16 S_map[], /* o : short-term correlation map Q7 */
949 : const Word16 ini_frame /* i : Frame number (init) */
950 : )
951 : {
952 : Word16 alpha, alpha2, alpha2m1, alpham1;
953 : Word16 cor_min, cor_max, num, den, ExpNum, ExpDen, noise_chartmp;
954 : Word16 wtmp1, wtmp, ExpLmax, ExpLmax2, tmpExp, nchar_thr, cor_tmp;
955 : Word16 i, tmp_pc, pc, th_eps;
956 : Word32 th_sta, Lnum, Lden, non_sta, LepsP, Ltmpden;
957 : Word16 e_ener, f_ener;
958 : Word32 Ltmp, Ltmp1, Lsum_num, Lsum_den, *pt1, *pt2, Ltmp2, Lnon_sta2;
959 : Word16 spec_div, noise_char;
960 : Word16 log_enr16;
961 : Word16 updt_step; /* Q15 */
962 : Word16 aE_bgd, sd1_bgd, bg_bgd2;
963 : Word16 tn_ini;
964 : Word16 epsP_0_2, epsP_0_2_ad, epsP_0_2_ad_lp_max;
965 : Word16 epsP_2_16, epsP_2_16_dlp, epsP_2_16_dlp_max;
966 : Word16 PAU, BG_1, NEW_POS_BG;
967 :
968 : Word16 haco_ev_max;
969 : Word16 Etot_l_lp_thr;
970 : Word16 comb_ahc_epsP, comb_hcm_epsP;
971 :
972 : Word16 enr_bgd, cns_bgd, lp_bgd, ns_mask;
973 : Word16 lt_haco_mask, bg_haco_mask;
974 : Word16 SD_1, SD_1_inv, bg_bgd3, PD_1, PD_2, PD_3, PD_4, PD_5;
975 :
976 : Word16 non_staB; /* Q8 */
977 : Word32 L_tmp_enr, L_tmp_ave_enr, L_tmp_ave_enr2;
978 : Word16 tmp_Q;
979 : Word16 tmp, tmp2; /* general temp registers */
980 : Word16 tmp_enr, tmp_floor; /* constants in Q8 */
981 : Word16 vad_bwidth_fx; /* vad ns control variabel for input bwidth from teh BWD */
982 : /* for DTX operation */
983 : Word16 vad_2nd_stage_fx;
984 :
985 : Word16 lim_Etot_fx; /* Q8 */
986 : Word16 lim_Etot_sq_fx; /* Q2 */
987 : Word16 st_E_var_est_fx; /* Q2 */
988 : NOISE_EST_HANDLE hNoiseEst;
989 : SP_MUS_CLAS_HANDLE hSpMusClas;
990 5150 : hSpMusClas = st_fx->hSpMusClas;
991 : (void) ( ncharX );
992 5150 : hNoiseEst = st_fx->hNoiseEst;
993 5150 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
994 :
995 : /*-----------------------------------------------------------------*
996 : * Initialization
997 : *-----------------------------------------------------------------*/
998 5150 : vad_bwidth_fx = st_fx->input_bwidth;
999 5150 : move16();
1000 :
1001 : /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/
1002 : {
1003 5150 : IF( hSpMusClas != NULL )
1004 : {
1005 5150 : Ltmp = L_shr( lf_E[0], 3 );
1006 41200 : FOR( i = 1; i < 8; i++ )
1007 : {
1008 36050 : Ltmp = L_add( Ltmp, L_shr( lf_E[i], 3 ) );
1009 : }
1010 5150 : IF( LT_32( Ltmp, L_shl( 1, add( Q_new, Q_SCALE - 2 ) ) ) )
1011 : {
1012 119 : hSpMusClas->ener_RAT_fx = 0;
1013 119 : move16();
1014 : }
1015 : ELSE
1016 : {
1017 5031 : Ltmp = L_max( Ltmp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */
1018 5031 : e_ener = norm_l( Ltmp );
1019 5031 : f_ener = Log2_norm_lc( L_shl( Ltmp, e_ener ) );
1020 5031 : e_ener = sub( 30, e_ener );
1021 5031 : e_ener = sub( e_ener, sub( add( Q_new, QSCALE ), 2 ) );
1022 5031 : Ltmp = Mpy_32_16( e_ener, f_ener, LG10 );
1023 5031 : wtmp = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/
1024 :
1025 : /* st_fx->ener_RAT /= (Etot + 0.01f); */
1026 5031 : wtmp1 = add( Etot, 3 ); /*3 is 0.01 in Q8 */
1027 : /* st_fx->ener_RAT_fx = wtmp/wtmp1 */
1028 5031 : hSpMusClas->ener_RAT_fx = 0;
1029 5031 : move16();
1030 5031 : IF( wtmp > 0 )
1031 : {
1032 5031 : hSpMusClas->ener_RAT_fx = 32767;
1033 5031 : move16(); /*Q15*/
1034 5031 : IF( GE_16( wtmp1, wtmp ) )
1035 : {
1036 5031 : hSpMusClas->ener_RAT_fx = div_s( wtmp, wtmp1 ); /*Q15*/ /* wtmp1 gte than wtmp */
1037 5031 : move16();
1038 : }
1039 : }
1040 : }
1041 : }
1042 : }
1043 :
1044 : /*-----------------------------------------------------------------*
1045 : * Set the threshold for eps & non_sta based on input sampling rate
1046 : * The reason is that in case of 8kHz sampling input, there is nothing
1047 : * between 4kHz-6.4kHz. In noisy conditions, this makes a fast
1048 : * transition even in noise-only parts, hence producing a "higher
1049 : * order" spectral envelope => the epsP ratio is much less effective.
1050 : *-----------------------------------------------------------------*/
1051 :
1052 5150 : IF( vad_bwidth_fx != NB ) /* WB input */
1053 : {
1054 5150 : th_eps = TH_EPS16_FX;
1055 5150 : move16(); /*Q11*/
1056 5150 : th_sta = TH_STA16_FX;
1057 5150 : move16(); /*Q10 */
1058 5150 : cor_min = COR_MIN16_FX;
1059 5150 : move16(); /*Q15*/
1060 5150 : cor_max = COR_MAX16_FX;
1061 5150 : move16(); /*Q15*/
1062 : }
1063 : ELSE /* NB input */
1064 : {
1065 0 : th_eps = TH_EPS8_FX;
1066 0 : move16(); /* Q11 */
1067 0 : th_sta = TH_STA8_FX;
1068 0 : move16(); /* Q10 */
1069 0 : cor_min = COR_MIN8_FX;
1070 0 : move16();
1071 0 : cor_max = COR_MAX8_FX;
1072 0 : move16();
1073 : }
1074 :
1075 : /*-----------------------------------------------------------------*
1076 : * Estimation of pitch stationarity
1077 : *-----------------------------------------------------------------*/
1078 :
1079 : /* pc = abs(pit[0] - pitO) + abs(pit[1] - pit[0]) */ /* needed in signal_clas() */
1080 5150 : wtmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) );
1081 5150 : wtmp1 = abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) );
1082 5150 : pc = add( wtmp, wtmp1 );
1083 :
1084 :
1085 5150 : Ltmp = L_deposit_h( corr_shift );
1086 5150 : Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 );
1087 5150 : Ltmp = L_mac_sat( Ltmp, st_fx->voicing_fx[1], 10923 );
1088 5150 : wtmp = mac_r_sat( Ltmp, st_fx->voicing_fx[2], 10923 );
1089 :
1090 5150 : tmp_pc = pc;
1091 5150 : move16();
1092 5150 : if ( LT_16( wtmp, cor_min ) )
1093 : {
1094 294 : tmp_pc = TH_PC_FX;
1095 294 : move16(); /* low correlation -> probably inactive signal */
1096 : }
1097 :
1098 : /* Update */
1099 :
1100 : /*-----------------------------------------------------------------*
1101 : * Multi-harmonic analysis
1102 : *-----------------------------------------------------------------*/
1103 :
1104 5150 : IF( st_fx->hSpMusClas != NULL )
1105 : {
1106 5150 : i = 0;
1107 5150 : move16();
1108 5150 : *loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
1109 10300 : st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map );
1110 5150 : move16();
1111 : }
1112 :
1113 : /*-----------------------------------------------------------------*
1114 : * Detection of frames with non-stationary spectral content
1115 : *-----------------------------------------------------------------*/
1116 :
1117 : /* weighted sum of spectral changes per critical bands */
1118 5150 : Lsum_num = L_deposit_l( 0 );
1119 5150 : Lsum_den = L_deposit_l( 0 );
1120 :
1121 : /* Find a proper scaling to prevent overflow, but acheiving good computation on low level signals */
1122 5150 : tmpExp = 0;
1123 5150 : move16();
1124 5150 : ExpLmax = sub( 30, norm_l( fr_bands[10] ) );
1125 5150 : ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[10] ) );
1126 5150 : tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) );
1127 51500 : FOR( i = 11; i <= st_fx->max_band; i++ )
1128 : {
1129 46350 : ExpLmax = sub( 30, norm_l( fr_bands[i] ) );
1130 46350 : ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[i] ) );
1131 46350 : tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) );
1132 : }
1133 5150 : tmpExp = sub( tmpExp, 30 - 4 - 4 ); /* 4bits for internal summation and 4 bits for comparaison */
1134 :
1135 5150 : pt1 = fr_bands + 10;
1136 5150 : pt2 = hNoiseEst->fr_bands2_fx + 10;
1137 56650 : FOR( i = 10; i <= st_fx->max_band; i++ )
1138 : {
1139 51500 : Lnum = L_max( *pt1, *pt2 ); /* Don't need if anymore */
1140 51500 : Lsum_den = L_add_sat( Lsum_den, Lnum );
1141 51500 : Ltmpden = L_min( *pt1, *pt2 );
1142 51500 : if ( Ltmpden == 0 )
1143 : {
1144 0 : Ltmpden = L_add( Ltmpden, 1 );
1145 : }
1146 51500 : ExpNum = sub( norm_l( Lnum ), 1 );
1147 51500 : num = extract_h( L_shl( Lnum, ExpNum ) );
1148 51500 : num = mult_r( num, num );
1149 51500 : ExpDen = norm_l( Ltmpden );
1150 51500 : den = extract_h( L_shl( Ltmpden, ExpDen ) );
1151 51500 : num = div_s( num, den );
1152 51500 : Ltmp = L_shr( num, add( sub( sub( shl( ExpNum, 1 ), ExpDen ), 15 + 1 ), tmpExp ) );
1153 51500 : Lsum_num = L_add( Lsum_num, Ltmp );
1154 :
1155 51500 : pt1++;
1156 51500 : pt2++;
1157 : }
1158 5150 : Lsum_den = L_shr( Lsum_den, tmpExp );
1159 :
1160 :
1161 : /* calculation of spectral diversity */
1162 : /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */
1163 5150 : spec_div = 0;
1164 5150 : move16();
1165 5150 : if ( GT_32( Mult_32_16( Lsum_num, 6554 ), Lsum_den ) ) /* Qx+Q15+1-16 ==> Qx */
1166 : {
1167 2533 : spec_div = 1;
1168 2533 : move16();
1169 : }
1170 :
1171 : /* *sp_div = Lsum_num / (Lsum_den + 1e-5f); */
1172 5150 : ExpNum = sub( norm_l( Lsum_num ), 1 );
1173 5150 : num = extract_h( L_shl( Lsum_num, ExpNum ) );
1174 :
1175 5150 : Lsum_den = L_add( Lsum_den, 1 );
1176 :
1177 5150 : ExpDen = norm_l( Lsum_den );
1178 5150 : den = extract_h( L_shl( Lsum_den, ExpDen ) );
1179 :
1180 5150 : *sp_div = div_s( num, den );
1181 5150 : move16();
1182 :
1183 5150 : *Q_sp_div = add( 15, sub( ExpNum, ExpDen ) );
1184 5150 : move16();
1185 :
1186 : /*-----------------------------------------------------------------*
1187 : * Detection of frames with high energy content in high frequencies
1188 : *-----------------------------------------------------------------*/
1189 :
1190 : /* calculation of energy in first 10 critical bands */
1191 5150 : Ltmp = sum32_fx( &fr_bands[st_fx->min_band], sub( 10, st_fx->min_band ) );
1192 :
1193 : /* calculation of energy in the rest of bands */
1194 5150 : Ltmp2 = sum32_fx( &fr_bands[10], sub( st_fx->max_band, 9 ) );
1195 :
1196 5150 : wtmp = shl_sat( 1, sub( add( Q_new, QSCALE ), 1 ) );
1197 :
1198 5150 : test();
1199 5150 : IF( L_msu( Ltmp, 100, wtmp ) < 0 || L_msu( Ltmp2, 100, wtmp ) < 0 )
1200 : {
1201 1422 : noise_chartmp = 0;
1202 1422 : move16();
1203 : }
1204 : ELSE
1205 : {
1206 : /* ftemp2 /= ftemp */
1207 3728 : ExpNum = sub( norm_l( Ltmp2 ), 1 );
1208 3728 : num = extract_h( L_shl( Ltmp2, ExpNum ) );
1209 :
1210 3728 : ExpDen = norm_l( Ltmp );
1211 3728 : den = extract_h( L_shl( Ltmp, ExpDen ) );
1212 3728 : num = div_s( num, den );
1213 3728 : noise_chartmp = extract_h( L_shr_sat( num, add( sub( ExpNum, ExpDen ), 4 - 16 ) ) ); /* Q11 */
1214 : }
1215 :
1216 5150 : noise_chartmp = s_min( noise_chartmp, (Word16) 10 << 11 ); /* Q11 */
1217 :
1218 : /* update LT value of the final parameter */
1219 : /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */
1220 5150 : hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp );
1221 :
1222 :
1223 5150 : nchar_thr = THR_NCHAR_WB_FX;
1224 5150 : move16(); /* 1.0 Q11 */
1225 5150 : if ( vad_bwidth_fx == NB )
1226 : {
1227 0 : nchar_thr = THR_NCHAR_NB_FX;
1228 0 : move16(); /* 1.0 Q11 */
1229 : }
1230 :
1231 5150 : noise_char = 0;
1232 5150 : move16();
1233 5150 : if ( GT_16( hNoiseEst->noise_char_fx, nchar_thr ) )
1234 : {
1235 992 : noise_char = 1;
1236 992 : move16();
1237 : }
1238 :
1239 : /* save the 2 last spectra per crit. bands for the future */
1240 5150 : Copy32( hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS );
1241 5150 : Copy32( fr_bands + NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS );
1242 :
1243 : /*-----------------------------------------------------------------*
1244 : * Non-stationarity estimation for each band
1245 : * Handicap high E frames in average computing
1246 : *-----------------------------------------------------------------*/
1247 :
1248 : /* set averaging factor */
1249 : /* ftemp = relE; */
1250 : /* if( ftemp < 0.0f ) { ftemp = 0.0f; } */
1251 5150 : tmp = s_max( relE, 0 ); /* Q8 */
1252 :
1253 : /* alpha = 0.064f * ftemp + 0.75f; */
1254 5150 : Ltmp = Mult_32_16( (Word32) 137438953L, tmp ); /* Q31(.064)+Q8+1-16 --> Q24 */
1255 5150 : Ltmp = L_mac( Ltmp, 256, 24576 ); /* Q8+Q15(.75)+1 --> Q24 */
1256 5150 : alpha = round_fx_sat( L_shl_sat( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/
1257 :
1258 : /*if( alpha > 0.999f { alpha = 0.999f;} */
1259 5150 : alpha = s_min( alpha, 32735 ); /*.999 in Q15*/
1260 5150 : alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */
1261 : /*--------------------------------------------------------------*
1262 : * during significant attacks, replace the LT energy by the
1263 : * current energy this will cause non_sta2 failures to occur in
1264 : * different frames than non_sta failures
1265 : *--------------------------------------------------------------*/
1266 :
1267 5150 : alpha2 = alpha;
1268 5150 : move16();
1269 5150 : alpha2m1 = alpham1;
1270 5150 : move16();
1271 5150 : IF( spec_div > 0 )
1272 : {
1273 2533 : alpha2 = 0;
1274 2533 : move16();
1275 2533 : alpha2m1 = 32767;
1276 2533 : move16();
1277 : }
1278 5150 : Lnon_sta2 = L_deposit_l( 1 << 10 );
1279 :
1280 5150 : non_sta = L_deposit_l( 1 << 10 );
1281 5150 : *non_staX = 0;
1282 5150 : move16();
1283 5150 : non_staB = 0;
1284 5150 : move16();
1285 :
1286 108150 : FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ )
1287 : {
1288 : /* + 1.0f added to reduce sensitivity to non stationarity in low energies */
1289 : /* tmp_enr = enr[i] + 1.0f; */
1290 103000 : tmp_Q = add( Q_new, Q_SCALE );
1291 103000 : Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */
1292 103000 : L_tmp_enr = L_add_sat( enr[i], Ltmp ); /* enr scale dynamic */
1293 103000 : L_tmp_ave_enr = L_add_sat( hNoiseEst->ave_enr_fx[i], Ltmp ); /* ave__enr scale dynamic */
1294 :
1295 103000 : IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */
1296 : {
1297 : /* if( enr[i] > st_ave_enr2[i] ) */
1298 : /* non_sta2 = non_sta2 * ((enr[i]+1) / (st_ave_enr2[i]+1)) */
1299 56609 : Lnum = L_max( L_tmp_enr, L_tmp_ave_enr );
1300 :
1301 : /* else */
1302 : /* non_sta2 = non_sta2 * ((st_ave_enr2[i]+1) / (enr[i]+1)) */
1303 56609 : Lden = L_min( L_tmp_enr, L_tmp_ave_enr );
1304 :
1305 56609 : ExpNum = sub( norm_l( Lnum ), 1 );
1306 56609 : num = extract_h( L_shl( Lnum, ExpNum ) );
1307 56609 : Lnum = L_shl( Lnum, ExpNum );
1308 56609 : ExpDen = norm_l( Lden );
1309 56609 : den = extract_h( L_shl( Lden, ExpDen ) );
1310 56609 : num = div_s( num, den );
1311 56609 : Ltmp = Mult_32_16( non_sta, num );
1312 56609 : non_sta = L_shr_sat( Ltmp, sub( ExpNum, ExpDen ) ); /* Q10 */
1313 : }
1314 :
1315 : /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */
1316 103000 : Ltmp = Mult_32_16( hNoiseEst->ave_enr_fx[i], alpha );
1317 103000 : Ltmp = L_add( Ltmp, Mult_32_16( enr[i], alpham1 ) );
1318 103000 : hNoiseEst->ave_enr_fx[i] = L_max( Le_min_scaled, Ltmp );
1319 103000 : move32();
1320 :
1321 : /* calculation of another non-stationarity measure (following attacks) */
1322 : /*if( non_sta2 <= th_sta ){
1323 : tmp_ave2 = st->ave_enr2[i] + 1.0f;
1324 : if( tmp_enr > tmp_ave2 ){
1325 : non_sta2 = non_sta2 * ( tmp_enr / tmp_ave2 );
1326 : } else {
1327 : non_sta2 = non_sta2 * (tmp_ave2 / tmp_enr );
1328 : }
1329 : } */
1330 :
1331 : /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */
1332 103000 : Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */
1333 : /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */
1334 103000 : L_tmp_ave_enr2 = L_add_sat( hNoiseEst->ave_enr2_fx[i], Ltmp ); /* ave__enr scale dynamic */
1335 103000 : IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */
1336 : {
1337 77315 : Lnum = L_max( L_tmp_enr, L_tmp_ave_enr2 );
1338 77315 : Lden = L_min( L_tmp_enr, L_tmp_ave_enr2 );
1339 :
1340 77315 : ExpNum = sub( norm_l( Lnum ), 1 );
1341 77315 : num = extract_h( L_shl( Lnum, ExpNum ) );
1342 77315 : Lnum = L_shl( Lnum, ExpNum );
1343 77315 : ExpDen = norm_l( Lden );
1344 77315 : den = extract_h( L_shl( Lden, ExpDen ) );
1345 77315 : num = div_s( num, den );
1346 77315 : Ltmp1 = Mult_32_16( Lnon_sta2, num );
1347 77315 : Lnon_sta2 = L_shr_sat( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */
1348 : }
1349 :
1350 : /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i]
1351 : + (1.0f - alpha2) * (enr[i]) */
1352 103000 : Ltmp1 = Mult_32_16( hNoiseEst->ave_enr2_fx[i], alpha2 );
1353 103000 : Ltmp1 = L_add( Ltmp1, Mult_32_16( enr[i], alpha2m1 ) );
1354 103000 : hNoiseEst->ave_enr2_fx[i] = L_max( Le_min_scaled, Ltmp1 );
1355 103000 : move32();
1356 :
1357 : /* calculation of non-stationarity measure for speech/music classification */
1358 : {
1359 103000 : test();
1360 103000 : test();
1361 103000 : IF( GE_16( i, START_BAND_SPMUS ) && LT_16( i, NB_BANDS_SPMUS + START_BAND_SPMUS ) && st_fx->hSpMusClas != NULL )
1362 : {
1363 : /* log_enr = (float)ln_fx(enr[i]); */
1364 77250 : log_enr16 = noise_est_ln_q8_fx( enr[i], 0, tmp_Q );
1365 77250 : wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) );
1366 77250 : *non_staX = add_sat( *non_staX, wtmp );
1367 77250 : move16(); /* Q8 */
1368 77250 : hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16;
1369 77250 : move16();
1370 : }
1371 : }
1372 103000 : test();
1373 103000 : IF( GE_16( i, 2 ) && LE_16( i, 16 ) )
1374 : {
1375 77250 : IF( GE_16( ini_frame, 100 ) )
1376 : {
1377 : /* calculate non-stationarity feature relative background */
1378 69750 : tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */
1379 69750 : tmp_floor = LN_E_MIN_PLUS_ONE_FX;
1380 69750 : move16(); /* non dynamic init constant in Q8 */
1381 69750 : tmp_floor = noise_est_ln_q8_fx( hNoiseEst->bckr_fx[i], 1, tmp_Q );
1382 69750 : non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */
1383 : }
1384 : ELSE /*ini_frame < 100*/
1385 : {
1386 : /* calculate non-stationarity feature relative background */
1387 7500 : tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */
1388 7500 : tmp_floor = LN_E_MIN_PLUS_ONE_FX;
1389 7500 : move16(); /* non dynamic init constant in Q8 */
1390 7500 : tmp_floor = noise_est_ln_q8_fx( E_MIN_FX, 1, tmp_Q );
1391 7500 : non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */
1392 : }
1393 : }
1394 :
1395 : } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */
1396 :
1397 5150 : IF( LT_16( Etot, -1280 ) )
1398 : {
1399 12 : non_sta = L_deposit_l( 1024 ); /* 1.0 in Q10 */
1400 12 : Lnon_sta2 = L_deposit_l( 1024 ); /* 1.0 in Q10 */
1401 : }
1402 :
1403 5150 : lim_Etot_fx = s_max( 5120, Etot ); /* 20.0f Q8 */
1404 5150 : lim_Etot_sq_fx = extract_h( L_shl_r( L_mult( lim_Etot_fx, lim_Etot_fx ), 1 ) ); /* Q2 */
1405 :
1406 5150 : IF( LT_16( st_fx->ini_frame, 150 ) )
1407 : {
1408 : /* Allow use of quicker filter during init - if needed */
1409 : /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */
1410 750 : hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx );
1411 750 : move16();
1412 : /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */
1413 750 : hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx );
1414 750 : move16();
1415 : }
1416 : ELSE
1417 : {
1418 : /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */
1419 4400 : hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx );
1420 4400 : move16();
1421 : /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */
1422 4400 : hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx );
1423 4400 : move16();
1424 : }
1425 :
1426 5150 : st_E_var_est_fx = sub( hNoiseEst->Etot_sq_st_est_fx, extract_h( L_shl_r( L_mult( hNoiseEst->Etot_st_est_fx, hNoiseEst->Etot_st_est_fx ), 1 ) ) );
1427 :
1428 :
1429 : /*-----------------------------------------------------------------*
1430 : * Count frames since last correlation or harmonic event
1431 : *-----------------------------------------------------------------*/
1432 :
1433 5150 : Ltmp = L_mult( st_fx->voicing_fx[0], 16384 );
1434 5150 : Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 );
1435 :
1436 5150 : test();
1437 5150 : test();
1438 5150 : *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 );
1439 5150 : move16();
1440 5150 : if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_16( round_fx( Ltmp ), COR_MAX_NNE_FX ) ) ) )
1441 : {
1442 4194 : *st_harm_cor_cnt = 0;
1443 4194 : move16();
1444 : }
1445 5150 : test();
1446 5150 : test();
1447 5150 : test();
1448 5795 : if ( ( GT_16( *st_harm_cor_cnt, 1 ) ) && ( ( LT_16( Etot, 3840 ) ) || /* 15 in Q8 */
1449 1265 : ( GT_16( st_fx->ini_frame, 10 ) &&
1450 620 : GT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) ) /* 7 in Q8 */
1451 : )
1452 : {
1453 230 : *st_harm_cor_cnt = 1;
1454 : }
1455 5150 : test();
1456 5150 : test();
1457 5688 : if ( GT_16( *st_harm_cor_cnt, 1 ) &&
1458 905 : GT_16( Etot, 7680 ) && /* 30.0f in Q8 */
1459 367 : GT_16( st_E_var_est_fx, 32 ) /* 8.0f in Q2 */
1460 : )
1461 : {
1462 :
1463 : /* st->harm_cor_cnt = max(1, (short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; */
1464 341 : *st_harm_cor_cnt = s_max( 1, shr( add( *st_harm_cor_cnt, 2 ), 1 ) );
1465 341 : move16();
1466 : }
1467 :
1468 :
1469 : /*-----------------------------------------------------------------*
1470 : * Energy based pause length counter
1471 : *-----------------------------------------------------------------*/
1472 5150 : test();
1473 5150 : IF( ( *bg_cnt >= 0 ) && ( GT_16( sub( Etot, Etot_l_lp ), 1280 ) /*5.0 in Q8*/ ) )
1474 : {
1475 : /* Possible speech burst */
1476 53 : *bg_cnt = -1;
1477 53 : move16();
1478 : }
1479 : ELSE
1480 : {
1481 5097 : test();
1482 5097 : if ( EQ_16( *bg_cnt, -1 ) && ( LT_16( sub( Etot, Etot_l_lp ), 1280 ) ) /*5 in Q8*/ )
1483 : {
1484 : /* Possible start of speech pause */
1485 53 : *bg_cnt = 0;
1486 53 : move16();
1487 : }
1488 : }
1489 5150 : if ( *bg_cnt >= 0 )
1490 : {
1491 354 : *bg_cnt = add( *bg_cnt, 1 );
1492 354 : move16();
1493 : }
1494 :
1495 : /*-----------------------------------------------------------------*
1496 : * Linear predition efficiency 0 to 2 order
1497 : *-----------------------------------------------------------------*/
1498 :
1499 : /*epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); */
1500 5150 : Ltmp = eps_quota_fx( epsP_h[0], epsP_l[0],
1501 5150 : epsP_h[2], epsP_l[2], 12 ); /* Word32 Q12 */
1502 : BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/
1503 5150 : epsP_0_2 = round_fx_sat( L_shl_sat( Ltmp, 16 ) );
1504 : /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */
1505 : BASOP_SATURATE_WARNING_ON_EVS
1506 :
1507 5150 : epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */
1508 :
1509 :
1510 : /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */
1511 5150 : alpha = 4915;
1512 5150 : move16(); /*0.15 in Q15 */
1513 5150 : hNoiseEst->epsP_0_2_lp_fx = noise_est_AR1_Qx( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx, alpha );
1514 5150 : move16();
1515 : /* epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); */
1516 5150 : epsP_0_2_ad = abs_s( sub( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx ) ); /* Q12 */
1517 :
1518 : /*if (epsP_0_2_ad < st->epsP_0_2_ad_lp) {
1519 : st->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + (1.0f - 0.1f) * st->epsP_0_2_ad_lp;
1520 : } else {
1521 : st->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + (1.0f - 0.2f) * st->epsP_0_2_ad_lp;
1522 : } */
1523 5150 : alpha = 6554;
1524 5150 : move16(); /* 0.2 Q15 */
1525 5150 : if ( LT_16( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ) )
1526 : {
1527 3772 : alpha = shr( alpha, 1 ); /* 0.1 Q15 */
1528 : }
1529 5150 : hNoiseEst->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx, alpha );
1530 5150 : move16();
1531 : /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/
1532 5150 : epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */
1533 :
1534 :
1535 : /*-----------------------------------------------------------------*
1536 : * Linear predition efficiency 2 to 16 order
1537 : *-----------------------------------------------------------------*/
1538 :
1539 : /* epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */
1540 5150 : Ltmp = eps_quota_fx( epsP_h[2], epsP_l[2],
1541 5150 : epsP_h[16], epsP_l[16], 12 ); /* Word32 Q12 */
1542 : BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/
1543 5150 : epsP_2_16 = round_fx_sat( L_shl_sat( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 ,*/
1544 : /*NB saturation in Q12 sets max value to 7,999 */
1545 : BASOP_SATURATE_WARNING_ON_EVS
1546 :
1547 5150 : epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */
1548 :
1549 :
1550 : /* if (epsP_2_16 > st->epsP_2_16_lp){
1551 : st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp;
1552 : } else {
1553 : st->epsP_2_16_lp = 0.03f * epsP_2_16 + (1.0f-0.03f) * st->epsP_2_16_lp;
1554 : }
1555 :
1556 : st->epsP_2_16_lp2 = 0.02f * epsP_2_16 + (1.0f-0.02f) * st->epsP_2_16_lp2; */
1557 :
1558 5150 : alpha = 983;
1559 5150 : move16(); /* 0.03 Q15 */
1560 5150 : if ( GT_16( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx ) )
1561 : {
1562 896 : alpha = 6554;
1563 896 : move16(); /* 0.2 Q15 */
1564 : }
1565 5150 : hNoiseEst->epsP_2_16_lp_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx, alpha );
1566 5150 : move16();
1567 5150 : hNoiseEst->epsP_2_16_lp2_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp2_fx, 655 ); /* 0.02 */
1568 5150 : move16();
1569 5150 : epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx );
1570 :
1571 :
1572 : /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) {
1573 : st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2;
1574 : } else {
1575 : st->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + (1.0f-0.05f) * st->epsP_2_16_dlp_lp2;
1576 : }*/
1577 5150 : alpha = 1638;
1578 5150 : move16(); /* 0.05 Q15 */
1579 5150 : if ( LT_16( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ) )
1580 : {
1581 3691 : alpha = 655;
1582 3691 : move16(); /* 0.02 Q15 */
1583 : }
1584 5150 : hNoiseEst->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx, alpha );
1585 5150 : move16();
1586 : /* epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); */
1587 5150 : epsP_2_16_dlp_max = s_max( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx );
1588 :
1589 : /*-----------------------------------------------------------------*
1590 : * long term extensions of frame features
1591 : *-----------------------------------------------------------------*/
1592 :
1593 5150 : tmp = sub( Etot, hNoiseEst->totalNoise_fx ); /* Q8 */
1594 : /* st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; */
1595 5150 : tmp2 = 0;
1596 5150 : move16();
1597 5150 : if ( LT_16( tmp, 2560 ) ) /*10 in Q8 */
1598 : {
1599 20 : tmp2 = 32767;
1600 20 : move16();
1601 : }
1602 5150 : hNoiseEst->lt_tn_track_fx = noise_est_AR1_Qx( tmp2, hNoiseEst->lt_tn_track_fx, 983 ); /*0.03 in Q15 ,Q15 state*/
1603 5150 : move16();
1604 : /* st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; */
1605 5150 : hNoiseEst->lt_tn_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_tn_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/
1606 5150 : move16();
1607 : /* st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist;*/
1608 5150 : tmp = sub( Etot, hNoiseEst->Etot_l_lp_fx ); /* Q8 */
1609 5150 : hNoiseEst->lt_Ellp_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_Ellp_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/
1610 5150 : move16();
1611 :
1612 : /* if (st->harm_cor_cnt == 0) {
1613 : st->lt_haco_ev = 0.03f*1.0 + 0.97f*st->lt_haco_ev;
1614 : } else {
1615 : st->lt_haco_ev = 0.99f*st->lt_haco_ev;
1616 : } */
1617 5150 : IF( *st_harm_cor_cnt == 0 )
1618 : {
1619 4194 : hNoiseEst->lt_haco_ev_fx = noise_est_AR1_Qx( (Word16) 32767, hNoiseEst->lt_haco_ev_fx, 983 ); /*.03 in Q15 , Q15 state */
1620 : }
1621 : ELSE
1622 : {
1623 956 : hNoiseEst->lt_haco_ev_fx = mult_r( 32440, hNoiseEst->lt_haco_ev_fx ); /*.99 in Q15 , Q15 state */
1624 : }
1625 5150 : move16();
1626 :
1627 : /* if (st->lt_tn_track < 0.05f) {
1628 : st->low_tn_track_cnt++;
1629 : } else {
1630 : st->low_tn_track_cnt=0;
1631 : }*/
1632 5150 : tmp = 0;
1633 5150 : move16();
1634 5150 : move16();
1635 5150 : if ( LT_16( hNoiseEst->lt_tn_track_fx, 1638 ) ) /* 0.05 in Q15*/
1636 : {
1637 4891 : tmp = add( hNoiseEst->low_tn_track_cnt, 1 );
1638 : }
1639 5150 : hNoiseEst->low_tn_track_cnt = tmp;
1640 5150 : move16();
1641 :
1642 :
1643 : /* update of the long-term non-stationarity measure (between 0 and 1) */
1644 : /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) {
1645 : st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1;
1646 : } else {
1647 : st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0;
1648 : }*/
1649 5150 : Ltmp = L_mult( M_GAMMA_FX, hNoiseEst->act_pred_fx ); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */
1650 5150 : tmp = round_fx( Ltmp ); /* Q15 */
1651 5150 : test();
1652 5150 : if ( ( GT_32( non_sta, th_sta ) ) /* float th_sta NB 5e10 , WB 3.5e10*/
1653 484 : || ( *loc_harm > 0 ) )
1654 : {
1655 4852 : tmp = mac_r( Ltmp, ( -32768 + M_GAMMA_FX ), -32768 ); /* (-0.01)*(-1.0) */
1656 : }
1657 5150 : hNoiseEst->act_pred_fx = tmp;
1658 5150 : move16();
1659 :
1660 :
1661 : /*-----------------------------------------------------------------*
1662 : * Background noise adaptation enable flag
1663 : *-----------------------------------------------------------------*/
1664 5150 : Ltmp = L_mult( st_fx->voicing_fx[0], 16384 );
1665 5150 : Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 );
1666 5150 : cor_tmp = mac_r_sat( Ltmp, corr_shift, MAX_16 );
1667 5150 : LepsP = eps_quota_fx( epsP_h[2], epsP_l[2],
1668 5150 : epsP_h[16], epsP_l[16], 11 ); /* L_epsP in Q11 */
1669 : /* note this epsP2/eps16 is not limited to 8 as, epsP_2_16 is !! */
1670 :
1671 5150 : vad_2nd_stage_fx = 0;
1672 5150 : move16(); /* background noise present - decrement counter */
1673 : /*
1674 : if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW )
1675 : && ( ( non_sta > th_sta ) ||
1676 : ( tmp_pc < TH_PC ) ||
1677 : ( noise_char > 0) )
1678 : )
1679 : ||
1680 : ( (st->ini_frame > 150) && (Etot - Etot_l_lp) > 10 ) ||
1681 : ( 0.5f * (voicing[0]+voicing[1]) > cor_max ) ||
1682 : ( epsP[2] / epsP[16] > th_eps ) ||
1683 : ( *loc_harm > 0) ||
1684 : ((st->act_pred > 0.8f) && (non_sta2 > th_sta))
1685 : ) */
1686 :
1687 5150 : Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); /* Q15 + Q15(.5)) + 1 -> Q31 */
1688 5150 : cor_tmp = mac_r( Ltmp, st_fx->voicing_fx[1], 16384 ); /* Q31 -16 -> Q15 */
1689 5150 : if ( Etot < 0 )
1690 : {
1691 20 : cor_tmp = 0;
1692 20 : move16();
1693 : }
1694 :
1695 5150 : test();
1696 5150 : test();
1697 5150 : test();
1698 5150 : test();
1699 5150 : test();
1700 5150 : test();
1701 5150 : test();
1702 5150 : test();
1703 5150 : test();
1704 5150 : test();
1705 :
1706 5267 : if ( ( ( LT_16( *st_harm_cor_cnt, ( 3 * HC_CNT_SLOW_FX ) ) ) && ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || ( GT_16( noise_char, 0 ) ) ) ) ||
1707 274 : ( ( GT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( sub( Etot, Etot_l_lp ), 2560 ) ) ) ||
1708 161 : ( GT_16( cor_tmp, cor_max ) ) || /* Q15 */
1709 152 : ( GT_32( LepsP, th_eps ) ) || /* Q11 */
1710 140 : ( GT_16( *loc_harm, 0 ) ) ||
1711 134 : ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) /*act_pred in Q15 , th_sta in Q10 */
1712 : )
1713 : {
1714 5083 : vad_2nd_stage_fx = 1;
1715 5083 : move16(); /* active signal present - increment counter */
1716 : }
1717 :
1718 5150 : tmp = 2;
1719 5150 : move16(); /* Signal present */
1720 5150 : if ( vad_2nd_stage_fx == 0 )
1721 : {
1722 67 : tmp = -1;
1723 67 : move16(); /* Background present */
1724 : }
1725 5150 : hNoiseEst->aEn = add( hNoiseEst->aEn, tmp );
1726 :
1727 :
1728 5150 : hNoiseEst->aEn = s_min( hNoiseEst->aEn, 6 );
1729 5150 : hNoiseEst->aEn = s_max( hNoiseEst->aEn, 0 );
1730 :
1731 : /* Additional NNE detectors */
1732 :
1733 : /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */
1734 : /* Q15 Q15 Q12 */
1735 5150 : comb_ahc_epsP = s_max( s_max( shr( hNoiseEst->act_pred_fx, 15 - 12 ), shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ) ), epsP_2_16_dlp ); /* Q12 */
1736 :
1737 :
1738 : /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */
1739 : /* Q15 Q12 Q12 */
1740 5150 : comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */
1741 :
1742 : /*haco_ev_max = max(*st_harm_cor_cnt==0,st->lt_haco_ev); */
1743 5150 : tmp = 0;
1744 5150 : move16();
1745 5150 : if ( *st_harm_cor_cnt == 0 )
1746 : {
1747 4194 : tmp = (Word16) 32767;
1748 4194 : move16();
1749 : }
1750 5150 : haco_ev_max = s_max( tmp, hNoiseEst->lt_haco_ev_fx ); /* Q15 */
1751 :
1752 : /* Etot_l_lp_thr = st->Etot_l_lp + (1.5f + 1.5f * (st->Etot_lp<50.0f))*st->Etot_v_h2; */
1753 5150 : tmp = 12288;
1754 5150 : move16(); /* 1.5 Q13 */
1755 5150 : if ( LT_16( hNoiseEst->Etot_lp_fx, 12800 ) ) /* 50.0 in Q8 */
1756 : {
1757 2798 : tmp = shl( tmp, 1 ); /*1.5 + 1.5 Q13 */
1758 : }
1759 5150 : Ltmp = L_deposit_h( hNoiseEst->Etot_l_lp_fx );
1760 5150 : Etot_l_lp_thr = round_fx( L_add( Ltmp, L_shl( L_mult( tmp, Etot_v_h2 ), 2 ) ) ); /* Q13+Q8+1 +2 = Q24 -> Q8*/
1761 :
1762 : /* enr_bgd = Etot < Etot_l_lp_thr; */
1763 5150 : enr_bgd = 0;
1764 5150 : move16();
1765 5150 : if ( LT_16( Etot, Etot_l_lp_thr ) ) /* Q8 */
1766 : {
1767 374 : enr_bgd = 1;
1768 374 : move16(); /* Q0 */
1769 : }
1770 :
1771 : /* cns_bgd = (epsP_0_2 > 7.95f) && (non_sta< 1e3f); */
1772 5150 : cns_bgd = 0;
1773 5150 : move16();
1774 5150 : test();
1775 5150 : if ( ( GT_16( epsP_0_2, 32563 ) ) /* 7.95 in Q12 */
1776 2222 : && ( LT_32( non_sta, 1024000L ) ) ) /* 1e3f in Q10 ? */
1777 : {
1778 109 : cns_bgd = 1;
1779 109 : move16(); /* Q0 */
1780 : }
1781 :
1782 : /*lp_bgd = epsP_2_16_dlp_max < 0.10f; */
1783 5150 : lp_bgd = 0;
1784 5150 : move16();
1785 5150 : if ( LT_16( epsP_2_16_dlp_max, 410 ) ) /*0.10 Q12 */
1786 : {
1787 5 : lp_bgd = 1;
1788 5 : move16(); /* Q0 */
1789 : }
1790 :
1791 :
1792 : /* ns_mask = non_sta < 1e5f; */
1793 5150 : ns_mask = 0;
1794 5150 : move16();
1795 5150 : if ( LT_32( non_sta, (Word32) 102400000L ) ) /* (1e5f in Q10)*/
1796 : {
1797 383 : ns_mask = 1;
1798 383 : move16(); /* Q0 */
1799 : }
1800 :
1801 :
1802 : /* lt_haco_mask = st->lt_haco_ev < 0.5f; */
1803 5150 : lt_haco_mask = 0;
1804 5150 : move16();
1805 5150 : if ( LT_16( hNoiseEst->lt_haco_ev_fx, 16384 ) ) /* ( .5 in Q15)*/
1806 : {
1807 125 : lt_haco_mask = 1;
1808 125 : move16(); /* Q0 */
1809 : }
1810 :
1811 : /* bg_haco_mask = haco_ev_max < 0.4f; */
1812 5150 : bg_haco_mask = 0;
1813 5150 : move16();
1814 5150 : if ( LT_16( haco_ev_max, 13107 ) ) /* ( 0.4 in Q15)*/
1815 : {
1816 70 : bg_haco_mask = 1;
1817 70 : move16(); /* Q0 */
1818 : }
1819 :
1820 :
1821 : /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */
1822 5150 : SD_1 = 0;
1823 5150 : move16();
1824 5150 : test();
1825 5150 : if ( ( GT_16( epsP_0_2_ad, 2048 ) ) /* 0.5 in Q12 */
1826 3815 : && ( GT_16( epsP_0_2, 32563 ) ) ) /* 7.95 in Q12 */
1827 : {
1828 1572 : SD_1 = 1;
1829 1572 : move16(); /* Q0 */
1830 : }
1831 5150 : SD_1_inv = sub( 1, SD_1 ); /* Q0 */
1832 :
1833 : /* NB "STL::test()"; has a cost of 2, using bitwise "s_and" , "s_or" at a cost of 1 */
1834 : /* NB only lowest bit position is used, result is always 0 or 1 */
1835 :
1836 : /* bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1==0 ); */
1837 5150 : tmp = s_and( s_and( s_and( s_or( cns_bgd, lp_bgd ), ns_mask ), lt_haco_mask ), SD_1_inv );
1838 5150 : bg_bgd3 = s_or( enr_bgd, tmp );
1839 :
1840 : /*PD_1 = (epsP_2_16_dlp_max < 0.10f ) ; */
1841 5150 : PD_1 = 0;
1842 5150 : move16();
1843 5150 : if ( ( LT_16( epsP_2_16_dlp_max, 410 ) ) ) /* 0.10 in Q12 */
1844 : {
1845 5 : PD_1 = 1;
1846 5 : move16(); /* Q0 */
1847 : }
1848 :
1849 : /*PD_2 = (epsP_0_2_ad_lp_max < 0.10f ) ; */
1850 5150 : PD_2 = 0;
1851 5150 : move16();
1852 5150 : if ( ( LT_16( epsP_0_2_ad_lp_max, 410 ) ) ) /* 0.10 in Q12 */
1853 : {
1854 177 : PD_2 = 1;
1855 177 : move16(); /* Q0 */
1856 : }
1857 :
1858 : /*PD_3 = (comb_ahc_epsP < 0.85f ); */
1859 5150 : PD_3 = 0;
1860 5150 : move16();
1861 5150 : if ( ( LT_16( comb_ahc_epsP, 3482 ) ) ) /* 0.85 in Q12 */
1862 : {
1863 140 : PD_3 = 1;
1864 140 : move16(); /* Q0 */
1865 : }
1866 :
1867 : /* PD_4 = comb_ahc_epsP < 0.15f; */
1868 5150 : PD_4 = 0;
1869 5150 : move16();
1870 5150 : if ( ( LT_16( comb_ahc_epsP, 614 ) ) ) /* 0.15 in Q12 */
1871 : {
1872 0 : PD_4 = 1;
1873 0 : move16(); /* Q0 */
1874 : }
1875 :
1876 : /*PD_5 = comb_hcm_epsP < 0.30f; */
1877 5150 : PD_5 = 0;
1878 5150 : move16();
1879 5150 : if ( ( LT_16( comb_hcm_epsP, 1229 ) ) ) /* 0.30 in Q12 */
1880 : {
1881 0 : PD_5 = 1;
1882 0 : move16(); /* Q0 */
1883 : }
1884 :
1885 : /* BG_1 = ( (SD_1==0) || (Etot < Etot_l_lp_thr) )
1886 : && bg_haco_mask && (st->act_pred < 0.85f) && (st->Etot_lp < 50.0f); */
1887 5150 : BG_1 = 0;
1888 5150 : move16();
1889 5150 : test();
1890 5150 : test();
1891 5150 : test();
1892 5150 : test();
1893 5150 : if ( ( ( SD_1 == 0 ) || ( LT_16( Etot, Etot_l_lp_thr ) ) ) && ( bg_haco_mask != 0 ) && ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85f in Q15 */
1894 0 : && ( LT_16( hNoiseEst->Etot_lp_fx, 50 * 256 ) ) ) /* 50.0 in Q8 */
1895 : {
1896 0 : BG_1 = 1;
1897 0 : move16();
1898 : }
1899 :
1900 : /* PAU = (st->aEn==0)
1901 : || ( (Etot < 55.0f) && (SD_1==0)
1902 : && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); */
1903 5150 : PAU = 0;
1904 5150 : move16(); /*Q0*/
1905 5150 : if ( hNoiseEst->aEn == 0 )
1906 : {
1907 4 : PAU = 1;
1908 4 : move16(); /*Q0*/
1909 : }
1910 5150 : tmp = 0;
1911 5150 : move16(); /*Q0*/
1912 5150 : if ( LT_16( Etot, 55 * 256 ) ) /*55.0 in Q8 */
1913 : {
1914 3632 : tmp = 1;
1915 3632 : move16(); /*Q0*/
1916 : }
1917 5150 : tmp = s_and( tmp, SD_1_inv );
1918 5150 : PAU = s_or( PAU, s_and( tmp, s_or( s_and( PD_3, s_or( PD_1, PD_2 ) ), s_or( PD_4, PD_5 ) ) ) );
1919 :
1920 :
1921 : /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */
1922 5150 : NEW_POS_BG = s_and( s_or( PAU, BG_1 ), bg_bgd3 );
1923 :
1924 : /* Original silence detector works in most cases */
1925 : /* aE_bgd = (st->aEn == 0);*/
1926 5150 : aE_bgd = 0;
1927 5150 : move16();
1928 5150 : if ( hNoiseEst->aEn == 0 )
1929 : {
1930 4 : aE_bgd = 1;
1931 4 : move16();
1932 : }
1933 :
1934 :
1935 : /* When the signal dynamics is high and the energy is close to the background estimate */
1936 : /* sd1_bgd = (st->sign_dyn_lp > 15)
1937 : && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2
1938 : && st->harm_cor_cnt > 20; */
1939 5150 : sd1_bgd = 0;
1940 5150 : move16();
1941 5150 : test();
1942 5150 : test();
1943 5150 : if ( ( GT_16( hNoiseEst->sign_dyn_lp_fx, 15 * 256 ) ) /* 15 in Q8 */
1944 5085 : && ( LT_16( sub( Etot, hNoiseEst->Etot_l_lp_fx ), shl( Etot_v_h2, 1 ) ) ) /* Q8 , Etot_v_h2 has limited dynmics can be upscaled*/
1945 296 : && ( GT_16( *st_harm_cor_cnt, 20 ) ) )
1946 : {
1947 0 : sd1_bgd = 1;
1948 0 : move16();
1949 : }
1950 :
1951 : /* tn_ini = st->ini_frame < 150 && st->harm_cor_cnt > 5 &&
1952 : ( (st->act_pred < 0.59f && st->lt_haco_ev <0.23f ) ||
1953 : st->act_pred < 0.38f ||
1954 : st->lt_haco_ev < 0.15f ||
1955 : non_staB < 50.0f ||
1956 : aE_bgd );*/
1957 :
1958 5150 : tmp = 0;
1959 5150 : move16();
1960 5150 : test();
1961 5150 : test();
1962 5150 : test();
1963 5150 : test();
1964 5150 : test();
1965 5150 : test();
1966 5150 : test();
1967 5150 : test();
1968 5150 : test();
1969 5150 : test();
1970 5150 : test();
1971 5150 : test();
1972 5150 : if ( ( ( LT_16( hNoiseEst->act_pred_fx, 19333 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 7537 ) ) ) /* .59 in Q15 .23 in Q15 */
1973 5150 : || ( LT_16( hNoiseEst->act_pred_fx, 12452 ) ) /* .38 in Q15 */
1974 5150 : || ( ( st_fx->element_mode == EVS_MONO && LT_16( hNoiseEst->lt_haco_ev_fx, 4915 ) ) || ( st_fx->element_mode > EVS_MONO && LT_16( hNoiseEst->lt_haco_ev_fx, 2621 ) ) ) /* .15 in Q15 || 0.08 */
1975 5150 : || ( LT_16( non_staB, 50 * 256 ) ) /* 50.0 in Q8 */
1976 3773 : || aE_bgd != 0 || ( ( LT_16( Etot, 10752 ) ) /* 42 in Q8 */
1977 641 : && ( GT_16( hNoiseEst->harm_cor_cnt, 10 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 11469 ) ) /* 0.35 in Q15 */
1978 0 : && ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* 0.80 in Q15 */
1979 : ) )
1980 : {
1981 1377 : tmp = 1;
1982 1377 : move16();
1983 : }
1984 :
1985 5150 : tn_ini = 0;
1986 5150 : move16();
1987 5150 : test();
1988 5150 : test();
1989 5150 : test();
1990 5150 : if ( ( LT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( hNoiseEst->harm_cor_cnt, 5 ) ) /* > 5 Q0 */
1991 0 : && ( LT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) /* 7 in Q8 */
1992 0 : && ( NE_16( tmp, 0 ) ) )
1993 : {
1994 0 : tn_ini = 1;
1995 0 : move16();
1996 : }
1997 :
1998 : /* Energy close to the background estimate serves as a mask for other background detectors */
1999 : /* bg_bgd2 = Etot < Etot_l_lp_thr || tn_ini ; */
2000 5150 : bg_bgd2 = 0;
2001 5150 : move16();
2002 5150 : test();
2003 5150 : if ( ( LT_16( Etot, Etot_l_lp_thr ) ) || ( tn_ini != 0 ) )
2004 : {
2005 374 : bg_bgd2 = 1;
2006 374 : move16(); /* Q0 */
2007 : }
2008 :
2009 5150 : updt_step = 0;
2010 5150 : move16(); /* Q15 */
2011 : /*if (( bg_bgd2 && ( aE_bgd || sd1_bgd || st->lt_tn_track >0.90f || NEW_POS_BG ) )
2012 : || tn_ini ) */
2013 5150 : tmp = 0;
2014 5150 : move16();
2015 5150 : if ( GT_16( hNoiseEst->lt_tn_track_fx, 29491 ) ) /* .90 in Q15 */
2016 : {
2017 0 : tmp = 1;
2018 0 : move16();
2019 : }
2020 :
2021 5150 : IF( s_or( s_and( bg_bgd2, s_or( aE_bgd, s_or( sd1_bgd, s_or( tmp, NEW_POS_BG ) ) ) ), tn_ini ) )
2022 : {
2023 : /*if( ( ( st->act_pred < 0.85f )
2024 : && (aE_bgd !=0)
2025 : && ( st->lt_Ellp_dist < 10 || sd1_bgd )
2026 : && (st->lt_tn_dist<40)
2027 : && ( ( Etot - st->totalNoise ) < 10.0f )
2028 : )
2029 : || ( (st->first_noise_updt == 0) && (st->harm_cor_cnt > 80) && (aE_bgd!=0) && (st->lt_aEn_zero > 0.5f) )
2030 : || ( (tn_ini!=0) && ( aE_bgd != 0) || (non_staB < 10.0) || (st->harm_cor_cnt > 80) )
2031 : )*/
2032 :
2033 0 : test();
2034 0 : test();
2035 0 : test();
2036 0 : test();
2037 0 : test();
2038 0 : test();
2039 0 : test(); /* for the ELSE IF below*/
2040 0 : test();
2041 0 : test();
2042 0 : test();
2043 0 : test();
2044 0 : test();
2045 0 : test(); /* for the ELSE IF below*/
2046 :
2047 0 : test();
2048 0 : test();
2049 0 : test();
2050 0 : test();
2051 0 : test();
2052 0 : test();
2053 0 : test();
2054 0 : test();
2055 0 : test();
2056 0 : test();
2057 0 : test();
2058 0 : test();
2059 0 : test();
2060 0 : test();
2061 0 : test();
2062 0 : IF( ( ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85 in Q15 */
2063 : && ( NE_16( aE_bgd, 0 ) ) && ( ( LT_16( hNoiseEst->lt_Ellp_dist_fx, 10 * 256 ) ) || ( NE_16( sd1_bgd, 0 ) ) ) /* 10.0 in Q8*/
2064 : && ( LT_16( hNoiseEst->lt_tn_dist_fx, 40 * 256 ) ) /* 40.0 in Q8*/
2065 : && ( LT_16( sub( Etot, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8*/
2066 : ) ||
2067 : ( ( hNoiseEst->first_noise_updt == 0 ) && ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) && ( aE_bgd != 0 ) && ( GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 ) ) /*.5 in Q15*/
2068 : ) ||
2069 : ( ( tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 10 * 256 ) ) || ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) ) /* 10.0 in Q8*/
2070 : ) )
2071 :
2072 : {
2073 0 : updt_step = 32767;
2074 0 : move16();
2075 0 : hNoiseEst->first_noise_updt = 1;
2076 0 : move16();
2077 0 : FOR( i = 0; i < NB_BANDS; i++ )
2078 : {
2079 0 : hNoiseEst->bckr_fx[i] = tmpN[i];
2080 0 : move32();
2081 : }
2082 : }
2083 : /* else if ( ( ( st->act_pred < 0.80f ) && ( aE_bgd || PAU ) && st->lt_haco_ev < 0.10f )
2084 : || ( ( st->act_pred < 0.70f ) && ( aE_bgd || non_staB < 17.0f ) && PAU && st->lt_haco_ev < 0.15f )
2085 : || ( st->harm_cor_cnt > 80 && st->totalNoise > 5.0f && Etot < max(1.0f,Etot_l_lp + 1.5f* st->Etot_v_h2) )
2086 : ||
2087 : ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f )
2088 : || tn_ini
2089 : ) */
2090 0 : ELSE IF( ( ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* .8 in Q15*/
2091 : && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 3277 ) ) ) /* .10 in q15*/
2092 : || ( ( LT_16( hNoiseEst->act_pred_fx, 22938 ) ) /* 0.70 in Q15 */
2093 : && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 17 * 256 ) ) ) /* 17.0 in Q8 */
2094 : && ( PAU != 0 ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 4915 ) ) /* 0.15 in Q15 */
2095 : ) ||
2096 : ( ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) && ( GT_16( hNoiseEst->totalNoise_fx, 5 * 256 ) ) /* 5.0 in Q8 */
2097 : && ( LT_16( Etot, s_max( (Word16) 1 * 256, add( Etot_l_lp, add( hNoiseEst->Etot_v_h2_fx, shr( hNoiseEst->Etot_v_h2_fx, 1 ) ) ) ) ) ) /* 1.5= 1.0+.5 */
2098 : ) ||
2099 : ( ( GT_16( hNoiseEst->harm_cor_cnt, 50 ) ) && ( GT_16( hNoiseEst->first_noise_updt, 30 ) ) && ( aE_bgd != 0 ) && ( GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 ) ) ) /*.5 in Q15*/
2100 : || ( tn_ini != 0 ) )
2101 :
2102 : {
2103 0 : updt_step = 3277;
2104 0 : move16(); /* 0.1 in Q15 */
2105 : /* if ( !aE_bgd && st->harm_cor_cnt < 50
2106 : && ( (st->act_pred > 0.6f)
2107 : || ( (tn_ini==0) && (Etot_l_lp - st->totalNoise < 10.0f) && non_staB > 8.0f )
2108 : )
2109 : )
2110 : */
2111 0 : test();
2112 0 : test();
2113 0 : test();
2114 0 : test();
2115 0 : test();
2116 0 : IF( ( aE_bgd == 0 ) && ( LT_16( hNoiseEst->harm_cor_cnt, 50 ) ) && ( ( GT_16( hNoiseEst->act_pred_fx, 19661 ) ) /* 0.6 in Q15*/
2117 : || ( ( tn_ini == 0 ) && ( LT_16( sub( Etot_l_lp, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8 */
2118 : && ( GT_16( non_staB, 8 * 256 ) ) /* 8.0 in in Q8*/
2119 : ) ) )
2120 : {
2121 0 : updt_step = 328;
2122 0 : move16(); /* 0.01 Q15 */
2123 : }
2124 : /*
2125 : IF (updt_step > 0 )
2126 : {
2127 : */
2128 0 : hNoiseEst->first_noise_updt = 1;
2129 0 : move16();
2130 0 : FOR( i = 0; i < NB_BANDS; i++ )
2131 : {
2132 : /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/
2133 : /* 32 bit state update */
2134 0 : Ltmp = L_sub( tmpN[i], hNoiseEst->bckr_fx[i] ); /*Q_new+Q_SCALE*/
2135 0 : Ltmp = Mult_32_16( Ltmp, updt_step ); /* Q_new+Q_SCALE+15+1 -16*/
2136 0 : hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] );
2137 0 : move32();
2138 : }
2139 : /*
2140 : } */
2141 : }
2142 : /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/
2143 0 : ELSE IF( ( aE_bgd != 0 ) || ( GT_16( hNoiseEst->harm_cor_cnt, 100 ) ) )
2144 : {
2145 0 : hNoiseEst->first_noise_updt = add( hNoiseEst->first_noise_updt, 1 );
2146 0 : move16();
2147 : }
2148 : }
2149 : ELSE
2150 : {
2151 : /* If in music lower bckr to drop further */
2152 5150 : test();
2153 5150 : test();
2154 5150 : IF( ( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) ) && ( GT_16( hNoiseEst->lt_haco_ev_fx, 29491 ) ) /*.9 in Q15 */
2155 : && ( hNoiseEst->totalNoise_fx > 0 ) )
2156 : {
2157 0 : updt_step = -655;
2158 0 : move16(); /* for debug purposes */
2159 0 : FOR( i = 0; i < NB_BANDS; i++ )
2160 : {
2161 0 : IF( GT_32( hNoiseEst->bckr_fx[i], L_shl( Le_min_scaled, 1L ) ) ) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */
2162 : {
2163 : /* st->bckr[i] = 0.98f*st->bckr[i]; */
2164 0 : hNoiseEst->bckr_fx[i] = Mult_32_16( hNoiseEst->bckr_fx[i], 32113 ); /* .98 in Q15 */
2165 0 : move32(); /* move to array */
2166 : }
2167 : }
2168 : }
2169 : /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f) *st->lt_aEn_zero;*/
2170 : /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */
2171 5150 : tmp = 0;
2172 5150 : move16();
2173 5150 : if ( hNoiseEst->aEn == 0 )
2174 : {
2175 4 : tmp = 32767;
2176 4 : move16();
2177 : }
2178 5150 : hNoiseEst->lt_aEn_zero_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_aEn_zero_fx, 6554 ); /* alpha=0.2 , Q15 */
2179 5150 : move16();
2180 : }
2181 :
2182 5150 : return;
2183 : }
2184 :
2185 : /*-----------------------------------------------------------------*
2186 : * noise_est_fx()
2187 : *
2188 : * Noise energy estimation (noise energy is updated in case of noise-only frame)
2189 : *-----------------------------------------------------------------*/
2190 1374528 : void noise_est_ivas_fx(
2191 : Encoder_State *st_fx, /* i/o: state structure */
2192 : const Word16 old_pitch1, /* i : previous frame OL pitch[1] */
2193 : const Word32 tmpN[], /* i : temporary noise update q_tmpN */
2194 : const Word16 q_tmpN, /* i : Q-factor of tmpN buffer */
2195 : const Word32 epsP[], /* i : msb prediction error energies Qx */
2196 : const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */
2197 : const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */
2198 : const Word16 corr_shift, /* i : normalized correlation correction Q15 */
2199 : const Word32 enr[], /* i : averaged energy over both subframes q_enr */
2200 : const Word16 q_enr, /* i : q_enr of enr Q0 */
2201 : Word32 fr_bands[], /* i : spectrum per critical bands of the current frame q_fr_bands */
2202 : Word16 q_fr_bands, /* i : Q of q_fr_bands */
2203 : Word16 *cor_map_sum, /* o : Q8 */
2204 : Word16 *ncharX, /* o : Q11 */
2205 : Word16 *sp_div, /* o : Q_sp_div */
2206 : Word16 *Q_sp_div, /* o : Q factor for sp_div */
2207 : Word32 *non_staX, /* o : non-stationarity for sp/mus classifier */
2208 : Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */
2209 : const Word32 *lf_E, /* i : per bin energy for low frequencies q_lf_E */
2210 : const Word16 q_lf_E, /* i : Q of lf_E Q0 */
2211 : Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */
2212 : const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */
2213 : const Word32 Etot_v_h2, /* i : Energy variations Q24 */
2214 : Word16 *bg_cnt, /* i : Background burst length timer Q0 */
2215 : Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */
2216 : Word16 *sp_floor, /* o : noise floor estimate Q7 */
2217 : Word16 S_map[], /* o : short-term correlation map Q7 */
2218 : STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
2219 : FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */
2220 : const Word16 ini_frame /* i : Frame number (init) */
2221 : )
2222 : {
2223 : Word16 alpha, alpha2, alpha2m1, alpham1;
2224 : Word16 cor_min, cor_max, num, den, ExpNum, ExpDen, noise_chartmp;
2225 : Word16 wtmp1, wtmp, nchar_thr, cor_tmp;
2226 : Word16 i, tmp_pc, pc, th_eps;
2227 : Word32 th_sta, Lnum, Lden, non_sta, LepsP;
2228 : Word16 e_ener, f_ener;
2229 : Word32 Ltmp, Ltmp1, Lsum_num, Lsum_den, *pt1, *pt2, Ltmp2, Lnon_sta2;
2230 : Word64 w_sum_num, w_tmp;
2231 : Word16 spec_div, noise_char;
2232 : Word16 log_enr16;
2233 : Word16 updt_step; /* Q15 */
2234 : Word16 aE_bgd, sd1_bgd, bg_bgd2;
2235 : Word16 tn_ini;
2236 : Word16 epsP_0_2, epsP_0_2_ad, epsP_0_2_ad_lp_max;
2237 : Word16 epsP_2_16, epsP_2_16_dlp, epsP_2_16_dlp_max;
2238 : Word16 PAU, BG_1, NEW_POS_BG;
2239 :
2240 : Word16 haco_ev_max;
2241 : Word16 Etot_l_lp_thr;
2242 : Word16 comb_ahc_epsP, comb_hcm_epsP;
2243 :
2244 : Word16 enr_bgd, cns_bgd, lp_bgd, ns_mask;
2245 : Word16 lt_haco_mask, bg_haco_mask;
2246 : Word16 SD_1, bg_bgd3, PD_1, PD_2, PD_3, PD_4, PD_5;
2247 :
2248 : Word16 non_staB; /* Q8 */
2249 : Word32 L_tmp_enr, L_tmp_ave, L_tmp_ave2;
2250 : Word16 tmp, tmp2, diff; /* general temp registers */
2251 : Word16 tmp_enr, tmp_floor; /* constants in Q8 */
2252 : Word16 vad_bwidth_fx; /* vad ns control variabel for input bwidth from teh BWD */
2253 : /* for DTX operation */
2254 : Word32 L_tmp;
2255 :
2256 : Word16 lim_Etot_fx; /* Q8 */
2257 : Word32 lim_Etot_sq_fx; /* Q16 */
2258 : Word32 st_E_var_est_fx;
2259 : NOISE_EST_HANDLE hNoiseEst;
2260 : SP_MUS_CLAS_HANDLE hSpMusClas;
2261 : Word32 Le_min_scaled;
2262 : Word64 temp;
2263 1374528 : hSpMusClas = st_fx->hSpMusClas;
2264 :
2265 1374528 : Le_min_scaled = L_shl( E_MIN_FXQ31, sub( q_fr_bands, Q31 ) ); // q_fr_bands
2266 :
2267 1374528 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
2268 :
2269 : /* Check if LR-VAD */
2270 1374528 : IF( hFrontVad != NULL )
2271 : {
2272 84146 : hNoiseEst = hFrontVad->hNoiseEst;
2273 : }
2274 : ELSE
2275 : {
2276 1290382 : hNoiseEst = st_fx->hNoiseEst;
2277 : }
2278 :
2279 : /*-----------------------------------------------------------------*
2280 : * Initialization
2281 : *-----------------------------------------------------------------*/
2282 1374528 : vad_bwidth_fx = st_fx->input_bwidth;
2283 1374528 : move16();
2284 :
2285 :
2286 : /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/
2287 1374528 : temp = 0;
2288 1374528 : move64();
2289 1374528 : IF( hFrontVad == NULL )
2290 : {
2291 1290382 : IF( hSpMusClas != NULL )
2292 : {
2293 : /* E = mean( lf_E, 8 ); */
2294 11613438 : FOR( i = 0; i < 8; i++ )
2295 : {
2296 10323056 : temp = W_mac_32_16( temp, lf_E[i], 1 ); // q_lf_E+1
2297 : }
2298 : /* (temp / 8) */
2299 1290382 : Ltmp = W_extract_l( W_shr( temp, 4 ) ); // q_lf_E+1 -> q_lf_E
2300 :
2301 1290382 : IF( LT_32( Ltmp, L_shl_sat( 1, q_lf_E ) ) )
2302 : {
2303 158570 : hSpMusClas->ener_RAT_fx = 0;
2304 : }
2305 : ELSE
2306 : {
2307 1131812 : e_ener = norm_l( Ltmp );
2308 1131812 : f_ener = Log2_norm_lc( L_shl( Ltmp, e_ener ) );
2309 1131812 : e_ener = sub( 30, e_ener );
2310 1131812 : e_ener = sub( e_ener, q_lf_E );
2311 1131812 : Ltmp = L_mac( L_deposit_h( e_ener ), f_ener, 1 ); // Q16
2312 1131812 : Ltmp = Mpy_32_16_1( Ltmp, LG10 ); // Q14 (16+13-15)
2313 1131812 : Ltmp = L_shl( Ltmp, 10 ); // Q24
2314 1131812 : wtmp = round_fx( Ltmp ); /*Q8*/
2315 :
2316 : /* st_fx->ener_RAT /= (Etot + 0.01f);
2317 : if ( st->hSpMusClas->ener_RAT > 1.0 )
2318 : {
2319 : st->hSpMusClas->ener_RAT = 1.0f;
2320 : }
2321 : */
2322 :
2323 1131812 : wtmp1 = add( Etot, 3 ); /* 0.01f in Q8 */
2324 1131812 : hSpMusClas->ener_RAT_fx = 0;
2325 1131812 : move16();
2326 1131812 : IF( wtmp > 0 )
2327 : {
2328 1131802 : hSpMusClas->ener_RAT_fx = 32767;
2329 1131802 : move16(); /*Q15*/
2330 1131802 : IF( GE_16( wtmp1, wtmp ) )
2331 : {
2332 1131802 : hSpMusClas->ener_RAT_fx = div_s( wtmp, wtmp1 ); /*Q15*/ /* wtmp1 gte than wtmp */
2333 1131802 : move16();
2334 : }
2335 : }
2336 : }
2337 : }
2338 : }
2339 : /*-----------------------------------------------------------------*
2340 : * Set the threshold for eps & non_sta based on input sampling rate
2341 : * The reason is that in case of 8kHz sampling input, there is nothing
2342 : * between 4kHz-6.4kHz. In noisy conditions, this makes a fast
2343 : * transition even in noise-only parts, hence producing a "higher
2344 : * order" spectral envelope => the epsP ratio is much less effective.
2345 : *-----------------------------------------------------------------*/
2346 :
2347 1374528 : IF( vad_bwidth_fx != NB ) /* WB input */
2348 : {
2349 1371487 : th_eps = TH_EPS16_FX;
2350 1371487 : move16(); /*Q11*/
2351 1371487 : th_sta = TH_STA16_FX;
2352 1371487 : move16(); /*Q10 */
2353 1371487 : cor_min = COR_MIN16_FX;
2354 1371487 : move16(); /*Q15*/
2355 1371487 : cor_max = COR_MAX16_FX;
2356 1371487 : move16(); /*Q15*/
2357 : }
2358 : ELSE /* NB input */
2359 : {
2360 3041 : th_eps = TH_EPS8_FX;
2361 3041 : move16(); /* Q11 */
2362 3041 : th_sta = TH_STA8_FX;
2363 3041 : move16(); /* Q10 */
2364 3041 : cor_min = COR_MIN8_FX;
2365 3041 : move16();
2366 3041 : cor_max = COR_MAX8_FX;
2367 3041 : move16();
2368 : }
2369 :
2370 : /*-----------------------------------------------------------------*
2371 : * Estimation of pitch stationarity
2372 : *-----------------------------------------------------------------*/
2373 :
2374 : /* pc = abs(pit[0] - pitO) + abs(pit[1] - pit[0]) */ /* needed in signal_clas() */
2375 1374528 : wtmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) );
2376 1374528 : wtmp1 = abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) );
2377 1374528 : pc = add( wtmp, wtmp1 );
2378 :
2379 1374528 : Ltmp = L_deposit_h( corr_shift );
2380 1374528 : Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 );
2381 1374528 : Ltmp = L_mac_sat( Ltmp, st_fx->voicing_fx[1], 10923 );
2382 1374528 : wtmp = mac_r_sat( Ltmp, st_fx->voicing_fx[2], 10923 );
2383 :
2384 1374528 : tmp_pc = pc;
2385 1374528 : move16();
2386 1374528 : if ( LT_16( wtmp, cor_min ) )
2387 : {
2388 321739 : tmp_pc = TH_PC_FX;
2389 321739 : move16(); /* low correlation -> probably inactive signal */
2390 : }
2391 :
2392 : /* Update */
2393 :
2394 : /*-----------------------------------------------------------------*
2395 : * Multi-harmonic analysis
2396 : *-----------------------------------------------------------------*/
2397 1374528 : IF( hFrontVad == NULL )
2398 : {
2399 1290382 : IF( st_fx->hSpMusClas != NULL )
2400 : {
2401 1290382 : i = 0;
2402 1290382 : move16();
2403 1290382 : *loc_harm = multi_harm_ivas_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
2404 2580764 : st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map );
2405 1290382 : move16();
2406 : }
2407 : }
2408 : /*-----------------------------------------------------------------*
2409 : * Detection of frames with non-stationary spectral content
2410 : *-----------------------------------------------------------------*/
2411 : /* weighted sum of spectral changes per critical bands */
2412 1374528 : w_sum_num = 0;
2413 1374528 : move64();
2414 1374528 : Lsum_den = L_deposit_l( 0 );
2415 :
2416 1374528 : pt1 = fr_bands + 10;
2417 1374528 : pt2 = hNoiseEst->fr_bands2_fx + 10;
2418 : Word64 w_sum_den;
2419 : Word16 exp, exp2;
2420 1374528 : w_sum_den = 0;
2421 1374528 : move64();
2422 15110745 : FOR( i = 10; i <= st_fx->max_band; i++ )
2423 : {
2424 13736217 : Lnum = L_max( *pt1, *pt2 );
2425 13736217 : Lden = L_min( *pt1, *pt2 );
2426 :
2427 13736217 : w_sum_den = W_mac_32_16( w_sum_den, Lnum, 1 ); // q_fr_bands+1
2428 :
2429 13736217 : exp = sub( norm_l( Lnum ), 1 );
2430 13736217 : Lnum = L_shl( Lnum, exp ); // q_fr_bands+exp
2431 13736217 : num = extract_h( Mpy_32_32( Lnum, Lnum ) ); // 2*(q_fr_bands+exp)-31-16
2432 13736217 : ExpNum = add( sub( shl( q_fr_bands, 1 ), 47 ), shl( exp, 1 ) );
2433 :
2434 :
2435 13736217 : den = E_MIN_FXQ31 >> 8; // 29360, 0.0035f in Q23
2436 13736217 : ExpDen = Q23;
2437 13736217 : move32();
2438 13736217 : move16();
2439 :
2440 13736217 : IF( Lden != 0 )
2441 : {
2442 13605983 : exp = norm_l( Lden );
2443 13605983 : den = extract_h( L_shl( Lden, exp ) ); // q_fr_bands+ExpDen-16
2444 13605983 : ExpDen = sub( add( q_fr_bands, exp ), Q16 );
2445 : }
2446 :
2447 13736217 : num = div_s( num, den ); // Q15+ExpNum-ExpDen
2448 13736217 : w_tmp = W_shl( num, s_min( 63, sub( q_fr_bands, sub( ExpNum, ExpDen ) ) ) ); // q_fr_bands+15
2449 13736217 : w_sum_num = W_add( w_sum_num, w_tmp );
2450 :
2451 13736217 : pt1++;
2452 13736217 : pt2++;
2453 : }
2454 :
2455 1374528 : ExpNum = W_norm( w_sum_num );
2456 1374528 : Lsum_num = W_extract_h( W_shl( w_sum_num, ExpNum ) ); // q_fr_bands+15+ExpNum-32
2457 1374528 : ExpNum = add( q_fr_bands, sub( ExpNum, 17 ) );
2458 :
2459 1374528 : ExpDen = W_norm( w_sum_den );
2460 1374528 : Lsum_den = W_extract_h( W_shl( w_sum_den, ExpDen ) ); // q_fr_bands+1+ExpDen-32
2461 1374528 : ExpDen = add( add( q_fr_bands, 1 ), sub( ExpDen, 32 ) );
2462 :
2463 : /* calculation of spectral diversity */
2464 : /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */
2465 1374528 : spec_div = 0;
2466 1374528 : move16();
2467 1374528 : if ( GT_32( Mult_32_16( Lsum_num, 6554 ), L_shl_sat( Lsum_den, sub( ExpNum, ExpDen ) ) ) ) /* Qx+Q15+1-16 ==> Qx */
2468 : {
2469 459164 : spec_div = 1;
2470 459164 : move16();
2471 : }
2472 :
2473 : /* *sp_div = Lsum_num / (Lsum_den + 1e-5f); */
2474 1374528 : IF( Lsum_den == 0 )
2475 : {
2476 0 : Lsum_den = 1407374884; // 1e-5 in Q47
2477 0 : ExpDen = 47;
2478 0 : move32();
2479 0 : move16();
2480 : }
2481 :
2482 1374528 : *sp_div = BASOP_Util_Divide3232_Scale( Lsum_num, Lsum_den, &exp );
2483 1374528 : move16();
2484 1374528 : *Q_sp_div = add( sub( 15, exp ), sub( ExpNum, ExpDen ) );
2485 1374528 : move16();
2486 :
2487 : /*-----------------------------------------------------------------*
2488 : * Detection of frames with high energy content in high frequencies
2489 : *-----------------------------------------------------------------*/
2490 :
2491 1374528 : pt1 = &fr_bands[st_fx->min_band];
2492 1374528 : pt2 = &fr_bands[10];
2493 1374528 : w_sum_num = 0;
2494 1374528 : w_sum_den = 0;
2495 1374528 : move64();
2496 1374528 : move64();
2497 :
2498 : /* calculation of energy in first 10 critical bands */
2499 15116787 : FOR( i = 0; i < sub( 10, st_fx->min_band ); i++ )
2500 : {
2501 13742259 : w_sum_den = W_mac_32_16( w_sum_den, *pt1, 1 ); // q_fr_bands+1
2502 13742259 : pt1++;
2503 : }
2504 1374528 : exp = W_norm( w_sum_den );
2505 1374528 : Ltmp = W_extract_h( W_shl( w_sum_den, exp ) ); // q_fr_bands+1+exp-32
2506 1374528 : exp = sub( add( q_fr_bands, exp ), 31 );
2507 :
2508 : /* calculation of energy in the rest of bands */
2509 15110745 : FOR( i = 0; i < sub( st_fx->max_band, 9 ); i++ )
2510 : {
2511 13736217 : w_sum_num = W_mac_32_16( w_sum_num, *pt2, 1 );
2512 13736217 : pt2++;
2513 : }
2514 1374528 : exp2 = sub( W_norm( w_sum_num ), 1 );
2515 1374528 : Ltmp2 = W_extract_h( W_shl( w_sum_num, exp2 ) ); // q_fr_bands+1+exp2-32
2516 1374528 : exp2 = sub( add( q_fr_bands, exp2 ), 31 );
2517 :
2518 1374528 : test();
2519 1374528 : IF( LT_32( L_shr( Ltmp, exp ), 100 ) || LT_32( L_shr( Ltmp2, exp2 ), 100 ) )
2520 : {
2521 511665 : noise_chartmp = 0;
2522 511665 : move16();
2523 : }
2524 : ELSE
2525 : {
2526 : /* ftemp2 /= ftemp */
2527 862863 : num = div_s( extract_h( Ltmp2 ), extract_h( Ltmp ) ); // 15+exp2-exp
2528 862863 : noise_chartmp = shl_sat( num, sub( sub( exp, exp2 ), 4 ) ); // 15+exp2-exp1 -> Q11
2529 : }
2530 :
2531 1374528 : if ( ncharX != NULL )
2532 : {
2533 1355438 : *ncharX = noise_chartmp; /* Q11 */
2534 1355438 : move16();
2535 : }
2536 :
2537 1374528 : IF( hStereoClassif != NULL )
2538 : {
2539 879589 : IF( st_fx->idchan == 0 )
2540 : {
2541 480845 : hStereoClassif->nchar_ch1_fx = noise_chartmp; /* Q11 */
2542 480845 : move32();
2543 480845 : hStereoClassif->nchar_ch1_e = 31 - Q11;
2544 480845 : move16();
2545 : }
2546 : ELSE
2547 : {
2548 398744 : hStereoClassif->nchar_ch2_fx = noise_chartmp; /* Q11 */
2549 398744 : move32();
2550 398744 : hStereoClassif->nchar_ch2_e = 31 - Q11;
2551 398744 : move16();
2552 : }
2553 : }
2554 :
2555 1374528 : noise_chartmp = s_min( noise_chartmp, 10 << 11 ); /* Q11 */
2556 :
2557 : /* update LT value of the final parameter */
2558 : /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */
2559 1374528 : hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp );
2560 1374528 : move16();
2561 :
2562 1374528 : nchar_thr = THR_NCHAR_WB_FX;
2563 1374528 : move16(); /* 1.0 Q11 */
2564 1374528 : if ( vad_bwidth_fx == NB )
2565 : {
2566 3041 : nchar_thr = THR_NCHAR_NB_FX;
2567 3041 : move16(); /* 1.0 Q11 */
2568 : }
2569 :
2570 1374528 : noise_char = 0;
2571 1374528 : move16();
2572 1374528 : if ( GT_16( hNoiseEst->noise_char_fx, nchar_thr ) )
2573 : {
2574 132796 : noise_char = 1;
2575 132796 : move16();
2576 : }
2577 :
2578 : /* save the 2 last spectra per crit. bands for the future */
2579 1374528 : Copy32( hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS ); // q_fr_bands
2580 1374528 : Copy32( fr_bands + NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS ); // q_fr_bands
2581 :
2582 : /*-----------------------------------------------------------------*
2583 : * Non-stationarity estimation for each band
2584 : * Handicap high E frames in average computing
2585 : *-----------------------------------------------------------------*/
2586 :
2587 : /* set averaging factor */
2588 : /* ftemp = relE; */
2589 : /* if( ftemp < 0.0f ) { ftemp = 0.0f; } */
2590 1374528 : tmp = s_max( relE, 0 ); /* Q8 */
2591 :
2592 : /* alpha = 0.064f * ftemp + 0.75f; */
2593 1374528 : Ltmp = Madd_32_16( 12582912 /* 0.75 in Q24*/, 137438953, tmp ); // Q24
2594 1374528 : alpha = round_fx_sat( L_shl_sat( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/
2595 :
2596 : /*if( alpha > 0.999f { alpha = 0.999f;} */
2597 1374528 : alpha = s_min( alpha, 32735 ); /*.999 in Q15*/
2598 1374528 : alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */
2599 : /*--------------------------------------------------------------*
2600 : * during significant attacks, replace the LT energy by the
2601 : * current energy this will cause non_sta2 failures to occur in
2602 : * different frames than non_sta failures
2603 : *--------------------------------------------------------------*/
2604 :
2605 1374528 : alpha2 = alpha;
2606 1374528 : move16();
2607 1374528 : alpha2m1 = alpham1;
2608 1374528 : move16();
2609 1374528 : IF( spec_div > 0 )
2610 : {
2611 459164 : alpha2 = 0;
2612 459164 : move16();
2613 459164 : alpha2m1 = 32767;
2614 459164 : move16();
2615 : }
2616 1374528 : Lnon_sta2 = L_deposit_l( 1 << 10 ); // Q10
2617 :
2618 1374528 : non_sta = L_deposit_l( 1 << 10 ); // Q10
2619 1374528 : *non_staX = 0;
2620 1374528 : move16();
2621 1374528 : non_staB = 0;
2622 1374528 : move16();
2623 :
2624 1374528 : Le_min_scaled = L_shl( E_MIN_FXQ31, sub( q_enr, Q31 ) ); // q_enr
2625 :
2626 28853004 : FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ )
2627 : {
2628 27478476 : Ltmp = L_shl( 1, q_enr ); // q_enr
2629 : /* + 1.0f added to reduce sensitivity to non stationarity in low energies */
2630 : /* tmp_enr = enr[i] + 1.0f; */
2631 27478476 : L_tmp_enr = L_add( enr[i], Ltmp ); // q_enr
2632 :
2633 27478476 : IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */
2634 : {
2635 18234325 : L_tmp_ave = L_add( hNoiseEst->ave_enr_fx[i], Ltmp ); // q_enr
2636 :
2637 : /* if( enr[i] > st_ave_enr2[i] ) */
2638 : /* non_sta2 = non_sta2 * ((enr[i]+1) / (st_ave_enr2[i]+1)) */
2639 18234325 : Lnum = L_max( L_tmp_enr, L_tmp_ave ); // q_enr
2640 :
2641 : /* else */
2642 : /* non_sta2 = non_sta2 * ((st_ave_enr2[i]+1) / (enr[i]+1)) */
2643 18234325 : Lden = L_min( L_tmp_enr, L_tmp_ave ); // q_enr
2644 :
2645 18234325 : if ( Lden == 0 )
2646 : {
2647 0 : Lden = L_max( Ltmp, EPSILON_FX ); // q_enr
2648 : }
2649 :
2650 18234325 : ExpNum = sub( norm_l( Lnum ), 1 );
2651 18234325 : num = extract_h( L_shl( Lnum, ExpNum ) ); // q_enr+ExpNum-16
2652 :
2653 18234325 : ExpDen = norm_l( Lden );
2654 18234325 : den = extract_h( L_shl( Lden, ExpDen ) ); // q_enr+ExpDen-16
2655 :
2656 18234325 : num = div_s( num, den ); // 15+ExpNum-ExpDen
2657 18234325 : Ltmp1 = Mult_32_16( non_sta, num ); // 15+ExpNum-ExpDen+10-15
2658 18234325 : non_sta = L_shr_sat( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */
2659 : }
2660 :
2661 : /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */
2662 27478476 : Ltmp1 = Mult_32_16( hNoiseEst->ave_enr_fx[i], alpha ); // q_enr
2663 27478476 : Ltmp1 = Madd_32_16( Ltmp1, enr[i], alpham1 ); // q_enr
2664 27478476 : hNoiseEst->ave_enr_fx[i] = L_max( Le_min_scaled, Ltmp1 ); // q_enr
2665 27478476 : move32();
2666 :
2667 : /* calculation of another non-stationarity measure (following attacks) */
2668 : /*if( non_sta2 <= th_sta ){
2669 : tmp_ave2 = st->ave_enr2[i] + 1.0f;
2670 : if( tmp_enr > tmp_ave2 ){
2671 : non_sta2 = non_sta2 * ( tmp_enr / tmp_ave2 );
2672 : } else {
2673 : non_sta2 = non_sta2 * (tmp_ave2 / tmp_enr );
2674 : }
2675 : } */
2676 :
2677 : /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */
2678 27478476 : IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */
2679 : {
2680 22439079 : L_tmp_ave2 = L_add( hNoiseEst->ave_enr2_fx[i], Ltmp ); // q_enr
2681 22439079 : Lnum = L_max( L_tmp_enr, L_tmp_ave2 ); // q_enr
2682 22439079 : Lden = L_min( L_tmp_enr, L_tmp_ave2 ); // q_enr
2683 :
2684 22439079 : if ( Lden == 0 )
2685 : {
2686 0 : Lden = L_max( Ltmp, EPSILON_FX ); // q_enr
2687 : }
2688 :
2689 22439079 : ExpNum = sub( norm_l( Lnum ), 1 );
2690 22439079 : num = extract_h( L_shl( Lnum, ExpNum ) ); // q_enr+ExpNum-16
2691 :
2692 22439079 : ExpDen = norm_l( Lden );
2693 22439079 : den = extract_h( L_shl( Lden, ExpDen ) ); // q_enr+ExpDen-16
2694 :
2695 22439079 : num = div_s( num, den ); // 15+ExpNum-ExpDen
2696 22439079 : Ltmp1 = Mult_32_16( Lnon_sta2, num ); // 15+ExpNum-ExpDen+10-15
2697 22439079 : Lnon_sta2 = L_shr_sat( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */
2698 : }
2699 :
2700 : /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i] + (1.0f - alpha2) * (enr[i]) */
2701 27478476 : Ltmp1 = Mult_32_16( hNoiseEst->ave_enr2_fx[i], alpha2 ); // q_enr
2702 27478476 : Ltmp1 = Madd_32_16( Ltmp1, enr[i], alpha2m1 ); // q_enr
2703 27478476 : hNoiseEst->ave_enr2_fx[i] = L_max( Le_min_scaled, Ltmp1 ); // q_enr
2704 27478476 : move32();
2705 :
2706 : /* calculation of non-stationarity measure for speech/music classification */
2707 27478476 : IF( hFrontVad == NULL )
2708 : {
2709 25795556 : test();
2710 25795556 : test();
2711 25795556 : IF( GE_16( i, START_BAND_SPMUS ) && LT_16( i, NB_BANDS_SPMUS + START_BAND_SPMUS ) && st_fx->hSpMusClas != NULL )
2712 : {
2713 : /* log_enr = (float)ln_fx(enr[i]); */
2714 19355730 : Ltmp1 = L_max( enr[i], 1 );
2715 19355730 : e_ener = norm_l( Ltmp1 );
2716 19355730 : f_ener = Log2_norm_lc( L_shl( Ltmp1, e_ener ) );
2717 19355730 : e_ener = sub( sub( 30, e_ener ), q_enr );
2718 19355730 : Ltmp1 = L_mac( f_ener, e_ener, ONE_IN_Q14 ); // Q15
2719 19355730 : Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15
2720 19355730 : log_enr16 = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */
2721 19355730 : wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) );
2722 19355730 : *non_staX = L_add( *non_staX, wtmp );
2723 19355730 : move16(); /* Q8 */
2724 19355730 : hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16;
2725 19355730 : move16();
2726 : }
2727 : }
2728 :
2729 27478476 : test();
2730 27478476 : IF( GE_16( i, 2 ) && LE_16( i, 16 ) )
2731 : {
2732 20617920 : tmp_enr = LN_E_MIN_PLUS_ONE_FX; // Q8
2733 20617920 : move16();
2734 20617920 : IF( enr[i] != 0 )
2735 : {
2736 20617478 : Ltmp1 = L_add( enr[i], Ltmp ); // q_enr
2737 20617478 : e_ener = norm_l( Ltmp1 );
2738 20617478 : f_ener = Log2_norm_lc( L_shl( Ltmp1, e_ener ) );
2739 20617478 : e_ener = sub( sub( 30, e_ener ), q_enr );
2740 20617478 : Ltmp1 = L_mac( f_ener, e_ener, ONE_IN_Q14 ); // Q15
2741 20617478 : Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15
2742 20617478 : tmp_enr = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */
2743 : }
2744 :
2745 20617920 : IF( LT_16( ini_frame, 100 ) )
2746 : {
2747 4609020 : non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, LN_E_MIN_PLUS_ONE_FX ) ) ); /* Q8 */
2748 : }
2749 : ELSE /*ini_frame < 100*/
2750 : {
2751 16008900 : tmp_floor = LN_E_MIN_PLUS_ONE_FX; // Q8
2752 16008900 : move16();
2753 16008900 : IF( hNoiseEst->bckr_fx[i] != 0 )
2754 : {
2755 16008900 : diff = 1;
2756 16008900 : move16();
2757 16008900 : IF( GT_16( hNoiseEst->q_bckr, 30 ) )
2758 : {
2759 2190975 : diff = add( diff, sub( hNoiseEst->q_bckr, 30 ) );
2760 : }
2761 16008900 : Ltmp1 = L_add( L_shr( hNoiseEst->bckr_fx[i], diff ), L_shl( 1, sub( hNoiseEst->q_bckr, diff ) ) ); // hNoiseEst->q_bckr - diff
2762 16008900 : e_ener = norm_l( Ltmp1 );
2763 16008900 : f_ener = Log2_norm_lc( L_shl( Ltmp1, e_ener ) );
2764 16008900 : e_ener = sub( sub( 30, e_ener ), sub( hNoiseEst->q_bckr, diff ) );
2765 16008900 : Ltmp1 = L_mac( f_ener, e_ener, ONE_IN_Q14 ); // Q15
2766 16008900 : Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15
2767 16008900 : tmp_floor = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */
2768 : }
2769 16008900 : non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */
2770 : }
2771 : }
2772 :
2773 : } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */
2774 1374528 : *non_staX = L_shl( *non_staX, 12 ); // Q20
2775 1374528 : move32();
2776 1374528 : IF( LT_16( Etot, -1280 /* -5.0f in Q8 */ ) )
2777 : {
2778 129644 : non_sta = L_deposit_l( 1024 ); /* 1.0 in Q10 */
2779 129644 : Lnon_sta2 = L_deposit_l( 1024 ); /* 1.0 in Q10 */
2780 : }
2781 :
2782 1374528 : lim_Etot_fx = s_max( 5120, Etot ); /* 20.0f Q8 */
2783 1374528 : lim_Etot_sq_fx = L_mult0( lim_Etot_fx, lim_Etot_fx ); /* Q16 */
2784 :
2785 1374528 : IF( LT_16( ini_frame, 150 ) )
2786 : {
2787 : /* Allow use of quicker filter during init - if needed */
2788 : /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */
2789 394958 : hNoiseEst->L_Etot_st_est_fx = Madd_32_16_r( L_mult0( 8192, lim_Etot_fx ), hNoiseEst->L_Etot_st_est_fx, 24576 ); // Q23
2790 394958 : move32();
2791 : /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */
2792 394958 : hNoiseEst->L_Etot_sq_st_est_fx = Madd_32_16_r( Mult_32_16( lim_Etot_sq_fx, 8192 ), hNoiseEst->L_Etot_sq_st_est_fx, 24576 ); // Q16
2793 394958 : move32();
2794 : }
2795 : ELSE
2796 : {
2797 : /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */
2798 979570 : hNoiseEst->L_Etot_st_est_fx = Madd_32_16_r( L_mult0( 8192, lim_Etot_fx ), hNoiseEst->L_Etot_st_est_fx, 24576 ); // Q23
2799 979570 : move32();
2800 : /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */
2801 979570 : hNoiseEst->L_Etot_sq_st_est_fx = Madd_32_16_r( Mult_32_16( lim_Etot_sq_fx, 8192 ), hNoiseEst->L_Etot_sq_st_est_fx, 24576 ); // Q16
2802 979570 : move32();
2803 : }
2804 :
2805 : Word16 exp_tmp;
2806 1374528 : st_E_var_est_fx = BASOP_Util_Add_Mant32Exp( hNoiseEst->L_Etot_sq_st_est_fx, Q15, L_negate( Mpy_32_32( hNoiseEst->L_Etot_st_est_fx, hNoiseEst->L_Etot_st_est_fx ) ), Q16, &exp_tmp ); // exp(exp_tmp)
2807 : /*-----------------------------------------------------------------*
2808 : * Count frames since last correlation or harmonic event
2809 : *-----------------------------------------------------------------*/
2810 :
2811 1374528 : Ltmp = L_mult( st_fx->voicing_fx[0], 16384 /* 0.5 in Q15 */ ); // Q31
2812 1374528 : Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 /* 0.5 in Q15 */ ); // Q31
2813 :
2814 1374528 : *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 );
2815 1374528 : move16();
2816 1374528 : test();
2817 1374528 : test();
2818 1374528 : if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_32( Ltmp, 1825361101 /* 0.85 in Q31 */ ) ) ) )
2819 : {
2820 709797 : *st_harm_cor_cnt = 0;
2821 709797 : move16();
2822 : }
2823 :
2824 1374528 : test();
2825 1374528 : test();
2826 1374528 : test();
2827 1832519 : if ( ( GT_16( *st_harm_cor_cnt, 1 ) ) && ( ( LT_16( Etot, 3840 /* 15 in Q8 */ ) ) ||
2828 867513 : ( GT_16( ini_frame, 10 ) &&
2829 409522 : GT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 /* 7 in Q8 */ ) ) ) )
2830 : {
2831 172519 : *st_harm_cor_cnt = 1;
2832 172519 : move16();
2833 : }
2834 1374528 : test();
2835 1374528 : test();
2836 1374528 : IF( GT_16( *st_harm_cor_cnt, 1 ) && GT_16( Etot, 7680 /* 30.0f in Q8 */ ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( st_E_var_est_fx, exp_tmp, 524288 /* 8.0f in Q16 */, Q15 ), 1 ) )
2837 : {
2838 : /* st->harm_cor_cnt = max(1, (short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; */
2839 173011 : *st_harm_cor_cnt = s_max( 1, shr( add( *st_harm_cor_cnt, 2 ), 2 ) );
2840 173011 : move16();
2841 : }
2842 :
2843 :
2844 : /*-----------------------------------------------------------------*
2845 : * Energy based pause length counter
2846 : *-----------------------------------------------------------------*/
2847 1374528 : test();
2848 1374528 : IF( ( *bg_cnt >= 0 ) && ( GT_16( sub( Etot, Etot_l_lp ), 1280 ) /*5.0 in Q8*/ ) )
2849 : {
2850 : /* Possible speech burst */
2851 39543 : *bg_cnt = -1;
2852 39543 : move16();
2853 : }
2854 : ELSE
2855 : {
2856 1334985 : test();
2857 1334985 : if ( EQ_16( *bg_cnt, -1 ) && ( LT_16( sub( Etot, Etot_l_lp ), 1280 ) ) /*5 in Q8*/ )
2858 : {
2859 : /* Possible start of speech pause */
2860 34157 : *bg_cnt = 0;
2861 34157 : move16();
2862 : }
2863 : }
2864 1374528 : if ( *bg_cnt >= 0 )
2865 : {
2866 390624 : *bg_cnt = add( *bg_cnt, 1 );
2867 390624 : move16();
2868 : }
2869 :
2870 : /*-----------------------------------------------------------------*
2871 : * Linear predition efficiency 0 to 2 order
2872 : *-----------------------------------------------------------------*/
2873 :
2874 : /*epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); */
2875 1374528 : exp = sub( norm_l( epsP[0] ), 1 );
2876 1374528 : num = extract_h( L_shl( epsP[0], exp ) ); // Qx+exp-16
2877 :
2878 1374528 : exp2 = norm_l( epsP[2] );
2879 1374528 : den = extract_h( L_shl( epsP[2], exp2 ) ); // Qx+exp2-16
2880 :
2881 : /* max(0, min(8, epsP[0] / epsP[2])) */
2882 1374528 : epsP_0_2 = div_s( num, den ); // Q15+exp-exp2
2883 1374528 : epsP_0_2 = shr_sat( epsP_0_2, add( sub( exp, exp2 ), 3 ) ); // Q12
2884 1374528 : epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */
2885 :
2886 : /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */
2887 1374528 : hNoiseEst->epsP_0_2_lp_fx = mac_r( L_mult( epsP_0_2, 4915 /* 0.15 in Q15*/ ), hNoiseEst->epsP_0_2_lp_fx, 27853 /* 0.85 in Q15*/ ); // Q12
2888 1374528 : move16();
2889 :
2890 : /* epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); */
2891 1374528 : epsP_0_2_ad = abs_s( sub( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx ) ); /* Q12 */
2892 :
2893 : /*if (epsP_0_2_ad < st->epsP_0_2_ad_lp) {
2894 : st->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + (1.0f - 0.1f) * st->epsP_0_2_ad_lp;
2895 : } else {
2896 : st->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + (1.0f - 0.2f) * st->epsP_0_2_ad_lp;
2897 : } */
2898 :
2899 1374528 : IF( LT_16( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ) )
2900 : {
2901 966111 : hNoiseEst->epsP_0_2_ad_lp_fx = mac_r( L_mult( epsP_0_2_ad, 3277 /* 0.1 in Q15*/ ), hNoiseEst->epsP_0_2_ad_lp_fx, 29491 /* 0.9 in Q15*/ ); // Q12
2902 966111 : move16();
2903 : }
2904 : ELSE
2905 : {
2906 408417 : hNoiseEst->epsP_0_2_ad_lp_fx = mac_r( L_mult( epsP_0_2_ad, 6554 /* 0.2 in Q15*/ ), hNoiseEst->epsP_0_2_ad_lp_fx, 26214 /* 0.8 in Q15*/ ); // Q12
2907 408417 : move16();
2908 : }
2909 :
2910 : /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/
2911 1374528 : epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */
2912 :
2913 :
2914 : /*-----------------------------------------------------------------*
2915 : * Linear predition efficiency 2 to 16 order
2916 : *-----------------------------------------------------------------*/
2917 :
2918 : /*epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */
2919 1374528 : exp = sub( norm_l( epsP[2] ), 1 );
2920 1374528 : num = extract_h( L_shl( epsP[2], exp ) ); // Qx+exp-16
2921 :
2922 1374528 : exp2 = norm_l( epsP[16] );
2923 1374528 : den = extract_h( L_shl( epsP[16], exp2 ) ); // Qx+exp2-16
2924 :
2925 1374528 : epsP_2_16 = div_s( num, den ); // Q15+exp-exp2
2926 1374528 : epsP_2_16 = shr_sat( epsP_2_16, add( sub( exp, exp2 ), 3 ) ); // Q12
2927 1374528 : epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */
2928 :
2929 : /* if (epsP_2_16 > st->epsP_2_16_lp){
2930 : st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp;
2931 : } else {
2932 : st->epsP_2_16_lp = 0.03f * epsP_2_16 + (1.0f-0.03f) * st->epsP_2_16_lp;
2933 : } */
2934 :
2935 1374528 : IF( GT_16( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx ) )
2936 : {
2937 281935 : hNoiseEst->epsP_2_16_lp_fx = mac_r( L_mult( epsP_2_16, 6554 /* 0.2 in Q15*/ ), hNoiseEst->epsP_2_16_lp_fx, 26214 /* 0.8 in Q15*/ ); // Q12
2938 281935 : move16();
2939 : }
2940 : ELSE
2941 : {
2942 1092593 : hNoiseEst->epsP_2_16_lp_fx = mac_r( L_mult( epsP_2_16, 983 /* 0.03 in Q15*/ ), hNoiseEst->epsP_2_16_lp_fx, 31785 /* 0.97 in Q15*/ ); // Q12
2943 1092593 : move16();
2944 : }
2945 :
2946 1374528 : hNoiseEst->epsP_2_16_lp2_fx = mac_r( L_mult( epsP_2_16, 655 /* 0.02 in Q15*/ ), hNoiseEst->epsP_2_16_lp2_fx, 32113 /* 0.98 in Q15*/ ); // Q12
2947 1374528 : move16();
2948 :
2949 1374528 : epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx );
2950 :
2951 : /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) {
2952 : st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2;
2953 : } else {
2954 : st->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + (1.0f-0.05f) * st->epsP_2_16_dlp_lp2;
2955 : }*/
2956 :
2957 1374528 : IF( LT_16( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ) )
2958 : {
2959 813984 : hNoiseEst->epsP_2_16_dlp_lp2_fx = mac_r( L_mult( epsP_2_16_dlp, 655 /* 0.02 in Q15*/ ), hNoiseEst->epsP_2_16_dlp_lp2_fx, 32113 /* 0.98 in Q15*/ ); // Q12
2960 813984 : move16();
2961 : }
2962 : ELSE
2963 : {
2964 560544 : hNoiseEst->epsP_2_16_dlp_lp2_fx = mac_r( L_mult( epsP_2_16_dlp, 1638 /* 0.05 in Q15*/ ), hNoiseEst->epsP_2_16_dlp_lp2_fx, 31130 /* 0.95 in Q15*/ ); // Q12
2965 560544 : move16();
2966 : }
2967 :
2968 : /* epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); */
2969 1374528 : epsP_2_16_dlp_max = s_max( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx );
2970 :
2971 : /*-----------------------------------------------------------------*
2972 : * long term extensions of frame features
2973 : *-----------------------------------------------------------------*/
2974 :
2975 1374528 : tmp = sub( Etot, extract_h( hNoiseEst->totalNoise_32fx ) ); /* Q8 */
2976 : /* st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; */
2977 1374528 : tmp2 = 0;
2978 1374528 : move16();
2979 1374528 : if ( LT_16( tmp, 2560 ) ) /*10 in Q8 */
2980 : {
2981 258529 : tmp2 = 32767;
2982 258529 : move16();
2983 : }
2984 1374528 : hNoiseEst->lt_tn_track_fx = mac_r( L_mult( tmp2, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_tn_track_fx, 31785 /* 0.97 in Q15*/ ); // Q12
2985 1374528 : move16();
2986 :
2987 : /* st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; */
2988 1374528 : hNoiseEst->lt_tn_dist_fx = mac_r( L_mult( tmp, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_tn_dist_fx, 31785 /* 0.97 in Q15*/ ); // Q8
2989 1374528 : move16();
2990 :
2991 : /* st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist;*/
2992 1374528 : tmp = sub( Etot, extract_h( hNoiseEst->Etot_l_lp_32fx ) ); /* Q8 */
2993 1374528 : hNoiseEst->lt_Ellp_dist_fx = mac_r( L_mult( tmp, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_Ellp_dist_fx, 31785 /* 0.97 in Q15*/ ); // Q8
2994 1374528 : move16();
2995 :
2996 :
2997 : /* if (st->harm_cor_cnt == 0) {
2998 : st->lt_haco_ev = 0.03f*1.0 + 0.97f*st->lt_haco_ev;
2999 : } else {
3000 : st->lt_haco_ev = 0.99f*st->lt_haco_ev;
3001 : } */
3002 1374528 : IF( *st_harm_cor_cnt == 0 )
3003 : {
3004 709797 : hNoiseEst->lt_haco_ev_fx = mac_r( 64424509 /* 0.03 in Q31*/, hNoiseEst->lt_haco_ev_fx, 31785 /* 0.97 in Q15*/ ); // Q15
3005 709797 : move16();
3006 : }
3007 : ELSE
3008 : {
3009 664731 : hNoiseEst->lt_haco_ev_fx = mult_r( 32440, hNoiseEst->lt_haco_ev_fx ); /*.99 in Q15 , Q15 state */
3010 664731 : move16();
3011 : }
3012 :
3013 : /* if (st->lt_tn_track < 0.05f) {
3014 : st->low_tn_track_cnt++;
3015 : } else {
3016 : st->low_tn_track_cnt=0;
3017 : }*/
3018 1374528 : IF( LT_16( hNoiseEst->lt_tn_track_fx, 1638 ) ) /* 0.05 in Q15*/
3019 : {
3020 799471 : hNoiseEst->low_tn_track_cnt = add( hNoiseEst->low_tn_track_cnt, 1 );
3021 799471 : move16();
3022 : }
3023 : ELSE
3024 : {
3025 575057 : hNoiseEst->low_tn_track_cnt = 0;
3026 575057 : move16();
3027 : }
3028 :
3029 : /* update of the long-term non-stationarity measure (between 0 and 1) */
3030 : /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) {
3031 : st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1;
3032 : } else {
3033 : st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0;
3034 : }*/
3035 1374528 : test();
3036 1374528 : IF( ( GT_32( non_sta, th_sta ) ) || ( *loc_harm > 0 ) )
3037 : {
3038 1030679 : hNoiseEst->act_pred_fx = mac_r( 21474836 /* 1 - M_GAMMA in Q31 */, M_GAMMA_FX, hNoiseEst->act_pred_fx ); // Q31
3039 1030679 : move16();
3040 : }
3041 : ELSE
3042 : {
3043 343849 : hNoiseEst->act_pred_fx = mult_r( M_GAMMA_FX, hNoiseEst->act_pred_fx ); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */
3044 343849 : move16();
3045 : }
3046 :
3047 : /*-----------------------------------------------------------------*
3048 : * Background noise adaptation enable flag
3049 : *-----------------------------------------------------------------*/
3050 : /*
3051 : if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW )
3052 : && ( ( non_sta > th_sta ) ||
3053 : ( tmp_pc < TH_PC ) ||
3054 : ( noise_char > 0) )
3055 : )
3056 : ||
3057 : ( (st->ini_frame > 150) && (Etot - Etot_l_lp) > 10 ) ||
3058 : ( 0.5f * (voicing[0]+voicing[1]) > cor_max ) ||
3059 : ( epsP[2] / epsP[16] > th_eps ) ||
3060 : ( *loc_harm > 0) ||
3061 : ((st->act_pred > 0.8f) && (non_sta2 > th_sta))
3062 : ) */
3063 :
3064 1374528 : Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); /* Q15 + Q15(.5)) + 1 -> Q31 */
3065 1374528 : cor_tmp = mac_r( Ltmp, st_fx->voicing_fx[1], 16384 ); /* Q31 -16 -> Q15 */
3066 1374528 : if ( Etot < 0 )
3067 : {
3068 141606 : cor_tmp = 0;
3069 141606 : move16();
3070 : }
3071 : /* epsP[2] / epsP[16] */
3072 1374528 : exp = sub( norm_l( epsP[2] ), 1 );
3073 1374528 : num = extract_h( L_shl( epsP[2], exp ) ); // Qx+exp-16
3074 :
3075 1374528 : exp2 = norm_l( epsP[16] );
3076 1374528 : den = extract_h( L_shl( epsP[16], exp2 ) ); // Qx+exp2-16
3077 :
3078 1374528 : LepsP = extract_l( div_s( num, den ) ); // Q15+exp-exp2
3079 1374528 : LepsP = L_shr( LepsP, add( sub( exp, exp2 ), 4 ) ); // Q11
3080 :
3081 :
3082 1374528 : test();
3083 1374528 : test();
3084 1374528 : test();
3085 1374528 : test();
3086 1374528 : test();
3087 1374528 : test();
3088 1374528 : test();
3089 1374528 : test();
3090 1374528 : test();
3091 1374528 : test();
3092 1374528 : IF( ( ( LT_16( *st_harm_cor_cnt, ( 3 * HC_CNT_SLOW_FX ) ) ) && ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || ( noise_char > 0 ) ) ) ||
3093 : ( ( GT_16( ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( sub( Etot, Etot_l_lp ), 2560 ) ) ) ||
3094 : ( GT_16( cor_tmp, cor_max ) ) || /* Q15 */
3095 : ( GT_32( LepsP, th_eps ) ) || /* Q11 */
3096 : ( GT_16( *loc_harm, 0 ) ) ||
3097 : ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) /*act_pred in Q15 , th_sta in Q10 */
3098 : )
3099 : {
3100 : /* hNoiseEst->aEn = hNoiseEst->aEn + 2; */
3101 1144617 : hNoiseEst->aEn = add( hNoiseEst->aEn, 2 ); /* active signal present - increment counter */
3102 1144617 : move16();
3103 : }
3104 : ELSE
3105 : {
3106 : /* hNoiseEst->aEn = hNoiseEst->aEn - 1; */
3107 229911 : hNoiseEst->aEn = add( hNoiseEst->aEn, -1 ); /* background noise present - decrement counter */
3108 229911 : move16();
3109 : }
3110 :
3111 1374528 : hNoiseEst->aEn = s_max( s_min( hNoiseEst->aEn, 6 ), 0 );
3112 1374528 : move16();
3113 :
3114 1374528 : IF( LE_16( hNoiseEst->aEn, 1 ) )
3115 : {
3116 184975 : hNoiseEst->aEn_inac_cnt = add( hNoiseEst->aEn_inac_cnt, 1 );
3117 184975 : hNoiseEst->aEn_inac_cnt = s_min( hNoiseEst->aEn_inac_cnt, 128 );
3118 184975 : move16();
3119 184975 : move16();
3120 : }
3121 : /*-----------------------------------------------------------------*
3122 : * Stereo classifier - save raw aEn
3123 : *-----------------------------------------------------------------*/
3124 1374528 : IF( hStereoClassif != NULL )
3125 : {
3126 : /*
3127 : if ( ( non_sta > th_sta ) ||
3128 : ( tmp_pc < TH_PC ) ||
3129 : ( 0.5f * ( st->voicing[0] + st->voicing[1] ) > cor_max ) ||
3130 : ( epsP[2] / epsP[16] > th_eps ) ||
3131 : ( ( hNoiseEst->act_pred > 0.8f ) && ( non_sta2 > th_sta ) ) )*/
3132 879589 : wtmp = sub( hStereoClassif->aEn_raw[st_fx->idchan], 1 );
3133 879589 : test();
3134 879589 : test();
3135 879589 : test();
3136 879589 : test();
3137 879589 : test();
3138 1063853 : if ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) ||
3139 366822 : ( GT_16( cor_tmp, cor_max ) ) ||
3140 346092 : ( GT_32( LepsP, th_eps ) ) ||
3141 217342 : ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) ) /*act_pred in Q15 , th_sta in Q10 */
3142 : {
3143 : /* active signal present - increment counter */
3144 722565 : wtmp = add( hStereoClassif->aEn_raw[st_fx->idchan], 2 );
3145 : }
3146 879589 : hStereoClassif->aEn_raw[st_fx->idchan] = wtmp;
3147 879589 : move16();
3148 :
3149 879589 : wtmp = s_min( hStereoClassif->aEn_raw[st_fx->idchan], 6 );
3150 879589 : hStereoClassif->aEn_raw[st_fx->idchan] = s_max( wtmp, 0 );
3151 879589 : move16();
3152 : }
3153 :
3154 :
3155 : /* Additional NNE detectors */
3156 :
3157 : /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */
3158 : /* Q15 Q15 Q12 */
3159 1374528 : comb_ahc_epsP = s_max( shr( s_max( hNoiseEst->act_pred_fx, hNoiseEst->lt_haco_ev_fx ), 15 - 12 ), epsP_2_16_dlp ); /* Q12 */
3160 :
3161 :
3162 : /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */
3163 : /* Q15 Q12 Q12 */
3164 1374528 : comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */
3165 :
3166 : /*haco_ev_max = max(*st_harm_cor_cnt==0,st->lt_haco_ev); */
3167 1374528 : tmp = 0;
3168 1374528 : move16();
3169 1374528 : if ( *st_harm_cor_cnt == 0 )
3170 : {
3171 709797 : tmp = 32767;
3172 709797 : move16();
3173 : }
3174 1374528 : haco_ev_max = s_max( tmp, hNoiseEst->lt_haco_ev_fx ); /* Q15 */
3175 :
3176 : /* Etot_l_lp_thr = st->Etot_l_lp + (1.5f + 1.5f * (st->Etot_lp<50.0f))*st->Etot_v_h2; */
3177 1374528 : L_tmp = 49152; /* 1.5 Q15 */
3178 1374528 : move32();
3179 1374528 : if ( LT_16( hNoiseEst->Etot_lp_fx, 12800 ) ) /* 50.0 in Q8 */
3180 : {
3181 1017028 : L_tmp = L_shl( L_tmp, 1 ); /*1.5 + 1.5 Q15 */
3182 : }
3183 1374528 : temp = W_mac_32_32( W_mult_32_32( hNoiseEst->Etot_l_lp_32fx, ONE_IN_Q15 ), Etot_v_h2, L_tmp ); // Q40(24+15+1)
3184 1374528 : Etot_l_lp_thr = W_round32_s( temp ); // Q8
3185 :
3186 : /* enr_bgd = Etot < Etot_l_lp_thr; */
3187 1374528 : enr_bgd = 0;
3188 1374528 : move16();
3189 1374528 : if ( LT_16( Etot, Etot_l_lp_thr ) ) /* Q8 */
3190 : {
3191 359389 : enr_bgd = 1;
3192 359389 : move16(); /* Q0 */
3193 : }
3194 :
3195 : /* cns_bgd = (epsP_0_2 > 7.95f) && (non_sta< 1e3f); */
3196 1374528 : cns_bgd = 0;
3197 1374528 : move16();
3198 1374528 : test();
3199 1374528 : if ( ( GT_16( epsP_0_2, 32563 ) ) /* 7.95 in Q12 */
3200 499444 : && ( LT_32( non_sta, 1024000L ) ) ) /* 1e3f in Q10 ? */
3201 : {
3202 72719 : cns_bgd = 1;
3203 72719 : move16(); /* Q0 */
3204 : }
3205 :
3206 : /*lp_bgd = epsP_2_16_dlp_max < 0.10f; */
3207 1374528 : lp_bgd = 0;
3208 1374528 : move16();
3209 1374528 : if ( LT_16( epsP_2_16_dlp_max, 410 ) ) /*0.10 Q12 */
3210 : {
3211 156295 : lp_bgd = 1;
3212 156295 : move16(); /* Q0 */
3213 : }
3214 :
3215 :
3216 : /* ns_mask = non_sta < 1e5f; */
3217 1374528 : ns_mask = 0;
3218 1374528 : move16();
3219 1374528 : if ( LT_32( non_sta, 102400000 ) ) /* (1e5f in Q10)*/
3220 : {
3221 401940 : ns_mask = 1;
3222 401940 : move16(); /* Q0 */
3223 : }
3224 :
3225 :
3226 : /* lt_haco_mask = st->lt_haco_ev < 0.5f; */
3227 1374528 : lt_haco_mask = 0;
3228 1374528 : move16();
3229 1374528 : if ( LT_16( hNoiseEst->lt_haco_ev_fx, 16384 ) ) /* ( .5 in Q15)*/
3230 : {
3231 515769 : lt_haco_mask = 1;
3232 515769 : move16(); /* Q0 */
3233 : }
3234 :
3235 : /* bg_haco_mask = haco_ev_max < 0.4f; */
3236 1374528 : bg_haco_mask = 0;
3237 1374528 : move16();
3238 1374528 : if ( LT_16( haco_ev_max, 13107 ) ) /* ( 0.4 in Q15)*/
3239 : {
3240 380344 : bg_haco_mask = 1;
3241 380344 : move16(); /* Q0 */
3242 : }
3243 :
3244 :
3245 : /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */
3246 1374528 : SD_1 = 0;
3247 1374528 : move16();
3248 1374528 : test();
3249 1374528 : if ( ( GT_16( epsP_0_2_ad, 2048 ) ) /* 0.5 in Q12 */
3250 736473 : && ( GT_16( epsP_0_2, 32563 ) ) ) /* 7.95 in Q12 */
3251 : {
3252 284553 : SD_1 = 1;
3253 284553 : move16(); /* Q0 */
3254 : }
3255 :
3256 : /* NB "STL::test()"; has a cost of 2, using bitwise "s_and" , "s_or" at a cost of 1 */
3257 : /* NB only lowest bit position is used, result is always 0 or 1 */
3258 :
3259 : /* bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1==0 ); */
3260 1374528 : test();
3261 1374528 : test();
3262 1374528 : test();
3263 1374528 : test();
3264 1374528 : test();
3265 1374528 : bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && ( SD_1 == 0 ) );
3266 1374528 : move16();
3267 :
3268 : /*PD_1 = (epsP_2_16_dlp_max < 0.10f ) ; */
3269 1374528 : PD_1 = 0;
3270 1374528 : move16();
3271 1374528 : if ( ( LT_16( epsP_2_16_dlp_max, 410 ) ) ) /* 0.10 in Q12 */
3272 : {
3273 156295 : PD_1 = 1;
3274 156295 : move16(); /* Q0 */
3275 : }
3276 :
3277 : /*PD_2 = (epsP_0_2_ad_lp_max < 0.10f ) ; */
3278 1374528 : PD_2 = 0;
3279 1374528 : move16();
3280 1374528 : if ( ( LT_16( epsP_0_2_ad_lp_max, 410 ) ) ) /* 0.10 in Q12 */
3281 : {
3282 190469 : PD_2 = 1;
3283 190469 : move16(); /* Q0 */
3284 : }
3285 :
3286 : /*PD_3 = (comb_ahc_epsP < 0.85f ); */
3287 1374528 : PD_3 = 0;
3288 1374528 : move16();
3289 1374528 : if ( ( LT_16( comb_ahc_epsP, 3482 ) ) ) /* 0.85 in Q12 */
3290 : {
3291 336169 : PD_3 = 1;
3292 336169 : move16(); /* Q0 */
3293 : }
3294 :
3295 : /* PD_4 = comb_ahc_epsP < 0.15f; */
3296 1374528 : PD_4 = 0;
3297 1374528 : move16();
3298 1374528 : if ( ( LT_16( comb_ahc_epsP, 614 ) ) ) /* 0.15 in Q12 */
3299 : {
3300 75570 : PD_4 = 1;
3301 75570 : move16(); /* Q0 */
3302 : }
3303 :
3304 : /*PD_5 = comb_hcm_epsP < 0.30f; */
3305 1374528 : PD_5 = 0;
3306 1374528 : move16();
3307 1374528 : if ( ( LT_16( comb_hcm_epsP, 1229 ) ) ) /* 0.30 in Q12 */
3308 : {
3309 116378 : PD_5 = 1;
3310 116378 : move16(); /* Q0 */
3311 : }
3312 :
3313 : /* BG_1 = ( (SD_1==0) || (Etot < Etot_l_lp_thr) )
3314 : && bg_haco_mask && (st->act_pred < 0.85f) && (st->Etot_lp < 50.0f); */
3315 1374528 : BG_1 = 0;
3316 1374528 : move16();
3317 1374528 : test();
3318 1374528 : test();
3319 1374528 : test();
3320 1374528 : test();
3321 1374528 : if ( ( ( SD_1 == 0 ) || ( LT_16( Etot, Etot_l_lp_thr ) ) ) && ( bg_haco_mask != 0 ) && ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85f in Q15 */
3322 247345 : && ( LT_16( hNoiseEst->Etot_lp_fx, 50 * 256 ) ) ) /* 50.0 in Q8 */
3323 : {
3324 226284 : BG_1 = 1;
3325 226284 : move16();
3326 : }
3327 :
3328 : /* PAU = (st->aEn==0)
3329 : || ( (Etot < 55.0f) && (SD_1==0)
3330 : && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); */
3331 1374528 : PAU = 0;
3332 1374528 : move16();
3333 1374528 : test();
3334 1374528 : test();
3335 1374528 : test();
3336 1374528 : test();
3337 1374528 : test();
3338 1374528 : test();
3339 1374528 : test();
3340 1374528 : if ( ( hNoiseEst->aEn == 0 ) || ( LT_16( Etot, 55 * 256 ) && ( SD_1 == 0 ) && ( ( PD_3 && ( PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ) )
3341 : {
3342 211891 : PAU = 1;
3343 211891 : move16();
3344 : }
3345 :
3346 :
3347 : /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */
3348 1374528 : NEW_POS_BG = s_and( s_or( PAU, BG_1 ), bg_bgd3 );
3349 :
3350 : /* Original silence detector works in most cases */
3351 : /* aE_bgd = (st->aEn == 0);*/
3352 1374528 : aE_bgd = 0;
3353 1374528 : move16();
3354 1374528 : if ( hNoiseEst->aEn == 0 )
3355 : {
3356 174043 : aE_bgd = 1;
3357 174043 : move16();
3358 : }
3359 :
3360 : /* When the signal dynamics is high and the energy is close to the background estimate */
3361 : /* sd1_bgd = (st->sign_dyn_lp > 15)
3362 : && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2
3363 : && st->harm_cor_cnt > 20; */
3364 1374528 : sd1_bgd = 0;
3365 1374528 : move16();
3366 1374528 : test();
3367 1374528 : test();
3368 1374528 : if ( ( GT_16( hNoiseEst->sign_dyn_lp_fx, 15 * 256 ) ) /* 15 in Q8 */
3369 1037213 : && ( LT_32( L_sub( L_deposit_h( Etot ), hNoiseEst->Etot_l_lp_32fx ), L_shl( Etot_v_h2, 1 ) ) ) /* Q24 , Etot_v_h2 has limited dynmics can be upscaled*/
3370 143428 : && ( GT_16( *st_harm_cor_cnt, 20 ) ) )
3371 : {
3372 13415 : sd1_bgd = 1;
3373 13415 : move16();
3374 : }
3375 :
3376 : /* tn_ini = st->ini_frame < 150 && st->harm_cor_cnt > 5 &&
3377 : ( (st->act_pred < 0.59f && st->lt_haco_ev <0.23f ) ||
3378 : st->act_pred < 0.38f ||
3379 : st->lt_haco_ev < 0.15f ||
3380 : non_staB < 50.0f ||
3381 : aE_bgd );*/
3382 1374528 : tn_ini = 0;
3383 1374528 : move16();
3384 1374528 : test();
3385 1374528 : test();
3386 1374528 : test();
3387 1374528 : test();
3388 1374528 : test();
3389 1374528 : test();
3390 1374528 : test();
3391 1374528 : test();
3392 1374528 : test();
3393 1374528 : test();
3394 1374528 : test();
3395 1374528 : test();
3396 1374528 : test();
3397 1374528 : test();
3398 1374528 : test();
3399 1420419 : if ( LT_16( ini_frame, HE_LT_CNT_INIT_FX ) && GT_16( hNoiseEst->harm_cor_cnt, 5 ) && LT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 /* 7 in Q8 */ ) &&
3400 91782 : ( ( LT_16( hNoiseEst->act_pred_fx, 19333 /* 0.59 in Q15 */ ) && LT_16( hNoiseEst->lt_haco_ev_fx, 7537 /* 0.23 in Q15 */ ) ) || LT_16( hNoiseEst->act_pred_fx, 12452 /* 0.38 in Q15 */ ) ||
3401 52799 : ( ( ( st_fx->element_mode == EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 4915 /* 0.15 in Q15 */ ) ) || ( ( st_fx->element_mode > EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 2621 /* 0.08 in Q15 */ ) ) ) ||
3402 37020 : LT_16( non_staB, 50 * 256 /* 50 in Q8 */ ) || ( aE_bgd != 0 ) || ( LT_16( Etot, 10752 /* 42.0 in Q8 */ ) && GT_16( hNoiseEst->harm_cor_cnt, 10 ) && LT_16( hNoiseEst->lt_haco_ev_fx, 11469 /* 0.35 in Q8 */ ) && LT_16( hNoiseEst->act_pred_fx, 26214 /* 0.8 in Q8 */ ) ) ) )
3403 : {
3404 36259 : tn_ini = 1;
3405 36259 : move16();
3406 : }
3407 :
3408 : /* Energy close to the background estimate serves as a mask for other background detectors */
3409 : /* bg_bgd2 = Etot < Etot_l_lp_thr || tn_ini ; */
3410 1374528 : bg_bgd2 = 0;
3411 1374528 : move16();
3412 1374528 : test();
3413 1374528 : if ( ( LT_16( Etot, Etot_l_lp_thr ) ) || ( tn_ini != 0 ) )
3414 : {
3415 374814 : bg_bgd2 = 1;
3416 374814 : move16(); /* Q0 */
3417 : }
3418 :
3419 1374528 : updt_step = 0;
3420 1374528 : move16(); /* Q15 */
3421 : /*if (( bg_bgd2 && ( aE_bgd || sd1_bgd || st->lt_tn_track >0.90f || NEW_POS_BG ) )
3422 : || tn_ini ) */
3423 1374528 : test();
3424 1374528 : test();
3425 1374528 : test();
3426 1374528 : test();
3427 1374528 : test();
3428 1374528 : IF( ( bg_bgd2 && ( aE_bgd || sd1_bgd || GT_16( hNoiseEst->lt_tn_track_fx, 29491 /* 0.90 in Q15 */ ) || NEW_POS_BG ) ) || tn_ini )
3429 : {
3430 : /*if( ( ( st->act_pred < 0.85f )
3431 : && (aE_bgd !=0)
3432 : && ( st->lt_Ellp_dist < 10 || sd1_bgd )
3433 : && (st->lt_tn_dist<40)
3434 : && ( ( Etot - st->totalNoise ) < 10.0f )
3435 : )
3436 : || ( (st->first_noise_updt == 0) && (st->harm_cor_cnt > 80) && (aE_bgd!=0) && (st->lt_aEn_zero > 0.5f) )
3437 : || ( (tn_ini!=0) && ( aE_bgd != 0) || (non_staB < 10.0) || (st->harm_cor_cnt > 80) )
3438 : )*/
3439 :
3440 195325 : test();
3441 195325 : test();
3442 195325 : test();
3443 195325 : test();
3444 195325 : test();
3445 195325 : test();
3446 195325 : test(); /* for the ELSE IF below*/
3447 195325 : test();
3448 195325 : test();
3449 195325 : test();
3450 195325 : test();
3451 195325 : test();
3452 195325 : test(); /* for the ELSE IF below*/
3453 :
3454 195325 : test();
3455 195325 : test();
3456 195325 : test();
3457 195325 : test();
3458 195325 : test();
3459 195325 : test();
3460 195325 : test();
3461 195325 : test();
3462 195325 : test();
3463 195325 : test();
3464 195325 : test();
3465 195325 : test();
3466 195325 : test();
3467 195325 : test();
3468 195325 : test();
3469 195325 : test();
3470 195325 : test();
3471 195325 : IF( ( LT_16( hNoiseEst->act_pred_fx, 27853 /* 0.85 in Q15 */ ) && ( aE_bgd != 0 ) && ( LT_16( hNoiseEst->lt_Ellp_dist_fx, 10 * 256 /* 10 in Q8*/ ) || ( sd1_bgd != 0 ) ) && ( LT_16( hNoiseEst->lt_tn_dist_fx, 40 * 256 ) ) /* 40.0 in Q8*/
3472 : && LT_16( sub( Etot, extract_h( hNoiseEst->totalNoise_32fx ) ), 10 * 256 /* 10 in Q8 */ ) /* 10.0 in Q8*/ ) ||
3473 : ( ( hNoiseEst->first_noise_updt == 0 ) && GT_16( hNoiseEst->harm_cor_cnt, 80 ) && ( aE_bgd != 0 ) && GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 /* 0.5 in Q15 */ ) ) ||
3474 : ( ( tn_ini != 0 ) && ( ( aE_bgd != 0 ) || LT_16( non_staB, 10 * 256 /* 10 in Q8*/ ) || GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) ) )
3475 : {
3476 147699 : updt_step = 32767;
3477 147699 : move16();
3478 147699 : hNoiseEst->first_noise_updt = 1;
3479 147699 : move16();
3480 3101679 : FOR( i = 0; i < NB_BANDS; i++ )
3481 : {
3482 2953980 : hNoiseEst->bckr_fx[i] = tmpN[i];
3483 2953980 : move32();
3484 : }
3485 147699 : hNoiseEst->q_bckr = q_tmpN;
3486 147699 : move16();
3487 : }
3488 : /* else if ( ( ( st->act_pred < 0.80f ) && ( aE_bgd || PAU ) && st->lt_haco_ev < 0.10f )
3489 : || ( ( st->act_pred < 0.70f ) && ( aE_bgd || non_staB < 17.0f ) && PAU && st->lt_haco_ev < 0.15f )
3490 : || ( st->harm_cor_cnt > 80 && st->totalNoise > 5.0f && Etot < max(1.0f,Etot_l_lp + 1.5f* st->Etot_v_h2) )
3491 : ||
3492 : ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f )
3493 : || tn_ini
3494 : ) */
3495 47626 : ELSE IF( ( LT_16( hNoiseEst->act_pred_fx, 26214 /* 0.8 in Q15*/ ) && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 3277 /* 0.1 in q15*/ ) ) ) ||
3496 : ( ( LT_16( hNoiseEst->act_pred_fx, 22938 /* 0.70 in Q15 */ ) ) && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 17 * 256 /* 17.0 in Q8 */ ) ) ) && ( PAU != 0 ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 4915 /* 0.15 in Q15 */ ) ) ) ||
3497 : ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) && GT_16( extract_h( hNoiseEst->totalNoise_32fx ), 5 * 256 /* 5.0 in Q8 */ ) && LT_16( Etot, s_max( 1 * 256, add( Etot_l_lp, extract_h( L_add( hNoiseEst->Etot_v_h2_32fx, L_shr( hNoiseEst->Etot_v_h2_32fx, 1 ) ) ) /* 1.5= 1.0+.5 */ ) ) ) ) ||
3498 : ( GT_16( hNoiseEst->harm_cor_cnt, 50 ) && GT_16( hNoiseEst->first_noise_updt, 30 ) && ( aE_bgd != 0 ) && GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 /*.5 in Q15*/ ) ) || ( tn_ini != 0 ) )
3499 : {
3500 14409 : updt_step = 3277;
3501 14409 : move16(); /* 0.1 in Q15 */
3502 :
3503 : /* if ( !aE_bgd && st->harm_cor_cnt < 50
3504 : && ( (st->act_pred > 0.6f)
3505 : || ( (tn_ini==0) && (Etot_l_lp - st->totalNoise < 10.0f) && non_staB > 8.0f )
3506 : )
3507 : )
3508 : */
3509 14409 : test();
3510 14409 : test();
3511 14409 : test();
3512 14409 : test();
3513 14409 : test();
3514 24811 : if ( ( aE_bgd == 0 ) && LT_16( hNoiseEst->harm_cor_cnt, 50 ) &&
3515 15032 : ( GT_16( hNoiseEst->act_pred_fx, 19661 /* 0.6 in Q15*/ ) ||
3516 2502 : ( ( tn_ini == 0 ) && LT_16( sub( Etot_l_lp, extract_h( hNoiseEst->totalNoise_32fx ) ), 10 * 256 /* 10.0 in Q8 */ ) && GT_16( non_staB, 8 * 256 /* 8.0 in in Q8*/ ) ) ) )
3517 : {
3518 6195 : updt_step = 328;
3519 6195 : move16(); /* 0.01 Q15 */
3520 : }
3521 :
3522 14409 : hNoiseEst->first_noise_updt = 1;
3523 14409 : move16();
3524 14409 : IF( LT_16( q_tmpN, hNoiseEst->q_bckr ) )
3525 : {
3526 1573 : diff = sub( hNoiseEst->q_bckr, q_tmpN );
3527 33033 : FOR( i = 0; i < NB_BANDS; i++ )
3528 : {
3529 : /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/
3530 : /* 32 bit state update */
3531 31460 : Ltmp1 = L_shr( hNoiseEst->bckr_fx[i], diff );
3532 31460 : Ltmp = L_sub( tmpN[i], Ltmp1 ); // q_tmpN
3533 31460 : Ltmp = Mult_32_16( Ltmp, updt_step );
3534 31460 : hNoiseEst->bckr_fx[i] = L_add( Ltmp, Ltmp1 ); // q_tmpN
3535 31460 : move32();
3536 : }
3537 1573 : hNoiseEst->q_bckr = q_tmpN;
3538 1573 : move16();
3539 : }
3540 : ELSE
3541 : {
3542 12836 : diff = sub( q_tmpN, hNoiseEst->q_bckr );
3543 269556 : FOR( i = 0; i < NB_BANDS; i++ )
3544 : {
3545 : /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/
3546 : /* 32 bit state update */
3547 256720 : Ltmp = L_sub( L_shr( tmpN[i], diff ), hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr
3548 256720 : Ltmp = Mult_32_16( Ltmp, updt_step );
3549 256720 : hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); // hNoiseEst->q_bckr
3550 256720 : move32();
3551 : }
3552 : }
3553 : }
3554 : /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/
3555 33217 : ELSE IF( ( aE_bgd != 0 ) || GT_16( hNoiseEst->harm_cor_cnt, 100 ) )
3556 : {
3557 12911 : hNoiseEst->first_noise_updt = add( hNoiseEst->first_noise_updt, 1 );
3558 12911 : move16();
3559 : }
3560 : }
3561 : ELSE
3562 : {
3563 : /* If in music lower bckr to drop further */
3564 1179203 : test();
3565 1179203 : test();
3566 1179203 : IF( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) && GT_16( hNoiseEst->lt_haco_ev_fx, 29491 /* 0.9 in Q15 */ ) && ( hNoiseEst->totalNoise_32fx > 0 ) )
3567 : {
3568 3861 : updt_step = -655;
3569 3861 : move16(); /* for debug purposes */
3570 81081 : FOR( i = 0; i < NB_BANDS; i++ )
3571 : {
3572 77220 : IF( GT_32( hNoiseEst->bckr_fx[i], L_shl_sat( E_MIN_FXQ31, sub( hNoiseEst->q_bckr, Q30 ) ) /* 2*E_MIN */ ) )
3573 : {
3574 : /* st->bckr[i] = 0.98f*st->bckr[i]; */
3575 65340 : hNoiseEst->bckr_fx[i] = Mult_32_16( hNoiseEst->bckr_fx[i], 32113 /* .98 in Q15 */ ); // hNoiseEst->q_bckr
3576 65340 : move32(); /* move to array */
3577 : }
3578 : }
3579 : }
3580 : }
3581 : /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f) *st->lt_aEn_zero;*/
3582 : /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */
3583 1374528 : L_tmp = 0;
3584 1374528 : move32();
3585 1374528 : if ( hNoiseEst->aEn == 0 )
3586 : {
3587 174043 : L_tmp = 429496730; // 0.2 in Q31
3588 174043 : move32();
3589 : }
3590 1374528 : hNoiseEst->lt_aEn_zero_fx = mac_r( L_tmp, hNoiseEst->lt_aEn_zero_fx, 26214 /* 0.8 in Q15*/ ); // Q15
3591 1374528 : move16();
3592 :
3593 1374528 : IF( st_fx->element_mode > EVS_MONO )
3594 : {
3595 1374528 : test();
3596 1374528 : IF( hNoiseEst->first_noise_updt > 0 && LT_16( hNoiseEst->first_noise_updt_cnt, 100 ) )
3597 : {
3598 102872 : hNoiseEst->first_noise_updt_cnt = add( hNoiseEst->first_noise_updt_cnt, 1 );
3599 102872 : move16();
3600 : }
3601 : }
3602 :
3603 1374528 : return;
3604 : }
|