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 "rom_com_fx.h" /* Static table prototypes */
8 : #include "rom_com.h" /* Static table prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 : #include "prot_fx_enc.h" /* Function prototypes */
11 :
12 : /*-------------------------------------------------------------------*
13 : * Local constantes
14 : *-------------------------------------------------------------------*/
15 : #define NB_VOIC_FX 13
16 : #define DIV_NB_VOIC_FX 2521
17 :
18 : #define ALPA_FX 31130
19 : #define ALPAM1_FX ( 32768 - ALPA_FX )
20 :
21 : #define BETA_FX 819
22 : #define AFREQ_THR 2
23 :
24 : #define HANGOVER_DELAY 2
25 :
26 : /*======================================================================*/
27 : /* FUNCTION : Pit_exc_contribution_len_fx() */
28 : /*----------------------------------------------------------------------*/
29 : /* PURPOSE : Determine up to which band the pit contribution is significant*/
30 : /*----------------------------------------------------------------------*/
31 : /* INPUT ARGUMENTS : */
32 : /* _ (Struct) st_fx : encoder static memory */
33 : /* _ (Word16[]) dct_res : DCT of residual Qnew */
34 : /* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */
35 : /* _ (Word16[]) pitch_buf : Pitch per subframe Q6 */
36 : /* _ (Word16[]) nb_subfr : Number of subframe considered */
37 : /* _ (Word16) hangover : hangover for the time contribution switching*/
38 : /* _ (Word16) Qnew : */
39 : /*-----------------------------------------------------------------------*/
40 : /* OUTPUT ARGUMENTS : */
41 : /* _ (Word16[]) dct_res : DCT of residual Qnew */
42 : /* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */
43 : /*-----------------------------------------------------------------------*/
44 :
45 :
46 : /*-----------------------------------------------------------------------*/
47 : /* RETURN ARGUMENTS : */
48 : /* _ None */
49 : /*=======================================================================*/
50 :
51 7 : Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */
52 : Encoder_State *st_fx, /* i/o: state structure */
53 : const Word16 *dct_res, /* i : DCT of residual Qnew*/
54 : Word16 *dct_pitex, /* i/o: DCT of pitch contribution Qnew*/
55 : Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/
56 : const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
57 : Word16 *hangover, /* i : hangover for the time contribution switching Q0*/
58 : Word16 Qnew )
59 : {
60 :
61 : Word16 corr_dct_pit[MBANDS_LOC];
62 : Word32 corr_tmp, L_tmp;
63 : Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res;
64 : Word16 freq, i, j;
65 : Word16 last_pit_band, pit_contr_idx, last_pit_bin;
66 : Word32 ener_res;
67 : Word32 ener_pit;
68 : Word16 low_pit, F1st_harm, F8th_harm;
69 : Word16 corr_dct_pit_tmp[MBANDS_LOC];
70 7 : Word16 time_flg = 0;
71 : Word16 Len, max_len;
72 : Word16 tmp_dec;
73 7 : Word16 Mbands_loc = MBANDS_LOC - 2;
74 : Word16 exp1, tmp, exp2;
75 : Word32 L_tmp1, ener_init;
76 : Word16 exp_norm;
77 : Word16 norm;
78 : Word16 val_thrs;
79 7 : SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
80 7 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
81 7 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
82 7 : move16();
83 7 : move16();
84 :
85 7 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
86 : {
87 0 : Mbands_loc = MBANDS_LOC;
88 0 : move16();
89 : }
90 :
91 7 : minimum_fx( pitch_buf, nb_subfr, &low_pit );
92 7 : exp1 = norm_s( low_pit );
93 7 : tmp = shl( low_pit, exp1 );
94 7 : tmp_dec = 12800;
95 7 : move16();
96 7 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
97 : {
98 0 : tmp_dec = 16000;
99 0 : move16();
100 : }
101 : /*F1st_harm = (12800.0f|160000.f)/low_pit;*/
102 7 : tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/
103 7 : F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/
104 :
105 : /*F8th_harm = 8.0f*F1st_harm;*/
106 7 : F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/
107 :
108 7 : freq = 0;
109 7 : move16();
110 7 : ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5) 2*Qnew*/
111 98 : FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
112 : {
113 91 : corr_tmp = L_deposit_l( 0 );
114 91 : ener_res = L_add( ener_init, 0 );
115 91 : ener_pit = L_add( ener_init, 0 );
116 :
117 1435 : FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */
118 : {
119 1344 : tmp_ex = mult_r( dct_pitex[j + freq], 8192 /* 0.25 in Q15 */ );
120 1344 : tmp_res = mult_r( dct_res[j + freq], 8192 /* 0.25 in Q15 */ );
121 1344 : corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/
122 1344 : ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/
123 1344 : ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/
124 : }
125 :
126 91 : L_tmp1 = Mult_32_32( ener_res, ener_pit );
127 91 : exp2 = norm_l( L_tmp1 );
128 91 : L_tmp1 = L_shl( L_tmp1, exp2 );
129 91 : exp_norm = sub( 30, exp2 );
130 91 : L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm );
131 91 : norm = extract_h( L_tmp1 ); /*15-exp_norm*/
132 91 : L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm );
133 91 : corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/
134 :
135 91 : freq = add( freq, mfreq_bindiv_loc[i] );
136 : }
137 :
138 7 : val_thrs = 8192;
139 7 : move16(); /* 0.5 in Q14*/
140 : /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/
141 7 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/
142 7 : tmp = s_max( tmp, val_thrs );
143 :
144 7 : corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 );
145 7 : move16();
146 :
147 84 : FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */
148 : {
149 77 : L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q30 */
150 77 : L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q30 */
151 :
152 77 : tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q30 */
153 77 : tmp = s_max( tmp, val_thrs );
154 :
155 77 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 );
156 77 : move16();
157 : }
158 7 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/
159 7 : tmp = s_max( tmp, val_thrs );
160 7 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 );
161 7 : move16();
162 :
163 7 : Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc );
164 :
165 7 : L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/
166 91 : FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */
167 : {
168 84 : L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] );
169 : }
170 7 : av_corr = round_fx( L_tmp1 ); /*Qnew*/
171 :
172 : /* Find the cut-off freq similarly to HSX */
173 7 : last_pit_band = 0;
174 7 : move16();
175 7 : av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/
176 :
177 7 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
178 : {
179 : /*av_corr *= 1.25f;*/
180 0 : av_corr = add( av_corr, shr( av_corr, 2 ) ); /* Q2 */
181 : }
182 7 : test();
183 7 : if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) )
184 : {
185 0 : av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/
186 : }
187 7 : min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/
188 :
189 91 : FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
190 : {
191 84 : ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/
192 :
193 84 : IF( LT_16( ftmp, min_corr ) )
194 : {
195 1 : last_pit_band = i;
196 1 : move16();
197 1 : min_corr = ftmp; /* Q2 */
198 1 : move16();
199 : }
200 : }
201 :
202 7 : IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) )
203 : {
204 : DO
205 : {
206 61 : last_pit_band = add( last_pit_band, 1 );
207 : }
208 61 : WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) );
209 : }
210 7 : if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) )
211 : {
212 0 : last_pit_band = s_max( last_pit_band, 7 );
213 : }
214 7 : test();
215 7 : test();
216 7 : test();
217 7 : IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/
218 : {
219 0 : last_pit_band = 7 + BAND1k2;
220 0 : move16();
221 : }
222 7 : ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) )
223 : {
224 0 : last_pit_band = add( 10, BAND1k2 );
225 : }
226 :
227 7 : time_flg = 0;
228 7 : move16();
229 7 : test();
230 7 : test();
231 7 : test();
232 7 : test();
233 7 : test();
234 7 : test();
235 7 : test();
236 7 : test();
237 7 : test();
238 7 : test();
239 7 : IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) )
240 : {
241 7 : tmp_dec = 1;
242 7 : move16();
243 : }
244 : ELSE
245 : {
246 0 : tmp_dec = 0;
247 0 : move16();
248 : }
249 :
250 : /* Different past and current decision */
251 7 : test();
252 7 : test();
253 7 : test();
254 7 : IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) )
255 : {
256 0 : IF( *hangover == 0 )
257 : {
258 0 : time_flg = tmp_dec;
259 0 : move16();
260 0 : *hangover = HANGOVER_DELAY;
261 0 : move16();
262 : }
263 : ELSE
264 : {
265 0 : time_flg = 0;
266 0 : move16();
267 0 : if ( hGSCEnc->mem_last_pit_band > 0 )
268 : {
269 0 : time_flg = 1;
270 0 : move16();
271 : }
272 :
273 0 : ( *hangover ) = sub( ( *hangover ), 1 );
274 0 : if ( *hangover < 0 )
275 : {
276 0 : *hangover = 0;
277 0 : move16();
278 : }
279 : }
280 : }
281 : ELSE
282 : {
283 7 : time_flg = tmp_dec;
284 7 : move16();
285 7 : *hangover = HANGOVER_DELAY;
286 7 : move16();
287 : }
288 :
289 : /* Decicison on final length of time contribution */
290 7 : pit_contr_idx = 0;
291 7 : move16();
292 7 : test();
293 7 : test();
294 7 : IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech )
295 : {
296 7 : test();
297 7 : test();
298 : /*if(st_fx->core_brate <ACELP_9k60)*/
299 7 : IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 ) )
300 : {
301 0 : last_pit_band = add( 9, BAND1k2 );
302 0 : if ( EQ_16( st_fx->bwidth, NB ) )
303 : {
304 0 : last_pit_band = add( 7, BAND1k2 );
305 : }
306 : }
307 7 : ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 ) )
308 : {
309 0 : last_pit_band = add( 5, BAND1k2 );
310 : }
311 7 : ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
312 : {
313 0 : last_pit_band = add( 3, BAND1k2 );
314 : }
315 7 : ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) )
316 : {
317 1 : last_pit_band = add( BAND1k2, 1 );
318 : }
319 7 : last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q0 */
320 7 : move16();
321 :
322 7 : st_fx->bpf_off = 0;
323 7 : move16();
324 :
325 7 : max_len = sub( st_fx->L_frame, last_pit_bin ); /* Q0 */
326 :
327 7 : if ( EQ_16( st_fx->bwidth, NB ) )
328 : {
329 0 : max_len = sub( 160, last_pit_bin );
330 : }
331 :
332 7 : Len = 80;
333 7 : move16();
334 7 : if ( LT_16( max_len, 80 ) )
335 : {
336 2 : Len = max_len;
337 2 : move16();
338 : }
339 7 : test();
340 7 : IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) )
341 : {
342 0 : move16(); /*ptr init*/
343 0 : FOR( i = 0; i < max_len; i++ )
344 : {
345 0 : dct_pitex[i + last_pit_bin] = 0;
346 0 : move16();
347 : }
348 : }
349 : ELSE
350 : {
351 :
352 537 : FOR( i = 0; i < Len; i++ )
353 : {
354 530 : dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */
355 : }
356 252 : FOR( ; i < max_len; i++ )
357 : {
358 245 : dct_pitex[i + last_pit_bin] = 0;
359 245 : move16();
360 : }
361 : }
362 7 : hGSCEnc->mem_last_pit_band = last_pit_band; /* Q0 */
363 7 : move16();
364 7 : pit_contr_idx = sub( last_pit_band, BAND1k2 );
365 : }
366 : ELSE
367 : {
368 0 : set16_fx( dct_pitex, 0, st_fx->L_frame );
369 0 : st_fx->bpf_off = 1;
370 0 : move16();
371 0 : last_pit_bin = 0;
372 0 : move16();
373 0 : last_pit_band = 0;
374 0 : move16();
375 0 : pit_contr_idx = 0;
376 0 : move16();
377 0 : hGSCEnc->mem_last_pit_band = 0;
378 0 : move16();
379 :
380 0 : set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k );
381 :
382 : #ifdef HARM_PUSH_BIT
383 : /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */
384 0 : for ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ )
385 : {
386 0 : delete_indice( hBstr, i );
387 : }
388 :
389 0 : delete_indice( hBstr, IND_ES_PRED );
390 : #else
391 : /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */
392 : FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ )
393 : {
394 : IF( hBstr->ind_list[i].nb_bits != -1 )
395 : {
396 : hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[i].nb_bits ); /* Q0 */
397 : hBstr->ind_list[i].nb_bits = -1;
398 : move16();
399 : }
400 : }
401 :
402 : IF( hBstr->ind_list[IND_ES_PRED].nb_bits != -1 )
403 : {
404 : hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_ES_PRED].nb_bits ); /* Q0 */
405 : move16();
406 : hBstr->ind_list[IND_ES_PRED].nb_bits = -1;
407 : move16();
408 : }
409 : #endif
410 : }
411 7 : IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) )
412 : {
413 0 : IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
414 : {
415 0 : if ( pit_contr_idx > 0 )
416 : {
417 0 : pit_contr_idx = 1;
418 0 : move16();
419 : }
420 :
421 0 : IF( EQ_16( st_fx->coder_type, INACTIVE ) )
422 : {
423 0 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 );
424 : }
425 : }
426 : ELSE
427 : {
428 0 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 );
429 : }
430 : }
431 : ELSE
432 : {
433 7 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 );
434 : }
435 :
436 7 : return last_pit_bin;
437 : }
438 :
439 :
440 15159 : Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */
441 : Encoder_State *st_fx, /* i/o: state structure */
442 : const Word16 *dct_res, /* i : DCT of residual Q_new*/
443 : Word16 *dct_pitex, /* i/o: DCT of pitch contribution Q_new*/
444 : Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/
445 : const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
446 : Word16 *hangover, /* i : hangover for the time contribution switching Q0*/
447 : Word16 Qnew )
448 : {
449 :
450 : Word16 corr_dct_pit[MBANDS_LOC];
451 : Word32 corr_tmp, L_tmp;
452 : Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res;
453 : Word16 freq, i, j;
454 : Word16 last_pit_band, pit_contr_idx, last_pit_bin;
455 : Word32 ener_res;
456 : Word32 ener_pit;
457 : Word16 low_pit, F1st_harm, F8th_harm;
458 : Word16 corr_dct_pit_tmp[MBANDS_LOC];
459 15159 : Word16 time_flg = 0;
460 : Word16 Len, max_len;
461 : Word16 tmp_dec;
462 15159 : Word16 Mbands_loc = MBANDS_LOC - 2;
463 : Word16 exp1, tmp, exp2;
464 : Word32 L_tmp1, ener_init;
465 : Word16 exp_norm;
466 : Word16 norm;
467 : Word16 val_thrs;
468 15159 : SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
469 15159 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
470 15159 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
471 15159 : move16();
472 :
473 15159 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
474 : {
475 2650 : Mbands_loc = MBANDS_LOC;
476 2650 : move16();
477 : }
478 :
479 15159 : minimum_fx( pitch_buf, nb_subfr, &low_pit );
480 15159 : exp1 = norm_s( low_pit );
481 15159 : tmp = shl( low_pit, exp1 );
482 15159 : tmp_dec = 12800;
483 15159 : move16();
484 15159 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
485 : {
486 2650 : tmp_dec = 16000;
487 2650 : move16();
488 : }
489 : /*F1st_harm = (12800.0f|160000.f)/low_pit;*/
490 15159 : tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/
491 15159 : F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/
492 :
493 : /*F8th_harm = 8.0f*F1st_harm;*/
494 15159 : F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/
495 :
496 15159 : freq = 0;
497 15159 : move16();
498 15159 : ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5) 2*Qnew*/
499 217526 : FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
500 : {
501 202367 : corr_tmp = L_deposit_l( 0 );
502 202367 : ener_res = L_add( ener_init, 0 );
503 202367 : ener_pit = L_add( ener_init, 0 );
504 :
505 3197695 : FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */
506 : {
507 2995328 : tmp_ex = mult_r( dct_pitex[j + freq], 8192 );
508 2995328 : tmp_res = mult_r( dct_res[j + freq], 8192 );
509 2995328 : corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/
510 2995328 : ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/
511 2995328 : ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/
512 : }
513 :
514 202367 : L_tmp1 = Mult_32_32( ener_res, ener_pit );
515 202367 : exp2 = norm_l( L_tmp1 );
516 202367 : L_tmp1 = L_shl( L_tmp1, exp2 );
517 202367 : exp_norm = sub( 30, exp2 );
518 202367 : L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm );
519 202367 : norm = extract_h( L_tmp1 ); /*15-exp_norm*/
520 202367 : L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm );
521 202367 : corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/
522 :
523 202367 : freq = add( freq, mfreq_bindiv_loc[i] );
524 : }
525 :
526 15159 : val_thrs = 8192;
527 15159 : move16(); /* 0.5 in Q14*/
528 : /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/
529 15159 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/
530 15159 : tmp = s_max( tmp, val_thrs ); /*Qnew */
531 :
532 15159 : corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
533 15159 : move16();
534 :
535 187208 : FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */
536 : {
537 172049 : L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q_new + 16 */
538 172049 : L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q_new + 16 */
539 :
540 172049 : tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q_new */
541 172049 : tmp = s_max( tmp, val_thrs ); /* Q_new */
542 :
543 172049 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
544 172049 : move16();
545 : }
546 15159 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/
547 15159 : tmp = s_max( tmp, val_thrs ); /* Q_new */
548 15159 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
549 15159 : move16();
550 :
551 15159 : Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); /* Q_new + 1 */
552 :
553 15159 : L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/
554 197067 : FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */
555 : {
556 181908 : L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); /* Q_new + 16 */
557 : }
558 15159 : av_corr = round_fx( L_tmp1 ); /*Qnew*/
559 :
560 : /* Find the cut-off freq similarly to HSX */
561 15159 : last_pit_band = 0;
562 15159 : move16();
563 15159 : av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/
564 :
565 15159 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
566 : {
567 : /*av_corr *= 1.25f;*/
568 2650 : av_corr = add( av_corr, shr( av_corr, 2 ) );
569 : }
570 15159 : test();
571 15159 : if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) )
572 : {
573 10521 : av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/
574 : }
575 15159 : min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/
576 :
577 202367 : FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
578 : {
579 187208 : ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/
580 :
581 187208 : IF( LT_16( ftmp, min_corr ) )
582 : {
583 32237 : last_pit_band = i;
584 32237 : move16();
585 32237 : min_corr = ftmp;
586 32237 : move16();
587 : }
588 : }
589 :
590 15159 : IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) )
591 : {
592 : DO
593 : {
594 60379 : last_pit_band = add( last_pit_band, 1 );
595 : }
596 60379 : WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) );
597 : }
598 15159 : if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) )
599 : {
600 4932 : last_pit_band = s_max( last_pit_band, 7 );
601 : }
602 15159 : test();
603 15159 : test();
604 15159 : test();
605 15159 : IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/
606 : {
607 1331 : last_pit_band = 7 + BAND1k2;
608 1331 : move16();
609 : }
610 13828 : ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) )
611 : {
612 239 : last_pit_band = add( 10, BAND1k2 );
613 : }
614 :
615 15159 : time_flg = 0;
616 15159 : move16();
617 15159 : test();
618 15159 : test();
619 15159 : test();
620 15159 : test();
621 15159 : test();
622 15159 : test();
623 15159 : test();
624 15159 : test();
625 15159 : test();
626 15159 : test();
627 15159 : IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) )
628 : {
629 10224 : tmp_dec = 1;
630 10224 : move16();
631 : }
632 : ELSE
633 : {
634 4935 : tmp_dec = 0;
635 4935 : move16();
636 : }
637 :
638 : /* Different past and current decision */
639 15159 : test();
640 15159 : test();
641 15159 : test();
642 15159 : IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) )
643 : {
644 4567 : IF( *hangover == 0 )
645 : {
646 857 : time_flg = tmp_dec;
647 857 : move16();
648 857 : *hangover = HANGOVER_DELAY;
649 857 : move16();
650 : }
651 : ELSE
652 : {
653 3710 : time_flg = 0;
654 3710 : move16();
655 3710 : if ( hGSCEnc->mem_last_pit_band > 0 )
656 : {
657 2916 : time_flg = 1;
658 2916 : move16();
659 : }
660 :
661 3710 : ( *hangover ) = sub( ( *hangover ), 1 ); /* Q0 */
662 3710 : if ( *hangover < 0 )
663 : {
664 0 : *hangover = 0;
665 0 : move16();
666 : }
667 : }
668 : }
669 : ELSE
670 : {
671 10592 : time_flg = tmp_dec;
672 10592 : move16();
673 10592 : *hangover = HANGOVER_DELAY;
674 10592 : move16();
675 : }
676 :
677 : /* Decicison on final length of time contribution */
678 15159 : pit_contr_idx = 0;
679 15159 : move16();
680 15159 : test();
681 15159 : test();
682 15159 : IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech )
683 : {
684 12908 : test();
685 12908 : test();
686 : /*if(st_fx->core_brate <ACELP_9k60)*/
687 12908 : IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 /* 64 in Q6 */ ) )
688 : {
689 3408 : last_pit_band = add( 9, BAND1k2 );
690 3408 : if ( EQ_16( st_fx->bwidth, NB ) )
691 : {
692 0 : last_pit_band = add( 7, BAND1k2 );
693 : }
694 : }
695 9500 : ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 /* 128 in Q6 */ ) )
696 : {
697 2382 : last_pit_band = add( 5, BAND1k2 );
698 : }
699 7118 : ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
700 : {
701 1840 : last_pit_band = add( 3, BAND1k2 );
702 : }
703 5278 : ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) )
704 : {
705 714 : last_pit_band = add( BAND1k2, 1 );
706 : }
707 12908 : last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q15 */
708 12908 : move16();
709 :
710 12908 : st_fx->bpf_off = 0;
711 12908 : move16();
712 :
713 12908 : max_len = sub( st_fx->L_frame, last_pit_bin );
714 :
715 12908 : if ( EQ_16( st_fx->bwidth, NB ) )
716 : {
717 0 : max_len = sub( 160, last_pit_bin );
718 : }
719 :
720 12908 : Len = 80;
721 12908 : move16();
722 12908 : if ( LT_16( max_len, 80 ) )
723 : {
724 3632 : Len = max_len;
725 3632 : move16();
726 : }
727 12908 : test();
728 12908 : IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) )
729 : {
730 41 : move16(); /*ptr init*/
731 3762 : FOR( i = 0; i < max_len; i++ )
732 : {
733 3721 : dct_pitex[i + last_pit_bin] = 0;
734 3721 : move16();
735 : }
736 : }
737 : ELSE
738 : {
739 :
740 985897 : FOR( i = 0; i < Len; i++ )
741 : {
742 973030 : dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */
743 : }
744 668064 : FOR( ; i < max_len; i++ )
745 : {
746 655197 : dct_pitex[i + last_pit_bin] = 0;
747 655197 : move16();
748 : }
749 : }
750 12908 : hGSCEnc->mem_last_pit_band = last_pit_band;
751 12908 : move16();
752 12908 : pit_contr_idx = sub( last_pit_band, BAND1k2 );
753 : }
754 : ELSE
755 : {
756 2251 : set16_fx( dct_pitex, 0, st_fx->L_frame );
757 2251 : st_fx->bpf_off = 1;
758 2251 : move16();
759 2251 : last_pit_bin = 0;
760 2251 : move16();
761 2251 : last_pit_band = 0;
762 2251 : move16();
763 2251 : pit_contr_idx = 0;
764 2251 : move16();
765 2251 : hGSCEnc->mem_last_pit_band = 0;
766 2251 : move16();
767 :
768 2251 : set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k );
769 : /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */
770 677551 : FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ )
771 : {
772 675300 : delete_indice( hBstr, i );
773 : }
774 2251 : delete_indice( hBstr, IND_ES_PRED );
775 : }
776 15159 : IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) )
777 : {
778 9788 : IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
779 : {
780 7750 : if ( pit_contr_idx > 0 )
781 : {
782 7630 : pit_contr_idx = 1;
783 7630 : move16();
784 : }
785 :
786 7750 : IF( EQ_16( st_fx->coder_type, INACTIVE ) )
787 : {
788 324 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 );
789 : }
790 : }
791 : ELSE
792 : {
793 2038 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 );
794 : }
795 : }
796 : ELSE
797 : {
798 5371 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 );
799 : }
800 :
801 15159 : return last_pit_bin;
802 : }
|