Commit 5e62bea2 authored by Jan Kiene's avatar Jan Kiene
Browse files

replace sinf and cosf with BASOP implementation in DFT stereo encoder

this achieves bit-exactness with Apple Clang between -O0 and -O2
parent b5bd5e06
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -616,6 +616,12 @@ Word16 shl( Word16 var1, Word16 var2 )

    return ( var_out );
}

Word16 shl_sat( Word16 var1, Word16 var2 )
{
    Flag Overflow;
    return shl_o( var1, var2, &Overflow );
}
#endif /* BASOP_NOGLOB */

/*___________________________________________________________________________
+27 −26
Original line number Diff line number Diff line
@@ -252,6 +252,7 @@ Word32 L_msu0( Word32 L_v3, Word16 v1, Word16 v2 ); /* 32-bit Msu w/o shift 1 *
Word16 add_o( Word16 var1, Word16 var2, Flag *Overflow );
Word16 sub_o( Word16 var1, Word16 var2, Flag *Overflow );
Word16 shl_o( Word16 var1, Word16 var2, Flag *Overflow );
Word16 shl_sat( Word16 var1, Word16 var2 );
Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow );
Word32 L_mult_o( Word16 var1, Word16 var2, Flag *Overflow );
Word16 round_fx_o( Word32 L_var1, Flag *Overflow );
+47 −0
Original line number Diff line number Diff line
@@ -636,6 +636,53 @@ static Word16 fixp_sin_cos_residual_16(
    return residual;
}

Word16 getCosWord16( Word16 theta )
{
    Word16 result, residual, sine, cosine;

    residual = fixp_sin_cos_residual_16( theta, 2, &sine, &cosine, 0 );
    /* This negation prevents the subsequent addition from overflow */
    /* The negation cannot overflow, sine is in range [0x0..0x7FFF] */
    sine = negate( sine );
    result = mac_r( L_mult0( sine, residual ), cosine, 16384 );


    return result;
}

#define EVS_PI_BY_2_FX ( Word16 )( 0x3244 ) // Q13
#define EVS_PI_FX      25736                /* pi in Q13 */
#define ONE_IN_Q14     16384

Word16 getSinWord16( Word16 theta )
{
    Word16 sine;
    Word32 theta_new = L_sub( EVS_PI_BY_2_FX, theta );
    Word16 l_theta;
    IF( GT_32( theta_new, EVS_PI_FX ) )
    {
        l_theta = extract_l( L_sub( L_sub( theta_new, EVS_PI_FX ), EVS_PI_FX ) );
    }
    ELSE IF( LT_32( theta_new, -EVS_PI_FX ) )
    {
        l_theta = extract_l( L_add( L_add( theta_new, EVS_PI_FX ), EVS_PI_FX ) );
    }
    ELSE
    {
        l_theta = extract_l( theta_new );
    }
    sine = getCosWord16( l_theta );
    IF( EQ_16( sine, ONE_IN_Q14 ) )
    {
        sine = MAX_16;
    }
    ELSE
    {
        sine = shl( sine, 1 );
    }
    return sine;
}


Word16 getCosWord16R2(
    Word16 theta )
+3 −0
Original line number Diff line number Diff line
@@ -273,6 +273,9 @@ Word16 mult0( Word16 x, /* i : Multiplier */
 */
Word16 getCosWord16R2( Word16 theta );

Word16 getSinWord16( Word16 theta );
Word16 getCosWord16( Word16 theta );

/****************************************************************************/
/*!
  \brief    16/16->16 unsigned integer division
+1 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@

#define NONBE_1412_AVOID_ROUNDING_AZ_ELEV              /* FhG:  Avoid rounding when passing azimuth and elevation to efap_determine_gains() */
#define NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG       /* FhG: Fix MDCT-Stereo comfort noise for certain noise types */
#define NONBE_TRIG_FUNC_2_BASOP_IN_DFT_STEREO          /* FhG: Fix for non-BE between different optimization levels in dft stereo code by using BASOPs for trigonometric functions */

/* ##################### End NON-BE switches ########################### */

Loading