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