Commit 4155d899 authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Removed headroom to improve determinate precision; replaced L_add/L_sub with...

Removed headroom to improve determinate precision; replaced L_add/L_sub with L_add_sat/L_sub_sat to avoid overflow assertions.
parent a01aa619
Loading
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ Word16 slot_fx[4] = { 32767, 16384, 10922, 8192 };
#define MAX_GAIN_CACHE_SIZE ( ( MASA_MAXIMUM_DIRECTIONS * 3 ) + MAX_NUM_OBJECTS ) /* == different calls to get gains */

#ifdef FIX_1819_EIGENVALUE_ERROR
#define EPSILON_EIGENVALUE 50
#define SMALL_EIGENVALUE 50
#endif

typedef struct hrtfGainCache
@@ -4404,15 +4404,16 @@ static void formulate2x2MixingMatrix_fx(
    eig2x2_fx( tmpRe_fx[0][0], tmpRe_fx[1][1], q_temp, tmpRe_fx[1][0], tmpIm_fx[1][0], q_temp, Ure_fx, Uim_fx, &q_U, D_fx, &q_D );

#ifdef FIX_1819_EIGENVALUE_ERROR
    IF( D_fx[0] != 0 && D_fx[1] == 0 )
    IF( D_fx[0] != 0 && D_fx[1] == 0 )  // Due to an eig2x2 error, sometimes D_fx[1] becomes zero, which implies that the input matrix should be singular (i.e., determinant = 0).
    {
        Word32 det_fx = L_sub( L_shr( Mult_32_32( tmpRe_fx[0][0], tmpRe_fx[1][1] ), 1 ),
                               L_add(
                                   L_shr( Mult_32_32( tmpRe_fx[1][0], tmpRe_fx[1][0] ), 1 ),
                                   L_shr( Mult_32_32( tmpIm_fx[1][0], tmpIm_fx[1][0] ), 1 ) ) );
        IF( det_fx != 0 )
        Word32 det_fx = L_sub_sat( Mult_32_32( tmpRe_fx[0][0], tmpRe_fx[1][1] ),
                                   L_add_sat(
                                       Mult_32_32( tmpRe_fx[1][0], tmpRe_fx[1][0] ),
                                       Mult_32_32( tmpIm_fx[1][0], tmpIm_fx[1][0] ) ) );
        if( det_fx != 0 )
        {
            D_fx[1] = EPSILON_EIGENVALUE;
            D_fx[1] = SMALL_EIGENVALUE; // Setting D_fx[1] to epsilon has no effect, as the value is too small to affect the output.
            move32();
        }
    }
#endif