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