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

Reverted changes in computeDiffuseness_fixed to resolve regressions

parent 8e2135bd
Loading
Loading
Loading
Loading
Loading
+66 −23
Original line number Diff line number Diff line
@@ -793,66 +793,109 @@ void computeDiffuseness_fixed(
)
{
    Word32 intensity_slow[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX];
    Word16 intensity_slow_e[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX];
    Word32 intensity_slow_abs[CLDFB_NO_CHANNELS_MAX];
    Word64 intensity_slow_abs_64[CLDFB_NO_CHANNELS_MAX];
    Word16 intensity_slow_abs_q[CLDFB_NO_CHANNELS_MAX];
    Word32 energy_slow[CLDFB_NO_CHANNELS_MAX];
    Word16 energy_slow_e[CLDFB_NO_CHANNELS_MAX];
    Word16 i, j, k;
    Word32 tmp = 0;
    move32();
    Word32 *p_tmp;
    const Word32 *p_tmp_c;
    Word16 exp1, exp2, q_tmp;
    Word16 min_q_shift1, min_q_shift2, exp1, exp2, q_tmp;
    Word16 q_ene, q_intensity;

    /* Compute Intensity slow and energy slow buffer_intensity and buffer_energy */

    set_zero_fx( intensity_slow, ( DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX ) );
    set16_fx( intensity_slow_e, 0, ( DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX ) );
    set_zero_fx( intensity_slow, i_mult( DIRAC_NUM_DIMS, CLDFB_NO_CHANNELS_MAX ) );
    set_zero_fx( intensity_slow_abs, CLDFB_NO_CHANNELS_MAX );
    set_zero_fx( energy_slow, CLDFB_NO_CHANNELS_MAX );
    set16_fx( energy_slow_e, 0, CLDFB_NO_CHANNELS_MAX );

    /* Calculate max possible shift for the buffer buffer_energy and buffer_intensity */
    min_q_shift1 = Q31;
    move16();
    min_q_shift1 = s_min( min_q_shift1, getScaleFactor32( buffer_energy, i_mult( DIRAC_NO_COL_AVG_DIFF, num_freq_bands ) ) );
    min_q_shift1 = sub( min_q_shift1, find_guarded_bits_fx( DIRAC_NO_COL_AVG_DIFF ) );

    min_q_shift2 = Q31;
    move16();
    FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
    {
        FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
        {
            min_q_shift2 = s_min( min_q_shift2, getScaleFactor32( buffer_intensity[i][j], num_freq_bands ) );
        }
    }
    min_q_shift2 = sub( min_q_shift2, find_guarded_bits_fx( DIRAC_NO_COL_AVG_DIFF ) );

    q_ene = add( q_factor_energy[0], min_q_shift1 );
    move16();
    q_intensity = add( q_factor_intensity[0], min_q_shift2 );
    move16();

    FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i )
    {
        /* Energy slow */
        p_tmp_c = buffer_energy + i * num_freq_bands;

        q_tmp = add( q_factor_energy[i], min_q_shift1 );


        Word16 shift_q = sub( q_tmp, q_ene );
        Word32 shiftEquiv = L_add( 0, 0 );
        Word16 shift_qtotal;
        if ( shift_q < 0 )
        {
            shiftEquiv = L_lshl( (Word32) 0x80000000, shift_q );
        }
        if ( shift_q >= 0 )
        {
            shiftEquiv = L_add( 0x7FFFFFFF, 0 );
        }
        shift_qtotal = sub( min_q_shift1, s_max( shift_q, 0 ) );

        FOR( k = 0; k < num_freq_bands; k++ )
        {
            energy_slow[k] = BASOP_Util_Add_Mant32Exp( p_tmp_c[k], sub( 31, q_factor_energy[i] ), energy_slow[k], energy_slow_e[k], &energy_slow_e[k] );
            tmp = L_shl( p_tmp_c[k], shift_qtotal );
            energy_slow[k] = Madd_32_32_r( tmp, energy_slow[k], shiftEquiv );
            move32();
        }


        q_ene = s_min( q_ene, q_tmp );

        /* Intensity slow */
        q_tmp = add( q_factor_intensity[i], min_q_shift2 );

        shift_q = sub( q_tmp, q_intensity );
        if ( shift_q < 0 )
        {
            shiftEquiv = L_lshl( (Word32) 0x80000000, shift_q );
        }
        if ( shift_q >= 0 )
        {
            shiftEquiv = L_lshl( 0x7FFFFFFF, 0 );
        }
        shift_qtotal = sub( min_q_shift2, s_max( shift_q, 0 ) );

        FOR( j = 0; j < DIRAC_NUM_DIMS; ++j )
        {
            p_tmp = buffer_intensity[j][i];
            FOR( k = 0; k < num_freq_bands; k++ )
            {
                intensity_slow[j * num_freq_bands + k] = BASOP_Util_Add_Mant32Exp( p_tmp[k], sub( 31, q_factor_intensity[i] ), intensity_slow[j * num_freq_bands + k], intensity_slow_e[j * num_freq_bands + k], &intensity_slow_e[j * num_freq_bands + k] );
                tmp = L_shl( p_tmp[k], shift_qtotal );
                intensity_slow[j * num_freq_bands + k] = Madd_32_32_r( tmp, intensity_slow[j * num_freq_bands + k], shiftEquiv );
                move32();
            }
        }
    }
    Word16 max_e;
    maximum_fx( energy_slow_e, CLDFB_NO_CHANNELS_MAX, &max_e );
    q_ene = sub( 31, max_e );
    FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ )
    {
        energy_slow[i] = L_shr( energy_slow[i], sub( max_e, energy_slow_e[i] ) ); // scaling to q_ene
        move32();
    }

    maximum_fx( intensity_slow_e, DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX, &max_e );
    q_intensity = sub( 31, max_e );
    FOR( i = 0; i < DIRAC_NUM_DIMS * num_freq_bands; i++ )
    {
        intensity_slow[i] = L_shr( intensity_slow[i], sub( max_e, intensity_slow_e[i] ) ); // scaling to q_intensity
        move32();
        q_intensity = s_min( q_intensity, q_tmp );
    }

    min_q_shift1 = getScaleFactor32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ) );
    min_q_shift1 = sub( min_q_shift1, idiv1616( add( find_guarded_bits_fx( DIRAC_NUM_DIMS ), 1 ), 2 ) );
    scale_sig32( intensity_slow, i_mult( DIRAC_NUM_DIMS, num_freq_bands ), min_q_shift1 );
    q_intensity = add( q_intensity, min_q_shift1 );
    FOR( k = 0; k < num_freq_bands; k++ )
    {
        intensity_slow_abs_64[k] = 0;