LCOV - code coverage report
Current view: top level - lib_enc - inov_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 194 285 68.1 %
Date: 2025-05-03 01:55:50 Functions: 2 2 100.0 %

          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        6376 : 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        6376 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
      92             :     (void) last_L_frame;
      93        6376 :     stack_pulses = 0;
      94        6376 :     move16();
      95             : 
      96        6376 :     IF( EQ_16( L_frame, L_FRAME ) )
      97             :     {
      98        2987 :         g1 = FORMANT_SHARPENING_G1;
      99        2987 :         move16();
     100        2987 :         g2 = FORMANT_SHARPENING_G2;
     101        2987 :         move16();
     102             :     }
     103             :     ELSE
     104             :     {
     105        3389 :         g1 = FORMANT_SHARPENING_G1_16k;
     106        3389 :         move16();
     107        3389 :         g2 = FORMANT_SHARPENING_G2_16k;
     108        3389 :         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        6376 :     test();
     118        6376 :     test();
     119        6376 :     IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) )
     120             :     {
     121        3389 :         acelpautoc = 1;
     122        3389 :         move16();
     123             : 
     124        3389 :         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        3389 :         /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 );
     127             : 
     128        3389 :         E_ACELP_conv( xn2, h2, cn );
     129             : 
     130             :         /* dn_e -> Rw_e*Q_xn */
     131        3389 :         /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 );
     132             :     }
     133             :     ELSE
     134             :     {
     135        2987 :         acelpautoc = 0;
     136        2987 :         move16();
     137        2987 :         updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr );
     138             :         /* scaling of cn[] to limit dynamic at 12 bits */
     139        2987 :         Scale_sig( cn, L_subfr, shift );
     140             : 
     141        2987 :         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        2987 :         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        6376 :     cmpl_flag = 0;
     150        6376 :     move16();
     151        6376 :     test();
     152        6376 :     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        6376 :     ELSE IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) )
     163             :     {
     164         300 :         test();
     165         300 :         test();
     166         300 :         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         300 :         test();
     172         300 :         test();
     173         300 :         test();
     174         300 :         test();
     175         300 :         test();
     176         300 :         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         142 :             cmpl_flag = 3;
     179         142 :             move16();
     180             :         }
     181         300 :         test();
     182         300 :         test();
     183         300 :         test();
     184         300 :         test();
     185         300 :         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        6376 :     IF( EQ_16( L_frame, L_FRAME16k ) )
     193             :     {
     194        3389 :         IF( LE_32( core_brate, ACELP_32k ) )
     195             :         {
     196          19 :             cmpl_flag = 4;
     197          19 :             move16();
     198             : 
     199          19 :             test();
     200          19 :             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        6376 :     test();
     255        6376 :     test();
     256        6376 :     test();
     257        6376 :     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        6376 :     set16_fx( y2, 0, L_SUBFR );
     270             : 
     271        6376 :     IF( !Opt_AMR_WB )
     272             :     {
     273        6376 :         IF( st_fx->acelp_cfg.fcb_mode )
     274             :         {
     275             :         }
     276             :         ELSE
     277             :         {
     278        6376 :             nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )];
     279        6376 :             move16();
     280             : 
     281             : 
     282        6376 :             IF( EQ_16( nBits, 7 ) )
     283             :             {
     284           0 :                 acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR );
     285             :             }
     286        6376 :             ELSE IF( EQ_16( nBits, 12 ) )
     287             :             {
     288           0 :                 acelp_2t32_fx( hBstr, dn, h2, code, y2 );
     289             :             }
     290             :             ELSE
     291             :             {
     292        6376 :                 *unbits = add( *unbits, acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB ) );
     293        6376 :                 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        6376 :     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        6376 :     return stack_pulses;
     345             : }
     346             : 
     347      610406 : 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;
     374             :     Word16 nBits, cmpl_flag;
     375             :     Word16 stack_pulses;
     376             :     Word16 g1, g2;
     377             :     Word16 Rw[L_SUBFR];
     378             :     Word16 acelpautoc;
     379      610406 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     380             :     Word16 i, k;
     381             :     Word16 Qxn, Rw_q, j, max_xn2;
     382      610406 :     stack_pulses = 0;
     383      610406 :     move16();
     384             : 
     385      610406 :     IF( EQ_16( L_frame, L_FRAME ) )
     386             :     {
     387      257686 :         g1 = FORMANT_SHARPENING_G1;
     388      257686 :         move16();
     389      257686 :         g2 = FORMANT_SHARPENING_G2;
     390      257686 :         move16();
     391             :     }
     392             :     ELSE
     393             :     {
     394      352720 :         g1 = FORMANT_SHARPENING_G1_16k;
     395      352720 :         move16();
     396      352720 :         g2 = FORMANT_SHARPENING_G2_16k;
     397      352720 :         move16();
     398             :     }
     399             : 
     400      610406 :     maximum_abs_16_fx( xn2, L_subfr, &max_xn2 );
     401      610406 :     IF( max_xn2 )
     402             :     {
     403      607703 :         Qxn = add( sub( Q_new, 1 ), shift );
     404             :     }
     405             :     ELSE
     406             :     {
     407        2703 :         Qxn = 0;
     408        2703 :         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      610406 :     test();
     418      610406 :     test();
     419      610406 :     IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) )
     420      400416 :     {
     421      400416 :         acelpautoc = 1;
     422      400416 :         move16();
     423      400416 :         Word16 q_h1 = sub( 14, norm_s( h2[0] ) );
     424      400416 :         Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/
     425      400416 :         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      400416 :         corr_hh_ivas_fx( h2, Rw, &Rw_q, L_subfr ); // Q(Rw) = Q11-2
     428      400416 :         E_ACELP_conv_ivas_fx( xn2, h2, cn );       // Qcn = Qxn2
     429             : 
     430             :         /* dn_e -> Rw_e*Q_xn */
     431      400416 :         j = E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 );
     432      400416 :         Qdn = add( add( Qxn, Rw_q ), add( j, 1 ) );
     433             :     }
     434             :     ELSE
     435             :     {
     436      209990 :         acelpautoc = 0;
     437      209990 :         move16();
     438      209990 :         updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr );
     439             :         /* scaling of cn[] to limit dynamic at 12 bits */
     440      209990 :         Scale_sig( cn, L_subfr, shift );
     441      209990 :         Word16 q_h1 = sub( 14, norm_s( h2[0] ) );
     442      209990 :         Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/
     443      209990 :         cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr );
     444      209990 :         corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1
     445             :     }
     446             : 
     447             :     /*-----------------------------------------------------------------*
     448             :      * Set complexity reduction flag to limit the number of iterations
     449             :      * in algebraic innovation search
     450             :      *-----------------------------------------------------------------*/
     451      610406 :     cmpl_flag = 0;
     452      610406 :     move16();
     453      610406 :     test();
     454      610406 :     IF( st_fx->acelp_cfg.fcb_mode )
     455             :     {
     456             :         /* set number of iterations in TD stereo, secondary channel */
     457      536852 :         if ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) )
     458             :         {
     459       15222 :             cmpl_flag = 1;
     460       15222 :             move16();
     461             :         }
     462             :     }
     463             :     ELSE
     464             :     {
     465       73554 :         IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) )
     466             :         {
     467           0 :             test();
     468           0 :             test();
     469           0 :             if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) )
     470             :             {
     471           0 :                 cmpl_flag = 3;
     472           0 :                 move16();
     473             :             }
     474           0 :             test();
     475           0 :             test();
     476           0 :             test();
     477           0 :             test();
     478           0 :             test();
     479           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 ) ) ) )
     480             :             {
     481           0 :                 cmpl_flag = 3;
     482           0 :                 move16();
     483             :             }
     484           0 :             test();
     485           0 :             test();
     486           0 :             test();
     487           0 :             test();
     488           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 ) ) )
     489             :             {
     490           0 :                 cmpl_flag = 3;
     491           0 :                 move16();
     492             :             }
     493             :         }
     494             : 
     495       73554 :         IF( EQ_16( L_frame, L_FRAME16k ) )
     496             :         {
     497       70770 :             IF( LE_32( core_brate, ACELP_32k ) )
     498             :             {
     499       26075 :                 cmpl_flag = 4;
     500       26075 :                 move16();
     501             : 
     502       26075 :                 test();
     503       26075 :                 IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) )
     504             :                 {
     505        2025 :                     IF( LE_16( i_subfr, L_SUBFR ) )
     506             :                     {
     507         810 :                         cmpl_flag = sub( cmpl_flag, 1 );
     508             :                     }
     509             :                     ELSE
     510             :                     {
     511        1215 :                         cmpl_flag = sub( cmpl_flag, 2 );
     512             :                     }
     513             :                 }
     514             :             }
     515       44695 :             ELSE IF( LE_32( core_brate, ACELP_48k ) )
     516             :             {
     517       44695 :                 cmpl_flag = 3;
     518       44695 :                 move16();
     519             : 
     520       44695 :                 IF( EQ_16( coder_type, TRANSITION ) )
     521             :                 {
     522        4185 :                     IF( LE_16( i_subfr, L_SUBFR ) )
     523             :                     {
     524        1674 :                         cmpl_flag = sub( cmpl_flag, 1 );
     525             :                     }
     526             :                     ELSE
     527             :                     {
     528        2511 :                         cmpl_flag = sub( cmpl_flag, 2 );
     529             :                     }
     530             :                 }
     531             :             }
     532             :             ELSE
     533             :             {
     534           0 :                 cmpl_flag = 4;
     535           0 :                 move16();
     536             : 
     537           0 :                 IF( EQ_16( coder_type, TRANSITION ) )
     538             :                 {
     539           0 :                     IF( LE_16( i_subfr, L_SUBFR ) )
     540             :                     {
     541           0 :                         cmpl_flag = sub( cmpl_flag, 1 );
     542             :                     }
     543             :                     ELSE
     544             :                     {
     545           0 :                         cmpl_flag = sub( cmpl_flag, 2 );
     546             :                     }
     547             :                 }
     548             : 
     549           0 :                 if ( EQ_16( coder_type, INACTIVE ) )
     550             :                 {
     551           0 :                     cmpl_flag = 4;
     552           0 :                     move16();
     553             :                 }
     554             :             }
     555             :         }
     556             : 
     557       73554 :         test();
     558       73554 :         test();
     559       73554 :         test();
     560       73554 :         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 ) ) )
     561             :         {
     562          80 :             if ( GT_16( cmpl_flag, 1 ) )
     563             :             {
     564          77 :                 cmpl_flag = sub( cmpl_flag, 1 );
     565             :             }
     566             :         }
     567             :     }
     568             : 
     569             :     /*-----------------------------------------------------------------*
     570             :      * Find and encode the algebraic innovation
     571             :      *-----------------------------------------------------------------*/
     572             : 
     573      610406 :     set16_fx( y2, 0, L_SUBFR );
     574             : 
     575      610406 :     IF( !Opt_AMR_WB )
     576             :     {
     577      610406 :         IF( st_fx->acelp_cfg.fcb_mode )
     578             :         {
     579      536852 :             Word16 idx = 0, idx2 = 0;
     580      536852 :             move16();
     581      536852 :             move16();
     582             : 
     583      536852 :             IF( i_subfr != 0 )
     584             :             {
     585      415682 :                 idx = idiv1616( i_subfr, L_subfr );
     586      415682 :                 idx2 = idiv1616( i_subfr, L_SUBFR );
     587             :             }
     588             : 
     589      536852 :             IF( LT_16( st_fx->acelp_cfg.fixed_cdk_index[idx], ACELP_FIXED_CDK_NB ) )
     590             :             {
     591             :                 Word16 wordcnt, bitcnt;
     592             :                 Word16 prm[8];
     593             : 
     594      536852 :                 IF( st_fx->acelp_cfg.fixed_cdk_index[idx] >= 0 )
     595             :                 {
     596      536814 :                     test();
     597      536814 :                     test();
     598      536814 :                     test();
     599      536814 :                     IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
     600             :                     {
     601        4218 :                         nBits = st_fx->acelp_cfg.fixed_cdk_index[idx];
     602        4218 :                         move16();
     603             : 
     604        4218 :                         IF( EQ_16( nBits, 8 ) )
     605             :                         {
     606           0 :                             acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr );
     607             :                         }
     608             :                         ELSE
     609             :                         {
     610        4218 :                             acelp_fast_fx( hBstr, nBits, dn, Qdn, cn, Q_new, h2, code, y2, L_subfr );
     611             :                         }
     612             :                     }
     613      532596 :                     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 ) ) )
     614             :                     {
     615       24796 :                         IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 )
     616             :                         {
     617         367 :                             acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr );
     618             :                         }
     619             :                         ELSE
     620             :                         {
     621       24429 :                             acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, Qdn, cn, Q_new, h2, code, y2, L_SUBFR );
     622             :                         }
     623             :                     }
     624             :                     ELSE
     625             :                     {
     626      507800 :                         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 );
     627             : 
     628      507800 :                         wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 4 );
     629      507800 :                         bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 15 );
     630             : 
     631     1675936 :                         FOR( i = 0; i < wordcnt; i++ )
     632             :                         {
     633     1168136 :                             push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], 16 );
     634             :                         }
     635      507800 :                         IF( bitcnt )
     636             :                         {
     637      472799 :                             push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], bitcnt );
     638             :                         }
     639             : 
     640             :                         /* Generate weighted code */
     641      507800 :                         set16_fx( y2, 0, L_SUBFR );
     642      507800 :                         Word16 sh = add( norm_s( h2[0] ), 1 );
     643    33007000 :                         FOR( i = 0; i < L_SUBFR; i++ )
     644             :                         {
     645             :                             /* Code is sparse, so check which samples are non-zero */
     646    32499200 :                             IF( code[i] != 0 )
     647             :                             {
     648   168596168 :                                 FOR( k = 0; k < L_SUBFR - i; k++ )
     649             :                                 {
     650   163536953 :                                     y2[i + k] = add_sat( y2[i + k], round_fx( L_shl( L_mult( code[i], h2[k] ), sh ) ) ); // Q9 Added saturation: needs to be rechecked
     651   163536953 :                                     move16();
     652             :                                 }
     653             :                             }
     654             :                         }
     655             :                     }
     656             :                 }
     657             :                 ELSE
     658             :                 {
     659          38 :                     set16_fx( code, 0, L_SUBFR );
     660          38 :                     set16_fx( y2, 0, L_SUBFR );
     661             :                 }
     662             :             }
     663             : #ifdef DEBUGGING
     664             :             else
     665             :             {
     666             :                 IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid mode for acelp frame!\n" );
     667             :             }
     668             : #endif
     669             :         }
     670             :         ELSE
     671             :         {
     672       73554 :             nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr >> 6];
     673       73554 :             move16();
     674             : 
     675             : 
     676       73554 :             IF( EQ_16( nBits, 7 ) )
     677             :             {
     678           0 :                 acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_SUBFR );
     679             :             }
     680       73554 :             ELSE IF( EQ_16( nBits, 12 ) )
     681             :             {
     682       15103 :                 acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 );
     683             :             }
     684             :             ELSE
     685             :             {
     686       58451 :                 *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 ) );
     687       58451 :                 move16();
     688             :             }
     689             :         }
     690             :     }
     691             :     ELSE
     692             :     {
     693           0 :         IF( EQ_32( core_brate, ACELP_6k60 ) )
     694             :         {
     695           0 :             acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 );
     696             :         }
     697           0 :         ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) )
     698             :         {
     699           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
     700             :         }
     701           0 :         ELSE IF( EQ_32( core_brate, ACELP_12k65 ) )
     702             :         {
     703           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
     704             :         }
     705           0 :         ELSE IF( EQ_32( core_brate, ACELP_14k25 ) )
     706             :         {
     707           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
     708             :         }
     709           0 :         ELSE IF( EQ_32( core_brate, ACELP_15k85 ) )
     710             :         {
     711           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
     712             :         }
     713           0 :         ELSE IF( EQ_32( core_brate, ACELP_18k25 ) )
     714             :         {
     715           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
     716             :         }
     717           0 :         ELSE IF( EQ_32( core_brate, ACELP_19k85 ) )
     718             :         {
     719           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
     720             :         }
     721           0 :         ELSE IF( EQ_32( core_brate, ACELP_23k05 ) )
     722             :         {
     723           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB, st_fx->element_mode );
     724             :         }
     725           0 :         ELSE IF( EQ_32( core_brate, ACELP_23k85 ) )
     726             :         {
     727           0 :             acelp_4t64_ivas_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB, st_fx->element_mode );
     728             :         }
     729             :     }
     730             : 
     731             : 
     732             :     /*----------------------------------------------------------------*
     733             :      * Pitch sharpening
     734             :      *----------------------------------------------------------------*/
     735             : 
     736      610406 :     cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr );
     737             : 
     738      610406 :     return stack_pulses;
     739             : }

Generated by: LCOV version 1.14