From 1278eea70e281d61f99f4b4820a579b2fb6e1ba6 Mon Sep 17 00:00:00 2001 From: szczerba Date: Wed, 1 Mar 2023 12:09:27 +0100 Subject: [PATCH 01/12] Orientation tracking refactoring --- lib_dec/ivas_binRenderer_internal.c | 12 ----- lib_dec/ivas_dirac_dec.c | 11 ----- lib_dec/ivas_ism_renderer.c | 12 ----- lib_dec/ivas_objectRenderer_internal.c | 4 -- lib_dec/lib_dec.c | 4 ++ lib_rend/ivas_dirac_dec_binaural_functions.c | 8 ---- lib_rend/ivas_objectRenderer.c | 22 --------- lib_rend/ivas_orient_trk.c | 20 ++++----- lib_rend/ivas_prot_rend.h | 6 +-- lib_rend/ivas_rotation.c | 33 -------------- lib_rend/lib_rend.c | 47 +++----------------- 11 files changed, 20 insertions(+), 159 deletions(-) diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index d61b488e1b..9c7e07734e 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -989,9 +989,6 @@ void ivas_binRenderer( { int16_t chIdx, k; int16_t numTimeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif push_wmops( "fastconv_binaural_rendering" ); @@ -1014,16 +1011,7 @@ void ivas_binRenderer( /* Rotation in SHD (HOA3) */ if ( hHeadTrackData->shd_rot_max_order == -1 ) { -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, - &hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], - FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, hHeadTrackData->Rmat ); -#else QuatToRotMat( hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], hHeadTrackData->Rmat ); -#endif - rotateFrame_shd_cldfb( RealBuffer, ImagBuffer, hHeadTrackData->Rmat, hBinRenderer->hInputSetup->nchan_out_woLFE, 3 ); } else if ( hHeadTrackData->shd_rot_max_order > 0 ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 3aa3edb0d1..f46815a4b6 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1810,9 +1810,6 @@ void ivas_dirac_dec( float *reference_power, *reference_power_smooth; float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; uint16_t coherence_flag; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif push_wmops( "ivas_dirac_dec" ); @@ -1879,15 +1876,7 @@ void ivas_dirac_dec( if ( st_ivas->hHeadTrackData ) { -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( st_ivas->hHeadTrackData->OrientationTracker, - &st_ivas->hHeadTrackData->Quaternions[st_ivas->hHeadTrackData->num_quaternions++], - (float) ( FRAMES_PER_SEC * ( sf2 - sf1 ) ), - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, st_ivas->hHeadTrackData->Rmat ); -#else QuatToRotMat( st_ivas->hHeadTrackData->Quaternions[st_ivas->hHeadTrackData->num_quaternions++], st_ivas->hHeadTrackData->Rmat ); -#endif p_Rmat = &st_ivas->hHeadTrackData->Rmat[0][0]; diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 3e2c027eca..a965a0ffed 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -110,9 +110,6 @@ void ivas_ism_render( int16_t num_objects, nchan_out_woLFE, lfe_index; int16_t azimuth, elevation; float Rmat[3][3]; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif num_objects = st_ivas->nchan_transport; nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; @@ -136,17 +133,8 @@ void ivas_ism_render( if ( st_ivas->hHeadTrackData != NULL && st_ivas->hHeadTrackData->num_quaternions >= 0 ) { -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( st_ivas->hHeadTrackData->OrientationTracker, - &st_ivas->hHeadTrackData->Quaternions[st_ivas->hHeadTrackData->num_quaternions++], - FRAMES_PER_SEC, - &trackedHeadOrientation ); - /* Calculate rotation matrix from the quaternion */ - QuatToRotMat( trackedHeadOrientation, Rmat ); -#else /* Calculate rotation matrix from the quaternion */ QuatToRotMat( st_ivas->hHeadTrackData->Quaternions[st_ivas->hHeadTrackData->num_quaternions++], Rmat ); -#endif } for ( i = 0; i < num_objects; i++ ) diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 7f11f8e3b5..b9fade9290 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -93,9 +93,5 @@ void ivas_td_binaural_renderer( ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, output, output_frame -#ifdef FIX_I109_ORIENTATION_TRACKING - , - pOtr -#endif ); } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index b9db571d2b..cd19fe9d52 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -911,10 +911,14 @@ ivas_error IVAS_DEC_FeedHeadTrackData( /* Move head-tracking data to the decoder handle */ for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { +#ifdef FIX_I109_ORIENTATION_TRACKING + ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation[i], FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hHeadTrackData->Quaternions ); +#else hHeadTrackData->Quaternions[i].w = orientation[i].w; hHeadTrackData->Quaternions[i].x = orientation[i].x; hHeadTrackData->Quaternions[i].y = orientation[i].y; hHeadTrackData->Quaternions[i].z = orientation[i].z; +#endif } hIvasDec->st_ivas->hHeadTrackData->num_quaternions = 0; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index bc8e3351f0..020dd27cfa 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -426,9 +426,6 @@ static void ivas_dirac_dec_binaural_internal( uint8_t firstSlot, slotEnd; int16_t max_band_decorr; DIFFUSE_DISTRIBUTION_DATA diffuseDistData; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif firstSlot = firstSubframe * ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ); slotEnd = ( firstSubframe + nSubframes ) * ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ); @@ -561,12 +558,7 @@ static void ivas_dirac_dec_binaural_internal( if ( st_ivas->hHeadTrackData && st_ivas->hHeadTrackData->num_quaternions >= 0 ) { -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( st_ivas->hHeadTrackData->OrientationTracker, &st_ivas->hHeadTrackData->Quaternions[firstSubframe], FRAMES_PER_SEC, &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, Rmat ); -#else QuatToRotMat( st_ivas->hHeadTrackData->Quaternions[firstSubframe], Rmat ); -#endif if ( nchan_transport == 2 ) { diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 7fcae1c0cc..b0f5295ded 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -240,18 +240,11 @@ void ivas_td_binaural_renderer_unwrap( const IVAS_QUATERNION *Quaternions, /* i : Head tracking data per subframe */ float output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ const int16_t output_frame /* i : output frame length */ -#ifdef FIX_I109_ORIENTATION_TRACKING - , - ivas_orient_trk_state_t *pOTR /* i/o: orientation tracker handle */ -#endif ) { int16_t subframe_length; int16_t subframe_idx; float reverb_signal[BINAURAL_CHANNELS][L_FRAME48k]; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif subframe_length = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; if ( hRenderConfig != NULL ) @@ -278,18 +271,7 @@ void ivas_td_binaural_renderer_unwrap( for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) { /* Update the listener's location/orientation */ -#ifdef FIX_I109_ORIENTATION_TRACKING - if ( pOTR != NULL ) - { - if ( ivas_orient_trk_Process( pOTR, ( Quaternions != NULL ) ? &Quaternions[subframe_idx] : NULL, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &trackedHeadOrientation ) != IVAS_ERR_OK ) - { - exit( -1 ); - } - } - TDREND_Update_listener_orientation( hBinRendererTd, Opt_Headrotation, ( pOTR != NULL ) ? &trackedHeadOrientation : NULL ); -#else TDREND_Update_listener_orientation( hBinRendererTd, Opt_Headrotation, ( Quaternions != NULL ) ? &Quaternions[subframe_idx] : NULL ); -#endif if ( ( hRenderConfig != NULL ) && ( hRenderConfig->roomAcoustics.late_reverb_on ) ) { @@ -661,10 +643,6 @@ ivas_error ivas_td_binaural_renderer_ext( ( headRotData != NULL ) ? headRotData->headPositions : NULL, output, output_frame -#ifdef FIX_I109_ORIENTATION_TRACKING - , - headRotData->hOrientationTracker -#endif ); pop_wmops(); diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 70a14b1797..9a8aba83f7 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -444,10 +444,10 @@ ivas_error ivas_orient_trk_SetAbsoluteOrientation( #ifdef FIX_I109_ORIENTATION_TRACKING ivas_error ivas_orient_trk_Process( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - const IVAS_QUATERNION *pAbsRot, /* i : absolute head rotation */ - float updateRate, /* i : rotation update rate [Hz] */ - IVAS_QUATERNION *pTrkRot ) /* o : tracked rotation */ + ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ + IVAS_QUATERNION absRot, /* i : absolute head rotation */ + float updateRate, /* i : rotation update rate [Hz] */ + IVAS_QUATERNION *pTrkRot ) /* o : tracked rotation */ { float normalizedOrientation; float relativeOrientationRate; @@ -467,34 +467,34 @@ ivas_error ivas_orient_trk_Process( switch ( pOTR->trackingType ) { case OTR_TRACKING_NONE: - *pTrkRot = *pAbsRot; + *pTrkRot = absRot; break; case OTR_TRACKING_REF_ORIENT: /* Reset average orientation */ - pOTR->absAvgRot = *pAbsRot; + pOTR->absAvgRot = absRot; /* Reset adaptation filter - start adaptation at center rate */ pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse( pOTR->refRot, pTrkRot ); - QuaternionProduct( *pTrkRot, *pAbsRot, pTrkRot ); + QuaternionProduct( *pTrkRot, absRot, pTrkRot ); break; case OTR_TRACKING_AVG_ORIENT: /* Compute average (low-pass filtered) absolute orientation */ - QuaternionSlerp( pOTR->absAvgRot, *pAbsRot, alpha, &pOTR->absAvgRot ); + QuaternionSlerp( pOTR->absAvgRot, absRot, alpha, &pOTR->absAvgRot ); /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ QuaternionInverse( pOTR->absAvgRot, pTrkRot ); - QuaternionProduct( *pTrkRot, *pAbsRot, pTrkRot ); + QuaternionProduct( *pTrkRot, absRot, pTrkRot ); /* Adapt LPF constant based on orientation excursion relative to current mean: - low cutoff (slow adaptation) for small excursions (around center) - high cutoff (fast adaptation) for large excursions (off-center) */ - ang = QuaternionAngle( *pAbsRot, *pTrkRot ); + ang = QuaternionAngle( absRot, *pTrkRot ); normalizedOrientation = ang * ang; relativeOrientationRate = sqrtf( normalizedOrientation ) / pOTR->adaptationAngle; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 4712ccbf67..88da5dd674 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -234,10 +234,6 @@ void ivas_td_binaural_renderer_unwrap( const IVAS_QUATERNION *Quaternions, /* i : Head tracking data per subframe */ float output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ const int16_t output_frame /* i : output frame length */ -#ifdef FIX_I109_ORIENTATION_TRACKING - , - ivas_orient_trk_state_t *pOTR /* i/o: orientation tracker handle */ -#endif ); ivas_error ivas_td_binaural_renderer_ext( @@ -913,7 +909,7 @@ ivas_error ivas_orient_trk_GetTrackedRotation( #ifdef FIX_I109_ORIENTATION_TRACKING ivas_error ivas_orient_trk_Process( ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - const IVAS_QUATERNION *pAbsRot, /* i : absolute head rotation */ + IVAS_QUATERNION absRot, /* i : absolute head rotation */ float updateRate, /* i : rotation update rate [Hz] */ IVAS_QUATERNION *pTrkRot /* o : tracked rotation */ ); diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 90354497a0..71133994d5 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -283,9 +283,6 @@ void rotateFrame_shd( float SHrotmat_prev[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; float SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; float cross_fade[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif shd_rot_max_order = hTransSetup.ambisonics_order; @@ -303,15 +300,7 @@ void rotateFrame_shd( } /* get next quaternion */ -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, - &hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], - FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, hHeadTrackData->Rmat ); -#else QuatToRotMat( hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], hHeadTrackData->Rmat ); -#endif /* calculate ambisonics rotation matrices for the previous and current frames */ SHrotmatgen( SHrotmat_prev, hHeadTrackData->Rmat_prev, shd_rot_max_order ); @@ -400,9 +389,6 @@ void rotateFrame_sd( float gains_prev[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS]; float output_tmp[MAX_CICP_CHANNELS][L_FRAME48k]; float cross_fade[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif push_wmops( "rotateFrame_sd" ); @@ -416,15 +402,7 @@ void rotateFrame_sd( } /* Get next quaternion and calculate rotation matrix */ -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, - &hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], - FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, hHeadTrackData->Rmat ); -#else QuatToRotMat( hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], hHeadTrackData->Rmat ); -#endif for ( ch_in = 0; ch_in < nchan; ch_in++ ) { @@ -639,9 +617,6 @@ void rotateFrame_sd_cldfb( float *p_real, *p_imag; int16_t nInChannels; int16_t isPlanar; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif push_wmops( "rotateFrame_sd_cldfb" ); @@ -657,15 +632,7 @@ void rotateFrame_sd_cldfb( } /* Get next quaternion and calculate rotation matrix */ -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, - &hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], - FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, Rmat ); -#else QuatToRotMat( hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], Rmat ); -#endif /* rotation of Euler angles */ for ( n = 0; n < nInChannels; n++ ) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 7c784c545a..0145f1163c 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3924,7 +3924,11 @@ ivas_error IVAS_REND_SetHeadRotation( hIvasRend->headRotData.headRotEnabled = 1; for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; ++i ) { +#ifdef FIX_I109_ORIENTATION_TRACKING + ivas_orient_trk_Process( hIvasRend->headRotData.hOrientationTracker, headRot[i], FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hIvasRend->headRotData.headPositions[i] ); +#else hIvasRend->headRotData.headPositions[i] = headRot[i]; +#endif } } @@ -4123,9 +4127,6 @@ static ivas_error rotateFrameMc( rotation_matrix Rmat; rotation_gains gains; float tmp_gains[MAX_INPUT_CHANNELS]; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif push_wmops( "rotateFrameMc" ); @@ -4152,15 +4153,7 @@ static ivas_error rotateFrameMc( for ( subframe_idx = 0; subframe_idx < RENDERER_HEAD_POSITIONS_PER_FRAME; subframe_idx++ ) { /* Get next quaternion and calculate rotation matrix */ -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( headRotData->hOrientationTracker, - &headRotData->headPositions[subframe_idx], - (float) ( FRAMES_PER_SEC * RENDERER_HEAD_POSITIONS_PER_FRAME ), - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, Rmat ); -#else QuatToRotMat( headRotData->headPositions[subframe_idx], Rmat ); -#endif for ( ch_in = 0; ch_in < nchan; ch_in++ ) { @@ -4242,9 +4235,6 @@ static ivas_error rotateFrameSba( rotation_matrix Rmat; float tmpRot[2 * HEADROT_ORDER + 1]; rotation_gains gains; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif push_wmops( "rotateFrameSba" ); @@ -4261,15 +4251,7 @@ static ivas_error rotateFrameSba( } /* Get next quaternion and calculate rotation matrix */ -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( headRotData->hOrientationTracker, - &headRotData->headPositions[subframe_idx], - (float) ( FRAMES_PER_SEC * RENDERER_HEAD_POSITIONS_PER_FRAME ), - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, Rmat ); -#else QuatToRotMat( headRotData->headPositions[subframe_idx], Rmat ); -#endif /* calculate ambisonics rotation matrices for the previous and current frames */ SHrotmatgen( gains, Rmat, shd_rot_max_order ); @@ -4375,18 +4357,12 @@ static ivas_error renderIsmToBinauralRoom( int16_t tmp; rotation_matrix Rmat; float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; -#ifndef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION quat; -#endif ivas_error error; pan_vector currentPanGains; pan_vector previousPanGains; IVAS_REND_AudioBuffer tmpMcBuffer; IVAS_REND_AudioObjectPosition rotatedPos; const IVAS_REND_HeadRotData *headRotData; -#ifdef FIX_I109_ORIENTATION_TRACKING - IVAS_QUATERNION trackedHeadOrientation; -#endif push_wmops( "renderIsmToBinauralRoom" ); @@ -4399,20 +4375,7 @@ static ivas_error renderIsmToBinauralRoom( // for ( subframe_idx = 0; subframe_idx < RENDERER_HEAD_POSITIONS_PER_FRAME; subframe_idx++ ) for ( subframe_idx = 0; subframe_idx < 1; subframe_idx++ ) { -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( headRotData->hOrientationTracker, - &headRotData->headPositions[subframe_idx], - (float) ( FRAMES_PER_SEC ), - &trackedHeadOrientation ); - QuatToRotMat( trackedHeadOrientation, Rmat ); -#else - quat.w = headRotData->headPositions[subframe_idx].w; - quat.x = headRotData->headPositions[subframe_idx].x; - quat.y = headRotData->headPositions[subframe_idx].y; - quat.z = headRotData->headPositions[subframe_idx].z; - - QuatToRotMat( quat, Rmat ); -#endif + QuatToRotMat( headRotData->headPositions[subframe_idx], Rmat ); } (void) subframe_len; // avoid warning } -- GitLab From 125196112c8e10968d720358f8d0028ce363fea7 Mon Sep 17 00:00:00 2001 From: szczerba Date: Wed, 1 Mar 2023 12:38:31 +0100 Subject: [PATCH 02/12] Orientation tracking refactoring --- lib_dec/lib_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index cd19fe9d52..29f1ff2a8c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -912,7 +912,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData( for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { #ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation[i], FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hHeadTrackData->Quaternions ); + ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation[i], FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hHeadTrackData->Quaternions[i] ); #else hHeadTrackData->Quaternions[i].w = orientation[i].w; hHeadTrackData->Quaternions[i].x = orientation[i].x; -- GitLab From f73558f1fbd7780fd2792fee4db3c65e6a19fa6a Mon Sep 17 00:00:00 2001 From: hsd Date: Mon, 6 Mar 2023 14:18:02 +0100 Subject: [PATCH 03/12] [fix] call SetReferenceRotation before SetHeadRotation. Ohterwise the reference rotation gets applied one frame too late --- apps/decoder.c | 54 ++++++++++++++++++++++++++++++++----------------- apps/renderer.c | 36 ++++++++++++++++----------------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 40ac02238e..dcd5cf62e8 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1509,6 +1509,42 @@ static ivas_error decodeG192( goto cleanup; } +#ifdef FIX_I109_ORIENTATION_TRACKING + /* Reference rotation */ + if ( arg.enableReferenceRotation ) + { + IVAS_QUATERNION quaternion; + if ( ( error = HeadRotationFileReading( refRotReader, &quaternion ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( refRotReader ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif +#ifdef FIX_I109_ORIENTATION_TRACKING + /* Reference rotation */ + if ( arg.enableReferenceRotation ) + { + IVAS_QUATERNION quaternion; + if ( ( error = HeadRotationFileReading( refRotReader, &quaternion ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( refRotReader ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) { @@ -1538,24 +1574,6 @@ static ivas_error decodeG192( } } -#ifdef FIX_I109_ORIENTATION_TRACKING - /* Reference rotation */ - if ( arg.enableReferenceRotation ) - { - IVAS_QUATERNION quaternion; - if ( ( error = HeadRotationFileReading( refRotReader, &quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( refRotReader ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } -#endif /* Run decoder for one frame (get rendered output) */ if ( ( error = IVAS_DEC_GetSamples( hIvasDec, pcmBuf, &nOutSamples ) ) != IVAS_ERR_OK ) { diff --git a/apps/renderer.c b/apps/renderer.c index fa3a3d21ee..fef1e65eba 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -942,6 +942,24 @@ int main( ObjectPositionBuffer mtdBuffer; IsmPositionProvider_getNextFrame( positionProvider, &mtdBuffer ); +#ifdef FIX_I109_ORIENTATION_TRACKING + /* Read from reference rotation trajectory file if specified */ + if ( referenceRotReader != NULL ) + { + IVAS_QUATERNION quaternion; + if ( HeadRotationFileReading( referenceRotReader, &quaternion ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error in Head Rotation File Reading.\r\n" ); + exit( -1 ); + } + if ( IVAS_REND_SetReferenceRotation( hIvasRend, quaternion ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error setting Reference Rotation.\r\n" ); + exit( -1 ); + } + } +#endif + /* Read from head rotation trajectory file if specified */ if ( headRotReader != NULL ) { @@ -973,24 +991,6 @@ int main( } } -#ifdef FIX_I109_ORIENTATION_TRACKING - /* Read from reference rotation trajectory file if specified */ - if ( referenceRotReader != NULL ) - { - IVAS_QUATERNION quaternion; - if ( HeadRotationFileReading( referenceRotReader, &quaternion ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error in Head Rotation File Reading.\r\n" ); - exit( -1 ); - } - if ( IVAS_REND_SetReferenceRotation( hIvasRend, quaternion ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error setting Reference Rotation.\r\n" ); - exit( -1 ); - } - } -#endif - for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) { if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numChannels ) ) != IVAS_ERR_OK ) -- GitLab From 826f05f83310afa425c8d70f548c65f8985c3bcb Mon Sep 17 00:00:00 2001 From: hsd Date: Tue, 7 Mar 2023 10:00:07 +0100 Subject: [PATCH 04/12] [fix] removed duplicated HeadRotationFileReading block, thx2szczerba --- apps/decoder.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index dcd5cf62e8..0612c9b2a5 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1509,24 +1509,6 @@ static ivas_error decodeG192( goto cleanup; } -#ifdef FIX_I109_ORIENTATION_TRACKING - /* Reference rotation */ - if ( arg.enableReferenceRotation ) - { - IVAS_QUATERNION quaternion; - if ( ( error = HeadRotationFileReading( refRotReader, &quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( refRotReader ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } -#endif #ifdef FIX_I109_ORIENTATION_TRACKING /* Reference rotation */ if ( arg.enableReferenceRotation ) -- GitLab From 9be23381048a10fbc2ba0a68c1a86b343fc6a7f8 Mon Sep 17 00:00:00 2001 From: szczerba Date: Tue, 7 Mar 2023 10:49:22 +0100 Subject: [PATCH 05/12] Cleanup --- apps/decoder.c | 32 +++++++++++++------------- lib_dec/ivas_objectRenderer_internal.c | 8 +------ lib_rend/ivas_objectRenderer.c | 3 +-- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 0612c9b2a5..671d702b84 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1510,22 +1510,22 @@ static ivas_error decodeG192( } #ifdef FIX_I109_ORIENTATION_TRACKING - /* Reference rotation */ - if ( arg.enableReferenceRotation ) - { - IVAS_QUATERNION quaternion; - if ( ( error = HeadRotationFileReading( refRotReader, &quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( refRotReader ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } + /* Reference rotation */ + if ( arg.enableReferenceRotation ) + { + IVAS_QUATERNION quaternion; + if ( ( error = HeadRotationFileReading( refRotReader, &quaternion ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( refRotReader ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } #endif /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index b9fade9290..921c56e6e6 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -71,11 +71,6 @@ void ivas_td_binaural_renderer( const int16_t output_frame /* i : output frame length */ ) { -#ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_state_t *pOtr = NULL; - if ( st_ivas->hHeadTrackData != NULL ) - pOtr = st_ivas->hHeadTrackData->OrientationTracker; -#endif ivas_td_binaural_renderer_unwrap( st_ivas->hRenderConfig, st_ivas->ini_frame, #ifdef FIX_197_CREND_INTERFACE st_ivas->hCrendWrapper, @@ -92,6 +87,5 @@ void ivas_td_binaural_renderer( st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, output, - output_frame - ); + output_frame ); } diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index b0f5295ded..4276568519 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -642,8 +642,7 @@ ivas_error ivas_td_binaural_renderer_ext( headRotData->headRotEnabled, ( headRotData != NULL ) ? headRotData->headPositions : NULL, output, - output_frame - ); + output_frame ); pop_wmops(); -- GitLab From 39ef324fb0208f46526a0eef345d02104631a18f Mon Sep 17 00:00:00 2001 From: hsd Date: Wed, 8 Mar 2023 17:50:50 +0100 Subject: [PATCH 06/12] [fix] set reference vector/rot before set headrotation gets called, otherwise there's one frame of delay in the processing which lets the bit exactness tests fails --- apps/renderer.c | 50 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 7206d14585..9437204ee6 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -980,6 +980,22 @@ int main( IsmPositionProvider_getNextFrame( positionProvider, &mtdBuffer ); #ifdef FIX_I109_ORIENTATION_TRACKING +#ifdef OTR_REFERENCE_VECTOR_TRACKING + if ( referenceVectorReader != NULL ) + { + IVAS_VECTOR3 listenerPos, refPos; + if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPos, &refPos ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); + exit( -1 ); + } + if ( ( error = IVAS_REND_SetReferenceVector( hIvasRend, listenerPos, refPos ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); + exit( -1 ); + } + } +#endif /* OTR_REFERENCE_VECTOR_TRACKING */ /* Read from reference rotation trajectory file if specified */ if ( referenceRotReader != NULL ) { @@ -1028,40 +1044,6 @@ int main( } } -#ifdef FIX_I109_ORIENTATION_TRACKING -#ifdef OTR_REFERENCE_VECTOR_TRACKING - if ( referenceVectorReader != NULL ) - { - IVAS_VECTOR3 listenerPos, refPos; - if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPos, &refPos ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); - exit( -1 ); - } - if ( ( error = IVAS_REND_SetReferenceVector( hIvasRend, listenerPos, refPos ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) ); - exit( -1 ); - } - } -#endif /* OTR_REFERENCE_VECTOR_TRACKING */ - /* Read from reference rotation trajectory file if specified */ - if ( referenceRotReader != NULL ) - { - IVAS_QUATERNION quaternion; - if ( HeadRotationFileReading( referenceRotReader, &quaternion ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error in Head Rotation File Reading.\r\n" ); - exit( -1 ); - } - if ( IVAS_REND_SetReferenceRotation( hIvasRend, quaternion ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error setting Reference Rotation.\r\n" ); - exit( -1 ); - } - } -#endif - for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) { if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numChannels ) ) != IVAS_ERR_OK ) -- GitLab From f30e323c2015252305920e66cbe094e94c5c7648 Mon Sep 17 00:00:00 2001 From: hsd Date: Wed, 8 Mar 2023 19:18:37 +0100 Subject: [PATCH 07/12] [fix] set reference vector/rot before set headrotation gets called, otherwise there's one frame of delay in the processing --- apps/decoder.c | 56 ++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index ce81d3a904..6788953ee8 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1585,6 +1585,24 @@ static ivas_error decodeG192( } #ifdef FIX_I109_ORIENTATION_TRACKING +#ifdef OTR_REFERENCE_VECTOR_TRACKING + /* reference vector */ + if ( arg.enableReferenceVectorTracking ) + { + IVAS_VECTOR3 listenerPosition, referencePosition; + if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif /* OTR_REFERENCE_VECTOR_TRACKING */ /* Reference rotation */ if ( arg.enableReferenceRotation ) { @@ -1630,44 +1648,6 @@ static ivas_error decodeG192( goto cleanup; } } - -#ifdef FIX_I109_ORIENTATION_TRACKING - /* Reference rotation */ - if ( arg.enableReferenceRotation ) - { - IVAS_QUATERNION quaternion; - if ( ( error = HeadRotationFileReading( refRotReader, &quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( refRotReader ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } -#ifdef OTR_REFERENCE_VECTOR_TRACKING - /* reference vector */ - if ( arg.enableReferenceVectorTracking ) - { - IVAS_VECTOR3 listenerPosition, referencePosition; - if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); - goto cleanup; - } - - if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } -#endif /* OTR_REFERENCE_VECTOR_TRACKING */ -#endif - /* Run decoder for one frame (get rendered output) */ if ( ( error = IVAS_DEC_GetSamples( hIvasDec, pcmBuf, &nOutSamples ) ) != IVAS_ERR_OK ) { -- GitLab From afe79562e230fdc4a899df14e2fb7bbff5c67ee0 Mon Sep 17 00:00:00 2001 From: szczerba Date: Wed, 8 Mar 2023 21:59:33 +0100 Subject: [PATCH 08/12] Conversion back to Euler angles removed from orientation tracker, no Euler input anymore for QuatToRotMat function --- lib_rend/ivas_orient_trk.c | 38 +++++++------------------- lib_rend/ivas_prot_rend.h | 18 ++++++------- lib_rend/ivas_rotation.c | 55 +++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 67 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 994fbe822a..bc685c704a 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -367,7 +367,7 @@ void VectorRotationToQuaternion( r->x = cross_product.x; r->y = cross_product.y; r->z = cross_product.z; - r->w = 1.0 + dot_product; + r->w = 1.0f + dot_product; } QuaternionNormalize( *r, r ); } @@ -665,8 +665,7 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; - IVAS_QUATERNION absQuat, trkQuat; - IVAS_QUATERNION trkEuler; + IVAS_QUATERNION absQuat; if ( pOTR == NULL || pTrkRot == NULL ) { @@ -688,7 +687,7 @@ ivas_error ivas_orient_trk_Process( switch ( pOTR->trackingType ) { case OTR_TRACKING_NONE: - trkQuat = absQuat; + pOTR->trkRot = absQuat; break; case OTR_TRACKING_REF_ORIENT: @@ -699,8 +698,8 @@ ivas_error ivas_orient_trk_Process( pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ - QuaternionInverse( pOTR->refRot, &trkQuat ); - QuaternionProduct( trkQuat, absQuat, &trkQuat ); + QuaternionInverse( pOTR->refRot, &pOTR->trkRot ); + QuaternionProduct( pOTR->trkRot, absQuat, &pOTR->trkRot ); break; case OTR_TRACKING_AVG_ORIENT: @@ -708,14 +707,14 @@ ivas_error ivas_orient_trk_Process( QuaternionSlerp( pOTR->absAvgRot, absQuat, alpha, &pOTR->absAvgRot ); /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ - QuaternionInverse( pOTR->absAvgRot, &trkQuat ); - QuaternionProduct( trkQuat, absQuat, &trkQuat ); + QuaternionInverse( pOTR->absAvgRot, &pOTR->trkRot ); + QuaternionProduct( pOTR->trkRot, absQuat, &pOTR->trkRot ); /* Adapt LPF constant based on orientation excursion relative to current mean: - low cutoff (slow adaptation) for small excursions (around center) - high cutoff (fast adaptation) for large excursions (off-center) */ - ang = QuaternionAngle( absQuat, trkQuat ); + ang = QuaternionAngle( absQuat, pOTR->trkRot ); normalizedOrientation = ang * ang; relativeOrientationRate = sqrtf( normalizedOrientation ) / pOTR->adaptationAngle; @@ -744,7 +743,7 @@ ivas_error ivas_orient_trk_Process( case OTR_TRACKING_REF_VEC_LEV: { /* This processing step of the OTR_TRACKING_REF_VEC/OTR_TRACKING_REF_VEC_LEVEL is identical */ - QuaternionProduct( pOTR->refRot, absQuat, &trkQuat ); + QuaternionProduct( pOTR->refRot, absQuat, &pOTR->trkRot ); break; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ @@ -753,25 +752,6 @@ ivas_error ivas_orient_trk_Process( break; } - if ( result == IVAS_ERR_OK ) - { - pOTR->trkRot = trkQuat; - - if ( absRot.w == -3.0f ) - { - Quat2Euler( trkQuat, &trkEuler.z, &trkEuler.y, &trkEuler.x ); - trkEuler.x = rad2deg( trkEuler.x ); - trkEuler.y = rad2deg( trkEuler.y ); - trkEuler.z = rad2deg( trkEuler.z ); - trkEuler.w = -3.0f; - *pTrkRot = trkEuler; - } - else - { - *pTrkRot = trkQuat; - } - } - return result; } #else diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index dcf78e7984..25dfa078cc 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -799,16 +799,7 @@ ivas_error ivas_headTrack_open( void ivas_headTrack_close( HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ ); -#endif -void Quat2Euler( - const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ - float *yaw, /* o : yaw (z) */ - float *pitch, /* o : pitch (y) */ - float *roll /* o : roll (x) */ -); - -#ifdef FIX_I109_ORIENTATION_TRACKING void Euler2Quat( const float roll, /* i : roll (x) */ const float pitch, /* i : pitch (y) */ @@ -818,9 +809,16 @@ void Euler2Quat( float deg2rad( float degrees ); -float rad2deg( float radians ); +#else +void Quat2Euler( + const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ + float *yaw, /* o : yaw (z) */ + float *pitch, /* o : pitch (y) */ + float *roll /* o : roll (x) */ +); #endif + void QuatToRotMat( const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ float Rmat[3][3] /* o : real-space rotation matrix for this rotation */ diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 3e30b7952e..e946654a07 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -120,6 +120,29 @@ void QuatToRotMat( ) { float s1, s2, s3, c1, c2, c3; + +#ifdef FIX_I109_ORIENTATION_TRACKING + c1 = cosf( quat.z / _180_OVER_PI ); + c2 = cosf( quat.y / _180_OVER_PI ); + c3 = cosf( quat.x / _180_OVER_PI ); + + s1 = sinf( quat.z / _180_OVER_PI ); + s2 = sinf( -quat.y / _180_OVER_PI ); + s3 = sinf( quat.x / _180_OVER_PI ); + + Rmat[0][0] = c2 * c3; + Rmat[0][1] = -c2 * s3; + Rmat[0][2] = s2; + + Rmat[1][0] = c1 * s3 + c3 * s1 * s2; + Rmat[1][1] = c1 * c3 - s1 * s2 * s3; + Rmat[1][2] = -c2 * s1; + + Rmat[2][0] = s1 * s3 - c1 * c3 * s2; + Rmat[2][1] = c3 * s1 + c1 * s2 * s3; + Rmat[2][2] = c1 * c2; +#else + #ifdef DEBUGGING /* PrintQuat( quat ); */ #endif @@ -177,10 +200,12 @@ void QuatToRotMat( Rmat[2][1] = c3 * s1 + c1 * s2 * s3; Rmat[2][2] = c1 * c2; } +#endif return; } +#ifndef FIX_I109_ORIENTATION_TRACKING /*------------------------------------------------------------------------- * Quat2Euler() * @@ -196,15 +221,9 @@ void Quat2Euler( { if ( quat.w != -3.0 ) { -#ifdef FIX_I109_ORIENTATION_TRACKING - *roll = atan2f( 2 * ( quat.w * quat.x + quat.y * quat.z ), 1 - 2 * ( quat.x * quat.x + quat.y * quat.y ) ); - *pitch = asinf( 2 * ( quat.w * quat.y - quat.z * quat.x ) ); - *yaw = atan2f( 2 * ( quat.w * quat.z + quat.x * quat.y ), 1 - 2 * ( quat.y * quat.y + quat.z * quat.z ) ); -#else // bug: x and z swapped *yaw = atan2f( 2 * ( quat.w * quat.x + quat.y * quat.z ), 1 - 2 * ( quat.x * quat.x + quat.y * quat.y ) ); *pitch = asinf( 2 * ( quat.w * quat.y - quat.z * quat.x ) ); *roll = atan2f( 2 * ( quat.w * quat.z + quat.x * quat.y ), 1 - 2 * ( quat.y * quat.y + quat.z * quat.z ) ); -#endif } else { @@ -221,6 +240,7 @@ void Quat2Euler( return; } +#endif #ifdef FIX_I109_ORIENTATION_TRACKING /*------------------------------------------------------------------------- @@ -252,7 +272,7 @@ void Euler2Quat( } /*------------------------------------------------------------------------- - * rad2deg() + * deg2rad() * * Return angle in radians from degrees *------------------------------------------------------------------------*/ @@ -269,29 +289,8 @@ float deg2rad( float degrees ) return PI_OVER_180 * degrees; } - -/*------------------------------------------------------------------------- - * deg2rad() - * - * Return angle in degrees from radians - *------------------------------------------------------------------------*/ -float rad2deg( float radians ) -{ - if ( radians >= EVS_PI ) - { - radians = radians - PI2; - } - if ( radians <= -EVS_PI ) - { - radians = radians + PI2; - } - - return _180_OVER_PI * radians; -} - #endif - /*------------------------------------------------------------------------- * rotateAziEle() * -- GitLab From a39e0f1f7e2642ae675d492d62904d18553b3c3c Mon Sep 17 00:00:00 2001 From: szczerba Date: Thu, 9 Mar 2023 10:54:10 +0100 Subject: [PATCH 09/12] QuatToRotMat update correction (wrong input mode) --- lib_rend/ivas_rotation.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 52858fdb80..8f236a64c8 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -122,25 +122,17 @@ void QuatToRotMat( float s1, s2, s3, c1, c2, c3; #ifdef FIX_I109_ORIENTATION_TRACKING - c1 = cosf( quat.z / _180_OVER_PI ); - c2 = cosf( quat.y / _180_OVER_PI ); - c3 = cosf( quat.x / _180_OVER_PI ); + Rmat[0][0] = quat.w * quat.w + quat.x * quat.x - quat.y * quat.y - quat.z * quat.z; + Rmat[0][1] = 2.0f * ( quat.x * quat.y - quat.w * quat.z ); + Rmat[0][2] = 2.0f * ( quat.x * quat.z + quat.w * quat.y ); - s1 = sinf( quat.z / _180_OVER_PI ); - s2 = sinf( -quat.y / _180_OVER_PI ); - s3 = sinf( quat.x / _180_OVER_PI ); + Rmat[1][0] = 2.0f * ( quat.x * quat.y + quat.w * quat.z ); + Rmat[1][1] = quat.w * quat.w - quat.x * quat.x + quat.y * quat.y - quat.z * quat.z; + Rmat[1][2] = 2.0f * ( quat.y * quat.z - quat.w * quat.x ); - Rmat[0][0] = c2 * c3; - Rmat[0][1] = -c2 * s3; - Rmat[0][2] = s2; - - Rmat[1][0] = c1 * s3 + c3 * s1 * s2; - Rmat[1][1] = c1 * c3 - s1 * s2 * s3; - Rmat[1][2] = -c2 * s1; - - Rmat[2][0] = s1 * s3 - c1 * c3 * s2; - Rmat[2][1] = c3 * s1 + c1 * s2 * s3; - Rmat[2][2] = c1 * c2; + Rmat[2][0] = 2.0f * ( quat.x * quat.z - quat.w * quat.y ); + Rmat[2][1] = 2.0f * ( quat.y * quat.z + quat.w * quat.x ); + Rmat[2][2] = quat.w * quat.w - quat.x * quat.x - quat.y * quat.y + quat.z * quat.z; #else #ifdef DEBUGGING -- GitLab From 7546d0553cf364f881275a15ccd7e695623ea3e9 Mon Sep 17 00:00:00 2001 From: szczerba Date: Thu, 9 Mar 2023 10:57:20 +0100 Subject: [PATCH 10/12] Unused variables cleanup --- lib_rend/ivas_rotation.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 8f236a64c8..f1bbabdab1 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -119,8 +119,6 @@ void QuatToRotMat( float Rmat[3][3] /* o : real-space rotation matrix for this rotation */ ) { - float s1, s2, s3, c1, c2, c3; - #ifdef FIX_I109_ORIENTATION_TRACKING Rmat[0][0] = quat.w * quat.w + quat.x * quat.x - quat.y * quat.y - quat.z * quat.z; Rmat[0][1] = 2.0f * ( quat.x * quat.y - quat.w * quat.z ); @@ -134,6 +132,7 @@ void QuatToRotMat( Rmat[2][1] = 2.0f * ( quat.y * quat.z + quat.w * quat.x ); Rmat[2][2] = quat.w * quat.w - quat.x * quat.x - quat.y * quat.y + quat.z * quat.z; #else + float s1, s2, s3, c1, c2, c3; #ifdef DEBUGGING /* PrintQuat( quat ); */ -- GitLab From c7cc7d9a5216ce6ee24a431936a028aace6d78e3 Mon Sep 17 00:00:00 2001 From: szczerba Date: Thu, 9 Mar 2023 11:04:45 +0100 Subject: [PATCH 11/12] Missing assignment --- lib_rend/ivas_orient_trk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index bc685c704a..49748ae85b 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -752,6 +752,10 @@ ivas_error ivas_orient_trk_Process( break; } + if ( result == IVAS_ERR_OK ) + { + *pTrkRot = pOTR->trkRot; + } return result; } #else -- GitLab From 718f59c918aade943e9695ff27345edfc4e13479 Mon Sep 17 00:00:00 2001 From: szczerba Date: Thu, 9 Mar 2023 11:23:55 +0100 Subject: [PATCH 12/12] Euler to quaternion conversion moved out of orientation tracking processing --- lib_dec/lib_dec.c | 10 ++++++++++ lib_rend/ivas_orient_trk.c | 25 +++++++------------------ lib_rend/lib_rend.c | 19 ++++++++++++++++--- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index ab81c62206..faf2ddc204 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -906,7 +906,11 @@ ivas_error IVAS_DEC_FeedHeadTrackData( HEAD_TRACK_DATA_HANDLE hHeadTrackData; int16_t i; +#ifdef FIX_I109_ORIENTATION_TRACKING + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || orientation == NULL ) +#else if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) +#endif { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } @@ -922,6 +926,12 @@ ivas_error IVAS_DEC_FeedHeadTrackData( for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { #ifdef FIX_I109_ORIENTATION_TRACKING + /* check for Euler angle signaling */ + if ( orientation[i].w == -3.0f ) + { + Euler2Quat( deg2rad( orientation[i].x ), deg2rad( orientation[i].y ), deg2rad( orientation[i].z ), &orientation[i] ); + } + ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation[i], FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hHeadTrackData->Quaternions[i] ); #else hHeadTrackData->Quaternions[i].w = orientation[i].w; diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 49748ae85b..f8eaca2e23 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -665,56 +665,45 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; - IVAS_QUATERNION absQuat; if ( pOTR == NULL || pTrkRot == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - /* check for Euler angle signaling */ - if ( absRot.w == -3.0f ) - { - Euler2Quat( deg2rad( absRot.x ), deg2rad( absRot.y ), deg2rad( absRot.z ), &absQuat ); - } - else - { - absQuat = absRot; - } - result = IVAS_ERR_OK; switch ( pOTR->trackingType ) { case OTR_TRACKING_NONE: - pOTR->trkRot = absQuat; + pOTR->trkRot = absRot; break; case OTR_TRACKING_REF_ORIENT: /* Reset average orientation */ - pOTR->absAvgRot = absQuat; + pOTR->absAvgRot = absRot; /* Reset adaptation filter - start adaptation at center rate */ pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse( pOTR->refRot, &pOTR->trkRot ); - QuaternionProduct( pOTR->trkRot, absQuat, &pOTR->trkRot ); + QuaternionProduct( pOTR->trkRot, absRot, &pOTR->trkRot ); break; case OTR_TRACKING_AVG_ORIENT: /* Compute average (low-pass filtered) absolute orientation */ - QuaternionSlerp( pOTR->absAvgRot, absQuat, alpha, &pOTR->absAvgRot ); + QuaternionSlerp( pOTR->absAvgRot, absRot, alpha, &pOTR->absAvgRot ); /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ QuaternionInverse( pOTR->absAvgRot, &pOTR->trkRot ); - QuaternionProduct( pOTR->trkRot, absQuat, &pOTR->trkRot ); + QuaternionProduct( pOTR->trkRot, absRot, &pOTR->trkRot ); /* Adapt LPF constant based on orientation excursion relative to current mean: - low cutoff (slow adaptation) for small excursions (around center) - high cutoff (fast adaptation) for large excursions (off-center) */ - ang = QuaternionAngle( absQuat, pOTR->trkRot ); + ang = QuaternionAngle( absRot, pOTR->trkRot ); normalizedOrientation = ang * ang; relativeOrientationRate = sqrtf( normalizedOrientation ) / pOTR->adaptationAngle; @@ -743,7 +732,7 @@ ivas_error ivas_orient_trk_Process( case OTR_TRACKING_REF_VEC_LEV: { /* This processing step of the OTR_TRACKING_REF_VEC/OTR_TRACKING_REF_VEC_LEVEL is identical */ - QuaternionProduct( pOTR->refRot, absQuat, &pOTR->trkRot ); + QuaternionProduct( pOTR->refRot, absRot, &pOTR->trkRot ); break; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 7e0b2997bc..dc8fe6f510 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3017,7 +3017,7 @@ static IVAS_REND_InputId makeInputId( /* Put config type in second byte (from LSB), put index + 1 in first byte * * Index is incremented here so that a valid ID can never be 0. */ - return (IVAS_REND_InputId) ( ( ( (uint32_t) getAudioConfigType( config ) ) << 8 ) | ( inputIndex + 1 ) ); + return ( IVAS_REND_InputId )( ( ( (uint32_t) getAudioConfigType( config ) ) << 8 ) | ( inputIndex + 1 ) ); } static ivas_error getInputById( @@ -3642,7 +3642,7 @@ ivas_error IVAS_REND_GetDelay( { if ( hIvasRend->inputsMasa[i].base.inConfig != IVAS_REND_AUDIO_CONFIG_UNKNOWN ) { - latency_ns = NS2SA( hIvasRend->sampleRateOut, (int32_t) ( (float) IVAS_FB_DEC_DELAY_NS + 0.5f ) ); + latency_ns = NS2SA( hIvasRend->sampleRateOut, ( int32_t )( (float) IVAS_FB_DEC_DELAY_NS + 0.5f ) ); max_latency_ns = max( max_latency_ns, latency_ns ); } } @@ -3967,6 +3967,9 @@ ivas_error IVAS_REND_SetHeadRotation( ) { int16_t i; +#ifdef FIX_I109_ORIENTATION_TRACKING + IVAS_QUATERNION rotQuat; +#endif /*-----------------------------------------------------------------* * Validate function arguments @@ -3993,7 +3996,17 @@ ivas_error IVAS_REND_SetHeadRotation( for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; ++i ) { #ifdef FIX_I109_ORIENTATION_TRACKING - ivas_orient_trk_Process( hIvasRend->headRotData.hOrientationTracker, headRot[i], FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hIvasRend->headRotData.headPositions[i] ); + /* check for Euler angle signaling */ + if ( headRot[i].w == -3.0f ) + { + Euler2Quat( deg2rad( headRot[i].x ), deg2rad( headRot[i].y ), deg2rad( headRot[i].z ), &rotQuat ); + } + else + { + rotQuat = headRot[i]; + } + + ivas_orient_trk_Process( hIvasRend->headRotData.hOrientationTracker, rotQuat, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hIvasRend->headRotData.headPositions[i] ); #else hIvasRend->headRotData.headPositions[i] = headRot[i]; #endif -- GitLab