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 6359 : 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 6359 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
92 : (void) last_L_frame;
93 6359 : stack_pulses = 0;
94 6359 : move16();
95 :
96 6359 : IF( EQ_16( L_frame, L_FRAME ) )
97 : {
98 2968 : g1 = FORMANT_SHARPENING_G1;
99 2968 : move16();
100 2968 : g2 = FORMANT_SHARPENING_G2;
101 2968 : move16();
102 : }
103 : ELSE
104 : {
105 3391 : g1 = FORMANT_SHARPENING_G1_16k;
106 3391 : move16();
107 3391 : g2 = FORMANT_SHARPENING_G2_16k;
108 3391 : 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 6359 : test();
118 6359 : test();
119 6359 : IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) )
120 : {
121 3391 : acelpautoc = 1;
122 3391 : move16();
123 :
124 3391 : 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 3391 : /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 );
127 :
128 3391 : E_ACELP_conv( xn2, h2, cn );
129 :
130 : /* dn_e -> Rw_e*Q_xn */
131 3391 : /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 );
132 : }
133 : ELSE
134 : {
135 2968 : acelpautoc = 0;
136 2968 : move16();
137 2968 : updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr );
138 : /* scaling of cn[] to limit dynamic at 12 bits */
139 2968 : Scale_sig( cn, L_subfr, shift );
140 :
141 2968 : 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 2968 : 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 6359 : cmpl_flag = 0;
150 6359 : move16();
151 6359 : test();
152 6359 : 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 6359 : ELSE IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) )
163 : {
164 296 : test();
165 296 : test();
166 296 : 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 296 : test();
172 296 : test();
173 296 : test();
174 296 : test();
175 296 : test();
176 296 : 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 150 : cmpl_flag = 3;
179 150 : move16();
180 : }
181 296 : test();
182 296 : test();
183 296 : test();
184 296 : test();
185 296 : 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 6359 : IF( EQ_16( L_frame, L_FRAME16k ) )
193 : {
194 3391 : IF( LE_32( core_brate, ACELP_32k ) )
195 : {
196 21 : cmpl_flag = 4;
197 21 : move16();
198 :
199 21 : test();
200 21 : 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 6359 : test();
255 6359 : test();
256 6359 : test();
257 6359 : 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 6359 : set16_fx( y2, 0, L_SUBFR );
270 :
271 6359 : IF( !Opt_AMR_WB )
272 : {
273 6359 : IF( st_fx->acelp_cfg.fcb_mode )
274 : {
275 : }
276 : ELSE
277 : {
278 6359 : nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )];
279 6359 : move16();
280 :
281 :
282 6359 : IF( EQ_16( nBits, 7 ) )
283 : {
284 0 : acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR );
285 : }
286 6359 : ELSE IF( EQ_16( nBits, 12 ) )
287 : {
288 0 : acelp_2t32_fx( hBstr, dn, h2, code, y2 );
289 : }
290 : ELSE
291 : {
292 6359 : *unbits = add( *unbits, acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ) );
293 6359 : 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, st_fx->element_mode );
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, st_fx->element_mode );
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, st_fx->element_mode );
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, st_fx->element_mode );
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, st_fx->element_mode );
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, st_fx->element_mode );
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, st_fx->element_mode );
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, st_fx->element_mode );
334 : }
335 : }
336 :
337 :
338 : /*----------------------------------------------------------------*
339 : * Pitch sharpening
340 : *----------------------------------------------------------------*/
341 :
342 6359 : 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 6359 : return stack_pulses;
345 : }
346 :
347 613840 : 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, Qh2;
374 : Word16 nBits, cmpl_flag;
375 : Word16 stack_pulses;
376 : Word16 g1, g2;
377 : Word16 Rw[L_SUBFR];
378 : Word16 acelpautoc;
379 613840 : BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
380 : Word16 i, k;
381 : Word16 Qxn, max_xn2;
382 613840 : stack_pulses = 0;
383 613840 : move16();
384 :
385 613840 : IF( EQ_16( L_frame, L_FRAME ) )
386 : {
387 260400 : g1 = FORMANT_SHARPENING_G1;
388 260400 : move16();
389 260400 : g2 = FORMANT_SHARPENING_G2;
390 260400 : move16();
391 : }
392 : ELSE
393 : {
394 353440 : g1 = FORMANT_SHARPENING_G1_16k;
395 353440 : move16();
396 353440 : g2 = FORMANT_SHARPENING_G2_16k;
397 353440 : move16();
398 : }
399 :
400 613840 : maximum_abs_16_fx( xn2, L_subfr, &max_xn2 );
401 613840 : IF( max_xn2 )
402 : {
403 611077 : Qxn = add( sub( Q_new, 1 ), shift );
404 : }
405 : ELSE
406 : {
407 2763 : Qxn = 0;
408 2763 : 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 613840 : test();
418 613840 : test();
419 613840 : Qcn = Q_new;
420 613840 : move16();
421 613840 : IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) )
422 : {
423 401276 : acelpautoc = 1;
424 401276 : move16();
425 401276 : 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 401276 : /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 );
428 :
429 401276 : E_ACELP_conv( xn2, h2, cn );
430 :
431 : /* dn_e -> Rw_e*Q_xn */
432 401276 : /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 );
433 401276 : Qdn = Qcn;
434 401276 : move16();
435 : }
436 : ELSE
437 : {
438 212564 : acelpautoc = 0;
439 212564 : move16();
440 212564 : updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr );
441 : /* scaling of cn[] to limit dynamic at 12 bits */
442 212564 : Scale_sig( cn, L_subfr, shift );
443 212564 : Word16 q_h1 = sub( 14, norm_s( h2[0] ) );
444 212564 : Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/
445 212564 : 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 212564 : corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1
447 212564 : IF( LT_16( Qdn, Qcn ) )
448 : {
449 176841 : scale_sig( cn, L_subfr, sub( Qdn, Qcn ) );
450 176841 : Qcn = Qdn;
451 176841 : move16();
452 : }
453 : ELSE
454 : {
455 35723 : scale_sig( dn, L_subfr, sub( Qcn, Qdn ) );
456 35723 : Qdn = Qcn;
457 35723 : move16();
458 : }
459 : }
460 :
461 : /*-----------------------------------------------------------------*
462 : * Set complexity reduction flag to limit the number of iterations
463 : * in algebraic innovation search
464 : *-----------------------------------------------------------------*/
465 613840 : cmpl_flag = 0;
466 613840 : move16();
467 613840 : test();
468 613840 : IF( st_fx->acelp_cfg.fcb_mode )
469 : {
470 : /* set number of iterations in TD stereo, secondary channel */
471 540416 : 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 73424 : 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 73424 : IF( EQ_16( L_frame, L_FRAME16k ) )
510 : {
511 70640 : IF( LE_32( core_brate, ACELP_32k ) )
512 : {
513 26045 : cmpl_flag = 4;
514 26045 : move16();
515 :
516 26045 : test();
517 26045 : IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) )
518 : {
519 2040 : IF( LE_16( i_subfr, L_SUBFR ) )
520 : {
521 816 : cmpl_flag = sub( cmpl_flag, 1 );
522 : }
523 : ELSE
524 : {
525 1224 : cmpl_flag = sub( cmpl_flag, 2 );
526 : }
527 : }
528 : }
529 44595 : ELSE IF( LE_32( core_brate, ACELP_48k ) )
530 : {
531 44595 : cmpl_flag = 3;
532 44595 : move16();
533 :
534 44595 : IF( EQ_16( coder_type, TRANSITION ) )
535 : {
536 4215 : IF( LE_16( i_subfr, L_SUBFR ) )
537 : {
538 1686 : cmpl_flag = sub( cmpl_flag, 1 );
539 : }
540 : ELSE
541 : {
542 2529 : 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 73424 : test();
572 73424 : test();
573 73424 : test();
574 73424 : 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 75 : if ( GT_16( cmpl_flag, 1 ) )
577 : {
578 72 : cmpl_flag = sub( cmpl_flag, 1 );
579 : }
580 : }
581 : }
582 :
583 : /*-----------------------------------------------------------------*
584 : * Find and encode the algebraic innovation
585 : *-----------------------------------------------------------------*/
586 :
587 613840 : set16_fx( y2, 0, L_SUBFR );
588 :
589 613840 : Qh2 = sub( 14, norm_s( h2[0] ) );
590 613840 : Scale_sig( h2, L_SUBFR, sub( Q12, Qh2 ) );
591 :
592 613840 : IF( !Opt_AMR_WB )
593 : {
594 613840 : IF( st_fx->acelp_cfg.fcb_mode )
595 : {
596 540416 : Word16 idx = 0, idx2 = 0;
597 540416 : move16();
598 540416 : move16();
599 :
600 540416 : IF( i_subfr != 0 )
601 : {
602 418429 : idx = idiv1616( i_subfr, L_subfr );
603 418429 : idx2 = shr( i_subfr, L_SUBFR_LOG2 );
604 : }
605 :
606 540416 : IF( LT_16( st_fx->acelp_cfg.fixed_cdk_index[idx], ACELP_FIXED_CDK_NB ) )
607 : {
608 : Word16 wordcnt, bitcnt;
609 : Word16 prm[8];
610 :
611 540416 : IF( st_fx->acelp_cfg.fixed_cdk_index[idx] >= 0 )
612 : {
613 540378 : test();
614 540378 : test();
615 540378 : test();
616 540378 : IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
617 : {
618 4092 : nBits = st_fx->acelp_cfg.fixed_cdk_index[idx];
619 4092 : move16();
620 :
621 4092 : IF( EQ_16( nBits, 8 ) )
622 : {
623 0 : acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr );
624 : }
625 : ELSE
626 : {
627 4092 : acelp_fast_fx( hBstr, nBits, dn, Qdn, cn, Qcn, h2, code, y2, L_subfr );
628 : }
629 : }
630 536286 : 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 ) ) )
631 : {
632 25104 : IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 )
633 : {
634 367 : acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr );
635 : }
636 : ELSE
637 : {
638 24737 : acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, Qdn, cn, Qcn, h2, code, y2, L_SUBFR );
639 : }
640 : }
641 : ELSE
642 : {
643 511182 : E_ACELP_4t_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 );
644 511182 : wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 4 );
645 511182 : bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 15 );
646 :
647 1684820 : FOR( i = 0; i < wordcnt; i++ )
648 : {
649 1173638 : push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], 16 );
650 : }
651 511182 : IF( bitcnt )
652 : {
653 476020 : push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], bitcnt );
654 : }
655 :
656 : /* Generate weighted code */
657 511182 : set16_fx( y2, 0, L_SUBFR );
658 511182 : Word16 sh = add( norm_s( h2[0] ), 1 );
659 33226830 : FOR( i = 0; i < L_SUBFR; i++ )
660 : {
661 : /* Code is sparse, so check which samples are non-zero */
662 32715648 : IF( code[i] != 0 )
663 : {
664 169578680 : FOR( k = 0; k < L_SUBFR - i; k++ )
665 : {
666 164494417 : 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
667 164494417 : move16();
668 : }
669 : }
670 : }
671 : }
672 : }
673 : ELSE
674 : {
675 38 : set16_fx( code, 0, L_SUBFR );
676 38 : set16_fx( y2, 0, L_SUBFR );
677 : }
678 : }
679 : #ifdef DEBUGGING
680 : else
681 : {
682 : IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid mode for acelp frame!\n" );
683 : }
684 : #endif
685 : }
686 : ELSE
687 : {
688 73424 : nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr >> 6];
689 73424 : move16();
690 :
691 :
692 73424 : IF( EQ_16( nBits, 7 ) )
693 : {
694 0 : acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR );
695 : }
696 73424 : ELSE IF( EQ_16( nBits, 12 ) )
697 : {
698 15118 : acelp_2t32_fx( hBstr, dn, h2, code, y2 );
699 : }
700 : ELSE
701 : {
702 58306 : *unbits = add( *unbits, acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ) );
703 58306 : move16();
704 : }
705 : }
706 : }
707 : ELSE
708 : {
709 0 : IF( EQ_32( core_brate, ACELP_6k60 ) )
710 : {
711 0 : acelp_2t32_fx( hBstr, dn, h2, code, y2 );
712 : }
713 0 : ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) )
714 : {
715 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
716 : }
717 0 : ELSE IF( EQ_32( core_brate, ACELP_12k65 ) )
718 : {
719 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
720 : }
721 0 : ELSE IF( EQ_32( core_brate, ACELP_14k25 ) )
722 : {
723 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
724 : }
725 0 : ELSE IF( EQ_32( core_brate, ACELP_15k85 ) )
726 : {
727 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
728 : }
729 0 : ELSE IF( EQ_32( core_brate, ACELP_18k25 ) )
730 : {
731 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
732 : }
733 0 : ELSE IF( EQ_32( core_brate, ACELP_19k85 ) )
734 : {
735 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
736 : }
737 0 : ELSE IF( EQ_32( core_brate, ACELP_23k05 ) )
738 : {
739 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
740 : }
741 0 : ELSE IF( EQ_32( core_brate, ACELP_23k85 ) )
742 : {
743 0 : acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB, st_fx->element_mode );
744 : }
745 : }
746 :
747 :
748 : /*----------------------------------------------------------------*
749 : * Pitch sharpening
750 : *----------------------------------------------------------------*/
751 :
752 613840 : cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr );
753 :
754 613840 : return stack_pulses;
755 : }
|