From a7674b95759bc801dd18d6c814cf819dd2e92918 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 6 Feb 2024 11:39:49 +0530 Subject: [PATCH] Few functions in ivas_orient_trk converted to fixed point [x] Functions converted: IdentityQuaternion, ivas_orient_trk_SetTrackingType, ivas_orient_trk_GetTrackedRotation, ivas_orient_trk_GetMainOrientation --- lib_dec/ivas_init_dec.c | 11 +++++- lib_rend/ivas_orient_trk.c | 75 ++++++++++++++++++++++++++++++++++++++ lib_rend/ivas_prot_rend.h | 17 +++++++++ lib_rend/ivas_rotation.c | 15 ++++++++ lib_rend/ivas_stat_rend.h | 16 +++++--- lib_rend/lib_rend.c | 70 +++++++++++++++++++++++++++++++++++ 6 files changed, 198 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 690ff014d..140f966f9 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -758,12 +758,21 @@ ivas_error ivas_init_decoder_front( { return error; } +#ifdef IVAS_FLOAT_FIXED + error = ivas_orient_trk_SetTrackingType_fx( st_ivas->hHeadTrackData->OrientationTracker_fx, st_ivas->hDecoderConfig->orientation_tracking ); + st_ivas->hHeadTrackData->OrientationTracker->orientation_tracking = st_ivas->hHeadTrackData->OrientationTracker_fx->orientation_tracking_fx; + IF( ( error ) != IVAS_ERR_OK ) + { + return error; + } + } +#else IF ( ( error = ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, st_ivas->hDecoderConfig->orientation_tracking ) ) != IVAS_ERR_OK ) { return error; } } - +#endif /*-------------------------------------------------------------------* * Allocate and initialize external orientation handle *--------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 57bede878..f761fa83c 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -72,6 +72,19 @@ static IVAS_QUATERNION IdentityQuaternion( return q; } +#ifdef IVAS_FLOAT_FIXED +static IVAS_QUATERNION_FX IdentityQuaternion_fx( + void ) +{ + IVAS_QUATERNION_FX q; + + q.w_fx = ONE_IN_Q31; + q.x_fx = q.y_fx = q.z_fx = 0; + q.w_qfact = q.x_qfact = q.y_qfact = q.z_qfact = Q31; + + return q; +} +#endif /*------------------------------------------------------------------------------------------* * QuaternionProduct() @@ -796,6 +809,23 @@ ivas_error ivas_orient_trk_SetTrackingType( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_orient_trk_SetTrackingType_fx( + ivas_orient_trk_state_t_fx *pOTR, /* i/o: orientation tracker handle */ + const IVAS_HEAD_ORIENT_TRK_T orientation_tracking /* i : orientation tracking type */ +) +{ + if ( pOTR == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + pOTR->orientation_tracking_fx = orientation_tracking; + + return IVAS_ERR_OK; +} +#endif + /*-------------------------------------------------------------------* * ivas_orient_trk_SetReferenceRotation() * @@ -860,6 +890,35 @@ ivas_error ivas_orient_trk_GetMainOrientation( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_orient_trk_GetMainOrientation_fx( + ivas_orient_trk_state_t_fx *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION_FX *pOrientation /* i/o: average/reference orientation */ +) +{ + if ( pOTR == NULL || pOrientation == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + switch ( pOTR->orientation_tracking_fx ) + { + case IVAS_HEAD_ORIENT_TRK_NONE: + *pOrientation = IdentityQuaternion_fx(); + break; + case IVAS_HEAD_ORIENT_TRK_REF_VEC: + case IVAS_HEAD_ORIENT_TRK_REF_VEC_LEV: + case IVAS_HEAD_ORIENT_TRK_REF: + *pOrientation = pOTR->refRot_fx; + break; + case IVAS_HEAD_ORIENT_TRK_AVG: + *pOrientation = pOTR->absAvgRot_fx; + break; + } + + return IVAS_ERR_OK; +} +#endif /*-------------------------------------------------------------------* * ivas_orient_trk_GetTrackedRotation() @@ -882,6 +941,22 @@ ivas_error ivas_orient_trk_GetTrackedRotation( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_orient_trk_GetTrackedRotation_fx( + ivas_orient_trk_state_t_fx *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION_FX *pRotation /* i/o: processed rotation */ +) +{ + if (pOTR == NULL || pRotation == NULL) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *pRotation = pOTR->trkRot_fx; + + return IVAS_ERR_OK; +} +#endif /*-------------------------------------------------------------------* * ivas_orient_trk_SetReferenceVector() diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 0fc612616..458d0c03b 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1787,6 +1787,23 @@ ivas_error ivas_orient_trk_Process( IVAS_QUATERNION *pTrkRot /* o : tracked rotation */ ); +#ifdef IVAS_FLOAT_FIXED + +ivas_error ivas_orient_trk_SetTrackingType_fx( + ivas_orient_trk_state_t_fx *pOTR, /* i/o: orientation tracker handle */ + const IVAS_HEAD_ORIENT_TRK_T orientation_tracking /* i : orientation tracking type */ +); + +ivas_error ivas_orient_trk_GetMainOrientation_fx( + ivas_orient_trk_state_t_fx *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION_FX *pOrientation /* i/o: average/reference orientation */ +); + +ivas_error ivas_orient_trk_GetTrackedRotation_fx( + ivas_orient_trk_state_t_fx *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION_FX *pRotation /* i/o: processed rotation */ +); +#endif /*----------------------------------------------------------------------------------* * Rendering & merging to MASA format diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index ccd4b7431..611701a0b 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -131,6 +131,13 @@ ivas_error ivas_headTrack_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); } +#ifdef IVAS_FLOAT_FIXED + if (((*hHeadTrackData)->OrientationTracker_fx = (ivas_orient_trk_state_t_fx *)malloc(sizeof(ivas_orient_trk_state_t_fx))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking"); + } +#endif + if ( ( error = ivas_orient_trk_Init( ( *hHeadTrackData )->OrientationTracker ) ) != IVAS_ERR_OK ) { return error; @@ -174,6 +181,14 @@ void ivas_headTrack_close( ( *hHeadTrackData )->OrientationTracker = NULL; } +#ifdef IVAS_FLOAT_FIXED + if ((*hHeadTrackData)->OrientationTracker_fx != NULL) + { + free((*hHeadTrackData)->OrientationTracker_fx); + (*hHeadTrackData)->OrientationTracker_fx = NULL; + } +#endif + free( ( *hHeadTrackData ) ); *hHeadTrackData = NULL; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 817a35fa2..ba4b5d5aa 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -803,11 +803,11 @@ typedef struct ivas_orient_trk_state_t typedef struct ivas_orient_trk_state_t_fx { IVAS_HEAD_ORIENT_TRK_T orientation_tracking_fx; - Word16 centerAdaptationRate_fx; - Word16 offCenterAdaptationRate_fx; - Word16 adaptationAngle_fx; + Word32 centerAdaptationRate_fx; + Word32 offCenterAdaptationRate_fx; + Word32 adaptationAngle_fx; - Word16 alpha_fx; + Word32 alpha_fx; IVAS_QUATERNION_FX absAvgRot_fx; /* average absolute orientation */ IVAS_QUATERNION_FX refRot_fx; /* reference orientation */ IVAS_QUATERNION_FX trkRot_fx; /* tracked rotation */ @@ -827,6 +827,7 @@ typedef struct IVAS_VECTOR3 Pos[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED Word32 crossfade_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; + ivas_orient_trk_state_t_fx *hOrientationTracker_fx; #endif float crossfade[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; ivas_orient_trk_state_t *hOrientationTracker; @@ -859,7 +860,9 @@ typedef struct ivas_binaural_head_track_struct int16_t shd_rot_max_order; ivas_orient_trk_state_t *OrientationTracker; - +#ifdef IVAS_FLOAT_FIXED + ivas_orient_trk_state_t_fx *OrientationTracker_fx; +#endif } HEAD_TRACK_DATA, *HEAD_TRACK_DATA_HANDLE; @@ -874,6 +877,9 @@ typedef struct ivas_external_orientation_struct int8_t enableRotationInterpolation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* 0 - disable, 1 - enable */ int16_t numFramesToTargetOrientation[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Number of frames until target orientation is reached */ IVAS_QUATERNION Quaternions[MAX_PARAM_SPATIAL_SUBFRAMES]; /* External orientation in quaternions */ +#ifdef IVAS_FLOAT_FIXED + IVAS_QUATERNION_FX Quaternions_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* External orientation in quaternions */ +#endif int16_t num_subframes; } EXTERNAL_ORIENTATION_DATA, *EXTERNAL_ORIENTATION_HANDLE; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 078cffa7c..178d733d2 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1385,6 +1385,13 @@ static ivas_error initHeadRotation( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); } +#ifdef IVAS_FLOAT_FIXED + IF((hIvasRend->headRotData.hOrientationTracker_fx = (ivas_orient_trk_state_t_fx *)malloc(sizeof(ivas_orient_trk_state_t_fx))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking"); + } +#endif + IF( ( error = ivas_orient_trk_Init( hIvasRend->headRotData.hOrientationTracker ) ) != IVAS_ERR_OK ) { return error; @@ -1439,6 +1446,13 @@ static void closeHeadRotation( free( hIvasRend->headRotData.hOrientationTracker ); } +#ifdef IVAS_FLOAT_FIXED + if ( ( hIvasRend != NULL ) && ( hIvasRend->headRotData.hOrientationTracker_fx != NULL ) ) + { + free( hIvasRend->headRotData.hOrientationTracker_fx ); + } +#endif + return; } @@ -4696,7 +4710,14 @@ ivas_error IVAS_REND_SetOrientationTrackingMode( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking /* i : Head orientation tracking type */ ) { +#ifdef IVAS_FLOAT_FIXED + ivas_error ret; + ret = ivas_orient_trk_SetTrackingType_fx( hIvasRend->headRotData.hOrientationTracker_fx, orientation_tracking ); + hIvasRend->headRotData.hOrientationTracker->orientation_tracking = hIvasRend->headRotData.hOrientationTracker_fx->orientation_tracking_fx; + return ret; +#else return ivas_orient_trk_SetTrackingType( hIvasRend->headRotData.hOrientationTracker, orientation_tracking ); +#endif } @@ -4746,10 +4767,39 @@ ivas_error IVAS_REND_GetMainOrientation( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef IVAS_FLOAT_FIXED + IVAS_QUATERNION_FX *pOrientation_fx = malloc( sizeof( IVAS_QUATERNION_FX ) ); + Word16 q_fact = hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.w_qfact = hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.x_qfact = + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.z_qfact = Q29; + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.w_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.w, q_fact); + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.x_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.x, q_fact); + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.y_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.y, q_fact); + hIvasRend->headRotData.hOrientationTracker_fx->refRot_fx.z_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->refRot.z, q_fact); + + + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.w_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.x_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.y_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.z_fx = (Word32)float_to_fix( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z, Q29 ); + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.w_qfact = hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.x_qfact = + hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->absAvgRot_fx.z_qfact = Q29; + + error = ivas_orient_trk_GetMainOrientation_fx( hIvasRend->headRotData.hOrientationTracker_fx, pOrientation_fx ); + pOrientation->w = fix_to_float( pOrientation_fx->w_fx, pOrientation_fx->w_qfact ); + pOrientation->x = fix_to_float( pOrientation_fx->x_fx, pOrientation_fx->x_qfact ); + pOrientation->y = fix_to_float( pOrientation_fx->y_fx, pOrientation_fx->y_qfact ); + pOrientation->z = fix_to_float( pOrientation_fx->z_fx, pOrientation_fx->z_qfact ); + free(pOrientation_fx); + IF(error != IVAS_ERR_OK) + { + return error; + } +#else if ( ( error = ivas_orient_trk_GetMainOrientation( hIvasRend->headRotData.hOrientationTracker, pOrientation ) ) != IVAS_ERR_OK ) { return error; } +#endif return IVAS_ERR_OK; } @@ -4773,10 +4823,30 @@ ivas_error IVAS_REND_GetTrackedRotation( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef IVAS_FLOAT_FIXED + IVAS_QUATERNION_FX *pRotation_fx = malloc(sizeof(IVAS_QUATERNION_FX)); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.w_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.w, Q29); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.x_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.x, Q29); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.y_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.y, Q29); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.z_fx = (Word32)float_to_fix(hIvasRend->headRotData.hOrientationTracker->trkRot.z, Q29); + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.w_qfact = hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.x_qfact = + hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.y_qfact = hIvasRend->headRotData.hOrientationTracker_fx->trkRot_fx.z_qfact = Q29; + error = ivas_orient_trk_GetTrackedRotation_fx(hIvasRend->headRotData.hOrientationTracker_fx, pRotation_fx); + pRotation->w = fix_to_float(pRotation_fx->w_fx, pRotation_fx->w_qfact); + pRotation->x = fix_to_float(pRotation_fx->x_fx, pRotation_fx->x_qfact); + pRotation->y = fix_to_float(pRotation_fx->y_fx, pRotation_fx->y_qfact); + pRotation->z = fix_to_float(pRotation_fx->z_fx, pRotation_fx->z_qfact); + free(pRotation_fx); + IF(error != IVAS_ERR_OK) + { + return error; + } +#else if ( ( error = ivas_orient_trk_GetTrackedRotation( hIvasRend->headRotData.hOrientationTracker, pRotation ) ) != IVAS_ERR_OK ) { return error; } +#endif return IVAS_ERR_OK; } -- GitLab