Commit f5b0d6fa authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch '3gpp_issue_1786_fix' into 'main'

[allow regression] Fix for 3GPP issue 1786: Metadata output result of MASA prerend with muted...

See merge request !1861
parents 5d9ebfb5 25242c01
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -978,7 +978,7 @@ static Word16 quantize_phi_masa_fx(
    Word32 tmp32;
    Word16 tmp_e, delta_phi_e;

    delta_phi_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( 360, n, &delta_phi_e ) );
    delta_phi_fx = BASOP_Util_Divide3232_Scale_newton( 360, n, &delta_phi_e );
    delta_phi_fx = L_shr( delta_phi_fx, sub( sub( 31, delta_phi_e ), 22 ) ); // Q22

    IF( EQ_16( n, 1 ) )
@@ -1000,8 +1000,8 @@ static Word16 quantize_phi_masa_fx(
    }

    tmp32 = L_add( L_sub( phi_fx, dd_fx ), L_shr( delta_phi_fx, 1 ) );
    id_phi = BASOP_Util_Divide3232_Scale( tmp32, delta_phi_fx, &tmp_e );
    id_phi = shr( id_phi, sub( 15, tmp_e ) ); // Q0
    tmp32 = BASOP_Util_Divide3232_Scale_newton( tmp32, delta_phi_fx, &tmp_e );
    id_phi = extract_l( L_shr( tmp32, sub( 31, tmp_e ) ) ); // Q0

    if ( EQ_16( id_phi, n ) )
    {
@@ -1014,7 +1014,10 @@ static Word16 quantize_phi_masa_fx(
        id_phi = sub( n, 1 );
    }

    *phi_hat_fx = L_add( L_shl( Mpy_32_16_1( delta_phi_fx, id_phi ), 15 ), dd_fx ); // q22 + q0 - 15 = q7 -> q7 + 15 = q22
    delta_phi_fx = BASOP_Util_Divide3232_Scale_newton( L_mult0( 360, id_phi ), n, &delta_phi_e );
    delta_phi_fx = L_shr( delta_phi_fx, sub( sub( 31, delta_phi_e ), 22 ) ); // Q22

    *phi_hat_fx = L_add( delta_phi_fx, dd_fx ); // Q22
    move32();

    return id_phi; // Q0
+33 −18
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "wmc_auto.h"
#include "ivas_prot_fx.h"

#define INV_UINT8_MAX 8421505 /* 1/UINT8_MAX in Q31 */

/*---------------------------------------------------------------------*
 * Local function prototypes
@@ -172,31 +173,37 @@ void diffuse_meta_merge_1x1_fx(
        FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
        {
            Word32 energyTimesRatio_fx, energyTimesRatioISM_fx, total_diff_nrg_fx, dir_nrg_ratio_fx, total_nrg_fx = 0;
            Word32 dir_ratio_ism_fx, L_tmp1, L_tmp2;
            Word32 dir_ratio_ism_fx, L_tmp, L_tmp1, L_tmp2;
            Word16 scale, energyTimesRatio_e, tmp, total_nrg_e = 0, total_diff_nrg_e, dir_ratio_ism_e, energyTimesRatioISM_e, dir_nrg_ratio_e;
            move32();
            move16();

            tmp = BASOP_Util_Divide1616_Scale( inMeta->directToTotalRatio[0][sf][band], UINT8_MAX, &scale );
            energyTimesRatio_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); /* Q( 31 - ( nEne_e[sf] + scale ) ) */
            L_tmp = Mpy_32_16_1( INV_UINT8_MAX, inMeta->directToTotalRatio[0][sf][band] ); // Q31 - 15 => Q16
            scale = 15;
            move16();
            energyTimesRatio_fx = Mpy_32_32_r( inEne_fx[sf][band], L_tmp ); /* Q( 31 - ( nEne_e[sf] + scale ) ) */
            energyTimesRatio_e = add( inEne_e[sf][band], scale );
            total_nrg_fx = BASOP_Util_Add_Mant32Exp( inEne_fx[sf][band], inEne_e[sf][band], inEneISM_fx[sf][band], inEneISM_e[sf][band], &total_nrg_e );

            /* target is original MASA diffuseness */
            tmp = BASOP_Util_Divide1616_Scale( inMeta->diffuseToTotalRatio[sf][band], UINT8_MAX, &scale );
            total_diff_nrg_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); /* Q( 31 - ( nEne_e[sf] + scale ) ) */
            L_tmp = Mpy_32_16_1( INV_UINT8_MAX, inMeta->diffuseToTotalRatio[sf][band] ); // Q31 - 15 => Q16
            scale = 15;
            move16();
            total_diff_nrg_fx = Mpy_32_32_r( inEne_fx[sf][band], L_tmp ); /* Q( 31 - ( nEne_e[sf] + scale ) ) */
            total_diff_nrg_e = add( inEne_e[sf][band], scale );

            /* criterion is mean of ISM ratio and new ratio */
            dir_ratio_ism_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( inMetaISM->directToTotalRatio[0][sf][band], UINT8_MAX, &dir_ratio_ism_e ) );
            dir_ratio_ism_fx = Mpy_32_16_1( INV_UINT8_MAX, inMetaISM->directToTotalRatio[0][sf][band] ); // Q31 - 15 => Q16
            dir_ratio_ism_e = 15;
            move16();
            tmp = BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, L_add( total_nrg_fx, EPSILON_FX ), &scale );
            L_tmp1 = L_deposit_h( tmp ); /* Q( 31 - ( scale + total_nrg_e - total_diff_nrg_e ) ) */
            scale = add( scale, sub( total_diff_nrg_e, total_nrg_e ) );
            IF( L_tmp1 == 0 )
            {
                scale = 31;
                scale = 0;
                move16();
                L_tmp2 = 1;
                L_tmp2 = MAX_32;
                move32();
            }
            ELSE
@@ -245,7 +252,7 @@ void diffuse_meta_merge_1x1_fx(
                    move16();
                }

                outMeta->directToTotalRatio[0][sf][band] = (UWord8) extract_l( L_shr( new_dir_ratio_fx, sub( sub( 31, new_dir_ratio_e ), 8 ) ) );
                outMeta->directToTotalRatio[0][sf][band] = (UWord8) extract_l( L_shr( Mpy_32_16_1( new_dir_ratio_fx, UINT8_MAX ) /* (31 - new_dir_ratio_e) - 15*/, sub( 31 - 15, new_dir_ratio_e ) ) );
                move16();
                IF( GT_16( sub( 31, new_dir_ratio_e ), Q30 ) )
                {
@@ -325,7 +332,7 @@ void full_stream_merge_fx(
{
    UWord8 n_dirs_1, n_dirs_2;
    UWord8 sf, band;
    Word16 scale, tmp, dir_nrg_1_e, dir_nrg_2_e;
    Word16 scale, dir_nrg_1_e, dir_nrg_2_e;
    Word32 dir_nrg_1_fx, dir_nrg_2_fx, L_tmp;

    /* full stream select based on total direct energy */
@@ -336,26 +343,34 @@ void full_stream_merge_fx(
    {
        FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
        {
            tmp = BASOP_Util_Divide1616_Scale( inMeta1->directToTotalRatio[0][sf][band], UINT8_MAX, &scale );
            dir_nrg_1_fx = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); /* Q( 31 - ( scale + inEne1_e[sf] ) ) */
            L_tmp = Mpy_32_16_1( INV_UINT8_MAX, inMeta1->directToTotalRatio[0][sf][band] ); // Q31 - 15 => Q16
            scale = 15;
            move16();
            dir_nrg_1_fx = Mpy_32_32( L_tmp, inEne1_fx[sf][band] ); /* Q( 31 - ( scale + inEne1_e[sf] ) ) */
            dir_nrg_1_e = add( scale, inEne1_e[sf][band] );

            tmp = BASOP_Util_Divide1616_Scale( inMeta2->directToTotalRatio[0][sf][band], UINT8_MAX, &scale );
            dir_nrg_2_fx = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); /* Q( 31 - ( scale + inEne2_e[sf] ) ) */
            L_tmp = Mpy_32_16_1( INV_UINT8_MAX, inMeta2->directToTotalRatio[0][sf][band] ); // Q31 - 15 => Q16
            scale = 15;
            move16();
            dir_nrg_2_fx = Mpy_32_32( L_tmp, inEne2_fx[sf][band] ); /* Q( 31 - ( scale + inEne2_e[sf] ) ) */
            dir_nrg_2_e = add( scale, inEne2_e[sf][band] );

            IF( EQ_16( n_dirs_1, 2 ) )
            {
                tmp = BASOP_Util_Divide1616_Scale( inMeta1->directToTotalRatio[1][sf][band], UINT8_MAX, &scale );
                L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); /* Q( 31 - ( scale + inEne1_e[sf] ) ) */
                L_tmp = Mpy_32_16_1( INV_UINT8_MAX, inMeta1->directToTotalRatio[1][sf][band] ); // Q31 - 15 => Q16
                scale = 15;
                move16();
                L_tmp = Mpy_32_32( L_tmp, inEne1_fx[sf][band] ); /* Q( 31 - ( scale + inEne1_e[sf] ) ) */
                scale = add( scale, inEne1_e[sf][band] );
                dir_nrg_1_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale, dir_nrg_1_fx, dir_nrg_1_e, &dir_nrg_1_e );
            }

            IF( EQ_16( n_dirs_2, 2 ) )
            {
                tmp = BASOP_Util_Divide1616_Scale( inMeta2->directToTotalRatio[1][sf][band], UINT8_MAX, &scale );
                L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); /* Q( 31 - ( scale + inEne2_e[sf] ) ) */
                L_tmp = Mpy_32_16_1( INV_UINT8_MAX, inMeta2->directToTotalRatio[1][sf][band] ); // Q31 - 15 => Q16
                scale = 15;
                move16();
                L_tmp = Mpy_32_32( L_tmp, inEne2_fx[sf][band] ); /* Q( 31 - ( scale + inEne2_e[sf] ) ) */
                scale = add( scale, inEne2_e[sf][band] );
                dir_nrg_2_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale, dir_nrg_2_fx, dir_nrg_2_e, &dir_nrg_2_e );
            }