Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #include <math.h>
40 : #include "cnst.h"
41 : #include "prot.h"
42 : #include "wmc_auto.h"
43 :
44 : /*-----------------------------------------------------------------*
45 : * Local constants
46 : *-----------------------------------------------------------------*/
47 :
48 : #define ALPHA 0.1f
49 :
50 : #define COR_MIN8 0.65f
51 : #define COR_MAX8 0.7f
52 : #define TH_PC8 14
53 : #define TH_EPS8 10.4f
54 : #define TH_STA8 5.0e5f
55 : #define K_8 0.0091f
56 : #define C_8 0.3185f
57 : #define ALPHA_MAX8 0.999f
58 : #define THR_NCHAR8 1.0f
59 :
60 : #define COR_MIN16 0.52f
61 : #define COR_MAX16 0.85f
62 : #define TH_PC16 4
63 : #define TH_EPS16 1.6f
64 : /* 10.0e5f causes problems with music - as the noise estimate starts to track the music */
65 : #define TH_STA16 3.5e5f
66 : #define K_16 0.0245f
67 : #define C_16 -0.235f
68 : #define ALPHA_MAX16 0.99f
69 : #define THR_NCHAR16 1.0f
70 :
71 : #define TH_PC 12
72 : #define TH_PRED 0.8f
73 : #define THR_SPDIV 5
74 :
75 : #define HC_CNT 20 /* limit for harm corr count */
76 : #define HC_CNT_SLOW 80 /* limit for harm corr count slow */
77 : #define BCKR_SLOW_UPDATE_SCALE 0.1f /* step size for slow bckr update */
78 :
79 : #define HE_LT_THR1 10.0f
80 : #define HE_LT_THR2 30.0f
81 : #define HE_LT_CNT 30
82 :
83 : /*-----------------------------------------------------------------*
84 : * noise_est_init()
85 : *
86 : * Initialization of Noise estimator
87 : *-----------------------------------------------------------------*/
88 :
89 9785 : void noise_est_init(
90 : NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */
91 : )
92 : {
93 : int16_t i;
94 :
95 205485 : for ( i = 0; i < NB_BANDS; i++ )
96 : {
97 195700 : hNoiseEst->fr_bands1[i] = 1e-5f;
98 195700 : hNoiseEst->fr_bands2[i] = 1e-5f;
99 195700 : hNoiseEst->ave_enr2[i] = E_MIN;
100 :
101 195700 : hNoiseEst->enrO[i] = E_MIN;
102 195700 : hNoiseEst->bckr[i] = E_MIN;
103 195700 : hNoiseEst->ave_enr[i] = E_MIN;
104 : }
105 :
106 9785 : hNoiseEst->totalNoise = 0.0f;
107 9785 : hNoiseEst->first_noise_updt = 0;
108 9785 : hNoiseEst->first_noise_updt_cnt = 0;
109 :
110 9785 : hNoiseEst->aEn = 6;
111 9785 : hNoiseEst->aEn_inac_cnt = 0;
112 9785 : hNoiseEst->harm_cor_cnt = 0;
113 9785 : hNoiseEst->bg_cnt = 0;
114 9785 : hNoiseEst->lt_tn_track = 0.20f;
115 9785 : hNoiseEst->lt_tn_dist = 0.0f;
116 9785 : hNoiseEst->lt_Ellp_dist = 0.0f;
117 9785 : hNoiseEst->lt_haco_ev = 0.4f;
118 9785 : hNoiseEst->low_tn_track_cnt = 0;
119 :
120 9785 : hNoiseEst->Etot_st_est = 20.0f;
121 9785 : hNoiseEst->Etot_sq_st_est = 400.0f;
122 :
123 9785 : hNoiseEst->epsP_0_2_lp = 1.0f;
124 9785 : hNoiseEst->epsP_0_2_ad_lp = 0.0f;
125 9785 : hNoiseEst->epsP_2_16_lp = 1.0f;
126 9785 : hNoiseEst->epsP_2_16_lp2 = 1.0f;
127 9785 : hNoiseEst->epsP_2_16_dlp_lp = 0.0f;
128 9785 : hNoiseEst->epsP_2_16_dlp_lp2 = 0.0f;
129 9785 : hNoiseEst->lt_aEn_zero = 0.0f;
130 :
131 : /* Tonal detector */
132 1262265 : for ( i = 0; i < L_FFT / 2; i++ )
133 : {
134 1252480 : hNoiseEst->old_S[i] = 1;
135 : }
136 9785 : set_f( hNoiseEst->cor_map, 0, L_FFT / 2 );
137 9785 : hNoiseEst->act_pred = 1;
138 9785 : hNoiseEst->noise_char = 0;
139 9785 : hNoiseEst->multi_harm_limit = THR_CORR;
140 :
141 9785 : hNoiseEst->Etot_lp = 0.0f;
142 9785 : hNoiseEst->Etot_h = 0.0f;
143 9785 : hNoiseEst->Etot_l = 0.0f;
144 9785 : hNoiseEst->Etot_l_lp = 0.0f;
145 9785 : hNoiseEst->Etot_last = 0.0f;
146 9785 : hNoiseEst->Etot_v_h2 = 0.0f;
147 9785 : hNoiseEst->sign_dyn_lp = 0.0f;
148 :
149 9785 : return;
150 : }
151 :
152 :
153 : /*-----------------------------------------------------------------*
154 : * noise_est_pre()
155 : *
156 : * Track energy and signal dynamics
157 : *-----------------------------------------------------------------*/
158 :
159 1217770 : void noise_est_pre(
160 : const float Etot, /* i : Energy of current frame */
161 : const int16_t ini_frame, /* i : Frame number (init) */
162 : NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation data handle*/
163 : const int16_t idchan, /* i : channel ID */
164 : const int16_t element_mode, /* i : element mode */
165 : const int16_t last_element_mode /* i : last element mode */
166 : )
167 : {
168 1217770 : if ( ini_frame <= 1 || ( idchan == 1 && element_mode == IVAS_CPE_TD && last_element_mode == IVAS_CPE_DFT ) )
169 : {
170 17973 : hNoiseEst->Etot_lp = Etot;
171 17973 : hNoiseEst->Etot_h = Etot;
172 17973 : hNoiseEst->Etot_l = Etot;
173 17973 : hNoiseEst->Etot_l_lp = Etot;
174 17973 : hNoiseEst->Etot_last = Etot;
175 17973 : hNoiseEst->Etot_v_h2 = 0.0f;
176 17973 : hNoiseEst->sign_dyn_lp = 0.0f;
177 : }
178 : else
179 : {
180 1199797 : hNoiseEst->Etot_lp = 0.20f * Etot + 0.80f * hNoiseEst->Etot_lp;
181 1199797 : hNoiseEst->Etot_h -= 0.04f;
182 1199797 : if ( Etot > hNoiseEst->Etot_h )
183 : {
184 127089 : hNoiseEst->Etot_h = Etot;
185 : }
186 1199797 : hNoiseEst->Etot_l += 0.08f;
187 :
188 : /* Could even be higher but it also delays first entry to DTX */
189 1199797 : if ( hNoiseEst->harm_cor_cnt > 50 )
190 : {
191 53797 : if ( ini_frame < min( 150, MAX_FRAME_COUNTER - 1 ) && ( hNoiseEst->Etot_h - hNoiseEst->Etot_lp ) < 3.0f )
192 : {
193 8795 : hNoiseEst->Etot_l += min( 2, ( hNoiseEst->Etot_last - hNoiseEst->Etot_l ) * 0.1f );
194 : }
195 :
196 : /* Avoids large steps in short active segments */
197 53797 : if ( hNoiseEst->Etot_last - hNoiseEst->Etot_l > HE_LT_THR2 && hNoiseEst->harm_cor_cnt > 250 )
198 : {
199 0 : hNoiseEst->Etot_l += ( hNoiseEst->Etot_last - hNoiseEst->Etot_l ) * 0.02f;
200 : }
201 53797 : else if ( ( hNoiseEst->Etot_last - hNoiseEst->Etot_l ) > HE_LT_THR1 )
202 : {
203 2282 : hNoiseEst->Etot_l += 0.08f;
204 : }
205 : }
206 :
207 1199797 : if ( Etot < hNoiseEst->Etot_l )
208 : {
209 169366 : hNoiseEst->Etot_l = Etot;
210 : }
211 :
212 1199797 : if ( ini_frame < 100 && hNoiseEst->Etot_l < hNoiseEst->Etot_l_lp )
213 : {
214 90987 : hNoiseEst->Etot_l_lp = 0.1f * hNoiseEst->Etot_l + ( 1.0f - 0.1f ) * hNoiseEst->Etot_l_lp;
215 : }
216 1108810 : else if ( ( hNoiseEst->harm_cor_cnt > HE_LT_CNT && ( hNoiseEst->Etot_last - hNoiseEst->Etot_l ) > HE_LT_THR2 ) || ( hNoiseEst->harm_cor_cnt > HE_LT_CNT && ( ini_frame < 150 ) ) || ( ( hNoiseEst->Etot_l_lp - hNoiseEst->Etot_l ) > HE_LT_THR2 ) )
217 : {
218 28003 : hNoiseEst->Etot_l_lp = 0.03f * hNoiseEst->Etot_l + ( 1.0f - 0.03f ) * hNoiseEst->Etot_l_lp;
219 : }
220 : else
221 : {
222 1080807 : hNoiseEst->Etot_l_lp = 0.02f * hNoiseEst->Etot_l + ( 1.0f - 0.02f ) * hNoiseEst->Etot_l_lp;
223 : }
224 :
225 1199797 : hNoiseEst->sign_dyn_lp = 0.1f * ( hNoiseEst->Etot_h - hNoiseEst->Etot_l ) + ( 1.0f - 0.1f ) * hNoiseEst->sign_dyn_lp;
226 : }
227 :
228 1217770 : return;
229 : }
230 :
231 :
232 : /*-----------------------------------------------------------------*
233 : * noise_est_down()
234 : *
235 : * Down-ward noise updatation routine
236 : * Total Noise computation, relative frame Energy computation
237 : * Noise energy update - here, the energy is updated only if it is
238 : * decreasing to improve noise suppression. Otherwise, the noise
239 : * update is done on noise-only frames and this decision is made in
240 : * nois_est() later in this file.
241 : *-----------------------------------------------------------------*/
242 :
243 1217770 : void noise_est_down(
244 : const float fr_bands[], /* i : per band input energy (contains 2 vectors) */
245 : float bckr[], /* i/o: per band background noise energy estimate */
246 : float tmpN[], /* o : temporary noise update */
247 : float enr[], /* o : averaged energy over both subframes */
248 : const int16_t min_band, /* i : minimum critical band */
249 : const int16_t max_band, /* i : maximum critical band */
250 : float *totalNoise, /* o : noise estimate over all critical bands */
251 : const float Etot, /* i : Energy of current frame */
252 : float *Etot_last, /* i/o: Energy of last frame */
253 : float *Etot_v_h2 /* i/o: Energy variaions of noise frames */
254 : )
255 : {
256 : const float *pt1, *pt2;
257 : int16_t i;
258 : float Etot_v;
259 :
260 : /*-----------------------------------------------------------------*
261 : * Estimate total noise energy
262 : *-----------------------------------------------------------------*/
263 :
264 1217770 : *totalNoise = 0.0f;
265 25557230 : for ( i = min_band; i <= max_band; i++ )
266 : {
267 24339460 : *totalNoise += bckr[i];
268 : }
269 1217770 : *totalNoise = 10.0f * (float) log10( *totalNoise );
270 :
271 : /*-----------------------------------------------------------------*
272 : * Average energy per frame for each frequency band
273 : *-----------------------------------------------------------------*/
274 :
275 1217770 : pt1 = fr_bands;
276 1217770 : pt2 = fr_bands + NB_BANDS;
277 :
278 25573170 : for ( i = 0; i < NB_BANDS; i++ )
279 : {
280 24355400 : enr[i] = 0.5f * ( *pt1++ + *pt2++ );
281 : }
282 :
283 : /*-----------------------------------------------------------------*
284 : * Background noise energy update
285 : *-----------------------------------------------------------------*/
286 :
287 25573170 : for ( i = 0; i < NB_BANDS; i++ )
288 : {
289 24355400 : tmpN[i] = ( 1 - ALPHA ) * bckr[i] + ALPHA * enr[i];
290 24355400 : if ( tmpN[i] < bckr[i] )
291 : {
292 1670378 : bckr[i] = tmpN[i]; /* Defend to increase noise estimate: keep as it is or decrease */
293 : }
294 : }
295 :
296 : /*------------------------------------------------------------------*
297 : * Energy variation update
298 : *------------------------------------------------------------------*/
299 :
300 1217770 : Etot_v = (float) fabs( *Etot_last - Etot );
301 :
302 1217770 : *Etot_v_h2 = ( 1.0f - 0.02f ) * *Etot_v_h2 + 0.02f * min( 3.0f, Etot_v );
303 1217770 : if ( *Etot_v_h2 < 0.1f )
304 : {
305 89850 : *Etot_v_h2 = 0.1f;
306 : }
307 :
308 1217770 : return;
309 : }
310 :
311 :
312 : /*-----------------------------------------------------------------*
313 : * noise_est()
314 : *
315 : * Noise energy estimation (noise energy is updated in case of noise-only frame)
316 : *-----------------------------------------------------------------*/
317 :
318 1217770 : void noise_est(
319 : Encoder_State *st, /* i/o: encoder state structure */
320 : const int16_t old_pitch1, /* i : previous frame OL pitch[1] */
321 : const float tmpN[], /* i : temporary noise update */
322 : const float *epsP, /* i : LP prediction error energies */
323 : const float Etot, /* i : total channel E */
324 : const float relE, /* i : relative frame energy */
325 : const float corr_shift, /* i : normalized correlation correction */
326 : const float enr[], /* i : averaged energy over both subframes */
327 : float fr_bands[], /* i : spectrum per critical bands of the current frame*/
328 : float *cor_map_sum, /* o : sum of correlation map from mult-harm analysis */
329 : float *ncharX, /* o : noise character for sp/mus classifier */
330 : float *sp_div, /* o : spectral diversity feature */
331 : float *non_staX, /* o : non-stationarity for sp/mus classifier */
332 : int16_t *loc_harm, /* o : multi-harmonicity flag for UV classifier */
333 : const float *lf_E, /* i : per bin energy for low frequencies */
334 : int16_t *st_harm_cor_cnt, /* i/o: 1st harm correlation timer */
335 : const float Etot_l_lp, /* i : Smoothed low energy */
336 : float *sp_floor, /* o : noise floor estimate */
337 : float S_map[], /* o : short-term correlation map */
338 : STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
339 : FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */
340 : const int16_t ini_frame /* i : Frame number (init) */
341 : )
342 : {
343 : int16_t i, tmp_pc, pc, spec_div, noise_char;
344 : float alpha, th_eps, th_sta, non_sta, cor_min, cor_max;
345 : float non_sta2, alpha2, sum_num, sum_den, *pt1, *pt2, ftemp, ftemp2, nchar_thr;
346 : float updt_step, log_enr;
347 : int16_t aE_bgd, sd1_bgd, bg_bgd2;
348 : int16_t tn_ini;
349 : float epsP_0_2, epsP_0_2_ad, epsP_0_2_ad_lp_max;
350 : float epsP_2_16, epsP_2_16_dlp, epsP_2_16_dlp_max;
351 : int16_t PAU, BG_1, NEW_POS_BG;
352 : float haco_ev_max;
353 : float Etot_l_lp_thr;
354 : float comb_ahc_epsP, comb_hcm_epsP;
355 : int16_t enr_bgd, cns_bgd, lp_bgd, ns_mask;
356 : int16_t lt_haco_mask, bg_haco_mask;
357 : int16_t SD_1, bg_bgd3, PD_1, PD_2, PD_3, PD_4, PD_5;
358 : float tmp_enr, tmp_ave, tmp_ave2;
359 : float non_staB;
360 : float lim_Etot;
361 : NOISE_EST_HANDLE hNoiseEst;
362 :
363 : /* Check if LR-VAD */
364 1217770 : if ( hFrontVad != NULL )
365 : {
366 81726 : hNoiseEst = hFrontVad->hNoiseEst;
367 : }
368 : else
369 : {
370 1136044 : hNoiseEst = st->hNoiseEst;
371 : }
372 :
373 : /*-----------------------------------------------------------------*
374 : * Initialization
375 : *-----------------------------------------------------------------*/
376 :
377 1217770 : if ( hFrontVad == NULL )
378 : {
379 1136044 : if ( st->hSpMusClas != NULL )
380 : {
381 : float E;
382 :
383 1136044 : E = mean( lf_E, 8 );
384 1136044 : if ( E < 1.0f )
385 : {
386 137331 : st->hSpMusClas->ener_RAT = 0.f;
387 : }
388 : else
389 : {
390 998713 : st->hSpMusClas->ener_RAT = 10.0f * (float) log10( E );
391 998713 : st->hSpMusClas->ener_RAT /= ( Etot + 0.01f );
392 : }
393 :
394 1136044 : if ( st->hSpMusClas->ener_RAT > 1.0 )
395 : {
396 0 : st->hSpMusClas->ener_RAT = 1.0f;
397 : }
398 : }
399 : }
400 :
401 : /*-----------------------------------------------------------------*
402 : * Set the threshold for eps & non_sta based on input sampling rate
403 : * The reason is that in case of 8kHz sampling input, there is nothing
404 : * between 4kHz-6.4kHz. In noisy conditions, this makes a fast
405 : * transition even in noise-only parts, hence producing a "higher
406 : * order" spectral envelope => the epsP ratio is much less effective.
407 : *-----------------------------------------------------------------*/
408 :
409 1217770 : if ( st->input_bwidth != NB )
410 : {
411 : /* WB input */
412 1213759 : th_eps = TH_EPS16;
413 1213759 : th_sta = TH_STA16;
414 1213759 : cor_min = COR_MIN16;
415 1213759 : cor_max = COR_MAX16;
416 : }
417 : else
418 : {
419 : /* NB input */
420 4011 : th_eps = TH_EPS8;
421 4011 : th_sta = TH_STA8;
422 4011 : cor_min = COR_MIN8;
423 4011 : cor_max = COR_MAX8;
424 : }
425 :
426 : /*-----------------------------------------------------------------*
427 : * Estimation of pitch stationarity
428 : *-----------------------------------------------------------------*/
429 :
430 1217770 : pc = (int16_t) ( abs( st->pitch[0] - old_pitch1 ) + abs( st->pitch[1] - st->pitch[0] ) );
431 :
432 1217770 : if ( ( ( st->voicing[0] + st->voicing[1] + st->voicing[2] ) / 3.0f + corr_shift ) < cor_min )
433 : {
434 : /* low correlation -> probably inactive signal */
435 262809 : tmp_pc = TH_PC;
436 : }
437 : else
438 : {
439 954961 : tmp_pc = pc;
440 : }
441 :
442 : /*-----------------------------------------------------------------*
443 : * Multi-harmonic analysis
444 : *-----------------------------------------------------------------*/
445 :
446 1217770 : if ( hFrontVad == NULL )
447 : {
448 1136044 : if ( st->hSpMusClas != NULL )
449 : {
450 1136044 : i = 0;
451 1136044 : *loc_harm = multi_harm( st->Bin_E, hNoiseEst->old_S, hNoiseEst->cor_map, &hNoiseEst->multi_harm_limit, st->total_brate, st->bwidth, ( st->hGSCEnc != NULL ) ? &st->hGSCEnc->cor_strong_limit : &i, &st->hSpMusClas->mean_avr_dyn, &st->hSpMusClas->last_sw_dyn, cor_map_sum, sp_floor, S_map );
452 : }
453 : }
454 :
455 : /*-----------------------------------------------------------------*
456 : * Detection of frames with non-stationary spectral content
457 : *-----------------------------------------------------------------*/
458 :
459 : /* weighted sum of spectral changes per critical bands */
460 1217770 : sum_num = 0;
461 1217770 : sum_den = 0;
462 :
463 1217770 : pt1 = fr_bands + 10;
464 1217770 : pt2 = hNoiseEst->fr_bands2 + 10;
465 13383515 : for ( i = 10; i <= st->max_band; i++ )
466 : {
467 12165745 : if ( *pt1 > *pt2 )
468 : {
469 5148572 : sum_num += *pt1 * *pt1 / *pt2;
470 5148572 : sum_den += *pt1;
471 : }
472 : else
473 : {
474 7017173 : sum_num += *pt2 * *pt2 / *pt1;
475 7017173 : sum_den += *pt2;
476 : }
477 :
478 12165745 : pt1++;
479 12165745 : pt2++;
480 : }
481 :
482 : /* calculation of spectral diversity */
483 1217770 : if ( sum_num > THR_SPDIV * sum_den )
484 : {
485 400197 : spec_div = 1;
486 : }
487 : else
488 : {
489 817573 : spec_div = 0;
490 : }
491 :
492 1217770 : *sp_div = sum_num / ( sum_den + 1e-5f );
493 :
494 : /*-----------------------------------------------------------------*
495 : * Detection of frames with high energy content in high frequencies
496 : *-----------------------------------------------------------------*/
497 :
498 : /* calculation of energy in first 10 critical bands */
499 1217770 : ftemp = sum_f( &fr_bands[st->min_band], 10 - st->min_band );
500 :
501 : /* calculation of energy in the rest of bands */
502 1217770 : ftemp2 = sum_f( &fr_bands[10], st->max_band - 10 + 1 );
503 :
504 1217770 : if ( ncharX != NULL )
505 : {
506 1214670 : *ncharX = ftemp2 / ( ftemp + 1e-5f );
507 : }
508 :
509 1217770 : if ( ftemp < 1e2 || ftemp2 < 1e2 )
510 : {
511 475546 : ftemp2 = 0;
512 : }
513 : else
514 : {
515 742224 : ftemp2 /= ftemp;
516 : }
517 :
518 1217770 : if ( hStereoClassif != NULL )
519 : {
520 782031 : if ( st->idchan == 0 )
521 : {
522 420855 : hStereoClassif->nchar_ch1 = ftemp2;
523 : }
524 : else
525 : {
526 361176 : hStereoClassif->nchar_ch2 = ftemp2;
527 : }
528 : }
529 :
530 1217770 : if ( ftemp2 > 10 )
531 : {
532 12000 : ftemp2 = 10;
533 : }
534 :
535 : /* update LT value of the final parameter */
536 1217770 : hNoiseEst->noise_char = M_ALPHA * hNoiseEst->noise_char + ( 1 - M_ALPHA ) * ftemp2;
537 :
538 1217770 : if ( st->input_bwidth == NB )
539 : {
540 4011 : nchar_thr = THR_NCHAR8;
541 : }
542 : else
543 : {
544 1213759 : nchar_thr = THR_NCHAR16;
545 : }
546 :
547 1217770 : if ( hNoiseEst->noise_char > nchar_thr )
548 : {
549 114797 : noise_char = 1;
550 : }
551 : else
552 : {
553 1102973 : noise_char = 0;
554 : }
555 :
556 : /* save the 2 last spectra per crit. bands for the future */
557 1217770 : mvr2r( hNoiseEst->fr_bands1, hNoiseEst->fr_bands2, NB_BANDS );
558 1217770 : mvr2r( fr_bands + NB_BANDS, hNoiseEst->fr_bands1, NB_BANDS );
559 :
560 : /*-----------------------------------------------------------------*
561 : * Non-stationarity estimation for each band (handicap high E frames in average computing)
562 : *-----------------------------------------------------------------*/
563 :
564 : /* set averaging factor */
565 1217770 : ftemp = relE;
566 1217770 : if ( ftemp < 0.0f )
567 : {
568 826312 : ftemp = 0.0f;
569 : }
570 :
571 1217770 : alpha = 0.064f * ftemp + 0.75f;
572 :
573 1217770 : if ( alpha > 0.999f )
574 : {
575 211493 : alpha = 0.999f;
576 : }
577 :
578 : /* during significant attacks, replace LT energy by the */
579 : /* current energy - this will cause non_sta2 failures to occur in */
580 : /* different frames than non_sta failures */
581 1217770 : alpha2 = alpha;
582 1217770 : if ( spec_div > 0 )
583 : {
584 400197 : alpha2 = 0.0f;
585 : }
586 :
587 : /* calculate non-stationarity */
588 1217770 : non_sta = 1.0f;
589 1217770 : non_sta2 = 1.0f;
590 1217770 : *non_staX = 0.0f;
591 1217770 : non_staB = 0.0f;
592 25557230 : for ( i = st->min_band; i <= st->max_band; i++ )
593 : {
594 : /* + 1.0f added to reduce sencitivity to non stationarity in low energies */
595 24339460 : tmp_enr = enr[i] + 1.0f;
596 24339460 : if ( non_sta <= th_sta ) /* Just to limit the saturation */
597 : {
598 16488462 : tmp_ave = hNoiseEst->ave_enr[i] + 1.0f;
599 16488462 : if ( tmp_enr > tmp_ave )
600 : {
601 6104959 : non_sta = non_sta * ( tmp_enr / tmp_ave ); /* non_stationarity measure */
602 : }
603 : else
604 : {
605 10383503 : non_sta = non_sta * ( tmp_ave / tmp_enr ); /* non_stationarity measure */
606 : }
607 : }
608 24339460 : hNoiseEst->ave_enr[i] = alpha * hNoiseEst->ave_enr[i] + ( 1 - alpha ) * enr[i]; /* update long-term average */
609 :
610 : /* calculation of another non-stationarity measure (following attacks) */
611 24339460 : if ( non_sta2 <= th_sta )
612 : {
613 20089507 : tmp_ave2 = hNoiseEst->ave_enr2[i] + 1.0f;
614 20089507 : if ( tmp_enr > tmp_ave2 )
615 : {
616 7705486 : non_sta2 = non_sta2 * ( tmp_enr / tmp_ave2 );
617 : }
618 : else
619 : {
620 12384021 : non_sta2 = non_sta2 * ( tmp_ave2 / tmp_enr );
621 : }
622 : }
623 :
624 24339460 : hNoiseEst->ave_enr2[i] = alpha2 * hNoiseEst->ave_enr2[i] + ( 1 - alpha2 ) * enr[i];
625 :
626 : /* calculate non-stationarity feature for speech/music classifier */
627 24339460 : if ( hFrontVad == NULL )
628 : {
629 22704940 : if ( i >= START_BAND_SPMUS && i < NB_BANDS_SPMUS + START_BAND_SPMUS && st->hSpMusClas != NULL )
630 : {
631 17040660 : log_enr = (float) log( enr[i] );
632 17040660 : if ( log_enr > st->hSpMusClas->past_log_enr[i - START_BAND_SPMUS] )
633 : {
634 7200901 : *non_staX += log_enr - st->hSpMusClas->past_log_enr[i - START_BAND_SPMUS];
635 : }
636 : else
637 : {
638 9839759 : *non_staX += st->hSpMusClas->past_log_enr[i - START_BAND_SPMUS] - log_enr;
639 : }
640 :
641 17040660 : st->hSpMusClas->past_log_enr[i - START_BAND_SPMUS] = log_enr;
642 : }
643 : }
644 :
645 : /* calculate non-stationarity feature relative background */
646 24339460 : if ( ini_frame < 100 )
647 : {
648 : /* During init don't include updates */
649 5646640 : if ( i >= 2 && i <= 16 )
650 : {
651 4234980 : non_staB += (float) fabs( log( enr[i] + 1.0f ) - log( E_MIN + 1.0f ) );
652 : }
653 : }
654 : else
655 : {
656 : /* After init compare with background estimate */
657 18692820 : if ( i >= 2 && i <= 16 )
658 : {
659 14031570 : non_staB += (float) fabs( log( enr[i] + 1.0f ) - log( hNoiseEst->bckr[i] + 1.0f ) );
660 : }
661 : }
662 :
663 24339460 : if ( non_staB >= 128 )
664 : {
665 163979 : non_staB = MAX16B_FLT / 256.0f;
666 : }
667 : }
668 :
669 1217770 : if ( Etot < -5.0f )
670 : {
671 117434 : non_sta = 1.0f;
672 117434 : non_sta2 = 1.0f;
673 : }
674 :
675 1217770 : lim_Etot = max( 20.0f, Etot );
676 :
677 1217770 : if ( ini_frame < 150 )
678 : {
679 : /* Allow use of quicker filter during init - if needed */
680 368694 : hNoiseEst->Etot_st_est = 0.25f * lim_Etot + ( 1.0f - 0.25F ) * hNoiseEst->Etot_st_est;
681 368694 : hNoiseEst->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + ( 1.0f - 0.25f ) * hNoiseEst->Etot_sq_st_est;
682 : }
683 : else
684 : {
685 849076 : hNoiseEst->Etot_st_est = 0.25f * lim_Etot + ( 1.0f - 0.25f ) * hNoiseEst->Etot_st_est;
686 849076 : hNoiseEst->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + ( 1.0f - 0.25f ) * hNoiseEst->Etot_sq_st_est;
687 : }
688 :
689 : /*-----------------------------------------------------------------*
690 : * Count frames since last correlation or harmonic event
691 : *-----------------------------------------------------------------*/
692 :
693 1217770 : if ( Etot > 0 && ( *loc_harm > 0 || 0.5f * ( st->voicing[0] + st->voicing[1] ) > 0.85f ) )
694 : {
695 634874 : hNoiseEst->harm_cor_cnt = 0;
696 : }
697 : else
698 : {
699 582896 : hNoiseEst->harm_cor_cnt += 1;
700 : }
701 :
702 1217770 : if ( hNoiseEst->harm_cor_cnt > 1 && ( ( Etot < 15.0f ) || ( ini_frame > 10 && ( Etot - hNoiseEst->Etot_lp ) > 7.0f ) ) )
703 : {
704 149247 : hNoiseEst->harm_cor_cnt = 1;
705 : }
706 :
707 1217770 : if ( hNoiseEst->harm_cor_cnt > 1 && Etot > 30.0f && ( hNoiseEst->Etot_sq_st_est - hNoiseEst->Etot_st_est * hNoiseEst->Etot_st_est ) > 8.0f )
708 : {
709 154808 : hNoiseEst->harm_cor_cnt = max( 1, (int16_t) round_f( (float) hNoiseEst->harm_cor_cnt / 4.0f ) );
710 : }
711 :
712 : /*-----------------------------------------------------------------*
713 : * Energy-based pause-length counter
714 : *-----------------------------------------------------------------*/
715 :
716 1217770 : if ( hNoiseEst->bg_cnt >= 0 && ( Etot - hNoiseEst->Etot_l_lp ) > 5 )
717 : {
718 : /* probably speech burst */
719 38755 : hNoiseEst->bg_cnt = -1;
720 : }
721 : else
722 : {
723 1179015 : if ( hNoiseEst->bg_cnt == -1 && ( Etot - hNoiseEst->Etot_l_lp ) < 5 )
724 : {
725 : /* probably start of speech pause */
726 35105 : hNoiseEst->bg_cnt = 0;
727 : }
728 : }
729 :
730 1217770 : if ( hNoiseEst->bg_cnt >= 0 )
731 : {
732 373750 : hNoiseEst->bg_cnt += 1;
733 : }
734 :
735 : /*-----------------------------------------------------------------*
736 : * Linear predition efficiency 0 to 2 order
737 : *-----------------------------------------------------------------*/
738 :
739 1217770 : epsP_0_2 = max( 0, min( 8, epsP[0] / epsP[2] ) );
740 1217770 : hNoiseEst->epsP_0_2_lp = 0.15f * epsP_0_2 + ( 1.0f - 0.15f ) * hNoiseEst->epsP_0_2_lp;
741 1217770 : epsP_0_2_ad = (float) fabs( epsP_0_2 - hNoiseEst->epsP_0_2_lp );
742 1217770 : if ( epsP_0_2_ad < hNoiseEst->epsP_0_2_ad_lp )
743 : {
744 862368 : hNoiseEst->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + ( 1.0f - 0.1f ) * hNoiseEst->epsP_0_2_ad_lp;
745 : }
746 : else
747 : {
748 355402 : hNoiseEst->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + ( 1.0f - 0.2f ) * hNoiseEst->epsP_0_2_ad_lp;
749 : }
750 1217770 : epsP_0_2_ad_lp_max = max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp );
751 :
752 : /*-----------------------------------------------------------------*
753 : * Linear predition efficiency 2 to 16 order
754 : *-----------------------------------------------------------------*/
755 :
756 1217770 : epsP_2_16 = max( 0, min( 8, epsP[2] / epsP[16] ) );
757 1217770 : if ( epsP_2_16 > hNoiseEst->epsP_2_16_lp )
758 : {
759 244023 : hNoiseEst->epsP_2_16_lp = 0.2f * epsP_2_16 + ( 1.0f - 0.2f ) * hNoiseEst->epsP_2_16_lp;
760 : }
761 : else
762 : {
763 973747 : hNoiseEst->epsP_2_16_lp = 0.03f * epsP_2_16 + ( 1.0f - 0.03f ) * hNoiseEst->epsP_2_16_lp;
764 : }
765 1217770 : hNoiseEst->epsP_2_16_lp2 = 0.02f * epsP_2_16 + ( 1.0f - 0.02f ) * hNoiseEst->epsP_2_16_lp2;
766 :
767 1217770 : epsP_2_16_dlp = hNoiseEst->epsP_2_16_lp - hNoiseEst->epsP_2_16_lp2;
768 :
769 1217770 : if ( epsP_2_16_dlp < hNoiseEst->epsP_2_16_dlp_lp2 )
770 : {
771 726079 : hNoiseEst->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + ( 1.0f - 0.02f ) * hNoiseEst->epsP_2_16_dlp_lp2;
772 : }
773 : else
774 : {
775 491691 : hNoiseEst->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + ( 1.0f - 0.05f ) * hNoiseEst->epsP_2_16_dlp_lp2;
776 : }
777 :
778 1217770 : epsP_2_16_dlp_max = max( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2 );
779 :
780 : /*-----------------------------------------------------------------*
781 : * long term extensions of frame features
782 : *-----------------------------------------------------------------*/
783 :
784 1217770 : hNoiseEst->lt_tn_track = 0.03f * ( Etot - hNoiseEst->totalNoise < 10 ) + 0.97f * hNoiseEst->lt_tn_track;
785 1217770 : hNoiseEst->lt_tn_dist = 0.03f * ( Etot - hNoiseEst->totalNoise ) + 0.97f * hNoiseEst->lt_tn_dist;
786 1217770 : hNoiseEst->lt_Ellp_dist = 0.03f * ( Etot - hNoiseEst->Etot_l_lp ) + 0.97f * hNoiseEst->lt_Ellp_dist;
787 :
788 1217770 : if ( hNoiseEst->harm_cor_cnt == 0 )
789 : {
790 634874 : hNoiseEst->lt_haco_ev = 0.03f + 0.97f * hNoiseEst->lt_haco_ev;
791 : }
792 : else
793 : {
794 582896 : hNoiseEst->lt_haco_ev = 0.99f * hNoiseEst->lt_haco_ev;
795 : }
796 :
797 1217770 : if ( hNoiseEst->lt_tn_track < 0.05f )
798 : {
799 695269 : hNoiseEst->low_tn_track_cnt++;
800 : }
801 : else
802 : {
803 522501 : hNoiseEst->low_tn_track_cnt = 0;
804 : }
805 :
806 :
807 : /* update of the long-term non-stationarity measure (between 0 and 1) */
808 1217770 : if ( ( non_sta > th_sta ) || ( *loc_harm > 0 ) )
809 : {
810 897014 : hNoiseEst->act_pred = M_GAMMA * hNoiseEst->act_pred + ( 1 - M_GAMMA ) * 1;
811 : }
812 : else
813 : {
814 320756 : hNoiseEst->act_pred = M_GAMMA * hNoiseEst->act_pred + ( 1 - M_GAMMA ) * 0;
815 : }
816 :
817 : /*-----------------------------------------------------------------*
818 : * Increment/decrement counter for enabling background noise update
819 : *-----------------------------------------------------------------*/
820 :
821 1217770 : if ( ( ( *st_harm_cor_cnt < 3 * HC_CNT_SLOW ) && ( ( non_sta > th_sta ) ||
822 295849 : ( tmp_pc < TH_PC ) ||
823 289382 : ( noise_char > 0 ) ) ) ||
824 206681 : ( ( ini_frame > 150 ) && ( Etot - Etot_l_lp ) > 10 ) ||
825 244363 : ( 0.5f * ( st->voicing[0] + st->voicing[1] ) > cor_max ) ||
826 241512 : ( epsP[2] / epsP[16] > th_eps ) ||
827 226751 : ( *loc_harm > 0 ) ||
828 216479 : ( ( hNoiseEst->act_pred > 0.8f ) && ( non_sta2 > th_sta ) ) )
829 :
830 : {
831 : /* active signal present - increment counter */
832 1002867 : hNoiseEst->aEn = hNoiseEst->aEn + 2;
833 : }
834 : else
835 : {
836 : /* background noise present - decrement counter */
837 214903 : hNoiseEst->aEn = hNoiseEst->aEn - 1;
838 : }
839 :
840 1217770 : if ( hNoiseEst->aEn > 6 )
841 : {
842 982077 : hNoiseEst->aEn = 6;
843 : }
844 235693 : else if ( hNoiseEst->aEn < 0 )
845 : {
846 155013 : hNoiseEst->aEn = 0;
847 : }
848 :
849 1217770 : if ( hNoiseEst->aEn <= 1 )
850 : {
851 174156 : hNoiseEst->aEn_inac_cnt++;
852 174156 : hNoiseEst->aEn_inac_cnt = min( hNoiseEst->aEn_inac_cnt, 128 );
853 : }
854 :
855 : /*-----------------------------------------------------------------*
856 : * Stereo classifier - save raw aEn
857 : *-----------------------------------------------------------------*/
858 :
859 1217770 : if ( hStereoClassif != NULL )
860 : {
861 782031 : if ( ( non_sta > th_sta ) ||
862 169242 : ( tmp_pc < TH_PC ) ||
863 169242 : ( 0.5f * ( st->voicing[0] + st->voicing[1] ) > cor_max ) ||
864 167127 : ( epsP[2] / epsP[16] > th_eps ) ||
865 149518 : ( ( hNoiseEst->act_pred > 0.8f ) && ( non_sta2 > th_sta ) ) )
866 : {
867 : /* active signal present - increment counter */
868 637405 : hStereoClassif->aEn_raw[st->idchan] = hStereoClassif->aEn_raw[st->idchan] + 2;
869 : }
870 : else
871 : {
872 : /* background noise present - decrement counter */
873 144626 : hStereoClassif->aEn_raw[st->idchan] = hStereoClassif->aEn_raw[st->idchan] - 1;
874 : }
875 :
876 782031 : if ( hStereoClassif->aEn_raw[st->idchan] > 6 )
877 : {
878 605429 : hStereoClassif->aEn_raw[st->idchan] = 6;
879 : }
880 176602 : else if ( hStereoClassif->aEn_raw[st->idchan] < 0 )
881 : {
882 108110 : hStereoClassif->aEn_raw[st->idchan] = 0;
883 : }
884 : }
885 :
886 : /*--------------------------------------------------------------*
887 : * Background noise update
888 : * (bckr[] has been already updated downwards in nois_est_down())
889 : *--------------------------------------------------------------*/
890 :
891 : /* Additional detectors */
892 1217770 : comb_ahc_epsP = max( max( hNoiseEst->act_pred, hNoiseEst->lt_haco_ev ), epsP_2_16_dlp );
893 1217770 : comb_hcm_epsP = max( max( hNoiseEst->lt_haco_ev, epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max );
894 :
895 1217770 : haco_ev_max = max( *st_harm_cor_cnt == 0, hNoiseEst->lt_haco_ev );
896 1217770 : Etot_l_lp_thr = hNoiseEst->Etot_l_lp + ( 1.5f + 1.5f * ( hNoiseEst->Etot_lp < 50.0f ) ) * hNoiseEst->Etot_v_h2;
897 :
898 1217770 : enr_bgd = Etot < Etot_l_lp_thr;
899 1217770 : cns_bgd = ( epsP_0_2 > 7.95f ) && ( non_sta < 1e3f );
900 1217770 : lp_bgd = epsP_2_16_dlp_max < 0.10f;
901 1217770 : ns_mask = non_sta < 1e5f;
902 1217770 : lt_haco_mask = hNoiseEst->lt_haco_ev < 0.5f;
903 1217770 : bg_haco_mask = haco_ev_max < 0.4f;
904 :
905 1217770 : SD_1 = ( ( epsP_0_2_ad > 0.5f ) && ( epsP_0_2 > 7.95f ) );
906 :
907 1217770 : bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1 == 0 );
908 :
909 1217770 : PD_1 = ( epsP_2_16_dlp_max < 0.10f );
910 1217770 : PD_2 = ( epsP_0_2_ad_lp_max < 0.10f );
911 1217770 : PD_3 = ( comb_ahc_epsP < 0.85f );
912 1217770 : PD_4 = comb_ahc_epsP < 0.15f;
913 1217770 : PD_5 = comb_hcm_epsP < 0.30f;
914 :
915 1217770 : BG_1 = ( ( SD_1 == 0 ) || ( Etot < Etot_l_lp_thr ) ) && bg_haco_mask && ( hNoiseEst->act_pred < 0.85f ) && ( hNoiseEst->Etot_lp < 50.0f );
916 :
917 1217770 : PAU = ( hNoiseEst->aEn == 0 ) || ( ( Etot < 55.0f ) && ( SD_1 == 0 ) && ( ( PD_3 && ( PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) );
918 :
919 1217770 : NEW_POS_BG = ( PAU | BG_1 ) & bg_bgd3;
920 :
921 : /* Original silence detector works in most cases */
922 1217770 : aE_bgd = hNoiseEst->aEn == 0;
923 :
924 : /* When the signal dynamics is high and the energy is close to the background estimate */
925 1217770 : sd1_bgd = ( hNoiseEst->sign_dyn_lp > 15 ) && ( Etot - hNoiseEst->Etot_l_lp ) < 2 * hNoiseEst->Etot_v_h2 && hNoiseEst->harm_cor_cnt > 20;
926 :
927 : /* init conditions steadily dropping act_pred and/or lt_haco_ev */
928 368694 : tn_ini = ini_frame < 150 && hNoiseEst->harm_cor_cnt > 5 &&
929 1632102 : ( Etot - hNoiseEst->Etot_lp ) < 7 &&
930 45638 : ( ( hNoiseEst->act_pred < 0.59f && hNoiseEst->lt_haco_ev < 0.23f ) ||
931 28202 : hNoiseEst->act_pred < 0.38f ||
932 28201 : ( ( st->element_mode == EVS_MONO && hNoiseEst->lt_haco_ev < 0.15f ) || ( st->element_mode > EVS_MONO && hNoiseEst->lt_haco_ev < 0.08f ) ) ||
933 14773 : non_staB < 50.0f ||
934 13711 : aE_bgd || ( Etot < 42.0f && hNoiseEst->harm_cor_cnt > 10 && hNoiseEst->lt_haco_ev < 0.35f && hNoiseEst->act_pred < 0.8f ) );
935 :
936 : /* Energy close to the background estimate serves as a mask for other background detectors */
937 1217770 : bg_bgd2 = Etot < Etot_l_lp_thr || tn_ini;
938 :
939 1217770 : updt_step = 0.0f;
940 1217770 : if ( ( bg_bgd2 && ( aE_bgd || sd1_bgd || hNoiseEst->lt_tn_track > 0.90f || NEW_POS_BG ) ) || tn_ini )
941 : {
942 189731 : if ( ( ( hNoiseEst->act_pred < 0.85f ) &&
943 142456 : aE_bgd &&
944 142456 : ( hNoiseEst->lt_Ellp_dist < 10 || sd1_bgd ) && hNoiseEst->lt_tn_dist < 40 &&
945 140167 : ( ( Etot - hNoiseEst->totalNoise ) < 10.0f ) ) ||
946 51377 : ( hNoiseEst->first_noise_updt == 0 && hNoiseEst->harm_cor_cnt > 80 && aE_bgd && hNoiseEst->lt_aEn_zero > 0.5f ) ||
947 10992 : ( tn_ini && ( aE_bgd || non_staB < 10.0 || hNoiseEst->harm_cor_cnt > 80 ) ) )
948 : {
949 143090 : updt_step = 1.0f;
950 143090 : hNoiseEst->first_noise_updt = 1;
951 3004890 : for ( i = 0; i < NB_BANDS; i++ )
952 : {
953 2861800 : hNoiseEst->bckr[i] = tmpN[i];
954 : }
955 : }
956 46641 : else if ( ( ( hNoiseEst->act_pred < 0.80f ) && ( aE_bgd || PAU ) && hNoiseEst->lt_haco_ev < 0.10f ) || ( ( hNoiseEst->act_pred < 0.70f ) && ( aE_bgd || non_staB < 17.0f ) && PAU && hNoiseEst->lt_haco_ev < 0.15f ) || ( hNoiseEst->harm_cor_cnt > 80 && hNoiseEst->totalNoise > 5.0f && Etot < max( 1.0f, Etot_l_lp + 1.5f * hNoiseEst->Etot_v_h2 ) ) || ( hNoiseEst->harm_cor_cnt > 50 && hNoiseEst->first_noise_updt > 30 && aE_bgd && hNoiseEst->lt_aEn_zero > 0.5f ) || tn_ini )
957 : {
958 11158 : updt_step = 0.1f;
959 11158 : if ( !aE_bgd &&
960 10542 : hNoiseEst->harm_cor_cnt < 50 &&
961 7539 : ( hNoiseEst->act_pred > 0.6f ||
962 2472 : ( !tn_ini && Etot_l_lp - hNoiseEst->totalNoise < 10.0f && non_staB > 8.0f ) ) )
963 : {
964 4573 : updt_step = 0.01f;
965 : }
966 :
967 11158 : hNoiseEst->first_noise_updt = 1;
968 234318 : for ( i = 0; i < NB_BANDS; i++ )
969 : {
970 223160 : hNoiseEst->bckr[i] = hNoiseEst->bckr[i] + updt_step * ( tmpN[i] - hNoiseEst->bckr[i] );
971 : }
972 : }
973 35483 : else if ( aE_bgd || hNoiseEst->harm_cor_cnt > 100 )
974 : {
975 9314 : hNoiseEst->first_noise_updt += 1;
976 : }
977 : }
978 : else
979 : {
980 : /* If in music decrease bckr[] to drop further */
981 1028039 : if ( hNoiseEst->low_tn_track_cnt > 300 && hNoiseEst->lt_haco_ev > 0.9f && hNoiseEst->totalNoise > 0.0f )
982 : {
983 3592 : updt_step = -0.02f;
984 75432 : for ( i = 0; i < NB_BANDS; i++ )
985 : {
986 71840 : if ( hNoiseEst->bckr[i] > 2 * E_MIN )
987 : {
988 59960 : hNoiseEst->bckr[i] = 0.98f * hNoiseEst->bckr[i];
989 : }
990 : }
991 : }
992 : }
993 1217770 : hNoiseEst->lt_aEn_zero = 0.2f * ( hNoiseEst->aEn == 0 ) + ( 1 - 0.2f ) * hNoiseEst->lt_aEn_zero;
994 :
995 1217770 : if ( st->element_mode > EVS_MONO )
996 : {
997 1214670 : if ( hNoiseEst->first_noise_updt > 0 && hNoiseEst->first_noise_updt_cnt < 100 )
998 : {
999 99213 : hNoiseEst->first_noise_updt_cnt++;
1000 : }
1001 : }
1002 :
1003 1217770 : return;
1004 : }
|