diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index a3ccaefc72cb6501d16564a2a64fe016f7680d1c..8da4f72e2cfc58d9c50ba6ae6bae112ea5f46bde 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 ff1c8374194fb9f48be425ae8132d7a48276db4c..6d4ad09eb5380703323eb64b54fb32fc34e26ca0 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; }