Commit 1c27e59d authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Conversion of functions in ivas_lfe_plc

[x] Functions in LFE PLC converted to fixed point.
[x] Used new 32 bit division basop
BASOP_Util_Divide3232_Scale_cadence for more precision.
parent 24b88201
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -297,6 +297,7 @@
    <ClCompile Include="..\lib_dec\ivas_lfe_dec.c" />
    <ClCompile Include="..\lib_dec\ivas_lfe_dec_fx.c" />
    <ClCompile Include="..\lib_dec\ivas_lfe_plc.c" />
    <ClCompile Include="..\lib_dec\ivas_lfe_plc_fx.c" />
    <ClCompile Include="..\lib_dec\ivas_ls_custom_dec.c" />
    <ClCompile Include="..\lib_dec\ivas_masa_dec.c" />
    <ClCompile Include="..\lib_dec\ivas_mcmasa_dec.c" />
+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;
+3 −0
Original line number Diff line number Diff line
@@ -325,6 +325,9 @@ 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*/

/************************************************************************/
/*!
+12 −10
Original line number Diff line number Diff line
@@ -73,8 +73,10 @@ void ivas_tda_fx(

    FOR( i = 0; i < len_by_2; i++ )
    {
        pOut[i] = L_sub(pIn[len_by_2 + i], pIn[len_by_2 - i - 1]);
        pOut[len_by_2 + i] = L_add(pIn[length * 2 - i - 1], pIn[length + i]);
        pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] );
        move32();
        pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( i_mult( length, 2 ), i ), 1 )], pIn[add( length, i )] );
        move32();
    }

    return;
@@ -111,17 +113,17 @@ void ivas_dct_windowing_fx(

    FOR( i = 0; i < fade_len; i++ )
    {
        pOut_buf[zero_pad_len + i] = Mult_32_32(pOut_buf[zero_pad_len + i], pWindow_coeffs[i]);
        pOut_buf[add( zero_pad_len, i )] = Mult_32_32( pOut_buf[add( zero_pad_len, i )], pWindow_coeffs[i] );
    }

    rem_len = full_len - ( zero_pad_len * 3 + fade_len );
    rem_len = sub( full_len, ( add( i_mult( zero_pad_len, 3 ), fade_len ) ) );

    FOR( i = 0; i < rem_len; i++ )
    {
        pOut_buf[zero_pad_len * 3 + fade_len + i] = Mult_32_32(pOut_buf[zero_pad_len * 3 + fade_len + i], pWindow_coeffs[fade_len - i - 1]);
        pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )] = Mult_32_32( pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )], pWindow_coeffs[sub( sub( fade_len, i ), 1 )] );
    }

    set32_fx(&pOut_buf[full_len], 0, frame_len - full_len);
    set32_fx( &pOut_buf[full_len], 0, sub( frame_len, full_len ) );

    return;
}
Loading