From 7126e32e6d3d0f4ac1a228b67df845cdf6102398 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 16 Jan 2024 18:30:41 +0530 Subject: [PATCH] Fix for MLD difference observed with few files [x] Includes fixes in the function in_tri_fixed() for improving precision. --- lib_com/basop_util.c | 15 ++++----------- lib_rend/ivas_efap.c | 11 ++++++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index a3ccaefc7..8da4f72e2 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1256,22 +1256,15 @@ Word16 getCosWord16R2( Word16 getSineWord16R2( Word16 theta ) { - IF ( theta == 0 ) + IF ( EQ_16( theta, (Word16) 0 ) ) { return 0; } - Word16 cosine = getCosWord16R2( theta ); - Word16 result = 32767 - ( mult_r( cosine, cosine ) ); - Word16 exp = 0; - Word16 sine = Sqrt16( result, &exp ); - sine = shl( sine, exp ); - - IF ( ( ( theta >= 16384 ) && ( theta <= 32767 ) ) || ( ( theta < 0 ) && ( theta >= -16384 ) ) ) + ELSE IF ( LT_16( theta, (Word16) -24576 ) ) { - sine = negate( sine ); + theta = add( add( theta, (Word16) 32767 ), (Word16) 1 ); } - - return sine; + return getCosWord16R2( sub( 8192, theta ) ); } /* diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index ff1c83741..6d4ad09eb 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -2783,8 +2783,8 @@ static Word16 in_tri_fixed( Word32 tmpDot1[2], tmpDot2[2]; Word32 matInv[2][2]; Word32 invFactor; - Word32 S[2]; - Word32 thresh_int = 34; // 1e-6f in Q25 + Word64 S[2]; + Word64 thresh_int = 4295; // 1e-6f in Q32 /* Not a Valid Triangle : Colinear edges @@ -2797,14 +2797,14 @@ static Word16 in_tri_fixed( v_sub_fixed( C, A, tmpDot2, 2, 0 ); /* Verification of the non-colinearity : Q22 * Q22 = Q13 */ - invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); + invFactor = L_shr( L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ), Q5 ); IF( invFactor == 0 ) { return 0; } - invFactor = ( 0x7FFFFFFF / invFactor ) << Q13; + invFactor = L_shl( ( 0x7FFFFFFF / invFactor ), Q8 ); // Q22 = Q22 * Q31 matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); @@ -2817,7 +2817,8 @@ static Word16 in_tri_fixed( S[1] = L_add( Mpy_32_32( matInv[1][0], P_minus_A[0] ), Mpy_32_32( matInv[1][1], P_minus_A[1] ) ); /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ - IF( ( S[0] << Q12 ) < -thresh_int || ( S[1] << Q12 ) < -thresh_int || ( ( S[0] + S[1] ) << Q12 ) > ( ( 1 << Q25 ) + thresh_int ) ) + IF( ( S[0] << Q19 ) < -thresh_int || ( S[1] << Q19 ) < -thresh_int || + ( ( S[0] + S[1] ) << Q19 ) > ( ( ( (Word64) 1 ) << 32 ) + thresh_int ) ) { return 0; } -- GitLab