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