Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdlib.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h" /* Common constants */
8 : #include "rom_com.h" /* Static table prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 : #include "stl.h"
11 : #include "basop_util.h"
12 :
13 : /*======================================================================*/
14 : /* FUNCTION : decod_gen_voic_fx() */
15 : /*----------------------------------------------------------------------*/
16 : /* PURPOSE : Decode generic (GC), voiced (VC) and AMR-WB IO frames */
17 : /* */
18 : /*----------------------------------------------------------------------*/
19 : /* GLOBAL INPUT ARGUMENTS : */
20 : /* _ (Struct) st_fx : decoder static memory */
21 : /* _ (Word16) L_frame : length of the frame */
22 : /* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */
23 : /* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */
24 : /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/
25 : /* _ (Word16[]) voice_factors_fx: frame error rate Q15 */
26 : /*----------------------------------------------------------------------*/
27 : /* OUTPUT ARGUMENTS : */
28 : /* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */
29 : /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */
30 : /*----------------------------------------------------------------------*/
31 : /*----------------------------------------------------------------------*/
32 : /* RETURN ARGUMENTS : */
33 : /* _ None */
34 : /*======================================================================*/
35 :
36 107775 : ivas_error decod_gen_voic_fx(
37 : Decoder_State *st_fx, /* i/o: decoder static memory */
38 : const Word16 L_frame, /* i : length of the frame */
39 : const Word16 sharpFlag_fx, /* i : formant sharpening flag */
40 : const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */
41 : const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */
42 : const Word16 do_WI_fx, /* i : do interpolation after a FER */
43 : Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6 */
44 : Word16 *voice_factors_fx, /* o : voicing factors Q15 */
45 : Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */
46 : Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */
47 : Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */
48 : Word16 *unbits, /* number of unused bits */
49 : Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14 */
50 : const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
51 : const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */
52 : )
53 : {
54 : Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */
55 : Word16 gain_pit_fx; /* pitch gain Q14 */
56 : Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */
57 : Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */
58 : Word16 gain_inov_fx; /* Innovation gain Q12 */
59 : Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
60 : Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */
61 : Word16 voice_fac_fx; /* voicing factor Q15 */
62 : Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */
63 :
64 : const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */
65 : Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */
66 : Word16 i_subfr_fx, i; /* tmp variables */
67 : Word16 error_fx;
68 : Word16 gain_preQ_fx; /* Gain of prequantizer excitation */
69 : Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */
70 : Word32 norm_gain_preQ_fx;
71 : Word16 pitch_limit_flag_fx;
72 :
73 : Word16 tmp1_fx, gain_code16;
74 : Word32 L_tmp_GC;
75 : Word32 L_tmp;
76 :
77 : Word16 harm_flag_acelp;
78 :
79 : Word16 shft_prev, ph_offset_fx;
80 : Word32 prev_res_nrg;
81 : Word32 prev_spch_nrg;
82 : Word32 curr_res_nrg;
83 : Word32 curr_spch_nrg;
84 : Word16 rint_bfi_pitch, rint_pitch;
85 : Word16 fraca, fracb, expa, expb, scale, exp1;
86 : Word16 *p_exc;
87 : Word16 mem_tmp_fx[M];
88 : Word16 syn_tmp_fx[L_FRAME16k];
89 : Word16 shft_curr;
90 : Word16 *p_syn;
91 : Word16 sp_enratio, Qsp_enratio;
92 : Word16 enratio, Qenratio;
93 : DTFS_STRUCTURE *PREVP, *CURRP;
94 : Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1];
95 : Word16 dummy2[2];
96 : Word16 out_fx[L_FRAME16k];
97 :
98 : Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */
99 : Word16 pf_temp2[MAXLAG_WI];
100 : Word16 pf_temp[MAXLAG_WI];
101 : Word16 pf_n2[MAXLAG_WI];
102 : MUSIC_POSTFILT_HANDLE hMusicPF;
103 : #ifdef FIX_2010_PREP_TBE_EXC
104 : Word16 Q_code_preQ;
105 : #endif
106 :
107 107775 : gain_pit_fx = 0;
108 107775 : gain_code_fx = 0;
109 107775 : norm_gain_code_fx = 0;
110 107775 : gain_inov_fx = 0;
111 107775 : error_fx = 0;
112 107775 : gain_preQ_fx = 0;
113 107775 : move16();
114 107775 : move32();
115 107775 : move32();
116 107775 : move16();
117 107775 : move16();
118 107775 : move16();
119 :
120 107775 : hMusicPF = st_fx->hMusicPF;
121 :
122 : GSC_DEC_HANDLE hGSCDec;
123 107775 : hGSCDec = st_fx->hGSCDec;
124 : ivas_error error;
125 :
126 107775 : error = IVAS_ERR_OK;
127 107775 : move32();
128 :
129 107775 : T0_fx = PIT_MIN;
130 107775 : move16();
131 107775 : T0_frac_fx = 0;
132 107775 : move16();
133 :
134 : /* read harmonicity flag */
135 107775 : harm_flag_acelp = 0;
136 107775 : move16();
137 107775 : test();
138 107775 : test();
139 107775 : IF( ( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) ) && EQ_16( st_fx->coder_type, GENERIC ) )
140 : {
141 6910 : harm_flag_acelp = (Word16) get_next_indice_fx( st_fx, 1 );
142 : }
143 :
144 : /*------------------------------------------------------------------*
145 : * ACELP subframe loop
146 : *------------------------------------------------------------------*/
147 :
148 107775 : p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */
149 107775 : pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
150 107775 : norm_gain_preQ_fx = 0;
151 107775 : move32();
152 107775 : gain_preQ_fx = 0;
153 107775 : move16();
154 107775 : set16_fx( code_preQ_fx, 0, L_SUBFR );
155 :
156 598463 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
157 : {
158 : /*----------------------------------------------------------------------*
159 : * Decode pitch lag
160 : *----------------------------------------------------------------------*/
161 :
162 490688 : *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx,
163 : &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
164 490688 : move16(); /*Q6*/
165 :
166 : /*--------------------------------------------------------------*
167 : * Find the adaptive codebook vector
168 : *--------------------------------------------------------------*/
169 490688 : IF( st_fx->element_mode != EVS_MONO )
170 : {
171 484900 : pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
172 : }
173 : ELSE
174 : {
175 5788 : pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
176 : }
177 :
178 : // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx);
179 490688 : tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag );
180 :
181 : /*--------------------------------------------------------------*
182 : * LP filtering of the adaptive excitation
183 : *--------------------------------------------------------------*/
184 490688 : lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx );
185 : /*-----------------------------------------------------------------*
186 : * Transform-domain contribution decoding (active frames)
187 : *-----------------------------------------------------------------*/
188 :
189 490688 : test();
190 490688 : IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) )
191 : {
192 47150 : gain_code_fx = 0;
193 47150 : move16();
194 47150 : transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits );
195 : }
196 :
197 : /*--------------------------------------------------------------*
198 : * Innovation decoding
199 : *--------------------------------------------------------------*/
200 :
201 490688 : inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR );
202 :
203 : /*--------------------------------------------------------------*
204 : * Gain decoding
205 : * Estimate spectrum tilt and voicing
206 : *--------------------------------------------------------------*/
207 :
208 490688 : IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
209 : {
210 13064 : gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR );
211 : }
212 477624 : ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) )
213 : {
214 37865 : gain_dec_SQ_fx( st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
215 : }
216 : ELSE
217 : {
218 439759 : gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
219 : }
220 490688 : st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); // Q15
221 490688 : move16();
222 :
223 : /*-----------------------------------------------------------------*
224 : * Transform domain contribution decoding
225 : *-----------------------------------------------------------------*/
226 490688 : test();
227 490688 : IF( !st_fx->inactive_coder_type_flag && st_fx->coder_type == INACTIVE )
228 : {
229 9700 : transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits );
230 : }
231 :
232 : /* update LP filtered gains for the case of frame erasures */
233 490688 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
234 : {
235 5788 : lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame );
236 : }
237 : ELSE
238 : {
239 484900 : lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame );
240 : }
241 :
242 : /*----------------------------------------------------------------------*
243 : * Find the total excitation
244 : *----------------------------------------------------------------------*/
245 :
246 490688 : IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */
247 : {
248 192748 : IF( ( bwe_exc_fx != NULL ) )
249 : {
250 192344 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx,
251 192344 : L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
252 : }
253 : ELSE
254 : {
255 404 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
256 404 : L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
257 : }
258 : }
259 : ELSE /* Rescaling for 16k core */
260 : {
261 :
262 297940 : L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/
263 297940 : IF( bwe_exc_fx != NULL )
264 : {
265 297940 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx,
266 297940 : L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
267 : }
268 : ELSE
269 : {
270 0 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
271 0 : L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
272 : }
273 : }
274 :
275 490688 : gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
276 :
277 : /*-----------------------------------------------------------------*
278 : * Add the ACELP pre-quantizer contribution
279 : *-----------------------------------------------------------------*/
280 :
281 490688 : IF( gain_preQ_fx != 0 )
282 : {
283 56845 : IF( st_fx->element_mode == EVS_MONO )
284 : {
285 3120 : tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc );
286 : }
287 : ELSE
288 : {
289 53725 : tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc );
290 : }
291 3694925 : FOR( i = 0; i < L_SUBFR; i++ )
292 : {
293 : Word32 Ltmp1;
294 : /* Contribution from AVQ layer */
295 3638080 : Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/
296 3638080 : Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */
297 :
298 : /* Compute exc2 */
299 3638080 : L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 );
300 3638080 : exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
301 3638080 : move16();
302 : /* gain_pit in Q14 */
303 3638080 : L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1
304 3638080 : L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5
305 3638080 : L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+16
306 3638080 : L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
307 :
308 3638080 : exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
309 3638080 : move16();
310 : }
311 : }
312 : ELSE
313 : {
314 433843 : Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR );
315 : }
316 :
317 : /*-----------------------------------------------------------------*
318 : * Prepare TBE excitation
319 : *-----------------------------------------------------------------*/
320 :
321 : Word16 idx;
322 490688 : idx = 0;
323 490688 : move16();
324 490688 : IF( i_subfr_fx != 0 )
325 : {
326 382913 : idx = idiv1616( i_subfr_fx, L_SUBFR );
327 : }
328 :
329 : #ifdef FIX_2010_PREP_TBE_EXC
330 : /*
331 : 2025-09-15 multrus:
332 : TODO:
333 : check with vaillancourt
334 : - where this difference between EVS and IVAS comes from
335 : - where Q_code_preQ could be derived
336 : - whether any of the above calculations need to be adjusted
337 : */
338 490688 : Q_code_preQ = Q6;
339 490688 : move16();
340 490688 : if ( EQ_16( st_fx->element_mode, EVS_MONO ) )
341 : {
342 5788 : Q_code_preQ = Q10;
343 5788 : move16();
344 : }
345 :
346 490688 : prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
347 490688 : &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_code_preQ,
348 490688 : st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
349 490688 : st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
350 : #else
351 : prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
352 : &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
353 : st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
354 : st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
355 : #endif
356 :
357 :
358 : /*----------------------------------------------------------------*
359 : * Excitation enhancements (update of total excitation signal)
360 : *----------------------------------------------------------------*/
361 :
362 490688 : test();
363 490688 : IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) )
364 : {
365 41685 : Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR );
366 : }
367 : ELSE
368 : {
369 449003 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
370 : {
371 2668 : enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
372 2668 : norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc );
373 : }
374 : ELSE
375 : {
376 446335 : enhancer_ivas_fx( MODE1, st_fx->core_brate, -1, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
377 446335 : norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc );
378 : }
379 : }
380 :
381 490688 : p_Aq_fx += ( M + 1 );
382 490688 : move16();
383 490688 : pt_pitch_fx++;
384 490688 : gain_buf[idx] = gain_pit_fx; // Q14
385 490688 : move16();
386 : }
387 :
388 : /* FEC fast recovery */
389 :
390 107775 : IF( do_WI_fx )
391 : {
392 : /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/
393 0 : L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/
394 0 : rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/
395 0 : shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/
396 :
397 0 : p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev;
398 0 : p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev;
399 :
400 0 : prev_res_nrg = 1;
401 0 : move32();
402 0 : prev_spch_nrg = 1;
403 0 : move32();
404 0 : FOR( i = 0; i < rint_bfi_pitch; i++ )
405 : {
406 0 : prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */
407 0 : prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */
408 0 : p_exc++;
409 0 : p_syn++;
410 : }
411 :
412 0 : Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M );
413 :
414 0 : syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn );
415 :
416 0 : L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/
417 0 : rint_pitch = rint_new_fx( L_tmp ); /*Q0*/
418 0 : shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/
419 :
420 0 : p_exc = exc2_fx + shft_curr;
421 0 : p_syn = syn_tmp_fx + shft_curr;
422 :
423 0 : curr_res_nrg = 1;
424 0 : move32();
425 0 : curr_spch_nrg = 1;
426 0 : move32();
427 0 : FOR( i = 0; i < rint_pitch; i++ )
428 : {
429 0 : curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */
430 0 : curr_spch_nrg = L_mac0( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */
431 0 : p_exc++;
432 0 : p_syn++;
433 : }
434 :
435 : /* enratio = (curr_res_nrg / prev_res_nrg); */
436 0 : IF( prev_res_nrg > 0 )
437 : {
438 0 : expa = norm_l( prev_res_nrg );
439 0 : fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr +expa -16*/
440 0 : expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) );
441 :
442 0 : expb = norm_l( curr_res_nrg );
443 0 : fracb = round_fx( L_shl( curr_res_nrg, expb ) ); /* 2*st_fx->prev_Q_exc_fr +expb -16*/
444 0 : expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) );
445 :
446 0 : scale = shr( sub( fraca, fracb ), 15 );
447 0 : fracb = shl( fracb, scale ); // Q(15-expb)+scale
448 0 : expb = sub( expb, scale );
449 :
450 0 : enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)
451 0 : exp1 = sub( expb, expa );
452 0 : Qenratio = sub( 15, exp1 );
453 : }
454 : ELSE
455 : {
456 0 : enratio = 0;
457 0 : move16();
458 0 : Qenratio = 0;
459 0 : move16();
460 : }
461 :
462 : /* sp_enratio = curr_spch_nrg/prev_spch_nrg */
463 0 : IF( prev_spch_nrg > 0 )
464 : {
465 0 : expa = norm_l( prev_spch_nrg );
466 0 : fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr -16 +expa */
467 0 : expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) );
468 :
469 0 : expb = norm_l( curr_spch_nrg );
470 0 : fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb -16*/
471 0 : expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) );
472 :
473 0 : scale = shr( sub( fraca, fracb ), 15 );
474 0 : fracb = shl( fracb, scale ); // Q(15-expb)+scale
475 0 : expb = sub( expb, scale );
476 :
477 0 : sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa))
478 0 : exp1 = sub( expb, expa );
479 0 : Qsp_enratio = sub( 15, exp1 );
480 : }
481 : ELSE
482 : {
483 0 : sp_enratio = 0;
484 0 : move16();
485 0 : Qsp_enratio = 0;
486 0 : move16();
487 : }
488 :
489 0 : test();
490 0 : test();
491 0 : test();
492 0 : test();
493 0 : IF( GT_16( shr_r_sat( enratio, sub( Qenratio, 15 ) ), 8192 ) && /*compare with 0.25 in Q15*/
494 : LT_16( shr_r_sat( enratio, sub( Qenratio, 10 ) ), 15360 ) && /*compare with 15.0 in Q10*/
495 : GT_16( shr_r_sat( sp_enratio, sub( Qsp_enratio, 15 ) ), 4915 ) && /*compare with 0.15 in Q15*/
496 : LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/
497 : LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) ) /*Q6*/
498 : {
499 0 : IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) )
500 : {
501 0 : return error;
502 : }
503 :
504 0 : IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) )
505 : {
506 0 : return error;
507 : }
508 :
509 0 : GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx );
510 0 : DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx );
511 0 : PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr );
512 0 : move16();
513 :
514 0 : GetSinCosTab_fx( rint_pitch, S_fx, C_fx );
515 0 : DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx );
516 0 : CURRP->Q = add( CURRP->Q, st_fx->Q_exc );
517 0 : move16();
518 :
519 0 : ph_offset_fx = 0;
520 0 : move16();
521 0 : IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) )
522 : {
523 0 : return error;
524 : }
525 :
526 :
527 0 : Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
528 0 : Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
529 :
530 : /* update bwe_exc for SWB-TBE */
531 0 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
532 : {
533 0 : interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR );
534 : }
535 :
536 0 : free( PREVP );
537 0 : free( CURRP );
538 : }
539 : }
540 :
541 : /* SC-VBR */
542 107775 : st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
543 107775 : move16(); /*Q14*/
544 107775 : st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx;
545 107775 : move16(); /*Q15*/
546 :
547 107775 : return error;
548 : }
|