Commit 0819a635 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'quaternion_funcs_fxd_point_changes' into 'main'

Quaternion and vector functions simplified fixed implementation

See merge request !291
parents d16a2c90 8fdad991
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ typedef struct
    float w, x, y, z;
#ifdef IVAS_FLOAT_FIXED
    Word32 w_fx, x_fx, y_fx, z_fx;
    Word16 w_qfact, x_qfact, y_qfact, z_qfact;
    Word16 q_fact;
#endif

} IVAS_QUATERNION;
@@ -145,7 +145,7 @@ typedef struct
    float x, y, z;
#ifdef IVAS_FLOAT_FIXED
    Word32 x_fx, y_fx, z_fx;
    Word16 x_qfact, y_qfact, z_qfact;
    Word16 q_fact;
#endif
} IVAS_VECTOR3;

+4 −36
Original line number Diff line number Diff line
@@ -269,45 +269,13 @@ ivas_error ivas_td_binaural_renderer_sf_fx(
            tmp_vector_fx = &st_ivas->hCombinedOrientationData->listenerPos[st_ivas->hCombinedOrientationData->subframe_idx];
            enableCombinedOrientation = st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx];

            /* Shifting w_fx, x_fx, y_fx, z_fx to a common Q-factor if they are not having the same Q-factor */
            Word16 min_q;
            IF( !( EQ_16( tmp_Quaternion_fx->w_qfact, tmp_Quaternion_fx->x_qfact ) && EQ_16( tmp_Quaternion_fx->x_qfact, tmp_Quaternion_fx->y_qfact ) && EQ_16( tmp_Quaternion_fx->y_qfact, tmp_Quaternion_fx->z_qfact ) ) )
            {
                min_q = MAX16B;
                move16();
                min_q = s_min( min_q, tmp_Quaternion_fx->w_qfact );
                min_q = s_min( min_q, tmp_Quaternion_fx->x_qfact );
                min_q = s_min( min_q, tmp_Quaternion_fx->y_qfact );
                min_q = s_min( min_q, tmp_Quaternion_fx->z_qfact );
                tmp_Quaternion_fx->w_fx = L_shr( tmp_Quaternion_fx->w_fx, sub( tmp_Quaternion_fx->w_qfact, min_q ) );
                tmp_Quaternion_fx->x_fx = L_shr( tmp_Quaternion_fx->x_fx, sub( tmp_Quaternion_fx->x_qfact, min_q ) );
                tmp_Quaternion_fx->y_fx = L_shr( tmp_Quaternion_fx->y_fx, sub( tmp_Quaternion_fx->y_qfact, min_q ) );
                tmp_Quaternion_fx->z_fx = L_shr( tmp_Quaternion_fx->z_fx, sub( tmp_Quaternion_fx->z_qfact, min_q ) );
                tmp_Quaternion_fx->w_qfact = min_q;
                move16();
                tmp_Quaternion_fx->x_qfact = min_q;
                move16();
                tmp_Quaternion_fx->y_qfact = min_q;
                move16();
                tmp_Quaternion_fx->z_qfact = min_q;
                move16();
            }

            /* Shifting x_fx, y_fx, z_fx to the same Q-factor as Listener_p->Pos_q (usually Q25) */
            Word16 pos_q = st_ivas->hBinRendererTd->Listener_p->Pos_q;
            move16();
            IF( NE_16( tmp_vector_fx->x_qfact, pos_q ) || NE_16( tmp_vector_fx->z_qfact, pos_q ) || NE_16( tmp_vector_fx->y_qfact, pos_q ) )
            {
                tmp_vector_fx->x_fx = L_shr( tmp_vector_fx->x_fx, sub( tmp_vector_fx->x_qfact, pos_q ) );
                tmp_vector_fx->y_fx = L_shr( tmp_vector_fx->y_fx, sub( tmp_vector_fx->y_qfact, pos_q ) );
                tmp_vector_fx->z_fx = L_shr( tmp_vector_fx->z_fx, sub( tmp_vector_fx->z_qfact, pos_q ) );
                tmp_vector_fx->x_qfact = pos_q;
                move16();
                tmp_vector_fx->y_qfact = pos_q;
                move16();
                tmp_vector_fx->z_qfact = pos_q;
                move16();
            }
                tmp_vector_fx->x_fx = L_shr( tmp_vector_fx->x_fx, sub( tmp_vector_fx->q_fact, pos_q ) );
                tmp_vector_fx->y_fx = L_shr( tmp_vector_fx->y_fx, sub( tmp_vector_fx->q_fact, pos_q ) );
                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;
        }
        ELSE
        {
+5 −0
Original line number Diff line number Diff line
@@ -496,8 +496,13 @@ ivas_error IVAS_DEC_FeedRefRotData(
/*! r: error code */
ivas_error IVAS_DEC_FeedRefVectorData(
  IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
#ifndef IVAS_FLOAT_FIXED 
  const IVAS_VECTOR3 listenerPos,             /* i  : Listener position                                                       */
  const IVAS_VECTOR3 refPos                   /* i  : Reference position                                                      */
#else
  IVAS_VECTOR3 listenerPos,             /* i  : Listener position                                                       */
  IVAS_VECTOR3 refPos                   /* i  : Reference position                                                      */
#endif
);

/*! r: error code */
+29 −27
Original line number Diff line number Diff line
@@ -1472,9 +1472,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData(
    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;
    hHeadTrackData->Pos[subframe_idx].x_qfact = Pos.x_qfact;
    hHeadTrackData->Pos[subframe_idx].y_qfact = Pos.y_qfact;
    hHeadTrackData->Pos[subframe_idx].z_qfact = Pos.z_qfact;
    hHeadTrackData->Pos[subframe_idx].q_fact = Pos.q_fact;
#endif

    hIvasDec->updateOrientation = true;
@@ -1524,8 +1522,13 @@ ivas_error IVAS_DEC_FeedRefRotData(

ivas_error IVAS_DEC_FeedRefVectorData(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle     */
#ifndef IVAS_FLOAT_FIXED
    const IVAS_VECTOR3 listenerPos, /* i  : Listener position       */
    const IVAS_VECTOR3 refPos       /* i  : Reference position      */
#else
    IVAS_VECTOR3 listenerPos, /* i  : Listener position       */
    IVAS_VECTOR3 refPos       /* i  : Reference position      */
#endif
)
{
    ivas_orient_trk_state_t *pOtr;
@@ -1540,20 +1543,19 @@ ivas_error IVAS_DEC_FeedRefVectorData(
    hIvasDec->updateOrientation = true;

#ifdef IVAS_FLOAT_FIXED
    IVAS_VECTOR3 listenerPos_fx, refPos_fx;
    listenerPos_fx.x_qfact = listenerPos_fx.y_qfact = listenerPos_fx.z_qfact = Q27;
    refPos_fx.x_qfact = refPos_fx.y_qfact = refPos_fx.z_qfact = Q27;
    listenerPos_fx.x_fx = float_to_fix( listenerPos.x, listenerPos_fx.x_qfact );
    listenerPos_fx.y_fx = float_to_fix( listenerPos.y, listenerPos_fx.y_qfact );
    listenerPos_fx.z_fx = float_to_fix( listenerPos.z, listenerPos_fx.z_qfact );
    refPos_fx.x_fx = float_to_fix( refPos.x, refPos_fx.x_qfact );
    refPos_fx.y_fx = float_to_fix( refPos.y, refPos_fx.y_qfact );
    refPos_fx.z_fx = float_to_fix( refPos.z, refPos_fx.z_qfact );
    ivas_error error_fx = ivas_orient_trk_SetReferenceVector_fx(pOtr, listenerPos_fx, refPos_fx );
    pOtr->refRot.w = me2f(pOtr->refRot.w_fx, 31- pOtr->refRot.w_qfact );
    pOtr->refRot.x = me2f(pOtr->refRot.x_fx, 31 - pOtr->refRot.x_qfact );
    pOtr->refRot.y = me2f(pOtr->refRot.y_fx, 31- pOtr->refRot.y_qfact );
    pOtr->refRot.z = me2f(pOtr->refRot.z_fx, 31 - pOtr->refRot.z_qfact );
    listenerPos.q_fact = Q27;
    refPos.q_fact = Q27;
    listenerPos.x_fx = float_to_fix( listenerPos.x, listenerPos.q_fact );
    listenerPos.y_fx = float_to_fix( listenerPos.y, listenerPos.q_fact );
    listenerPos.z_fx = float_to_fix( listenerPos.z, listenerPos.q_fact );
    refPos.x_fx = float_to_fix( refPos.x, refPos.q_fact );
    refPos.y_fx = float_to_fix( refPos.y, refPos.q_fact );
    refPos.z_fx = float_to_fix( refPos.z, refPos.q_fact );
    ivas_error error_fx = ivas_orient_trk_SetReferenceVector_fx( pOtr, listenerPos, refPos );
    pOtr->refRot.w = me2f( pOtr->refRot.w_fx, 31 - pOtr->refRot.q_fact );
    pOtr->refRot.x = me2f( pOtr->refRot.x_fx, 31 - pOtr->refRot.q_fact );
    pOtr->refRot.y = me2f( pOtr->refRot.y_fx, 31 - pOtr->refRot.q_fact );
    pOtr->refRot.z = me2f( pOtr->refRot.z_fx, 31 - pOtr->refRot.q_fact );
    return error_fx;
#else
    return ivas_orient_trk_SetReferenceVector( pOtr, listenerPos, refPos );
@@ -1593,21 +1595,21 @@ ivas_error IVAS_DEC_FeedExternalOrientationData(

#ifdef IVAS_FLOAT_FIXED
    IVAS_QUATERNION orientation_fx = { 0 };
    orientation_fx.w_qfact = orientation_fx.x_qfact = orientation_fx.y_qfact = orientation_fx.z_qfact = Q29;
    orientation_fx.w_fx = float_to_fix(orientation.w, orientation_fx.w_qfact);
    orientation_fx.x_fx = float_to_fix(orientation.x, orientation_fx.x_qfact);
    orientation_fx.y_fx = float_to_fix(orientation.y, orientation_fx.y_qfact);
    orientation_fx.z_fx = float_to_fix(orientation.z, orientation_fx.z_qfact);
    orientation_fx.q_fact = Q29;
    orientation_fx.w_fx = float_to_fix(orientation.w, orientation_fx.q_fact);
    orientation_fx.x_fx = float_to_fix(orientation.x, orientation_fx.q_fact);
    orientation_fx.y_fx = float_to_fix(orientation.y, orientation_fx.q_fact);
    orientation_fx.z_fx = float_to_fix(orientation.z, orientation_fx.q_fact);
    /* Move external orientation data to the decoder handle (invert orientations) */
    QuaternionInverse_fx(orientation_fx, &hExternalOrientationData->Quaternions[subframe_idx]);
    hExternalOrientationData->Quaternions[subframe_idx].w = me2f(hExternalOrientationData->Quaternions[subframe_idx].w_fx,
      31 - hExternalOrientationData->Quaternions[subframe_idx].w_qfact);
      31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact);
    hExternalOrientationData->Quaternions[subframe_idx].x = me2f(hExternalOrientationData->Quaternions[subframe_idx].x_fx,
      31 - hExternalOrientationData->Quaternions[subframe_idx].x_qfact);
      31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact);
    hExternalOrientationData->Quaternions[subframe_idx].y = me2f(hExternalOrientationData->Quaternions[subframe_idx].y_fx,
      31 - hExternalOrientationData->Quaternions[subframe_idx].y_qfact);
      31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact);
    hExternalOrientationData->Quaternions[subframe_idx].z = me2f(hExternalOrientationData->Quaternions[subframe_idx].z_fx,
      31 - hExternalOrientationData->Quaternions[subframe_idx].z_qfact);
      31 - hExternalOrientationData->Quaternions[subframe_idx].q_fact);
#else
    /* Move external orientation data to the decoder handle (invert orientations) */
    QuaternionInverse( orientation, &hExternalOrientationData->Quaternions[subframe_idx] );
+3 −10
Original line number Diff line number Diff line
@@ -649,13 +649,13 @@ ivas_error ivas_td_binaural_renderer_unwrap(
        tmp_Quaternions->x_fx = float_to_fix(tmp_Quaternions->x, quat_q);
        tmp_Quaternions->y_fx = float_to_fix(tmp_Quaternions->y, quat_q);
        tmp_Quaternions->z_fx = float_to_fix(tmp_Quaternions->z, quat_q);
        tmp_Quaternions->w_qfact = tmp_Quaternions->x_qfact = tmp_Quaternions->y_qfact = tmp_Quaternions->z_qfact = quat_q;
        tmp_Quaternions->q_fact = quat_q;

        Word16 pos_q = Q25;
        tmp_Pos->x_fx = (Word32)float_to_fix(tmp_Pos->x, pos_q);
        tmp_Pos->y_fx = (Word32)float_to_fix(tmp_Pos->y, pos_q);
        tmp_Pos->z_fx = (Word32)float_to_fix(tmp_Pos->z, pos_q);
        tmp_Pos->x_qfact = tmp_Pos->y_qfact = tmp_Pos->z_qfact = pos_q;
        tmp_Pos->q_fact= pos_q;
        for (int i = 0; i < 3; i++)
        {
            hBinRendererTd->Listener_p->Front_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Front[i], Q30);
@@ -1218,10 +1218,7 @@ ivas_error TDREND_Update_listener_orientation_fx(
    {
        Word16 Rmat_q;

        assert(headPosition_fx->w_qfact == headPosition_fx->x_qfact
            && headPosition_fx->x_qfact == headPosition_fx->y_qfact
            && headPosition_fx->y_qfact == headPosition_fx->z_qfact);
        headPosition_q = headPosition_fx->w_qfact;  // Assuming Q is same for w, x, y and z
        headPosition_q = headPosition_fx->q_fact;
        move16();

        /* Obtain head rotation matrix */
@@ -1242,10 +1239,6 @@ ivas_error TDREND_Update_listener_orientation_fx(

        IF ( Pos_fx != NULL )
        {
            // Assuming Q is same for x, y and z
            assert((*Pos_fx).x_qfact == (*Pos_fx).y_qfact && (*Pos_fx).y_qfact == (*Pos_fx).z_qfact );
            assert((*Pos_fx).x_qfact == hBinRendererTd->Listener_p->Pos_q );

            /* Input position   */
            Pos_p_fx[0] = ( *Pos_fx ).x_fx;
            Pos_p_fx[1] = ( *Pos_fx ).y_fx;
Loading