Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdint.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h"
8 : #include "rom_com.h"
9 : #include "prot_fx.h"
10 : #include "ivas_cnst.h"
11 :
12 : /*Temporary location to be move in prot* when merge is done*/
13 : void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m );
14 : void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m );
15 :
16 : /*-----------------------------------------------------------------*
17 : * Local function prototypes
18 : *-----------------------------------------------------------------*/
19 :
20 : static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn );
21 :
22 : static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn );
23 :
24 : /*-----------------------------------------------------------------*
25 : * CNG_dec_fx()
26 : *
27 : * Decode residual signal energy
28 : *-----------------------------------------------------------------*/
29 :
30 2378 : void CNG_dec_fx(
31 : Decoder_State *st_fx, /* i/o: State structure */
32 : const Word16 last_element_mode, /* i : last element mode Q0 */
33 : Word16 Aq[], /* o : LP coefficients Q12 */
34 : Word16 *lsp_new, /* i/o: current frame LSPs Q15 */
35 : Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */
36 : Word16 *allow_cn_step, /* o : allow CN step Q0 */
37 : Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */
38 : Word32 *q_env )
39 : {
40 : Word16 istep;
41 : Word16 i, L_enr_index;
42 : Word32 L_ener;
43 : Word16 ener_fra, ener_int;
44 : Word16 num_bits;
45 : Word16 weights, ptr, j, k;
46 : Word16 m1;
47 2378 : Word16 m = 0;
48 2378 : move16();
49 : Word16 tmp[HO_HIST_SIZE * M];
50 2378 : Word16 burst_ho_cnt = 0;
51 2378 : move16();
52 : Word16 ll, s_ptr;
53 : Word32 L_enr, L_tmp1;
54 : Word16 tmp1, exp;
55 : Word16 lsf_tmp[M];
56 : Word32 C[M];
57 : Word32 max_val[2];
58 : Word16 max_idx[2];
59 : Word16 ftmp_fx;
60 : Word16 lsp_tmp[M];
61 : Word16 dev;
62 : Word16 max_dev;
63 : Word16 dist;
64 : Word16 tmpv;
65 : Word16 env_idx[2];
66 : Word32 enr1;
67 : Word32 env[NUM_ENV_CNG];
68 : Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG];
69 : Word32 L_tmp;
70 : Word16 fra;
71 : Word16 temp_lo_fx, temp_hi_fx;
72 : Word16 exp_pow;
73 : Word16 tmp_loop;
74 : Word16 enr_new, Aq_tmp[M + 1];
75 : Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */
76 : TD_CNG_DEC_HANDLE hTdCngDec;
77 : #ifndef ISSUE_1866_replace_overflow_libdec
78 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
79 : Flag Overflow = 0;
80 : move32();
81 : #endif
82 : #endif
83 2378 : hTdCngDec = st_fx->hTdCngDec;
84 :
85 2378 : m = 0;
86 2378 : move16();
87 : /*-----------------------------------------------------------------*
88 : * Decode CNG spectral envelope (only in SID frame)
89 : *-----------------------------------------------------------------*/
90 2378 : test();
91 2378 : IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) )
92 : {
93 : /* de-quantize the LSF vector */
94 417 : IF( st_fx->Opt_AMR_WB != 0 )
95 : {
96 : /* Flt function */
97 0 : isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new );
98 : /* check IF ISPs may trigger too much synthesis energy */
99 :
100 0 : E_LPC_f_isp_a_conversion( lsp_new, Aq_tmp, M );
101 0 : enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR );
102 :
103 0 : IF( ( shr( enr_new, 14 ) > 0 ) )
104 : {
105 : /* Use old LSP vector */
106 0 : Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */
107 0 : Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */
108 : }
109 : }
110 : ELSE
111 : {
112 417 : lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, NULL );
113 :
114 : /* check IF LSPs may trigger too much synthesis energy */
115 417 : E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M );
116 417 : enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR );
117 :
118 417 : IF( shr( enr_new, 14 ) > 0 )
119 : {
120 : /* Use old LSP vector */
121 0 : Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */
122 0 : Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */
123 : }
124 : }
125 : }
126 : ELSE
127 : {
128 : /* Use old LSP vector */
129 1961 : Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */
130 1961 : Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */
131 : }
132 :
133 : /* Initialize the CNG spectral envelope in case of the very first CNG frame */
134 2378 : IF( st_fx->first_CNG == 0 )
135 : {
136 28 : Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); /* Q15 */
137 : }
138 :
139 : /*-----------------------------------------------------------------*
140 : * Decode residual signal energy
141 : *-----------------------------------------------------------------*/
142 :
143 2378 : *allow_cn_step = 0;
144 2378 : move16();
145 2378 : test();
146 2378 : IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) )
147 : {
148 417 : istep = ISTEP_AMR_WB_SID_FX; /* Q15 */
149 417 : move16();
150 417 : if ( EQ_32( st_fx->core_brate, SID_2k40 ) )
151 : {
152 417 : istep = ISTEP_SID_FX; /* Q15 */
153 417 : move16();
154 : }
155 :
156 : /* initialize the energy quantization parameters */
157 417 : num_bits = 6;
158 417 : move16();
159 417 : if ( st_fx->Opt_AMR_WB == 0 )
160 : {
161 417 : num_bits = 7;
162 417 : move16();
163 : }
164 :
165 : /* decode the energy index */
166 417 : L_enr_index = get_next_indice_fx( st_fx, num_bits );
167 :
168 417 : IF( LE_32( st_fx->last_core_brate, SID_2k40 ) || EQ_16( st_fx->prev_bfi, 1 ) )
169 : {
170 228 : tmp1 = add( hTdCngDec->old_enr_index, 20 );
171 : }
172 : ELSE
173 : {
174 189 : tmp1 = add( hTdCngDec->old_enr_index, 40 );
175 : }
176 417 : IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */
177 : {
178 0 : L_enr_index = tmp1;
179 0 : move16();
180 0 : L_enr_index = s_min( L_enr_index, 127 ); /* Q0 */
181 0 : IF( st_fx->Opt_AMR_WB )
182 : {
183 0 : L_enr_index = s_min( L_enr_index, 63 ); /* Q0 */
184 : }
185 : }
186 :
187 417 : test();
188 417 : test();
189 417 : test();
190 417 : IF( GT_32( st_fx->last_core_brate, SID_1k75 ) &&
191 : NE_16( st_fx->first_CNG, 0 ) &&
192 : GE_16( hTdCngDec->old_enr_index, 0 ) &&
193 : GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) )
194 : {
195 0 : *allow_cn_step = 1;
196 0 : move16();
197 : }
198 :
199 417 : hTdCngDec->old_enr_index = L_enr_index;
200 417 : move16();
201 417 : if ( !L_enr_index )
202 : {
203 18 : L_enr_index = -5;
204 18 : move16();
205 : }
206 : /* st_fx->Enew = L_enr_index / step - 2.0f;*/
207 417 : L_ener = L_mult( L_enr_index, istep ); /* Q16 (0+15) */
208 : /* subtract by 2 not done to leave Energy in Q2 */
209 :
210 : /* extract integral and fractional parts */
211 417 : ener_fra = L_Extract_lc( L_ener, &ener_int );
212 417 : ener_int = add( ener_int, 4 ); /* Q2 to Q6 */
213 :
214 : /* find the new energy value */
215 417 : hTdCngDec->Enew_fx = Pow2( ener_int, ener_fra );
216 417 : move32();
217 :
218 417 : IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
219 : {
220 417 : burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */
221 :
222 417 : *sid_bw = get_next_indice_fx( st_fx, 1 );
223 417 : move16();
224 417 : IF( *sid_bw == 0 )
225 : {
226 0 : env_idx[0] = get_next_indice_fx( st_fx, 6 );
227 0 : move16();
228 :
229 : /* get quantized res_env_details */
230 0 : FOR( i = 0; i < NUM_ENV_CNG; i++ )
231 : {
232 0 : q_env[i] = L_deposit_l( CNG_details_codebook_fx[env_idx[0]][i] );
233 0 : move32();
234 : }
235 : }
236 : }
237 : /* Reset CNG history IF CNG frame length is changed */
238 417 : test();
239 417 : test();
240 417 : IF( EQ_16( st_fx->bwidth, WB ) && NE_16( st_fx->first_CNG, 0 ) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) )
241 : {
242 1 : hTdCngDec->ho_hist_size = 0;
243 1 : move16();
244 : }
245 : }
246 :
247 : /*---------------------------------------------------------------------*
248 : * CNG spectral envelope update
249 : * Find A(z) coefficients
250 : *---------------------------------------------------------------------*/
251 2378 : test();
252 2378 : test();
253 2378 : test();
254 2378 : IF( LE_32( st_fx->last_core_brate, SID_2k40 ) )
255 : {
256 : /* Reset hangover counter if not first SID period */
257 2189 : if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) )
258 : {
259 228 : hTdCngDec->num_ho = 0;
260 228 : move16();
261 : }
262 : /* Update LSPs IF last SID energy not outliers or insufficient number of hangover frames */
263 2189 : test();
264 2189 : IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) )
265 : {
266 36669 : FOR( i = 0; i < M; i++ )
267 : {
268 : /* AR low-pass filter */
269 34512 : st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] );
270 34512 : move16(); /* Q15 (15+15+1-16) */
271 : }
272 : }
273 : }
274 : ELSE
275 : {
276 : /* Update CNG_mode IF allowed */
277 189 : test();
278 189 : test();
279 189 : test();
280 189 : IF( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !st_fx->first_CNG || GE_16( hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) )
281 : {
282 6 : IF( GT_32( st_fx->last_active_brate, ACELP_16k40 ) )
283 : {
284 3 : st_fx->CNG_mode = -1;
285 3 : move16();
286 : }
287 : ELSE
288 : {
289 3 : st_fx->CNG_mode = get_cng_mode( st_fx->last_active_brate );
290 3 : move16();
291 : }
292 : }
293 :
294 : /* If first sid after active burst update LSF history from circ buffer */
295 189 : burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX Q0*/
296 189 : hTdCngDec->act_cnt = 0;
297 189 : move16();
298 189 : s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 );
299 189 : IF( s_ptr < 0 )
300 : {
301 34 : s_ptr = add( s_ptr, hTdCngDec->ho_circ_size );
302 : }
303 :
304 478 : FOR( ll = burst_ho_cnt; ll > 0; ll-- )
305 : {
306 289 : hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); /* Q0 */
307 289 : move16();
308 289 : if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) )
309 : {
310 25 : hTdCngDec->ho_hist_ptr = 0;
311 25 : move16();
312 : }
313 :
314 : /* Conversion between 12.8k and 16k LSPs */
315 289 : test();
316 289 : test();
317 289 : test();
318 289 : IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) )
319 : {
320 : /* Conversion from 16k LPSs to 12k8 */
321 61 : lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 );
322 : }
323 : /* update the circular buffers */
324 289 : Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); /* Qx */
325 289 : Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); /* Q6 */
326 289 : hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 );
327 289 : move32();
328 289 : Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Qx */
329 :
330 289 : hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 );
331 289 : move16();
332 :
333 289 : if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) )
334 : {
335 32 : hTdCngDec->ho_hist_size = HO_HIST_SIZE;
336 32 : move16();
337 : }
338 :
339 289 : s_ptr = add( s_ptr, 1 );
340 289 : if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) )
341 : {
342 36 : s_ptr = 0;
343 36 : move16();
344 : }
345 : }
346 :
347 189 : IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */
348 : {
349 : /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/
350 137 : L_tmp1 = L_shr( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 );
351 137 : L_tmp1 = L_sub( L_tmp1, st_fx->lp_ener_fx );
352 :
353 137 : test();
354 137 : test();
355 137 : IF( ( L_tmp1 > 0 && ( st_fx->first_CNG || st_fx->element_mode == EVS_MONO ) ) )
356 : {
357 8 : *allow_cn_step = s_or( *allow_cn_step, 1 );
358 8 : move16();
359 : }
360 : }
361 189 : IF( EQ_16( last_element_mode, IVAS_CPE_TD ) )
362 : {
363 15 : *allow_cn_step = 1;
364 15 : move16();
365 : }
366 189 : test();
367 189 : IF( EQ_16( *allow_cn_step, 0 ) && GT_16( hTdCngDec->ho_hist_size, 0 ) )
368 : {
369 : /* Use average of energies below last energy */
370 122 : ptr = hTdCngDec->ho_hist_ptr;
371 122 : move16();
372 122 : Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); /* Qx */
373 122 : m1 = 0;
374 122 : move16();
375 122 : IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 )
376 : {
377 77 : Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG );
378 77 : m1 = 1;
379 77 : move16();
380 : }
381 122 : L_enr = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */
382 :
383 122 : weights = W_DTX_HO_FX[0]; /* Q15 */
384 122 : move16();
385 :
386 122 : m = 1;
387 122 : move16();
388 531 : FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ )
389 : {
390 409 : ptr--;
391 409 : if ( ptr < 0 )
392 : {
393 22 : ptr = HO_HIST_SIZE - 1;
394 22 : move16();
395 : }
396 :
397 409 : test();
398 409 : IF( LT_32( Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ) &&
399 : GT_32( hTdCngDec->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], BUF_L_NRG_FX ) ) )
400 : {
401 : /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/
402 185 : L_tmp1 = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */
403 185 : L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */
404 :
405 : /*weights += W_DTX_HO[k];*/
406 185 : weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */
407 :
408 185 : Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); /* Qx */
409 185 : IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) )
410 : {
411 122 : Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); /* Qx */
412 122 : m1++;
413 : }
414 185 : m++;
415 : }
416 : }
417 :
418 : /*enr /= weights;*/
419 122 : exp = norm_s( weights );
420 122 : tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */
421 122 : L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */
422 122 : L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */
423 :
424 122 : st_fx->lp_ener_fx = L_enr; /* Q6 */
425 122 : move32();
426 122 : set32_fx( max_val, 0, 2 );
427 122 : set16_fx( max_idx, 0, 2 );
428 :
429 429 : FOR( i = 0; i < m; i++ )
430 : {
431 307 : IF( EQ_16( st_fx->L_frame, L_FRAME ) )
432 : {
433 201 : lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX );
434 201 : ftmp_fx = 964;
435 201 : move16(); /*X2.56 */
436 201 : tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/
437 201 : L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/
438 : }
439 : ELSE
440 : {
441 106 : lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX );
442 106 : ftmp_fx = 1205;
443 106 : move16(); /*QX2.56*/
444 106 : tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/
445 106 : L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/
446 : }
447 :
448 307 : tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/
449 307 : L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/
450 4912 : FOR( j = 0; j < M - 1; j++ )
451 : {
452 4605 : tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/
453 4605 : L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/
454 : }
455 :
456 307 : C[i] = Mpy_32_16_1( L_tmp, 1928 ); /*QX6.5536*/
457 307 : move32();
458 :
459 307 : IF( GT_32( C[i], max_val[0] ) )
460 : {
461 220 : max_val[1] = max_val[0];
462 220 : move32();
463 220 : max_idx[1] = max_idx[0];
464 220 : move16();
465 220 : max_val[0] = C[i];
466 220 : move32();
467 220 : max_idx[0] = i;
468 220 : move16();
469 : }
470 87 : ELSE IF( GT_32( C[i], max_val[1] ) )
471 : {
472 49 : max_val[1] = C[i];
473 49 : move32();
474 49 : max_idx[1] = i;
475 49 : move16();
476 : }
477 : }
478 :
479 122 : IF( EQ_16( m, 1 ) )
480 : {
481 42 : Copy( tmp, lsp_tmp, M ); /* Qx */
482 : }
483 80 : ELSE IF( LT_16( m, 4 ) )
484 : {
485 1020 : FOR( i = 0; i < M; i++ )
486 : {
487 960 : L_tmp1 = 0;
488 960 : move32();
489 3504 : FOR( j = 0; j < m; j++ )
490 : {
491 2544 : L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) );
492 : }
493 :
494 960 : L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) );
495 960 : tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/
496 960 : L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/
497 960 : lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/
498 960 : move16();
499 : }
500 : }
501 : ELSE
502 : {
503 340 : FOR( i = 0; i < M; i++ )
504 : {
505 320 : L_tmp1 = 0;
506 320 : move32();
507 2016 : FOR( j = 0; j < m; j++ )
508 : {
509 1696 : L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) );
510 : }
511 :
512 320 : L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/
513 320 : tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/
514 320 : L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/
515 320 : lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/
516 320 : move16();
517 : }
518 : }
519 :
520 122 : dist = 0;
521 122 : move16(); /*Q15*/
522 122 : max_dev = 0;
523 122 : move16(); /*Q15*/
524 2074 : FOR( i = 0; i < M; i++ )
525 : {
526 1952 : dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/
527 : #ifdef ISSUE_1866_replace_overflow_libdec
528 1952 : dist = add_sat( dist, dev ); /*Q15*/
529 : #else
530 : dist = add_o( dist, dev, &Overflow ); /*Q15*/
531 : #endif
532 1952 : if ( GT_16( dev, max_dev ) )
533 : {
534 610 : max_dev = dev;
535 610 : move16();
536 : }
537 : }
538 :
539 122 : test();
540 122 : IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) /* 0.4 and 0.1 in Q15 */
541 : {
542 34 : FOR( i = 0; i < M; i++ )
543 : {
544 32 : st_fx->lspCNG_fx[i] = lsp_tmp[i];
545 32 : move16(); /*Q15*/
546 : }
547 : }
548 : ELSE
549 : {
550 2040 : FOR( i = 0; i < M; i++ )
551 : {
552 : /* AR low-pass filter */
553 1920 : st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); /* Q15 */
554 1920 : move16();
555 : }
556 : }
557 122 : IF( m1 > 0 )
558 : {
559 1953 : FOR( i = 0; i < NUM_ENV_CNG; i++ )
560 : {
561 1860 : L_tmp = L_deposit_l( 0 );
562 5840 : FOR( j = 0; j < m1; j++ )
563 : {
564 : /* env[i] += tmp_env[j*NUM_ENV_CNG+i];*/
565 3980 : L_tmp = L_add_sat( L_tmp, tmp_env[j * NUM_ENV_CNG + i] );
566 : }
567 : /* env[i] /= (float)m1; */
568 : /* env[i] = env[i] - 2*st_fx->lp_ener_fx; */
569 1860 : IF( EQ_16( m1, 1 ) )
570 : {
571 680 : L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */
572 : }
573 : ELSE
574 : {
575 1180 : tmp1 = div_s( 1, m1 );
576 1180 : L_tmp = Mult_32_16( L_tmp, tmp1 ); /* Q6 */
577 1180 : L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */
578 : }
579 1860 : env[i] = L_tmp; /* Q6 */
580 1860 : move32();
581 : }
582 :
583 93 : Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); /* Q6 */
584 : }
585 : }
586 : ELSE
587 : {
588 67 : Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */
589 : }
590 : }
591 :
592 2378 : test();
593 2378 : IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) )
594 : {
595 : /* Update hangover memory during CNG */
596 417 : test();
597 417 : IF( ( *allow_cn_step == 0 ) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) )
598 : {
599 : /* update the pointer to circular buffer of old LSP vectors */
600 285 : hTdCngDec->ho_hist_ptr++;
601 285 : move16();
602 285 : if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) )
603 : {
604 34 : hTdCngDec->ho_hist_ptr = 0;
605 34 : move16();
606 : }
607 :
608 : /* update the circular buffer of old LSP vectors with the new LSP vector */
609 285 : Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); /* Q15 */
610 :
611 : /* update the hangover energy buffer */
612 285 : hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; /* Q6 */
613 285 : move32();
614 285 : test();
615 285 : IF( EQ_32( st_fx->core_brate, SID_2k40 ) && ( *sid_bw == 0 ) )
616 : {
617 : /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/
618 0 : exp = norm_l( hTdCngDec->Enew_fx );
619 0 : L_tmp = L_shl( hTdCngDec->Enew_fx, exp ); /*Q(exp+6)*/
620 0 : L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /*Q(exp+6+5-15=exp-4)*/
621 0 : L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /*Q6*/
622 0 : exp = norm_l( L_tmp );
623 0 : fra = Log2_norm_lc( L_shl( L_tmp, exp ) );
624 0 : exp = sub( sub( 30, exp ), 6 );
625 0 : L_tmp = L_Comp( exp, fra );
626 0 : enr1 = L_shr( L_tmp, 10 ); /* Q6 */
627 :
628 0 : FOR( i = 0; i < NUM_ENV_CNG; i++ )
629 : {
630 : /* get quantized envelope */
631 : /* env[i] = pow(2.0f,(enr1 - q_env[i])) + 2*st->Enew;*/
632 0 : L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */
633 0 : L_tmp = L_shl( L_tmp, 10 ); /* 16 */
634 0 : temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx );
635 :
636 0 : exp_pow = sub( 14, temp_hi_fx );
637 0 : L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */
638 0 : env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); /* Q6 */
639 0 : move32();
640 0 : L_tmp = L_add( hTdCngDec->Enew_fx, hTdCngDec->Enew_fx );
641 0 : env[i] = L_add( env[i], L_tmp ); /* Q6 */
642 0 : move32();
643 : }
644 0 : hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */
645 0 : move32();
646 0 : Copy32( env, &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Q6 */
647 : }
648 285 : ELSE IF( ( *sid_bw != 0 ) )
649 : {
650 285 : hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */
651 285 : move32();
652 285 : hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); /* Q0 */
653 285 : move32();
654 : }
655 :
656 285 : hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 );
657 285 : move16();
658 285 : if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) )
659 : {
660 169 : hTdCngDec->ho_hist_size = HO_HIST_SIZE;
661 169 : move16();
662 : }
663 : }
664 : /* Update the frame length memory */
665 417 : st_fx->last_CNG_L_frame = st_fx->L_frame;
666 417 : move16();
667 :
668 417 : if ( NE_32( st_fx->core_brate, SID_1k75 ) )
669 : {
670 417 : hTdCngDec->num_ho = m;
671 417 : move16();
672 : }
673 : }
674 :
675 2378 : IF( st_fx->element_mode == EVS_MONO )
676 : {
677 0 : st_fx->last_CNG_L_frame = st_fx->L_frame;
678 0 : move16();
679 :
680 0 : IF( NE_32( st_fx->core_brate, SID_1k75 ) )
681 : {
682 0 : hTdCngDec->num_ho = m;
683 0 : move16();
684 : }
685 : }
686 2378 : IF( st_fx->Opt_AMR_WB )
687 : {
688 0 : E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M );
689 : }
690 : ELSE
691 : {
692 2378 : E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M );
693 : }
694 :
695 2378 : tmp_loop = shr( st_fx->L_frame, 6 );
696 11044 : FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */
697 : {
698 8666 : Copy( Aq, &Aq[i * ( M + 1 )], add( M, 1 ) ); /* Q12 */
699 : }
700 :
701 2378 : return;
702 : }
703 :
704 : /*---------------------------------------------------------------------*
705 : * swb_CNG_dec()
706 : *
707 : * Comfort noise generation for SHB signal
708 : *---------------------------------------------------------------------*/
709 :
710 1850 : void swb_CNG_dec_fx(
711 : Decoder_State *st_fx, /* i/o: State structure */
712 : const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/
713 : Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/
714 : const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/
715 : const Word16 Qsyn /* i : Q value of ACELP core synthesis */
716 : )
717 : {
718 1850 : test();
719 1850 : IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) )
720 : {
721 : /* SHB SID decoding and CNG */
722 0 : test();
723 0 : IF( EQ_16( st_fx->cng_type, LP_CNG ) && EQ_16( st_fx->extl, SWB_CNG ) )
724 : {
725 0 : shb_CNG_decod_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn );
726 : }
727 0 : st_fx->last_vad_fx = 0;
728 0 : move16();
729 0 : st_fx->hTdCngDec->burst_cnt_fx = 0;
730 0 : move16();
731 : }
732 : ELSE
733 : {
734 1850 : st_fx->last_vad_fx = 1;
735 1850 : move16();
736 1850 : st_fx->hTdCngDec->burst_cnt_fx = add( st_fx->hTdCngDec->burst_cnt_fx, 1 );
737 1850 : move16();
738 1850 : if ( GT_16( st_fx->hTdCngDec->burst_cnt_fx, 10 ) )
739 : {
740 166 : st_fx->hTdCngDec->burst_cnt_fx = 0;
741 166 : move16();
742 : }
743 : }
744 :
745 1850 : return;
746 : }
747 :
748 217481 : void swb_CNG_dec_ivas_fx(
749 : Decoder_State *st_fx, /* i/o: State structure */
750 : const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/
751 : Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/
752 : const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/
753 : const Word16 Qsyn /* i : Q value of ACELP core synthesis */
754 : )
755 : {
756 217481 : test();
757 217481 : IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) )
758 : {
759 : /* SHB SID decoding and CNG */
760 12817 : test();
761 12817 : IF( EQ_16( st_fx->cng_type, LP_CNG ) && EQ_16( st_fx->extl, SWB_CNG ) )
762 : {
763 1788 : shb_CNG_decod_ivas_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn );
764 : }
765 12817 : st_fx->last_vad_fx = 0;
766 12817 : move16();
767 12817 : st_fx->hTdCngDec->burst_cnt_fx = 0;
768 12817 : move16();
769 : }
770 : ELSE
771 : {
772 204664 : st_fx->last_vad_fx = 1;
773 204664 : move16();
774 204664 : st_fx->hTdCngDec->burst_cnt_fx = add_sat( st_fx->hTdCngDec->burst_cnt_fx, 1 ); // saturation reached?
775 204664 : move16();
776 204664 : if ( GT_16( st_fx->hTdCngDec->burst_cnt_fx, 10 ) )
777 : {
778 17670 : st_fx->hTdCngDec->burst_cnt_fx = 0;
779 17670 : move16();
780 : }
781 : }
782 :
783 217481 : return;
784 : }
785 :
786 : /*---------------------------------------------------------------------*
787 : * shb_CNG_decod()
788 : *
789 : * Main routine of SHB SID decoding and CNG
790 : *---------------------------------------------------------------------*/
791 :
792 0 : static void shb_CNG_decod_fx(
793 : Decoder_State *st_fx, /* i/o: State structure */
794 : const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/
795 : Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/
796 : const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/
797 : const Word16 Qsyn /* i : Q value of ACELP core synthesis */
798 : )
799 : {
800 : Word16 i;
801 : Word16 idx_ener_fx;
802 : TD_CNG_DEC_HANDLE hTdCngDec;
803 : Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1];
804 : Word16 shb_lspCNG_fx[LPC_SHB_ORDER];
805 : Word16 excTmp_fx[L_FRAME16k];
806 : Word16 excSHB_fx[L_FRAME16k];
807 : Word16 tmp_lsp[LPC_SHB_ORDER];
808 : Word16 ener_excSHB_fx;
809 : Word32 wb_ener_fx;
810 : Word16 wb_ener16_fx;
811 : Word32 L_gain_fx;
812 : Word16 gain_fx;
813 : Word16 shb_syn16k_fx[L_FRAME16k];
814 : Word16 tmp;
815 : Word16 step_fx;
816 : Word16 interp_fx;
817 : Word16 ener_fx;
818 : Word16 exp, exp1;
819 : Word16 fra;
820 : Word32 L_tmp;
821 : Word16 tmp2;
822 0 : Word16 allow_cn_step_fx = 0;
823 0 : move16();
824 : Word16 q;
825 : TD_BWE_DEC_HANDLE hBWE_TD;
826 :
827 0 : hBWE_TD = st_fx->hBWE_TD;
828 0 : hTdCngDec = st_fx->hTdCngDec;
829 :
830 0 : IF( st_fx->bfi == 0 )
831 : {
832 0 : test();
833 0 : IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) )
834 : {
835 0 : idx_ener_fx = get_next_indice_fx( st_fx, 4 );
836 :
837 0 : if ( !idx_ener_fx )
838 : {
839 0 : idx_ener_fx = -15;
840 0 : move16();
841 : }
842 0 : IF( st_fx->element_mode == EVS_MONO )
843 : {
844 : /* de-quantization of SHB CNG parameters */
845 0 : L_tmp = L_mult( idx_ener_fx, 27400 ); /*Q14 */
846 0 : hTdCngDec->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 295924 ), 6 ) ); /*Q8 */
847 0 : move16();
848 : }
849 : ELSE
850 : {
851 : }
852 : }
853 : }
854 :
855 : /* SHB spectrum estimation */
856 :
857 :
858 0 : interp_fx = s_min( hTdCngDec->shb_dtx_count_fx, 32 );
859 0 : interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/
860 0 : FOR( i = 0; i < LPC_SHB_ORDER; i++ )
861 : {
862 0 : tmp2 = mult( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ); /*Q14*/
863 0 : tmp = mult( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ); /*Q14*/
864 0 : shb_lspCNG_fx[i] = add( tmp2, tmp );
865 0 : move16(); /*Q14*/
866 : }
867 :
868 0 : IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) )
869 : {
870 0 : if ( LT_16( hTdCngDec->shb_dtx_count_fx, 1000 ) )
871 : {
872 0 : hTdCngDec->shb_dtx_count_fx = add( hTdCngDec->shb_dtx_count_fx, 1 );
873 0 : move16();
874 : }
875 : }
876 0 : E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/
877 0 : E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER );
878 :
879 0 : Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */
880 :
881 : /* SHB energy estimation */
882 0 : wb_ener_fx = L_deposit_l( 1 ); /*Q1 */
883 0 : FOR( i = 0; i < L_FRAME32k; i++ )
884 : {
885 0 : wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */
886 : }
887 0 : exp = norm_l( wb_ener_fx );
888 0 : fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) );
889 0 : exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) );
890 0 : wb_ener_fx = Mpy_32_16( exp, fra, LG10 );
891 0 : wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */
892 0 : if ( !st_fx->first_CNG )
893 : {
894 0 : hTdCngDec->wb_cng_ener_fx = wb_ener16_fx;
895 0 : move16(); /*Q8 */
896 : }
897 0 : if ( GT_16( abs_s( sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ) ), 3072 ) )
898 : {
899 0 : allow_cn_step_fx = 1;
900 0 : move16();
901 : }
902 :
903 0 : IF( EQ_16( allow_cn_step_fx, 1 ) )
904 : {
905 0 : hTdCngDec->wb_cng_ener_fx = wb_ener16_fx;
906 0 : move16(); /*Q8 */
907 : }
908 : ELSE
909 : {
910 0 : tmp = sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ); /*Q8 */
911 0 : tmp = mult_r( tmp, 29491 ); /*Q8 */
912 0 : hTdCngDec->wb_cng_ener_fx = add( hTdCngDec->wb_cng_ener_fx, tmp ); /*Q8 */
913 0 : move16();
914 : }
915 0 : test();
916 0 : test();
917 0 : IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && ( st_fx->bfi == 0 ) )
918 : {
919 0 : hTdCngDec->last_wb_cng_ener_fx = hTdCngDec->wb_cng_ener_fx;
920 0 : move16();
921 :
922 0 : if ( !st_fx->first_CNG )
923 : {
924 0 : hTdCngDec->shb_cng_ener_fx = hTdCngDec->last_shb_cng_ener_fx;
925 0 : move16();
926 : }
927 : }
928 :
929 0 : gain_fx = sub( hTdCngDec->wb_cng_ener_fx, hTdCngDec->last_wb_cng_ener_fx ); /* Q8 */
930 0 : if ( GT_16( gain_fx, 15 ) )
931 : {
932 0 : gain_fx = 15;
933 0 : move16();
934 : }
935 0 : step_fx = sub( add( gain_fx, hTdCngDec->last_shb_cng_ener_fx ), hTdCngDec->shb_cng_ener_fx ); /*Q8 */
936 0 : test();
937 0 : IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st_fx->last_core_brate, SID_2k40 ) )
938 : {
939 0 : hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, step_fx ); /* Q8 */
940 0 : move16();
941 : }
942 : ELSE
943 : {
944 0 : hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, mult( 8192, step_fx ) ); /*Q8 */
945 0 : move16();
946 : }
947 : /* generate white noise excitation */
948 0 : FOR( i = 0; i < L_FRAME16k; i++ )
949 : {
950 0 : excTmp_fx[i] = shr_r( Random( &hTdCngDec->swb_cng_seed ), 8 );
951 0 : move16(); /*Q-8*/
952 : }
953 :
954 : /* synthesis filtering */
955 0 : Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, hBWE_TD->state_lpc_syn_fx, 1 );
956 :
957 :
958 : /* synthesis signal gain shaping */
959 0 : L_tmp = 0;
960 0 : move32();
961 0 : FOR( i = 0; i < L_FRAME16k; i++ )
962 : {
963 0 : L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/
964 : }
965 0 : q = norm_l( L_tmp );
966 0 : L_tmp = L_shl( L_tmp, q );
967 0 : q = sub( q, 32 );
968 0 : ener_excSHB_fx = round_fx( L_tmp ); /*Qq */
969 0 : IF( EQ_16( st_fx->last_vad_fx, 1 ) )
970 : {
971 0 : hTdCngDec->trans_cnt_fx = 0;
972 0 : move16();
973 0 : test();
974 0 : IF( GT_16( hTdCngDec->burst_cnt_fx, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) )
975 : {
976 0 : hTdCngDec->trans_cnt_fx = 5;
977 0 : move16();
978 : }
979 : }
980 :
981 0 : ener_fx = hTdCngDec->shb_cng_ener_fx;
982 0 : move16(); /*Q8 */
983 0 : IF( hTdCngDec->trans_cnt_fx > 0 )
984 : {
985 0 : i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */
986 0 : ener_fx = add_sat( hTdCngDec->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( hTdCngDec->last_shb_ener_fx, hTdCngDec->shb_cng_ener_fx ) ) ); /*Q8 */
987 0 : hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 );
988 0 : move16();
989 : }
990 :
991 0 : tmp = mult( 3277, ener_fx ); /*Q8 */
992 0 : L_tmp = L_mult( 27213, tmp ); /*Q22, 27213=3.321928 in Q13 */
993 0 : L_tmp = L_shr( L_tmp, 6 ); /*Q16 */
994 0 : L_tmp = L_add( L_tmp, 10 << 16 );
995 0 : if ( L_tmp < 0 )
996 : {
997 0 : L_tmp = 0;
998 0 : move32();
999 : }
1000 0 : fra = L_Extract_lc( L_tmp, &exp );
1001 0 : L_tmp = L_shl_sat( Pow2( exp, fra ), 5 ); /*Q5 */
1002 0 : L_tmp = L_shr( L_tmp, 10 );
1003 0 : if ( !L_tmp )
1004 : {
1005 0 : L_tmp = 1; /*Q5 */
1006 : }
1007 0 : exp = norm_l( L_tmp );
1008 0 : L_tmp = L_shl( L_tmp, exp ); /*Q31*/
1009 0 : tmp = extract_h( L_tmp ); /*Q15*/
1010 0 : exp = sub( exp, 16 );
1011 0 : exp1 = norm_s( ener_excSHB_fx );
1012 0 : fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/
1013 :
1014 0 : IF( GT_16( fra, tmp ) )
1015 : {
1016 0 : fra = shr( fra, 1 ); /*Q15*/
1017 0 : exp1 = sub( exp1, 1 );
1018 : }
1019 0 : tmp = div_s( fra, tmp ); /*Q15*/
1020 :
1021 0 : L_tmp = L_deposit_h( tmp ); /*Q31 */
1022 0 : tmp = sub( add( 5, exp ), add( q, exp1 ) );
1023 0 : L_gain_fx = Isqrt_lc( L_tmp, &tmp ); /*Q31-Qtmp */
1024 :
1025 0 : FOR( i = 0; i < L_FRAME16k; i++ )
1026 : {
1027 0 : shb_syn16k_fx[i] = extract_l( L_shr( Mpy_32_16_1( L_gain_fx, excSHB_fx[i] ), sub( 5, tmp ) ) ); /*Q3 = 31-Qtmp-8-15-5+Qtmp */
1028 0 : move16();
1029 : }
1030 :
1031 0 : test();
1032 0 : IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) )
1033 : {
1034 : /* rescale the Hilbert memories to Q0 */
1035 0 : FOR( i = 0; i < HILBERT_MEM_SIZE; i++ )
1036 : {
1037 0 : hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */
1038 0 : move32();
1039 : }
1040 :
1041 0 : FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ )
1042 : {
1043 0 : hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */
1044 0 : move16();
1045 : }
1046 : }
1047 0 : GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) );
1048 :
1049 0 : IF( EQ_32( st_fx->output_Fs, 48000 ) )
1050 : {
1051 0 : interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, hTdCngDec->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 );
1052 : }
1053 :
1054 0 : ResetSHBbuffer_Dec_fx( st_fx->hBWE_TD, st_fx->extl );
1055 :
1056 0 : return;
1057 : }
1058 :
1059 1788 : static void shb_CNG_decod_ivas_fx(
1060 : Decoder_State *st, /* i/o: State structure */
1061 : const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/
1062 : Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/
1063 : const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/
1064 : const Word16 Qsyn )
1065 : {
1066 : Word16 i;
1067 : Word16 idx_ener;
1068 : TD_CNG_DEC_HANDLE hTdCngDec;
1069 : Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1];
1070 : Word16 shb_lspCNG_fx[LPC_SHB_ORDER];
1071 : Word16 excTmp_fx[L_FRAME16k];
1072 : Word16 excSHB_fx[L_FRAME16k];
1073 : Word16 tmp_lsp[LPC_SHB_ORDER];
1074 : Word16 ener_excSHB_fx;
1075 : Word32 wb_ener_fx;
1076 : Word16 wb_ener16_fx;
1077 : Word32 L_gain_fx;
1078 : Word32 gain_fx;
1079 : Word16 shb_syn16k_fx[L_FRAME16k];
1080 : Word32 tmp;
1081 : Word32 step_fx;
1082 : Word16 interp_fx;
1083 : Word32 ener_fx;
1084 : Word16 exp, exp1;
1085 : Word16 fra;
1086 : Word32 L_tmp;
1087 : Word16 allow_cn_step_fx;
1088 : Word16 q;
1089 : TD_BWE_DEC_HANDLE hBWE_TD;
1090 :
1091 1788 : hBWE_TD = st->hBWE_TD;
1092 1788 : hTdCngDec = st->hTdCngDec;
1093 1788 : allow_cn_step_fx = 0;
1094 1788 : move16();
1095 :
1096 1788 : IF( st->bfi == 0 )
1097 : {
1098 1788 : test();
1099 1788 : IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) )
1100 : {
1101 324 : idx_ener = get_next_indice_fx( st, 4 );
1102 :
1103 324 : IF( idx_ener == 0 )
1104 : {
1105 5 : idx_ener = -15;
1106 5 : move16();
1107 : }
1108 :
1109 : /* de-quantization of SHB CNG parameters */
1110 324 : IF( st->element_mode == EVS_MONO )
1111 : {
1112 0 : hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 6850 ), 36991 ); // Q11
1113 0 : move32();
1114 : }
1115 : ELSE
1116 : {
1117 324 : hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 8807 ), 36991 ); // Q11
1118 324 : move32();
1119 : }
1120 : }
1121 : }
1122 :
1123 : /* SHB spectrum estimation */
1124 1788 : interp_fx = s_min( hTdCngDec->shb_dtx_count_fx, 32 );
1125 1788 : interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/
1126 :
1127 19668 : FOR( i = 0; i < LPC_SHB_ORDER; i++ )
1128 : {
1129 17880 : shb_lspCNG_fx[i] = add( mult_r( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14
1130 17880 : move16();
1131 : }
1132 :
1133 1788 : IF( LE_16( hTdCngDec->shb_dtx_count_fx, 1000 ) )
1134 : {
1135 1788 : hTdCngDec->shb_dtx_count_fx = add( hTdCngDec->shb_dtx_count_fx, 1 );
1136 1788 : move16();
1137 : }
1138 :
1139 1788 : E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/
1140 1788 : E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER );
1141 :
1142 1788 : Copy_Scale_sig( shb_lpcCNG_fx, hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */
1143 :
1144 1788 : Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */
1145 :
1146 : /* SHB energy estimation */
1147 1788 : wb_ener_fx = L_deposit_l( 1 ); /*Q1 */
1148 1788 : IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
1149 : {
1150 0 : FOR( i = 0; i < L_FRAME32k; i++ )
1151 : {
1152 0 : wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */
1153 : }
1154 : }
1155 1788 : exp = norm_l( wb_ener_fx );
1156 1788 : fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) );
1157 1788 : exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) );
1158 1788 : wb_ener_fx = Mpy_32_16( exp, fra, LG10 );
1159 1788 : wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */
1160 1788 : Word32 wb_ener32_fx = L_shl( wb_ener16_fx, 3 ); /*wb_ener_fx in Q11 */
1161 1788 : if ( EQ_16( st->first_CNG, 0 ) )
1162 : {
1163 19 : hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx;
1164 19 : move32(); /*Q11 */
1165 : }
1166 1788 : if ( GT_32( L_abs( L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */
1167 : {
1168 0 : allow_cn_step_fx = 1;
1169 0 : move16();
1170 : }
1171 :
1172 1788 : IF( EQ_16( allow_cn_step_fx, 1 ) )
1173 : {
1174 0 : hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx;
1175 0 : move32(); /*Q11 */
1176 : }
1177 : ELSE
1178 : {
1179 1788 : tmp = L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */
1180 1788 : tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */
1181 1788 : hTdCngDec->wb_cng_ener_fx_32 = L_add( hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */
1182 1788 : move32();
1183 : }
1184 1788 : test();
1185 1788 : test();
1186 1788 : IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) )
1187 : {
1188 324 : hTdCngDec->last_wb_cng_ener_fx_32 = hTdCngDec->wb_cng_ener_fx_32; /* Q11 */
1189 324 : move32();
1190 :
1191 324 : if ( !st->first_CNG )
1192 : {
1193 19 : hTdCngDec->shb_cng_ener_fx_32 = hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */
1194 19 : move32();
1195 : }
1196 : }
1197 :
1198 1788 : gain_fx = L_sub( hTdCngDec->wb_cng_ener_fx_32, hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */
1199 1788 : if ( GT_32( gain_fx, 30720 ) )
1200 : {
1201 0 : gain_fx = 30720;
1202 0 : move32();
1203 : }
1204 1788 : step_fx = L_sub( L_add( gain_fx, hTdCngDec->last_shb_cng_ener_fx_32 ), hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */
1205 1788 : test();
1206 1788 : IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) )
1207 : {
1208 151 : hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */
1209 151 : move32();
1210 : }
1211 : ELSE
1212 : {
1213 1637 : hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */
1214 1637 : move32();
1215 : }
1216 : /* generate white noise excitation */
1217 573948 : FOR( i = 0; i < L_FRAME16k; i++ )
1218 : {
1219 572160 : excTmp_fx[i] = shr_r( Random( &hTdCngDec->swb_cng_seed ), 8 );
1220 572160 : move16(); /*Q-8*/
1221 : }
1222 :
1223 : /* synthesis filtering */
1224 1788 : Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, hBWE_TD->state_lpc_syn_fx, 1 );
1225 :
1226 :
1227 : /* synthesis signal gain shaping */
1228 1788 : L_tmp = 0;
1229 1788 : move32();
1230 573948 : FOR( i = 0; i < L_FRAME16k; i++ )
1231 : {
1232 572160 : L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/
1233 : }
1234 1788 : q = norm_l( L_tmp );
1235 1788 : L_tmp = L_shl( L_tmp, q );
1236 1788 : q = sub( q, 32 );
1237 1788 : ener_excSHB_fx = round_fx( L_tmp ); /*Qq */
1238 :
1239 1788 : IF( EQ_16( st->last_vad_fx, 1 ) )
1240 : {
1241 151 : hTdCngDec->trans_cnt_fx = 0;
1242 151 : move16();
1243 151 : test();
1244 151 : if ( GT_16( hTdCngDec->burst_cnt_fx, 3 ) && NE_16( st->last_core, HQ_CORE ) )
1245 : {
1246 40 : hTdCngDec->trans_cnt_fx = 5;
1247 40 : move16();
1248 : }
1249 : }
1250 :
1251 1788 : ener_fx = hTdCngDec->shb_cng_ener_fx_32;
1252 1788 : move32(); /*Q11 */
1253 1788 : IF( GT_16( st->hTdCngDec->trans_cnt_fx, 0 ) )
1254 : {
1255 85 : i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */
1256 85 : ener_fx = L_add( hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( hTdCngDec->last_shb_ener_fx_32, hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */
1257 85 : hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 );
1258 85 : move16();
1259 : }
1260 :
1261 1788 : tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */
1262 1788 : IF( GT_32( tmp, 32767 ) )
1263 0 : abort();
1264 : Word16 tmp_16;
1265 1788 : tmp_16 = (Word16) tmp;
1266 1788 : move16();
1267 1788 : L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */
1268 1788 : L_tmp = L_shr( L_tmp, 6 ); /*Q16 */
1269 1788 : L_tmp = L_add( L_tmp, L_shl( 10, 16 ) );
1270 1788 : if ( ( L_tmp < 0 ) )
1271 : {
1272 36 : L_tmp = 0;
1273 36 : move32();
1274 : }
1275 1788 : fra = L_Extract_lc( L_tmp, &exp );
1276 1788 : L_tmp = L_shr( Pow2( exp, fra ), 5 ); /*Q5 */
1277 1788 : if ( !L_tmp )
1278 : {
1279 40 : L_tmp = 1;
1280 40 : move32(); /*Q5 */
1281 : }
1282 1788 : exp = norm_l( L_tmp );
1283 1788 : L_tmp = L_shl( L_tmp, exp ); /*Q31*/
1284 1788 : tmp_16 = extract_h( L_tmp ); /*Q15*/
1285 1788 : exp = sub( exp, 16 );
1286 1788 : exp1 = norm_s( ener_excSHB_fx );
1287 1788 : fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/
1288 :
1289 1788 : IF( GT_16( fra, tmp_16 ) )
1290 : {
1291 758 : fra = shr( fra, 1 ); /*Q15*/
1292 758 : exp1 = sub( exp1, 1 );
1293 : }
1294 1788 : tmp_16 = div_s( fra, tmp_16 ); /*Q15*/
1295 :
1296 1788 : L_tmp = L_deposit_h( tmp_16 ); /*Q31 */
1297 1788 : tmp_16 = sub( add( 5, exp ), add( q, exp1 ) );
1298 1788 : L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */
1299 1788 : hTdCngDec->shb_cng_gain_fx_32 = ener_fx;
1300 1788 : move32();
1301 573948 : FOR( i = 0; i < L_FRAME16k; i++ )
1302 : {
1303 572160 : shb_syn16k_fx[i] = extract_l( L_shr( Mpy_32_16_1( L_gain_fx, excSHB_fx[i] ), sub( 5, tmp_16 ) ) ); /*Q3 = 31-Qtmp-8-15-5+Qtmp */
1304 572160 : move16();
1305 : }
1306 :
1307 1788 : test();
1308 1788 : IF( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) )
1309 : {
1310 : /* rescale the Hilbert memories to Q0 */
1311 528 : FOR( i = 0; i < HILBERT_MEM_SIZE; i++ )
1312 : {
1313 504 : hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */
1314 504 : move32();
1315 : }
1316 :
1317 168 : FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ )
1318 : {
1319 144 : hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */
1320 144 : move16();
1321 : }
1322 : }
1323 1788 : GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->L_frame, &( hBWE_TD->syn_dm_phase ) );
1324 :
1325 1788 : IF( EQ_32( st->output_Fs, 48000 ) )
1326 : {
1327 970 : interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, hTdCngDec->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 );
1328 : }
1329 :
1330 1788 : Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); /* Qx - 3 */
1331 :
1332 1788 : ResetSHBbuffer_Dec_fx( st->hBWE_TD, st->extl );
1333 :
1334 1788 : return;
1335 : }
1336 :
1337 : /*-------------------------------------------------------------------*
1338 : * td_cng_dec_init_fx()
1339 : *
1340 : *
1341 : *-------------------------------------------------------------------*/
1342 :
1343 1433 : void td_cng_dec_init_fx(
1344 : DEC_CORE_HANDLE st /* i/o: decoder state structure */
1345 : )
1346 : {
1347 : Word16 i;
1348 : TD_CNG_DEC_HANDLE hTdCngDec;
1349 :
1350 1433 : hTdCngDec = st->hTdCngDec;
1351 :
1352 1433 : hTdCngDec->cng_seed = RANDOM_INITSEED;
1353 1433 : move16();
1354 1433 : hTdCngDec->cng_ener_seed = RANDOM_INITSEED;
1355 1433 : move16();
1356 1433 : hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED;
1357 1433 : move16();
1358 1433 : hTdCngDec->old_enr_index = -1;
1359 1433 : move16();
1360 1433 : hTdCngDec->Enew_fx = 0;
1361 1433 : move32();
1362 1433 : Copy( st->lsp_old_fx, st->lspCNG_fx, M ); // Q(15)
1363 1433 : hTdCngDec->last_allow_cn_step = 0;
1364 1433 : move16();
1365 1433 : hTdCngDec->shb_cng_ener_fx = -1541; // Q8
1366 1433 : move16();
1367 1433 : hTdCngDec->shb_cng_ener_fx_32 = -12329; // -6.02 in Q(11)
1368 1433 : move32();
1369 1433 : IF( st->element_mode != EVS_MONO )
1370 : {
1371 1430 : set16_fx( hTdCngDec->shb_lpcCNG_fx, 0, LPC_SHB_ORDER + 1 );
1372 1430 : hTdCngDec->shb_lpcCNG_fx[0] = 32767; // 1 in Q(15)
1373 1430 : move16();
1374 1430 : hTdCngDec->shb_cng_gain_fx_32 = -167936; //-82.0 in Q(11) /* a dB value approximately corresponding to shb index 0(used as index -15) */
1375 1430 : move32();
1376 : }
1377 :
1378 1433 : hTdCngDec->wb_cng_ener_fx = -1541; // Q8
1379 1433 : move16();
1380 1433 : hTdCngDec->wb_cng_ener_fx_32 = -12329; // Q(11)
1381 1433 : move32();
1382 1433 : hTdCngDec->last_wb_cng_ener_fx = -1541; // Q8
1383 1433 : move16();
1384 1433 : hTdCngDec->last_wb_cng_ener_fx_32 = -12329; // Q(11)
1385 1433 : move32();
1386 1433 : hTdCngDec->last_shb_cng_ener_fx = -1541; // Q8
1387 1433 : move16();
1388 1433 : hTdCngDec->last_shb_cng_ener_fx_32 = -12329; // Q(11)
1389 1433 : move32();
1390 1433 : hTdCngDec->swb_cng_seed = RANDOM_INITSEED;
1391 1433 : move16();
1392 1433 : hTdCngDec->ho_hist_ptr = -1;
1393 1433 : move16();
1394 1433 : hTdCngDec->ho_sid_bw = 0;
1395 1433 : move16();
1396 1433 : set16_fx( hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M );
1397 1433 : set32_fx( hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE );
1398 1433 : set32_fx( hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
1399 1433 : hTdCngDec->ho_hist_size = 0;
1400 1433 : move16();
1401 1433 : hTdCngDec->act_cnt = 0;
1402 1433 : move16();
1403 1433 : hTdCngDec->ho_circ_ptr = -1;
1404 1433 : move16();
1405 1433 : set16_fx( hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M );
1406 1433 : set32_fx( hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE );
1407 1433 : set32_fx( hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
1408 1433 : hTdCngDec->ho_circ_size = 0;
1409 1433 : move16();
1410 :
1411 1433 : set16_fx( hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE );
1412 1433 : st->CNG_mode = -1;
1413 1433 : move16();
1414 1433 : hTdCngDec->act_cnt2 = 0;
1415 1433 : move16();
1416 1433 : hTdCngDec->num_ho = 0;
1417 1433 : move16();
1418 1433 : set32_fx( hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG );
1419 1433 : set16_fx( hTdCngDec->exc_mem_fx, 0, 24 );
1420 1433 : set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 );
1421 1433 : set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG );
1422 :
1423 15763 : FOR( i = 0; i < LPC_SHB_ORDER; i++ )
1424 : {
1425 14330 : IF( st->element_mode != EVS_MONO )
1426 : {
1427 14300 : hTdCngDec->lsp_shb_prev_fx[i] = ivas_lsp_shb_prev_tbl_fx[i]; /* Q14 */
1428 14300 : move16();
1429 : }
1430 : ELSE
1431 : {
1432 30 : hTdCngDec->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; /* Q14 */
1433 30 : move16();
1434 : }
1435 14330 : hTdCngDec->lsp_shb_prev_prev_fx[i] = hTdCngDec->lsp_shb_prev_fx[i]; /* Q14 */
1436 14330 : move16();
1437 : }
1438 :
1439 1433 : hTdCngDec->shb_dtx_count_fx = 0;
1440 1433 : move16();
1441 1433 : hTdCngDec->trans_cnt_fx = 0;
1442 1433 : move16();
1443 1433 : hTdCngDec->burst_cnt_fx = 0;
1444 1433 : move16();
1445 :
1446 1433 : hTdCngDec->last_shb_ener_fx = 0; // Q8
1447 1433 : move16();
1448 1433 : hTdCngDec->last_shb_ener_fx_32 = 2; // 0.001 in Q11
1449 1433 : move32();
1450 :
1451 1433 : set16_fx( hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN );
1452 :
1453 1433 : return;
1454 : }
|