Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 : #include <assert.h>
5 : #include <stdint.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h" /* Common constants */
8 : #include "prot_fx.h" /* Function prototypes */
9 : #include "rom_com.h"
10 : #include "prot_fx_enc.h" /* Function prototypes */
11 :
12 : /*-------------------------------------------------------------------*
13 : * encod_unvoiced()
14 : *
15 : * Encode unvoiced (UC) frames
16 : *-------------------------------------------------------------------*/
17 : /*fixed point implementation of unvoiced_encoder*/
18 0 : void encod_unvoiced_fx(
19 : Encoder_State *st_fx, /* i/o: state structure */
20 : const Word16 *speech_fx, /* i : Input speech Q_new*/
21 : const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
22 : const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/
23 : const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
24 : const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/
25 : const Word16 *res_fx, /* i : residual signal Q_new*/
26 : Word16 *syn_fx, /* o : core synthesis Q_new -1 */
27 : Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/
28 : Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
29 : Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
30 : Word16 *voice_factors_fx, /* o : voicing factors Q15*/
31 : Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/
32 : const Word16 Q_new,
33 : const Word16 shift )
34 : {
35 : Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */
36 : Word16 h1_fx[L_SUBFR]; /* Impulse response vector */
37 : Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */
38 : Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */
39 : Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */
40 : Word16 gain_pit_fx; /* Pitch gain */
41 : Word16 voice_fac_fx; /* Voicing factor */
42 : Word32 L_gain_code_fx; /* gain of code */
43 : Word16 gain_inov_fx; /* inovative gain */
44 : Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */
45 : Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */
46 : Word16 code2[L_SUBFR]; /* Gaussian excitation */
47 : Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */
48 0 : Word16 prm_t[2 * NPRM_DIV], *prm = prm_t;
49 : const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */
50 : Word32 norm_gain_code_fx;
51 : ACELP_config *acelp_cfg;
52 : ACELP_CbkCorr g_corr;
53 : Word32 gain_code2;
54 : Word32 gain_code_vect[2], Ltmp, Ltmp2;
55 : Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i;
56 : Word16 index, i_subfr_idx;
57 0 : acelp_cfg = &( st_fx->acelp_cfg );
58 0 : SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
59 0 : LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
60 :
61 : /*------------------------------------------------------------------*
62 : * Initializations
63 : *------------------------------------------------------------------*/
64 0 : gain_pit_fx = 0;
65 0 : move16();
66 :
67 0 : test();
68 0 : test();
69 0 : test();
70 0 : IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) || EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) )
71 : {
72 : /* SC_VBR - reset the encoder, to avoid memory not updated issue for the
73 : case when UNVOICED mode is used to code inactive speech */
74 0 : CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 1 );
75 : }
76 :
77 0 : p_Aw_fx = Aw_fx;
78 0 : p_Aq_fx = Aq_fx;
79 0 : pt_pitch_fx = pitch_buf_fx;
80 0 : move16();
81 0 : Q_xn = add( sub( Q_new, 1 ), shift );
82 0 : Q_new_p5 = add( Q_new, 5 );
83 :
84 :
85 0 : FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
86 : {
87 : /*----------------------------------------------------------------*
88 : * Bandwidth expansion of A(z) filter coefficients
89 : * Find the excitation search target "xn" and innovation target in residual domain "cn"
90 : * Compute impulse response, h1[], of weighted synthesis filter
91 : *----------------------------------------------------------------*/
92 0 : i_subfr_idx = shr( i_subfr, 6 );
93 0 : Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
94 :
95 0 : find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
96 0 : res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );
97 :
98 : /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/
99 0 : Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
100 :
101 : /* scaling of xn[] to limit dynamic at 12 bits */
102 0 : Scale_sig( xn_fx, L_SUBFR, shift );
103 : /*----------------------------------------------------------------*
104 : * Unvoiced subframe processing
105 : *----------------------------------------------------------------*/
106 0 : IF( !uc_two_stage_flag )
107 : {
108 0 : *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx,
109 : &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx,
110 : &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */
111 : }
112 : ELSE
113 : {
114 : /*----------------------------------------------------------------*
115 : * Unvoiced subframe processing in two stages
116 : *----------------------------------------------------------------*/
117 :
118 : /* No adaptive codebook (UC) */
119 0 : set16_fx( y1, 0, L_SUBFR );
120 0 : set16_fx( exc_fx + i_subfr, 0, L_SUBFR );
121 :
122 : /*-----------------------------------------------------------------*
123 : * Gain clipping test to avoid unstable synthesis on frame erasure
124 : * or in case of floating point encoder & fixed p. decoder
125 : *-----------------------------------------------------------------*/
126 0 : Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn );
127 0 : *pt_pitch_fx = L_SUBFR;
128 0 : move16();
129 : /*----------------------------------------------------------------------*
130 : * Encode the algebraic innovation *
131 : *----------------------------------------------------------------------*/
132 :
133 0 : E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate );
134 :
135 0 : E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn );
136 :
137 0 : g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */
138 0 : g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */
139 0 : g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */
140 0 : g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */
141 :
142 0 : assert( gain_pit_fx == 0 );
143 0 : gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift );
144 :
145 : /*----------------------------------------------------------*
146 : * - Compute the fixed codebook gain *
147 : * - quantize fixed codebook gain *
148 : *----------------------------------------------------------*/
149 :
150 0 : index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2,
151 0 : st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); /* Q0 */
152 :
153 : #ifdef DEBUGGING
154 : assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" );
155 : #endif
156 0 : push_indice( st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx] );
157 :
158 0 : gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
159 :
160 0 : gain_code_vect[0] = L_gain_code_fx;
161 0 : move32();
162 0 : gain_code_vect[1] = L_gain_code_fx;
163 0 : move32();
164 :
165 : /*----------------------------------------------------------*
166 : * - voice factor (for pitch enhancement) *
167 : *----------------------------------------------------------*/
168 0 : E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift );
169 :
170 0 : IF( st_fx->Opt_RF_ON )
171 : {
172 0 : st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code;
173 : }
174 : /*-----------------------------------------------------------------*
175 : * Update memory of the weighting filter
176 : *-----------------------------------------------------------------*/
177 : /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
178 0 : Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); /* Q10 */
179 0 : Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); /* Q15 + Q_xn */
180 0 : Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); /* Q15 + Q_xn */
181 : /* Add Gaussian contribution*/
182 0 : Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); /* Q10 */
183 0 : Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); /* Q15 + Q_xn */
184 0 : Ltmp = L_add( Ltmp, Ltmp2 ); /* Q15 + Q_xn */
185 0 : hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); /* Q_xn */
186 0 : move16();
187 : BASOP_SATURATE_WARNING_OFF_EVS;
188 0 : hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/
189 : BASOP_SATURATE_WARNING_ON_EVS;
190 :
191 : /*-------------------------------------------------------*
192 : * - Find the total excitation. *
193 : *-------------------------------------------------------*/
194 :
195 0 : tmp2 = shr( L_SUBFR, 1 );
196 0 : FOR( j = 0; j < 2; j++ )
197 : {
198 0 : FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ )
199 : {
200 : /* code in Q9, gain_pit in Q14; exc Q_new */
201 0 : Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */
202 0 : Ltmp = L_shl( Ltmp, Q_new_p5 ); /* Q15 + Q_new */
203 0 : Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); /* Q_new + Q15 */
204 0 : Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); /* Q10 */
205 0 : Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */
206 0 : Ltmp = L_add( Ltmp, Ltmp2 ); /* Q15 + Q_new */
207 0 : Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */
208 0 : exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */
209 : }
210 0 : tmp2 = L_SUBFR;
211 0 : move16();
212 : }
213 : }
214 :
215 0 : *tmp_noise_fx = extract_h( norm_gain_code_fx ); /* Q0 */
216 0 : voice_factors_fx[i_subfr / L_SUBFR] = 0;
217 0 : move16();
218 :
219 0 : interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR );
220 :
221 : /*-----------------------------------------------------------------*
222 : * Synthesize speech to update mem_syn[].
223 : * Update A(z) filters
224 : *-----------------------------------------------------------------*/
225 0 : Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
226 :
227 0 : p_Aw_fx += ( M + 1 );
228 0 : p_Aq_fx += ( M + 1 );
229 0 : pt_pitch_fx++;
230 : }
231 :
232 : /* SC-VBR */
233 0 : hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */
234 0 : move16();
235 0 : hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
236 0 : move16();
237 :
238 0 : return;
239 : }
240 :
241 2000 : void encod_unvoiced_ivas_fx(
242 : Encoder_State *st_fx, /* i/o: state structure */
243 : const Word16 *speech_fx, /* i : Input speech Q_new*/
244 : const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
245 : const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/
246 : const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
247 : const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/
248 : const Word16 *res_fx, /* i : residual signal Q_new*/
249 : Word16 *syn_fx, /* o : core synthesis Q_new*/
250 : Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/
251 : Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
252 : Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
253 : Word16 *voice_factors_fx, /* o : voicing factors Q15*/
254 : Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/
255 : const Word16 Q_new,
256 : const Word16 shift )
257 : {
258 : Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */
259 : Word16 h1_fx[L_SUBFR]; /* Impulse response vector */
260 : Word16 h2_fx[L_SUBFR]; /* Impulse response vector */
261 : Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */
262 : Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */
263 : Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */
264 : Word16 gain_pit_fx; /* Pitch gain */
265 : Word16 voice_fac_fx; /* Voicing factor */
266 : Word32 L_gain_code_fx; /* gain of code */
267 : Word16 gain_inov_fx; /* inovative gain */
268 : Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */
269 : Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */
270 : Word16 code2[L_SUBFR]; /* Gaussian excitation */
271 : Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */
272 : // Word16 prm_t[2 * NPRM_DIV], *prm = prm_t;
273 : const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */
274 : Word32 norm_gain_code_fx;
275 : ACELP_config *acelp_cfg;
276 : ACELP_CbkCorr g_corr;
277 : Word32 gain_code2;
278 : Word32 gain_code_vect[2], Ltmp, Ltmp2;
279 : Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i;
280 : Word16 index, i_subfr_idx;
281 : Word16 unbits_PI;
282 : Word16 q_h1;
283 2000 : acelp_cfg = &( st_fx->acelp_cfg );
284 2000 : SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
285 2000 : LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
286 :
287 : /*------------------------------------------------------------------*
288 : * Initializations
289 : *------------------------------------------------------------------*/
290 2000 : gain_pit_fx = 0;
291 2000 : move16();
292 :
293 2000 : test();
294 2000 : test();
295 2000 : test();
296 2000 : IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) || EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) )
297 : {
298 : /* SC_VBR - reset the encoder, to avoid memory not updated issue for the
299 : case when UNVOICED mode is used to code inactive speech */
300 0 : CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 1 );
301 : }
302 :
303 2000 : p_Aw_fx = Aw_fx;
304 2000 : p_Aq_fx = Aq_fx;
305 2000 : pt_pitch_fx = pitch_buf_fx;
306 2000 : Q_xn = add( sub( Q_new, 1 ), shift );
307 2000 : Q_new_p5 = add( Q_new, 5 );
308 :
309 :
310 10000 : FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
311 : {
312 : /*----------------------------------------------------------------*
313 : * Bandwidth expansion of A(z) filter coefficients
314 : * Find the excitation search target "xn" and innovation target in residual domain "cn"
315 : * Compute impulse response, h1[], of weighted synthesis filter
316 : *----------------------------------------------------------------*/
317 8000 : i_subfr_idx = shr( i_subfr, 6 );
318 8000 : Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
319 :
320 8000 : find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
321 8000 : res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );
322 :
323 8000 : q_h1 = sub( 14, norm_s( h1_fx[0] ) );
324 8000 : Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) );
325 8000 : Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) );
326 :
327 : /* scaling of xn[] to limit dynamic at 12 bits */
328 8000 : Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift
329 : /*----------------------------------------------------------------*
330 : * Unvoiced subframe processing
331 : *----------------------------------------------------------------*/
332 8000 : IF( !uc_two_stage_flag )
333 : {
334 0 : *pt_pitch_fx = gaus_encode_ivas_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx,
335 : &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx,
336 : &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */
337 0 : move16();
338 : }
339 : ELSE
340 : {
341 : /*----------------------------------------------------------------*
342 : * Unvoiced subframe processing in two stages
343 : *----------------------------------------------------------------*/
344 : // PMT("The code below needs validation, never been tested")
345 : /* No adaptive codebook (UC) */
346 8000 : set16_fx( y1, 0, L_SUBFR );
347 8000 : set16_fx( exc_fx + i_subfr, 0, L_SUBFR );
348 : /*-----------------------------------------------------------------*
349 : * Gain clipping test to avoid unstable synthesis on frame erasure
350 : * or in case of floating point encoder & fixed p. decoder
351 : *-----------------------------------------------------------------*/
352 8000 : Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn );
353 8000 : *pt_pitch_fx = L_SUBFR << 6;
354 8000 : move16();
355 : /*----------------------------------------------------------------------*
356 : * Encode the algebraic innovation *
357 : *----------------------------------------------------------------------*/
358 :
359 : // E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate, st_fx->element_mode );
360 8000 : inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame,
361 8000 : UNVOICED, st_fx->bwidth, st_fx->sharpFlag, i_subfr, -1, p_Aq_fx,
362 8000 : gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new );
363 :
364 8000 : E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn );
365 :
366 8000 : g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */
367 8000 : g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */
368 8000 : g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */
369 8000 : g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */
370 8000 : move16();
371 8000 : move16();
372 8000 : move16();
373 8000 : move16();
374 :
375 8000 : assert( gain_pit_fx == 0 );
376 8000 : gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift );
377 :
378 : /*----------------------------------------------------------*
379 : * - Compute the fixed codebook gain *
380 : * - quantize fixed codebook gain *
381 : *----------------------------------------------------------*/
382 :
383 8000 : index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2,
384 8000 : st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); /* Q0 */
385 :
386 : #ifdef DEBUGGING
387 : assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" );
388 : #endif
389 8000 : push_indice( st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx] );
390 :
391 8000 : gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
392 :
393 8000 : gain_code_vect[0] = L_gain_code_fx;
394 8000 : move32();
395 8000 : gain_code_vect[1] = L_gain_code_fx;
396 8000 : move32();
397 :
398 : /*----------------------------------------------------------*
399 : * - voice factor (for pitch enhancement) *
400 : *----------------------------------------------------------*/
401 8000 : E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift );
402 :
403 8000 : if ( st_fx->Opt_RF_ON )
404 : {
405 0 : st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code;
406 0 : move16();
407 : }
408 : /*-----------------------------------------------------------------*
409 : * Update memory of the weighting filter
410 : *-----------------------------------------------------------------*/
411 : /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
412 8000 : Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); /* Q10 */
413 8000 : Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); // Qxn+15
414 8000 : Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); /* Qxn + Q15 */
415 : /* Add Gaussian contribution*/
416 8000 : Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); /* Q10 */
417 8000 : Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); // Q_xn+15
418 8000 : Ltmp = L_add( Ltmp, Ltmp2 ); /* Qxn + Q15 */
419 8000 : hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); // Q_xn
420 8000 : move16();
421 : BASOP_SATURATE_WARNING_OFF_EVS;
422 8000 : hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/
423 8000 : move16();
424 : BASOP_SATURATE_WARNING_ON_EVS;
425 :
426 : /*-------------------------------------------------------*
427 : * - Find the total excitation. *
428 : *-------------------------------------------------------*/
429 :
430 8000 : tmp2 = shr( L_SUBFR, 1 );
431 24000 : FOR( j = 0; j < 2; j++ )
432 : {
433 528000 : FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ )
434 : {
435 : /* code in Q9, gain_pit in Q14; exc Q_new */
436 512000 : Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */
437 512000 : Ltmp = L_shl_sat( Ltmp, Q_new_p5 ); /* Q15 + Q_new */
438 512000 : Ltmp = L_mac_sat( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); /* Q15 + Q_new */
439 512000 : Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); /* Q10 */
440 512000 : Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */
441 512000 : Ltmp = L_add_sat( Ltmp, Ltmp2 ); /* Q15 + Q_new */
442 512000 : Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */
443 512000 : exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */
444 512000 : move16();
445 : }
446 16000 : tmp2 = L_SUBFR;
447 16000 : move16();
448 : }
449 : }
450 :
451 8000 : *tmp_noise_fx = extract_h( norm_gain_code_fx );
452 8000 : move16();
453 8000 : voice_factors_fx[i_subfr / L_SUBFR] = 0;
454 8000 : move16();
455 :
456 8000 : if ( st_fx->hBWE_TD != NULL )
457 : {
458 8000 : interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR );
459 : }
460 :
461 : /*-----------------------------------------------------------------*
462 : * Synthesize speech to update mem_syn[].
463 : * Update A(z) filters
464 : *-----------------------------------------------------------------*/
465 8000 : Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
466 :
467 8000 : p_Aw_fx += ( M + 1 );
468 8000 : p_Aq_fx += ( M + 1 );
469 8000 : pt_pitch_fx++;
470 : }
471 :
472 : /* SC-VBR */
473 2000 : IF( hSC_VBR )
474 : {
475 0 : hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */
476 0 : move16();
477 0 : hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
478 0 : move16();
479 : }
480 :
481 2000 : return;
482 : }
|