Commit b8937cfb authored by multrus's avatar multrus
Browse files

[cleanup] accept FIX_198_TDREND_INTERFACE

parent 6c6b42d5
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -150,7 +150,6 @@

#define FIX_329_ENABLE_TD_RENDERER_REVERB_MC            /* Eri: Enable reverb for TD renderer for 5.1 and 7.1 with headtracking enabled for IVAS_dec */

#define FIX_198_TDREND_INTERFACE                        /* Issue 198: Harmonize interface for TD renderer between decoder and external renderer */

#define DFT_STEREO_SPAR_MIXING
#ifdef DFT_STEREO_SPAR_MIXING
+0 −191
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@
#include "wmc_auto.h"


#ifdef FIX_198_TDREND_INTERFACE

/*---------------------------------------------------------------------*
 * ivas_td_binaural_open()
@@ -59,141 +58,6 @@ ivas_error ivas_td_binaural_open(
                                         st_ivas->transport_config, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns );
}

#else

/*---------------------------------------------------------------------*
 * ivas_td_binaural_open()
 *
 * Open and initialize TD Object binaural renderer
 *---------------------------------------------------------------------*/

ivas_error ivas_td_binaural_open(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
)
{
    BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd;
    TDREND_PosType_t PosType;
    int16_t nS;
    int16_t SrcInd[MAX_NUM_TDREND_CHANNELS];
    const float *ls_azimuth, *ls_elevation;
    float Pos[3];
    float Dir[3];
    TDREND_DirAtten_t *DirAtten_p;
    int16_t nchan_rend;
    ivas_error error;

    error = IVAS_ERR_OK;

    if ( ( hBinRendererTd = malloc( sizeof( BINAURAL_TD_OBJECT_RENDERER ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }
    if ( ( hBinRendererTd->TdRend_MixSpatSpec_p = malloc( sizeof( TDREND_MixSpatSpec_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }
    if ( ( hBinRendererTd->DirAtten_p = malloc( sizeof( TDREND_DirAtten_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }
    if ( ( hBinRendererTd->Listener_p = malloc( sizeof( TDREND_MIX_Listener_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }

    hBinRendererTd->NumOfSrcs = 0;
    hBinRendererTd->MaxSrcInd = -1;

    /* Mixer spatial setup */
    hBinRendererTd->TdRend_MixSpatSpec_p->UseCommonDistAttenModel = TRUE;
    hBinRendererTd->TdRend_MixSpatSpec_p->DistAttenModel = 0; /* 0=Turned off, else use TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED */

    TDREND_MIX_Init( hBinRendererTd, &st_ivas->hHrtfTD, hBinRendererTd->TdRend_MixSpatSpec_p, st_ivas->hDecoderConfig->output_Fs );

    /* Set the attenuation (or can set MixSpatSpec.DistAttenModel above) */
    TDREND_MIX_SetDistAttenModel( hBinRendererTd, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED );

    /* Add sources to module and mixer, headphones */
    PosType = TDREND_POSTYPE_ABSOLUTE; /* or TDREND_POSTYPE_RELATIVE_TO_LISTENER */

    nchan_rend = st_ivas->nchan_transport;
    if ( st_ivas->ivas_format == MC_FORMAT )
    {
        nchan_rend--; /* Skip LFE channel -- added to the others */
    }

    for ( nS = 0; nS < nchan_rend; nS++ )
    {
        if ( ( error = TDREND_MIX_AddSrc( hBinRendererTd, &SrcInd[nS], PosType ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }

    if ( st_ivas->ivas_format == MC_FORMAT )
    {
        switch ( st_ivas->transport_config )
        {
            case AUDIO_CONFIG_5_1:
                ls_azimuth = ls_azimuth_CICP6;
                ls_elevation = ls_elevation_CICP6;
                break;
            case AUDIO_CONFIG_7_1:
                ls_azimuth = ls_azimuth_CICP12;
                ls_elevation = ls_elevation_CICP12;
                break;
            case AUDIO_CONFIG_5_1_2:
                ls_azimuth = ls_azimuth_CICP14;
                ls_elevation = ls_elevation_CICP14;
                break;
            case AUDIO_CONFIG_5_1_4:
                ls_azimuth = ls_azimuth_CICP16;
                ls_elevation = ls_elevation_CICP16;
                break;
            case AUDIO_CONFIG_7_1_4:
                ls_azimuth = ls_azimuth_CICP19;
                ls_elevation = ls_elevation_CICP19;
                break;
            case AUDIO_CONFIG_LS_CUSTOM:
                ls_azimuth = st_ivas->hTransSetup.ls_azimuth;
                ls_elevation = st_ivas->hTransSetup.ls_elevation;
                break;
            default:
                ls_azimuth = NULL;
                ls_elevation = NULL;
        }

        DirAtten_p = hBinRendererTd->DirAtten_p;

        for ( nS = 0; nS < nchan_rend; nS++ )
        {
            /* Set source positions according to loudspeaker layout */
            Pos[0] = cosf( ls_elevation[nS] * PI_OVER_180 ) * cosf( ls_azimuth[nS] * PI_OVER_180 );
            Pos[1] = cosf( ls_elevation[nS] * PI_OVER_180 ) * sinf( ls_azimuth[nS] * PI_OVER_180 );
            Pos[2] = sinf( ls_elevation[nS] * 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( hBinRendererTd, nS, Pos );
            TDREND_MIX_SRC_SetDir( hBinRendererTd, nS, Dir );
            TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING );
            TDREND_MIX_SRC_SetDirAtten( hBinRendererTd, nS, DirAtten_p );
        }
    }

    st_ivas->hBinRendererTd = hBinRendererTd;

    st_ivas->binaural_latency_ns = (int32_t) ( hBinRendererTd->HrFiltSet_p->latency_s * 1000000000.f );

    return error;
}
#endif


/*---------------------------------------------------------------------*
@@ -209,7 +73,6 @@ void ivas_td_binaural_renderer(
    const int16_t output_frame  /* i  : output frame length               */
)
{
#ifdef FIX_198_TDREND_INTERFACE
    ivas_td_binaural_renderer_unwrap( st_ivas->hRenderConfig, st_ivas->ini_frame,
#ifdef FIX_197_CREND_INTERFACE
                                      st_ivas->hCrendWrapper,
@@ -219,58 +82,4 @@ void ivas_td_binaural_renderer(
                                      st_ivas->transport_config,
                                      st_ivas->hDecoderConfig->output_Fs, 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 );
#else
    int16_t subframe_length;
    int16_t subframe_idx;
    float reverb_signal[BINAURAL_CHANNELS][L_FRAME48k];

    subframe_length = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES;
    if ( st_ivas->hRenderConfig != NULL ) /* Renderer Configuration not enabled in TD standalone renderer */
    {

        if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on && ( st_ivas->ini_frame == 0 ) )
        {
#ifdef FIX_197_CREND_INTERFACE
            ivas_reverb_open( &st_ivas->hCrendWrapper->hCrend->hReverb, st_ivas->transport_config, NULL, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs );
#else
            ivas_reverb_open( &st_ivas->hCrend->hReverb, st_ivas->transport_config, NULL, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs );
#endif
        }
    }

    /* Update object position(s) */
    TDREND_Update_object_positions( st_ivas->hBinRendererTd, st_ivas->nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, st_ivas->hIsmMetaData, 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->hBinRendererTd,
                                            st_ivas->hDecoderConfig->Opt_Headrotation,
                                            ( st_ivas->hHeadTrackData != NULL ) ? &st_ivas->hHeadTrackData->Quaternions[subframe_idx] : NULL );

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

        /* Render subframe */
        TDREND_GetMix( st_ivas->hBinRendererTd, output, subframe_length, subframe_idx );
    }

    if ( st_ivas->hRenderConfig != NULL ) /* Renderer Configuration not enabled in TD standalone renderer */
    {
        if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on )
        {
            /* add reverb to rendered signals */
            v_add( reverb_signal[0], output[0], output[0], output_frame );
            v_add( reverb_signal[1], output[1], output[1], output_frame );
        }
    }

    return;
#endif
}
+0 −372

File changed.

Preview size limit exceeded, changes collapsed.

+0 −4
Original line number Diff line number Diff line
@@ -215,7 +215,6 @@ void ivas_HRTF_CRend_binary_close(
 * TD object renderer
 *----------------------------------------------------------------------------------*/

#ifdef FIX_198_TDREND_INTERFACE
void ivas_td_binaural_renderer_unwrap(
    RENDER_CONFIG_DATA *hRenderConfig,                          /* i  : Renderer configuration                  */
    const int16_t ini_frame,                                    /* i  : Initialization frame counter            */
@@ -236,7 +235,6 @@ void ivas_td_binaural_renderer_unwrap(
    float output[][L_FRAME48k],                                 /* i/o: SCE channels / Binaural synthesis       */
    const int16_t output_frame                                  /* i  : output frame length                     */
);
#endif

ivas_error ivas_td_binaural_renderer_ext(
    const TDREND_WRAPPER *pTDRend,                              /* i  : TD Renderer wrapper structure           */
@@ -248,7 +246,6 @@ ivas_error ivas_td_binaural_renderer_ext(
    float output[][L_FRAME48k]                                  /* i/o: SCE channels / Binaural synthesis       */
);

#ifdef FIX_198_TDREND_INTERFACE
ivas_error ivas_td_binaural_open_unwrap(
    TDREND_HRFILT_FiltSet_t **hHrtfTD,                          /* i/o: HR filter model (from file or NULL)     */
    const int32_t output_Fs,                                    /* i  : Output sampling rate                    */
@@ -259,7 +256,6 @@ ivas_error ivas_td_binaural_open_unwrap(
    BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd,         /* o  : TD renderer handle                      */
    int32_t *binaural_latency_ns                                /* i  : Binauralization delay                   */
);
#endif

ivas_error ivas_td_binaural_open_ext(
    TDREND_WRAPPER *pTDRend,