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 105524 : 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 105524 : gain_pit_fx = 0;
104 105524 : gain_code_fx = 0;
105 105524 : norm_gain_code_fx = 0;
106 105524 : gain_inov_fx = 0;
107 105524 : error_fx = 0;
108 105524 : gain_preQ_fx = 0;
109 105524 : move16();
110 105524 : move32();
111 105524 : move32();
112 105524 : move16();
113 105524 : move16();
114 105524 : move16();
115 :
116 105524 : hMusicPF = st_fx->hMusicPF;
117 :
118 : GSC_DEC_HANDLE hGSCDec;
119 105524 : hGSCDec = st_fx->hGSCDec;
120 : ivas_error error;
121 :
122 105524 : error = IVAS_ERR_OK;
123 105524 : move32();
124 :
125 105524 : T0_fx = PIT_MIN;
126 105524 : move16();
127 105524 : T0_frac_fx = 0;
128 105524 : move16();
129 :
130 : /* read harmonicity flag */
131 105524 : harm_flag_acelp = 0;
132 105524 : move16();
133 105524 : test();
134 105524 : test();
135 105524 : 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 ) )
136 : {
137 6629 : harm_flag_acelp = (Word16) get_next_indice_fx( st_fx, 1 );
138 : }
139 :
140 : /*------------------------------------------------------------------*
141 : * ACELP subframe loop
142 : *------------------------------------------------------------------*/
143 :
144 105524 : p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */
145 105524 : pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
146 105524 : norm_gain_preQ_fx = 0;
147 105524 : move32();
148 105524 : gain_preQ_fx = 0;
149 105524 : move16();
150 105524 : set16_fx( code_preQ_fx, 0, L_SUBFR );
151 :
152 585708 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
153 : {
154 : /*----------------------------------------------------------------------*
155 : * Decode pitch lag
156 : *----------------------------------------------------------------------*/
157 :
158 480184 : *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,
159 : &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
160 480184 : move16(); /*Q6*/
161 :
162 : /*--------------------------------------------------------------*
163 : * Find the adaptive codebook vector
164 : *--------------------------------------------------------------*/
165 480184 : IF( st_fx->element_mode != EVS_MONO )
166 : {
167 474382 : 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 );
168 : }
169 : ELSE
170 : {
171 5802 : 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 );
172 : }
173 :
174 : // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx);
175 480184 : 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 );
176 :
177 : /*--------------------------------------------------------------*
178 : * LP filtering of the adaptive excitation
179 : *--------------------------------------------------------------*/
180 480184 : lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx );
181 : /*-----------------------------------------------------------------*
182 : * Transform-domain contribution decoding (active frames)
183 : *-----------------------------------------------------------------*/
184 :
185 480184 : test();
186 480184 : IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) )
187 : {
188 45840 : gain_code_fx = 0;
189 45840 : move16();
190 45840 : 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 );
191 : }
192 :
193 : /*--------------------------------------------------------------*
194 : * Innovation decoding
195 : *--------------------------------------------------------------*/
196 :
197 480184 : 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 );
198 :
199 : /*--------------------------------------------------------------*
200 : * Gain decoding
201 : * Estimate spectrum tilt and voicing
202 : *--------------------------------------------------------------*/
203 :
204 480184 : IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
205 : {
206 12804 : 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 );
207 : }
208 467380 : ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) )
209 : {
210 37820 : 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 );
211 : }
212 : ELSE
213 : {
214 429560 : 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 );
215 : }
216 480184 : 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
217 480184 : move16();
218 :
219 : /*-----------------------------------------------------------------*
220 : * Transform domain contribution decoding
221 : *-----------------------------------------------------------------*/
222 480184 : test();
223 480184 : IF( !st_fx->inactive_coder_type_flag && st_fx->coder_type == INACTIVE )
224 : {
225 9025 : 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 );
226 : }
227 :
228 : /* update LP filtered gains for the case of frame erasures */
229 480184 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
230 : {
231 5802 : 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 );
232 : }
233 : ELSE
234 : {
235 474382 : 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 );
236 : }
237 :
238 : /*----------------------------------------------------------------------*
239 : * Find the total excitation
240 : *----------------------------------------------------------------------*/
241 :
242 480184 : IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */
243 : {
244 189744 : IF( ( bwe_exc_fx != NULL ) )
245 : {
246 189304 : 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,
247 189304 : 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 );
248 : }
249 : ELSE
250 : {
251 440 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
252 440 : 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 );
253 : }
254 : }
255 : ELSE /* Rescaling for 16k core */
256 : {
257 :
258 290440 : 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*/
259 290440 : IF( bwe_exc_fx != NULL )
260 : {
261 290440 : 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,
262 290440 : 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 );
263 : }
264 : ELSE
265 : {
266 0 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
267 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 );
268 : }
269 : }
270 :
271 480184 : gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
272 :
273 : /*-----------------------------------------------------------------*
274 : * Add the ACELP pre-quantizer contribution
275 : *-----------------------------------------------------------------*/
276 :
277 480184 : IF( gain_preQ_fx != 0 )
278 : {
279 54858 : IF( st_fx->element_mode == EVS_MONO )
280 : {
281 3110 : tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc );
282 : }
283 : ELSE
284 : {
285 51748 : tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc );
286 : }
287 3565770 : FOR( i = 0; i < L_SUBFR; i++ )
288 : {
289 : Word32 Ltmp1;
290 : /* Contribution from AVQ layer */
291 3510912 : Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/
292 3510912 : Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */
293 :
294 : /* Compute exc2 */
295 3510912 : L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 );
296 3510912 : exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
297 3510912 : move16();
298 : /* gain_pit in Q14 */
299 3510912 : L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1
300 3510912 : L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5
301 3510912 : L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+16
302 3510912 : L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
303 :
304 3510912 : exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
305 3510912 : move16();
306 : }
307 : }
308 : ELSE
309 : {
310 425326 : Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR );
311 : }
312 :
313 : /*-----------------------------------------------------------------*
314 : * Prepare TBE excitation
315 : *-----------------------------------------------------------------*/
316 :
317 : Word16 idx;
318 480184 : idx = 0;
319 480184 : move16();
320 480184 : IF( i_subfr_fx != 0 )
321 : {
322 374660 : idx = idiv1616( i_subfr_fx, L_SUBFR );
323 : }
324 :
325 480184 : prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
326 480184 : &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
327 480184 : st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
328 480184 : st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
329 :
330 :
331 : /*----------------------------------------------------------------*
332 : * Excitation enhancements (update of total excitation signal)
333 : *----------------------------------------------------------------*/
334 :
335 480184 : test();
336 480184 : IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) )
337 : {
338 40955 : Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR );
339 : }
340 : ELSE
341 : {
342 439229 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
343 : {
344 2692 : enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
345 2692 : 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 );
346 : }
347 : ELSE
348 : {
349 436537 : 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,
350 436537 : 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 );
351 : }
352 : }
353 :
354 480184 : p_Aq_fx += ( M + 1 );
355 480184 : move16();
356 480184 : pt_pitch_fx++;
357 480184 : gain_buf[idx] = gain_pit_fx; // Q14
358 480184 : move16();
359 : }
360 :
361 : /* FEC fast recovery */
362 :
363 105524 : IF( do_WI_fx )
364 : {
365 : /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/
366 0 : L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/
367 0 : rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/
368 0 : shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/
369 :
370 0 : p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev;
371 0 : p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev;
372 :
373 0 : prev_res_nrg = 1;
374 0 : move32();
375 0 : prev_spch_nrg = 1;
376 0 : move32();
377 0 : FOR( i = 0; i < rint_bfi_pitch; i++ )
378 : {
379 0 : prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */
380 0 : prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */
381 0 : p_exc++;
382 0 : p_syn++;
383 : }
384 :
385 0 : Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M );
386 :
387 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 );
388 :
389 0 : L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/
390 0 : rint_pitch = rint_new_fx( L_tmp ); /*Q0*/
391 0 : shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/
392 :
393 0 : p_exc = exc2_fx + shft_curr;
394 0 : p_syn = syn_tmp_fx + shft_curr;
395 :
396 0 : curr_res_nrg = 1;
397 0 : move32();
398 0 : curr_spch_nrg = 1;
399 0 : move32();
400 0 : FOR( i = 0; i < rint_pitch; i++ )
401 : {
402 0 : curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */
403 0 : curr_spch_nrg = L_mac0( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */
404 0 : p_exc++;
405 0 : p_syn++;
406 : }
407 :
408 : /* enratio = (curr_res_nrg / prev_res_nrg); */
409 0 : IF( prev_res_nrg > 0 )
410 : {
411 0 : expa = norm_l( prev_res_nrg );
412 0 : fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr +expa -16*/
413 0 : expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) );
414 :
415 0 : expb = norm_l( curr_res_nrg );
416 0 : fracb = round_fx( L_shl( curr_res_nrg, expb ) ); /* 2*st_fx->prev_Q_exc_fr +expb -16*/
417 0 : expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) );
418 :
419 0 : scale = shr( sub( fraca, fracb ), 15 );
420 0 : fracb = shl( fracb, scale ); // Q(15-expb)+scale
421 0 : expb = sub( expb, scale );
422 :
423 0 : enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)
424 0 : exp1 = sub( expb, expa );
425 0 : Qenratio = sub( 15, exp1 );
426 : }
427 : ELSE
428 : {
429 0 : enratio = 0;
430 0 : move16();
431 0 : Qenratio = 0;
432 0 : move16();
433 : }
434 :
435 : /* sp_enratio = curr_spch_nrg/prev_spch_nrg */
436 0 : IF( prev_spch_nrg > 0 )
437 : {
438 0 : expa = norm_l( prev_spch_nrg );
439 0 : fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr -16 +expa */
440 0 : expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) );
441 :
442 0 : expb = norm_l( curr_spch_nrg );
443 0 : fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb -16*/
444 0 : expb = sub( 30, add( expb, shl( st_fx->Q_syn, 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 : sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa))
451 0 : exp1 = sub( expb, expa );
452 0 : Qsp_enratio = sub( 15, exp1 );
453 : }
454 : ELSE
455 : {
456 0 : sp_enratio = 0;
457 0 : move16();
458 0 : Qsp_enratio = 0;
459 0 : move16();
460 : }
461 :
462 0 : test();
463 0 : test();
464 0 : test();
465 0 : test();
466 : #ifdef ISSUE_1751_replace_shl_ro
467 0 : IF( GT_16( shr_r_sat( enratio, sub( Qenratio, 15 ) ), 8192 ) && /*compare with 0.25 in Q15*/
468 : LT_16( shr_r_sat( enratio, sub( Qenratio, 10 ) ), 15360 ) && /*compare with 15.0 in Q10*/
469 : GT_16( shr_r_sat( sp_enratio, sub( Qsp_enratio, 15 ) ), 4915 ) && /*compare with 0.15 in Q15*/
470 : LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/
471 : LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) ) /*Q6*/
472 : #else
473 : Flag Overflow;
474 : IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/
475 : LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/
476 : GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/
477 : LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/
478 : LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) ) /*Q6*/
479 : #endif
480 : {
481 0 : IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) )
482 : {
483 0 : return error;
484 : }
485 :
486 0 : IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) )
487 : {
488 0 : return error;
489 : }
490 :
491 0 : GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx );
492 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 );
493 0 : PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr );
494 0 : move16();
495 :
496 0 : GetSinCosTab_fx( rint_pitch, S_fx, C_fx );
497 0 : DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx );
498 0 : CURRP->Q = add( CURRP->Q, st_fx->Q_exc );
499 0 : move16();
500 :
501 0 : ph_offset_fx = 0;
502 0 : move16();
503 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 ) )
504 : {
505 0 : return error;
506 : }
507 :
508 :
509 0 : Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
510 0 : Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
511 :
512 : /* update bwe_exc for SWB-TBE */
513 0 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
514 : {
515 0 : interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR );
516 : }
517 :
518 0 : free( PREVP );
519 0 : free( CURRP );
520 : }
521 : }
522 :
523 : /* SC-VBR */
524 105524 : st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
525 105524 : move16(); /*Q14*/
526 105524 : st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx;
527 105524 : move16(); /*Q15*/
528 :
529 105524 : return error;
530 : }
|