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

Merge branch 'dirac_rend_funcs_and_cleanup' into 'main'

Few dirac_rend functions converted to fixed point, cleanup of float code in core decoder and CPE.

See merge request !273
parents 5827f1cb 9a457d33
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ Word32 L_abs( Word32 L_var1 ); /*
Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry );            /* Long saturation,       4  */
Word16 norm_s( Word16 var1 );                                                /* Short norm,            1  */
Word16 div_s( Word16 var1, Word16 var2 );                                    /* Short division,       18  */
Word32 div_w(Word32 L_num, Word32 L_den);
Word16 norm_l( Word32 L_var1 );                                              /* Long norm,             1  */
#endif                                    /* BASOP_NOGLOB */

+98 −0
Original line number Diff line number Diff line
@@ -933,6 +933,104 @@ Word16 BASOP_Util_Divide3232_uu_1616_Scale(Word32 x, Word32 y, Word16 *s)
  return (z);
}

Word32 div_w( Word32 L_num, Word32 L_den )
{
    Word32 L_var_out = (Word32) 0;
    Word16 iteration;


    if ( L_den == (Word32) 0 )
    {
        /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */
        return ( 0 );
    }

    if ( ( L_num < (Word32) 0 ) || ( L_den < (Word32) 0 ) )
    {
        /* printf("Division Error in div_l, Fatal error in "); printStack(); */
        return ( 0 );
    }
    Word64 W_num, W_den;
    W_num = W_deposit32_h( L_num );
    W_den = W_deposit32_h( L_den );

    if ( W_num >= W_den )
    {
        return MAX_32;
    }
    else
    {
        W_num = W_shr( W_num, (Word16) 1 );
        W_den = W_shr( W_den, (Word16) 1 );

        for ( iteration = (Word16) 0; iteration < (Word16) 31; iteration++ )
        {
            L_var_out = L_shl( L_var_out, (Word16) 1 );
            W_num = W_shl( W_num, (Word16) 1 );

            if ( W_num >= W_den )
            {
                W_num = W_sub( W_num, W_den );
                L_var_out = L_add( L_var_out, (Word32) 1 );
            }
        }

        return L_var_out;
    }
}

Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s )
{
    Word32 z;
    Word16 sx;
    Word16 sy;
    Word32 sign;

    /* assert (x >= (Word32)0); */
    assert( y != (Word32) 0 );

    sign = 0;
    move16();

    IF( x < 0 )
    {
        x = L_negate( x );
        sign = L_xor( sign, 1 );
    }

    IF( y < 0 )
    {
        y = L_negate( y );
        sign = L_xor( sign, 1 );
    }

    IF( x == (Word32) 0 )
    {
        *s = 0;
        return ( (Word32) 0 );
    }

    sx = norm_l( x );
    x = L_shl( x, sx );
    x = L_shr( x, 1 );
    move16();
    *s = sub( 1, sx );

    sy = norm_l( y );
    y = L_shl( y, sy );
    move16();
    *s = add( *s, sy );

    z = div_w( x, y );

    if ( sign != 0 )
    {
        z = L_negate( z );
    }

    return z;
}

Word16 BASOP_Util_Divide3232_Scale(Word32 x, Word32 y, Word16 *s)
{
  Word16 z;
+4 −0
Original line number Diff line number Diff line
@@ -325,6 +325,10 @@ Word16 BASOP_Util_Divide3232_Scale(Word32 x, /*!< i : Numerator*/
  Word32 y,   /*!< i  : Denominator*/
  Word16 *s); /*!< o  : Additional scalefactor difference*/

Word32 BASOP_Util_Divide3232_Scale_cadence(Word32 x,   /*!< i  : Numerator*/
  Word32 y,   /*!< i  : Denominator*/
  Word16 *s); /*!< o  : Additional scalefactor difference*/


/************************************************************************/
/*!
+3 −3
Original line number Diff line number Diff line
@@ -85,11 +85,11 @@ float fixedToFloat_32( Word32 number, Word16 Q )
    {
        if ( Q > 0 )
        {
            val = (float) ( ( number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) );
            val = ( ( (float) number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) );
        }
        else
        {
            val = (float) ( number * ( 1 << ( -Q - 31 ) ) * (unsigned int)MIN_32 );
            val = ( (float) number * ( 1 << ( -Q - 31 ) ) * (unsigned int) MIN_32 );
        }
    }
    else
+160 −0
Original line number Diff line number Diff line
@@ -1122,6 +1122,166 @@ void computeDiffuseness_fx(

#endif


#ifdef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------------
 * computeDiffuseness()
 *
 *
 *------------------------------------------------------------------------*/

void computeDiffuseness_fixed(
    Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF],
    const Word32 *buffer_energy,
    const Word16 num_freq_bands,
    Word32 *diffuseness,
    Word16 *q_factor_intensity,
    Word16 *q_factor_energy,
    Word16 *q_diffuseness /*Ouput Q*/
)
{
    Word32 intensity_slow[DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX];
    Word32 intensity_slow_abs[CLDFB_NO_CHANNELS_MAX];
    Word32 energy_slow[CLDFB_NO_CHANNELS_MAX];
    Word16 i, j, k;
    Word32 tmp = 0;
    Word32 *p_tmp;
    const Word32 *p_tmp_c;
    Word16 min_q_shift1, min_q_shift2, exp1, exp2, q_tmp;
    Word16 q_ene, q_intensity, q_intensity_slow;

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

    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 );

    /* 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();
    min_q_shift2 = s_min( min_q_shift2, getScaleFactor32( buffer_energy, i_mult( DIRAC_NUM_DIMS, i_mult( DIRAC_NO_COL_AVG_DIFF, num_freq_bands ) ) ) );
    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 = sub( 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_mult( i, num_freq_bands );

        q_tmp = add( q_factor_energy[i], min_q_shift1 );
        FOR( k = 0; k < num_freq_bands; k++ )
        {
            tmp = L_shl( p_tmp_c[k], min_q_shift1 );
            IF( LT_16( q_tmp, q_ene ) )
            {
                energy_slow[k] = L_add( L_shr( energy_slow[k], sub( q_ene, q_tmp ) ), tmp );
                move32();
            }
            ELSE
            {
                energy_slow[k] = L_add( energy_slow[k], L_shr( tmp, sub( q_tmp, q_ene ) ) );
                move32();
            }
        }
        q_ene = s_min( q_ene, q_tmp );

        /* Intensity slow */
        q_tmp = sub( q_factor_intensity[i], min_q_shift2 );
        FOR( j = 0; j < DIRAC_NUM_DIMS; ++j )
        {
            p_tmp = buffer_intensity[j][i];
            FOR( k = 0; k < num_freq_bands; k++ )
            {
                tmp = L_shr( p_tmp[k], min_q_shift2 );
                IF( LT_16( q_intensity, q_tmp ) )
                {
                    intensity_slow[add( i_mult( j, num_freq_bands ), k )] = L_add( intensity_slow[add( i_mult( j, num_freq_bands ), k )], L_shr( tmp, sub( q_tmp, q_intensity ) ) );
                    move32();
                }
                ELSE
                {
                    intensity_slow[add( i_mult( j, num_freq_bands ), k )] = L_add( L_shr( intensity_slow[add( i_mult( j, num_freq_bands ), k )], sub( q_intensity, q_tmp ) ), tmp );
                    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 );

    /* intensity_slow.^2 + intensity_slow_abs*/
    FOR( j = 0; j < DIRAC_NUM_DIMS; ++j )
    {
        p_tmp = intensity_slow + i_mult( j, num_freq_bands );

        FOR( k = 0; k < num_freq_bands; k++ )
        {
            p_tmp[k] = Mpy_32_32( p_tmp[k], p_tmp[k] );
            move32();
            intensity_slow_abs[k] = L_add( intensity_slow_abs[k], p_tmp[k] );
            move32();
        }
    }
    q_intensity_slow = sub( add( q_intensity, q_intensity ), 31 );

    /* Compute Diffuseness */
    p_tmp = intensity_slow_abs;
    exp2 = 0;
    move16();
    FOR( i = 0; i < num_freq_bands; ++i )
    {
        exp1 = sub( 31, q_intensity_slow );
        tmp = Sqrt32( p_tmp[i], &exp1 );

        tmp = BASOP_Util_Divide3232_Scale_cadence( tmp, L_add( energy_slow[i], EPSILLON_FX ), &exp2 );
        q_tmp = sub( 31, exp2 ) + sub( sub( 31, exp1 ), q_ene );

        IF( LT_16( q_tmp, Q30 ) )
        {
            tmp = L_sub( L_shr( ONE_IN_Q30, sub( Q30, q_tmp ) ), tmp );
        }
        ELSE
        {
            tmp = L_sub( ONE_IN_Q30, L_shr( tmp, sub( q_tmp, Q30 ) ) );
            q_tmp = Q30;
        }

        IF( GE_32( tmp, L_shl( 1, q_tmp ) ) )
        {
            diffuseness[i] = ONE_IN_Q30;
            move32();
        }
        ELSE IF( LE_32( tmp, 0 ) )
        {
            diffuseness[i] = 0;
            move32();
        }
        ELSE
        {
            diffuseness[i] = L_shl( tmp, sub( Q30, q_tmp ) );
            move32();
        }
    }
    *q_diffuseness = Q30;
    move16();

    return;
}
#endif

/*-------------------------------------------------------------------------
 * computeDiffuseness()
 *
Loading