diff --git a/apps/decoder.c b/apps/decoder.c index cf32f6bf5febb789b07cf0541a0800d338f6279d..2a69e9006c6a21e85a7013a28bc8066d65328335 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1597,36 +1597,25 @@ static ivas_error decodeG192( goto cleanup; } - /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) - { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - #ifdef FIX_I109_ORIENTATION_TRACKING - for ( i = 0; i < IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i] ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( headRotReader ) ); - goto cleanup; - } - } -#else - if ( ( error = HeadRotationFileReading( headRotReader, Quaternions, frame ) ) != IVAS_ERR_OK ) +#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 head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( headRotReader ) ); + fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); goto cleanup; } -#endif - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } } - -#ifdef FIX_I109_ORIENTATION_TRACKING +#endif /* OTR_REFERENCE_VECTOR_TRACKING */ /* Reference rotation */ if ( arg.enableReferenceRotation ) { @@ -1643,25 +1632,35 @@ static ivas_error decodeG192( goto cleanup; } } -#ifdef OTR_REFERENCE_VECTOR_TRACKING - /* reference vector */ - if ( arg.enableReferenceVectorTracking ) +#endif + /* Head-tracking input simulation */ + if ( arg.enableHeadRotation ) { - IVAS_VECTOR3 listenerPosition, referencePosition; - if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK ) + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; + +#ifdef FIX_I109_ORIENTATION_TRACKING + for ( i = 0; i < IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) ); + if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( headRotReader ) ); + goto cleanup; + } + } +#else + if ( ( error = HeadRotationFileReading( headRotReader, Quaternions, frame ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), HeadRotationFileReader_getFilePath( headRotReader ) ); goto cleanup; } +#endif - if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData 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 ) { diff --git a/apps/renderer.c b/apps/renderer.c index dba78d64383e4e99a914f8f3ef116b83cbfd6a5f..266be9a4fdc63c71bb9ab6c775cb65d9067042f9 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -979,37 +979,6 @@ int main( ObjectPositionBuffer mtdBuffer; IsmPositionProvider_getNextFrame( positionProvider, &mtdBuffer ); - /* Read from head rotation trajectory file if specified */ - if ( headRotReader != NULL ) - { - IVAS_QUATERNION quatBuffer[RENDERER_HEAD_POSITIONS_PER_FRAME]; -#ifdef FIX_I109_ORIENTATION_TRACKING - for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; i++ ) - { - if ( HeadRotationFileReading( headRotReader, &quatBuffer[i] ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error in Head Rotation File Reading.\r\n" ); - exit( -1 ); - } - } -#else - HeadRotationFileReading( headRotReader, quatBuffer, frame ); -#endif - if ( IVAS_REND_SetHeadRotation( hIvasRend, quatBuffer ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Error setting Head Rotation\n" ); - exit( -1 ); - } - } - else - { - if ( ( IVAS_REND_SetHeadRotation( hIvasRend, NULL ) != IVAS_ERR_OK ) && ( IVAS_REND_SetHeadRotation( hIvasRend, NULL ) != IVAS_ERR_INVALID_OUTPUT_FORMAT ) ) - { - fprintf( stderr, "Error setting Head Rotation\n" ); - exit( -1 ); - } - } - #ifdef FIX_I109_ORIENTATION_TRACKING #ifdef OTR_REFERENCE_VECTOR_TRACKING if ( referenceVectorReader != NULL ) @@ -1044,6 +1013,37 @@ int main( } #endif + /* Read from head rotation trajectory file if specified */ + if ( headRotReader != NULL ) + { + IVAS_QUATERNION quatBuffer[RENDERER_HEAD_POSITIONS_PER_FRAME]; +#ifdef FIX_I109_ORIENTATION_TRACKING + for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; i++ ) + { + if ( HeadRotationFileReading( headRotReader, &quatBuffer[i] ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error in Head Rotation File Reading.\r\n" ); + exit( -1 ); + } + } +#else + HeadRotationFileReading( headRotReader, quatBuffer, frame ); +#endif + if ( IVAS_REND_SetHeadRotation( hIvasRend, quatBuffer ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error setting Head Rotation\n" ); + exit( -1 ); + } + } + else + { + if ( ( IVAS_REND_SetHeadRotation( hIvasRend, NULL ) != IVAS_ERR_OK ) && ( IVAS_REND_SetHeadRotation( hIvasRend, NULL ) != IVAS_ERR_INVALID_OUTPUT_FORMAT ) ) + { + fprintf( stderr, "Error setting Head Rotation\n" ); + exit( -1 ); + } + } + for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) { if ( ( error = IVAS_REND_GetInputNumChannels( hIvasRend, mcIds[i], &numChannels ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index d61b488e1bc61c9c652ab10f2c8ffa983edfec58..9c7e07734e61ece45dacff9152ec9788a5d907af 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 055ea1e9c5eb83339af869bfa99e1ced06a9ea04..1f8de9cb38e7809b0d1b260087e6ee00eca2f963 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -2096,9 +2096,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" ); @@ -2165,15 +2162,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 3e2c027eca9d15f9044fb3e8a5a01e7ae7c80916..a965a0ffed38a43b5e3472da691aae20348293ff 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 149e62b3102527534b915445ddc49f91c10c5ae2..8780b4ea98d6397edf69a7ec701bc73a07d6021b 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -71,11 +71,6 @@ ivas_error 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 return ivas_td_binaural_renderer_unwrap( #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND st_ivas->hReverb, @@ -92,10 +87,5 @@ ivas_error ivas_td_binaural_renderer( st_ivas->hDecoderConfig->output_Fs, #endif st_ivas->hBinRendererTd, st_ivas->nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, - st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, output, output_frame -#ifdef FIX_I109_ORIENTATION_TRACKING - , - pOtr -#endif - ); + st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, output, output_frame ); } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 315d7684248d10cbd2624570ae63c462f2016d03..6e9393672058219f1debb63d451cf117fa7a6592 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -913,7 +913,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; } @@ -928,10 +932,20 @@ 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 + /* 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; 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 bc8e3351f09e0ebc40713c2672a1f9ae95b68a2c..020dd27cfa1b47d827fcf82d00f7e45094865297 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 17643665d4149159403aceffad40e5c8a25ac63e..7ec5e4aa52a7f453b3ad6fc06e689561625f7342 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -252,18 +252,11 @@ ivas_error 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 ivas_error error; subframe_length = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; @@ -293,18 +286,7 @@ ivas_error 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 #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND if ( ( hReverb != NULL ) && ( hReverb->pConfig.roomAcoustics.late_reverb_on ) ) @@ -704,29 +686,16 @@ ivas_error ivas_td_binaural_renderer_ext( transport_config = rendAudioConfigToIvasAudioConfig( inConfig ); #endif output_Fs = output_frame * 50; - #endif #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND - if ( ( error = ivas_td_binaural_renderer_unwrap( reverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, headRotData->headRotEnabled, - ( headRotData != NULL ) ? headRotData->headPositions : NULL, output, output_frame -#ifdef FIX_I109_ORIENTATION_TRACKING - , - headRotData->hOrientationTracker -#endif - ) ) != IVAS_ERR_OK ) + ( headRotData != NULL ) ? headRotData->headPositions : NULL, output, output_frame ) ) != IVAS_ERR_OK ) { return error; } #else - if ( ( error = error = ivas_td_binaural_renderer_unwrap( NULL, 1, NULL, transport_config, output_Fs, pTDRend->hBinRendererTd, num_src, lfe_idx, - ivas_format, hIsmMetaData, headRotData->headRotEnabled, ( headRotData != NULL ) ? headRotData->headPositions : NULL, - output, output_frame -#ifdef FIX_I109_ORIENTATION_TRACKING - , - headRotData->hOrientationTracker -#endif - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_binaural_renderer_unwrap( NULL, 1, NULL, transport_config, output_Fs, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, headRotData->headRotEnabled, + ( headRotData != NULL ) ? headRotData->headPositions : NULL, output, output_frame ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index a408cf284a8b3bcb6236cdde9ddcd0e5e58b43b7..471694637fc328ae2cb7def8399502cee41a87bc 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,10 +665,10 @@ void 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; @@ -677,57 +677,45 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; - IVAS_QUATERNION absQuat, trkQuat; - IVAS_QUATERNION trkEuler; if ( pOTR == NULL || pTrkRot == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - /* check for Euler angle signaling */ - if ( pAbsRot->w == -3.0f ) - { - Euler2Quat( deg2rad( pAbsRot->x ), deg2rad( pAbsRot->y ), deg2rad( pAbsRot->z ), &absQuat ); - } - else - { - absQuat = *pAbsRot; - } - result = IVAS_ERR_OK; switch ( pOTR->trackingType ) { case OTR_TRACKING_NONE: - trkQuat = 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, &trkQuat ); - QuaternionProduct( trkQuat, absQuat, &trkQuat ); + QuaternionInverse( pOTR->refRot, &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, &trkQuat ); - QuaternionProduct( trkQuat, absQuat, &trkQuat ); + QuaternionInverse( pOTR->absAvgRot, &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, trkQuat ); + ang = QuaternionAngle( absRot, pOTR->trkRot ); normalizedOrientation = ang * ang; relativeOrientationRate = sqrtf( normalizedOrientation ) / pOTR->adaptationAngle; @@ -756,7 +744,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, absRot, &pOTR->trkRot ); break; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ @@ -767,23 +755,8 @@ ivas_error ivas_orient_trk_Process( if ( result == IVAS_ERR_OK ) { - pOTR->trkRot = trkQuat; - - if ( pAbsRot->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; - } + *pTrkRot = pOTR->trkRot; } - return result; } #else diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index b6baa71389ebb9607c48c65872ebd9ab2255d2ea..c1b0c184908b61f06c5859c25ee41fd0970e6c93 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -240,10 +240,6 @@ ivas_error 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( @@ -798,28 +794,26 @@ 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 yaw, /* i : yaw (x) */ const float pitch, /* i : pitch (y) */ - const float yaw, /* i : yaw (z) */ + const float roll, /* i : roll (z) */ IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ); 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 */ @@ -942,7 +936,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 d3f6bec381948f938cdaeeaa232635585c0ca0cc..ab69b2453038e69232990e36a8cfdebb178a9552 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -119,7 +119,21 @@ void QuatToRotMat( float Rmat[3][3] /* o : real-space rotation matrix for this rotation */ ) { +#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 ); + Rmat[0][2] = 2.0f * ( quat.x * quat.z + quat.w * quat.y ); + + 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[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 float s1, s2, s3, c1, c2, c3; + #ifdef DEBUGGING /* PrintQuat( quat ); */ #endif @@ -177,10 +191,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 +212,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 +231,7 @@ void Quat2Euler( return; } +#endif #ifdef FIX_I109_ORIENTATION_TRACKING /*------------------------------------------------------------------------- @@ -230,33 +241,35 @@ void Quat2Euler( *------------------------------------------------------------------------*/ void Euler2Quat( - const float roll, /* i : roll (x) */ + const float yaw, /* i : yaw (x) */ const float pitch, /* i : pitch (y) */ - const float yaw, /* i : yaw (z) */ + const float roll, /* i : roll (z) */ IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ) { float cr = cosf( roll * 0.5f ); float sr = sinf( roll * 0.5f ); float cp = cosf( pitch * 0.5f ); - float sp = sinf( pitch * 0.5f ); + float sp = sinf( -pitch * 0.5f ); float cy = cosf( yaw * 0.5f ); float sy = sinf( yaw * 0.5f ); - quat->w = cr * cp * cy + sr * sp * sy; - quat->x = sr * cp * cy - cr * sp * sy; - quat->y = cr * sp * cy + sr * cp * sy; - quat->z = cr * cp * sy - sr * sp * cy; + quat->w = cr * cp * cy - sr * sp * sy; + quat->x = sr * cp * cy + cr * sp * sy; + quat->y = cr * sp * cy - sr * cp * sy; + quat->z = cr * cp * sy + sr * sp * cy; return; } /*------------------------------------------------------------------------- - * rad2deg() + * deg2rad() * - * Return angle in radians from degrees + * Converts degrees to normalized radians *------------------------------------------------------------------------*/ -float deg2rad( float degrees ) +float deg2rad( + float degrees +) { while ( degrees >= 180.0f ) { @@ -269,29 +282,8 @@ float deg2rad( float degrees ) return PI_OVER_180 * degrees; } - -/*------------------------------------------------------------------------- - * deg2rad() - * - * Return angle in degrees from radians - *------------------------------------------------------------------------*/ -float rad2deg( float radians ) -{ - while ( radians >= EVS_PI ) - { - radians = radians - PI2; - } - while ( radians <= -EVS_PI ) - { - radians = radians + PI2; - } - - return _180_OVER_PI * radians; -} - #endif - /*------------------------------------------------------------------------- * rotateAziEle() * @@ -361,9 +353,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; @@ -381,15 +370,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 ); @@ -478,9 +459,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" ); @@ -494,15 +472,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++ ) { @@ -717,9 +687,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" ); @@ -735,15 +702,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 aaac378c5c57da0e9a8ef0e66e676676f79a4ff8..025acc1860838f18ff67f87a31b4dbf8e422519d 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3102,7 +3102,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( @@ -3730,7 +3730,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 ); } } @@ -4055,6 +4055,9 @@ ivas_error IVAS_REND_SetHeadRotation( ) { int16_t i; +#ifdef FIX_I109_ORIENTATION_TRACKING + IVAS_QUATERNION rotQuat; +#endif /*-----------------------------------------------------------------* * Validate function arguments @@ -4080,7 +4083,21 @@ ivas_error IVAS_REND_SetHeadRotation( hIvasRend->headRotData.headRotEnabled = 1; for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; ++i ) { +#ifdef FIX_I109_ORIENTATION_TRACKING + /* 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 } } @@ -4312,9 +4329,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 ivas_error error; push_wmops( "rotateFrameMc" ); @@ -4348,15 +4362,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++ ) { @@ -4438,9 +4444,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 ivas_error error; push_wmops( "rotateFrameSba" ); @@ -4461,15 +4464,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 ); @@ -4594,18 +4589,13 @@ static ivas_error renderIsmToBinauralRoom( #else float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; #endif -#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" ); @@ -4645,20 +4635,12 @@ 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; + 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( quat, Rmat ); } (void) subframe_len; // avoid warning }