Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 : #include <stdint.h>
5 : #include "options.h" /* Compilation switches */
6 : #include "cnst.h" /* Common constants */
7 : //#include "prot_fx.h" /* Function prototypes */
8 : #include "rom_com.h" /* Function prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 : #include "prot_fx_enc.h" /* Function prototypes */
11 :
12 : /*-------------------------------------------------------------------*
13 : * Local constants
14 : *-------------------------------------------------------------------*/
15 :
16 : #define L_ENR ( NB_SSF + 2 )
17 :
18 :
19 : /*-------------------------------------------------------------------*
20 : * find_ener_decrease_fx()
21 : *
22 : * Find maximum energy ration between short subblocks in case
23 : * energy is trailing off after a spike
24 : *-------------------------------------------------------------------*/
25 :
26 30638 : static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10*/
27 : const Word16 ind_deltaMax, /* i : index of the beginning of maximum energy search Q0*/
28 : const Word32 *pt_enr_ssf /* i : Pointer to the energy buffer Qx*/
29 : )
30 : {
31 : Word16 i, j, end, flag;
32 : Word16 wtmp0, wtmp1;
33 : Word32 maxEnr, minEnr;
34 : Word16 dE2, exp0, exp1;
35 :
36 30638 : dE2 = 0;
37 30638 : move16();
38 :
39 30638 : j = ind_deltaMax + 2;
40 30638 : move16();
41 30638 : end = j + L_ENR;
42 30638 : move16();
43 30638 : maxEnr = L_add( pt_enr_ssf[j], 0 );
44 30638 : j = add( j, 1 );
45 30638 : flag = 0;
46 30638 : move16();
47 306380 : FOR( i = j; i < end; i++ )
48 : {
49 275742 : test();
50 275742 : IF( ( GT_32( pt_enr_ssf[i], maxEnr ) ) && ( flag == 0 ) )
51 : {
52 14086 : maxEnr = L_add( pt_enr_ssf[i], 0 ); /*Qx*/
53 14086 : j = add( j, 1 );
54 : }
55 : ELSE
56 : {
57 261656 : flag = 1;
58 261656 : move16();
59 : }
60 : }
61 :
62 30638 : minEnr = L_add( maxEnr, 0 );
63 292294 : FOR( i = j; i < end; i++ )
64 : {
65 261656 : minEnr = L_min( minEnr, pt_enr_ssf[i] ); /* Qx */
66 : }
67 :
68 :
69 30638 : minEnr = L_add_sat( minEnr, 100000 );
70 30638 : exp0 = norm_l( minEnr );
71 30638 : wtmp0 = extract_h( L_shl( minEnr, exp0 ) );
72 30638 : exp1 = sub( norm_l( maxEnr ), 1 );
73 30638 : wtmp1 = extract_h( L_shl( maxEnr, exp1 ) );
74 30638 : wtmp1 = div_s( wtmp1, wtmp0 );
75 30638 : dE2 = shr_r_sat( wtmp1, add( sub( exp1, exp0 ), 15 - 10 ) ); /*Q10*/
76 :
77 30638 : return dE2;
78 : }
79 :
80 : /*-------------------------------------------------------------------*
81 : * find_uv_fx()
82 : *
83 : * Decision about coder type
84 : *-------------------------------------------------------------------*/
85 :
86 5150 : Word16 find_uv_fx( /* o : coding type */
87 : Encoder_State *st_fx, /* i/o: encoder state structure */
88 : const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/
89 : const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/
90 : const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/
91 : const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/
92 : const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/
93 : const Word16 relE, /* i : relative frame energy Q8*/
94 : const Word16 Etot, /* i : total energy Q8*/
95 : const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/
96 : const Word16 Q_new,
97 : Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation Q0*/
98 : const Word16 shift,
99 : const Word16 last_core_orig /* i : original last core Q0*/
100 : )
101 : {
102 : Word16 coder_type, i;
103 : Word32 mean_ee, dE1, fac_32;
104 : const Word16 *pt_speech;
105 : Word32 L_tmp, enr_ssf[2 * NB_SSF + 2 * NB_SSF + 2], E_min_th;
106 : Word16 dE2;
107 : Word16 ind_deltaMax, tmp_offset_flag;
108 : Word32 Ltmp0, *pt_enr_ssf, *pt_enr_ssf1, dE2_th;
109 : Word16 exp0, exp1, Q_in;
110 : Word16 wtmp0, wtmp1;
111 : Word16 fac, mean_voi3, dE3;
112 : Word16 relE_thres;
113 : Word16 mean_voi3_offset;
114 : Word16 voicing_m, dpit1, dpit2, dpit3;
115 : Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE;
116 5150 : NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst;
117 5150 : SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
118 : Word16 Last_Resort;
119 : Word16 vadnoise;
120 :
121 5150 : IF( hSC_VBR != NULL )
122 : {
123 5150 : Last_Resort = hSC_VBR->Last_Resort; /* Q0 */
124 5150 : vadnoise = hSC_VBR->vadnoise_fx;
125 5150 : move16();
126 5150 : move16();
127 : }
128 : ELSE
129 : {
130 0 : Last_Resort = 0;
131 0 : vadnoise = 0;
132 0 : move16();
133 0 : move16();
134 : }
135 :
136 5150 : Q_in = sub( Q_new, 1 );
137 :
138 : /*-----------------------------------------------------------------*
139 : * Detect sudden energy increases to catch voice and music
140 : * temporal events (dE1)
141 : *
142 : * - Find maximum energy per short subblocks.
143 : * Two subblock sets are used shifted by half the subblock length
144 : * - Find maximum energy ratio between adjacent subblocks
145 : *-----------------------------------------------------------------*/
146 :
147 : /* Find maximum energy per short subblocks */
148 5150 : pt_speech = speech - SSF; /* Q_new */
149 5150 : pt_enr_ssf = enr_ssf + 2 * NB_SSF;
150 97850 : FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ )
151 : {
152 92700 : emaximum_fx( Q_in, pt_speech, SSF, pt_enr_ssf );
153 92700 : pt_speech += ( SSF / 2 );
154 92700 : pt_enr_ssf++;
155 : }
156 :
157 5150 : dE1 = 0;
158 5150 : move16();
159 5150 : ind_deltaMax = 0;
160 5150 : move16();
161 5150 : pt_enr_ssf = enr_ssf + 2 * NB_SSF;
162 5150 : pt_enr_ssf1 = pt_enr_ssf + 2;
163 :
164 : /* Test on energy increase between adjacent sub-subframes */
165 5150 : exp1 = 0;
166 5150 : move16();
167 87550 : FOR( i = 0; i < 2 * NB_SSF; i++ )
168 : {
169 : /*fac = *pt_enr_ssf1 / (*pt_enr_ssf + 1);*/
170 82400 : Ltmp0 = L_max( *pt_enr_ssf, 1 );
171 82400 : exp0 = norm_l( Ltmp0 );
172 82400 : wtmp0 = extract_h( L_shl( Ltmp0, exp0 ) );
173 82400 : exp1 = sub( norm_l( *pt_enr_ssf1 ), 1 );
174 82400 : wtmp1 = extract_h( L_shl( *pt_enr_ssf1, exp1 ) );
175 82400 : fac = div_s( wtmp1, wtmp0 );
176 82400 : fac_32 = L_shr_sat( L_deposit_l( fac ), add( sub( exp1, exp0 ), 15 - 13 ) ); /* fac32 in Q13*/
177 :
178 82400 : if ( GT_32( fac_32, dE1 ) )
179 : {
180 17373 : ind_deltaMax = i;
181 17373 : move16();
182 : }
183 :
184 82400 : dE1 = L_max( dE1, fac_32 ); /* Q13 */
185 :
186 82400 : pt_enr_ssf++;
187 82400 : pt_enr_ssf1++;
188 : }
189 :
190 : /*-----------------------------------------------------------------*
191 : * Average spectral tilt
192 : * Average voicing (normalized correlation)
193 : *-----------------------------------------------------------------*/
194 :
195 : /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */
196 5150 : mean_ee = L_add_sat( L_add_sat( st_fx->ee_old_fx, ee[0] ), ee[1] ); /* Q6 */
197 5150 : mean_ee = Mult_32_16( mean_ee, 10923 /* 1/3 in Q15 */ ); /*Q6*/
198 :
199 : /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/
200 5150 : Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ ); /* Q31 */
201 5150 : Ltmp0 = L_mac( Ltmp0, st_fx->voicing_fx[1], 10923 /* 1/3 in Q15 */ ); /* Q31 */
202 5150 : mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 /* 1/3 in Q15 */ ); /*Q15*/
203 : /*-----------------------------------------------------------------*
204 : * Total frame energy difference (dE3)
205 : *-----------------------------------------------------------------*/
206 :
207 5150 : dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/
208 :
209 : /*-----------------------------------------------------------------*
210 : * Energy decrease after spike (dE2)
211 : *-----------------------------------------------------------------*/
212 :
213 : /* set different thresholds and conditions for NB and WB input */
214 5150 : dE2_th = 30 << 10;
215 5150 : move32();
216 5150 : nb_cond = 1;
217 5150 : move16(); /* no additional condition for WB input */
218 5150 : IF( EQ_16( st_fx->input_bwidth, NB ) )
219 : {
220 0 : dE2_th = 21 << 10;
221 0 : move32();
222 0 : if ( GE_16( add_sat( mean_voi3, corr_shift ), 22282 /* 0.68 in Q15 */ ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/
223 : {
224 0 : nb_cond = 0;
225 0 : move16();
226 : }
227 : }
228 :
229 : /* calcualte maximum energy decrease */
230 5150 : dE2 = 0;
231 5150 : move16(); /* Test on energy decrease after an energy spike */
232 5150 : pt_enr_ssf = enr_ssf + 2 * NB_SSF;
233 :
234 5150 : test();
235 5150 : IF( GT_32( dE1, 30 << 13 ) && nb_cond ) /*>30 Q13*/
236 : {
237 132 : IF( LT_16( sub( shl( NB_SSF, 1 ), ind_deltaMax ), L_ENR ) )
238 : {
239 95 : st_fx->old_ind_deltaMax = ind_deltaMax; /* Q0 */
240 95 : move16();
241 95 : Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2 * NB_SSF ); /* Qx */
242 : }
243 : ELSE
244 : {
245 37 : st_fx->old_ind_deltaMax = -1;
246 37 : move16();
247 37 : dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/
248 :
249 37 : if ( GT_32( dE2, dE2_th ) )
250 : {
251 3 : st_fx->spike_hyst = 0;
252 3 : move16();
253 : }
254 : }
255 : }
256 : ELSE
257 : {
258 5018 : IF( st_fx->old_ind_deltaMax >= 0 )
259 : {
260 95 : Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2 * NB_SSF ); /* Qx */
261 95 : dE2 = find_ener_decrease_fx( st_fx->old_ind_deltaMax, enr_ssf ); /* Q10 */
262 :
263 95 : if ( GT_32( dE2, dE2_th ) )
264 : {
265 5 : st_fx->spike_hyst = 1;
266 5 : move16();
267 : }
268 : }
269 :
270 5018 : st_fx->old_ind_deltaMax = -1;
271 5018 : move16();
272 : }
273 :
274 : /*-----------------------------------------------------------------*
275 : * Detection of voiced offsets (tmp_offset_flag)
276 : *-----------------------------------------------------------------*/
277 :
278 5150 : tmp_offset_flag = 1;
279 5150 : move16();
280 :
281 5150 : IF( NE_16( st_fx->input_bwidth, NB ) )
282 : {
283 5150 : ee0_th = 154; /*2.4 in Q6 */
284 5150 : move16();
285 5150 : voi_th = 24248; /*0.74f Q15 */
286 5150 : move16();
287 : }
288 : ELSE
289 : {
290 0 : ee0_th = 627; /*9.8f Q6 */
291 0 : move16();
292 0 : voi_th = 24904; /*0.76f Q15*/
293 0 : move16();
294 : }
295 :
296 5150 : test();
297 5150 : test();
298 5150 : test();
299 10078 : if ( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */
300 6638 : ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], L_shl( E_MIN_FX, Q_new ) ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */
301 812 : ( LT_16( add_sat( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) ) /* normalized correlation is low */
302 : {
303 523 : tmp_offset_flag = 0;
304 523 : move16();
305 : }
306 :
307 : /*-----------------------------------------------------------------*
308 : * Decision about UC
309 : *-----------------------------------------------------------------*/
310 :
311 : /* SC-VBR - set additional parameters and thresholds for SC-VBR */
312 5150 : mean_voi3_offset = 0;
313 5150 : move16();
314 5150 : flag_low_relE = 0;
315 5150 : move16();
316 5150 : ee1_th = 608; /*9.5 Q6*/
317 5150 : move16();
318 5150 : IF( st_fx->Opt_SC_VBR || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) /* Allow the low energy flag for the secondary channel */
319 : {
320 0 : ee1_th = 544; /*8.5f Q6*/
321 0 : move16();
322 :
323 : /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */
324 0 : IF( NE_16( st_fx->input_bwidth, NB ) )
325 : {
326 : /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */
327 0 : L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, st_fx->lp_noise_fx ); // Q24
328 0 : if ( Last_Resort == 0 )
329 : {
330 : /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/
331 0 : L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, st_fx->lp_noise_fx ); // Q24
332 : }
333 0 : relE_thres = round_fx( L_tmp );
334 : }
335 : ELSE
336 : {
337 :
338 : /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/
339 0 : L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, st_fx->lp_noise_fx ); // Q24
340 0 : relE_thres = round_fx( L_tmp );
341 : }
342 0 : relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */
343 :
344 : /* SC-VBR = set flag on low relative energy */
345 0 : if ( LT_16( relE, relE_thres ) )
346 : {
347 0 : flag_low_relE = 1;
348 0 : move16();
349 : }
350 :
351 : /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */
352 0 : test();
353 0 : if ( EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) ) /* vadnoise in Q8, constant Q0<<8 */
354 : {
355 0 : mean_voi3_offset = 1638; /*0.05f Q15*/
356 0 : move16();
357 : }
358 : }
359 :
360 : /* make decision whether frame is unvoiced */
361 5150 : E_min_th = L_shl( E_MIN_FX, Q_new );
362 5150 : coder_type = GENERIC;
363 5150 : move16();
364 5150 : IF( EQ_16( st_fx->input_bwidth, NB ) )
365 : {
366 0 : test();
367 0 : test();
368 0 : test();
369 0 : test();
370 0 : test();
371 0 : test();
372 0 : test();
373 0 : test();
374 0 : test();
375 0 : test();
376 0 : test();
377 0 : if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */
378 0 : ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */
379 0 : ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */
380 0 : ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
381 0 : ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */
382 : /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */
383 0 : ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */
384 0 : ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */
385 0 : ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
386 : flag_low_relE ) /* low relative frame energy (only for SC-VBR) */
387 : {
388 0 : coder_type = UNVOICED;
389 0 : move16();
390 : }
391 : }
392 : ELSE
393 : {
394 5150 : test();
395 5150 : test();
396 5150 : test();
397 5150 : test();
398 5150 : test();
399 5150 : test();
400 5150 : test();
401 5150 : test();
402 5150 : test();
403 5150 : test();
404 5150 : test();
405 5150 : test();
406 6694 : if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */
407 2926 : ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.8 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */
408 2251 : ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */
409 779 : ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
410 257 : ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */
411 : /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */
412 497 : ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */
413 240 : ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */
414 224 : ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
415 4928 : || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */
416 : {
417 222 : coder_type = UNVOICED;
418 222 : move16();
419 : }
420 : }
421 :
422 : /*-----------------------------------------------------------------*
423 : * Decision about VC
424 : *-----------------------------------------------------------------*/
425 5150 : if ( st_fx->Opt_SC_VBR )
426 : {
427 0 : hSC_VBR->set_ppp_generic = 0;
428 : }
429 5150 : move16();
430 :
431 5150 : test();
432 5150 : test();
433 5150 : IF( EQ_16( st_fx->localVAD, 1 ) && EQ_16( coder_type, GENERIC ) && NE_16( last_core_orig, AMR_WB_CORE ) )
434 : {
435 4764 : dpit1 = abs_s( sub( T_op_fr[1], T_op_fr[0] ) ); // Q6
436 4764 : dpit2 = abs_s( sub( T_op_fr[2], T_op_fr[1] ) ); // Q6
437 4764 : dpit3 = abs_s( sub( T_op_fr[3], T_op_fr[2] ) ); // Q6
438 :
439 4764 : test();
440 4764 : test();
441 4764 : test();
442 4764 : test();
443 4764 : test();
444 4764 : test();
445 4764 : test();
446 4764 : test();
447 4764 : test();
448 4764 : IF( ( GT_16( voicing_fr[0], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 1st sf. */
449 : ( GT_16( voicing_fr[1], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
450 : ( GT_16( voicing_fr[2], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 3st sf. */
451 : ( GT_16( voicing_fr[3], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 4st sf. */
452 : ( GT_32( mean_ee, 256 /* 4.0f in Q6 */ ) ) && /* energy concentrated in low frequencies */
453 : ( LT_16( dpit1, 3 << 6 ) ) &&
454 : ( LT_16( dpit2, 3 << 6 ) ) &&
455 : ( LT_16( dpit3, 3 << 6 ) ) )
456 : {
457 2173 : coder_type = VOICED;
458 2173 : move16();
459 : }
460 2591 : ELSE IF( st_fx->Opt_SC_VBR && EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) )
461 : {
462 0 : test();
463 0 : test();
464 0 : test();
465 0 : test();
466 0 : test();
467 0 : test();
468 0 : test();
469 0 : IF( GT_16( voicing_fr[0], 8192 /* 0.25 in Q15 */ ) && /* normalized correlation high in 1st sf. */
470 : ( GT_16( voicing_fr[1], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
471 : ( GT_16( voicing_fr[2], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 3st sf. */
472 : ( GT_16( voicing_fr[3], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 4st sf. */
473 : ( GT_32( mean_ee, 64 ) ) && /* energy concentrated in low frequencies */
474 : ( LT_16( dpit1, 5 << 6 ) ) &&
475 : ( LT_16( dpit2, 5 << 6 ) ) &&
476 : ( LT_16( dpit3, 5 << 6 ) ) )
477 : {
478 0 : hSC_VBR->set_ppp_generic = 1;
479 0 : move16();
480 0 : coder_type = VOICED;
481 0 : move16();
482 : }
483 : }
484 :
485 : /* set VOICED mode for frames with very stable pitch and high correlation
486 : and avoid to switch to AUDIO/MUSIC later */
487 4764 : voicing_m = mac_r( L_mac( L_mac( L_mult( voicing_fr[3], 8192 /* 0.25 in Q15 */ ), voicing_fr[2], 8192 /* 0.25 in Q15 */ ), voicing_fr[1], 8192 /* 0.25 in Q15 */ ), voicing_fr[0], 8192 /* 0.25 in Q15 */ );
488 4764 : test();
489 4764 : test();
490 4764 : test();
491 4764 : test();
492 4764 : test();
493 4764 : IF( *flag_spitch || ( LE_16( dpit1, 3 << 6 ) && LE_16( dpit2, 3 << 6 ) && LE_16( dpit3, 3 << 6 ) &&
494 : GT_16( voicing_m, 31130 /* 0.95f in Q15 */ ) && GT_16( st_fx->voicing_sm_fx, 31785 /* 0.97f in Q15 */ ) ) )
495 : {
496 76 : coder_type = VOICED;
497 76 : move16();
498 76 : *flag_spitch = 1;
499 76 : move16(); /*to avoid switch to AUDIO/MUSIC later*/
500 : }
501 : }
502 :
503 : /*-----------------------------------------------------------------*
504 : * Channel-aware mode - set RF mode and total bitrate
505 : *-----------------------------------------------------------------*/
506 :
507 5150 : st_fx->rf_mode = st_fx->Opt_RF_ON; /* Q0 */
508 5150 : move16();
509 :
510 5150 : IF( EQ_16( coder_type, GENERIC ) )
511 : {
512 2755 : test();
513 2755 : test();
514 2755 : test();
515 2755 : test();
516 2755 : IF( ( LT_16( voicing_fr[0], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
517 : ( LT_16( voicing_fr[1], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
518 : ( LT_16( voicing_fr[2], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 3rd sf. */
519 : ( LT_16( voicing_fr[3], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 4th sf. */
520 : ( GT_16( vadnoise, 25 << 8 ) ) ) /* when speech is clean */
521 :
522 : {
523 0 : st_fx->rf_mode = 0;
524 0 : move16();
525 : /* Current frame cannot be compressed to pack the partial redundancy;*/
526 :
527 0 : if ( st_fx->rf_mode != st_fx->Opt_RF_ON )
528 : {
529 0 : core_coder_mode_switch_fx( st_fx, st_fx->last_total_brate, 0, shift );
530 : }
531 : }
532 : }
533 :
534 : /*-----------------------------------------------------------------*
535 : * Updates
536 : *-----------------------------------------------------------------*/
537 :
538 : /* update spike hysteresis parameters */
539 5150 : test();
540 5150 : if ( st_fx->spike_hyst >= 0 && LT_16( st_fx->spike_hyst, 2 ) )
541 : {
542 11 : st_fx->spike_hyst = add( st_fx->spike_hyst, 1 ); /* Q0 */
543 : }
544 :
545 : /* reset spike hysteresis */
546 5150 : test();
547 5150 : test();
548 5150 : test();
549 5222 : if ( ( GT_16( st_fx->spike_hyst, 1 ) ) &&
550 139 : ( GT_16( dE3, 5 << 8 ) || /* energy increases */
551 95 : ( GT_16( relE, -3328 ) && ( GT_16( add_sat( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */
552 : {
553 8 : st_fx->spike_hyst = -1;
554 8 : move16();
555 : }
556 :
557 : /* update tilt parameters */
558 5150 : st_fx->ee_old_fx = ee[1];
559 5150 : move32(); /*Q6*/
560 5150 : st_fx->old_dE1_fx = dE1;
561 5150 : move32(); /*Q13*/
562 :
563 : /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */
564 5150 : st_fx->coder_type_raw = coder_type;
565 5150 : move16();
566 :
567 5150 : return coder_type;
568 : }
569 :
570 : /*-------------------------------------------------------------------*
571 : * find_uv()
572 : *
573 : * Decision about coder type
574 : *-------------------------------------------------------------------*/
575 1304696 : Word16 find_uv_ivas_fx( /* o : coding type */
576 : Encoder_State *st_fx, /* i/o: encoder state structure */
577 : const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/
578 : const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/
579 : const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/
580 : const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/
581 : Word32 *dE1X, /* o : sudden energy increase for S/M classifier Q13*/
582 : const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/
583 : const Word16 relE, /* i : relative frame energy Q8*/
584 : const Word16 Etot, /* i : total energy Q8*/
585 : const Word32 hp_E[], /* i : energy in HF q_hp_E*/
586 : Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation Q0*/
587 : const Word16 last_core_orig, /* i : original last core Q0*/
588 : STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */
589 : const Word16 Q_new,
590 : const Word16 q_hp_E )
591 : {
592 : Word16 coder_type, i;
593 : Word32 mean_ee, dE1, fac_32;
594 : const Word16 *pt_speech;
595 : Word32 L_tmp, enr_ssf[2 * NB_SSF + 2 * NB_SSF + 2], E_min_th;
596 : Word16 dE2;
597 : Word16 ind_deltaMax, tmp_offset_flag;
598 : Word32 Ltmp0, *pt_enr_ssf, *pt_enr_ssf1, dE2_th;
599 : Word16 exp0, exp1;
600 : Word16 wtmp0, wtmp1;
601 : Word16 fac, mean_voi3, dE3;
602 : Word16 relE_thres;
603 : Word16 mean_voi3_offset;
604 : Word16 voicing_m, dpit1, dpit2, dpit3;
605 : Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE;
606 1304696 : NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst;
607 1304696 : SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
608 : Word16 Last_Resort;
609 : Word16 vadnoise;
610 :
611 1304696 : IF( hSC_VBR != NULL )
612 : {
613 0 : Last_Resort = hSC_VBR->Last_Resort; /* Q0 */
614 0 : move16();
615 0 : vadnoise = hSC_VBR->vadnoise_fx; /* Q8 */
616 0 : move16();
617 : }
618 : ELSE
619 : {
620 1304696 : Last_Resort = 0;
621 1304696 : move16();
622 1304696 : vadnoise = 0;
623 1304696 : move16();
624 : }
625 :
626 : /*-----------------------------------------------------------------*
627 : * Detect sudden energy increases to catch voice and music
628 : * temporal events (dE1)
629 : *
630 : * - Find maximum energy per short subblocks.
631 : * Two subblock sets are used shifted by half the subblock length
632 : * - Find maximum energy ratio between adjacent subblocks
633 : *-----------------------------------------------------------------*/
634 :
635 : /* Find maximum energy per short subblocks */
636 1304696 : pt_speech = speech - SSF;
637 1304696 : pt_enr_ssf = enr_ssf + 2 * NB_SSF;
638 24789224 : FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ )
639 : {
640 23484528 : emaximum_fx( Q_new, pt_speech, SSF, pt_enr_ssf );
641 23484528 : pt_speech += ( SSF / 2 );
642 23484528 : pt_enr_ssf++;
643 : }
644 :
645 1304696 : dE1 = 0;
646 1304696 : move16();
647 1304696 : ind_deltaMax = 0;
648 1304696 : move16();
649 1304696 : pt_enr_ssf = enr_ssf + 2 * NB_SSF;
650 1304696 : pt_enr_ssf1 = pt_enr_ssf + 2;
651 :
652 : /* Test on energy increase between adjacent sub-subframes */
653 1304696 : exp1 = 0;
654 1304696 : move16();
655 22179832 : FOR( i = 0; i < 2 * NB_SSF; i++ )
656 : {
657 : /*fac = *pt_enr_ssf1 / (*pt_enr_ssf + 1);*/
658 20875136 : Ltmp0 = L_max( *pt_enr_ssf, 1 );
659 20875136 : exp0 = norm_l( Ltmp0 );
660 20875136 : wtmp0 = extract_h( L_shl( Ltmp0, exp0 ) );
661 20875136 : exp1 = sub( norm_l( *pt_enr_ssf1 ), 1 );
662 20875136 : wtmp1 = extract_h( L_shl( *pt_enr_ssf1, exp1 ) );
663 20875136 : fac = div_s( wtmp1, wtmp0 );
664 20875136 : fac_32 = L_shr_sat( L_deposit_l( fac ), add( sub( exp1, exp0 ), 15 - 13 ) ); /* fac32 in Q13*/
665 :
666 20875136 : if ( GT_32( fac_32, dE1 ) )
667 : {
668 4061913 : ind_deltaMax = i;
669 4061913 : move16();
670 : }
671 :
672 20875136 : dE1 = L_max( dE1, fac_32 ); /* Q13 */
673 :
674 20875136 : pt_enr_ssf++;
675 20875136 : pt_enr_ssf1++;
676 : }
677 :
678 1304696 : IF( hStereoClassif != NULL )
679 : {
680 886921 : IF( st_fx->idchan == 0 )
681 : {
682 485845 : hStereoClassif->dE1_ch1_fx = dE1; /* Q13 */
683 485845 : move32();
684 485845 : hStereoClassif->dE1_ch1_e = 31 - Q13;
685 485845 : move16();
686 : }
687 : ELSE
688 : {
689 401076 : hStereoClassif->dE1_ch2_fx = dE1; /* Q13 */
690 401076 : move32();
691 401076 : hStereoClassif->dE1_ch2_e = 31 - Q13;
692 401076 : move16();
693 : }
694 : }
695 :
696 1304696 : if ( dE1X != NULL )
697 : {
698 1304696 : *dE1X = dE1; /* Q13 */
699 1304696 : move32();
700 : }
701 :
702 : /*-----------------------------------------------------------------*
703 : * Average spectral tilt
704 : * Average voicing (normalized correlation)
705 : *-----------------------------------------------------------------*/
706 :
707 : /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */
708 1304696 : mean_ee = L_add_sat( L_add_sat( st_fx->ee_old_fx, ee[0] ), ee[1] ); /* Q6 */
709 1304696 : mean_ee = Mult_32_16( mean_ee, 10923 ); /*Q6*/
710 :
711 : /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/
712 1304696 : Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ ); /* Q31 */
713 1304696 : Ltmp0 = L_mac( Ltmp0, st_fx->voicing_fx[1], 10923 /* 1/3 in Q15 */ ); /* Q31 */
714 1304696 : mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 /* 1/3 in Q15 */ ); /*Q15*/
715 : /*-----------------------------------------------------------------*
716 : * Total frame energy difference (dE3)
717 : *-----------------------------------------------------------------*/
718 :
719 1304696 : dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/
720 :
721 : /*-----------------------------------------------------------------*
722 : * Energy decrease after spike (dE2)
723 : *-----------------------------------------------------------------*/
724 :
725 : /* set different thresholds and conditions for NB and WB input */
726 1304696 : dE2_th = 30 << 10;
727 1304696 : move32();
728 1304696 : nb_cond = 1;
729 1304696 : move16(); /* no additional condition for WB input */
730 1304696 : IF( st_fx->input_bwidth == NB )
731 : {
732 3041 : dE2_th = 21 << 10;
733 3041 : move32();
734 3041 : if ( GE_16( add_sat( mean_voi3, corr_shift ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/
735 : {
736 2028 : nb_cond = 0;
737 2028 : move16();
738 : }
739 : }
740 :
741 : /* calcualte maximum energy decrease */
742 1304696 : dE2 = 0;
743 1304696 : move16(); /* Test on energy decrease after an energy spike */
744 1304696 : pt_enr_ssf = enr_ssf + 2 * NB_SSF;
745 :
746 1304696 : test();
747 1304696 : IF( GT_32( dE1, 30 << 13 ) && nb_cond ) /*>30 Q13*/
748 : {
749 27764 : IF( LT_16( sub( shl( NB_SSF, 1 ), ind_deltaMax ), L_ENR ) )
750 : {
751 10909 : st_fx->old_ind_deltaMax = ind_deltaMax; /* Q0 */
752 10909 : move16();
753 10909 : Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2 * NB_SSF ); /* Qx */
754 : }
755 : ELSE
756 : {
757 16855 : st_fx->old_ind_deltaMax = -1;
758 16855 : move16();
759 16855 : dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/
760 :
761 16855 : if ( GT_32( dE2, dE2_th ) )
762 : {
763 351 : st_fx->spike_hyst = 0;
764 351 : move16();
765 : }
766 : }
767 : }
768 : ELSE
769 : {
770 1276932 : IF( st_fx->old_ind_deltaMax >= 0 )
771 : {
772 13651 : Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2 * NB_SSF ); /* Qx */
773 13651 : dE2 = find_ener_decrease_fx( st_fx->old_ind_deltaMax, enr_ssf ); /* Q10 */
774 :
775 13651 : if ( GT_32( dE2, dE2_th ) )
776 : {
777 317 : st_fx->spike_hyst = 1;
778 317 : move16();
779 : }
780 : }
781 :
782 1276932 : st_fx->old_ind_deltaMax = -1;
783 1276932 : move16();
784 : }
785 :
786 : /*-----------------------------------------------------------------*
787 : * Detection of voiced offsets (tmp_offset_flag)
788 : *-----------------------------------------------------------------*/
789 :
790 1304696 : tmp_offset_flag = 1;
791 1304696 : move16();
792 :
793 1304696 : IF( st_fx->input_bwidth != NB )
794 : {
795 1301655 : ee0_th = 154; /*2.4 in Q6 */
796 1301655 : move16();
797 1301655 : voi_th = 24248; /*0.74f Q15 */
798 1301655 : move16();
799 : }
800 : ELSE
801 : {
802 3041 : ee0_th = 627; /*9.8f Q6 */
803 3041 : move16();
804 3041 : voi_th = 24904; /*0.76f Q15*/
805 3041 : move16();
806 : }
807 :
808 1304696 : E_min_th = L_shl( E_MIN_IVAS_FX_Q31, sub( q_hp_E, Q31 ) );
809 :
810 1304696 : test();
811 1304696 : test();
812 1304696 : test();
813 1304696 : IF( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */
814 : ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */
815 : ( LT_16( add_sat( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) )
816 : /* normalized correlation is low */
817 : {
818 166077 : tmp_offset_flag = 0;
819 166077 : move16();
820 : }
821 :
822 : /*-----------------------------------------------------------------*
823 : * Decision about UC
824 : *-----------------------------------------------------------------*/
825 :
826 : /* SC-VBR - set additional parameters and thresholds for SC-VBR */
827 1304696 : mean_voi3_offset = 0;
828 1304696 : move16();
829 1304696 : flag_low_relE = 0;
830 1304696 : move16();
831 1304696 : ee1_th = 608; /*9.5 Q6*/
832 1304696 : move16();
833 1304696 : test();
834 1304696 : test();
835 1304696 : IF( st_fx->Opt_SC_VBR || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) /* Allow the low energy flag for the secondary channel */
836 : {
837 4237 : ee1_th = 544; /*8.5f Q6*/
838 4237 : move16();
839 :
840 : /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */
841 4237 : IF( st_fx->input_bwidth != NB )
842 : {
843 : /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */
844 4237 : L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24
845 4237 : IF( Last_Resort == 0 )
846 : {
847 : /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/
848 4237 : L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24
849 : }
850 4237 : relE_thres = round_fx( L_tmp );
851 : }
852 : ELSE
853 : {
854 :
855 : /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/
856 0 : L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24
857 0 : relE_thres = round_fx( L_tmp );
858 : }
859 4237 : relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */
860 :
861 : /* SC-VBR = set flag on low relative energy */
862 4237 : if ( LT_16( relE, relE_thres ) )
863 : {
864 403 : flag_low_relE = 1;
865 403 : move16();
866 : }
867 :
868 : /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */
869 4237 : test();
870 4237 : if ( st_fx->input_bwidth == NB && LT_16( vadnoise, 20 << 8 ) ) /* vadnoise in Q8, constant Q0<<8 */
871 : {
872 0 : mean_voi3_offset = 1638; /*0.05f Q15*/
873 0 : move16();
874 : }
875 : }
876 :
877 : /* make decision whether frame is unvoiced */
878 1304696 : coder_type = GENERIC;
879 1304696 : move16();
880 1304696 : IF( st_fx->input_bwidth == NB )
881 : {
882 3041 : test();
883 3041 : test();
884 3041 : test();
885 3041 : test();
886 3041 : test();
887 3041 : test();
888 3041 : test();
889 3041 : test();
890 3041 : test();
891 3041 : test();
892 3041 : IF( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */
893 : ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */
894 : ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */
895 : ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
896 : ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */
897 : /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */
898 : ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */
899 : ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */
900 : ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
901 : flag_low_relE )
902 : /* low relative frame energy (only for SC-VBR) */
903 : {
904 96 : coder_type = UNVOICED;
905 96 : move16();
906 : }
907 : }
908 : ELSE
909 : {
910 1301655 : test();
911 1301655 : test();
912 1301655 : test();
913 1301655 : test();
914 1301655 : test();
915 1301655 : test();
916 1301655 : test();
917 1301655 : test();
918 1301655 : test();
919 2012055 : if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */
920 : /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */
921 1171984 : ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */
922 309183 : ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
923 114602 : ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */
924 : /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */
925 224148 : ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */
926 109546 : ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */
927 105896 : ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */
928 1196029 : || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */
929 : {
930 105929 : coder_type = UNVOICED;
931 105929 : move16();
932 : }
933 : }
934 :
935 : /*-----------------------------------------------------------------*
936 : * Decision about VC
937 : *-----------------------------------------------------------------*/
938 1304696 : if ( st_fx->Opt_SC_VBR )
939 : {
940 0 : hSC_VBR->set_ppp_generic = 0;
941 : }
942 1304696 : move16();
943 :
944 1304696 : test();
945 1304696 : test();
946 1304696 : IF( EQ_16( st_fx->localVAD, 1 ) && EQ_16( coder_type, GENERIC ) && NE_16( last_core_orig, AMR_WB_CORE ) )
947 : {
948 1031806 : dpit1 = abs_s( sub( T_op_fr[1], T_op_fr[0] ) ); /* Q6 */
949 1031806 : dpit2 = abs_s( sub( T_op_fr[2], T_op_fr[1] ) ); /* Q6 */
950 1031806 : dpit3 = abs_s( sub( T_op_fr[3], T_op_fr[2] ) ); /* Q6 */
951 :
952 1031806 : test();
953 1031806 : test();
954 1031806 : test();
955 1031806 : test();
956 1031806 : test();
957 1031806 : test();
958 1031806 : test();
959 1031806 : test();
960 1031806 : test();
961 1031806 : IF( ( GT_16( voicing_fr[0], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 1st sf. */
962 : ( GT_16( voicing_fr[1], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
963 : ( GT_16( voicing_fr[2], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 3st sf. */
964 : ( GT_16( voicing_fr[3], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 4st sf. */
965 : ( GT_32( mean_ee, 256 /* 4.0f in Q6 */ ) ) && /* energy concentrated in low frequencies */
966 : ( LT_16( dpit1, 3 << 6 ) ) &&
967 : ( LT_16( dpit2, 3 << 6 ) ) &&
968 : ( LT_16( dpit3, 3 << 6 ) ) )
969 : {
970 415309 : coder_type = VOICED;
971 415309 : move16();
972 : }
973 616497 : ELSE IF( st_fx->Opt_SC_VBR && st_fx->input_bwidth == NB && LT_16( vadnoise, 20 << 8 ) )
974 : {
975 0 : test();
976 0 : test();
977 0 : test();
978 0 : test();
979 0 : test();
980 0 : test();
981 0 : test();
982 0 : IF( GT_16( voicing_fr[0], 8192 /* 0.25 in Q15 */ ) && /* normalized correlation high in 1st sf. */
983 : ( GT_16( voicing_fr[1], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
984 : ( GT_16( voicing_fr[2], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 3st sf. */
985 : ( GT_16( voicing_fr[3], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 4st sf. */
986 : ( GT_32( mean_ee, 64 /* 1.0f in Q6 */ ) ) && /* energy concentrated in low frequencies */
987 : ( LT_16( dpit1, 5 << 6 ) ) &&
988 : ( LT_16( dpit2, 5 << 6 ) ) &&
989 : ( LT_16( dpit3, 5 << 6 ) ) )
990 : {
991 0 : hSC_VBR->set_ppp_generic = 1;
992 0 : move16();
993 0 : coder_type = VOICED;
994 0 : move16();
995 : }
996 : }
997 :
998 : /* set VOICED mode for frames with very stable pitch and high correlation
999 : and avoid to switch to AUDIO/MUSIC later */
1000 1031806 : voicing_m = mac_r( L_mac( L_mac( L_mult( voicing_fr[3], 8192 /* 0.25 in Q15 */ ), voicing_fr[2], 8192 /* 0.25 in Q15 */ ), voicing_fr[1], 8192 /* 0.25 in Q15 */ ), voicing_fr[0], 8192 /* 0.25 in Q15 */ ); /* Q15 */
1001 1031806 : test();
1002 1031806 : test();
1003 1031806 : test();
1004 1031806 : test();
1005 1031806 : test();
1006 1031806 : IF( *flag_spitch || ( LE_16( dpit1, 3 << 6 ) && LE_16( dpit2, 3 << 6 ) && LE_16( dpit3, 3 << 6 ) &&
1007 : GT_16( voicing_m, 31130 /* 0.95f in Q15 */ ) && GT_16( st_fx->voicing_sm_fx, 31785 /* 0.97f in Q15 */ ) ) )
1008 : {
1009 42342 : coder_type = VOICED;
1010 42342 : move16();
1011 42342 : *flag_spitch = 1;
1012 42342 : move16(); /*to avoid switch to AUDIO/MUSIC later*/
1013 : }
1014 : }
1015 :
1016 : /*-----------------------------------------------------------------*
1017 : * Channel-aware mode - set RF mode and total bitrate
1018 : *-----------------------------------------------------------------*/
1019 :
1020 1304696 : st_fx->rf_mode = st_fx->Opt_RF_ON; /* Q0 */
1021 1304696 : move16();
1022 :
1023 1304696 : IF( EQ_16( coder_type, GENERIC ) )
1024 : {
1025 777940 : test();
1026 777940 : test();
1027 777940 : test();
1028 777940 : test();
1029 777940 : IF( ( LT_16( voicing_fr[0], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
1030 : ( LT_16( voicing_fr[1], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf. */
1031 : ( LT_16( voicing_fr[2], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 3rd sf. */
1032 : ( LT_16( voicing_fr[3], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 4th sf. */
1033 : ( GT_16( vadnoise, 25 << 8 ) ) ) /* when speech is clean */
1034 :
1035 : {
1036 0 : st_fx->rf_mode = 0;
1037 0 : move16();
1038 : /* Current frame cannot be compressed to pack the partial redundancy;*/
1039 :
1040 0 : IF( NE_16( st_fx->rf_mode, st_fx->Opt_RF_ON ) )
1041 : {
1042 0 : core_coder_mode_switch_ivas_fx( st_fx, st_fx->last_total_brate, 0 );
1043 : }
1044 : }
1045 : }
1046 :
1047 : /*-----------------------------------------------------------------*
1048 : * UNCLR classifier
1049 : *-----------------------------------------------------------------*/
1050 :
1051 1304696 : IF( hStereoClassif != NULL )
1052 : {
1053 886921 : test();
1054 886921 : test();
1055 886921 : test();
1056 886921 : test();
1057 886921 : test();
1058 886921 : IF( st_fx->element_mode > EVS_MONO && ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, UNVOICED ) || coder_type == INACTIVE || st_fx->localVAD == 0 ) && LT_16( hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan], MAX_UV_CNT ) )
1059 : {
1060 574806 : hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan] = add( hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan], 1 );
1061 574806 : move16();
1062 : }
1063 : ELSE
1064 : {
1065 312115 : hStereoClassif->unclr_sw_enable_cnt[st_fx->idchan] = 0;
1066 312115 : move16();
1067 : }
1068 : }
1069 :
1070 : /*-----------------------------------------------------------------*
1071 : * Updates
1072 : *-----------------------------------------------------------------*/
1073 :
1074 : /* update spike hysteresis parameters */
1075 1304696 : test();
1076 1304696 : if ( st_fx->spike_hyst >= 0 && LT_16( st_fx->spike_hyst, 2 ) )
1077 : {
1078 1007 : st_fx->spike_hyst = add( st_fx->spike_hyst, 1 ); /* Q0 */
1079 1007 : move16();
1080 : }
1081 :
1082 : /* reset spike hysteresis */
1083 1304696 : test();
1084 1304696 : test();
1085 1304696 : test();
1086 1309235 : if ( ( GT_16( st_fx->spike_hyst, 1 ) ) &&
1087 8798 : ( GT_16( dE3, 5 << 8 ) || /* energy increases */
1088 7334 : ( GT_16( relE, -3328 /* 13 in Q8 */ ) && ( GT_16( add_sat( mean_voi3, corr_shift ), 22774 /* 0.695 in Q15 */ ) ) ) ) ) /* normalized correlation is high */
1089 : {
1090 620 : st_fx->spike_hyst = -1;
1091 620 : move16();
1092 : }
1093 :
1094 : /* update tilt parameters */
1095 1304696 : st_fx->ee_old_fx = ee[1];
1096 1304696 : move32(); /*Q6*/
1097 1304696 : st_fx->old_dE1_fx = dE1;
1098 1304696 : move32(); /*Q13*/
1099 :
1100 : /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */
1101 1304696 : st_fx->coder_type_raw = coder_type; /* Q0 */
1102 1304696 : move16();
1103 :
1104 1304696 : return coder_type;
1105 : }
|