Commit b6ed1a05 authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Implements HRTF binary support for parametric binauralizer.

parent a6584a7e
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -518,6 +518,15 @@ int main(
        {
            fprintf( stderr, "\nError in loading HRTF binary file %s for FastConv \n\n", arg.hrtfCRendFileName );
        }
#endif
#ifdef HRTF_BINARY_PARAM
        IVAS_DEC_HRTF_PARAMBIN_HANDLE hHrtfParambin;
        IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin );

        if ( ( error = load_parambin_HRTF_from_binary( hHrtfParambin, hrtfReader) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in loading HRTF binary file %s for parametric binauralizer \n\n", arg.hrtfCRendFileName );
        }
#endif
    }

+4 −0
Original line number Diff line number Diff line
@@ -100,6 +100,10 @@ typedef struct ivas_hrtfs_crend_structure *IVAS_DEC_HRTF_CREND_HANDLE;
typedef struct ivas_hrtfs_fastconv_struct *IVAS_DEC_HRTF_FASTCONV_HANDLE;
#endif

#ifdef HRTF_BINARY_PARAM
typedef struct ivas_hrtfs_parambin_struct *IVAS_DEC_HRTF_PARAMBIN_HANDLE;
#endif

#ifdef DEBUGGING
typedef enum
{
+29 −2
Original line number Diff line number Diff line
@@ -3253,14 +3253,27 @@ void ivas_dirac_dec(
    const int16_t i_sf
);

#ifdef HRTF_BINARY_PARAM
ivas_error ivas_dirac_dec_init_binaural_data(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                  */
    HRTFS_PARAMBIN_HANDLE hHrtfParambin                         /* i  : HRTF structure for rendering            */
);
#else
ivas_error ivas_dirac_dec_init_binaural_data(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                  */
);
#endif

void ivas_dirac_dec_close_binaural_data(
    DIRAC_DEC_BIN_HANDLE *hBinaural                             /* i/o: decoder DirAC binaural data handle      */
);

#ifdef HRTF_BINARY_PARAM
ivas_error ivas_dirac_dec_binaural_copy_hrtfs(
    HRTFS_PARAMBIN_HANDLE *hHrtfParambin                        /* i/o: HRTF structure for rendering            */
);
#endif

void ivas_dirac_dec_binaural(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                  */
    float output_f[][L_FRAME48k],                               /* i/o: synthesized core-coder transport channels/DirAC output  */
@@ -3279,6 +3292,10 @@ ivas_error ivas_binaural_reverb_open(
    ,
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv                   /* i  : FastConv HRTF handle                    */
#endif
#ifdef HRTF_BINARY_PARAM
    ,
    const HRTFS_PARAMBIN_HANDLE hHrtfParambin                   /* i  : Parametric binauralizer HRTF handle             */
#endif
);

void ivas_binaural_reverb_close(
@@ -4558,6 +4575,16 @@ void ivas_HRTF_fastconv_binary_close(
);
#endif

#ifdef HRTF_BINARY_PARAM
ivas_error ivas_HRTF_parambin_binary_open(
    HRTFS_PARAMBIN **hHrtfParambin                              /* i/o: Parametric binauralizer HRTF structure */
);

void ivas_HRTF_parambin_binary_close(
    HRTFS_PARAMBIN **hHrtfParambin                              /* i/o: Parametric binauralizer HRTF structure */
);
#endif

void QuatToRotMat(
#ifdef EXT_RENDERER
    const IVAS_QUATERNION quat,                                 /* i  : quaternion describing the rotation                      */
+69 −3
Original line number Diff line number Diff line
@@ -86,9 +86,16 @@ static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], f
 * Initialize parametric binaural renderer
 *------------------------------------------------------------------------*/

#ifdef HRTF_BINARY_PARAM
ivas_error ivas_dirac_dec_init_binaural_data(
    Decoder_Struct *st_ivas,            /* i/o: IVAS decoder structure                  */
    HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i  : HRTF structure for rendering            */
)
#else
ivas_error ivas_dirac_dec_init_binaural_data(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure                  */
)
#endif
{
    DIRAC_DEC_BIN_HANDLE hBinaural;
    int16_t nBins;
@@ -199,7 +206,11 @@ ivas_error ivas_dirac_dec_init_binaural_data(
    }
    else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */
    {
#ifdef HRTF_BINARY_PARAM
        mvr2r( hHrtfParambin->parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins );
#else
        mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins );
#endif

#ifdef BRATE_SWITCHING_RENDERING
        /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */
@@ -216,7 +227,11 @@ ivas_error ivas_dirac_dec_init_binaural_data(
            if ( hBinaural->useSubframeMode )
            {
#ifdef HRTF_BINARY_FASTCONV
                if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
                if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM, st_ivas->hHrtfFastConv
#ifdef HRTF_BINARY_PARAM
                                                          , st_ivas->hHrtfParambin
#endif
                                                          ) ) != IVAS_ERR_OK )
#else
                if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK )
#endif
@@ -227,7 +242,11 @@ ivas_error ivas_dirac_dec_init_binaural_data(
            else
            {
#ifdef HRTF_BINARY_FASTCONV
                if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
                if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM, st_ivas->hHrtfFastConv
#ifdef HRTF_BINARY_PARAM
                                                          , st_ivas->hHrtfParambin
#endif
                                                          ) ) != IVAS_ERR_OK )
#else
                if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK )
#endif
@@ -316,6 +335,53 @@ void ivas_dirac_dec_close_binaural_data(
    return;
}

#ifdef HRTF_BINARY_PARAM
/*-------------------------------------------------------------------------
 * ivas_dirac_dec_binaural_copy_hrtfs()
 *
 * Temporary function for copying HRTF data from rom tables if no binary
 * file was given.
 *------------------------------------------------------------------------*/

ivas_error ivas_dirac_dec_binaural_copy_hrtfs(
    HRTFS_PARAMBIN_HANDLE *hHrtfParambin /* i/o: HRTF structure for rendering */
)
{
    int16_t i, j;
    if ( hHrtfParambin != NULL && *hHrtfParambin != NULL )
    {
        /* Tables already loaded from file */
        return IVAS_ERR_OK;
    }
    else
    {
        /* Initialise tables from ROM */
        HRTFS_PARAMBIN *hrtfParambin;

        if ( ( hrtfParambin = (HRTFS_PARAMBIN *) count_malloc( sizeof( HRTFS_PARAMBIN ) ) ) == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for parametric binauralizer HRTF tables" );
        }

        for ( i = 0; i < BINAURAL_CHANNELS; i++ )
        {
            for ( j = 0; j < HRTF_SH_CHANNELS; j++ )
            {
                mvr2r( hrtfShCoeffsRe[i][j], hrtfParambin->hrtfShCoeffsRe[i][j], HRTF_NUM_BINS );
                mvr2r( hrtfShCoeffsIm[i][j], hrtfParambin->hrtfShCoeffsIm[i][j], HRTF_NUM_BINS );
            }
        }

        mvr2r( parametricReverberationTimes, hrtfParambin->parametricReverberationTimes, CLDFB_NO_CHANNELS_MAX );
        mvr2r( parametricReverberationEneCorrections, hrtfParambin->parametricReverberationEneCorrections, CLDFB_NO_CHANNELS_MAX );
        mvr2r( parametricEarlyPartEneCorrection, hrtfParambin->parametricEarlyPartEneCorrection, CLDFB_NO_CHANNELS_MAX );

        *hHrtfParambin = hrtfParambin;
    }

    return IVAS_ERR_OK;
}
#endif

/*-------------------------------------------------------------------------
 * ivas_dirac_dec_binaural()
+33 −0
Original line number Diff line number Diff line
@@ -587,6 +587,13 @@ ivas_error ivas_init_decoder_front(
            return error;
        }
#endif

#ifdef HRTF_BINARY_PARAM
        if ( ( error = ivas_HRTF_parambin_binary_open( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#endif
    }

    /*-------------------------------------------------------------------*
@@ -1173,10 +1180,25 @@ ivas_error ivas_init_decoder(
    }
    else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
    {
#ifdef HRTF_BINARY_PARAM
        if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC )
        {
            if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

        if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#else
        if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#endif
    }
    else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
    {
@@ -1509,6 +1531,9 @@ void ivas_initialize_handles_dec(
#endif
#ifdef HRTF_BINARY_FASTCONV
    st_ivas->hHrtfFastConv = NULL;
#endif
#ifdef HRTF_BINARY_PARAM
    st_ivas->hHrtfParambin = NULL;
#endif
    st_ivas->hoa_dec_mtx = NULL;

@@ -1732,6 +1757,14 @@ void ivas_destroy_dec(
    }
#endif

#ifdef HRTF_BINARY_PARAM
    /* Parametric binauralizer HRTF filters */
    if ( st_ivas->hHrtfParambin != NULL )
    {
        ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin );
    }
#endif

    /* Config. Renderer */
    ivas_render_config_close( &( st_ivas->hRenderConfig ) );

Loading