Commit 14188caf authored by vaclav's avatar vaclav Committed by Manuel Jander
Browse files

remove float <-> fixed conversion leftovers

parent b431ec8d
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -161,7 +161,6 @@
    <ClCompile Include="..\lib_com\fill_spectrum_fx.c" />
    <ClCompile Include="..\lib_com\findpulse_fx.c" />
    <ClCompile Include="..\lib_com\fine_gain_bits_fx.c" />
    <ClCompile Include="..\lib_com\float_to_fix_ops.c" />
    <ClCompile Include="..\lib_com\frame_ener_fx.c" />
    <ClCompile Include="..\lib_com\gain_inov_fx.c" />
    <ClCompile Include="..\lib_com\get_gain_fx.c" />
+0 −3
Original line number Diff line number Diff line
@@ -256,9 +256,6 @@
    <ClCompile Include="..\lib_com\fine_gain_bits_fx.c">
      <Filter>common_all_c</Filter>
    </ClCompile>
    <ClCompile Include="..\lib_com\float_to_fix_ops.c">
      <Filter>common_all_c</Filter>
    </ClCompile>
    <ClCompile Include="..\lib_com\frame_ener_fx.c">
      <Filter>common_all_c</Filter>
    </ClCompile>
+3 −1
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@
    <ClCompile Include="..\lib_util\cmdln_parser.c" />
    <ClCompile Include="..\lib_util\cmdl_tools.c" />
    <ClCompile Include="..\lib_util\evs_rtp_payload.c" />
    <ClCompile Include="..\lib_util\float_to_fix_ops.c" />
    <ClCompile Include="..\lib_util\g192.c" />
    <ClCompile Include="..\lib_util\ivas_bpool.c" />
    <ClCompile Include="..\lib_util\ivas_queue.c" />
@@ -141,6 +142,7 @@
    <ClInclude Include="..\lib_util\cmdln_parser.h" />
    <ClInclude Include="..\lib_util\cmdl_tools.h" />
    <ClInclude Include="..\lib_util\evs_rtp_payload.h" />
    <ClInclude Include="..\lib_util\float_to_fix_ops.h" />
    <ClInclude Include="..\lib_util\g192.h" />
    <ClInclude Include="..\lib_util\ivas_bpool.h" />
    <ClInclude Include="..\lib_util\ivas_queue.h" />

lib_com/float_to_fix_ops.c

deleted100644 → 0
+0 −297
Original line number Diff line number Diff line
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include "options.h"
#include "prot_fx.h"
#define WMC_TOOL_SKIP

Word32 floatToFixed( float f, Word16 Q )
{
    Word64 result_32;
    if ( f == 1.0f && Q == Q15 )
        return MAX16B;
    if ( f == 1.0f && Q == Q31 )
        return MAXVAL_WORD32;
    if ( Q < 0 )
        result_32 = (Word64) ( (float) ( f ) / (double) ( (unsigned Word64) 1 << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) );
    else
        result_32 = (Word64) ( f * (double) ( (unsigned Word64) 1 << Q ) + ( f >= 0 ? 0.5 : -0.5 ) );
    if ( result_32 > MAX_32 )
        return MAX_32;
    if ( result_32 < MIN_32 )
        return MIN_32;
    return (Word32) result_32;
}


float fixedToFloat( Word32 i, Word16 Q )
{
    if ( Q < 0 )
        return ( i * (float) ( ( 1LL ) << ( -Q ) ) );
    else
        return (float) ( i ) / (float) ( 1LL << Q );
}
void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l )
{
    for ( int j = 0; j < l; j++ )
    {
        Word64 i64_val = floatToFixed( f[j], Q );
        IF( i64_val > MAX_32 )
        {
            i64_val = MAX_32;
        }
        ELSE IF( i64_val < MIN_32 )
        {
            i64_val = MIN_32;
        }
        i[j] = (Word32) i64_val;
    }
}
void floatToFixed_arr16( float *f, Word16 *i, Word16 Q, Word16 l )
{
    if ( Q <= 0 )
    {
        floatToFixed_arr( f, i, Q, l );
        return;
    }
    for ( int j = 0; j < l; j++ )
    {
        i[j] = float_to_fix16( f[j], Q );
    }
}
void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l )
{
    if ( Q <= 0 )
    {
        floatToFixed_arrL( f, i, Q, l );
        return;
    }
    for ( int j = 0; j < l; j++ )
    {
        i[j] = float_to_fix( f[j], Q );
    }
}

float fixedToFloat_16( Word16 i, Word16 Q )
{
    if ( Q < 0 )
        return ( i * (float) ( ( (unsigned) 1 ) << ( -Q ) ) );
    else
        return (float) ( i ) / (float) ( (unsigned int) 1 << Q );
}
float fixedToFloat_32( Word32 number, Word16 Q )
{
    float val = 0.0f;
    assert( abs_s( Q ) <= 63 );
    if ( abs_s( Q ) > 31 )
    {
        if ( Q > 0 )
        {
            val = ( ( (float) number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) );
        }
        else
        {
            val = ( (float) number * ( 1 << ( -Q - 31 ) ) * (unsigned int) MIN_32 );
        }
    }
    else
    {
        val = fixedToFloat( number, Q );
    }
    return val;
}

Word32 floatToFixed_32( float number, Word16 Q )
{
    float val = 0.0f;
    assert( abs_s( Q ) <= 63 );
    if ( abs_s( Q ) > 31 )
    {
        if ( Q > 0 )
        {
            val = ( number * ( (unsigned int) MAX_32 + 1 ) ) * ( 1 << ( Q - 31 ) );
        }
        else
        {
            val = ( number / ( 1 << ( -Q - 31 ) ) ) / (unsigned int) MIN_32;
        }
        if ( val >= 0.0f )
        {
            assert( (Word32) val <= MAX_32 );
        }
        else
        {
            assert( (Word32) val >= MIN_32 );
        }
    }
    else
    {
        return floatToFixed( number, Q );
    }

    return (Word32) val;
}

void floatToFixed_arrL32( float *f, Word32 *i, Word16 Q, Word16 l )
{
    for ( int j = 0; j < l; j++ )
    {
        i[j] = floatToFixed_32( f[j], Q );
    }
}

void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l )
{
    for ( int j = 0; j < l; j++ )
    {
        f[j] = fixedToFloat_32( i[j], Q );
    }
}

void floatToFixed_arr( float *f, Word16 *i, Word16 Q, Word16 l )
{
    for ( int j = 0; j < l; j++ )
    {
        Word32 i32_val = floatToFixed( f[j], Q );
        IF( i32_val > MAX_16 )
        {
            i32_val = MAX_16;
        }
        ELSE IF( i32_val < MIN_16 )
        {
            i32_val = MIN_16;
        }
        i[j] = (Word16) i32_val;
    }
}
void fixedToFloat_arrL( Word32 *i, float *f, Word16 Q, Word16 l )
{
    for ( int j = 0; j < l; j++ )
    {
        f[j] = fixedToFloat( i[j], Q );
    }
}
void fixedToFloat_arr( Word16 *i, float *f, Word16 Q, Word16 l )
{
    for ( int j = 0; j < l; j++ )
    {
        f[j] = fixedToFloat( i[j], Q );
    }
}
Word16 Q_factor( float x )
{
    Word16 Q = 15;
    if ( x >= 1 || x <= -1 )
        Q = norm_s( (Word16) L_abs( (Word32) x ) );
    return Q;
}
Word16 Q_factor_L( float x )
{
    Word16 Q = 31;
    if ( x >= 1 || x <= -1 )
        Q = norm_l( L_abs( (Word32) x ) );
    return Q;
}
Word16 Q_factor_L_32( Word32 x )
{
    Word16 Q = 31;
    if ( x >= 1 || x <= -1 )
        Q = norm_l( L_abs( (Word32) x ) );
    return Q;
}
Word16 Q_factor_arr( float *x, Word16 l )
{
    Word16 Q = 15;
    for ( int i = 0; i < l; i++ )
    {
        if ( x[i] >= 1 || x[i] <= -1 )
            Q = s_min( Q, norm_s( (Word16) L_abs( (Word32) x[i] ) ) );
    }
    return Q;
}
Word16 Q_factor_arrL( float *x, Word16 l )
{
    Word16 Q = 31;
    for ( int i = 0; i < l; i++ )
    {
        if ( x[i] >= 1 || x[i] <= -1 )
            Q = s_min( Q, norm_l( (Word32) L_abs( (Word32) x[i] ) ) );
    }
    return Q;
}

Word16 L_get_q( float f )
{
    if ( fabsf( f ) > (float) INT_MAX )
    {
        return sub( sub( W_norm( (Word64) f ), 32 ), 0 );
    }
    else
    {
        return sub( norm_l( (Word32) f ), 0 );
    }
}

Word16 L_get_q_buf( float *ptr_flt, Word16 length )
{
    Word16 k;
    float ftemp = 0.0;

    for ( k = 0; k < length; k++ )
    {
        if ( fabsf( ptr_flt[k] ) > ftemp )
            ftemp = fabsf( ptr_flt[k] );
    }

    if ( ftemp > (float) INT_MAX )
    {
        return sub( sub( W_norm( (Word64) ftemp ), 32 ), 0 );
    }
    else
    {
        return sub( norm_l( (Word32) ftemp ), 0 );
    }
}

Word16 L_get_q1( float f )
{
    if ( fabsf( f ) >= 0.f && fabsf( f ) < 1.f )
    {
        return Q31;
    }
    else if ( fabsf( f ) > (float) INT_MAX )
    {
        return sub( sub( W_norm( (Word64) f ), 32 ), 0 );
    }
    else
    {
        return sub( norm_l( (Word32) f ), 0 );
    }
}

Word16 L_get_q_buf1( float *ptr_flt, Word16 length )
{
    Word16 k;
    float ftemp = 0.0;

    for ( k = 0; k < length; k++ )
    {
        if ( fabsf( ptr_flt[k] ) > ftemp )
            ftemp = fabsf( ptr_flt[k] );
    }

    if ( ftemp >= 0.f && ftemp < 1.f )
    {
        return Q31;
    }
    else if ( ftemp > (float) INT_MAX )
    {
        return sub( sub( W_norm( (Word64) ftemp ), 32 ), 0 );
    }
    else
    {
        return sub( norm_l( (Word32) ftemp ), 0 );
    }
}
#undef WMC_TOOL_SKIP
+4 −96
Original line number Diff line number Diff line
@@ -102,80 +102,16 @@
    }
#endif
/*================================================================================*/
/* conversion functions: */
/*================================================================================*/
// Float to Word32
Word32 float_to_fix( float number, Word32 Q );
// Word32 to Float
float fix_to_float( Word32 number, Word32 Q );
// Float to Word16
Word16 float_to_fix16( float number, Word16 Q );
// Word16 to Float
float fix16_to_float( Word16 number, Word16 Q );
Word16 float_to_fix16_thrld( float number, Word16 Q );
void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l );
void floatToFixed_arr( float *f, Word16 *i, Word16 Q, Word16 l );
void fixedToFloat_arrL( Word32 *i, float *f, Word16 Q, Word16 l );
void fixedToFloat_arr( Word16 *i, float *f, Word16 Q, Word16 l );
void floatToFixed_arrL32( float *f, Word32 *i, Word16 Q, Word16 l );
void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l );
Word16 Q_factor( float x );
Word16 Q_factor_L( float x );
Word16 Q_factor_arr( float *x, Word16 l );
Word16 Q_factor_arrL( float *x, Word16 l );
Word16 Q_factor_L_32( Word32 x );
// Handles the cases where Q is negative
Word32 floatToFixed( float f, Word16 Q );
float fixedToFloat( Word32 i, Word16 Q );
Word32 floatToFixed_32( float f, Word16 Q );
float fixedToFloat_32( Word32 i, Word16 Q );
float fixedToFloat_16( Word16 i, Word16 Q );
void floatToFixed_arr16( float *f, Word16 *i, Word16 Q, Word16 l );
void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l );
// Float to 32-bit Mantissa and Exponent using frexp
void f2me( float n, Word32 *mantissa, Word16 *expo );
// 32-bit Mantissa and Exponent to Float using ldexp
float me2f( Word32 m, Word16 expo );
// Float to 32-bit Mantissa Array and Exponent
void f2me_buf( const float *x, Word32 *m, Word16 *e, const Word32 n );
// 32-bit Mantissa Array and Exponent to Float
void me2f_buf( const Word32 *m, const Word16 e, float *out, const Word32 n );
// Float to 16-bit Mantissa and Exponent using frexp
void f2me_16( float n, Word16 *mantissa, Word16 *expo );
// 16-bit Mantissa and Exponent to Float using ldexp
float me2f_16( Word16 m, Word16 expo );
// Float to 16-bit Mantissa Array and Exponent
void f2me_buf_16( const float *x, Word16 *m, Word16 *e, const Word32 n );
// 16-bit Mantissa Array and Exponent to Float
void me2f_buf_16( const Word16 *m, const Word16 e, float *out, const Word32 n );
void f2fix_16( float *var_flt, Word16 *var_fix, Word32 expo );
void fix2f_16( Word16 *var_fix, float *var_flt, Word32 expo );
void f2fix( float *var_flt, Word32 *var_fix, Word32 expo );
void fix2f( Word32 *var_fix, float *var_flt, Word32 expo );
// Get max Q factor for a float value before sat in 32-bit
Word16 L_get_q( float f );
Word16 L_get_q1( float f );
// Get max Q factor for a float buffer before sat in 32-bit
Word16 L_get_q_buf( float *ptr_flt, Word16 length );
Word16 L_get_q_buf1( float *ptr_flt, Word16 length );
/*================================================================================*/
/* conversion functions: */
/*================================================================================*/
/*----------------------------------------------------------------------------------*
 * Prototypes of tools
 *----------------------------------------------------------------------------------*/
Word32 sum_l_fx(
    const Word32 *vec, /* i  : input vector                          */
    const Word16 lvec  /* i  : length of input vector                */
);
Word32 Mult_32_16(
    Word32 a,
    Word16 b );
@@ -215,13 +151,11 @@ void set32_fx(
    const Word16 N  /* i  : Lenght of the vector                */
);
// tools.c
/* o  : output random value */
Word16 Random(
    Word16 *seed /* i/o: random seed         */
);
// tools.c
void Copy(
    const Word16 x[], /* i  : i   vector  */
    Word16 y[],       /* o  : output vector */
@@ -10980,9 +10914,6 @@ Word16 own_random(
    Word16 *seed /* i/o: random seed                                     */
);
Word16 norm_ul_float(
    UWord32 UL_var1 );
/*! r: sum of all vector elements */
Word16 sum_s(
    const Word16 *vec, /* i  : input vector                                    */
@@ -11022,17 +10953,6 @@ void set16_zero_fx(
    const Word16 lvec /* i  : length of the vector                            */
);
void set_zero(
    float *vec,       /* o  : input vector                                    */
    const Word16 lvec /* i  : length of the vector                            */
);
void mvr2r(
    const float x[], /* i  : input vector                                    */
    float y[],       /* o  : output vector                                   */
    const Word16 n   /* i  : vector size                                     */
);
void mvs2s(
    const Word16 x[], /* i  : input vector                                    */
    Word16 y[],       /* o  : output vector                                   */
@@ -11058,18 +10978,6 @@ Word16 minimum_s(
    Word16 *min_val    /* o  : minimum value in the input vector               */
);
/*! r: dequanzited gain */
float usdequant(
    const Word16 idx, /* i  : quantizer index                                 */
    const float qlow, /* i  : lowest codebook entry (index 0)                 */
    const float delta /* i  : quantization step                               */
);
void sort(
    UWord16 *x, /* i/o: Vector to be sorted                             */
    UWord16 len /* i/o: vector length                                   */
);
void sort_l(
    Word32 *x, /* i/o: Vector to be sorted                             */
    Word16 len /* i/o: vector length                                   */
Loading