From c267c4dc56c3026e95df66d70877fa5bb662b366 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Mon, 12 Dec 2022 10:30:24 +0100 Subject: [PATCH 1/8] fixed panning_wrap_angles --- lib_com/ivas_tools.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index b8fbaa833f..9e59b92174 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1030,7 +1030,7 @@ void panning_wrap_angles( ele = ele_deg; /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ - if ( ( ele != 0 ) && ( fmodf( ele, 90 ) == 0 ) ) + if ( ( ele != 0 ) && ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) { azi = 0; while ( fabsf( ele ) > 90 ) @@ -1049,11 +1049,11 @@ void panning_wrap_angles( /* Compensate elevation accordingly */ if ( ele > 90 ) { - ele -= 180; + ele = 180 - ele; } else if ( ele < -90 ) { - ele += 180; + ele = -180 - ele; } } -- GitLab From 30b6f9a7d436fc89cce36553634bcad7fe96f895 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Tue, 13 Dec 2022 15:57:16 +0100 Subject: [PATCH 2/8] added early return in wrap angles --- lib_com/ivas_tools.c | 90 ++++++++++++++++++++++++++++++++++++++++++++ lib_com/options.h | 1 + 2 files changed, 91 insertions(+) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 9e59b92174..17e76d61e3 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1016,7 +1016,96 @@ void lls_interp_n( * elevation = [-90, 90] * Considers direction changes from large elevation values *-------------------------------------------------------------------*/ +#ifdef FIX_ANGLE_WRAPPING +void panning_wrap_angles( + const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ + const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ + float *azi_wrapped, /* o : wrapped azimuth component */ + float *ele_wrapped /* o : wrapped elevation component */ +) +{ + float azi, ele; + + azi = azi_deg; + ele = ele_deg; + + if ( ele <= 90 && ele >= -90 ) + { + *ele_wrapped = ele; + if ( azi > 180.0f || azi <= -180.0f ) + { + /* Wrap azimuth value */ + if ( fabsf( azi ) > 180 ) + { + azi = fmodf( azi + 180, 360 ); + azi -= 180; + } + /* Set -180 to 180 for deduplication purposes; angles are otherwise identical */ + if ( azi == -180 ) + { + azi = 180; + } + } + *azi_wrapped = azi; + return; + + } + else + { + /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ + if ( ( ele != 0 ) && ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) + { + azi = 0; + while ( ele > 90 ) + { + ele -= 360; + } + while ( ele < 90 ) + { + ele += 360; + } + } + else + { + /* Wrap elevation and adjust azimuth accordingly */ + while ( fabsf( ele ) > 90 ) + { + /* Flip to other hemisphere */ + azi += 180; + + /* Compensate elevation accordingly */ + if ( ele > 90 ) + { + ele = 180 - ele; + } + else if ( ele < -90 ) + { + ele = -180 - ele; + } + } + + /* Wrap azimuth value */ + if ( fabsf( azi ) > 180 ) + { + azi = fmodf( azi + 180, 360 ); + azi -= 180; + } + } + + /* Set -180 to 180 for deduplication purposes; angles are otherwise identical */ + if ( azi == -180 ) + { + azi = 180; + } + } + + *azi_wrapped = azi; + *ele_wrapped = ele; + + return; +} +#else void panning_wrap_angles( const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ @@ -1080,6 +1169,7 @@ void panning_wrap_angles( return; } +#endif /*-------------------------------------------------------------------------* * v_sort_ind() diff --git a/lib_com/options.h b/lib_com/options.h index 2011fb56b4..e69d668699 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,7 @@ #define IMPROVE_CMDLINE_ROBUSTNESS /* Issue 233: Improve robustness of command-line parameters */ #define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ +#define FIX_ANGLE_WRAPPING /* Issue 244: Problems with angle wrapping*/ /* ################## End DEVELOPMENT switches ######################### */ -- GitLab From d88c5709fe4dd83723c71649e07e99ba273bbf64 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Thu, 15 Dec 2022 12:54:51 +0100 Subject: [PATCH 3/8] restructured panning_wrap_angles --- lib_com/ivas_tools.c | 142 +++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 66 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 17e76d61e3..bc596402eb 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1007,6 +1007,32 @@ void lls_interp_n( return; } +#ifdef FIX_ANGLE_WRAPPING +/* helper function for panning_wrap_angles */ +float static wrap_azi( + const float azi_deg ) +{ + float azi = azi_deg; + + /* Wrap azimuth value */ + if ( fabsf( azi ) > 180 ) + { + azi = fmodf( azi + 180, 360 ); + if ( azi < 0 ) + { + azi += 360; + } + + azi -= 180; + } + + /* Set -180 to 180 for deduplication purposes; angles are otherwise identical */ + if ( azi == -180 ) + { + azi = 180; + } + return azi; +} /*-------------------------------------------------------------------* * panning_wrap_angles() @@ -1016,7 +1042,6 @@ void lls_interp_n( * elevation = [-90, 90] * Considers direction changes from large elevation values *-------------------------------------------------------------------*/ -#ifdef FIX_ANGLE_WRAPPING void panning_wrap_angles( const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ @@ -1029,83 +1054,68 @@ void panning_wrap_angles( azi = azi_deg; ele = ele_deg; - if ( ele <= 90 && ele >= -90 ) + if ( fabs( ele ) <= 90 ) { *ele_wrapped = ele; - if ( azi > 180.0f || azi <= -180.0f ) + if ( azi > 180 || azi <= -180 ) { - /* Wrap azimuth value */ - if ( fabsf( azi ) > 180 ) - { - azi = fmodf( azi + 180, 360 ); - azi -= 180; - } - - /* Set -180 to 180 for deduplication purposes; angles are otherwise identical */ - if ( azi == -180 ) - { - azi = 180; - } + azi = wrap_azi( azi ); } *azi_wrapped = azi; return; - - } + } else { - /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ - if ( ( ele != 0 ) && ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) - { - azi = 0; - while ( ele > 90 ) - { - ele -= 360; - } - while ( ele < 90 ) + /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ + if ( ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) + { + float y = fmodf( ele, 180 ); + azi = 0; + while ( ele > 90 ) + { + ele -= 360; + } + while ( ele < -90 ) { ele += 360; } - } - else - { - /* Wrap elevation and adjust azimuth accordingly */ - while ( fabsf( ele ) > 90 ) - { - /* Flip to other hemisphere */ - azi += 180; - - /* Compensate elevation accordingly */ - if ( ele > 90 ) - { - ele = 180 - ele; - } - else if ( ele < -90 ) - { - ele = -180 - ele; - } - } - - /* Wrap azimuth value */ - if ( fabsf( azi ) > 180 ) - { - azi = fmodf( azi + 180, 360 ); - azi -= 180; - } - } - - /* Set -180 to 180 for deduplication purposes; angles are otherwise identical */ - if ( azi == -180 ) - { - azi = 180; - } - } + } + else + { + /* Wrap elevation and adjust azimuth accordingly */ + while ( fabsf( ele ) > 90 ) + { + /* Flip to other hemisphere */ + azi += 180; - *azi_wrapped = azi; - *ele_wrapped = ele; + /* Compensate elevation accordingly */ + if ( ele > 90 ) + { + ele = 180 - ele; + } + else if ( ele < -90 ) + { + ele = -180 - ele; + } + } + azi = wrap_azi( azi ); + } - return; + *azi_wrapped = azi; + *ele_wrapped = ele; + + return; + } } #else +/*-------------------------------------------------------------------* + * panning_wrap_angles() + * + * Wrap angles for amplitude panning to the range: + * azimuth = (-180, 180] + * elevation = [-90, 90] + * Considers direction changes from large elevation values + *-------------------------------------------------------------------*/ void panning_wrap_angles( const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ @@ -1119,7 +1129,7 @@ void panning_wrap_angles( ele = ele_deg; /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ - if ( ( ele != 0 ) && ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) + if ( ( ele != 0 ) && ( fmodf( ele, 90 ) == 0 ) ) { azi = 0; while ( fabsf( ele ) > 90 ) @@ -1138,11 +1148,11 @@ void panning_wrap_angles( /* Compensate elevation accordingly */ if ( ele > 90 ) { - ele = 180 - ele; + ele -= 180; } else if ( ele < -90 ) { - ele = -180 - ele; + ele += 180; } } -- GitLab From 0f831556ea8492ada0f1d9642a71e9a30a46f627 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Thu, 15 Dec 2022 13:00:09 +0100 Subject: [PATCH 4/8] removed test variable --- lib_com/ivas_tools.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index bc596402eb..c6a62e2328 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1069,7 +1069,6 @@ void panning_wrap_angles( /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ if ( ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) { - float y = fmodf( ele, 180 ); azi = 0; while ( ele > 90 ) { -- GitLab From ffc787d019d25dcc01c86978126b62eeb96460ae Mon Sep 17 00:00:00 2001 From: Treffehn Date: Thu, 15 Dec 2022 13:02:56 +0100 Subject: [PATCH 5/8] small change --- lib_com/ivas_tools.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index c6a62e2328..503d726faf 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1009,7 +1009,7 @@ void lls_interp_n( #ifdef FIX_ANGLE_WRAPPING /* helper function for panning_wrap_angles */ -float static wrap_azi( +static float wrap_azi( const float azi_deg ) { float azi = azi_deg; -- GitLab From ded0c6fe55a697f05ba075367079663e890b6529 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Fri, 16 Dec 2022 11:02:52 +0100 Subject: [PATCH 6/8] small changes --- lib_com/ivas_tools.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 503d726faf..66a4a2a4e9 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1054,22 +1054,17 @@ void panning_wrap_angles( azi = azi_deg; ele = ele_deg; - if ( fabs( ele ) <= 90 ) + if ( fabsf( ele ) < 90 ) { *ele_wrapped = ele; - if ( azi > 180 || azi <= -180 ) - { - azi = wrap_azi( azi ); - } - *azi_wrapped = azi; - return; + *azi_wrapped = wrap_azi( azi ); } else { /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ if ( ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) { - azi = 0; + *azi_wrapped = 0; while ( ele > 90 ) { ele -= 360; @@ -1078,6 +1073,7 @@ void panning_wrap_angles( { ele += 360; } + *ele_wrapped = ele; } else { @@ -1097,12 +1093,10 @@ void panning_wrap_angles( ele = -180 - ele; } } - azi = wrap_azi( azi ); + *azi_wrapped = wrap_azi( azi ); + *ele_wrapped = ele; } - *azi_wrapped = azi; - *ele_wrapped = ele; - return; } } -- GitLab From 1ff2ef1bcbfddd603900c076c114aa8b55ea8580 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Fri, 16 Dec 2022 13:46:53 +0100 Subject: [PATCH 7/8] changed helper function wrap_azi --- lib_com/ivas_tools.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 66a4a2a4e9..6af6dc9bb8 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1015,22 +1015,16 @@ static float wrap_azi( float azi = azi_deg; /* Wrap azimuth value */ - if ( fabsf( azi ) > 180 ) + while ( azi > 180 ) { - azi = fmodf( azi + 180, 360 ); - if ( azi < 0 ) - { - azi += 360; - } - - azi -= 180; + azi -= 360.0f; } - /* Set -180 to 180 for deduplication purposes; angles are otherwise identical */ - if ( azi == -180 ) + while ( azi <= -180 ) { - azi = 180; + azi += 360; } + return azi; } -- GitLab From 2b749287c2f8e35e7bfba75c1e9db95ae77df1eb Mon Sep 17 00:00:00 2001 From: Treffehn Date: Fri, 23 Dec 2022 12:39:14 +0100 Subject: [PATCH 8/8] added return --- lib_com/ivas_tools.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 6af6dc9bb8..50ccc9ad35 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1052,6 +1052,7 @@ void panning_wrap_angles( { *ele_wrapped = ele; *azi_wrapped = wrap_azi( azi ); + return; } else { -- GitLab