Commit 0951f0b9 authored by Jan Kiene's avatar Jan Kiene
Browse files

Merge branch 'main' into...

Merge branch 'main' into 27-tcx-plc-fadeout-to-noise-for-long-frameloss-periods-not-working-correctly-185
parents 87f2f9eb d3f28017
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -840,6 +840,9 @@ typedef enum {
 *----------------------------------------------------------------------------------*/
// VE: this should be renamed to e.g. N_SPATIAL_SUBFRAMES
#define MAX_PARAM_SPATIAL_SUBFRAMES             4                           /* Maximum number of subframes for parameteric spatial coding */
#ifdef FIX_I106_TDREND_5MS
#define L_SPATIAL_SUBFR_48k                     (L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES)
#endif


/*----------------------------------------------------------------------------------*
+13 −0
Original line number Diff line number Diff line
@@ -4947,12 +4947,21 @@ void TDREND_HRFILT_SetFiltSet(
#endif

ivas_error TDREND_REND_RenderSourceHRFilt(
#ifdef FIX_I106_TDREND_5MS
    TDREND_SRC_t *Src_p,                                         /* i/o: The source to be rendered               */
#else
    const TDREND_SRC_t *Src_p,                                  /* i/o: The source to be rendered               */
#endif
#ifdef TDREND_HRTF_TABLE_METHODS
    BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd,          /* i/o: TD renderer handle                      */
#endif
#ifdef FIX_I106_TDREND_5MS
    float output_buf[][L_SPATIAL_SUBFR_48k],                    /* o  : Output buffer                           */
    const int16_t subframe_length,                              /* i  : Subframe length in use                  */
#else
    float output_buf[][L_FRAME48k],                             /* o  : Output buffer                           */
    const int16_t output_frame,                                 /* i  : Output frame length in use              */
#endif
    const int32_t output_Fs                                     /* i  : Output sample rate                      */
);

@@ -5092,7 +5101,11 @@ void TDREND_SFX_SpatBin_SetParams(
void TDREND_SFX_SpatBin_Execute_Main(
    SFX_SpatBin_t *SfxSpatBin_p,                                /* i/o: Spatial parameters handle                  */
    const float *InBuffer_p,                                    /* i  : Input buffer                               */
#ifdef FIX_I106_TDREND_5MS
    const int16_t subframe_length,                                 /* i  : subframe length                            */
#else
    const int16_t output_frame,                                 /* i  : frame length                               */
#endif
    float *LeftOutBuffer_p,                                     /* o  : Rendered left channel                      */
    float *RightOutBuffer_p,                                    /* o  : Rendered right channel                     */
    int16_t *NoOfUsedInputSamples_p,                            /* o  : Number of input samples actually used      */
+4 −0
Original line number Diff line number Diff line
@@ -149,6 +149,8 @@

#define SPAR_SCALING_HARMONIZATION                      /* Issue 80: Changes to harmonize scaling in spar */
#define FIX_I98_HANDLES_TO_NULL                         /* Issue 98: do the setting of all handles to NULL in one place */
#define FIX_I106_TDREND_5MS                             /* Issue 106: 5 ms update rate in TD object renderer */
#define QUANTISE_REAL_FCN_CLEAN_UP                      /*Clean up the ivas_quantise_real_values() function*/

#define FIX_I74_BW_LIMITATION_ALT                       /* issue 74: Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band <BW>" and BW limited by bitrate; alternative fix */
#define FIX_I74_CLEANING                                /* issue 74: remove redundant function call in ivas_cpe_enc() */
@@ -157,6 +159,8 @@

#define ALIGN_SID_SIZE                                  /* Issue 111: make all DTX modes use one SID frame bitrate (5.2 kbps) */

#define FIX_135_MDCT_STEREO_MODE_UNINITIALIZED          /* Issue 135: fix uninitialized value usage in SBA MDCT-Stereo core with PLC */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
#endif
+6 −0
Original line number Diff line number Diff line
@@ -823,6 +823,12 @@ ivas_error create_cpe_dec(
        set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB );
        set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB );
        hCPE->hStereoMdct->lastCoh = 1.f;
#ifdef FIX_135_MDCT_STEREO_MODE_UNINITIALIZED
        hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO;
        hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO;
        hCPE->hStereoMdct->IGFStereoMode[0] = -1;
        hCPE->hStereoMdct->IGFStereoMode[1] = -1;
#endif
    }

    /*-----------------------------------------------------------------*
+203 −5
Original line number Diff line number Diff line
@@ -46,9 +46,16 @@
 * Local function prototypes
 *---------------------------------------------------------------------*/

#ifdef FIX_I106_TDREND_5MS
static ivas_error TDREND_GetMix( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, float output[][L_FRAME48k], const int16_t subframe_length, const int32_t output_Fs, const int16_t subframe_idx );
#else
static ivas_error TDREND_GetMix( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, float output[][L_FRAME48k], const int16_t output_frame, const int32_t output_Fs );
#endif
static void TDREND_Clear_Update_flags( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd );

#ifdef FIX_I106_TDREND_5MS
static void TDREND_Update_listener_orientation( Decoder_Struct *st_ivas, const int16_t subframe_idx );
static void TDREND_Update_object_positions( Decoder_Struct *st_ivas, float output[][L_FRAME48k] );
#endif

/*---------------------------------------------------------------------*
 * ivas_td_binaural_open()
@@ -220,6 +227,7 @@ void ObjRenderIVASFrame(
    const int16_t output_frame  /* i  : output frame length               */
)
{
#ifndef FIX_I106_TDREND_5MS
    TDREND_DirAtten_t *DirAtten_p;
    int16_t nS;
    float Pos[3];
@@ -228,9 +236,15 @@ void ObjRenderIVASFrame(
    float UpVec[3];
    float Rmat[3][3];
    int16_t c_indx;
#else
    int16_t subframe_length;
#endif
    int16_t subframe_idx;
    float reverb_signal[BINAURAL_CHANNELS][L_FRAME48k];

#ifdef FIX_I106_TDREND_5MS
    subframe_length = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES;
#else
    DirAtten_p = st_ivas->hBinRendererTd->DirAtten_p;

    /* Update the listener's location/orientation */
@@ -302,8 +316,16 @@ void ObjRenderIVASFrame(
            TDREND_MIX_SRC_SetPlayState( st_ivas->hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING );
        }
    }
#endif
    if ( st_ivas->hRenderConfig != NULL ) /* Renderer Configuration not enabled in TD standalone renderer */
    {

#ifdef FIX_I106_TDREND_5MS
        if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on && ( st_ivas->ini_frame == 0 ) )
        {
            ivas_reverb_open( &st_ivas->hCrend->hReverb, st_ivas->transport_config, NULL, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs );
        }
#else
        if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on )
        {
            if ( st_ivas->ini_frame == 0 )
@@ -315,10 +337,31 @@ void ObjRenderIVASFrame(
                ivas_reverb_process( st_ivas->hCrend->hReverb, st_ivas->transport_config, 0, output, reverb_signal, subframe_idx );
            }
        }
#endif
    }

#ifdef FIX_I106_TDREND_5MS
    /* Update object position(s) */
    TDREND_Update_object_positions( st_ivas, output );

    for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ )
    {
        /* Update the listener's location/orientation */
        TDREND_Update_listener_orientation( st_ivas, subframe_idx );

        if ( ( st_ivas->hRenderConfig != NULL ) && ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) )
        {
            ivas_reverb_process( st_ivas->hCrend->hReverb, st_ivas->transport_config, 0, output, reverb_signal, subframe_idx );
        }

        /* Render subframe */
        TDREND_GetMix( st_ivas->hBinRendererTd, output, subframe_length, st_ivas->hDecoderConfig->output_Fs, subframe_idx );
    }
#else
    /* Call the renderer */
    TDREND_GetMix( st_ivas->hBinRendererTd, output, output_frame, st_ivas->hDecoderConfig->output_Fs );
#endif

    if ( st_ivas->hRenderConfig != NULL ) /* Renderer Configuration not enabled in TD standalone renderer */
    {
        if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on )
@@ -333,17 +376,30 @@ void ObjRenderIVASFrame(
}


#ifdef FIX_I106_TDREND_5MS
/*---------------------------------------------------------------------*
 * TDREND_GetMix()
 *
 * Render one 5 ms subframe from the mixer
 *---------------------------------------------------------------------*/
#else
/*---------------------------------------------------------------------*
 * TDREND_GetMix()
 *
 * Render one output frame from the mixer
 *---------------------------------------------------------------------*/

#endif
static ivas_error TDREND_GetMix(
    BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */
    float output[][L_FRAME48k],                        /* i/o: ISm object synth / rendered output in 0,1 */
#ifdef FIX_I106_TDREND_5MS
    const int16_t subframe_length, /* i/o: subframe length                       */
    const int32_t output_Fs, /* i  : Output sampling rate                      */
    const int16_t subframe_idx /* i  : Subframe index to 5 ms subframe                      */
#else
    const int16_t output_frame,      /* i/o: Output frame length                       */
    const int32_t output_Fs /* i  : Output sampling rate                      */
#endif
)
{
    int16_t i;
@@ -351,13 +407,22 @@ static ivas_error TDREND_GetMix(
    TDREND_SRC_SPATIAL_t *SrcSpatial_p;
    TDREND_SRC_REND_t *SrcRend_p;
    ivas_error error;
#ifdef FIX_I106_TDREND_5MS
    float output_buf[2][L_SPATIAL_SUBFR_48k]; /* Temp buffer for left/right rendered signal */
#else
    float output_buf[2][L_FRAME48k]; /* Temp buffer for left/right rendered signal */

#endif
    error = IVAS_ERR_OK;

#ifdef FIX_I106_TDREND_5MS
    /* Clear the output buffer to accumulate rendered sources */
    set_f( output_buf[0], 0.0f, subframe_length );
    set_f( output_buf[1], 0.0f, subframe_length );
#else
    /* Zero out the output buffer since objects are accumulated.  */
    set_f( output_buf[0], 0.0f, output_frame );
    set_f( output_buf[1], 0.0f, output_frame );
#endif

    /* Create the mix */
    /* Loop through the source list and render each source */
@@ -376,20 +441,39 @@ static ivas_error TDREND_GetMix(
        /* Render source if needed */
        if ( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) )
        {
#ifdef FIX_I106_TDREND_5MS
#ifdef TDREND_HRTF_TABLE_METHODS
            error = TDREND_REND_RenderSourceHRFilt( Src_p, hBinRendererTd, output_buf, subframe_length, output_Fs );
#else
            error = TDREND_REND_RenderSourceHRFilt( Src_p, output_buf, subframe_length, output_Fs );
#endif
#else
#ifdef TDREND_HRTF_TABLE_METHODS
            error = TDREND_REND_RenderSourceHRFilt( Src_p, hBinRendererTd, output_buf, output_frame, output_Fs );
#else
            error = TDREND_REND_RenderSourceHRFilt( Src_p, output_buf, output_frame, output_Fs );
#endif
#endif
        }
#ifndef FIX_I106_TDREND_5MS
        SrcRend_p->InputAvailable = FALSE;
#endif
    }

    /* Populate output variable */
#ifdef FIX_I106_TDREND_5MS
    mvr2r( output_buf[0], output[0] + subframe_idx * subframe_length, subframe_length ); /* Left */
    mvr2r( output_buf[1], output[1] + subframe_idx * subframe_length, subframe_length ); /* Right */
#else
    mvr2r( output_buf[0], output[0], output_frame ); /* Left */
    mvr2r( output_buf[1], output[1], output_frame ); /* Right */
#endif

#ifdef FIX_I106_TDREND_5MS
    /* Clear the PoseUpdated and Source position update flags */
#else
    /* Clear the mixer update flags */
#endif
    TDREND_Clear_Update_flags( hBinRendererTd );

    return error;
@@ -417,3 +501,117 @@ static void TDREND_Clear_Update_flags(

    return;
}

#ifdef FIX_I106_TDREND_5MS
/*---------------------------------------------------------------------*
 * TDREND_Update_object_positions()
 *
 * Update object position(s)
 *---------------------------------------------------------------------*/

static void TDREND_Update_object_positions(
    Decoder_Struct *st_ivas,       /* i/o: IVAS decoder structure    */
    float output[][L_FRAME48k]     /* i/o: SCE/MC channels           */
)
{
    TDREND_DirAtten_t *DirAtten_p;
    int16_t nS;
    float Pos[3];
    float Dir[3];
    int16_t c_indx;

    DirAtten_p = st_ivas->hBinRendererTd->DirAtten_p;

    /* For each source, write the frame data to the source object*/
    c_indx = 0;
    for ( nS = 0; nS < st_ivas->nchan_transport; nS++ )
    {
        if ( !( st_ivas->ivas_format == MC_FORMAT && nS == LFE_CHANNEL ) ) /* Skip LFE for MC */
        {
            st_ivas->hBinRendererTd->Sources[c_indx]->InputFrame_p = output[nS];
            st_ivas->hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE;
            c_indx++;
        }

        if ( st_ivas->ivas_format == ISM_FORMAT )
        {

            /* Update the source positions */
            /* Source position and direction */
            Pos[0] = cosf( st_ivas->hIsmMetaData[nS]->elevation * PI_OVER_180 ) * cosf( st_ivas->hIsmMetaData[nS]->azimuth * PI_OVER_180 );
            Pos[1] = cosf( st_ivas->hIsmMetaData[nS]->elevation * PI_OVER_180 ) * sinf( st_ivas->hIsmMetaData[nS]->azimuth * PI_OVER_180 );
            Pos[2] = sinf( st_ivas->hIsmMetaData[nS]->elevation * PI_OVER_180 );
            Dir[0] = 1.0f;
            Dir[1] = 0.0f;
            Dir[2] = 0.0f;

            /* Source directivity info */
            DirAtten_p->ConeInnerAngle = 360.0f;
            DirAtten_p->ConeOuterAngle = 360.0f;
            DirAtten_p->ConeOuterGain = 1.0f;

            TDREND_MIX_SRC_SetPos( st_ivas->hBinRendererTd, nS, Pos );
            TDREND_MIX_SRC_SetDirAtten( st_ivas->hBinRendererTd, nS, DirAtten_p );
            TDREND_MIX_SRC_SetPlayState( st_ivas->hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING );
                        
            TDREND_MIX_SRC_SetDir( st_ivas->hBinRendererTd, nS, Dir );
        }
    }
    
    return;
}

/*---------------------------------------------------------------------*
 * TDREND_Update_listener_orientation()
 *
 * Update listener orientation (s)
 *---------------------------------------------------------------------*/

static void TDREND_Update_listener_orientation(
    Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure    */
    const int16_t subframe_idx     /*  i: subframe index*/
)
{
    float Pos[3];
    float FrontVec[3];
    float UpVec[3];
    float Rmat[3][3];

    /* Update the listener's location/orientation */
    /* Listener at the origin   */
    Pos[0] = 0.0f;
    Pos[1] = 0.0f;
    Pos[2] = 0.0f;

    if ( st_ivas->hHeadTrackData != NULL )
    {
        /* Obtain head rotation matrix */
        QuatToRotMat( st_ivas->hHeadTrackData->Quaternions[subframe_idx], Rmat );
        /* Apply rotation matrix to looking vector [1;0;0] */
        FrontVec[0] = Rmat[0][0];
        FrontVec[1] = Rmat[0][1];
        FrontVec[2] = Rmat[0][2];
        /* Apply rotation matrix to up vector [0;0;1] */
        UpVec[0] = Rmat[2][0];
        UpVec[1] = Rmat[2][1];
        UpVec[2] = Rmat[2][2];
    }
    else
    {
        /* Oriented with looking vector along the x axis */
        FrontVec[0] = 1.0f;
        FrontVec[1] = 0.0f;
        FrontVec[2] = 0.0f;
        /* Oriented with up vector along the z axis      */
        UpVec[0] = 0.0f;
        UpVec[1] = 0.0f;
        UpVec[2] = 1.0f;
    }

    /* Set the listener position and orientation:*/
    TDREND_MIX_LIST_SetPos( st_ivas->hBinRendererTd, Pos );
    TDREND_MIX_LIST_SetOrient( st_ivas->hBinRendererTd, FrontVec, UpVec );

    return;
}
#endif
Loading