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 8 : 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 8 : Word16 time_flg = 0;
71 : Word16 Len, max_len;
72 : Word16 tmp_dec;
73 8 : 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 8 : SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
80 8 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
81 8 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
82 8 : move16();
83 8 : move16();
84 :
85 8 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
86 : {
87 0 : Mbands_loc = MBANDS_LOC;
88 0 : move16();
89 : }
90 :
91 8 : minimum_fx( pitch_buf, nb_subfr, &low_pit );
92 8 : exp1 = norm_s( low_pit );
93 8 : tmp = shl( low_pit, exp1 );
94 8 : tmp_dec = 12800;
95 8 : move16();
96 8 : 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 8 : tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/
103 8 : F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/
104 :
105 : /*F8th_harm = 8.0f*F1st_harm;*/
106 8 : F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/
107 :
108 8 : freq = 0;
109 8 : move16();
110 8 : ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5) 2*Qnew*/
111 112 : FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
112 : {
113 104 : corr_tmp = L_deposit_l( 0 );
114 104 : ener_res = L_add( ener_init, 0 );
115 104 : ener_pit = L_add( ener_init, 0 );
116 :
117 1640 : FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */
118 : {
119 1536 : tmp_ex = mult_r( dct_pitex[j + freq], 8192 /* 0.25 in Q15 */ );
120 1536 : tmp_res = mult_r( dct_res[j + freq], 8192 /* 0.25 in Q15 */ );
121 1536 : corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/
122 1536 : ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/
123 1536 : ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/
124 : }
125 :
126 104 : L_tmp1 = Mult_32_32( ener_res, ener_pit );
127 104 : exp2 = norm_l( L_tmp1 );
128 104 : L_tmp1 = L_shl( L_tmp1, exp2 );
129 104 : exp_norm = sub( 30, exp2 );
130 104 : L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm );
131 104 : norm = extract_h( L_tmp1 ); /*15-exp_norm*/
132 104 : L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm );
133 104 : corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/
134 :
135 104 : freq = add( freq, mfreq_bindiv_loc[i] );
136 : }
137 :
138 8 : val_thrs = 8192;
139 8 : 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 8 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/
142 8 : tmp = s_max( tmp, val_thrs );
143 :
144 8 : corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 );
145 8 : move16();
146 :
147 96 : FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */
148 : {
149 88 : L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q30 */
150 88 : L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q30 */
151 :
152 88 : tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q30 */
153 88 : tmp = s_max( tmp, val_thrs );
154 :
155 88 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 );
156 88 : move16();
157 : }
158 8 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/
159 8 : tmp = s_max( tmp, val_thrs );
160 8 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 );
161 8 : move16();
162 :
163 8 : Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc );
164 :
165 8 : L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/
166 104 : FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */
167 : {
168 96 : L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] );
169 : }
170 8 : av_corr = round_fx( L_tmp1 ); /*Qnew*/
171 :
172 : /* Find the cut-off freq similarly to HSX */
173 8 : last_pit_band = 0;
174 8 : move16();
175 8 : av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/
176 :
177 8 : 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 8 : test();
183 8 : 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 8 : min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/
188 :
189 104 : FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
190 : {
191 96 : ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/
192 :
193 96 : IF( LT_16( ftmp, min_corr ) )
194 : {
195 2 : last_pit_band = i;
196 2 : move16();
197 2 : min_corr = ftmp; /* Q2 */
198 2 : move16();
199 : }
200 : }
201 :
202 8 : IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) )
203 : {
204 : DO
205 : {
206 65 : last_pit_band = add( last_pit_band, 1 );
207 : }
208 65 : WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) );
209 : }
210 8 : if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) )
211 : {
212 0 : last_pit_band = s_max( last_pit_band, 7 );
213 : }
214 8 : test();
215 8 : test();
216 8 : test();
217 8 : 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 8 : 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 8 : time_flg = 0;
228 8 : move16();
229 8 : test();
230 8 : test();
231 8 : test();
232 8 : test();
233 8 : test();
234 8 : test();
235 8 : test();
236 8 : test();
237 8 : test();
238 8 : test();
239 8 : 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 8 : tmp_dec = 1;
242 8 : move16();
243 : }
244 : ELSE
245 : {
246 0 : tmp_dec = 0;
247 0 : move16();
248 : }
249 :
250 : /* Different past and current decision */
251 8 : test();
252 8 : test();
253 8 : test();
254 8 : 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 8 : time_flg = tmp_dec;
284 8 : move16();
285 8 : *hangover = HANGOVER_DELAY;
286 8 : move16();
287 : }
288 :
289 : /* Decicison on final length of time contribution */
290 8 : pit_contr_idx = 0;
291 8 : move16();
292 8 : test();
293 8 : test();
294 8 : IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech )
295 : {
296 8 : test();
297 8 : test();
298 : /*if(st_fx->core_brate <ACELP_9k60)*/
299 8 : 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 8 : 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 8 : ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
312 : {
313 0 : last_pit_band = add( 3, BAND1k2 );
314 : }
315 8 : ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) )
316 : {
317 1 : last_pit_band = add( BAND1k2, 1 );
318 : }
319 8 : last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q0 */
320 8 : move16();
321 :
322 8 : st_fx->bpf_off = 0;
323 8 : move16();
324 :
325 8 : max_len = sub( st_fx->L_frame, last_pit_bin ); /* Q0 */
326 :
327 8 : if ( EQ_16( st_fx->bwidth, NB ) )
328 : {
329 0 : max_len = sub( 160, last_pit_bin );
330 : }
331 :
332 8 : Len = 80;
333 8 : move16();
334 8 : if ( LT_16( max_len, 80 ) )
335 : {
336 1 : Len = max_len;
337 1 : move16();
338 : }
339 8 : test();
340 8 : 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 617 : FOR( i = 0; i < Len; i++ )
353 : {
354 609 : dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */
355 : }
356 351 : FOR( ; i < max_len; i++ )
357 : {
358 343 : dct_pitex[i + last_pit_bin] = 0;
359 343 : move16();
360 : }
361 : }
362 8 : hGSCEnc->mem_last_pit_band = last_pit_band; /* Q0 */
363 8 : move16();
364 8 : 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 : /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */
383 0 : for ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ )
384 : {
385 0 : delete_indice( hBstr, i );
386 : }
387 :
388 0 : delete_indice( hBstr, IND_ES_PRED );
389 : }
390 8 : IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) )
391 : {
392 0 : IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
393 : {
394 0 : if ( pit_contr_idx > 0 )
395 : {
396 0 : pit_contr_idx = 1;
397 0 : move16();
398 : }
399 :
400 0 : IF( EQ_16( st_fx->coder_type, INACTIVE ) )
401 : {
402 0 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 );
403 : }
404 : }
405 : ELSE
406 : {
407 0 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 );
408 : }
409 : }
410 : ELSE
411 : {
412 8 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 );
413 : }
414 :
415 8 : return last_pit_bin;
416 : }
417 :
418 :
419 15091 : Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */
420 : Encoder_State *st_fx, /* i/o: state structure */
421 : const Word16 *dct_res, /* i : DCT of residual Q_new*/
422 : Word16 *dct_pitex, /* i/o: DCT of pitch contribution Q_new*/
423 : Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/
424 : const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
425 : Word16 *hangover, /* i : hangover for the time contribution switching Q0*/
426 : Word16 Qnew )
427 : {
428 :
429 : Word16 corr_dct_pit[MBANDS_LOC];
430 : Word32 corr_tmp, L_tmp;
431 : Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res;
432 : Word16 freq, i, j;
433 : Word16 last_pit_band, pit_contr_idx, last_pit_bin;
434 : Word32 ener_res;
435 : Word32 ener_pit;
436 : Word16 low_pit, F1st_harm, F8th_harm;
437 : Word16 corr_dct_pit_tmp[MBANDS_LOC];
438 15091 : Word16 time_flg = 0;
439 : Word16 Len, max_len;
440 : Word16 tmp_dec;
441 15091 : Word16 Mbands_loc = MBANDS_LOC - 2;
442 : Word16 exp1, tmp, exp2;
443 : Word32 L_tmp1, ener_init;
444 : Word16 exp_norm;
445 : Word16 norm;
446 : Word16 val_thrs;
447 15091 : SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
448 15091 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
449 15091 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
450 15091 : move16();
451 :
452 15091 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
453 : {
454 2659 : Mbands_loc = MBANDS_LOC;
455 2659 : move16();
456 : }
457 :
458 15091 : minimum_fx( pitch_buf, nb_subfr, &low_pit );
459 15091 : exp1 = norm_s( low_pit );
460 15091 : tmp = shl( low_pit, exp1 );
461 15091 : tmp_dec = 12800;
462 15091 : move16();
463 15091 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
464 : {
465 2659 : tmp_dec = 16000;
466 2659 : move16();
467 : }
468 : /*F1st_harm = (12800.0f|160000.f)/low_pit;*/
469 15091 : tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/
470 15091 : F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/
471 :
472 : /*F8th_harm = 8.0f*F1st_harm;*/
473 15091 : F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/
474 :
475 15091 : freq = 0;
476 15091 : move16();
477 15091 : ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5) 2*Qnew*/
478 216592 : FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
479 : {
480 201501 : corr_tmp = L_deposit_l( 0 );
481 201501 : ener_res = L_add( ener_init, 0 );
482 201501 : ener_pit = L_add( ener_init, 0 );
483 :
484 3184061 : FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */
485 : {
486 2982560 : tmp_ex = mult_r( dct_pitex[j + freq], 8192 );
487 2982560 : tmp_res = mult_r( dct_res[j + freq], 8192 );
488 2982560 : corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/
489 2982560 : ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/
490 2982560 : ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/
491 : }
492 :
493 201501 : L_tmp1 = Mult_32_32( ener_res, ener_pit );
494 201501 : exp2 = norm_l( L_tmp1 );
495 201501 : L_tmp1 = L_shl( L_tmp1, exp2 );
496 201501 : exp_norm = sub( 30, exp2 );
497 201501 : L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm );
498 201501 : norm = extract_h( L_tmp1 ); /*15-exp_norm*/
499 201501 : L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm );
500 201501 : corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/
501 :
502 201501 : freq = add( freq, mfreq_bindiv_loc[i] );
503 : }
504 :
505 15091 : val_thrs = 8192;
506 15091 : move16(); /* 0.5 in Q14*/
507 : /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/
508 15091 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/
509 15091 : tmp = s_max( tmp, val_thrs ); /*Qnew */
510 :
511 15091 : corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
512 15091 : move16();
513 :
514 186410 : FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */
515 : {
516 171319 : L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q_new + 16 */
517 171319 : L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q_new + 16 */
518 :
519 171319 : tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q_new */
520 171319 : tmp = s_max( tmp, val_thrs ); /* Q_new */
521 :
522 171319 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
523 171319 : move16();
524 : }
525 15091 : tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/
526 15091 : tmp = s_max( tmp, val_thrs ); /* Q_new */
527 15091 : corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
528 15091 : move16();
529 :
530 15091 : Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); /* Q_new + 1 */
531 :
532 15091 : L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/
533 196183 : FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */
534 : {
535 181092 : L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); /* Q_new + 16 */
536 : }
537 15091 : av_corr = round_fx( L_tmp1 ); /*Qnew*/
538 :
539 : /* Find the cut-off freq similarly to HSX */
540 15091 : last_pit_band = 0;
541 15091 : move16();
542 15091 : av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/
543 :
544 15091 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
545 : {
546 : /*av_corr *= 1.25f;*/
547 2659 : av_corr = add( av_corr, shr( av_corr, 2 ) );
548 : }
549 15091 : test();
550 15091 : if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) )
551 : {
552 10442 : av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/
553 : }
554 15091 : min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/
555 :
556 201501 : FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
557 : {
558 186410 : ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/
559 :
560 186410 : IF( LT_16( ftmp, min_corr ) )
561 : {
562 32081 : last_pit_band = i;
563 32081 : move16();
564 32081 : min_corr = ftmp;
565 32081 : move16();
566 : }
567 : }
568 :
569 15091 : IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) )
570 : {
571 : DO
572 : {
573 60236 : last_pit_band = add( last_pit_band, 1 );
574 : }
575 60236 : WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) );
576 : }
577 15091 : if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) )
578 : {
579 4875 : last_pit_band = s_max( last_pit_band, 7 );
580 : }
581 15091 : test();
582 15091 : test();
583 15091 : test();
584 15091 : 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*/
585 : {
586 1336 : last_pit_band = 7 + BAND1k2;
587 1336 : move16();
588 : }
589 13755 : ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) )
590 : {
591 243 : last_pit_band = add( 10, BAND1k2 );
592 : }
593 :
594 15091 : time_flg = 0;
595 15091 : move16();
596 15091 : test();
597 15091 : test();
598 15091 : test();
599 15091 : test();
600 15091 : test();
601 15091 : test();
602 15091 : test();
603 15091 : test();
604 15091 : test();
605 15091 : test();
606 15091 : 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*/ ) )
607 : {
608 10249 : tmp_dec = 1;
609 10249 : move16();
610 : }
611 : ELSE
612 : {
613 4842 : tmp_dec = 0;
614 4842 : move16();
615 : }
616 :
617 : /* Different past and current decision */
618 15091 : test();
619 15091 : test();
620 15091 : test();
621 15091 : IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) )
622 : {
623 4469 : IF( *hangover == 0 )
624 : {
625 817 : time_flg = tmp_dec;
626 817 : move16();
627 817 : *hangover = HANGOVER_DELAY;
628 817 : move16();
629 : }
630 : ELSE
631 : {
632 3652 : time_flg = 0;
633 3652 : move16();
634 3652 : if ( hGSCEnc->mem_last_pit_band > 0 )
635 : {
636 2863 : time_flg = 1;
637 2863 : move16();
638 : }
639 :
640 3652 : ( *hangover ) = sub( ( *hangover ), 1 ); /* Q0 */
641 3652 : if ( *hangover < 0 )
642 : {
643 0 : *hangover = 0;
644 0 : move16();
645 : }
646 : }
647 : }
648 : ELSE
649 : {
650 10622 : time_flg = tmp_dec;
651 10622 : move16();
652 10622 : *hangover = HANGOVER_DELAY;
653 10622 : move16();
654 : }
655 :
656 : /* Decicison on final length of time contribution */
657 15091 : pit_contr_idx = 0;
658 15091 : move16();
659 15091 : test();
660 15091 : test();
661 15091 : IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech )
662 : {
663 12838 : test();
664 12838 : test();
665 : /*if(st_fx->core_brate <ACELP_9k60)*/
666 12838 : IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 /* 64 in Q6 */ ) )
667 : {
668 3336 : last_pit_band = add( 9, BAND1k2 );
669 3336 : if ( EQ_16( st_fx->bwidth, NB ) )
670 : {
671 0 : last_pit_band = add( 7, BAND1k2 );
672 : }
673 : }
674 9502 : ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 /* 128 in Q6 */ ) )
675 : {
676 2369 : last_pit_band = add( 5, BAND1k2 );
677 : }
678 7133 : ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
679 : {
680 1823 : last_pit_band = add( 3, BAND1k2 );
681 : }
682 5310 : ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) )
683 : {
684 728 : last_pit_band = add( BAND1k2, 1 );
685 : }
686 12838 : last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q15 */
687 12838 : move16();
688 :
689 12838 : st_fx->bpf_off = 0;
690 12838 : move16();
691 :
692 12838 : max_len = sub( st_fx->L_frame, last_pit_bin );
693 :
694 12838 : if ( EQ_16( st_fx->bwidth, NB ) )
695 : {
696 0 : max_len = sub( 160, last_pit_bin );
697 : }
698 :
699 12838 : Len = 80;
700 12838 : move16();
701 12838 : if ( LT_16( max_len, 80 ) )
702 : {
703 3571 : Len = max_len;
704 3571 : move16();
705 : }
706 12838 : test();
707 12838 : IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) )
708 : {
709 43 : move16(); /*ptr init*/
710 4022 : FOR( i = 0; i < max_len; i++ )
711 : {
712 3979 : dct_pitex[i + last_pit_bin] = 0;
713 3979 : move16();
714 : }
715 : }
716 : ELSE
717 : {
718 :
719 980836 : FOR( i = 0; i < Len; i++ )
720 : {
721 968041 : dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */
722 : }
723 668573 : FOR( ; i < max_len; i++ )
724 : {
725 655778 : dct_pitex[i + last_pit_bin] = 0;
726 655778 : move16();
727 : }
728 : }
729 12838 : hGSCEnc->mem_last_pit_band = last_pit_band;
730 12838 : move16();
731 12838 : pit_contr_idx = sub( last_pit_band, BAND1k2 );
732 : }
733 : ELSE
734 : {
735 2253 : set16_fx( dct_pitex, 0, st_fx->L_frame );
736 2253 : st_fx->bpf_off = 1;
737 2253 : move16();
738 2253 : last_pit_bin = 0;
739 2253 : move16();
740 2253 : last_pit_band = 0;
741 2253 : move16();
742 2253 : pit_contr_idx = 0;
743 2253 : move16();
744 2253 : hGSCEnc->mem_last_pit_band = 0;
745 2253 : move16();
746 :
747 2253 : set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k );
748 : /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */
749 678153 : FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ )
750 : {
751 675900 : delete_indice( hBstr, i );
752 : }
753 2253 : delete_indice( hBstr, IND_ES_PRED );
754 : }
755 15091 : IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) )
756 : {
757 9721 : IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
758 : {
759 7656 : if ( pit_contr_idx > 0 )
760 : {
761 7528 : pit_contr_idx = 1;
762 7528 : move16();
763 : }
764 :
765 7656 : IF( EQ_16( st_fx->coder_type, INACTIVE ) )
766 : {
767 324 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 );
768 : }
769 : }
770 : ELSE
771 : {
772 2065 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 );
773 : }
774 : }
775 : ELSE
776 : {
777 5370 : push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 );
778 : }
779 :
780 15091 : return last_pit_bin;
781 : }
|