Commit 59e700e7 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

EVS Bitexactness issue fix

[x] Bitt exactness afftected with bug fix made for EVS code. Created a
copy to address the bug.
parent a3388112
Loading
Loading
Loading
Loading
Loading
+175 −3
Original line number Diff line number Diff line
@@ -2045,6 +2045,177 @@ static void calculate_Tonality_fx(
        }
    }

    max = 0;
    move16();
    FOR( n_coeff = 0; n_coeff < length; n_coeff++ )
    {
        gen_spec[n_coeff] = abs_s( gen[n_coeff] );
        move16(); /*Q15 */
        /*test();
        if( sub(max,gen_spec[n_coeff]) < 0)
        {
            max = gen_spec[n_coeff];move16();
        }*/
        max = s_max( max, org_spec[n_coeff] );
    }
    l_shift = norm_s( max );
    FOR( n_coeff = 0; n_coeff < length; n_coeff++ )
    {
#ifdef BASOP_NOGLOB
        gen_spec[n_coeff] = shl_sat( gen_spec[n_coeff], l_shift );
#else
        gen_spec[n_coeff] = shl( gen_spec[n_coeff], l_shift );
#endif
        move16();
        IF( gen_spec[n_coeff] == 0 )
        {
            gen_spec[n_coeff] = shl( 1, l_shift );
            move16();
        }
    }

    exp = norm_s( length );
    inv_len = div_s( shl( 1, exp ), shl( length, exp ) ); /*Q15 */

    L_am_org = L_deposit_l( 0 );
    L_am_gen = L_deposit_l( 0 );
    L_log_gm_org = 0;
    move32();
    L_log_gm_gen = 0;
    move32();

    FOR( n_coeff = 0; n_coeff < length; n_coeff++ )
    {
        L_am_org = L_add( L_am_org, L_deposit_l( org_spec[n_coeff] ) ); /*Q10 */
        L_am_gen = L_add( L_am_gen, L_deposit_l( gen_spec[n_coeff] ) ); /*Q10 */

        IF( org_spec[n_coeff] != 0 )
        {
            L_tmp = L_deposit_h( org_spec[n_coeff] ); /*Q26 */
            e_tmp = norm_l( L_tmp );
            f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) );
            e_tmp = sub( sub( 30, e_tmp ), 26 );
            L_tmp = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */
            L_log_gm_org = L_add( L_log_gm_org, L_tmp );        /*Q14 */
        }

        IF( gen_spec[n_coeff] != 0 )
        {
            L_tmp = L_deposit_h( gen_spec[n_coeff] ); /*Q26 */
            e_tmp = norm_l( L_tmp );
            f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) );
            e_tmp = sub( sub( 30, e_tmp ), 26 );
            L_tmp = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */
            L_log_gm_gen = L_add( L_log_gm_gen, L_tmp );        /*Q14 */
        }
    }

    IF( L_am_org != 0 )
    {
        L_tmp = Mpy_32_16_1( L_am_org, inv_len ); /*Q10 */
        e_tmp = norm_l( L_tmp );
        f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) );
        e_tmp = sub( sub( 30, e_tmp ), 10 );
        L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */
    }
    ELSE
    {
        L_tmp1 = L_deposit_l( 0 );
    }

    L_tmp2 = Mpy_32_16_1( L_log_gm_org, inv_len ); /* Q14 */

    L_tmp = L_sub( L_tmp1, L_tmp2 );
#ifdef BASOP_NOGLOB
    *SFM_org = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */
#else
    *SFM_org = round_fx( L_shl( L_tmp, 14 ) ); /*Q12 */
#endif
    move16();
    *SFM_org = s_max( 0, s_min( *SFM_org, 24547 ) );
    move16(); /*0.0001 and 5.993 in Q12 */

    IF( L_am_gen != 0 )
    {
        L_tmp = Mpy_32_16_1( L_am_gen, inv_len ); /*Q10 */
        e_tmp = norm_l( L_tmp );
        f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) );
        e_tmp = sub( sub( 30, e_tmp ), 10 );
        L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */
    }
    ELSE
    {
        L_tmp1 = L_deposit_l( 0 );
    }

    L_tmp2 = Mpy_32_16_1( L_log_gm_gen, inv_len ); /* Q14 */

    L_tmp = L_sub( L_tmp1, L_tmp2 );
#ifdef BASOP_NOGLOB
    *SFM_gen = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */
#else
    *SFM_gen = round_fx( L_shl( L_tmp, 14 ) ); /*Q12 */
#endif
    move16();
    *SFM_gen = s_max( 0, s_min( *SFM_gen, 24547 ) );
    move16(); /*0.0001 and 5.993 in Q12 */

    return;
}

#ifdef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
 * calculate_Tonality_ivas_fx()
 *
 * Calculate tonality
 *-------------------------------------------------------------------*/

static void calculate_Tonality_ivas_fx(
    const Word16 *org,  /* i  : MDCT coefficients of original              Q_new*/
    const Word16 *gen,  /* i  : MDCT coefficients of generated signal    Q15*/
    Word16 *SFM_org,    /* o  : Spectral Flatness results          Q12*/
    Word16 *SFM_gen,    /* o  : Spectral Flatness results                  Q12*/
    const Word16 length /* i  : length for calculating tonality         */
)
{
    Word16 n_coeff;
    Word16 inv_len, max;
    Word16 exp, e_tmp, f_tmp;
    Word32 L_tmp, L_tmp2, L_am_org, L_am_gen, L_tmp1;
    Word16 org_spec[80], gen_spec[80];
    Word32 L_log_gm_org, L_log_gm_gen;
    Word16 l_shift;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif

    /* to reduce dynamic range of original spectrum */
    max = 0;
    move16();
    FOR( n_coeff = 0; n_coeff < length; n_coeff++ )
    {
        org_spec[n_coeff] = abs_s( org[n_coeff] );
        move16(); /*Q_new */
        /*test(); */
        /*if( sub(max, org_spec[n_coeff]) < 0) */
        /*{ */
        /*    max = org_spec[n_coeff];move16();//Q_new */
        /*} */
        max = s_max( max, org_spec[n_coeff] );
    }
    l_shift = norm_s( max );
    FOR( n_coeff = 0; n_coeff < length; n_coeff++ )
    {
        org_spec[n_coeff] = shl( org_spec[n_coeff], l_shift );
        move16();
        IF( org_spec[n_coeff] == 0 )
        {
            org_spec[n_coeff] = shl( 1, l_shift );
            move16();
        }
    }

    max = 0;
    move16();
    FOR( n_coeff = 0; n_coeff < length; n_coeff++ )
@@ -2162,6 +2333,7 @@ static void calculate_Tonality_fx(

    return;
}
#endif

/*-------------------------------------------------------------------*
 * energy_control_fx()
@@ -2333,7 +2505,7 @@ static void energy_control_ivas_fx(

    FOR( n_band = 0; n_band < max_band; )
    {
        calculate_Tonality_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset,
        calculate_Tonality_ivas_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset,
                                    &SFM_org_fx[n_band], &SFM_gen_fx[n_band], swb_bwe_subband[n_band + band_step] - swb_bwe_subband[n_band] );

        IF( LT_16( SFM_gen_fx[n_band], mult_r( 24576, SFM_org_fx[n_band] ) ) )