diff --git a/apps/decoder.c b/apps/decoder.c index 55ef28160eae362d94b6558c775eb50ad7f68a49..4db62d0f1e8517f266aa0fb8f3de33bab0295c74 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3775,13 +3775,17 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { - if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_HRTF_binary( *hHrtfBinary->hHrtfTD, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -3881,11 +3885,15 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) +#else if ( hHrtfBinary->hHrtfStatistics == NULL ) +#endif { if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } diff --git a/apps/renderer.c b/apps/renderer.c index f90ec711f690416d00853e7ad19c499ca56b2441..22ffa4838dbae98e8a31691f9d806c2d1b8ab20f 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -910,7 +910,11 @@ int main( goto cleanup; } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( ( error = load_TDrend_HRTF_binary( *hHrtfTD, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_HRTF_binary( *hHrtfTD, hrtfFileReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { diff --git a/lib_com/ivas_error.h b/lib_com/ivas_error.h index 50b6c2d9bc87c77e6c86e0877b8951c4d65cffe3..a6a0e70ea56745767074361a22b45062acb0fe60 100644 --- a/lib_com/ivas_error.h +++ b/lib_com/ivas_error.h @@ -79,6 +79,9 @@ typedef enum IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED, IVAS_ERR_OBJECTS_EDITING_NOT_SUPPORTED, IVAS_ERR_INVALID_HRTF, +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + IVAS_ERR_INVALID_HRTF_SAMPLING_RATE, +#endif IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA, IVAS_ERR_INVALID_INPUT_FORMAT, IVAS_ERR_INVALID_INDEX, @@ -259,6 +262,10 @@ static inline const char *ivas_error_to_string( ivas_error error_code ) return "Objects editing not supported"; case IVAS_ERR_INVALID_HRTF: return "Unsupported HRTF filter set"; +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + case IVAS_ERR_INVALID_HRTF_SAMPLING_RATE: + return "Wrong sampling rate in HRTF binary file"; +#endif case IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA: return "Renderer data missing in HRTF binary file"; case IVAS_ERR_INVALID_INPUT_FORMAT: diff --git a/lib_com/options.h b/lib_com/options.h index 484de232aa48b1865b46fd4fea0e4eb7f0a5a0fb..059877b9b26b50818d4ccfbb5e5bb63a4bfdcd37 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,6 +163,7 @@ #define FIX_1226_FASTCONV_HRTF_LOADING_OPTIM /* VA: issue 1226: for FastConv binaural renderer in decoder, load only HTRT coefficient set that is needed */ #define FIX_1227_Crend_HRTF_LOADING_OPTIM /* VA: issue 1227: for Crend binaural renderer in decoder, load only HTRT coefficient set that is needed */ #define FIX_1222_OMASA_DEC_CHANNEL_BUFFERS /* VA: issue 1222: Reduction of the number of channel buffers in OMASA decoder */ +#define FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE /* VA: issue 1228: Exit the processing when a HRTF binary file with wrong sampling rate is provided */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index a71d801ae7ec24fa2b7c4fbfe293b6ee833a0088..8ac62b87c37a3df1b59dccb66380e8af88c048c2 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2679,12 +2679,12 @@ ivas_error IVAS_DEC_FeedCustomLsData( /*---------------------------------------------------------------------* - * IVAS_DEC_GetHrtfHandle( ) - * + * IVAS_DEC_GetHrtfTDrendHandle( ) * + * Get TD binaural renderer handle *---------------------------------------------------------------------*/ -ivas_error IVAS_DEC_GetHrtfHandle( +ivas_error IVAS_DEC_GetHrtfTDrendHandle( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ IVAS_DEC_HRTF_HANDLE **hHrtfTD /* o : HRTF handle */ ) @@ -2703,7 +2703,7 @@ ivas_error IVAS_DEC_GetHrtfHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfCRendHandle( ) * - * + * Get Crend binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfCRendHandle( @@ -2738,7 +2738,7 @@ ivas_error IVAS_DEC_GetHrtfCRendHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfFastConvHandle( ) * - * + * Get FastConv binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfFastConvHandle( @@ -2760,7 +2760,7 @@ ivas_error IVAS_DEC_GetHrtfFastConvHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfParamBinHandle( ) * - * + * Get Parametric binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfParamBinHandle( @@ -2781,7 +2781,7 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfStatisticsHandle( ) * - * + * Get HRTF statistics (room effect) binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( @@ -2867,7 +2867,11 @@ ivas_error IVAS_DEC_HRTF_binary_open( } } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( st_ivas->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) +#else if ( st_ivas->hHrtfStatistics == NULL ) +#endif { if ( ( error = ivas_HRTF_statistics_binary_open( &st_ivas->hHrtfStatistics ) ) != IVAS_ERR_OK ) { @@ -2883,7 +2887,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( /*---------------------------------------------------------------------* * IVAS_DEC_HRTF_binary_close( ) * - * + * Deallocate HRTF binary handles *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_HRTF_binary_close( diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 3aca0e9b1c2d86a068b9c4fe1b1b7a28f2a39466..43dcfb33ba6b4df0207022722164ca489050c1b7 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -436,7 +436,7 @@ ivas_error IVAS_DEC_FeedCustomLsData( ); /*! r: error code */ -ivas_error IVAS_DEC_GetHrtfHandle( +ivas_error IVAS_DEC_GetHrtfTDrendHandle( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ IVAS_DEC_HRTF_HANDLE **hHrtfTD /* o : HRTF handle */ ); diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index ac74c6c49a61c1136d99c47aa31d71346e27ca08..f3517edd3091ce3f1babb7d8b03c8dcd5893b2f6 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -56,19 +56,6 @@ typedef struct ivas_hrtfs_file_header_t } ivas_hrtfs_file_header_t; -#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM -typedef enum -{ - BINAURAL_INPUT_AUDIO_CONFIG_INVALID, - BINAURAL_INPUT_AUDIO_CONFIG_COMBINED, /* 5_1, 5_1_2, 5_1_4, 7_1, 7_1_4 */ - BINAURAL_INPUT_AUDIO_CONFIG_HOA3, /* HOA3 */ - BINAURAL_INPUT_AUDIO_CONFIG_HOA2, /* HOA2 */ - BINAURAL_INPUT_AUDIO_CONFIG_FOA, /* FOA */ - BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED /* Not used */ - -} BINAURAL_INPUT_AUDIO_CONFIG; - -#endif /*---------------------------------------------------------------------* * hrtfFileReader_open() @@ -215,7 +202,11 @@ static ivas_error check_hrtf_binary_header( /* Check the sampling frequency */ if ( ( hrtf_header->frequency != 48000 ) && ( hrtf_header->frequency != 32000 ) && ( hrtf_header->frequency != 16000 ) ) { +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Header of HRTF binary file not compliant (sampling frequency)" ); +#else + return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Header of HRTF binary file not compliant (sampling frequency)" ); +#endif } return IVAS_ERR_OK; @@ -290,12 +281,12 @@ static BINAURAL_INPUT_AUDIO_CONFIG audio_cfg_2_binaural_cfg( #endif /*-------------------------------------------------------------------* - * LoadBSplineBinaryITD() + * TDREND_LoadBSplineBinaryITD() * * Loads the B Spline HR filter model ITD data from file for TD renderer --------------------------------------------------------------------*/ -static ivas_error LoadBSplineBinaryITD( +static ivas_error TDREND_LoadBSplineBinaryITD( ModelParamsITD_t *modelITD, /* i/o: ITD model parameter structure */ FILE *f_hrtf /* i : HR filter data file handle */ ) @@ -445,12 +436,12 @@ static ivas_error LoadBSplineBinaryITD( } /*-------------------------------------------------------------------* - * LoadBSplineBinary() + * TDREND_LoadBSplineBinary() * * Loads the B Spline HR filter model data from file for TD renderer --------------------------------------------------------------------*/ -static ivas_error LoadBSplineBinary( +static ivas_error TDREND_LoadBSplineBinary( IVAS_DEC_HRTF_HANDLE HrFiltSet_p, /* i/o: HR filter model parameter structure */ FILE *f_hrtf /* i : HR filter data file handle */ ) @@ -722,7 +713,7 @@ static ivas_error LoadBSplineBinary( if ( HrFiltSet_p->ModelParams.UseItdModel ) { - if ( ( error = LoadBSplineBinaryITD( &HrFiltSet_p->ModelParamsITD, f_hrtf ) ) != IVAS_ERR_OK ) + if ( ( error = TDREND_LoadBSplineBinaryITD( &HrFiltSet_p->ModelParamsITD, f_hrtf ) ) != IVAS_ERR_OK ) { return error; } @@ -740,7 +731,7 @@ static ivas_error LoadBSplineBinary( static ivas_error load_reverb_from_binary( IVAS_DEC_HRTF_STATISTICS_HANDLE hHrtfStatistics, /* i/o: HRTF statistics handle */ - int32_t sampleRate, /* i : sample rate */ + const int32_t sampleRate, /* i : sample rate */ FILE *f_hrtf /* i : HR filter data file handle */ ) { @@ -814,6 +805,15 @@ static ivas_error load_reverb_from_binary( return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + else + { + if ( hrtf_header.frequency != sampleRate ) + { + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; + } + } +#endif } free( hrtf_data ); @@ -868,7 +868,7 @@ static ivas_error load_reverb_from_binary( ivas_error load_reverb_binary( IVAS_DEC_HRTF_STATISTICS_HANDLE hHrtfStatistics, /* i/o: HRTF statistics handle */ - int32_t sampleRate, /* i : sample rate */ + const int32_t sampleRate, /* i : sample rate */ const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle */ ) { @@ -890,7 +890,10 @@ ivas_error load_reverb_binary( --------------------------------------------------------------------*/ static ivas_error TDREND_MIX_LoadHRTF( - FILE *f_hrtf, /* i/o: File pointer to HRTF file */ + FILE *f_hrtf, /* i/o: File pointer to HRTF file */ +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + const int32_t sampleRate, /* i : sample rate */ +#endif IVAS_DEC_HRTF_HANDLE HrFiltSet_p /* o : Loaded HR filter set */ ) { @@ -912,8 +915,6 @@ static ivas_error TDREND_MIX_LoadHRTF( if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK ) { - - /* try if it is old format for BE tests*/ fseek( f_hrtf, 0, SEEK_SET ); if ( fread( &tmp, 1, sizeof( int16_t ), f_hrtf ) == 0 ) { @@ -928,7 +929,7 @@ static ivas_error TDREND_MIX_LoadHRTF( } else { - header_check_result = LoadBSplineBinary( HrFiltSet_p, f_hrtf ); + header_check_result = TDREND_LoadBSplineBinary( HrFiltSet_p, f_hrtf ); } return header_check_result; @@ -970,6 +971,15 @@ static ivas_error TDREND_MIX_LoadHRTF( return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + else + { + if ( hrtf_header.frequency != sampleRate ) + { + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; + } + } +#endif } free( hrtf_data ); @@ -989,7 +999,7 @@ static ivas_error TDREND_MIX_LoadHRTF( } else { - header_check_result = LoadBSplineBinary( HrFiltSet_p, f_hrtf ); + header_check_result = TDREND_LoadBSplineBinary( HrFiltSet_p, f_hrtf ); } } else @@ -1002,14 +1012,21 @@ static ivas_error TDREND_MIX_LoadHRTF( /*---------------------------------------------------------------------* - * load_HRTF_binary() + * load_TDrend_HRTF_binary() * * Load HRTF binary data into the HRTF handle for TD renderer *---------------------------------------------------------------------*/ +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE +ivas_error load_TDrend_HRTF_binary( +#else ivas_error load_HRTF_binary( - IVAS_DEC_HRTF_HANDLE hHrtf, /* i/o: HRTF handle */ - const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle */ +#endif + IVAS_DEC_HRTF_HANDLE hHrtf, /* i/o: HRTF handle */ +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + const int32_t sampleRate, /* i : sample rate */ +#endif + const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ) { if ( hrtfReader == NULL || hrtfReader->file == NULL ) @@ -1019,7 +1036,11 @@ ivas_error load_HRTF_binary( fseek( hrtfReader->file, 0, SEEK_SET ); +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + return TDREND_MIX_LoadHRTF( hrtfReader->file, sampleRate, hHrtf ); +#else return TDREND_MIX_LoadHRTF( hrtfReader->file, hHrtf ); +#endif } @@ -2174,6 +2195,13 @@ ivas_error load_fastconv_HRTF_from_binary( ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && intern_audio_config == IVAS_AUDIO_CONFIG_INVALID ) ) #endif { +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ + { + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; + } + +#endif if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { free( hrtf_data ); @@ -2265,8 +2293,16 @@ ivas_error load_parambin_HRTF_from_binary( free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); } + if ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) /* Parametric binauralizer data is represented as single entity */ { +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ + { + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; + } + +#endif if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { free( hrtf_data ); @@ -2311,7 +2347,7 @@ ivas_error load_Crend_HRTF_from_binary( const hrtfFileReader *hrtfReader, /* i : pointer to hrtfFileReader handle */ const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ const IVAS_AUDIO_CONFIG hrtf_set_audio_cfg, /* i : HRTF set audio config. */ - const int32_t output_Fs /* i : Output sampling frequency */ + const int32_t sampleRate /* i : sample rate */ ) #else ivas_error create_SetOfHRTF_from_binary( @@ -2430,7 +2466,13 @@ ivas_error create_SetOfHRTF_from_binary( } } #endif +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( hrtf_header.frequency != sampleRate ) + { + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; + } +#endif if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { free( hrtf_data ); @@ -2438,11 +2480,13 @@ ivas_error create_SetOfHRTF_from_binary( } #ifdef FIX_1227_Crend_HRTF_LOADING_OPTIM +#ifndef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE if ( hrtf_header.frequency != output_Fs ) { return IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA; } +#endif if ( ( create_Crend_HRTF_from_rawdata( &hHrtfCrend, hrtf_data ) ) != IVAS_ERR_OK ) { free( hrtf_data ); diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index db9b29f65e7ba6f4375d5fbfc55fd0e8a4109791..b27a42cf9f4e088fac4ebfb3264a2f3c05c85791 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -35,6 +35,7 @@ #include "common_api_types.h" + typedef struct hrtfFileReader hrtfFileReader; typedef enum @@ -47,8 +48,22 @@ typedef enum HRTF_READER_RENDERER_BINAURAL_MIXER_CONV, HRTF_READER_RENDERER_BINAURAL_MIXER_CONV_ROOM, HRTF_READER_RENDERER_BINAURAL_REVERB_ALL + } HRTF_READER_RENDERER_TYPE; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM +typedef enum +{ + BINAURAL_INPUT_AUDIO_CONFIG_INVALID, + BINAURAL_INPUT_AUDIO_CONFIG_COMBINED, /* 5_1, 5_1_2, 5_1_4, 7_1, 7_1_4 */ + BINAURAL_INPUT_AUDIO_CONFIG_HOA3, /* HOA3 */ + BINAURAL_INPUT_AUDIO_CONFIG_HOA2, /* HOA2 */ + BINAURAL_INPUT_AUDIO_CONFIG_FOA, /* FOA */ + BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED /* Not used */ + +} BINAURAL_INPUT_AUDIO_CONFIG; + +#endif typedef struct ivas_hrtfs_header_t { int32_t rend_type; @@ -80,14 +95,21 @@ void hrtfFileReader_close( ); /*---------------------------------------------------------------------* - * load_HRTF_binary() + * load_TDrend_HRTF_binary() * - * Load HRTF binary data into the HRTF handle + * Load TD renderer HRTF binary data into the HRTF handle *---------------------------------------------------------------------*/ +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE +ivas_error load_TDrend_HRTF_binary( +#else ivas_error load_HRTF_binary( - IVAS_DEC_HRTF_HANDLE hHrtf, /* i/o: HRTF handle */ - const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle */ +#endif + IVAS_DEC_HRTF_HANDLE hHrtf, /* i/o: HRTF handle */ +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + const int32_t sampleRate, /* i : sample rate */ +#endif + const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ); /*---------------------------------------------------------------------* @@ -98,9 +120,10 @@ ivas_error load_HRTF_binary( ivas_error load_reverb_binary( IVAS_DEC_HRTF_STATISTICS_HANDLE hHrtfStatistics, /* i/o: HRTF statistics handle */ - int32_t sampleRate, /* i : sample rate */ + const int32_t sampleRate, /* i : sample rate */ const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle */ ); + /*---------------------------------------------------------------------* * load_Crend_HRTF_from_binary() * @@ -113,7 +136,7 @@ ivas_error load_Crend_HRTF_from_binary( const hrtfFileReader *hrtfReader, /* i : pointer to hrtfFileReader handle */ const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ const IVAS_AUDIO_CONFIG hrtf_set_audio_cfg, /* i : HRTF set audio config. */ - const int32_t output_Fs /* i : Output sampling frequency */ + const int32_t sampleRate /* i : sample rate */ ); #else ivas_error create_SetOfHRTF_from_binary( diff --git a/scripts/binauralRenderer_interface/README.md b/scripts/binauralRenderer_interface/README.md index cedfb9841eea556ceb09d2e3fb443aac0b65949c..822d7237978a436a6c1b8d25394a03baa90a0535 100644 --- a/scripts/binauralRenderer_interface/README.md +++ b/scripts/binauralRenderer_interface/README.md @@ -27,8 +27,8 @@ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. --> -# Modeling tool for all IVAS binaural renderer -# Allows to convert SOFA file(s) to rom tables files (*.c|h) or binaural binary file(s) +# Modeling tool for all IVAS binaural renderers +# Allows to convert SOFA file(s) to ROM tables files (*.c|h) or binaural binary file(s) ## Requirements - MATLAB >= R2017b @@ -55,7 +55,7 @@ ``` - `generate_crend_ivas_tables` executable shall be in folder [`../../scripts/binauralRenderer_interface`](../../scripts/binauralRenderer_interface) - On Windows this executable requires DLL from MATLAB, you need to add to your path `*/matlab/version/bin/win64` - - For more details on `generate_crend_ivas_tables` see [`mixer_conv_sofa_to_rom_table_converter_readme.txt`](mixer_conv_sofa_to_rom_table_converter_readme.txt). + - For more details on `generate_crend_ivas_tables` see [`ivas_crend_sofa_to_rom_table_converter_readme.txt`](ivas_crend_sofa_to_rom_table_converter_readme.txt). - On Apple Silicon Mac with Intel MATLAB, it is necessary to add `SET(CMAKE_OSX_ARCHITECTURES "x86_64")` in the `CMakeLists.txt` near the top of the file. This forces the compilation to use Intel architecture instead ofo the native one. - if find_package do not find matlab, at the beginning of the cmakelists.txt file you can set the search path with the folowing line set(Matlab_ROOT_DIR matlab_path), for example on linux set(Matlab_ROOT_DIR ~/MATLAB/R2023b) on mac set(Matlab_ROOT_DIR /Applications/MATLAB_R2023b.app) @@ -109,11 +109,4 @@ See [`scripts/ThirdPartyLegalNotices`](../../scripts/ThirdPartyLegalNotices) for → Generated files are in folder [`binaural_renderers_hrtf_data`](binaural_renderers_hrtf_data) - Generated files : - `ivas_binaural_*kHz.bin`: file containing all tables values for all IVAS binaural renderers for one sample rate. - - `ivas_binaural_td_*kHz.bin`: file containing tables values for IVAS td binaural renderer for one sample rate. - - `ivas_binaural_reverb_*kHz.bin`: file containing tables values for IVAS td reverberation process for one sample rate. - - `ivas_binaural_fastconv_*kHz.bin`: file containing tables values for IVAS fastconv binaural renderers. Files for all sampling rate files are the same. - - `ivas_binaural_parambin_*kHz.bin`: file containing tables values for IVAS prametric binaural renderers. Files for all sampling rate files are the same. - - `ivas_binaural_td_*kHz.bin`: file containing tables values for IVAS td binaural renderers for one sample rate. - - `ivas_binaural_mixconv_hrir_*kHz.bin`: file containing tables values for IVAS mixer conv binaural renderer for HRIR for one sample rate. - - `ivas_binaural_mixconv_brir_*kHz.bin`: file containing tables values for IVAS mixer conv binaural renderer for BRIR for one sample rate. diff --git a/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c b/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c index c9a5d6df5c42e86a6b0c9f3c751bb92fff54d669..a7cc7d7574dd84ddb8bfedd8dcec812a57e8557a 100644 --- a/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c +++ b/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c @@ -73,21 +73,6 @@ const HRTF_READER_RENDERER_TYPE rend_types[IVAS_NB_RENDERER_TYPE] = { HRTF_READER_RENDERER_BINAURAL_REVERB_ALL }; -#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM -typedef enum -{ - BINAURAL_INPUT_AUDIO_CONFIG_INVALID, - BINAURAL_INPUT_AUDIO_CONFIG_COMBINED, /* 5_1, 5_1_2, 5_1_4, 7_1, 7_1_4 */ - BINAURAL_INPUT_AUDIO_CONFIG_HOA3, /* HOA3 */ - BINAURAL_INPUT_AUDIO_CONFIG_HOA2, /* HOA2 */ - BINAURAL_INPUT_AUDIO_CONFIG_FOA, /* FOA */ - BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED /* Not used */ - -} BINAURAL_INPUT_AUDIO_CONFIG; - -#endif - - const BINAURAL_INPUT_AUDIO_CONFIG input_cfgs[IVAS_NB_AUDIO_CONFIG] = { BINAURAL_INPUT_AUDIO_CONFIG_COMBINED, BINAURAL_INPUT_AUDIO_CONFIG_HOA3, diff --git a/scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_old.m b/scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_old.m deleted file mode 100644 index 3371eef834d6c6940299ffe000abf76d7a480bac..0000000000000000000000000000000000000000 --- a/scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_old.m +++ /dev/null @@ -1,294 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, -% Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., -% Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, -% Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other -% contributors to this repository. All Rights Reserved. -% -% This software is protected by copyright law and by international treaties. -% The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, -% Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., -% Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, -% Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other -% contributors to this repository retain full ownership rights in their respective contributions in -% the software. This notice grants no license of any kind, including but not limited to patent -% license, nor is any license granted by implication, estoppel or otherwise. -% -% Contributors are required to enter into the IVAS codec Public Collaboration agreement before making -% contributions. -% -% This software is provided "AS IS", without any express or implied warranties. The software is in the -% development stage. It is intended exclusively for experts who have experience with such software and -% solely for the purpose of inspection. All implied warranties of non-infringement, merchantability -% and fitness for a particular purpose are hereby disclaimed and excluded. -% -% Any dispute, controversy or claim arising under or in relation to providing this software shall be -% submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in -% accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and -% the United Nations Convention on Contracts on the International Sales of Goods. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function write_fastconv_binary_data(ivas_path, bin_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR) -% -% Writes HRIR & BRIR based data for FastConv binaural renderer into a binary file. -% -% write_fastconv_binary_data(rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR) -% -% filename : string -% name of the file to be written -% -% -% Output file format: -% Header [Declaration of the HRTF] -% Renderer type (int32_t) : See "RENDERER_TYPE" -% Decoder output format (int32_t) : See "BINAURAL_INPUT_AUDIO_CONFIG" -% Sampling Frequency (int32_t) -% Raw data size (uint32_t) -% -% HRIRs -% latency_s => float32 -% BINAURAL_CONVBANDS => uint16_t -% num_channels => uint16_t -% BINAURAL_NTAPS => uint16_t -% leftHRIRReal => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% leftHRIRImag => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% rightHRIRReal => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% rightHRIRImag => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% -% BRIRs -% latency_s => float32 -% num_channels => uint16_t -% BINAURAL_NTAPS_MAX => uint16_t -% leftBRIRReal => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% leftBRIRImag => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% rightBRIRReal => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% rightBRIRImag => float32[BINAURAL_CONVBANDS][num_channels][num_taps] -% CLDFB_NO_CHANNELS_MAX => uint16_t -% fastConvReverberationTimes => float32[CLDFB_NO_CHANNELS_MAX] -% fastConvReverberationEneCorrections => float32[CLDFB_NO_CHANNELS_MAX] -% - -[f_id, err_msg] = fopen(bin_file, 'wb'); - -if f_id == -1 - error('Could not open file %s for writing. Error message:\n%s', filename, err_msg); -end - -%% File header -% We need to get the chunksize of all IRs to get total size -% SHD HRIRs -% FOA -IR = FastConv_SHD_IR_FOA; -[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR); - -header = get_ivas_binary_header(ivas_path,'HRTF_READER_RENDERER_BINAURAL_FASTCONV', ['BINAURAL_INPUT_AUDIO_CONFIG_' IR.order]); -header.chunksize = header.chunksize + 4; % latency_s -header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS -header.chunksize = header.chunksize + 2; % num_channels -header.chunksize = header.chunksize + 2; % num_taps -header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im - -IR.header = header; -FastConv_SHD_IR_FOA = IR; - -% HOA2 -IR = FastConv_SHD_IR_HOA2; -[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR); - -header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV', ['BINAURAL_INPUT_AUDIO_CONFIG_' IR.order]); -header.chunksize = header.chunksize + 4; % latency_s -header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS -header.chunksize = header.chunksize + 2; % num_channels -header.chunksize = header.chunksize + 2; % num_taps -header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im - -IR.header = header; -FastConv_SHD_IR_HOA2 = IR; - -% HOA3 -IR = FastConv_SHD_IR_HOA3; -[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR); - -header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV', ['BINAURAL_INPUT_AUDIO_CONFIG_' IR.order]); -header.chunksize = header.chunksize + 4; % latency_s -header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS -header.chunksize = header.chunksize + 2; % num_channels -header.chunksize = header.chunksize + 2; % num_taps -header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im - -IR.header = header; -FastConv_SHD_IR_HOA3 = IR; - -% SD HRIRs -IR = FastConv_SD_IR; -[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR); - -header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV', 'BINAURAL_INPUT_AUDIO_CONFIG_COMBINED'); -header.chunksize = header.chunksize + 4; % latency_s -header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS -header.chunksize = header.chunksize + 2; % num_channels -header.chunksize = header.chunksize + 2; % num_taps -header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im - -IR.header = header; -FastConv_SD_IR = IR; - -% SD BRIRs -IR = FastConv_SD_BRIR; -[~, binaural_convbands, num_channels, ~] = size(IR.IR); -cldfb_no_channels_max = IR.rev_param.kAna; - -header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM', 'BINAURAL_INPUT_AUDIO_CONFIG_COMBINED'); -header.chunksize = header.chunksize + 4; % latency_s -header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS -header.chunksize = header.chunksize + 2; % num_channels -header.chunksize = header.chunksize + 2; % num_taps -header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * IR.rev_param.NFilter * 4 ); % HRTF L/R Re/Im -header.chunksize = header.chunksize + 2; % CLDFB_NO_CHANNELS_MAX -header.chunksize = header.chunksize + cldfb_no_channels_max * 4; % rt60 -header.chunksize = header.chunksize + cldfb_no_channels_max * 4; % nrgLr - -IR.header = header; -FastConv_SD_BRIR = IR; - -% calculate the size of all chunks -HRTFs = {FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR}; -hrtf_data_size = 0; -total_file_size = 0; -for i = 1:length(HRTFs) - hrtf_data_size = hrtf_data_size + HRTFs{i}.header.chunksize; - total_file_size = total_file_size + 4 * 4; % chunk header 4 (u)int32 values -end - -total_file_size = total_file_size + 8; % 'IVASHRTF' (char[8]) -total_file_size = total_file_size + 4; % file size (int32) -total_file_size = total_file_size + 2; % number of HRTFs in file (int16) -total_file_size = total_file_size + 4; % HRTF size (int32) -total_file_size = total_file_size + hrtf_data_size; % size of all HRTF data chunks - -fwrite(f_id, 'IVASHRTF', 'char'); % identifier -fwrite(f_id, total_file_size, 'int32'); % file size -fwrite(f_id, length(HRTFs), 'int16'); % number of HRTFs -fwrite(f_id, hrtf_data_size, 'int32'); % max data size (bytes to read after this header) - -%% HRIRs - -% SHD HRIRs -SHD_HRIRs = {FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3}; -for i = 1:length(SHD_HRIRs) - IR = SHD_HRIRs{i}; - [~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR); - - % write header for this chunk - fwrite(f_id, IR.header.renderer_type, 'int32'); - fwrite(f_id, IR.header.in_fmt, 'int32'); - fwrite(f_id, IR.header.fs, 'int32'); - fwrite(f_id, IR.header.chunksize, 'uint32'); - - fwrite(f_id, IR.latency_s, 'float32'); - fwrite(f_id, binaural_convbands, 'uint16'); - fwrite(f_id, num_channels, 'uint16'); - fwrite(f_id, binaural_ntaps, 'uint16'); - - for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, real(squeeze(IR.IR(1, band, ch, :))), 'float32'); - end - end - for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, imag(squeeze(IR.IR(1, band, ch, :))), 'float32'); - end - end - for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, real(squeeze(IR.IR(2, band, ch, :))), 'float32'); - end - end - for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, imag(squeeze(IR.IR(2, band, ch, :))), 'float32'); - end - end -end - -% SD HRIRs -IR = FastConv_SD_IR; -[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR); - -% write header for this chunk -fwrite(f_id, IR.header.renderer_type, 'int32'); -fwrite(f_id, IR.header.in_fmt, 'int32'); -fwrite(f_id, IR.header.fs, 'int32'); -fwrite(f_id, IR.header.chunksize, 'uint32'); - -fwrite(f_id, IR.latency_s, 'float32'); -fwrite(f_id, binaural_convbands, 'uint16'); -fwrite(f_id, num_channels, 'uint16'); -fwrite(f_id, binaural_ntaps, 'uint16'); -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, real(squeeze(IR.IR(1, band, ch, :))), 'float32'); - end -end -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, imag(squeeze(IR.IR(1, band, ch, :))), 'float32'); - end -end -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, real(squeeze(IR.IR(2, band, ch, :))), 'float32'); - end -end -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, imag(squeeze(IR.IR(2, band, ch, :))), 'float32'); - end -end - - -% SD BRIRs -IR = FastConv_SD_BRIR; -[~, binaural_convbands, num_channels, ~] = size(IR.IR); -cldfb_no_channels_max = IR.rev_param.kAna; - -% write header for this chunk -fwrite(f_id, IR.header.renderer_type, 'int32'); -fwrite(f_id, IR.header.in_fmt, 'int32'); -fwrite(f_id, IR.header.fs, 'int32'); -fwrite(f_id, IR.header.chunksize, 'uint32'); - -fwrite(f_id, IR.rev_param.latency_s, 'float32'); -fwrite(f_id, binaural_convbands, 'uint16'); -fwrite(f_id, num_channels, 'uint16'); -fwrite(f_id, IR.rev_param.NFilter, 'uint16'); -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, real(squeeze(IR.IR(1, band, ch, 1:IR.rev_param.NFilter))), 'float32' ); - end -end -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, imag(squeeze(IR.IR(1, band, ch, 1:IR.rev_param.NFilter))), 'float32' ); - end -end -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, real(squeeze(IR.IR(2, band, ch, 1:IR.rev_param.NFilter))), 'float32' ); - end -end -for band = 1:binaural_convbands - for ch = 1:num_channels - fwrite(f_id, imag(squeeze(IR.IR(2, band, ch, 1:IR.rev_param.NFilter))), 'float32' ); - end -end - -fwrite(f_id, cldfb_no_channels_max, 'uint16'); -fwrite(f_id, IR.rev_param.rt60, 'float32'); -fwrite(f_id, IR.rev_param.nrgLr, 'float32'); - -fclose(f_id); - -end \ No newline at end of file diff --git a/scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt b/scripts/binauralRenderer_interface/ivas_crend_sofa_to_rom_table_converter_readme.txt similarity index 100% rename from scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt rename to scripts/binauralRenderer_interface/ivas_crend_sofa_to_rom_table_converter_readme.txt diff --git a/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m b/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m deleted file mode 100644 index 21c013120aa56957b1311a330feaba46aeca7ca6..0000000000000000000000000000000000000000 --- a/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m +++ /dev/null @@ -1,99 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, -% Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., -% Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, -% Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other -% contributors to this repository. All Rights Reserved. -% -% This software is protected by copyright law and by international treaties. -% The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, -% Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., -% Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, -% Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other -% contributors to this repository retain full ownership rights in their respective contributions in -% the software. This notice grants no license of any kind, including but not limited to patent -% license, nor is any license granted by implication, estoppel or otherwise. -% -% Contributors are required to enter into the IVAS codec Public Collaboration agreement before making -% contributions. -% -% This software is provided "AS IS", without any express or implied warranties. The software is in the -% development stage. It is intended exclusively for experts who have experience with such software and -% solely for the purpose of inspection. All implied warranties of non-infringement, merchantability -% and fitness for a particular purpose are hereby disclaimed and excluded. -% -% Any dispute, controversy or claim arising under or in relation to providing this software shall be -% submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in -% accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and -% the United Nations Convention on Contracts on the International Sales of Goods. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -function write_parametric_binauralizer_binary_data(filename, SHhrtf, T60, late_enes, early_enes) -% -% Writes HRIR & BRIR based data for parametric binauralizer into a binary file. -% -% write_parametric_binauralizer_binary_data(filename, SHhrtf, T60, late_enes, early_enes) -% -% filename : string -% name of the file to be written -% SHhrtf : array of shape (2, 16, 60) i.e., (BINAURAL_CHANNELS, HRTF_SH_CHANNELS, HRTF_NUM_BINS), complex-valued -% HRTF coefficients -% T60 : array of shape (60, 1), i.e., (CLDFB_NO_CHANNELS_MAX, 1), double -% late_enes : array of shape (1, 60), i.e., (1, CLDFB_NO_CHANNELS_MAX), double -% early_enes : array of shape (1, 60), i.e., (1, CLDFB_NO_CHANNELS_MAX), double -% -% -% Output file format: -% HRTFs -% HRTF_SH_CHANNELS => uint16_t -% HRTF_NUM_BINS => uint16_t -% hrtfShCoeffsRe => float[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; -% 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]; -% parametricEarlyPartEneCorrection => float[CLDFB_NO_CHANNELS_MAX]; -% - -[f_id, err_msg] = fopen(filename, 'wb'); - -if f_id == -1 - error('Could not open file %s for writing. Error message:\n%s', filename, err_msg); -end - -% HRTFs -n_chnls_bin = 2; -hrtf_sh_channels = size(SHhrtf, 2); -hrtf_num_bins = size(SHhrtf, 3); - -fwrite(f_id, hrtf_sh_channels, 'uint16'); -fwrite(f_id, hrtf_num_bins, 'uint16'); - -% hrtfShCoeffsRe -for bin_chnl_idx = 1:n_chnls_bin - for hrtf_chnl_idx = 1:hrtf_sh_channels - fwrite(f_id, real(SHhrtf(bin_chnl_idx, hrtf_chnl_idx, :)), 'float32'); % HRTF_NUM_BINS elements - end -end - -% hrtfShCoeffsIm -for bin_chnl_idx = 1:n_chnls_bin - for hrtf_chnl_idx = 1:hrtf_sh_channels - fwrite(f_id, imag(SHhrtf(bin_chnl_idx, hrtf_chnl_idx, :)), 'float32'); % HRTF_NUM_BINS elements - end -end - -% BRIR-based reverb -cldfb_no_channels_max = size(T60, 1); - -fwrite(f_id, cldfb_no_channels_max, 'uint16'); -fwrite(f_id, T60, 'float32'); % parametricReverberationTimes -fwrite(f_id, late_enes, 'float32'); % parametricReverberationEneCorrections -fwrite(f_id, early_enes, 'float32'); % parametricEarlyPartEneCorrection - -fclose(f_id);