diff --git a/apps/decoder.c b/apps/decoder.c index 054a219063fd75252a41305e8803e344662371b1..1414eeb6255dc44d37687134248310f6909b658d 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1650,7 +1650,7 @@ static void resetHeadRotation( pPos[i].y_fx = 0; pPos[i].z_fx = 0; #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - pPos[i].q_fact = 22; + pPos[i].q_fact = 31; #else pPos[i].q_fact = 25; #endif diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 0a693d0451ab92c8a693b9f7f563b4b19d6c90c0..68f818067ba0a6b30fca29b0c86db11f58f13c67 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -165,7 +165,7 @@ typedef struct { float x, y, z; #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Word32 x_fx, y_fx, z_fx; /* Q22, Q22, Q22 */ + Word32 x_fx, y_fx, z_fx; /* qfact, qfact, qfact */ #else Word32 x_fx, y_fx, z_fx; #endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 02d720e2f92dcf70597900005b7a3a8c00bea5a6..36bdc823d4ad21ad4d670044cbf0517d347d782f 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1937,7 +1937,12 @@ ivas_error TDREND_MIX_LIST_SetOrient_fx( void TDREND_MIX_LIST_SetPos_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + const Word32 *Pos_p, /* i : Listener's position */ + const Word16 Pos_q /* i : Listener's position Q value */ +#else const Word32 *Pos_p /* i : Listener's position */ +#endif ); ivas_error TDREND_Update_listener_orientation_fx( diff --git a/lib_dec/ivas_objectRenderer_internal_fx.c b/lib_dec/ivas_objectRenderer_internal_fx.c index 814ba4254ff6373368d4ae5eea9c1513cf0282a7..8806a6aefc9a29436a76aabc5472f52980c72481 100644 --- a/lib_dec/ivas_objectRenderer_internal_fx.c +++ b/lib_dec/ivas_objectRenderer_internal_fx.c @@ -264,11 +264,8 @@ ivas_error ivas_td_binaural_renderer_sf_fx( enableCombinedOrientation = st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx]; move16(); -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - /* Shifting x_fx, y_fx, z_fx to the same Q-factor as Listener_p->Pos_q (usually Q22) */ -#else +#ifndef FIX_BASOP_2023_TDREND_DISTATT_PRECISION /* Shifting x_fx, y_fx, z_fx to the same Q-factor as Listener_p->Pos_q (usually Q25) */ -#endif Word16 pos_q = st_ivas->hBinRendererTd->Listener_p->Pos_q; move16(); tmp_vector_fx->x_fx = L_shr( tmp_vector_fx->x_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); @@ -276,6 +273,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( tmp_vector_fx->z_fx = L_shr( tmp_vector_fx->z_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); tmp_vector_fx->q_fact = pos_q; move16(); +#endif } ELSE { diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index c49bf243355ab98557df651359d2a63a37f8af9e..07a53676bdba954925946268c0c7d164afd1df1c 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -2109,15 +2109,9 @@ ivas_error IVAS_DEC_FeedHeadTrackData( return error; } -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - hHeadTrackData->Pos[subframe_idx].x_fx = max( min( IVAS_LISTENER_POSITION_MAX_Q22, Pos.x_fx ), -IVAS_LISTENER_POSITION_MAX_Q22 ); - hHeadTrackData->Pos[subframe_idx].y_fx = max( min( IVAS_LISTENER_POSITION_MAX_Q22, Pos.y_fx ), -IVAS_LISTENER_POSITION_MAX_Q22 ); - hHeadTrackData->Pos[subframe_idx].z_fx = max( min( IVAS_LISTENER_POSITION_MAX_Q22, Pos.z_fx ), -IVAS_LISTENER_POSITION_MAX_Q22 ); -#else hHeadTrackData->Pos[subframe_idx].x_fx = Pos.x_fx; hHeadTrackData->Pos[subframe_idx].y_fx = Pos.y_fx; hHeadTrackData->Pos[subframe_idx].z_fx = Pos.z_fx; -#endif hHeadTrackData->Pos[subframe_idx].q_fact = Pos.q_fact; move32(); move32(); diff --git a/lib_rend/ivas_objectRenderer_fx.c b/lib_rend/ivas_objectRenderer_fx.c index bfa5d30396b09886024bb8878181b4873e3f3064..b9b92a56fff032230876290057d30c27ae7a0a1a 100644 --- a/lib_rend/ivas_objectRenderer_fx.c +++ b/lib_rend/ivas_objectRenderer_fx.c @@ -82,11 +82,7 @@ ivas_error ivas_td_binaural_open_unwrap_fx( TDREND_PosType_t PosType; Word16 nS; const Word32 *ls_azimuth_fx, *ls_elevation_fx; -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Word32 Pos_fx[3]; // Q22 -#else Word32 Pos_fx[3]; // Q25 -#endif Word32 Dir_fx[3]; // Q30 TDREND_DirAtten_t *DirAtten_p; TDREND_DistAtten_t DistAtten; @@ -189,9 +185,6 @@ ivas_error ivas_td_binaural_open_unwrap_fx( { /* Set source positions according to loudspeaker layout */ angles_to_vec_fx( ONE_IN_Q9, ls_azimuth_fx[nS], ls_elevation_fx[nS], Pos_fx ); -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Scale_sig32( Pos_fx, 3, -3 ); /* Q25 -> Q22 */ -#endif Dir_fx[0] = ONE_IN_Q30; move32(); @@ -654,11 +647,7 @@ ivas_error TDREND_Update_object_positions_fx( ) { Word16 nS; -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Word32 Pos_fx[3]; // Q22 -#else Word32 Pos_fx[3]; // Q25 -#endif Word32 Dir_fx[3]; // Q30 ivas_error error; @@ -671,12 +660,7 @@ ivas_error TDREND_Update_object_positions_fx( { /* Update the source positions */ /* Source position and direction */ -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - angles_to_vec_fx( hIsmMetaData[nS]->radius_fx /*Q9*/, hIsmMetaData[nS]->azimuth_fx, hIsmMetaData[nS]->elevation_fx, Pos_fx ); - Scale_sig32( Pos_fx, 3, -3 ); /* Q25 -> Q22 */ -#else angles_to_vec_fx( hIsmMetaData[nS]->radius_fx /*Q9*/, hIsmMetaData[nS]->azimuth_fx, hIsmMetaData[nS]->elevation_fx, Pos_fx ); -#endif angles_to_vec_fx( ONE_IN_Q14, hIsmMetaData[nS]->yaw_fx, hIsmMetaData[nS]->pitch_fx, Dir_fx ); // DirAtten_p->ConeInnerAngle_fx = DEG_360_IN_Q22; @@ -699,11 +683,7 @@ ivas_error TDREND_Update_object_positions_fx( { Pos_fx[0] = 0; /* Pos[1] = hIsmMetaData[nS]->azimuth / 90.f; */ -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Pos_fx[1] = L_shl( Mpy_32_32_r( hIsmMetaData[nS]->azimuth_fx, 23860929 /* 1 / 90.f in Q31 */ ), 0 ); /* Q22 */ -#else Pos_fx[1] = L_shl( Mpy_32_32_r( hIsmMetaData[nS]->azimuth_fx, 23860929 /* 1 / 90.f in Q31 */ ), Q3 ); /* Q25 */ -#endif move32(); Pos_fx[2] = 0; move32(); @@ -749,6 +729,9 @@ ivas_error TDREND_Update_listener_orientation_fx( Word32 Rmat_fx[3][3]; Word16 orient_q, headPosition_q; Word32 Pos_p_fx[3]; +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + Word16 Pos_q; +#endif ivas_error error; IF( headRotEnabled ) @@ -787,6 +770,9 @@ ivas_error TDREND_Update_listener_orientation_fx( Pos_p_fx[0] = ( *Pos_fx ).x_fx; // Q Pos_fx->q_fact Pos_p_fx[1] = ( *Pos_fx ).y_fx; // Q Pos_fx->q_fact Pos_p_fx[2] = ( *Pos_fx ).z_fx; // Q Pos_fx->q_fact +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + Pos_q = ( *Pos_fx ).q_fact; +#endif } ELSE { @@ -794,10 +780,16 @@ ivas_error TDREND_Update_listener_orientation_fx( Pos_p_fx[0] = 0; Pos_p_fx[1] = 0; Pos_p_fx[2] = 0; +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + Pos_q = Q31; +#endif } move32(); move32(); move32(); +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + move16(); +#endif } ELSE { @@ -826,10 +818,18 @@ ivas_error TDREND_Update_listener_orientation_fx( move32(); Pos_p_fx[2] = 0; move32(); +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + Pos_q = Q31; + move16(); +#endif } /* Set the listener position and orientation:*/ +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + TDREND_MIX_LIST_SetPos_fx( hBinRendererTd, Pos_p_fx, Pos_q ); +#else TDREND_MIX_LIST_SetPos_fx( hBinRendererTd, Pos_p_fx ); +#endif error = TDREND_MIX_LIST_SetOrient_fx( hBinRendererTd, FrontVec_fx, UpVec_fx, orient_q ); @@ -1013,7 +1013,7 @@ ivas_error ivas_td_binaural_renderer_ext_fx( Word16 idx = subframe_idx; move16(); #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Word16 pos_q = Q22; + Word16 pos_q = Q31; #else Word16 pos_q = Q25; #endif @@ -1022,6 +1022,10 @@ ivas_error ivas_td_binaural_renderer_ext_fx( test(); IF( *hCombinedOrientationData != NULL && ( *hCombinedOrientationData )->listenerPos != NULL ) { +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + pos_q = ( *hCombinedOrientationData )->listenerPos[idx].q_fact; + move16(); +#else ( *hCombinedOrientationData )->listenerPos[idx].x_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].x_fx, sub( ( *hCombinedOrientationData )->listenerPos[idx].q_fact, pos_q ) ); move32(); ( *hCombinedOrientationData )->listenerPos[idx].y_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].y_fx, sub( ( *hCombinedOrientationData )->listenerPos[idx].q_fact, pos_q ) ); @@ -1030,14 +1034,23 @@ ivas_error ivas_td_binaural_renderer_ext_fx( move32(); ( *hCombinedOrientationData )->listenerPos[idx].q_fact = pos_q; move16(); +#endif } FOR( Word16 i = 0; i < 3; i++ ) { pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = L_shr( pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], sub( pTDRend->hBinRendererTd->Listener_p->Pos_q, pos_q ) ); +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + move32(); +#else pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; move32(); move16(); +#endif } +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; + move16(); +#endif } IF( NE_32( ( error = ivas_td_binaural_renderer_unwrap_fx( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, diff --git a/lib_rend/ivas_objectRenderer_mix_fx.c b/lib_rend/ivas_objectRenderer_mix_fx.c index e9c181692c359b718b14b2b40ca0437fcb775db9..2924da90809afc69e956f3760414f2a2ad457b85 100644 --- a/lib_rend/ivas_objectRenderer_mix_fx.c +++ b/lib_rend/ivas_objectRenderer_mix_fx.c @@ -54,8 +54,14 @@ static ivas_error DefaultBSplineModel_fx( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, --------------------------------------------------------------------*/ void TDREND_MIX_LIST_SetPos_fx( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + const Word32 *Pos_p, + /* i : Listener's position */ // Q Pos_fx->q_fact + const Word16 Pos_q /* i : Listener's position Q value */ +#else const Word32 *Pos_p /* i : Listener's position */ // Q Pos_fx->q_fact +#endif ) { TDREND_MIX_Listener_t *Listener_p; @@ -63,10 +69,19 @@ void TDREND_MIX_LIST_SetPos_fx( Listener_p = hBinRendererTd->Listener_p; test(); test(); +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + test(); + IF( NE_32( Pos_p[0], Listener_p->Pos_fx[0] ) || NE_32( Pos_p[1], Listener_p->Pos_fx[1] ) || NE_32( Pos_p[2], Listener_p->Pos_fx[2] ) || NE_16( Pos_q, Listener_p->Pos_q ) ) +#else IF( NE_32( Pos_p[0], Listener_p->Pos_fx[0] ) || NE_32( Pos_p[1], Listener_p->Pos_fx[1] ) || NE_32( Pos_p[2], Listener_p->Pos_fx[2] ) ) +#endif { /* Set position */ Copy32( Pos_p, Listener_p->Pos_fx, 3 ); // Q Pos_fx->q_fact +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + Listener_p->Pos_q = Pos_q; + move16(); +#endif /* Set pose update flag */ Listener_p->PoseUpdated = TRUE; @@ -205,7 +220,7 @@ ivas_error TDREND_MIX_Init_fx( /* Init virtual and rendering listeners for spatial mixers */ TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Pos_fx, 0, 0, 0 ); #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - hBinRendererTd->Listener_p->Pos_q = Q22; + hBinRendererTd->Listener_p->Pos_q = Q31; #else hBinRendererTd->Listener_p->Pos_q = Q25; #endif diff --git a/lib_rend/ivas_objectRenderer_sources_fx.c b/lib_rend/ivas_objectRenderer_sources_fx.c index 4f0ccb8cfceb906e555e01152bc8f0ef6ddaaf42..748ea0d0de24069c238e68805d6c30497e0d4785 100644 --- a/lib_rend/ivas_objectRenderer_sources_fx.c +++ b/lib_rend/ivas_objectRenderer_sources_fx.c @@ -61,11 +61,7 @@ static void TDREND_SRC_SPATIAL_Dealloc( TDREND_SRC_SPATIAL_t *SrcSpatial_p ); ivas_error TDREND_MIX_SRC_SetPos_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ const Word16 SrcInd, /* i : Source index */ -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - const Word32 *Vec_p /* i : Position vector Q22 */ -#else - const Word32 *Vec_p /* i : Position vector Q25 */ -#endif + const Word32 *Vec_p /* i : Position vector Q25 */ ) { TDREND_SRC_SPATIAL_t *SrcSpatial_p; @@ -77,15 +73,6 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( ELSE { SrcSpatial_p = hBinRendererTd->Sources[SrcInd]->SrcSpatial_p; -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], sub( SrcSpatial_p->q_Pos_p, Q22 ) ); // Q22 - move32(); - SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], sub( SrcSpatial_p->q_Pos_p, Q22 ) ); // Q22 - move32(); - SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], sub( SrcSpatial_p->q_Pos_p, Q22 ) ); // Q22 - move32(); - SrcSpatial_p->q_Pos_p = Q22; -#else SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 @@ -93,17 +80,12 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); // Q25 move32(); SrcSpatial_p->q_Pos_p = Q25; -#endif move16(); test(); test(); IF( NE_32( SrcSpatial_p->Pos_p_fx[0], Vec_p[0] ) || NE_32( SrcSpatial_p->Pos_p_fx[1], Vec_p[1] ) || NE_32( SrcSpatial_p->Pos_p_fx[2], Vec_p[2] ) ) { -#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); // Q22 -#else Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); // Q25 -#endif SrcSpatial_p->Updated = TRUE; move16(); } @@ -343,7 +325,8 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( Word32 elev_delta; Word16 ListRelPos_e, ListRelDist_e; #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Word32 Pos_p_q21[3], Lis_p_q21[3]; + Word16 pos_q; + Word32 Src_p_aligned[3], Lis_p_aligned[3]; #endif /* Evaluate the HR filters from the source and listener positions and orientations */ @@ -357,11 +340,11 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( /* Absolute position */ #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - /* Q22 -> Q21 for 1 bit headroom. Relative position has twice the range of the position */ - Copy_Scale_sig32( SrcSpatial_p->Pos_p_fx, Pos_p_q21, 3, -1 ); - Copy_Scale_sig32( Listener_p->Pos_fx, Lis_p_q21, 3, -1 ); - TDREND_SPATIAL_VecMapToNewCoordSystem_fx( Pos_p_q21, Lis_p_q21, Listener_p->Front_fx, Listener_p->Up_fx, Listener_p->Right_fx, ListRelPos, ListRelPosAbs ); - ListRelPos_e = 11; // Q21 + Q30 - 31 = Q20, exp = 31 - 20 = 11 + pos_q = s_min( SrcSpatial_p->q_Pos_p, Listener_p->Pos_q ); + Copy_Scale_sig32( SrcSpatial_p->Pos_p_fx, Src_p_aligned, 3, sub( pos_q, SrcSpatial_p->q_Pos_p ) ); + Copy_Scale_sig32( Listener_p->Pos_fx, Lis_p_aligned, 3, sub( pos_q, Listener_p->Pos_q ) ); + TDREND_SPATIAL_VecMapToNewCoordSystem_fx( Src_p_aligned, Lis_p_aligned, Listener_p->Front_fx, Listener_p->Up_fx, Listener_p->Right_fx, ListRelPos, ListRelPosAbs ); + ListRelPos_e = sub( 62, add( pos_q, Q30 ) ); // Qq + Q30 - 31, exp = 62 - q - 30 #else TDREND_SPATIAL_VecMapToNewCoordSystem_fx( SrcSpatial_p->Pos_p_fx, Listener_p->Pos_fx, Listener_p->Front_fx, Listener_p->Up_fx, Listener_p->Right_fx, ListRelPos, ListRelPosAbs ); ListRelPos_e = 7; // output q of above function is Q25 + Q30 - 31. so exp will be 62 - Q25 - Q30. @@ -406,7 +389,7 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( IF( SrcSpatial_p->DirAttenEnabled ) { #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - *SrcRend_p->DirGain_p_fx = TDREND_SRC_SPATIAL_GetDirGain_fx( &SrcSpatial_p->DirAtten, SrcSpatial_p->Front_p_fx, ListRelPosAbs, 9 /*exp: 31 - 22 = 9 */ ); + *SrcRend_p->DirGain_p_fx = TDREND_SRC_SPATIAL_GetDirGain_fx( &SrcSpatial_p->DirAtten, SrcSpatial_p->Front_p_fx, ListRelPosAbs, sub( 31, pos_q ) ); #else *SrcRend_p->DirGain_p_fx = TDREND_SRC_SPATIAL_GetDirGain_fx( &SrcSpatial_p->DirAtten, SrcSpatial_p->Front_p_fx, ListRelPosAbs, 6 ); #endif @@ -493,22 +476,16 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( set32_fx( hrf_left, 0, *filterlength ); set32_fx( hrf_right, 0, *filterlength ); #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - hrf_left[0] = L_shr( L_add( SrcSpatial_p->Pos_p_fx[1], ONE_IN_Q22 ), 1 ); // Q22 - move32(); - hrf_right[0] = L_sub( ONE_IN_Q22, hrf_left[0] ); // Q22 - move32(); - hrf_left_e = 9; - move16(); - hrf_right_e = 9; + hrf_left[0] = L_shr( L_add( L_shl( SrcSpatial_p->Pos_p_fx[1], sub( Q25, SrcSpatial_p->q_Pos_p ) ), ONE_IN_Q25 ), 1 ); // Q25 #else hrf_left[0] = L_shr( L_add( SrcSpatial_p->Pos_p_fx[1], ONE_IN_Q25 ), 1 ); // Q25 +#endif move32(); hrf_right[0] = L_sub( ONE_IN_Q25, hrf_left[0] ); // Q25 move32(); hrf_left_e = 6; move16(); hrf_right_e = 6; -#endif move16(); *intp_count = MAX_INTERPOLATION_STEPS; // Q22 move16(); diff --git a/lib_rend/ivas_objectRenderer_vec_fx.c b/lib_rend/ivas_objectRenderer_vec_fx.c index 81268e578e1e80b59cd60df7d4f8340bb432cc89..6f01adcd633048918926426b66d36274a71b88cb 100644 --- a/lib_rend/ivas_objectRenderer_vec_fx.c +++ b/lib_rend/ivas_objectRenderer_vec_fx.c @@ -77,8 +77,13 @@ Word32 TDREND_SPATIAL_VecNorm_fx( { Word32 tmp; Word16 tmp_e; +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + tmp = L_add( L_add( Mpy_32_32( L_shr( Vec_p[0], 1 ), Vec_p[0] ), Mpy_32_32( L_shr( Vec_p[1], 1 ), Vec_p[1] ) ), Mpy_32_32( L_shr( Vec_p[2], 1 ), Vec_p[2] ) ); + tmp_e = add( shl( in_exp, 1 ), 1 ); // 2 * in_exp + 1 +#else tmp = L_add( L_add( Mpy_32_32( Vec_p[0], Vec_p[0] ), Mpy_32_32( Vec_p[1], Vec_p[1] ) ), Mpy_32_32( Vec_p[2], Vec_p[2] ) ); tmp_e = shl( in_exp, 1 ); // 2 * in_exp +#endif tmp = Sqrt32( tmp, &tmp_e ); *out_exp = tmp_e; move16(); @@ -96,8 +101,13 @@ void TDREND_SPATIAL_VecNormalize_fx( Word32 sqrd_sum; Word16 exp, shift; +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + sqrd_sum = L_add( Mpy_32_32( L_shr( Vec_p_fx[0], 1 ), Vec_p_fx[0] ), L_add( Mpy_32_32( L_shr( Vec_p_fx[1], 1 ), Vec_p_fx[1] ), Mpy_32_32( L_shr( Vec_p_fx[2], 1 ), Vec_p_fx[2] ) ) ); + exp = add( shl( sub( 31, q ), 1 ), 1 ); +#else sqrd_sum = L_add( Mpy_32_32( Vec_p_fx[0], Vec_p_fx[0] ), L_add( Mpy_32_32( Vec_p_fx[1], Vec_p_fx[1] ), Mpy_32_32( Vec_p_fx[2], Vec_p_fx[2] ) ) ); exp = shl( sub( 31, q ), 1 ); +#endif scaler_fx = ISqrt32( sqrd_sum, &exp ); VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); // Q: ( q + ( 31 - exp ) ) - 31 diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index f2d1e48752a602c791f578849e517b743aec9212..9c5b31de0d6b7caa0d9382915f9f09d85f62ed2a 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1225,7 +1225,7 @@ typedef struct Word16 Updated; TDREND_PosType_t PosType; #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION - Word32 Pos_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q22 + Word32 Pos_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q q_Pos_p #else Word32 Pos_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q25 #endif diff --git a/lib_util/float_to_fix_ops.c b/lib_util/float_to_fix_ops.c index 4bab0a6b1d9a7b8012257c039f374a6757ab5314..4e020fc9c5a37bb8cec730685276e8947e9b7bbf 100644 --- a/lib_util/float_to_fix_ops.c +++ b/lib_util/float_to_fix_ops.c @@ -127,3 +127,19 @@ Word32 floatToFixed_32( return (Word32) val; } + + +Word16 float_to_fix_find_q( + const float val ) +{ + Word16 bits; + float absVal; + + absVal = fabsf( val ); + if ( absVal < 1e-10f ) + { + return Q31; + } + bits = (Word16) floorf( log2f( absVal ) ) + 1; + return (Word16) ( 31 - bits ); +} diff --git a/lib_util/float_to_fix_ops.h b/lib_util/float_to_fix_ops.h index 0cd23cbc687c24b8026a754c0acbd320a466c14f..be23e5a164d6f07a4c1519ba9a5d267a49129a4a 100644 --- a/lib_util/float_to_fix_ops.h +++ b/lib_util/float_to_fix_ops.h @@ -16,4 +16,6 @@ float fixedToFloat( const Word32 i, const Word16 Q ); float fix16_to_float( const Word16 number, const Word16 Q ); +Word16 float_to_fix_find_q( const float val ); + #endif /* FLOAT_TO_FIX_OPS_H */ diff --git a/lib_util/rotation_file_reader.c b/lib_util/rotation_file_reader.c index 2652fde9172540a6c809531aa8530ca3765cb878..5fa236a7fd2edaef7224015a88b4f630bf7608fa 100644 --- a/lib_util/rotation_file_reader.c +++ b/lib_util/rotation_file_reader.c @@ -33,6 +33,7 @@ #include "rotation_file_reader.h" #include #include +#include #include "float_to_fix_ops.h" @@ -115,6 +116,9 @@ ivas_error HeadRotationFileReading( { float w, x, y, z; float posx, posy, posz; +#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION + float maxAbsPos; +#endif int32_t read_values; posx = 0.0f; @@ -159,10 +163,13 @@ ivas_error HeadRotationFileReading( pPos->x = min( max( -IVAS_LISTENER_POSITION_MAX, posx ), IVAS_LISTENER_POSITION_MAX ); pPos->y = min( max( -IVAS_LISTENER_POSITION_MAX, posy ), IVAS_LISTENER_POSITION_MAX ); pPos->z = min( max( -IVAS_LISTENER_POSITION_MAX, posz ), IVAS_LISTENER_POSITION_MAX ); - pPos->x_fx = floatToFixed_32( pPos->x, Q22 ); - pPos->y_fx = floatToFixed_32( pPos->y, Q22 ); - pPos->z_fx = floatToFixed_32( pPos->z, Q22 ); - pPos->q_fact = Q22; + + maxAbsPos = max( max( fabsf( pPos->x ), fabsf( pPos->y ) ), fabsf( pPos->z ) ); + pPos->q_fact = float_to_fix_find_q( maxAbsPos ); + + pPos->x_fx = floatToFixed_32( pPos->x, pPos->q_fact ); + pPos->y_fx = floatToFixed_32( pPos->y, pPos->q_fact ); + pPos->z_fx = floatToFixed_32( pPos->z, pPos->q_fact ); #else pPos->x = posx; pPos->y = posy;