Commit 63bb612b authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'switch_div32_newton_part04' into 'main'

lib_enc: replace BASOP_Util_Divide3232_Scale_cadence() by BASOP_Util_Divide3232_Scale_newton() [allow regression]

See merge request !1413
parents aa97e07e f34b6383
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -329,7 +329,7 @@ void find_tilt_ivas_fx(
    {
        hp_bckr = L_deposit_l( 1 );
    }
    Ltmp = BASOP_Util_Divide3232_Scale_cadence( lp_bckr, hp_bckr, &e_tmp );
    Ltmp = BASOP_Util_Divide3232_Scale_newton( lp_bckr, hp_bckr, &e_tmp );
    Ltmp = Mpy_32_16_r( Ltmp, 3277 /* 0.1f in Q15 */ );
    Ltmp = L_shr_sat( Ltmp, sub( 15, e_tmp ) );
    *bckr_tilt_lt = L_add_sat( Mpy_32_16_r( *bckr_tilt_lt, 29491 /* 0.9f in Q15 */ ), Ltmp ); // Q16
+3 −3
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ static Word16 hf_spectrum_sparseness_fx(
            Word16 l_shift = W_norm( inv_rms_fx );
            inv_rms32_fx = W_extract_h( W_shl( inv_rms_fx, l_shift ) );                                     // Q15+l_shift-32
            Word16 q_rms = sub( add( Q15, l_shift ), 32 );                                                  // q_rms
            inv_rms32_div_fx = BASOP_Util_Divide3232_Scale_cadence( inv_rms32_fx, L_SPEC_HB, &inv_rms32_e ); /* Q31-inv_rms32_e */
            inv_rms32_div_fx = BASOP_Util_Divide3232_Scale_newton( inv_rms32_fx, L_SPEC_HB, &inv_rms32_e ); /* Q31-inv_rms32_e */
            inv_rms32_e = sub( 31, add( sub( Q31, inv_rms32_e ), q_rms ) );
            // inv_rms = 1.0f / (float) sqrtf( inv_rms / L_SPEC_HB );
            inv_rms32_fx = ISqrt32( inv_rms32_div_fx, &inv_rms32_e ); /* Q31-inv_rms32_e */
+1 −1
Original line number Diff line number Diff line
@@ -271,7 +271,7 @@ static Word16 ivas_spar_get_activeW_flag_fx(
    }
    ELSE
    {
        L_tmp = BASOP_Util_Divide3232_Scale_cadence( hCovEnc->bb_var_lt_fx[0], side_ch_var, &exp_diff );       // (Q31 - exp_diff)
        L_tmp = BASOP_Util_Divide3232_Scale_newton( hCovEnc->bb_var_lt_fx[0], side_ch_var, &exp_diff );        // (Q31 - exp_diff)
        en_ratio = L_shl_sat( L_tmp, exp_diff );                                                               // Q31
        IF( LT_32( en_ratio, Mpy_32_32( IVAS_SPAR_DYN_ACTIVEW_THRESH_FX, IVAS_SPAR_DYN_ACTIVEW_THRESH_FX ) ) ) // LHS Q31 :: RHS Q31
        {
+12 −12
Original line number Diff line number Diff line
@@ -1477,7 +1477,7 @@ static void combine_freqbands_and_subframes_fx(
                    move16();

                    hMeta->directional_meta[i].energy_ratio_fx[j][k] =
                        BASOP_Util_Divide3232_Scale_cadence( vecLen, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+vecLen_e-energySum_e*/
                        BASOP_Util_Divide3232_Scale_newton( vecLen, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+vecLen_e-energySum_e*/
                    move32();
                    exp_diff = add( exp_diff, sub( vecLen_e, energySum_e ) );
                    hMeta->directional_meta[i].energy_ratio_fx[j][k] =
@@ -1585,7 +1585,7 @@ static void combine_freqbands_and_subframes_fx(
                {
                    energyRatioSum = BASOP_Util_Add_Mant32Exp( energyRatioSum, energyRatioSum_e, Mpy_32_32( energy[j][k], hMeta->directional_meta[i].energy_ratio_fx[j][k] ), add( energy_e[j][k], 1 ), &energyRatioSum_e ); // 31-energyRatioSum_e
                }
                energyRatioTemp = BASOP_Util_Divide3232_Scale_cadence( energyRatioSum, L_add( energySum, EPSILON_FX ), &exp_diff );
                energyRatioTemp = BASOP_Util_Divide3232_Scale_newton( energyRatioSum, L_add( energySum, EPSILON_FX ), &exp_diff );
                exp_diff = add( exp_diff, sub( energyRatioSum_e, energySum_e ) );
                energyRatioTemp = L_shl( energyRatioTemp, sub( exp_diff, 1 ) ); // Q30

@@ -2264,13 +2264,13 @@ static void compensate_energy_ratios_fx(
                FOR( dir = 0; dir < numDirs; dir++ )
                {
                    hMeta->directional_meta[dir].energy_ratio_fx[sf][band] =
                        BASOP_Util_Divide3232_Scale_cadence( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum, &exp_diff );
                        BASOP_Util_Divide3232_Scale_newton( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum, &exp_diff );
                    move32();
                    hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30
                    move32();
                }
                hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] =
                    BASOP_Util_Divide3232_Scale_cadence( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum, &exp_diff );
                    BASOP_Util_Divide3232_Scale_newton( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum, &exp_diff );
                move32();
                hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30
                move32();
@@ -2406,7 +2406,7 @@ static void reduce_metadata_further_fx(

    IF( hMasa->data.onset_detector_1_fx != 0 )
    {
        onset_filter = L_max( BASOP_Util_Divide3232_Scale_cadence( hMasa->data.onset_detector_2_fx, hMasa->data.onset_detector_1_fx, &onset_filter_e ), 0 );
        onset_filter = L_max( BASOP_Util_Divide3232_Scale_newton( hMasa->data.onset_detector_2_fx, hMasa->data.onset_detector_1_fx, &onset_filter_e ), 0 );

        IF( BASOP_Util_Cmp_Mant32Exp( onset_filter, onset_filter_e, ONE_IN_Q31, 0 ) > 0 )
        {
@@ -2433,7 +2433,7 @@ static void reduce_metadata_further_fx(
            Word32 bandRatio;

            // threshold = totalEnergySum / ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 0.5f; /* Average energy multiplied with energy ratio of 0.5f */
            threshold = BASOP_Util_Divide3232_Scale_cadence( totalEnergySum, ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 2, &exp ); /* Average energy multiplied with energy ratio of 0.5f */
            threshold = BASOP_Util_Divide3232_Scale_newton( totalEnergySum, ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 2, &exp ); /* Average energy multiplied with energy ratio of 0.5f */
            exp = add( exp, sub( sub( 31, add( hMasa->data.q_energy, tmp2 ) ), 31 ) );
            bandRatio = hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[0]; // Q30
            move32();
@@ -2468,7 +2468,7 @@ static void reduce_metadata_further_fx(
        }
        IF( totalEnergySum != 0 )
        {
            meanRatio = BASOP_Util_Divide3232_Scale_cadence( meanRatio, totalEnergySum, &exp );
            meanRatio = BASOP_Util_Divide3232_Scale_newton( meanRatio, totalEnergySum, &exp );
            exp = add( add( exp, 1 ), tmp2 ); // 31 - (hMasa->data.q_energy - 1) - 31 - hMasa->data.q_energy - tmp2 => 1 + tmp2
        }
        ELSE
@@ -4730,7 +4730,7 @@ static void ivas_encode_masaism_metadata_fx(

                FOR( obj = 0; obj < nchan_ism; obj++ )
                {
                    hOmasaData->energy_ratio_ism_fx[sf][0][obj] = BASOP_Util_Divide3232_Scale_cadence( energy_ism_ind[obj], energy_ism, &L_tmp_e );
                    hOmasaData->energy_ratio_ism_fx[sf][0][obj] = BASOP_Util_Divide3232_Scale_newton( energy_ism_ind[obj], energy_ism, &L_tmp_e );
                    move32();
                    L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) );
                    /* Scaling to Q30 */
@@ -4740,7 +4740,7 @@ static void ivas_encode_masaism_metadata_fx(
                L_tmp = BASOP_Util_Add_Mant32Exp( eneBand32, eneBand_exp, energy_ism, energy_ism_e, &L_tmp_e );
                IF( L_tmp != 0 )
                {
                    hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = BASOP_Util_Divide3232_Scale_cadence( eneBand32, L_tmp, &tmp );
                    hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = BASOP_Util_Divide3232_Scale_newton( eneBand32, L_tmp, &tmp );
                    move32();
                    tmp = add( tmp, sub( eneBand_exp, L_tmp_e ) );
                    /* Scaling to Q30 */
@@ -4791,7 +4791,7 @@ static void ivas_encode_masaism_metadata_fx(
            {
                FOR( obj = 0; obj < nchan_ism; obj++ )
                {
                    hOmasaData->energy_ratio_ism_fx[0][band][obj] = BASOP_Util_Divide3232_Scale_cadence( energy_ism_ind[obj], energy_ism, &L_tmp_e );
                    hOmasaData->energy_ratio_ism_fx[0][band][obj] = BASOP_Util_Divide3232_Scale_newton( energy_ism_ind[obj], energy_ism, &L_tmp_e );
                    move32();
                    L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) );
                    /* Scaling to Q30 */
@@ -4819,7 +4819,7 @@ static void ivas_encode_masaism_metadata_fx(
                L_tmp = BASOP_Util_Add_Mant32Exp( eneBand32, eneBand_exp, energy_ism, energy_ism_e, &L_tmp_e );
                IF( L_tmp != 0 )
                {
                    hOmasaData->masa_to_total_energy_ratio_fx[0][band] = BASOP_Util_Divide3232_Scale_cadence( eneBand32, L_tmp, &tmp );
                    hOmasaData->masa_to_total_energy_ratio_fx[0][band] = BASOP_Util_Divide3232_Scale_newton( eneBand32, L_tmp, &tmp );
                    move32();
                    tmp = add( tmp, sub( eneBand_exp, L_tmp_e ) );
                    /* Scaling to Q30 */
@@ -4876,7 +4876,7 @@ static void ivas_encode_masaism_metadata_fx(
                    L_tmp = BASOP_Util_Add_Mant32Exp( eneBand32, eneBand_exp, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &L_tmp_e );
                    IF( L_tmp != 0 )
                    {
                        hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = BASOP_Util_Divide3232_Scale_cadence( eneBand32, L_tmp, &tmp );
                        hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = BASOP_Util_Divide3232_Scale_newton( eneBand32, L_tmp, &tmp );
                        move32();
                        tmp = add( tmp, sub( eneBand_exp, L_tmp_e ) );
                        /* Scaling to Q30 */
+5 −5
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ static Word16 kernel_switch_detect_fx(
    L_tmp1 = Sqrt32( L_tmp1, &exp_tmp1 );
    L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, exp_tmp, L_tmp1, exp_tmp1, &exp_tmp );
    L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, exp_tmp, ONE_IN_Q30, 1, &exp_tmp );
    cov00 = BASOP_Util_Divide3232_Scale_cadence( cov00, L_tmp, &exp_tmp1 );
    cov00 = BASOP_Util_Divide3232_Scale_newton( cov00, L_tmp, &exp_tmp1 );
    exp_tmp = add( exp_tmp1, sub( sub( Q31, q_com ), exp_tmp ) );
    /* Added saturation to handle overflows when value is very close to 1.f */
    cov00 = L_shl_sat( cov00, exp_tmp ); // Q31
@@ -247,7 +247,7 @@ static Word16 kernel_switch_detect_fx(
    L_tmp1 = Sqrt32( L_tmp1, &exp_tmp1 );
    L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, exp_tmp, L_tmp1, exp_tmp1, &exp_tmp );
    L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, exp_tmp, ONE_IN_Q30, 1, &exp_tmp );
    cov90 = BASOP_Util_Divide3232_Scale_cadence( cov90, L_tmp, &exp_tmp1 );
    cov90 = BASOP_Util_Divide3232_Scale_newton( cov90, L_tmp, &exp_tmp1 );
    exp_tmp = add( exp_tmp1, sub( sub( Q31, q_com ), exp_tmp ) );
    /* Added saturation to handle overflows when value is very close to 1.f */
    cov90 = L_shl_sat( cov90, exp_tmp ); // Q31
@@ -735,7 +735,7 @@ static void applyStereoPreProcessingCplx(
    d_q = sub( 31, d_q );

    deno = L_max( L_shl_sat( 1, d_q ), d_fx );
    sq_imp = BASOP_Util_Divide3232_Scale_cadence( n_fx, deno, &exp );
    sq_imp = BASOP_Util_Divide3232_Scale_newton( n_fx, deno, &exp );
    exp = add( exp, sub( d_q, n_q ) );
    d_fx = Sqrt32( sq_imp, &exp );
    *mdctSample1_fx = Mpy_32_32( dmxR1_fx, d_fx );
@@ -764,7 +764,7 @@ static void applyStereoPreProcessingCplx(
    d_q = sub( 31, d_q );

    deno = L_max( L_shl_sat( 1, d_q ), d_fx );
    sq_imp = BASOP_Util_Divide3232_Scale_cadence( n_fx, deno, &exp );
    sq_imp = BASOP_Util_Divide3232_Scale_newton( n_fx, deno, &exp );
    exp = add( exp, sub( d_q, n_q ) );
    d_fx = Sqrt32( sq_imp, &exp );
    *mdctSample2_fx = Mpy_32_32( dmxR2_fx, d_fx );
@@ -966,7 +966,7 @@ static UWord16 enc_ste_pre_mdct(
    ELSE
    {
        Word16 exp1;
        corr_fx = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( corr_fx, corr_fx ), Mpy_32_32( sumL_fx, sumR_fx ), &exp1 );
        corr_fx = BASOP_Util_Divide3232_Scale_newton( Mpy_32_32( corr_fx, corr_fx ), Mpy_32_32( sumL_fx, sumR_fx ), &exp1 );
        corr_e = add( exp1, sub( shl( corr_e, 1 ), add( sumL_e, sumR_e ) ) );
    }
    test();
Loading