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 :
23 : /* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */
24 : /* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */
25 : /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/
26 : /* _ (Word16[]) voice_factors_fx: frame error rate Q15 */
27 : /*----------------------------------------------------------------------*/
28 : /* OUTPUT ARGUMENTS : */
29 : /* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */
30 : /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */
31 : /*----------------------------------------------------------------------*/
32 :
33 :
34 : /*----------------------------------------------------------------------*/
35 : /* RETURN ARGUMENTS : */
36 : /* _ None */
37 : /*======================================================================*/
38 :
39 : #ifndef REMOVE_EVS_DUPLICATES
40 : ivas_error decod_gen_voic_fx(
41 : Decoder_State *st_fx, /* i/o: decoder static memory */
42 : const Word16 L_frame, /* i : length of the frame */
43 : const Word16 sharpFlag_fx, /* i : formant sharpening flag */
44 : const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */
45 : const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */
46 : const Word16 do_WI_fx, /* i : do interpolation after a FER */
47 : Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6 */
48 : Word16 *voice_factors_fx, /* o : voicing factors Q15 */
49 : Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */
50 : Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */
51 : Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */
52 : Word16 *unbits, /* number of unused bits */
53 : Word16 *gain_buf /*Q14*/
54 : )
55 : {
56 :
57 :
58 : Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */
59 : Word16 gain_pit_fx = 0; /* pitch gain Q14 */
60 : move16();
61 : Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */
62 : move32();
63 : Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */
64 : move32();
65 : Word16 gain_inov_fx = 0; /* Innovation gain Q12 */
66 : move16();
67 : Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
68 : Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */
69 : Word16 voice_fac_fx; /* voicing factor Q15 */
70 : Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */
71 :
72 : const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */
73 : Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */
74 : Word16 i_subfr_fx, i; /* tmp variables */
75 : Word16 error_fx = 0;
76 : move16();
77 : Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */
78 : move16();
79 : Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */
80 : Word32 norm_gain_preQ_fx;
81 : Word16 pitch_limit_flag_fx;
82 :
83 : Word16 tmp1_fx, gain_code16;
84 : Word32 L_tmp_GC;
85 : Word32 L_tmp;
86 :
87 : Word16 harm_flag_acelp;
88 :
89 : Word16 shft_prev, ph_offset_fx;
90 : Word32 prev_res_nrg;
91 : Word32 prev_spch_nrg;
92 : Word32 curr_res_nrg;
93 : Word32 curr_spch_nrg;
94 : Word16 rint_bfi_pitch, rint_pitch;
95 : Word16 fraca, fracb, expa, expb, scale, exp1;
96 : Word16 *p_exc;
97 : Word16 mem_tmp_fx[M];
98 : Word16 syn_tmp_fx[L_FRAME16k];
99 : Word16 shft_curr;
100 : Word16 *p_syn;
101 : Word16 sp_enratio, Qsp_enratio;
102 : Word16 enratio, Qenratio;
103 : DTFS_STRUCTURE *PREVP, *CURRP;
104 : Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1];
105 : Word16 dummy2[2];
106 : Word16 out_fx[L_FRAME16k];
107 :
108 : Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */
109 : Word16 pf_temp2[MAXLAG_WI];
110 : Word16 pf_temp[MAXLAG_WI];
111 : Word16 pf_n2[MAXLAG_WI];
112 : MUSIC_POSTFILT_HANDLE hMusicPF;
113 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
114 : Flag Overflow = 0;
115 : move32();
116 : #endif
117 :
118 : hMusicPF = st_fx->hMusicPF;
119 :
120 : GSC_DEC_HANDLE hGSCDec;
121 : hGSCDec = st_fx->hGSCDec;
122 : ivas_error error;
123 :
124 : error = IVAS_ERR_OK;
125 : move32();
126 :
127 : T0_fx = PIT_MIN;
128 : move16();
129 : T0_frac_fx = 0;
130 : move16();
131 :
132 : /* read harmonicity flag */
133 : harm_flag_acelp = 0;
134 : move16();
135 : test();
136 : test();
137 : 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 ) )
138 : {
139 : harm_flag_acelp = (Word16) get_next_indice( st_fx, 1 );
140 : }
141 :
142 : /*------------------------------------------------------------------*
143 : * ACELP subframe loop
144 : *------------------------------------------------------------------*/
145 :
146 : p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */
147 : pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
148 : norm_gain_preQ_fx = 0;
149 : move32();
150 : gain_preQ_fx = 0;
151 : move16();
152 : set16_fx( code_preQ_fx, 0, L_SUBFR );
153 :
154 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
155 : {
156 : /*----------------------------------------------------------------------*
157 : * Decode pitch lag
158 : *----------------------------------------------------------------------*/
159 :
160 : *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,
161 : &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR );
162 : move16(); /*Q6*/
163 :
164 : /*--------------------------------------------------------------*
165 : * Find the adaptive codebook vector
166 : *--------------------------------------------------------------*/
167 :
168 : 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 );
169 :
170 : tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx );
171 :
172 : /*--------------------------------------------------------------*
173 : * LP filtering of the adaptive excitation
174 : *--------------------------------------------------------------*/
175 : lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx );
176 : /*-----------------------------------------------------------------*
177 : * Transform-domain contribution decoding (active frames)
178 : *-----------------------------------------------------------------*/
179 :
180 : test();
181 : IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) )
182 : {
183 : gain_code_fx = 0;
184 : move16();
185 : 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 );
186 : }
187 :
188 : /*--------------------------------------------------------------*
189 : * Innovation decoding
190 : *--------------------------------------------------------------*/
191 :
192 : 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 );
193 :
194 : /*--------------------------------------------------------------*
195 : * Gain decoding
196 : * Estimate spectrum tilt and voicing
197 : *--------------------------------------------------------------*/
198 :
199 : IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
200 : {
201 : 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 );
202 : }
203 : ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) )
204 : {
205 : 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 );
206 : }
207 : ELSE
208 : {
209 : 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 );
210 : }
211 : st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); // Q15
212 : move16();
213 :
214 : /*-----------------------------------------------------------------*
215 : * Transform domain contribution decoding
216 : *-----------------------------------------------------------------*/
217 : test();
218 : IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) )
219 : {
220 : 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 );
221 : }
222 :
223 : /* update LP filtered gains for the case of frame erasures */
224 : 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 );
225 :
226 : /*----------------------------------------------------------------------*
227 : * Find the total excitation
228 : *----------------------------------------------------------------------*/
229 :
230 : IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */
231 : {
232 : 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,
233 : 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 );
234 : }
235 : ELSE /* Rescaling for 16k core */
236 : {
237 :
238 : 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*/
239 : 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,
240 : 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 );
241 : }
242 :
243 : gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
244 :
245 : /*-----------------------------------------------------------------*
246 : * Add the ACELP pre-quantizer contribution
247 : *-----------------------------------------------------------------*/
248 :
249 : IF( gain_preQ_fx != 0 )
250 : {
251 : IF( st_fx->element_mode == EVS_MONO )
252 : {
253 : tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc );
254 : }
255 : ELSE
256 : {
257 : tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc );
258 : }
259 : FOR( i = 0; i < L_SUBFR; i++ )
260 : {
261 : Word32 Ltmp1;
262 : /* Contribution from AVQ layer */
263 : Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/
264 : Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */
265 :
266 : /* Compute exc2 */
267 : L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); // Q_exc+Q14+1+1
268 : exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
269 : move16();
270 : /* gain_pit in Q14 */
271 : L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1
272 : L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5
273 : L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+Q15 +1
274 : L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
275 :
276 : exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
277 : move16();
278 : }
279 : }
280 : ELSE
281 : {
282 : Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR );
283 : }
284 :
285 : /*-----------------------------------------------------------------*
286 : * Prepare TBE excitation
287 : *-----------------------------------------------------------------*/
288 :
289 : Word16 idx = 0;
290 : move16();
291 : IF( i_subfr_fx != 0 )
292 : {
293 : idx = idiv1616( i_subfr_fx, L_SUBFR );
294 : }
295 :
296 : prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
297 : &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
298 : st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate );
299 :
300 :
301 : /*----------------------------------------------------------------*
302 : * Excitation enhancements (update of total excitation signal)
303 : *----------------------------------------------------------------*/
304 :
305 : test();
306 : IF( GT_32( st_fx->core_brate, ACELP_32k ) || ( st_fx->coder_type == INACTIVE ) )
307 : {
308 : Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR );
309 : }
310 : ELSE
311 : {
312 : enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
313 : 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 );
314 : }
315 :
316 : p_Aq_fx += ( M + 1 );
317 : pt_pitch_fx++;
318 : gain_buf[idx] = gain_pit_fx; // Q14
319 : move16();
320 : }
321 :
322 : /* FEC fast recovery */
323 :
324 : IF( do_WI_fx )
325 : {
326 : /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/
327 : L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/
328 : rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/
329 : shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/
330 :
331 : p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev;
332 : p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev;
333 : move16();
334 : move16();
335 :
336 : prev_res_nrg = L_deposit_l( 1 );
337 : prev_spch_nrg = L_deposit_l( 1 );
338 : FOR( i = 0; i < rint_bfi_pitch; i++ )
339 : {
340 : prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */
341 : prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */
342 : p_exc++;
343 : p_syn++;
344 : }
345 :
346 : Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M );
347 :
348 : 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 );
349 :
350 : L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/
351 : rint_pitch = rint_new_fx( L_tmp ); /*Q0*/
352 : shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/
353 :
354 : p_exc = exc2_fx + shft_curr;
355 : p_syn = syn_tmp_fx + shft_curr;
356 :
357 : curr_res_nrg = L_deposit_l( 1 );
358 : curr_spch_nrg = L_deposit_l( 1 );
359 : FOR( i = 0; i < rint_pitch; i++ )
360 : {
361 : curr_res_nrg = L_mac0_sat( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */
362 : curr_spch_nrg = L_mac0_sat( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */
363 : p_exc++;
364 : p_syn++;
365 : }
366 :
367 : /* enratio = (curr_res_nrg / prev_res_nrg); */
368 : IF( prev_res_nrg > 0 )
369 : {
370 : expa = norm_l( prev_res_nrg );
371 : fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr -16+expa +1*/
372 : expa = sub( 30, add( expa, ( shl( st_fx->prev_Q_exc_fr, 1 ) ) ) );
373 :
374 : expb = norm_l( curr_res_nrg );
375 : fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); /* 2*st_fx->Q_exc +expb+1 -16*/
376 : expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) );
377 :
378 : scale = shr( sub( fraca, fracb ), 15 );
379 : fracb = shl( fracb, scale ); // Q(15-expb)+scale
380 : expb = sub( expb, scale );
381 :
382 : enratio = div_s( fracb, fraca ); // Q(15-(expb-expa))
383 : exp1 = sub( expb, expa );
384 : Qenratio = sub( 15, exp1 );
385 : }
386 : ELSE
387 : {
388 : enratio = 0;
389 : move16();
390 : Qenratio = 0;
391 : move16();
392 : }
393 :
394 : /* sp_enratio = curr_spch_nrg/prev_spch_nrg */
395 : IF( prev_spch_nrg > 0 )
396 : {
397 : expa = norm_l( prev_spch_nrg );
398 : fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr +expa+1-16*/
399 : expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) );
400 :
401 : expb = norm_l( curr_spch_nrg );
402 : fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb-16 */
403 : expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) );
404 :
405 : scale = shr( sub( fraca, fracb ), 15 );
406 : fracb = shl( fracb, scale ); // Q(15-expb) +scale
407 : expb = sub( expb, scale );
408 :
409 : sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa))
410 : exp1 = sub( expb, expa );
411 : Qsp_enratio = sub( 15, exp1 );
412 : }
413 : ELSE
414 : {
415 : sp_enratio = 0;
416 : move16();
417 : Qsp_enratio = 0;
418 : move16();
419 : }
420 :
421 : test();
422 : test();
423 : test();
424 : test();
425 : IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/
426 : LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/
427 : GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/
428 : LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/
429 : LT_16( pitch_buf_fx[NB_SUBFR16k - 1], 9600 ) ) /*Q6*/
430 : {
431 : IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) )
432 : {
433 : return error;
434 : }
435 :
436 : IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) )
437 : {
438 : return error;
439 : }
440 :
441 : GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx );
442 : 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 );
443 : PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr );
444 : move16();
445 :
446 : GetSinCosTab_fx( rint_pitch, S_fx, C_fx );
447 : DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx );
448 : CURRP->Q = add( CURRP->Q, st_fx->Q_exc );
449 : move16();
450 :
451 : ph_offset_fx = 0;
452 : move16();
453 : 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 ) )
454 : {
455 : return error;
456 : }
457 :
458 :
459 : Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
460 : Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
461 :
462 : /* update bwe_exc for SWB-TBE */
463 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
464 : {
465 : interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + shl( i_subfr_fx, 1 ), L_SUBFR );
466 : }
467 :
468 : free( PREVP );
469 : free( CURRP );
470 : }
471 : }
472 :
473 : /* SC-VBR */
474 : st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
475 : move16(); /*Q14*/
476 : st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx;
477 : move16(); /*Q15*/
478 :
479 : return error;
480 : }
481 :
482 : /*======================================================================*/
483 : /* FUNCTION : decod_gen_voic_ivas_fx() */
484 : /*----------------------------------------------------------------------*/
485 : /* PURPOSE : Decode generic (GC), voiced (VC) and AMR-WB IO frames */
486 : /* */
487 : /*----------------------------------------------------------------------*/
488 : /* GLOBAL INPUT ARGUMENTS : */
489 : /* _ (Struct) st_fx : decoder static memory */
490 : /* _ (Word16) L_frame : length of the frame */
491 :
492 : /* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */
493 : /* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */
494 : /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/
495 : /* _ (Word16[]) voice_factors_fx: frame error rate Q15 */
496 : /*----------------------------------------------------------------------*/
497 : /* OUTPUT ARGUMENTS : */
498 : /* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */
499 : /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */
500 : /*----------------------------------------------------------------------*/
501 :
502 :
503 : /*----------------------------------------------------------------------*/
504 : /* RETURN ARGUMENTS : */
505 : /* _ None */
506 : /*======================================================================*/
507 : #endif
508 105524 : ivas_error decod_gen_voic_ivas_fx(
509 : Decoder_State *st_fx, /* i/o: decoder static memory */
510 : const Word16 L_frame, /* i : length of the frame */
511 : const Word16 sharpFlag_fx, /* i : formant sharpening flag */
512 : const Word16 *Aq_fx, /* i : LP filter coefficient Q12*/
513 : const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */
514 : const Word16 do_WI_fx, /* i : do interpolation after a FER */
515 : Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6*/
516 : Word16 *voice_factors_fx, /* o : voicing factors Q15 */
517 : Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */
518 : Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */
519 : Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */
520 : Word16 *unbits, /* number of unused bits */
521 : Word16 *gain_buf,
522 : const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
523 : const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */
524 : )
525 : {
526 :
527 :
528 : Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */
529 : Word16 gain_pit_fx; /* pitch gain Q14 */
530 : Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */
531 : Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */
532 : Word16 gain_inov_fx; /* Innovation gain Q12 */
533 : Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
534 : Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */
535 : Word16 voice_fac_fx; /* voicing factor Q15 */
536 : Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */
537 :
538 : const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */
539 : Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */
540 : Word16 i_subfr_fx, i; /* tmp variables */
541 : Word16 error_fx;
542 : Word16 gain_preQ_fx; /* Gain of prequantizer excitation */
543 : Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */
544 : Word32 norm_gain_preQ_fx;
545 : Word16 pitch_limit_flag_fx;
546 :
547 : Word16 tmp1_fx, gain_code16;
548 : Word32 L_tmp_GC;
549 : Word32 L_tmp;
550 :
551 : Word16 harm_flag_acelp;
552 :
553 : Word16 shft_prev, ph_offset_fx;
554 : Word32 prev_res_nrg;
555 : Word32 prev_spch_nrg;
556 : Word32 curr_res_nrg;
557 : Word32 curr_spch_nrg;
558 : Word16 rint_bfi_pitch, rint_pitch;
559 : Word16 fraca, fracb, expa, expb, scale, exp1;
560 : Word16 *p_exc;
561 : Word16 mem_tmp_fx[M];
562 : Word16 syn_tmp_fx[L_FRAME16k];
563 : Word16 shft_curr;
564 : Word16 *p_syn;
565 : Word16 sp_enratio, Qsp_enratio;
566 : Word16 enratio, Qenratio;
567 : DTFS_STRUCTURE *PREVP, *CURRP;
568 : Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1];
569 : Word16 dummy2[2];
570 : Word16 out_fx[L_FRAME16k];
571 :
572 : Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */
573 : Word16 pf_temp2[MAXLAG_WI];
574 : Word16 pf_temp[MAXLAG_WI];
575 : Word16 pf_n2[MAXLAG_WI];
576 : MUSIC_POSTFILT_HANDLE hMusicPF;
577 105524 : gain_pit_fx = 0;
578 105524 : gain_code_fx = 0;
579 105524 : norm_gain_code_fx = 0;
580 105524 : gain_inov_fx = 0;
581 105524 : error_fx = 0;
582 105524 : gain_preQ_fx = 0;
583 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
584 105524 : Flag Overflow = 0;
585 105524 : move32();
586 : #endif
587 105524 : move16();
588 105524 : move32();
589 105524 : move32();
590 105524 : move16();
591 105524 : move16();
592 105524 : move16();
593 :
594 105524 : hMusicPF = st_fx->hMusicPF;
595 :
596 : GSC_DEC_HANDLE hGSCDec;
597 105524 : hGSCDec = st_fx->hGSCDec;
598 : ivas_error error;
599 :
600 105524 : error = IVAS_ERR_OK;
601 105524 : move32();
602 :
603 105524 : T0_fx = PIT_MIN;
604 105524 : move16();
605 105524 : T0_frac_fx = 0;
606 105524 : move16();
607 :
608 : /* read harmonicity flag */
609 105524 : harm_flag_acelp = 0;
610 105524 : move16();
611 105524 : test();
612 105524 : test();
613 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 ) )
614 : {
615 6629 : harm_flag_acelp = (Word16) get_next_indice_fx( st_fx, 1 );
616 : }
617 :
618 : /*------------------------------------------------------------------*
619 : * ACELP subframe loop
620 : *------------------------------------------------------------------*/
621 :
622 105524 : p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */
623 105524 : pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
624 105524 : norm_gain_preQ_fx = 0;
625 105524 : move32();
626 105524 : gain_preQ_fx = 0;
627 105524 : move16();
628 105524 : set16_fx( code_preQ_fx, 0, L_SUBFR );
629 :
630 585708 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
631 : {
632 : /*----------------------------------------------------------------------*
633 : * Decode pitch lag
634 : *----------------------------------------------------------------------*/
635 :
636 : /**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,
637 : &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR);*/
638 480184 : *pt_pitch_fx = pit_decode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx,
639 : &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
640 480184 : move16(); /*Q6*/
641 :
642 : /*--------------------------------------------------------------*
643 : * Find the adaptive codebook vector
644 : *--------------------------------------------------------------*/
645 :
646 480184 : 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 );
647 :
648 : // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx);
649 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 );
650 :
651 : /*--------------------------------------------------------------*
652 : * LP filtering of the adaptive excitation
653 : *--------------------------------------------------------------*/
654 480184 : lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx );
655 : /*-----------------------------------------------------------------*
656 : * Transform-domain contribution decoding (active frames)
657 : *-----------------------------------------------------------------*/
658 :
659 480184 : test();
660 480184 : IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) )
661 : {
662 45840 : gain_code_fx = 0;
663 45840 : move16();
664 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 );
665 : }
666 :
667 : /*--------------------------------------------------------------*
668 : * Innovation decoding
669 : *--------------------------------------------------------------*/
670 :
671 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 );
672 :
673 : /*--------------------------------------------------------------*
674 : * Gain decoding
675 : * Estimate spectrum tilt and voicing
676 : *--------------------------------------------------------------*/
677 :
678 480184 : IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
679 : {
680 12804 : gain_dec_lbr_ivas_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 );
681 : }
682 467380 : ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) )
683 : {
684 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 );
685 : }
686 : ELSE
687 : {
688 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 );
689 : }
690 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
691 480184 : move16();
692 :
693 : /*-----------------------------------------------------------------*
694 : * Transform domain contribution decoding
695 : *-----------------------------------------------------------------*/
696 480184 : test();
697 480184 : IF( !st_fx->inactive_coder_type_flag && st_fx->coder_type == INACTIVE )
698 : {
699 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 );
700 : }
701 :
702 : /* update LP filtered gains for the case of frame erasures */
703 : #ifdef REMOVE_EVS_DUPLICATES
704 480184 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
705 : {
706 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 );
707 : }
708 : ELSE
709 : #endif
710 : {
711 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 );
712 : }
713 :
714 : /*----------------------------------------------------------------------*
715 : * Find the total excitation
716 : *----------------------------------------------------------------------*/
717 :
718 480184 : IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */
719 : {
720 189744 : IF( ( bwe_exc_fx != NULL ) )
721 : {
722 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,
723 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 );
724 : }
725 : ELSE
726 : {
727 440 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
728 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 );
729 : }
730 : }
731 : ELSE /* Rescaling for 16k core */
732 : {
733 :
734 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*/
735 290440 : IF( bwe_exc_fx != NULL )
736 : {
737 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,
738 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 );
739 : }
740 : ELSE
741 : {
742 0 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
743 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 );
744 : }
745 : }
746 :
747 480184 : gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
748 :
749 : /*-----------------------------------------------------------------*
750 : * Add the ACELP pre-quantizer contribution
751 : *-----------------------------------------------------------------*/
752 :
753 480184 : IF( gain_preQ_fx != 0 )
754 : {
755 54858 : IF( st_fx->element_mode == EVS_MONO )
756 : {
757 3110 : tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc );
758 : }
759 : ELSE
760 : {
761 51748 : tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc );
762 : }
763 3565770 : FOR( i = 0; i < L_SUBFR; i++ )
764 : {
765 : Word32 Ltmp1;
766 : /* Contribution from AVQ layer */
767 3510912 : Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/
768 3510912 : Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */
769 :
770 : /* Compute exc2 */
771 3510912 : L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 );
772 3510912 : exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
773 3510912 : move16();
774 : /* gain_pit in Q14 */
775 3510912 : L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1
776 3510912 : L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5
777 3510912 : L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+16
778 3510912 : L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
779 :
780 3510912 : exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
781 3510912 : move16();
782 : }
783 : }
784 : ELSE
785 : {
786 425326 : Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR );
787 : }
788 :
789 : /*-----------------------------------------------------------------*
790 : * Prepare TBE excitation
791 : *-----------------------------------------------------------------*/
792 :
793 : /*prep_tbe_exc_fx(L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
794 : &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
795 : st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate);*/
796 :
797 : Word16 idx;
798 480184 : idx = 0;
799 480184 : move16();
800 480184 : IF( i_subfr_fx != 0 )
801 : {
802 374660 : idx = idiv1616( i_subfr_fx, L_SUBFR );
803 : }
804 :
805 480184 : prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
806 480184 : &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
807 480184 : st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
808 480184 : st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
809 :
810 :
811 : /*----------------------------------------------------------------*
812 : * Excitation enhancements (update of total excitation signal)
813 : *----------------------------------------------------------------*/
814 :
815 480184 : test();
816 480184 : IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) )
817 : {
818 40955 : Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR );
819 : }
820 : ELSE
821 : {
822 : #ifdef REMOVE_EVS_DUPLICATES
823 439229 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
824 : {
825 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,
826 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 );
827 : }
828 : ELSE
829 : #endif
830 : {
831 436537 : enhancer_ivas_fx2( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
832 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 );
833 : }
834 : }
835 :
836 480184 : p_Aq_fx += ( M + 1 );
837 480184 : move16();
838 480184 : pt_pitch_fx++;
839 480184 : gain_buf[idx] = gain_pit_fx; // Q14
840 480184 : move16();
841 : }
842 :
843 : /* FEC fast recovery */
844 :
845 105524 : IF( do_WI_fx )
846 : {
847 : /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/
848 0 : L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/
849 0 : rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/
850 0 : shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/
851 :
852 0 : p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev;
853 0 : p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev;
854 :
855 0 : prev_res_nrg = 1;
856 0 : move32();
857 0 : prev_spch_nrg = 1;
858 0 : move32();
859 0 : FOR( i = 0; i < rint_bfi_pitch; i++ )
860 : {
861 0 : prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */
862 0 : prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */
863 0 : p_exc++;
864 0 : p_syn++;
865 : }
866 :
867 0 : Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M );
868 :
869 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 );
870 :
871 0 : L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/
872 0 : rint_pitch = rint_new_fx( L_tmp ); /*Q0*/
873 0 : shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/
874 :
875 0 : p_exc = exc2_fx + shft_curr;
876 0 : p_syn = syn_tmp_fx + shft_curr;
877 :
878 0 : curr_res_nrg = 1;
879 0 : move32();
880 0 : curr_spch_nrg = 1;
881 0 : move32();
882 0 : FOR( i = 0; i < rint_pitch; i++ )
883 : {
884 0 : curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */
885 0 : curr_spch_nrg = L_mac0( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */
886 0 : p_exc++;
887 0 : p_syn++;
888 : }
889 :
890 : /* enratio = (curr_res_nrg / prev_res_nrg); */
891 0 : IF( prev_res_nrg > 0 )
892 : {
893 0 : expa = norm_l( prev_res_nrg );
894 0 : fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr +expa -16*/
895 0 : expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) );
896 :
897 0 : expb = norm_l( curr_res_nrg );
898 0 : fracb = round_fx( L_shl( curr_res_nrg, expb ) ); /* 2*st_fx->prev_Q_exc_fr +expb -16*/
899 0 : expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) );
900 :
901 0 : scale = shr( sub( fraca, fracb ), 15 );
902 0 : fracb = shl( fracb, scale ); // Q(15-expb)+scale
903 0 : expb = sub( expb, scale );
904 :
905 0 : enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)
906 0 : exp1 = sub( expb, expa );
907 0 : Qenratio = sub( 15, exp1 );
908 : }
909 : ELSE
910 : {
911 0 : enratio = 0;
912 0 : move16();
913 0 : Qenratio = 0;
914 0 : move16();
915 : }
916 :
917 : /* sp_enratio = curr_spch_nrg/prev_spch_nrg */
918 0 : IF( prev_spch_nrg > 0 )
919 : {
920 0 : expa = norm_l( prev_spch_nrg );
921 0 : fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr -16 +expa */
922 0 : expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) );
923 :
924 0 : expb = norm_l( curr_spch_nrg );
925 0 : fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb -16*/
926 0 : expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) );
927 :
928 0 : scale = shr( sub( fraca, fracb ), 15 );
929 0 : fracb = shl( fracb, scale ); // Q(15-expb)+scale
930 0 : expb = sub( expb, scale );
931 :
932 0 : sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa))
933 0 : exp1 = sub( expb, expa );
934 0 : Qsp_enratio = sub( 15, exp1 );
935 : }
936 : ELSE
937 : {
938 0 : sp_enratio = 0;
939 0 : move16();
940 0 : Qsp_enratio = 0;
941 0 : move16();
942 : }
943 :
944 0 : test();
945 0 : test();
946 0 : test();
947 0 : test();
948 0 : IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/
949 : LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/
950 : GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/
951 : LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/
952 : LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) ) /*Q6*/
953 : {
954 0 : IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) )
955 : {
956 0 : return error;
957 : }
958 :
959 0 : IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) )
960 : {
961 0 : return error;
962 : }
963 :
964 0 : GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx );
965 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 );
966 0 : PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr );
967 0 : move16();
968 :
969 0 : GetSinCosTab_fx( rint_pitch, S_fx, C_fx );
970 0 : DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx );
971 0 : CURRP->Q = add( CURRP->Q, st_fx->Q_exc );
972 0 : move16();
973 :
974 0 : ph_offset_fx = 0;
975 0 : move16();
976 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 ) )
977 : {
978 0 : return error;
979 : }
980 :
981 :
982 0 : Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
983 0 : Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
984 :
985 : /* update bwe_exc for SWB-TBE */
986 0 : FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
987 : {
988 0 : interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR );
989 : }
990 :
991 0 : free( PREVP );
992 0 : free( CURRP );
993 : }
994 : }
995 :
996 : /* SC-VBR */
997 105524 : st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
998 105524 : move16(); /*Q14*/
999 105524 : st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx;
1000 105524 : move16(); /*Q15*/
1001 :
1002 105524 : return error;
1003 : }
|