Commit 025792cd authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[fix] bug for rendering with TD Object Renderer and switch to multiple instances of CREND

parent 67156800
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -724,7 +724,11 @@ void ObjRenderIvasFrame_splitBinaural(
    float tmpProcessing[MAX_NUM_OBJECTS][L_FRAME48k];
#endif
    float tmpBinaural[MAX_HEAD_ROT_POSES * 2][L_FRAME48k];
#ifdef SPLIT_REND_LC3PLUS_MC
    float *p_tmpProcessing[MAX_OUTPUT_CHANNELS];
#else
    float *p_tmpProcessing[MAX_NUM_OBJECTS];
#endif

    int16_t pos_idx;
    IVAS_QUATERNION originalHeadRot[MAX_PARAM_SPATIAL_SUBFRAMES];
@@ -798,7 +802,11 @@ void ObjRenderIvasFrame_splitBinaural(
                }
            }
        }
#ifdef SPLIT_REND_LC3PLUS_MC
        for ( i = 0; i < st_ivas->nchan_transport; ++i )
#else
        for ( i = 0; i < BINAURAL_CHANNELS; i++ )
#endif
        {
            p_tmpProcessing[i] = tmpProcessing[i];
        }
+58 −96
Original line number Diff line number Diff line
@@ -2290,7 +2290,11 @@ static ivas_error initMcBinauralRendering(
                                            NULL, outSampleRate
#ifdef SPLIT_REND_WITH_HEAD_ROT
                                            ,
#ifdef SPLIT_REND_LC3PLUS_MC
                                            ( ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) || ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_SPLIT_CLDFB ) ) ? inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1
#else
                                            1
#endif
#endif
                                            ) ) != IVAS_ERR_OK )
        {
@@ -6814,7 +6818,7 @@ static ivas_error renderMcToSplitBinaural(
    const IVAS_REND_AudioConfig outConfig,
    IVAS_REND_AudioBuffer outAudio )
{
    int16_t i, pos_idx;
    int16_t i, j, sf, pos_idx;
    int16_t output_frame;
    ivas_error error;
    const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData;
@@ -6824,9 +6828,8 @@ static ivas_error renderMcToSplitBinaural(
    float tmpSplitBinauralBuffer[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][L_FRAME48k];
    IVAS_REND_AudioConfig inConfig;
    IVAS_REND_AudioBuffer tmpRotBuffer;
    IVAS_QUATERNION originalHeadRot[MAX_PARAM_SPATIAL_SUBFRAMES];
    IVAS_REND_HeadRotData modifiedHeadRotData;
    const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData;
    COMBINED_ORIENTATION_DATA combinedOrientationDataLocal;
    COMBINED_ORIENTATION_HANDLE pCombinedOrientationDataLocal;

    push_wmops( "renderMcToSplitBinaural" );

@@ -6842,41 +6845,36 @@ static ivas_error renderMcToSplitBinaural(
    }

    /* save current head positions */
    for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; ++i )
    pCombinedOrientationDataLocal = *mcInput->base.ctx.pCombinedOrientationData;
    combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
    for ( sf = 1; sf < RENDERER_HEAD_POSITIONS_PER_FRAME; ++sf )
    {
        combinedOrientationDataLocal.Quaternions[sf] = combinedOrientationDataLocal.Quaternions[0];
        for ( i = 0; i < 3; i++ )
        {
        originalHeadRot[i] = mcInput->base.ctx.pHeadRotData->headPositions[i];
            for ( j = 0; j < 3; j++ )
            {
                combinedOrientationDataLocal.Rmat[sf][i][j] = combinedOrientationDataLocal.Rmat[0][i][j];
            }
        }
    }
    modifiedHeadRotData = *mcInput->base.ctx.pHeadRotData;


    for ( pos_idx = 0; pos_idx < pMultiBinPoseData->num_poses; pos_idx++ )
    {
        /* Update head positions */
        if ( pos_idx != 0 )
        {
            for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; ++i )
            {
                if ( originalHeadRot[i].w == -3.0f )
                {
                    modifiedHeadRotData.headPositions[i].w = -3.0f;
                    modifiedHeadRotData.headPositions[i].x = originalHeadRot[i].x + pMultiBinPoseData->relative_head_poses[pos_idx - 1][0];
                    modifiedHeadRotData.headPositions[i].y = originalHeadRot[i].y + pMultiBinPoseData->relative_head_poses[pos_idx - 1][1];
                    modifiedHeadRotData.headPositions[i].z = originalHeadRot[i].z + pMultiBinPoseData->relative_head_poses[pos_idx - 1][2];
                }
                else
        IVAS_QUATERNION Quaternions_orig[RENDERER_HEAD_POSITIONS_PER_FRAME], Quaternions_abs;
        for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; i++ )
        {
                    modifiedHeadRotData.headPositions[i].w = -3.0f;
                    Quat2EulerDegree( originalHeadRot[i],
                                      &modifiedHeadRotData.headPositions[i].z,
                                      &modifiedHeadRotData.headPositions[i].y,
                                      &modifiedHeadRotData.headPositions[i].x );
                    modifiedHeadRotData.headPositions[i].x += pMultiBinPoseData->relative_head_poses[pos_idx - 1][0];
                    modifiedHeadRotData.headPositions[i].y += pMultiBinPoseData->relative_head_poses[pos_idx - 1][1];
                    modifiedHeadRotData.headPositions[i].z += pMultiBinPoseData->relative_head_poses[pos_idx - 1][2];
                }
            Quaternions_orig[i] = combinedOrientationDataLocal.Quaternions[i];
            Quaternions_abs.w = -3.0f;
            Quat2EulerDegree( combinedOrientationDataLocal.Quaternions[i], &Quaternions_abs.z, &Quaternions_abs.y, &Quaternions_abs.x ); /*order in Quat2Euler seems to be reversed ?*/

                ( *mcInput->base.ctx.pCombinedOrientationData )->Quaternions[i] = modifiedHeadRotData.headPositions[i];
            }
            Quaternions_abs.x += pMultiBinPoseData->relative_head_poses[pos_idx][0];
            Quaternions_abs.y += pMultiBinPoseData->relative_head_poses[pos_idx][1];
            Quaternions_abs.z += pMultiBinPoseData->relative_head_poses[pos_idx][2];
            combinedOrientationDataLocal.Quaternions[i] = Quaternions_abs;
            QuatToRotMat( combinedOrientationDataLocal.Quaternions[i], combinedOrientationDataLocal.Rmat[i] );
        }

        if ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM || inConfig == IVAS_REND_AUDIO_CONFIG_5_1 || inConfig == IVAS_REND_AUDIO_CONFIG_7_1 )
@@ -6891,30 +6889,11 @@ static ivas_error renderMcToSplitBinaural(
            /* copy input to tdrend input/output buffer */
            copyBufferTo2dArray( mcInput->base.inputBuffer, tmpRendBuffer );

            /* set quaternions */
            hCombinedOrientationData = mcInput->base.ctx.pCombinedOrientationData;

            /* Render */
            if ( pos_idx == 0 )
            {
                if ( ( error = ivas_td_binaural_renderer_ext( &mcInput->tdRendWrapper,
                                                              mcInput->base.inConfig,
                                                              &mcInput->customLsInput,
                                                              hCombinedOrientationData,
                                                              NULL,
                                                              mcInput->hReverb,
                                                              mcInput->base.inputBuffer.config.numSamplesPerChannel,
                                                              tmpRendBuffer ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
            else
            {
            if ( ( error = ivas_td_binaural_renderer_ext( &mcInput->splitTdRendWrappers[pos_idx - 1],
                                                          mcInput->base.inConfig,
                                                          &mcInput->customLsInput,
                                                              hCombinedOrientationData,
                                                          &pCombinedOrientationDataLocal,
                                                          NULL,
                                                          mcInput->hReverb,
                                                          mcInput->base.inputBuffer.config.numSamplesPerChannel,
@@ -6922,7 +6901,6 @@ static ivas_error renderMcToSplitBinaural(
            {
                return error;
            }
            }

            /* Copy rendered audio to tmp storage buffer. Copying directly to output would
             * overwrite original audio, which is still needed for rendering next head pose. */
@@ -6942,36 +6920,23 @@ static ivas_error renderMcToSplitBinaural(
            tmpRotBuffer = mcInput->base.inputBuffer;
            tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) );

            /* copy input for in-place rotation */
            mvr2r( mcInput->base.inputBuffer.data, tmpRotBuffer.data,
                   tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel );

            /* perform rotation in source format to tmpRotBuffer */
            if ( pos_idx == 0 )
            {
            pCombinedOrientationDataLocal = &combinedOrientationDataLocal;
            if ( ( error = rotateFrameMc( mcInput->base.inputBuffer,
                                          mcInput->base.inConfig,
                                          mcInput->customLsInput,
                                          mcInput->base.ctx.pHeadRotData,
                                              mcInput->base.ctx.pCombinedOrientationData,
                                              mcInput->rot_gains_prev,
                                              mcInput->efapInWrapper.hEfap,
                                              tmpRotBuffer ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
            else
            {
                if ( ( error = rotateFrameMc( mcInput->base.inputBuffer,
                                              mcInput->base.inConfig,
                                              mcInput->customLsInput,
                                              &modifiedHeadRotData,
                                              mcInput->base.ctx.pCombinedOrientationData,
                                          &pCombinedOrientationDataLocal,
                                          mcInput->rot_gains_prev,
                                          mcInput->efapInWrapper.hEfap,
                                          tmpRotBuffer ) ) != IVAS_ERR_OK )
            {
                return error;
            }
            }

            copyBufferTo2dArray( tmpRotBuffer, tmpRendBuffer );

@@ -6984,12 +6949,8 @@ static ivas_error renderMcToSplitBinaural(
                                                   NULL,
                                                   NULL,
                                                   p_tmpRendBuffer,
                                                   *mcInput->base.ctx.pOutSampleRate
#ifdef SPLIT_REND_WITH_HEAD_ROT
                                                   ,
                                                   0
#endif
                                                   ) ) != IVAS_ERR_OK )
                                                   *mcInput->base.ctx.pOutSampleRate,
                                                   pos_idx ) ) != IVAS_ERR_OK )
            {
                return error;
            }
@@ -7001,6 +6962,12 @@ static ivas_error renderMcToSplitBinaural(

            free( tmpRotBuffer.data );
        }

        /* restore original headrotation data */
        for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; i++ )
        {
            combinedOrientationDataLocal.Quaternions[i] = Quaternions_orig[i];
        }
    }

    /* TODO tmu : needs delay compensation */
@@ -7011,11 +6978,6 @@ static ivas_error renderMcToSplitBinaural(

    accumulate2dArrayToBuffer( tmpSplitBinauralBuffer, &outAudio );

    /* restore original headrotation data */
    for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; ++i )
    {
        ( *mcInput->base.ctx.pCombinedOrientationData )->Quaternions[i] = originalHeadRot[i];
    }
    pop_wmops();

    return IVAS_ERR_OK;