Commit 4056354b authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

Merge branch...

Merge branch '312-rendering-update-share-scripts-for-fastconv-and-parametric-renderer-hrtf-table-generation' of forge.3gpp.org:ivas-codec-pc/ivas-codec into 744_step1_scripts
parents 2ed6ff4c 3ecb0807
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@
/*#define FIX_I4_OL_PITCH*/                             /* fix open-loop pitch used for EVS core switching */
/*#define SPLIT_REND_WITH_HEAD_ROT  */                  /* Dlb,FhG: Split Rendering contributions 21 and 35 */

/*#define FIX_312_FASTCONV_HRTF_LOAD*/                      /* FhG: update loading of FastConv HRTFs from binary data - to be enabled after Matlab binary blob generation is harmonised */
#define FIX_879_USAN_ERROR_IN_MASA_DECODING             /* FhG: Issue 879 : avoid arithmetic with NULL pointer in the DirAC decoder to fix USAN error */
#define FIX_740_MASA_PREREND_VALIDITY_CHECK             /* Nokia: issue 740: fix incorrect validity check in lib_rend to allow use of MASA prerenderer */
#define FIX_865_MOVE_TD_DECORR                          /* VA: issue 865: Move ivas_td_decorr.c from lib_com to lib_rend */
+37 −0
Original line number Diff line number Diff line
@@ -929,11 +929,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(

    hrtf_data_rptr = hrtf_data;

#ifndef FIX_312_FASTCONV_HRTF_LOAD
    /* BINAURAL_CONVBANDS */
    if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
    }
#endif
    hrtf_data_rptr += sizeof( uint16_t );

    /* HRIR */
@@ -942,6 +944,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        ( *hHRTF )->FASTCONV_HRIR_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );

#ifdef FIX_312_FASTCONV_HRTF_LOAD

        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" );
@@ -993,6 +1002,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        ( *hHRTF )->FASTCONV_HOA3_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );

#ifdef FIX_312_FASTCONV_HRTF_LOAD

        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HOA3_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA3_CHANNELS)" );
@@ -1042,6 +1058,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        /* HRIR_HOA2 */
        ( *hHRTF )->FASTCONV_HOA2_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );
#ifdef FIX_312_FASTCONV_HRTF_LOAD

        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HOA2_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA2_CHANNELS)" );
@@ -1092,6 +1115,14 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        /* HRIR_FOA */
        ( *hHRTF )->FASTCONV_FOA_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );
#ifdef FIX_312_FASTCONV_HRTF_LOAD


        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( FOA_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (FOA_CHANNELS)" );
@@ -1143,6 +1174,12 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        ( *hHRTF )->FASTCONV_BRIR_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );

#ifdef FIX_312_FASTCONV_HRTF_LOAD
        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" );
+225 −16
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@


#define FILE_HEADER
#define PARAMBIN_FILE_312

/*------------------------------------------------------------------------------------------*
 * Constants
@@ -56,6 +57,9 @@

#define DEFAULT_INPUT_ROM_FILE     "ivas_binaural"
#define DEFAULT_INPUT_TD_BIN_FILE  "hrfilter_model"
#ifdef PARAMBIN_FILE_312
#define DEFAULT_INPUT_PARAMBIN_FILE "parambin_binary_rom"
#endif
#define DEFAULT_BIN_FILE_EXT       ".bin"

#define IVAS_NB_RENDERER_TYPE 7
@@ -160,8 +164,15 @@ void usage_tables_format_converter( void )
             "-16 : Select 16 kHz sampling frequency (no multiple values, all frequencies by default).\n"
             "-32 : Select 32 kHz sampling frequency (no multiple values, all frequencies by default).\n"
             "-48 : Select 48 kHz sampling frequency (no multiple values, all frequencies by default).\n" );
    fprintf( stdout, "-input_td_file_path : Path of binary files for time-domain renderer (with separator, used as flag).\n" );
    fprintf( stdout, "-input_td_file_name : Name of input td file (without extension %s, default = '%s').\n", DEFAULT_BIN_FILE_EXT, DEFAULT_INPUT_TD_BIN_FILE );
    fprintf( stdout, "-input_td_file_path : Path of binary files for time-domain renderer (WITH separator, used as flag).\n" );
    fprintf( stdout, "-input_td_file_name : Name of input td file (WITHOUT extension %s, default = '%s').\n", DEFAULT_BIN_FILE_EXT, DEFAULT_INPUT_TD_BIN_FILE );
#ifdef PARAMBIN_FILE_312
    fprintf( stdout, "-input_parambin_file_path : Path of binary files for parambin renderer (WITH separator, used as flag).\n" );
    fprintf( stdout, "-input_parambin_file_name : Name of input parambin file (WITHOUT extension %s, default = '%s').\n", DEFAULT_BIN_FILE_EXT, DEFAULT_INPUT_PARAMBIN_FILE );
    fprintf( stdout, "\n" );
    fprintf( stdout, "For example :\n"
                     "tables_format_converter(.exe) -output_file_path ./ -48 -input_td_file_path ./../../../td_object_renderer/hrtf_data/IVAS_default/ -input_td_file_name hrfilter_model_v003 -input_parambin_file_path ../../param_bin/ -input_parambin_file_name parambin_binary_rom\n");
#endif
    fprintf( stdout, "\n" );
}

@@ -177,6 +188,12 @@ char *input_td_bin_path = NULL;
char *input_td_bin_file_name = NULL;
char *full_in_td_path = NULL;

#ifdef PARAMBIN_FILE_312
char *input_parambin_path = NULL;
char *input_parambin_file_name = NULL;
char *full_in_parambin_path = NULL;
#endif

int16_t nb_freq = IVAS_NB_SAMPLERATE;
const int32_t *freq_ptr = sample_rates;

@@ -1215,7 +1232,18 @@ char *create_hrtf_parametric( int32_t *hrtf_size )
    uint32_t data_size_tmp;

    int16_t i, j;
#ifdef PARAMBIN_FILE_312
    uint8_t file_read_ok;

    float hrtfShCoeffsReFile[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS];
    float hrtfShCoeffsImFile[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS];

    float parametricReverberationTimesFile[CLDFB_NO_CHANNELS_MAX];
    float parametricReverberationEneCorrectionsFile[CLDFB_NO_CHANNELS_MAX];
    float parametricEarlyPartEneCorrectionFile[CLDFB_NO_CHANNELS_MAX];

    FILE *input_parambin_file = NULL;
#endif
    hrtf_data_size = 0;

    /* Binary file - block description :
@@ -1227,7 +1255,6 @@ char *create_hrtf_parametric( int32_t *hrtf_size )
                hrtfShCoeffsIm => float[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS];

            BRIR-based reverb

                CLDFB_NO_CHANNELS_MAX => uint16_t
                parametricReverberationTimes => float[CLDFB_NO_CHANNELS_MAX];
                parametricReverberationEneCorrections => float[CLDFB_NO_CHANNELS_MAX];
@@ -1246,10 +1273,73 @@ char *create_hrtf_parametric( int32_t *hrtf_size )
    hrtf_data_size += CLDFB_NO_CHANNELS_MAX * sizeof( float ); // parametricReverberationEneCorrections
    hrtf_data_size += CLDFB_NO_CHANNELS_MAX * sizeof( float ); // parametricEarlyPartEneCorrection

#ifdef PARAMBIN_FILE_312
    file_read_ok = 0;
    file_read_ok = 0;
    input_parambin_file = fopen( full_in_parambin_path, "rb" );
    if ( input_parambin_file != NULL )
    {
        uint16_t hrtf_sh_channels, hrtf_num_bins, cldfb_no_channels_max;

        fseek( input_parambin_file, 0, SEEK_END );
        data_size_tmp = ftell( input_parambin_file );
        fseek( input_parambin_file, 0, SEEK_SET );

        if ( data_size_tmp != hrtf_data_size )
        {
            fprintf( stderr, "Inconsistent binary data file size (expected: %d, found %d). Using built-in default values.\n\n", hrtf_data_size, data_size_tmp );
        }
        else
        {
            fread( &hrtf_sh_channels, sizeof( uint16_t ), 1, input_parambin_file );
            fread( &hrtf_num_bins, sizeof( uint16_t ), 1, input_parambin_file );
            if ( hrtf_sh_channels != HRTF_SH_CHANNELS )
            {
                fprintf( stderr, "Warning: Inconsistent HRTF_SH_CHANNELS (expected: %d, found: %d).\n\n", HRTF_SH_CHANNELS, hrtf_sh_channels );
            }
            if ( hrtf_num_bins != HRTF_NUM_BINS )
            {
                fprintf( stderr, "Warning: Inconsistent HRTF_NUM_BINS (expected: %d, found: %d).\n\n", HRTF_NUM_BINS, hrtf_num_bins );
            }

            for ( size_t bin_chnl = 0; bin_chnl < BINAURAL_CHANNELS; bin_chnl++ )
            {
                for ( size_t hrtf_chnl = 0; hrtf_chnl < HRTF_SH_CHANNELS; hrtf_chnl++ )
                {
                    fread( hrtfShCoeffsReFile[bin_chnl][hrtf_chnl], sizeof( float ), HRTF_NUM_BINS, input_parambin_file );
                }
            }
            for ( size_t bin_chnl = 0; bin_chnl < BINAURAL_CHANNELS; bin_chnl++ )
            {
                for ( size_t hrtf_chnl = 0; hrtf_chnl < HRTF_SH_CHANNELS; hrtf_chnl++ )
                {
                    fread( hrtfShCoeffsImFile[bin_chnl][hrtf_chnl], sizeof( float ), HRTF_NUM_BINS, input_parambin_file );
                }
            }

            /* reverb */
            fread( &cldfb_no_channels_max, sizeof( uint16_t ), 1, input_parambin_file );
            if ( cldfb_no_channels_max != CLDFB_NO_CHANNELS_MAX )
            {
                fprintf( stderr, "Warning: Inconsistent CLDFB_NO_CHANNELS_MAX (expected: %d, found: %d).\n\n", CLDFB_NO_CHANNELS_MAX, cldfb_no_channels_max );
            }

            fread( parametricReverberationTimesFile, sizeof( float ), CLDFB_NO_CHANNELS_MAX, input_parambin_file );
            fread( parametricReverberationEneCorrectionsFile, sizeof( float ), CLDFB_NO_CHANNELS_MAX, input_parambin_file );
            fread( parametricEarlyPartEneCorrectionFile, sizeof( float ), CLDFB_NO_CHANNELS_MAX, input_parambin_file );

            file_read_ok = 1;
        }
    }
    else
    {
        fprintf( stderr, "Opening of parambin file %s failed. Using built-in default values.\n\n", full_in_parambin_path );
    }
#endif

    // Allocate memory
    *hrtf_size = sizeof( ivas_hrtfs_header_t ) + hrtf_data_size;
    hrtf = (char *) malloc( *hrtf_size );

    if ( hrtf == NULL )
    {
        fprintf( stderr, "Memory allocation for the block failed!\n\n" );
@@ -1257,6 +1347,7 @@ char *create_hrtf_parametric( int32_t *hrtf_size )
        return NULL;
    }


    // Write

    // Header [Declaration of the HRTF]
@@ -1292,14 +1383,24 @@ char *create_hrtf_parametric( int32_t *hrtf_size )
    *( (uint16_t *) ( hrtf_wptr ) ) = HRTF_NUM_BINS;
    hrtf_wptr += sizeof( uint16_t );


    // HRTF
    data_size_tmp = HRTF_NUM_BINS * sizeof( float );
    for ( i = 0; i < BINAURAL_CHANNELS; i++ )
    {
        for ( j = 0; j < HRTF_SH_CHANNELS; j++ )
        {
#ifdef PARAMBIN_FILE_312
            if ( file_read_ok )
            {
                memcpy( hrtf_wptr, &hrtfShCoeffsReFile[i][j], data_size_tmp );
            }
            else
            {
                memcpy( hrtf_wptr, &hrtfShCoeffsRe[i][j], data_size_tmp );
            }
#else
            memcpy( hrtf_wptr, &hrtfShCoeffsRe[i][j], data_size_tmp );
#endif
            hrtf_wptr += data_size_tmp;
        }
    }
@@ -1307,7 +1408,18 @@ char *create_hrtf_parametric( int32_t *hrtf_size )
    {
        for ( j = 0; j < HRTF_SH_CHANNELS; j++ )
        {
#ifdef PARAMBIN_FILE_312
            if ( file_read_ok )
            {
                memcpy( hrtf_wptr, &hrtfShCoeffsImFile[i][j], data_size_tmp );
            }
            else
            {
                memcpy( hrtf_wptr, &hrtfShCoeffsIm[i][j], data_size_tmp );
            }
#else
            memcpy( hrtf_wptr, &hrtfShCoeffsIm[i][j], data_size_tmp );
#endif
            hrtf_wptr += data_size_tmp;
        }
    }
@@ -1317,13 +1429,28 @@ char *create_hrtf_parametric( int32_t *hrtf_size )
    hrtf_wptr += sizeof( uint16_t );

    data_size_tmp = CLDFB_NO_CHANNELS_MAX * sizeof( float );
#ifdef PARAMBIN_FILE_312
    if ( file_read_ok )
    {
        memcpy( hrtf_wptr, &( parametricReverberationTimesFile ), data_size_tmp ); // parametricReverberationTimes
        hrtf_wptr += data_size_tmp;
        memcpy( hrtf_wptr, &( parametricReverberationEneCorrectionsFile ), data_size_tmp ); // parametricReverberationEneCorrections
        hrtf_wptr += data_size_tmp;
        memcpy( hrtf_wptr, &( parametricEarlyPartEneCorrectionFile ), data_size_tmp ); // parametricEarlyPartEneCorrection
        hrtf_wptr += data_size_tmp;
    }
    else
    {
#endif
        memcpy( hrtf_wptr, &( parametricReverberationTimes ), data_size_tmp ); // parametricReverberationTimes
        hrtf_wptr += data_size_tmp;
        memcpy( hrtf_wptr, &( parametricReverberationEneCorrections ), data_size_tmp ); // parametricReverberationEneCorrections
        hrtf_wptr += data_size_tmp;
        memcpy( hrtf_wptr, &( parametricEarlyPartEneCorrection ), data_size_tmp ); // parametricEarlyPartEneCorrection
        hrtf_wptr += data_size_tmp;

#ifdef PARAMBIN_FILE_312
    }
#endif
    return hrtf;
}

@@ -2332,6 +2459,34 @@ int rom2bin_init( int argc, char *argv[] )
            strcpy( input_td_bin_file_name, argv[i] );
            i++;
        }
#ifdef PARAMBIN_FILE_312
        else if ( strcmp( to_upper( argv[i] ), "-INPUT_PARAMBIN_FILE_PATH" ) == 0 )
        {
            i++;
            if ( strlen( argv[i] ) == 0 )
            {
                fprintf( stderr, "Wrong input parambin file path: %s\n\n", argv[i] );
                usage_tables_format_converter();
                return -1;
            }
            input_parambin_path = malloc( strlen( argv[i] ) + 1 );
            strcpy( input_parambin_path, argv[i] );
            i++;
        }
        else if ( strcmp( to_upper( argv[i] ), "-INPUT_PARAMBIN_FILE_NAME" ) == 0 )
        {
            i++;
            if ( strlen( argv[i] ) == 0 )
            {
                fprintf( stderr, "Wrong input parambin file name: %s\n\n", argv[i] );
                usage_tables_format_converter();
                return -1;
            }
            input_parambin_file_name = malloc( strlen( argv[i] ) + 1 );
            strcpy( input_parambin_file_name, argv[i] );
            i++;
        }
#endif
        else
        {
            fprintf( stderr, "Unknown option: %s\n\n", argv[i] );
@@ -2427,7 +2582,45 @@ int rom2bin_init( int argc, char *argv[] )
            return -1;
        }
    }
#ifdef PARAMBIN_FILE_312
    if ( input_parambin_path == NULL )
    {
        input_parambin_path = (char *) malloc( sizeof( char ) * ( strlen( DEFAULT_PATH ) + 1 ) );
        if ( input_parambin_path )
        {
            strcpy( input_parambin_path, DEFAULT_PATH );
        }
        else
        {
            fprintf( stderr, "Memory issue for input parambin file path!\n\n" );
            rom2bin_terminat();
            return -1;
        }
    }
    if ( input_parambin_file_name == NULL )
    {
        input_parambin_file_name = (char *) malloc( sizeof( char ) * ( strlen( DEFAULT_INPUT_PARAMBIN_FILE ) + 1 ) );
        if ( input_parambin_file_name )
        {
            strcpy( input_parambin_file_name, DEFAULT_INPUT_PARAMBIN_FILE );
        }
        else
        {
            fprintf( stderr, "Memory issue for input parambin file name!\n\n" );
            rom2bin_terminat();
            return -1;
        }
    }

    full_in_parambin_path = (char *) malloc( sizeof( char ) * ( strlen( input_parambin_path ) + strlen( input_parambin_file_name ) + strlen( DEFAULT_BIN_FILE_EXT ) + 2 ) );
    if ( full_in_parambin_path == NULL )
    {
        fprintf( stderr, "Memory issue for full input parambin path!\n\n" );
        rom2bin_terminat();
        return -1;
    }
    sprintf( full_in_parambin_path, "%s/%s%s", input_parambin_path, input_parambin_file_name, DEFAULT_BIN_FILE_EXT );
#endif
    return 0;
}

@@ -2467,6 +2660,22 @@ void rom2bin_terminat( void )
    {
        free( full_in_td_path );
    }
#ifdef PARAMBIN_FILE_312
    if ( input_parambin_path != NULL )
    {
        free( input_parambin_path );
    }

    if ( input_parambin_file_name != NULL )
    {
        free( input_parambin_file_name );
    }

    if ( full_in_parambin_path != NULL )
    {
        free( full_in_parambin_path );
    }
#endif
}

/*---------------------------------------------------------------------*
+6 −4
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ The table format converter is used to generate the file containing the binary re
filters for renderers (dynamic loading of generated file using –hrtf argument).
This tool is able :
   - to generate binary file for MIXER_CONV, MIXER_CONV_ROOM (tables conversion from ROM);
   - to aggregate the binary HR filter of OBJECTS_TD (to be done : FASTCONV and PARAMETRIC binaural)
   - to aggregate the binary HR filter of OBJECTS_TD, PARAM_BIN (to be done : FASTCONV)

First, build the converter under scripts/binauralRenderer_interface/Table_Format_Converter/ in VSCode (using CMakeList).

@@ -53,8 +53,10 @@ Options :
-16 : Select 16 kHz sampling frequency (no multiple values, all frequencies by default).
-32 : Select 32 kHz sampling frequency (no multiple values, all frequencies by default).
-48 : Select 48 kHz sampling frequency (no multiple values, all frequencies by default).
-input_td_file_path : Path of binary files for time-domain renderer (with separator, used as flag).
-input_td_file_name : Name of input td file (without extension .bin, default = 'hrfilter_model').
-input_td_file_path : Path of binary files for time-domain renderer (WITH separator, used as flag).
-input_td_file_name : Name of input td file (WITHOUT extension .bin, default = 'hrfilter_model').
-input_parambin_file_path : Path of binary files for parambin renderer (WITH separator, used as flag).
-input_parambin_file_name : Name of input parambin file (WITHOUT extension .bin, default = 'parambin_binary_rom').

For example :
tables_format_converter(.exe) -output_file_path './' -48 -input_td_file_path './../../../td_object_renderer/hrtf_data/IVAS_default/' -input_td_file_name 'hrfilter_model_v003'
 No newline at end of file
tables_format_converter(.exe) -output_file_path ./ -48 -input_td_file_path ./../../../td_object_renderer/hrtf_data/IVAS_default/ -input_td_file_name hrfilter_model_v003 -input_parambin_file_path ../../param_bin/ -input_parambin_file_name parambin_binary_rom
+3 −0
Original line number Diff line number Diff line
WIP:
The script to generate all FastConv Renderer tables is generate_tables_for_fastconv.m
Options can be set in the script to generate either or both ROM tables and a Binary file.
 No newline at end of file
Loading