diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 15defd670ab53ed7c7eb97be1ef29ecf8b8109f8..6b35161fd592c42e5370021fe103e7715332b67d 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1007,6 +1007,26 @@ void lls_interp_n( return; } +#ifdef FIX_ANGLE_WRAPPING +/* helper function for panning_wrap_angles */ +static float wrap_azi( + const float azi_deg ) +{ + float azi = azi_deg; + + /* Wrap azimuth value */ + while ( azi > 180 ) + { + azi -= 360.0f; + } + + while ( azi <= -180 ) + { + azi += 360; + } + + return azi; +} /*-------------------------------------------------------------------* * panning_wrap_angles() @@ -1016,7 +1036,74 @@ void lls_interp_n( * 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) */ + float *azi_wrapped, /* o : wrapped azimuth component */ + float *ele_wrapped /* o : wrapped elevation component */ +) +{ + float azi, ele; + azi = azi_deg; + ele = ele_deg; + + if ( fabsf( ele ) < 90 ) + { + *ele_wrapped = ele; + *azi_wrapped = wrap_azi( azi ); + return; + } + else + { + /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ + if ( ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) + { + *azi_wrapped = 0; + while ( ele > 90 ) + { + ele -= 360; + } + while ( ele < -90 ) + { + ele += 360; + } + *ele_wrapped = ele; + } + 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; + } + } + *azi_wrapped = wrap_azi( 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) */ @@ -1080,6 +1167,7 @@ void panning_wrap_angles( return; } +#endif /*-------------------------------------------------------------------------* * v_sort_ind() diff --git a/lib_com/options.h b/lib_com/options.h old mode 100755 new mode 100644 index 1deb15668697282105fe8a7c9d29f685913b2745..a5193624e92a95c6f117288e44cb91d93d97b0e2 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,7 +149,7 @@ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ #define MC_JBM /* FhG: extend JBM beyond mono for running IVAS in VoIP mode (contribution 19) */ #define FIX_265_MC_BRATE_SWITCHING /* Issue 265: fix use-of-uninitialized-value in MC bitrate switching */ - +#define FIX_ANGLE_WRAPPING /* Issue 244: Problems with angle wrapping*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */