Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 : #include <stdint.h>
5 : #include "options.h" /* Compilation switches */
6 : #include "cnst.h" /* Common constants */
7 : #include "rom_com_fx.h" /* Static table prototypes */
8 : #include "rom_com.h" /* Static table prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 : #include "prot_fx_enc.h" /* Function prototypes */
11 :
12 : /*======================================================================*/
13 : /* FUNCTION : enc_pit_exc_fx() */
14 : /*----------------------------------------------------------------------*/
15 : /* PURPOSE : Encode pitch only contribution */
16 : /* */
17 : /*----------------------------------------------------------------------*/
18 : /* INPUT ARGUMENTS : */
19 : /* _ (Struct) st_fx : encoder static memory */
20 : /* _ (Word16[]) speech_fx : input speech Qnew-1 */
21 : /* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */
22 : /* _ (Word16[]) A_fx : unquantized A(z) filter */
23 : /* with bandwidth expansion Q12 */
24 : /* _ (Word16) coder_type : coding type */
25 : /* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */
26 : /* _ (Word16[]) T_op_fx : open loop pitch Q0 */
27 : /* _ (Word16[]) voicing_fx : floating pitch values for each subframe Q15*/
28 : /* _ (Word16[]) res_fx : residual signal Q_new */
29 : /* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */
30 : /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */
31 : /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/
32 : /* _ (Word16[]) *wH1, : Weighted impulses response mask */
33 : /* _ (Word16) shift : shift */
34 : /* _ (Word16) Q_new : */
35 : /*-----------------------------------------------------------------------*/
36 : /* OUTPUT ARGUMENTS : */
37 : /* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */
38 : /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */
39 : /* _ (Word16[]) syn_fx :core synthesis */
40 : /* _ (Word16[]) voice_factors_fx: voicing factors Q15 */
41 : /* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE Q0 */
42 : /*-----------------------------------------------------------------------*/
43 :
44 : /*-----------------------------------------------------------------------*/
45 : /* RETURN ARGUMENTS : */
46 : /* _ None */
47 : /*=======================================================================*/
48 7 : void enc_pit_exc_fx(
49 : Encoder_State *st_fx, /* i/o: State structure */
50 : const Word16 *speech, /* i : Input speech Q_new-1*/
51 : const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/
52 : const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/
53 : const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
54 : const Word16 *res, /* i : residual signal Q_new*/
55 : Word16 *synth, /* i/o: core synthesis Q_new*/
56 : Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/
57 : Word16 *T0, /* i/o: close loop integer pitch Q0*/
58 : Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/
59 : Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/
60 : const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
61 : Word16 *gpit, /* o : pitch mean gpit Q15*/
62 : Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/
63 : const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/
64 : const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/
65 : Word16 Q_new,
66 : Word16 shift )
67 : {
68 : Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */
69 : Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */
70 : Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */
71 : Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */
72 : Word16 code[2 * L_SUBFR]; /* Fixed codebook excitation */
73 : Word16 y2[2 * L_SUBFR]; /* Filtered algebraic excitation */
74 : Word16 voice_fac; /* Voicing factor */
75 : Word32 gain_code; /* Gain of code */
76 : Word16 gain_inov; /* inovation gain */
77 : Word16 gain_pit; /* Pitch gain */
78 : Word16 pit_idx, i_subfr; /* tmp variables */
79 : Word16 T0_min, T0_max; /* pitch variables */
80 : Word16 g_corr[10]; /* ACELP correlation values + gain pitch */
81 : Word16 clip_gain, i; /* LSF clip gain and LP flag */
82 : const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */
83 : Word16 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */
84 : Word16 *pt_pitch; /* pointer to floating pitch */
85 : Word16 L_subfr;
86 : Word16 cum_gpit, gpit_tmp;
87 : Word32 Local_BR, Pitch_BR;
88 7 : Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */
89 7 : move16();
90 : Word32 norm_gain_code;
91 : Word16 pitch_limit_flag;
92 : Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */
93 : Word32 Ltmp;
94 : Word32 Lgcode;
95 : Word16 gcode16;
96 : Word16 shift_wsp;
97 : Word16 lp_select, lp_flag;
98 : Word16 use_fcb;
99 : Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
100 : Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/
101 7 : SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
102 7 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
103 7 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
104 7 : LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
105 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
106 7 : Flag Overflow = 0;
107 7 : move32();
108 : #endif
109 :
110 : /*------------------------------------------------------------------*
111 : * Initialization
112 : *------------------------------------------------------------------*/
113 :
114 7 : pitch_limit_flag = 1;
115 7 : move16(); /* always extended pitch Q range */
116 7 : use_fcb = 0;
117 7 : unbits_PI = 0;
118 7 : move16();
119 7 : move16();
120 7 : Pitch_CT = GENERIC;
121 7 : move16();
122 :
123 7 : test();
124 7 : test();
125 7 : IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
126 : {
127 0 : Local_BR = ACELP_8k00;
128 0 : Pitch_BR = ACELP_8k00;
129 0 : move32();
130 0 : move32();
131 0 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
132 : {
133 0 : Local_BR = ACELP_14k80;
134 0 : move32();
135 0 : if ( st_fx->GSC_IVAS_mode > 0 )
136 : {
137 0 : Local_BR = ACELP_9k60;
138 0 : move32();
139 : }
140 0 : Pitch_BR = st_fx->core_brate; /* Q0 */
141 0 : move32();
142 : }
143 : }
144 7 : ELSE IF( st_fx->GSC_noisy_speech )
145 : {
146 0 : Local_BR = ACELP_7k20;
147 0 : move32();
148 0 : Pitch_BR = ACELP_7k20;
149 0 : move32();
150 0 : Pitch_CT = GENERIC;
151 0 : move16();
152 0 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
153 : {
154 0 : Pitch_BR = st_fx->core_brate; /* Q0 */
155 0 : move32();
156 : }
157 : }
158 : ELSE
159 : {
160 :
161 7 : Local_BR = ACELP_7k20;
162 7 : move32();
163 7 : Pitch_BR = st_fx->core_brate; /* Q0 */
164 7 : move32();
165 7 : Pitch_CT = AUDIO;
166 7 : move16();
167 :
168 7 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
169 : {
170 0 : Local_BR = ACELP_13k20;
171 0 : move32();
172 0 : Pitch_CT = GENERIC;
173 0 : move16();
174 : }
175 : }
176 7 : gain_code = 0;
177 7 : move16();
178 :
179 7 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
180 : {
181 0 : T0_max = PIT16k_MAX;
182 0 : T0_min = PIT16k_MIN;
183 : }
184 : ELSE
185 : {
186 7 : T0_max = PIT_MAX;
187 7 : move16();
188 7 : T0_min = PIT_MIN;
189 7 : move16();
190 : }
191 7 : cum_gpit = 0;
192 7 : move16();
193 :
194 7 : L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */
195 :
196 7 : lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */
197 :
198 7 : test();
199 7 : test();
200 7 : test();
201 7 : test();
202 7 : test();
203 7 : test();
204 7 : test();
205 7 : test();
206 7 : IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) &&
207 : ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) ||
208 : ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) &&
209 : EQ_16( L_subfr, L_SUBFR ) ) )
210 : {
211 0 : use_fcb = 1;
212 0 : move16();
213 : }
214 7 : ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) )
215 : {
216 0 : use_fcb = 2;
217 0 : st_fx->acelp_cfg.fcb_mode = 1;
218 0 : move16();
219 0 : move16();
220 0 : set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR );
221 0 : set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR );
222 0 : set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k );
223 : }
224 :
225 7 : *saved_bit_pos = st_fx->next_bit_pos_fx;
226 7 : move16();
227 :
228 : /*------------------------------------------------------------------*
229 : * ACELP subframe loop
230 : *------------------------------------------------------------------*/
231 7 : cn = NULL;
232 7 : if ( EQ_16( L_subfr, L_SUBFR ) )
233 : {
234 0 : cn = cn1;
235 0 : move16();
236 : }
237 7 : p_Aw = Aw;
238 :
239 7 : p_Aq = Aq;
240 7 : pt_pitch = pitch_buf; /* pointer to the pitch buffer */
241 7 : shift_wsp = add( Q_new, shift );
242 21 : FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr )
243 : {
244 :
245 : /*----------------------------------------------------------------*
246 : * Bandwidth expansion of A(z) filter coefficients
247 : * Find the the excitation search target "xn" and innovation
248 : * target in residual domain "cn"
249 : * Compute impulse response, h1[], of weighted synthesis filter
250 : *----------------------------------------------------------------*/
251 14 : Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */
252 : /* condition on target (compared to float) has been put outside the loop */
253 14 : find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
254 14 : res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
255 14 : Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */
256 14 : Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
257 :
258 : /* scaling of xn[] to limit dynamic at 12 bits */
259 14 : Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */
260 :
261 : /*----------------------------------------------------------------*
262 : * Close-loop pitch search and quantization
263 : * Adaptive exc. construction
264 : *----------------------------------------------------------------*/
265 28 : *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc,
266 14 : L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */
267 : /*-----------------------------------------------------------------*
268 : * Find adaptive exitation
269 : *-----------------------------------------------------------------*/
270 :
271 14 : pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
272 : /*-----------------------------------------------------------------*
273 : * Gain clipping test to avoid unstable synthesis on frame erasure
274 : * or in case of floating point encoder & fixed p. decoder
275 : *-----------------------------------------------------------------*/
276 :
277 14 : clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
278 :
279 : /*-----------------------------------------------------------------*
280 : * Codebook target computation
281 : * (No LP filtering of the adaptive excitation)
282 : *-----------------------------------------------------------------*/
283 :
284 14 : lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1,
285 14 : xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
286 :
287 14 : IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
288 : {
289 0 : push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
290 : }
291 :
292 : /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/
293 14 : hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/
294 :
295 14 : gpit_tmp = gain_pit;
296 14 : move16(); /*Q14*/
297 14 : test();
298 14 : IF( use_fcb > 0 )
299 : {
300 : /* h2 in Q12 for codebook search */
301 : /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/
302 0 : Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) );
303 : }
304 :
305 14 : IF( use_fcb == 0 )
306 : {
307 14 : IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) )
308 : {
309 0 : pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 ); /* Q0 */
310 0 : push_indice( hBstr, IND_PIT_IDX, pit_idx, 5 );
311 : }
312 : ELSE
313 : {
314 14 : pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); /* Q0 */
315 14 : push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 );
316 : }
317 : }
318 0 : else if ( use_fcb == 2 )
319 : {
320 : /*-----------------------------------------------------------------*
321 : * Innovation encoding
322 : *-----------------------------------------------------------------*/
323 :
324 0 : inov_encode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq,
325 0 : gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift );
326 :
327 : /*-----------------------------------------------------------------*
328 : * Gain encoding
329 : *-----------------------------------------------------------------*/
330 :
331 0 : gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR );
332 : }
333 : ELSE
334 : {
335 : /*-----------------------------------------------------------------*
336 : * Innovation & gain encoding
337 : *-----------------------------------------------------------------*/
338 :
339 0 : inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq,
340 0 : gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift );
341 : /*-----------------------------------------------------------------*
342 : * Gain encoding
343 : *-----------------------------------------------------------------*/
344 0 : gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred,
345 : &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
346 : }
347 14 : gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );
348 :
349 14 : Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
350 14 : gcode16 = round_fx_sat( Lgcode );
351 14 : IF( use_fcb != 0 )
352 : {
353 0 : hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */
354 0 : move16();
355 : }
356 : ELSE
357 : {
358 14 : hLPDmem->tilt_code = 0;
359 14 : move16();
360 : }
361 : /*-----------------------------------------------------------------*
362 : * Update memory of the weighting filter
363 : *-----------------------------------------------------------------*/
364 14 : IF( use_fcb != 0 )
365 : {
366 0 : Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */
367 0 : Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); /* Q15 + Q_new + shift */
368 0 : Ltmp = L_negate( Ltmp );
369 0 : Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); /* Q_new + Q15 + shift */
370 0 : Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); /* Q_new + Q15 + shift */
371 0 : Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); /* Q_new + 15 */
372 0 : hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */
373 0 : move16();
374 : }
375 : ELSE
376 : {
377 14 : Ltmp = L_mult( xn[L_subfr - 1], 16384 ); /* Q_new + 14 -shift */
378 14 : Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + 14 -shift */
379 14 : Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */
380 14 : hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */
381 14 : move16();
382 : }
383 :
384 : /*-----------------------------------------------------------------*
385 : * Construct adaptive part of the excitation
386 : * Save the non-enhanced excitation for FEC_exc
387 : *-----------------------------------------------------------------*/
388 14 : IF( use_fcb != 0 )
389 : {
390 0 : FOR( i = 0; i < L_subfr; i++ )
391 : {
392 : /* code in Q9, gain_pit in Q14 */
393 0 : Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
394 0 : Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 + Q_new */
395 0 : Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
396 0 : Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q_new + Q16*/
397 0 : exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */
398 0 : move16();
399 : }
400 : }
401 : ELSE
402 : {
403 1806 : FOR( i = 0; i < L_subfr; i++ )
404 : {
405 :
406 1792 : Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
407 1792 : Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */
408 1792 : exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */
409 : }
410 : }
411 :
412 : /*-----------------------------------------------------------------*
413 : * Synthesize speech to update mem_syn[].
414 : * Update A(z) filters
415 : *-----------------------------------------------------------------*/
416 :
417 14 : Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 );
418 :
419 14 : IF( EQ_16( L_subfr, 5 * L_SUBFR ) )
420 : {
421 0 : cum_gpit = gpit_tmp; /* Q14 */
422 0 : move16();
423 0 : pt_pitch++;
424 0 : *pt_pitch = *( pt_pitch - 1 );
425 0 : move16();
426 0 : pt_pitch++;
427 0 : *pt_pitch = *( pt_pitch - 1 );
428 0 : move16();
429 0 : pt_pitch++;
430 0 : *pt_pitch = *( pt_pitch - 1 );
431 0 : move16();
432 0 : pt_pitch++;
433 0 : *pt_pitch = *( pt_pitch - 1 );
434 0 : move16();
435 0 : pt_pitch++;
436 :
437 0 : p_Aw += 5 * ( M + 1 );
438 0 : p_Aq += 5 * ( M + 1 );
439 : }
440 14 : ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) )
441 : {
442 0 : IF( i_subfr == 0 )
443 : {
444 0 : cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */
445 0 : pt_pitch++;
446 0 : *pt_pitch = *( pt_pitch - 1 );
447 0 : move16();
448 0 : pt_pitch++;
449 0 : p_Aw += 2 * ( M + 1 );
450 0 : p_Aq += 2 * ( M + 1 );
451 : }
452 : ELSE
453 : {
454 0 : cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */
455 0 : pt_pitch++;
456 0 : *pt_pitch = *( pt_pitch - 1 );
457 0 : move16();
458 0 : pt_pitch++;
459 0 : *pt_pitch = *( pt_pitch - 1 );
460 0 : move16();
461 0 : pt_pitch++;
462 0 : p_Aw += 3 * ( M + 1 );
463 0 : p_Aq += 3 * ( M + 1 );
464 : }
465 : }
466 14 : ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
467 : {
468 14 : IF( i_subfr == 0 )
469 : {
470 7 : cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */
471 : }
472 : ELSE
473 : {
474 7 : cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */
475 : }
476 14 : p_Aw += 2 * ( M + 1 );
477 14 : move16();
478 14 : p_Aq += 2 * ( M + 1 );
479 14 : move16();
480 14 : pt_pitch++;
481 14 : *pt_pitch = *( pt_pitch - 1 );
482 14 : move16();
483 14 : pt_pitch++;
484 : }
485 0 : ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) )
486 : {
487 0 : cum_gpit = gpit_tmp; /* Q14 */
488 0 : move16();
489 :
490 0 : pt_pitch++;
491 0 : *pt_pitch = *( pt_pitch - 1 );
492 0 : move16();
493 0 : pt_pitch++;
494 0 : *pt_pitch = *( pt_pitch - 1 );
495 0 : move16();
496 0 : pt_pitch++;
497 0 : *pt_pitch = *( pt_pitch - 1 );
498 0 : pt_pitch++;
499 0 : p_Aw += 4 * ( M + 1 );
500 0 : p_Aq += 4 * ( M + 1 );
501 : }
502 : ELSE
503 : {
504 0 : IF( i_subfr == 0 )
505 : {
506 :
507 0 : cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */
508 : }
509 : ELSE
510 : {
511 0 : cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */
512 : }
513 :
514 0 : pt_pitch++;
515 0 : p_Aw += ( M + 1 );
516 0 : p_Aq += ( M + 1 );
517 : }
518 : }
519 :
520 7 : cum_gpit = shl_o( cum_gpit, 1, &Overflow ); /*Q15*/
521 7 : *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/
522 7 : }
523 :
524 15159 : void enc_pit_exc_ivas_fx(
525 : Encoder_State *st_fx, /* i/o: State structure */
526 : const Word16 *speech, /* i : Input speech Q_new-1*/
527 : const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/
528 : const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/
529 : const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
530 : const Word16 *res, /* i : residual signal Q_new*/
531 : Word16 *synth, /* i/o: core synthesis Q_new*/
532 : Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/
533 : Word16 *T0, /* i/o: close loop integer pitch Q0*/
534 : Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/
535 : Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/
536 : const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
537 : Word16 *gpit, /* o : pitch mean gpit Q15*/
538 : Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/
539 : const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/
540 : const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/
541 : Word16 Q_new,
542 : Word16 shift )
543 : {
544 : Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */
545 : Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */
546 : Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */
547 : Word16 cn[PIT_EXC_L_SUBFR];
548 : Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */
549 : Word16 code[2 * L_SUBFR]; /* Fixed codebook excitation */
550 : Word16 y2[2 * L_SUBFR]; /* Filtered algebraic excitation */
551 : Word16 voice_fac; /* Voicing factor */
552 : Word32 gain_code; /* Gain of code */
553 : Word16 gain_inov; /* inovation gain */
554 : Word16 gain_pit; /* Pitch gain */
555 : Word16 pit_idx, i_subfr; /* tmp variables */
556 : Word16 T0_min, T0_max; /* pitch variables */
557 : Word16 g_corr[10]; /* ACELP correlation values + gain pitch */
558 : Word16 clip_gain, i; /* LSF clip gain and LP flag */
559 : const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */
560 : Word16 *pt_pitch; /* pointer to floating pitch */
561 : Word16 L_subfr;
562 : Word16 cum_gpit, gpit_tmp;
563 : Word32 Local_BR, Pitch_BR;
564 15159 : Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */
565 : Word32 norm_gain_code;
566 : Word16 pitch_limit_flag;
567 : Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */
568 : Word32 Ltmp;
569 : Word32 Lgcode;
570 : Word16 gcode16;
571 : Word16 shift_wsp;
572 : Word16 lp_select, lp_flag;
573 : Word16 use_fcb;
574 : Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
575 : Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/
576 : Word16 q_h1;
577 15159 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
578 15159 : GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
579 15159 : LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
580 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
581 15159 : Flag Overflow = 0;
582 15159 : move32();
583 : #endif
584 :
585 : /*------------------------------------------------------------------*
586 : * Initialization
587 : *------------------------------------------------------------------*/
588 :
589 15159 : pitch_limit_flag = 1;
590 15159 : move16(); /* always extended pitch Q range */
591 15159 : use_fcb = 0;
592 15159 : unbits_PI = 0;
593 15159 : move16();
594 15159 : move16();
595 15159 : Pitch_CT = GENERIC;
596 15159 : move16();
597 15159 : set16_fx( cn, 0, PIT_EXC_L_SUBFR );
598 15159 : test();
599 15159 : test();
600 15159 : IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
601 : {
602 112 : Local_BR = ACELP_8k00;
603 112 : Pitch_BR = ACELP_8k00;
604 112 : move32();
605 112 : move32();
606 112 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
607 : {
608 0 : Local_BR = ACELP_14k80;
609 0 : move32();
610 0 : if ( st_fx->GSC_IVAS_mode > 0 )
611 : {
612 0 : Local_BR = ACELP_9k60;
613 0 : move32();
614 : }
615 0 : Pitch_BR = st_fx->core_brate;
616 0 : move32();
617 : }
618 : }
619 15047 : ELSE IF( st_fx->GSC_noisy_speech )
620 : {
621 696 : Local_BR = ACELP_7k20;
622 696 : move32();
623 696 : Pitch_BR = ACELP_7k20;
624 696 : move32();
625 696 : Pitch_CT = GENERIC;
626 696 : move16();
627 696 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
628 : {
629 0 : Pitch_BR = st_fx->core_brate;
630 0 : move32();
631 : }
632 : }
633 : ELSE
634 : {
635 :
636 14351 : Local_BR = ACELP_7k20;
637 14351 : move32();
638 14351 : Pitch_BR = st_fx->core_brate;
639 14351 : move32();
640 14351 : Pitch_CT = AUDIO;
641 14351 : move16();
642 :
643 14351 : if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
644 : {
645 2650 : Local_BR = ACELP_13k20;
646 2650 : move32();
647 2650 : Pitch_CT = GENERIC;
648 2650 : move16();
649 : }
650 : }
651 15159 : gain_code = 0;
652 15159 : move16();
653 :
654 15159 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
655 : {
656 2650 : T0_max = PIT16k_MAX;
657 2650 : T0_min = PIT16k_MIN;
658 : }
659 : ELSE
660 : {
661 12509 : T0_max = PIT_MAX;
662 12509 : move16();
663 12509 : T0_min = PIT_MIN;
664 12509 : move16();
665 : }
666 15159 : cum_gpit = 0;
667 15159 : move16();
668 :
669 15159 : L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */
670 :
671 15159 : lp_flag = st_fx->acelp_cfg.ltf_mode;
672 15159 : move16();
673 :
674 15159 : test();
675 15159 : test();
676 15159 : test();
677 15159 : test();
678 15159 : test();
679 15159 : test();
680 15159 : test();
681 15159 : test();
682 15159 : IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) &&
683 : ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) ||
684 : ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) &&
685 : EQ_16( L_subfr, L_SUBFR ) ) )
686 : {
687 696 : use_fcb = 1;
688 696 : move16();
689 : }
690 14463 : ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) )
691 : {
692 2104 : use_fcb = 2;
693 2104 : st_fx->acelp_cfg.fcb_mode = 1;
694 2104 : move16();
695 2104 : move16();
696 2104 : set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR );
697 2104 : set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR );
698 2104 : set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k );
699 : }
700 :
701 15159 : *saved_bit_pos = st_fx->next_bit_pos_fx; /* Q0 */
702 15159 : move16();
703 :
704 : /*------------------------------------------------------------------*
705 : * ACELP subframe loop
706 : *------------------------------------------------------------------*/
707 15159 : p_Aw = Aw;
708 :
709 15159 : p_Aq = Aq;
710 15159 : pt_pitch = pitch_buf; /* pointer to the pitch buffer */
711 15159 : shift_wsp = add( Q_new, shift );
712 44277 : FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr )
713 : {
714 :
715 : /*----------------------------------------------------------------*
716 : * Bandwidth expansion of A(z) filter coefficients
717 : * Find the the excitation search target "xn" and innovation
718 : * target in residual domain "cn"
719 : * Compute impulse response, h1[], of weighted synthesis filter
720 : *----------------------------------------------------------------*/
721 29118 : Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */
722 : /* condition on target (compared to float) has been put outside the loop */
723 :
724 29118 : find_targets_ivas_new_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq,
725 29118 : res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
726 :
727 29118 : q_h1 = sub( 14, norm_s( h1[0] ) );
728 29118 : Copy_Scale_sig( h1, h2, L_subfr, sub( 11, q_h1 ) ); /*Q11*/
729 :
730 : /* scaling of xn[] to limit dynamic at 12 bits */
731 29118 : Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */
732 :
733 : /*----------------------------------------------------------------*
734 : * Close-loop pitch search and quantization
735 : * Adaptive exc. construction
736 : *----------------------------------------------------------------*/
737 :
738 58236 : *pt_pitch = pit_encode_ivas_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc,
739 29118 : L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new ); /* Q6 */
740 29118 : move16();
741 29118 : Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/
742 :
743 : /*-----------------------------------------------------------------*
744 : * Find adaptive exitation
745 : *-----------------------------------------------------------------*/
746 :
747 29118 : pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
748 : /*-----------------------------------------------------------------*
749 : * Gain clipping test to avoid unstable synthesis on frame erasure
750 : * or in case of floating point encoder & fixed p. decoder
751 : *-----------------------------------------------------------------*/
752 :
753 29118 : clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
754 :
755 : /*-----------------------------------------------------------------*
756 : * Codebook target computation
757 : * (No LP filtering of the adaptive excitation)
758 : *-----------------------------------------------------------------*/
759 29118 : lp_select = lp_filt_exc_enc_ivas_fx( MODE1, AUDIO, i_subfr, exc, h1,
760 29118 : xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
761 29118 : IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
762 : {
763 0 : push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
764 : }
765 :
766 29118 : st_fx->hSpMusClas->lowrate_pitchGain = mac_r( L_mult( 29491 /* 0.9 in Q15 */, st_fx->hSpMusClas->lowrate_pitchGain ), 3277 /* 0.1 in Q15 */, gain_pit ); /* Q14 */
767 :
768 29118 : gpit_tmp = gain_pit;
769 29118 : move16(); /*Q14*/
770 29118 : test();
771 29118 : IF( use_fcb > 0 )
772 : {
773 : /* h2 in Q12 for codebook search */
774 : /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/
775 6992 : Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) );
776 : }
777 :
778 29118 : IF( use_fcb == 0 )
779 : {
780 22126 : IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) )
781 : {
782 875 : pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 );
783 875 : push_indice( hBstr, IND_PIT_IDX, pit_idx, 5 );
784 : }
785 : ELSE
786 : {
787 21251 : pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 );
788 21251 : push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 );
789 : }
790 : }
791 6992 : else if ( use_fcb == 2 )
792 : {
793 : /*-----------------------------------------------------------------*
794 : * Innovation encoding
795 : *-----------------------------------------------------------------*/
796 :
797 4208 : inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq,
798 4208 : gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift, Q_new );
799 :
800 : /*-----------------------------------------------------------------*
801 : * Gain encoding
802 : *-----------------------------------------------------------------*/
803 :
804 4208 : gain_enc_lbr_ivas_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, sub( shift_wsp, 1 ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR );
805 : }
806 : ELSE
807 : {
808 : /*-----------------------------------------------------------------*
809 : * Innovation & gain encoding
810 : *-----------------------------------------------------------------*/
811 :
812 2784 : inov_encode_ivas_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq,
813 2784 : gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new );
814 : /*-----------------------------------------------------------------*
815 : * Gain encoding
816 : *-----------------------------------------------------------------*/
817 2784 : gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred,
818 : &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
819 : }
820 29118 : gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );
821 :
822 29118 : Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
823 29118 : gcode16 = round_fx_sat( Lgcode );
824 29118 : IF( use_fcb != 0 )
825 : {
826 6992 : hLPDmem->tilt_code = est_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15
827 6992 : move16();
828 : }
829 : ELSE
830 : {
831 22126 : hLPDmem->tilt_code = 0;
832 22126 : move16();
833 : }
834 : /*-----------------------------------------------------------------*
835 : * Update memory of the weighting filter
836 : *-----------------------------------------------------------------*/
837 29118 : IF( use_fcb != 0 )
838 : {
839 6992 : Ltmp = L_mult0( gcode16, y2[L_subfr - 1] );
840 6992 : Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); // Q_new+14+shift
841 6992 : Ltmp = L_negate( Ltmp );
842 6992 : Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); // Q_new-1+15+shift
843 6992 : Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); // Q_new-1+15+shift
844 6992 : Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); // Q_new+15
845 6992 : hGSCEnc->mem_w0_tmp_fx = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */
846 : }
847 : ELSE
848 : {
849 22126 : Ltmp = L_mult( xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift
850 22126 : Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift
851 22126 : Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15
852 22126 : hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */
853 : }
854 :
855 : /*-----------------------------------------------------------------*
856 : * Construct adaptive part of the excitation
857 : * Save the non-enhanced excitation for FEC_exc
858 : *-----------------------------------------------------------------*/
859 29118 : IF( use_fcb != 0 )
860 : {
861 723792 : FOR( i = 0; i < L_subfr; i++ )
862 : {
863 : /* code in Q9, gain_pit in Q14 */
864 716800 : Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
865 716800 : Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 + Q_new */
866 716800 : Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
867 716800 : Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new */
868 716800 : exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */
869 716800 : move16();
870 : }
871 : }
872 : ELSE
873 : {
874 3355630 : FOR( i = 0; i < L_subfr; i++ )
875 : {
876 :
877 3333504 : Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
878 3333504 : Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */
879 3333504 : exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */
880 3333504 : move16();
881 : }
882 : }
883 :
884 : /*-----------------------------------------------------------------*
885 : * Synthesize speech to update mem_syn[].
886 : * Update A(z) filters
887 : *-----------------------------------------------------------------*/
888 :
889 29118 : Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 );
890 :
891 29118 : IF( EQ_16( L_subfr, 5 * L_SUBFR ) )
892 : {
893 2650 : cum_gpit = gpit_tmp;
894 2650 : move16();
895 2650 : pt_pitch++;
896 2650 : *pt_pitch = *( pt_pitch - 1 );
897 2650 : move16();
898 2650 : pt_pitch++;
899 2650 : *pt_pitch = *( pt_pitch - 1 );
900 2650 : move16();
901 2650 : pt_pitch++;
902 2650 : *pt_pitch = *( pt_pitch - 1 );
903 2650 : move16();
904 2650 : pt_pitch++;
905 2650 : *pt_pitch = *( pt_pitch - 1 );
906 2650 : move16();
907 2650 : pt_pitch++;
908 :
909 2650 : p_Aw += 5 * ( M + 1 );
910 2650 : p_Aq += 5 * ( M + 1 );
911 : }
912 26468 : ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) )
913 : {
914 0 : IF( i_subfr == 0 )
915 : {
916 0 : cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */
917 0 : pt_pitch++;
918 0 : *pt_pitch = *( pt_pitch - 1 );
919 0 : move16();
920 0 : pt_pitch++;
921 0 : p_Aw += 2 * ( M + 1 );
922 0 : p_Aq += 2 * ( M + 1 );
923 : }
924 : ELSE
925 : {
926 0 : cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */
927 0 : pt_pitch++;
928 0 : *pt_pitch = *( pt_pitch - 1 );
929 0 : move16();
930 0 : pt_pitch++;
931 0 : *pt_pitch = *( pt_pitch - 1 );
932 0 : move16();
933 0 : pt_pitch++;
934 0 : p_Aw += 3 * ( M + 1 );
935 0 : p_Aq += 3 * ( M + 1 );
936 : }
937 : }
938 26468 : ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
939 : {
940 6774 : IF( i_subfr == 0 )
941 : {
942 3387 : cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */
943 : }
944 : ELSE
945 : {
946 3387 : cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */
947 : }
948 6774 : p_Aw += 2 * ( M + 1 );
949 6774 : move16();
950 6774 : p_Aq += 2 * ( M + 1 );
951 6774 : move16();
952 6774 : pt_pitch++;
953 6774 : *pt_pitch = *( pt_pitch - 1 );
954 6774 : move16();
955 6774 : pt_pitch++;
956 : }
957 19694 : ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) )
958 : {
959 5598 : cum_gpit = gpit_tmp;
960 5598 : move16();
961 :
962 5598 : pt_pitch++;
963 5598 : *pt_pitch = *( pt_pitch - 1 );
964 5598 : move16();
965 5598 : pt_pitch++;
966 5598 : *pt_pitch = *( pt_pitch - 1 );
967 5598 : move16();
968 5598 : pt_pitch++;
969 5598 : *pt_pitch = *( pt_pitch - 1 );
970 5598 : pt_pitch++;
971 5598 : p_Aw += 4 * ( M + 1 );
972 5598 : p_Aq += 4 * ( M + 1 );
973 : }
974 : ELSE
975 : {
976 14096 : IF( i_subfr == 0 )
977 : {
978 :
979 3524 : cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */
980 : }
981 : ELSE
982 : {
983 10572 : cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */
984 : }
985 :
986 14096 : pt_pitch++;
987 14096 : p_Aw += ( M + 1 );
988 14096 : p_Aq += ( M + 1 );
989 : }
990 : }
991 :
992 15159 : cum_gpit = shl_o( cum_gpit, 1, &Overflow ); /*Q15*/
993 15159 : *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/
994 15159 : }
|