Commit 2965b69b authored by Arash Azizi's avatar Arash Azizi
Browse files

issue: 2446 ´Replacing the legacy flag with a more generalized one - replacing...

issue: 2446 ´Replacing the legacy flag with a more generalized one - replacing shl() function with shl_sat()
parent 7725ade5
Loading
Loading
Loading
Loading
Loading
+61 −98
Original line number Diff line number Diff line
@@ -985,6 +985,10 @@ void con_tcx_ivas_fx(
    HQ_DEC_HANDLE hHQ_core;
    TCX_LTP_DEC_HANDLE hTcxLtpDec;
    TCX_DEC_HANDLE hTcxDec;
#ifdef HARMONIZE_2446_CON_TCX_FX
    Word16 leg_flag;
    leg_flag = EQ_16(st->element_mode, EVS_MONO) || EQ_16(st->element_mode, IVAS_SCE) || LE_16(st->element_brate,48000);
#endif // HARMONIZE_2446_CON_TCX_FX

    hTcxLtpDec = st->hTcxLtpDec;
    hHQ_core = st->hHQ_core;
@@ -1046,28 +1050,28 @@ void con_tcx_ivas_fx(
    IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc )
    {
        /* apply pre-emphasis to the signal */
        mem = shl( synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )], st->Q_syn_factor );
        mem = shl_sat( synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )], st->Q_syn_factor );
        move16();
#ifndef HARMONIZE_2446_CON_TCX_FX
        Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 );

#else
        IF( NE_16( st->element_mode, EVS_MONO ) )
        IF( !leg_flag )
        {
            Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 );
            Q_exc = E_UTIL_f_preemph3_ivas_fx(&(synth[-(((L_frame / 2) + hTcxDec->pit_max_TCX) + 2 * M)]), st->preemph_fac, add(add(shr(L_frame, 1), hTcxDec->pit_max_TCX), shl_sat(M, 1)), &mem, 1);
        }
        ELSE
        {
            Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 );
            Q_exc = E_UTIL_f_preemph3(&(synth[-(((L_frame / 2) + hTcxDec->pit_max_TCX) + 2 * M)]), st->preemph_fac, add(add(shr(L_frame, 1), hTcxDec->pit_max_TCX), shl_sat(M, 1)), &mem, 1);
        }
#endif // !HARMONIZE_2446_CON_TCX_FX


        scale_sig( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
        scale_sig( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl_sat( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */

        st->Mode2_lp_gainc = L_deposit_l( 0 );

        st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) );
        st->Mode2_lp_gainp = get_gain2( synth - shl_sat( L_subfr, 1 ), synth - add( shl_sat( L_subfr, 1 ), Tc ), shl_sat( L_subfr, 1 ) );
        move32();

        st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 );                   /*Q16*/
@@ -1091,7 +1095,7 @@ void con_tcx_ivas_fx(
        E_LPC_lev_dur_ivas_fx( r_h, r_l, A_local, NULL, M, NULL );

#else
        IF( NE_16( st->element_mode, EVS_MONO ) )
        IF( !leg_flag )
        {
            E_LPC_lev_dur_ivas_fx( r_h, r_l, A_local, NULL, M, NULL );
        }
@@ -1111,23 +1115,23 @@ void con_tcx_ivas_fx(
        BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/
            Residu3_fx(
                A_local,
                &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx   = Q0*/
                &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ),   /*Qx+1 = Q1*/
                add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ),
                &( synth[-add( add( add( shl_sat( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx   = Q0*/
                &( exc[-add( add( add( shl_sat( L_subfr, 1 ), Tc ), 1 ), M )] ),   /*Qx+1 = Q1*/
                add( add( add( shl_sat( L_subfr, 1 ), Tc ), 1 ), M ),
                1 );
        BASOP_SATURATE_WARNING_ON_EVS
    }
    ELSE
    {
        /* apply pre-emphasis to the signal */
        mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*hTcxDec->Q_synth_factor_old*/
        mem = shl_sat( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*hTcxDec->Q_synth_factor_old*/
        move16();
#ifndef HARMONIZE_2446_CON_TCX_FX
        Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 );
        scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */

#else
        IF( NE_16( st->element_mode, EVS_MONO ) )
        IF( !leg_flag )
        {
            Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 );
            scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
@@ -1153,7 +1157,7 @@ void con_tcx_ivas_fx(
        }
        ELSE
        {
            Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/
            Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl_sat( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/
        }
    }

@@ -1192,7 +1196,7 @@ void con_tcx_ivas_fx(
            scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) );                                                                                  /*getInvFrameLen()->9Q6*/
            tmp_shift = norm_s( scale_tmp );

            predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/
            predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl_sat( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/

            T0 = round_fx( predPitchLag ); /*Q0*/

@@ -1265,23 +1269,6 @@ void con_tcx_ivas_fx(
                                              0 /* 0.0000f Q15*/, pt1_exc[4] ),
                                       174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
#else
                    IF( NE_32( st->element_mode, EVS_MONO ) )
                    {
                        *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac(
                                                                                                       L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ),
                                                                                                       0 /* 0.0000f Q15*/, pt1_exc[-4] ),
                                                                                                   -1442 /*-0.0440f Q15*/, pt1_exc[-3] ),
                                                                                            0 /* 0.0000f Q15*/, pt1_exc[-2] ),
                                                                                     8641 /* 0.2637f Q15*/, pt1_exc[-1] ),
                                                                              18022 /* 0.5500f Q15*/, pt1_exc[0] ),
                                                                       8641 /* 0.2637f Q15*/, pt1_exc[1] ),
                                                                0 /* 0.0000f Q15*/, pt1_exc[2] ),
                                                         -1442 /*-0.0440f Q15*/, pt1_exc[3] ),
                                                  0 /* 0.0000f Q15*/, pt1_exc[4] ),
                                           174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
                    }
                    ELSE
                    {
                    * pt_exc++ = mac_r_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(
                        L_mult(174 /* 0.0053f Q15*/, pt1_exc[-5]),
                        0 /* 0.0000f Q15*/, pt1_exc[-4]),
@@ -1294,7 +1281,7 @@ void con_tcx_ivas_fx(
                        -1442 /*-0.0440f Q15*/, pt1_exc[3]),
                        0 /* 0.0000f Q15*/, pt1_exc[4]),
                        174 /* 0.0053f Q15*/, pt1_exc[5]); /*Q_exc*/
                    }


#endif // !HARMONIZE_2446_CON_TCX_FX
                    move16();
@@ -1319,23 +1306,6 @@ void con_tcx_ivas_fx(
                                              -121 /*-0.0037f Q15*/, pt1_exc[4] ),
                                       -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
#else
                    IF( NE_32( st->element_mode, EVS_MONO ) )
                    {
                        *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac(
                                                                                                       L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ),
                                                                                                       -121 /*-0.0037f Q15*/, pt1_exc[-4] ),
                                                                                                   -459 /*-0.0140f Q15*/, pt1_exc[-3] ),
                                                                                            590 /* 0.0180f Q15*/, pt1_exc[-2] ),
                                                                                     8743 /* 0.2668f Q15*/, pt1_exc[-1] ),
                                                                              16355 /* 0.4991f Q15*/, pt1_exc[0] ),
                                                                       8743 /* 0.2668f Q15*/, pt1_exc[1] ),
                                                                590 /* 0.0180f Q15*/, pt1_exc[2] ),
                                                         -459 /*-0.0140f Q15*/, pt1_exc[3] ),
                                                  -121 /*-0.0037f Q15*/, pt1_exc[4] ),
                                           -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/
                    }
                    ELSE
                    {
                * pt_exc++ = mac_r_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(L_mac_sat(
                    L_mult(-174 /*-0.0053f Q15*/, pt1_exc[-5]),
                    -121 /*-0.0037f Q15*/, pt1_exc[-4]),
@@ -1348,7 +1318,7 @@ void con_tcx_ivas_fx(
                    -459 /*-0.0140f Q15*/, pt1_exc[3]),
                    -121 /*-0.0037f Q15*/, pt1_exc[4]),
                    -174 /*-0.0053f Q15*/, pt1_exc[5]); /*Q_exc*/
                    }


#endif // !HARMONIZE_2446_CON_TCX_FX
                    move16();
@@ -1458,11 +1428,11 @@ void con_tcx_ivas_fx(
        /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/
        tmp16 = shr( imult1616( 3, L_frame ), 1 );
        tmp_e = norm_s( tmp16 );
        tmp16 = shl( tmp16, tmp_e );
        tmp16 = shl_sat(tmp16, tmp_e);

        tmp16 = div_s( 16384 /*1.f Q14*/, tmp16 ); /*Q15,1+tmp_e-15*/
        tmp16_2 = sub( shr( gain, 1 ), alpha ) /*Q14*/;
        step32 = L_shl( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/;

        step32 = L_shl_sat(L_mult(tmp16, tmp16_2) /*Q30, 1+tmp_e-15*/, add(1 - 14, tmp_e)) /*Q31*/;     
        /* PLC: Apply fade out */
        tmp_loop = shr( imult1616( L_frame, 3 ), 1 );
        FOR( i = offset; i < tmp_loop; i++ )
@@ -1507,7 +1477,7 @@ void con_tcx_ivas_fx(
#ifndef HARMONIZE_2446_CON_TCX_FX
    IF( NE_16( coh, -16384 ) )
#else
    IF( NE_16( coh, -16384 ) && NE_16( st->element_mode, EVS_MONO ) )
    IF( NE_16( coh, -16384 ) && !leg_flag )
#endif // !HARMONIZE_2446_CON_TCX_FX
    {
        Word16 tmpSeed1;
@@ -1574,7 +1544,7 @@ void con_tcx_ivas_fx(
        st->seed_acelp = tmpSeed;
        move16();

        tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), shl( L_FIR_FER2, 1 ) );
        tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), shl_sat( L_FIR_FER2, 1 ) );
        FOR( ; i < tmp_loop; i++ )
        {
            Random( &tmpSeed );
@@ -1695,14 +1665,7 @@ void con_tcx_ivas_fx(
#ifndef HARMONIZE_2446_CON_TCX_FX
    L_tmp = L_shl( gain32, 1 ); /*Q16*/
#else
    IF( NE_16( st->element_mode, EVS_MONO ) )
    {
        L_tmp = L_shl( gain32, 1 ); /*Q16*/
    }
    ELSE
    {
        L_tmp = L_shl_sat( gain32, 1 ); /*Q16*/
    }
#endif // !HARMONIZE_2446_CON_TCX_FX

    IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) )
@@ -1740,9 +1703,9 @@ void con_tcx_ivas_fx(
#ifndef HARMONIZE_2446_CON_TCX_FX
    tmp_e = sub( add( tmp_e, shl( noise_e, 1 ) ), 1 ); // actual multiplier!
#else
    IF( NE_16( st->element_mode, EVS_MONO ) )
    IF( !leg_flag )
    {
        tmp_e = sub( add( tmp_e, shl( noise_e, 1 ) ), 1 ); // actual multiplier!
        tmp_e = sub( add( tmp_e, shl_sat( noise_e, 1 ) ), 1 ); // actual multiplier!
    }
#endif // !HARMONIZE_2446_CON_TCX_FX

@@ -1855,7 +1818,7 @@ void con_tcx_ivas_fx(
    ELSE
    {
        bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ );
        Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/
        Copy( exc + sub( L_frame, shl_sat( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl_sat( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/
        /* copy old_exc as 16kHz for acelp decoding */
        IF( EQ_16( st->nbLostCmpt, 1 ) )
        {
@@ -1884,7 +1847,7 @@ void con_tcx_ivas_fx(
    Copy( synth - M, buf, M ); /*Q_syn*/

#ifdef HARMONIZE_2446_CON_TCX_FX
    IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness
    IF( !leg_flag ) // to keep evs bit-exactness
    {
#endif // HARMONIZE_2446_CON_TCX_FX
        scf = norm_s( tmp_deemph );
@@ -1911,14 +1874,14 @@ void con_tcx_ivas_fx(

    Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /* Q: tmp16 */
#ifdef HARMONIZE_2446_CON_TCX_FX
    IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness
    IF( !leg_flag ) // to keep evs bit-exactness
    {
#endif // !HARMONIZE_2446_CON_TCX_FX
        if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) )
        {
            Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf;
        }
        tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) );
        tmp_deemph = shl_sat( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) );
#ifdef HARMONIZE_2446_CON_TCX_FX
    }
    ELSE
@@ -1936,7 +1899,7 @@ void con_tcx_ivas_fx(
#ifndef HARMONIZE_2446_CON_TCX_FX
    IF( A_cng != NULL )
#else
    IF( ( A_cng != NULL ) && NE_32( st->element_mode, EVS_MONO ) )
    IF( ( A_cng != NULL ) && !leg_flag )
#endif // !HARMONIZE_2446_CON_TCX_FX
    {
        Word16 alpha_delayed;
@@ -1998,7 +1961,7 @@ void con_tcx_ivas_fx(
    deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph );

#ifdef HARMONIZE_2446_CON_TCX_FX
    IF( EQ_32( st->element_mode, EVS_MONO ) )
    IF( leg_flag )
    {
        bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/
    }
@@ -2043,7 +2006,7 @@ void con_tcx_ivas_fx(
    Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( st->Q_syn_factor, Q_syn ) );
    hTcxDec->Q_syn_OverlFB = st->Q_syn_factor;
#else
    IF( NE_16( st->element_mode, EVS_MONO ) )
    IF( !leg_flag )
    {
        scf = add( getScaleFactor16( syn, L_frame ), Q_syn );
        IF( LT_16( scf, 0 ) ) // Only avoid left shift in bufferCopyFX when overflow could occur
@@ -2094,7 +2057,7 @@ void con_tcx_ivas_fx(
    hTcxDec->Q_syn_Overl_TDACFB = Q_syn;

#else
    IF( NE_16( st->element_mode, EVS_MONO ) )
    IF( !leg_flag )
    {
        Copy( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ) );
        hTcxDec->Q_syn_Overl_TDACFB = Q_syn;
@@ -2154,7 +2117,7 @@ void con_tcx_ivas_fx(
#ifndef HARMONIZE_2446_CON_TCX_FX
    st->Q_syn = Q_syn;
#else
    IF( NE_16( st->element_mode, EVS_MONO ) )
    IF( !leg_flag )
    {
        st->Q_syn = Q_syn;
    }
@@ -2176,7 +2139,7 @@ void con_tcx_ivas_fx(
#ifndef HARMONIZE_2446_CON_TCX_FX
    st->hHQ_core->Q_old_wtda_LB = Q_syn; // st->hHQ_core->Q_old_wtda
#else
    IF( EQ_16( st->element_mode, EVS_MONO ) )
    IF( leg_flag )
    {
        st->hHQ_core->Q_old_wtda_LB = Q_syn; // st->hHQ_core->Q_old_wtda
    }