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 "prot_fx.h" /* Function prototypes */
8 : #include "basop_util.h"
9 : #include "rom_com_fx.h" /* Static table prototypes */
10 : #include "rom_com.h" /* Static table prototypes */
11 : #include "prot_fx.h" /* Function prototypes */
12 : #include "ivas_prot_fx.h" /* Function prototypes */
13 : #include "prot_fx_enc.h" /* Function prototypes */
14 :
15 :
16 : /*==============================================================================*/
17 : /* FUNCTION : inov_encode_fx() */
18 : /*------------------------------------------------------------------------------*/
19 : /* PURPOSE : Encode the algebraic innovation */
20 : /*------------------------------------------------------------------------------*/
21 : /* INPUT ARGUMENTS : */
22 : /* _ (Word16) core_brate: core bitrate Q0 */
23 : /* _ (Word16) Opt_AMR_WB: flag indicating AMR-WB IO mode Q0 */
24 : /* _ (Word16) bwidth : input signal bandwidth Q0 */
25 : /* _ (Word16) L_frame_fx : length of the frame Q0 */
26 : /* _ (Word16[]) h2 : weighted filter input response Q12 */
27 : /* _ (Word16[]) xn2 : target vector Q_new */
28 : /* _ (Word16) coder_type : coding type Q0 */
29 : /* _ (Word16) i_subfr : current sub frame indicator Q0 */
30 : /* _ (Word16[]) exc_fx : pointer to excitation signal frame Q_new */
31 : /* _ (Word16) L_subfr : subframe length Q0 */
32 : /* _ (Word16) clip_gain : adaptive gain clipping flag Q0 */
33 : /* _ (Word16) gain_pit : adaptive excitation gain Q14 */
34 : /* _ (Word16) sharpFlag : formant sharpening flag Q0 */
35 : /* _ (Word16) tc_subfr : TC subframe index Q0 */
36 : /* _ (Word16) p_Aq : LP filter coefficients Q12 */
37 : /* _ (Word16) Jopt_flag :joint optimization flag Q0 */
38 : /* _ (Word16) y1 : Filtered adaptive excitation Q_new */
39 : /* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */
40 : /* _ (Word16) cn : target vector in residual domain Q_new */
41 : /* _ (Word16) tilt_code : tilt of the excitation of previous subframe Q15 */
42 : /* _ (Word16) pt_pitch : pointer to current subframe fractional pitchQ6 */
43 : /* _ (Word16) index_buf_4T :5Sx4Track buffer for PI Q0 */
44 : /* _ (Word16) shift :shift */
45 : /* _ (Word16) Q_new : */
46 : /*------------------------------------------------------------------------------*/
47 : /* OUTPUT ARGUMENTS : */
48 : /* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */
49 : /* _ (Word16) cn : target vector in residual domain Q_new */
50 : /* _ (Word16) code :algebraic excitation Q9 */
51 : /* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */
52 : /* _ (Word16) unbits :number of unused bits for PI Q0 */
53 : /*------------------------------------------------------------------------------*/
54 :
55 : /*------------------------------------------------------------------------------*/
56 : /* RETURN ARGUMENTS : */
57 : /* _ None */
58 : /*==============================================================================*/
59 :
60 6388 : Word16 inov_encode_fx(
61 : Encoder_State *st_fx, /* i/o: encoder state structure */
62 : const Word32 core_brate, /* i : core bitrate */
63 : const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
64 : const Word16 L_frame, /* i : length of the frame */
65 : const Word16 last_L_frame, /* i : length of the last frame */
66 : const Word16 coder_type, /* i : coding type */
67 : const Word16 bwidth, /* i : input signal bandwidth */
68 : const Word16 sharpFlag, /* i : formant sharpening flag */
69 : const Word16 i_subfr, /* i : subframe index */
70 : const Word16 tc_subfr, /* i : TC subframe index */
71 : const Word16 *p_Aq, /* i : LP filter coefficients Q12*/
72 : const Word16 gain_pit, /* i : adaptive excitation gain Q14*/
73 : Word16 *cn, /* i/o: target vector in residual domain Q_new*/
74 : const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/
75 : Word16 *h2, /* i/o: weighted filter input response Q12*/
76 : const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/
77 : const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/
78 : const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/
79 : Word16 *code, /* o : algebraic excitation Q9*/
80 : Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/
81 : Word16 *unbits, /* o : number of unused bits for PI */
82 : const Word16 L_subfr, /* i : subframe length */
83 : Word16 shift )
84 : {
85 : Word16 dn[2 * L_SUBFR];
86 : Word16 nBits, cmpl_flag;
87 : Word16 stack_pulses;
88 : Word16 g1, g2;
89 : Word16 Rw[L_SUBFR];
90 : Word16 acelpautoc;
91 6388 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
92 : (void) last_L_frame;
93 6388 : stack_pulses = 0;
94 6388 : move16();
95 :
96 6388 : IF( EQ_16( L_frame, L_FRAME ) )
97 : {
98 2996 : g1 = FORMANT_SHARPENING_G1;
99 2996 : move16();
100 2996 : g2 = FORMANT_SHARPENING_G2;
101 2996 : move16();
102 : }
103 : ELSE
104 : {
105 3392 : g1 = FORMANT_SHARPENING_G1_16k;
106 3392 : move16();
107 3392 : g2 = FORMANT_SHARPENING_G2_16k;
108 3392 : move16();
109 : }
110 :
111 : /*----------------------------------------------------------------*
112 : * Update target vector for codebook search in residual domain
113 : * Preemphasize the impulse response and include fixed-gain pitch contribution into impulse resp. h1[] (pitch sharpenning)
114 : * Correlation between target xn2[] and impulse response h1[]
115 : *----------------------------------------------------------------*/
116 :
117 6388 : test();
118 6388 : test();
119 6388 : IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) )
120 : {
121 3392 : acelpautoc = 1;
122 3392 : move16();
123 :
124 3392 : cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_SUBFR );
125 : /* h2: Q11, Rw: (Rw_e)Q */
126 3392 : /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 );
127 :
128 3392 : E_ACELP_conv( xn2, h2, cn );
129 :
130 : /* dn_e -> Rw_e*Q_xn */
131 3392 : /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 );
132 : }
133 : ELSE
134 : {
135 2996 : acelpautoc = 0;
136 2996 : move16();
137 2996 : updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr );
138 : /* scaling of cn[] to limit dynamic at 12 bits */
139 2996 : Scale_sig( cn, L_subfr, shift );
140 :
141 2996 : cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr );
142 2996 : corr_xh_fx( xn2, dn, h2 );
143 : }
144 :
145 : /*-----------------------------------------------------------------*
146 : * Set complexity reduction flag to limit the number of iterations
147 : * in algebraic innovation search
148 : *-----------------------------------------------------------------*/
149 6388 : cmpl_flag = 0;
150 6388 : move16();
151 6388 : test();
152 6388 : IF( st_fx->acelp_cfg.fcb_mode )
153 : {
154 : /* set number of iterations in TD stereo, secondary channel */
155 0 : test();
156 0 : if ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) )
157 : {
158 0 : cmpl_flag = 1;
159 0 : move16();
160 : }
161 : }
162 6388 : ELSE IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) )
163 : {
164 284 : test();
165 284 : test();
166 284 : if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) )
167 : {
168 0 : cmpl_flag = 3;
169 0 : move16();
170 : }
171 284 : test();
172 284 : test();
173 284 : test();
174 284 : test();
175 284 : test();
176 284 : if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) )
177 : {
178 144 : cmpl_flag = 3;
179 144 : move16();
180 : }
181 284 : test();
182 284 : test();
183 284 : test();
184 284 : test();
185 284 : if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) )
186 : {
187 0 : cmpl_flag = 3;
188 0 : move16();
189 : }
190 : }
191 :
192 6388 : IF( EQ_16( L_frame, L_FRAME16k ) )
193 : {
194 3392 : IF( LE_32( core_brate, ACELP_32k ) )
195 : {
196 22 : cmpl_flag = 4;
197 22 : move16();
198 :
199 22 : test();
200 22 : IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) )
201 : {
202 0 : IF( LE_16( i_subfr, L_SUBFR ) )
203 : {
204 0 : cmpl_flag = sub( cmpl_flag, 1 );
205 : }
206 : ELSE
207 : {
208 0 : cmpl_flag = sub( cmpl_flag, 2 );
209 : }
210 : }
211 : }
212 3370 : ELSE IF( LE_32( core_brate, ACELP_48k ) )
213 : {
214 3370 : cmpl_flag = 3;
215 3370 : move16();
216 :
217 3370 : IF( EQ_16( coder_type, TRANSITION ) )
218 : {
219 250 : IF( LE_16( i_subfr, L_SUBFR ) )
220 : {
221 100 : cmpl_flag = sub( cmpl_flag, 1 );
222 : }
223 : ELSE
224 : {
225 150 : cmpl_flag = sub( cmpl_flag, 2 );
226 : }
227 : }
228 : }
229 : ELSE
230 : {
231 0 : cmpl_flag = 4;
232 0 : move16();
233 :
234 0 : IF( EQ_16( coder_type, TRANSITION ) )
235 : {
236 0 : IF( LE_16( i_subfr, L_SUBFR ) )
237 : {
238 0 : cmpl_flag = sub( cmpl_flag, 1 );
239 : }
240 : ELSE
241 : {
242 0 : cmpl_flag = sub( cmpl_flag, 2 );
243 : }
244 : }
245 :
246 0 : if ( coder_type == INACTIVE )
247 : {
248 0 : cmpl_flag = 4;
249 0 : move16();
250 : }
251 : }
252 : }
253 :
254 6388 : test();
255 6388 : test();
256 6388 : test();
257 6388 : IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) )
258 : {
259 0 : if ( GT_16( cmpl_flag, 1 ) )
260 : {
261 0 : cmpl_flag = sub( cmpl_flag, 1 );
262 : }
263 : }
264 :
265 : /*-----------------------------------------------------------------*
266 : * Find and encode the algebraic innovation
267 : *-----------------------------------------------------------------*/
268 :
269 6388 : set16_fx( y2, 0, L_SUBFR );
270 :
271 6388 : IF( !Opt_AMR_WB )
272 : {
273 6388 : IF( st_fx->acelp_cfg.fcb_mode )
274 : {
275 : }
276 : ELSE
277 : {
278 6388 : nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )];
279 6388 : move16();
280 :
281 :
282 6388 : IF( EQ_16( nBits, 7 ) )
283 : {
284 0 : acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR );
285 : }
286 6388 : ELSE IF( EQ_16( nBits, 12 ) )
287 : {
288 0 : acelp_2t32_fx( hBstr, dn, h2, code, y2 );
289 : }
290 : ELSE
291 : {
292 6388 : *unbits = add( *unbits, acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB ) );
293 6388 : move16();
294 : }
295 : }
296 : }
297 : ELSE
298 : {
299 0 : IF( EQ_32( core_brate, ACELP_6k60 ) )
300 : {
301 0 : acelp_2t32_fx( hBstr, dn, h2, code, y2 );
302 : }
303 0 : ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) )
304 : {
305 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB );
306 : }
307 0 : ELSE IF( EQ_32( core_brate, ACELP_12k65 ) )
308 : {
309 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB );
310 : }
311 0 : ELSE IF( EQ_32( core_brate, ACELP_14k25 ) )
312 : {
313 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB );
314 : }
315 0 : ELSE IF( EQ_32( core_brate, ACELP_15k85 ) )
316 : {
317 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB );
318 : }
319 0 : ELSE IF( EQ_32( core_brate, ACELP_18k25 ) )
320 : {
321 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB );
322 : }
323 0 : ELSE IF( EQ_32( core_brate, ACELP_19k85 ) )
324 : {
325 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB );
326 : }
327 0 : ELSE IF( EQ_32( core_brate, ACELP_23k05 ) )
328 : {
329 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB );
330 : }
331 0 : ELSE IF( EQ_32( core_brate, ACELP_23k85 ) )
332 : {
333 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB );
334 : }
335 : }
336 :
337 :
338 : /*----------------------------------------------------------------*
339 : * Pitch sharpening
340 : *----------------------------------------------------------------*/
341 :
342 6388 : cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr );
343 :
344 6388 : return stack_pulses;
345 : }
346 :
347 612152 : Word16 inov_encode_ivas_fx(
348 : Encoder_State *st_fx, /* i/o: encoder state structure */
349 : const Word32 core_brate, /* i : core bitrate */
350 : const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
351 : const Word16 L_frame, /* i : length of the frame */
352 : const Word16 last_L_frame, /* i : length of the last frame */
353 : const Word16 coder_type, /* i : coding type */
354 : const Word16 bwidth, /* i : input signal bandwidth */
355 : const Word16 sharpFlag, /* i : formant sharpening flag */
356 : const Word16 i_subfr, /* i : subframe index */
357 : const Word16 tc_subfr, /* i : TC subframe index */
358 : const Word16 *p_Aq, /* i : LP filter coefficients Q12*/
359 : const Word16 gain_pit, /* i : adaptive excitation gain Q14*/
360 : Word16 *cn, /* i/o: target vector in residual domain Q_new*/
361 : const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/
362 : Word16 *h2, /* i/o: weighted filter input response Q12*/
363 : const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/
364 : const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/
365 : const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/
366 : Word16 *code, /* o : algebraic excitation Q9*/
367 : Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/
368 : Word16 *unbits, /* o : number of unused bits for PI */
369 : const Word16 L_subfr, /* i : subframe length */
370 : Word16 shift,
371 : Word16 Q_new )
372 : {
373 : Word16 dn[2 * L_SUBFR], Qdn, Qcn;
374 : Word16 nBits, cmpl_flag;
375 : Word16 stack_pulses;
376 : Word16 g1, g2;
377 : Word16 Rw[L_SUBFR];
378 : Word16 acelpautoc;
379 612152 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
380 : Word16 i, k;
381 : Word16 Qxn, max_xn2;
382 612152 : stack_pulses = 0;
383 612152 : move16();
384 :
385 612152 : IF( EQ_16( L_frame, L_FRAME ) )
386 : {
387 259142 : g1 = FORMANT_SHARPENING_G1;
388 259142 : move16();
389 259142 : g2 = FORMANT_SHARPENING_G2;
390 259142 : move16();
391 : }
392 : ELSE
393 : {
394 353010 : g1 = FORMANT_SHARPENING_G1_16k;
395 353010 : move16();
396 353010 : g2 = FORMANT_SHARPENING_G2_16k;
397 353010 : move16();
398 : }
399 :
400 612152 : maximum_abs_16_fx( xn2, L_subfr, &max_xn2 );
401 612152 : IF( max_xn2 )
402 : {
403 609441 : Qxn = add( sub( Q_new, 1 ), shift );
404 : }
405 : ELSE
406 : {
407 2711 : Qxn = 0;
408 2711 : move16();
409 : }
410 :
411 : /*----------------------------------------------------------------*
412 : * Update target vector for codebook search in residual domain
413 : * Preemphasize the impulse response and include fixed-gain pitch contribution into impulse resp. h1[] (pitch sharpenning)
414 : * Correlation between target xn2[] and impulse response h1[]
415 : *----------------------------------------------------------------*/
416 :
417 612152 : test();
418 612152 : test();
419 612152 : Qcn = Q_new;
420 612152 : move16();
421 612152 : IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) )
422 : {
423 400642 : acelpautoc = 1;
424 400642 : move16();
425 400642 : cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_SUBFR );
426 : /* h2: Q11, Rw: (Rw_e)Q */
427 400642 : /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 );
428 :
429 400642 : E_ACELP_conv( xn2, h2, cn );
430 :
431 : /* dn_e -> Rw_e*Q_xn */
432 400642 : /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 );
433 400642 : Qdn = Qcn;
434 400642 : move16();
435 : }
436 : ELSE
437 : {
438 211510 : acelpautoc = 0;
439 211510 : move16();
440 211510 : updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr );
441 : /* scaling of cn[] to limit dynamic at 12 bits */
442 211510 : Scale_sig( cn, L_subfr, shift );
443 211510 : Word16 q_h1 = sub( 14, norm_s( h2[0] ) );
444 211510 : Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/
445 211510 : cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr );
446 211510 : corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1
447 211510 : IF( LT_16( Qdn, Qcn ) )
448 : {
449 176116 : scale_sig( cn, L_subfr, sub( Qdn, Qcn ) );
450 176116 : Qcn = Qdn;
451 176116 : move16();
452 : }
453 : ELSE
454 : {
455 35394 : scale_sig( dn, L_subfr, sub( Qcn, Qdn ) );
456 35394 : Qdn = Qcn;
457 35394 : move16();
458 : }
459 : }
460 :
461 : /*-----------------------------------------------------------------*
462 : * Set complexity reduction flag to limit the number of iterations
463 : * in algebraic innovation search
464 : *-----------------------------------------------------------------*/
465 612152 : cmpl_flag = 0;
466 612152 : move16();
467 612152 : test();
468 612152 : IF( st_fx->acelp_cfg.fcb_mode )
469 : {
470 : /* set number of iterations in TD stereo, secondary channel */
471 538578 : if ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) )
472 : {
473 15130 : cmpl_flag = 1;
474 15130 : move16();
475 : }
476 : }
477 : ELSE
478 : {
479 73574 : IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) )
480 : {
481 0 : test();
482 0 : test();
483 0 : if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) )
484 : {
485 0 : cmpl_flag = 3;
486 0 : move16();
487 : }
488 0 : test();
489 0 : test();
490 0 : test();
491 0 : test();
492 0 : test();
493 0 : if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) )
494 : {
495 0 : cmpl_flag = 3;
496 0 : move16();
497 : }
498 0 : test();
499 0 : test();
500 0 : test();
501 0 : test();
502 0 : if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) )
503 : {
504 0 : cmpl_flag = 3;
505 0 : move16();
506 : }
507 : }
508 :
509 73574 : IF( EQ_16( L_frame, L_FRAME16k ) )
510 : {
511 70790 : IF( LE_32( core_brate, ACELP_32k ) )
512 : {
513 26055 : cmpl_flag = 4;
514 26055 : move16();
515 :
516 26055 : test();
517 26055 : IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) )
518 : {
519 2045 : IF( LE_16( i_subfr, L_SUBFR ) )
520 : {
521 818 : cmpl_flag = sub( cmpl_flag, 1 );
522 : }
523 : ELSE
524 : {
525 1227 : cmpl_flag = sub( cmpl_flag, 2 );
526 : }
527 : }
528 : }
529 44735 : ELSE IF( LE_32( core_brate, ACELP_48k ) )
530 : {
531 44735 : cmpl_flag = 3;
532 44735 : move16();
533 :
534 44735 : IF( EQ_16( coder_type, TRANSITION ) )
535 : {
536 4250 : IF( LE_16( i_subfr, L_SUBFR ) )
537 : {
538 1700 : cmpl_flag = sub( cmpl_flag, 1 );
539 : }
540 : ELSE
541 : {
542 2550 : cmpl_flag = sub( cmpl_flag, 2 );
543 : }
544 : }
545 : }
546 : ELSE
547 : {
548 0 : cmpl_flag = 4;
549 0 : move16();
550 :
551 0 : IF( EQ_16( coder_type, TRANSITION ) )
552 : {
553 0 : IF( LE_16( i_subfr, L_SUBFR ) )
554 : {
555 0 : cmpl_flag = sub( cmpl_flag, 1 );
556 : }
557 : ELSE
558 : {
559 0 : cmpl_flag = sub( cmpl_flag, 2 );
560 : }
561 : }
562 :
563 0 : if ( EQ_16( coder_type, INACTIVE ) )
564 : {
565 0 : cmpl_flag = 4;
566 0 : move16();
567 : }
568 : }
569 : }
570 :
571 73574 : test();
572 73574 : test();
573 73574 : test();
574 73574 : IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) )
575 : {
576 80 : if ( GT_16( cmpl_flag, 1 ) )
577 : {
578 77 : cmpl_flag = sub( cmpl_flag, 1 );
579 : }
580 : }
581 : }
582 :
583 : /*-----------------------------------------------------------------*
584 : * Find and encode the algebraic innovation
585 : *-----------------------------------------------------------------*/
586 :
587 612152 : set16_fx( y2, 0, L_SUBFR );
588 :
589 612152 : IF( !Opt_AMR_WB )
590 : {
591 612152 : IF( st_fx->acelp_cfg.fcb_mode )
592 : {
593 538578 : Word16 idx = 0, idx2 = 0;
594 538578 : move16();
595 538578 : move16();
596 :
597 538578 : IF( i_subfr != 0 )
598 : {
599 417007 : idx = idiv1616( i_subfr, L_subfr );
600 417007 : idx2 = idiv1616( i_subfr, L_SUBFR );
601 : }
602 :
603 538578 : IF( LT_16( st_fx->acelp_cfg.fixed_cdk_index[idx], ACELP_FIXED_CDK_NB ) )
604 : {
605 : Word16 wordcnt, bitcnt;
606 : Word16 prm[8];
607 :
608 538578 : IF( st_fx->acelp_cfg.fixed_cdk_index[idx] >= 0 )
609 : {
610 538540 : test();
611 538540 : test();
612 538540 : test();
613 538540 : IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
614 : {
615 4150 : nBits = st_fx->acelp_cfg.fixed_cdk_index[idx];
616 4150 : move16();
617 :
618 4150 : IF( EQ_16( nBits, 8 ) )
619 : {
620 0 : acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr );
621 : }
622 : ELSE
623 : {
624 4150 : acelp_fast_fx( hBstr, nBits, dn, Qdn, cn, Qcn, h2, code, y2, L_subfr );
625 : }
626 : }
627 534390 : ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 7 ) ) || ( st_fx->idchan == 0 && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 3 ) ) )
628 : {
629 24837 : IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 )
630 : {
631 367 : acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr );
632 : }
633 : ELSE
634 : {
635 24470 : acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, Qdn, cn, Qcn, h2, code, y2, L_SUBFR );
636 : }
637 : }
638 : ELSE
639 : {
640 509553 : E_ACELP_4t_ivas_fx( dn, cn, h2, Rw, (Word8) acelpautoc, code, st_fx->acelp_cfg.fixed_cdk_index[idx2], prm, L_frame, last_L_frame, st_fx->total_brate, i_subfr, cmpl_flag, st_fx->element_mode );
641 :
642 509553 : wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 4 );
643 509553 : bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 15 );
644 :
645 1679759 : FOR( i = 0; i < wordcnt; i++ )
646 : {
647 1170206 : push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], 16 );
648 : }
649 509553 : IF( bitcnt )
650 : {
651 474490 : push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], bitcnt );
652 : }
653 :
654 : /* Generate weighted code */
655 509553 : set16_fx( y2, 0, L_SUBFR );
656 509553 : Word16 sh = add( norm_s( h2[0] ), 1 );
657 33120945 : FOR( i = 0; i < L_SUBFR; i++ )
658 : {
659 : /* Code is sparse, so check which samples are non-zero */
660 32611392 : IF( code[i] != 0 )
661 : {
662 168976556 : FOR( k = 0; k < L_SUBFR - i; k++ )
663 : {
664 163906398 : y2[i + k] = add_sat( y2[i + k], round_fx_sat( L_shl_sat( L_mult( code[i], h2[k] ), sh ) ) ); // Q9 Added saturation: needs to be rechecked
665 163906398 : move16();
666 : }
667 : }
668 : }
669 : }
670 : }
671 : ELSE
672 : {
673 38 : set16_fx( code, 0, L_SUBFR );
674 38 : set16_fx( y2, 0, L_SUBFR );
675 : }
676 : }
677 : #ifdef DEBUGGING
678 : else
679 : {
680 : IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid mode for acelp frame!\n" );
681 : }
682 : #endif
683 : }
684 : ELSE
685 : {
686 73574 : nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr >> 6];
687 73574 : move16();
688 :
689 :
690 73574 : IF( EQ_16( nBits, 7 ) )
691 : {
692 0 : acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_SUBFR );
693 : }
694 73574 : ELSE IF( EQ_16( nBits, 12 ) )
695 : {
696 15118 : acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 );
697 : }
698 : ELSE
699 : {
700 58456 : *unbits = add( *unbits, acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ) );
701 58456 : move16();
702 : }
703 : }
704 : }
705 : ELSE
706 : {
707 0 : IF( EQ_32( core_brate, ACELP_6k60 ) )
708 : {
709 0 : acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 );
710 : }
711 0 : ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) )
712 : {
713 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
714 : }
715 0 : ELSE IF( EQ_32( core_brate, ACELP_12k65 ) )
716 : {
717 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
718 : }
719 0 : ELSE IF( EQ_32( core_brate, ACELP_14k25 ) )
720 : {
721 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
722 : }
723 0 : ELSE IF( EQ_32( core_brate, ACELP_15k85 ) )
724 : {
725 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
726 : }
727 0 : ELSE IF( EQ_32( core_brate, ACELP_18k25 ) )
728 : {
729 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
730 : }
731 0 : ELSE IF( EQ_32( core_brate, ACELP_19k85 ) )
732 : {
733 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
734 : }
735 0 : ELSE IF( EQ_32( core_brate, ACELP_23k05 ) )
736 : {
737 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
738 : }
739 0 : ELSE IF( EQ_32( core_brate, ACELP_23k85 ) )
740 : {
741 0 : acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB, st_fx->element_mode );
742 : }
743 : }
744 :
745 :
746 : /*----------------------------------------------------------------*
747 : * Pitch sharpening
748 : *----------------------------------------------------------------*/
749 :
750 612152 : cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr );
751 :
752 612152 : return stack_pulses;
753 : }
|