From 0082c84ea589d40cdf4c9e4b5a5d9e06dd5cac51 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 5 Dec 2024 17:52:40 +0100 Subject: [PATCH 1/6] issue 1228: Exit the processing when a HRTF binary file with wrong sampling rate is provided; under FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE --- apps/decoder.c | 22 +++++++-- apps/renderer.c | 12 +++++ lib_com/ivas_error.h | 7 +++ lib_com/options.h | 3 +- lib_dec/lib_dec.c | 20 +++++--- lib_dec/lib_dec.h | 2 +- lib_util/hrtf_file_reader.c | 97 ++++++++++++++++++++++++++++++------- lib_util/hrtf_file_reader.h | 28 ++++++++--- 8 files changed, 154 insertions(+), 37 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 55ef28160e..9f3cb51889 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 ) { @@ -3840,7 +3844,11 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } #ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#endif #else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtfBinary->room_reverb_flag, hHrtfBinary->intern_audio_config, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #endif @@ -3866,7 +3874,11 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -3881,11 +3893,15 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } } +#ifdef FIX_1228_HRTF_STATISTICS + 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 f90ec711f6..20da0f967f 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 ) { @@ -968,7 +972,11 @@ int main( } #ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, args.outConfig.audioConfig, args.inConfig.ambisonicsBuses->audioConfig, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, args.outConfig.audioConfig, args.inConfig.ambisonicsBuses->audioConfig, hrtfFileReader ) ) != IVAS_ERR_OK ) +#endif #else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, 0, IVAS_AUDIO_CONFIG_INVALID, hrtfFileReader ) ) != IVAS_ERR_OK ) #endif @@ -990,7 +998,11 @@ int main( goto cleanup; } +#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE + if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, 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 50b6c2d9bc..a6a0e70ea5 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 484de232aa..af0ae671f6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,7 +163,8 @@ #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 */ +#define FIX_1228_HRTF_STATISTICS /* VA: issue 1228: allocate 'HRTFstatistics' handle only when needed */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index a71d801ae7..044c47e3bf 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_HRTF_STATISTICS + 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 3aca0e9b1c..43dcfb33ba 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 ac74c6c49a..2660e0a45c 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -215,7 +215,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 +294,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 +449,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 +726,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 +744,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 +818,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 +881,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 +903,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 +928,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 +942,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 +984,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 +1012,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 +1025,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 +1049,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 } @@ -2097,6 +2131,9 @@ ivas_error load_fastconv_HRTF_from_binary( #else const int16_t room_reverb_flag, /* i : room reverb flag */ const IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ +#endif +#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 */ ) @@ -2174,6 +2211,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 != 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 ); @@ -2216,7 +2260,10 @@ ivas_error load_fastconv_HRTF_from_binary( ivas_error load_parambin_HRTF_from_binary( IVAS_DEC_HRTF_PARAMBIN_HANDLE hHrtfParamBin, /* i/o: Parametric binauralizer HRTF handle */ - const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader 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 */ ) { FILE *f_hrtf; @@ -2265,8 +2312,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 != 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 ); @@ -2311,7 +2366,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 +2485,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 +2499,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 db9b29f65e..ead05ff9e6 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -80,14 +80,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 +105,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 +121,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( @@ -159,6 +167,9 @@ ivas_error load_fastconv_HRTF_from_binary( #else const int16_t room_reverb_flag, /* i : room reverb flag */ IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ +#endif +#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 */ ); @@ -181,7 +192,10 @@ void destroy_fastconv_hrtf( ivas_error load_parambin_HRTF_from_binary( IVAS_DEC_HRTF_PARAMBIN_HANDLE hHrtfParambin, /* i/o: Parambin HRTF handle */ - const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader 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 */ ); -- GitLab From b0b95b90e0d557db1d6a19d8cca3e7ee6b832833 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 6 Dec 2024 10:19:13 +0100 Subject: [PATCH 2/6] fix Param and FastConv cases --- apps/decoder.c | 8 -------- apps/renderer.c | 8 -------- lib_util/hrtf_file_reader.c | 12 +++--------- lib_util/hrtf_file_reader.h | 8 +------- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 9f3cb51889..15b5d69822 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3844,11 +3844,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } #ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM -#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE - if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) -#else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) -#endif #else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtfBinary->room_reverb_flag, hHrtfBinary->intern_audio_config, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) #endif @@ -3874,11 +3870,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } -#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE - if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) -#else if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) -#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { diff --git a/apps/renderer.c b/apps/renderer.c index 20da0f967f..22ffa4838d 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -972,11 +972,7 @@ int main( } #ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM -#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE - if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, args.outConfig.audioConfig, args.inConfig.ambisonicsBuses->audioConfig, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK ) -#else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, args.outConfig.audioConfig, args.inConfig.ambisonicsBuses->audioConfig, hrtfFileReader ) ) != IVAS_ERR_OK ) -#endif #else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, 0, IVAS_AUDIO_CONFIG_INVALID, hrtfFileReader ) ) != IVAS_ERR_OK ) #endif @@ -998,11 +994,7 @@ int main( goto cleanup; } -#ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE - if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK ) -#else if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hrtfFileReader ) ) != IVAS_ERR_OK ) -#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 2660e0a45c..a50b89e70f 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -2131,9 +2131,6 @@ ivas_error load_fastconv_HRTF_from_binary( #else const int16_t room_reverb_flag, /* i : room reverb flag */ const IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ -#endif -#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 */ ) @@ -2212,7 +2209,7 @@ ivas_error load_fastconv_HRTF_from_binary( #endif { #ifdef FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE - if ( hrtf_header.frequency != sampleRate ) + if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ { return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } @@ -2260,10 +2257,7 @@ ivas_error load_fastconv_HRTF_from_binary( ivas_error load_parambin_HRTF_from_binary( IVAS_DEC_HRTF_PARAMBIN_HANDLE hHrtfParamBin, /* i/o: Parametric binauralizer 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 */ + const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ) { FILE *f_hrtf; @@ -2316,7 +2310,7 @@ ivas_error load_parambin_HRTF_from_binary( 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 != sampleRate ) + if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ { return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index ead05ff9e6..b61c0847ba 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -167,9 +167,6 @@ ivas_error load_fastconv_HRTF_from_binary( #else const int16_t room_reverb_flag, /* i : room reverb flag */ IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ -#endif -#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 */ ); @@ -192,10 +189,7 @@ void destroy_fastconv_hrtf( ivas_error load_parambin_HRTF_from_binary( IVAS_DEC_HRTF_PARAMBIN_HANDLE hHrtfParambin, /* i/o: Parambin 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 */ + const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ); -- GitLab From 214277ba0f53b77192149b945817bde292951123 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 6 Dec 2024 12:18:52 +0100 Subject: [PATCH 3/6] update readme files to match the naming conventions and current status --- scripts/binauralRenderer_interface/README.md | 13 +++---------- ...as_crend_sofa_to_rom_table_converter_readme.txt} | 0 2 files changed, 3 insertions(+), 10 deletions(-) rename scripts/binauralRenderer_interface/{mixer_conv_sofa_to_rom_table_converter_readme.txt => ivas_crend_sofa_to_rom_table_converter_readme.txt} (100%) diff --git a/scripts/binauralRenderer_interface/README.md b/scripts/binauralRenderer_interface/README.md index cedfb9841e..822d723797 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/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 -- GitLab From 245b62947a90b26514d309d586f7d1caaa944624 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 6 Dec 2024 12:21:44 +0100 Subject: [PATCH 4/6] remove obsolete MATLAB scripts --- .../fastconv/write_fastconv_binary_data_old.m | 294 ------------------ ...rite_parametric_binauralizer_binary_data.m | 99 ------ 2 files changed, 393 deletions(-) delete mode 100644 scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_old.m delete mode 100644 scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m 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 3371eef834..0000000000 --- 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/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 21c013120a..0000000000 --- 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); -- GitLab From 4c0c556b9739e531efe6402ded5fa04998157ef7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 6 Dec 2024 12:24:40 +0100 Subject: [PATCH 5/6] define BINAURAL_INPUT_AUDIO_CONFIG enum only at one place --- lib_util/hrtf_file_reader.c | 13 ------------- lib_util/hrtf_file_reader.h | 15 +++++++++++++++ .../generate_tables_from_rom_to_bin.c | 15 --------------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index a50b89e70f..f3517edd30 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() diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index b61c0847ba..b27a42cf9f 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; 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 c9a5d6df5c..a7cc7d7574 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, -- GitLab From a7365b5b794543f4306a1ac26f7d20d81a5e77bd Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 6 Dec 2024 12:26:31 +0100 Subject: [PATCH 6/6] merge FIX_1228_HRTF_STATISTICS into FIX_1228_SAMPLING_RATE_MISMATCH_IN_HRTF_FILE --- apps/decoder.c | 2 +- lib_com/options.h | 2 +- lib_dec/lib_dec.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 15b5d69822..4db62d0f1e 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3885,7 +3885,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } } -#ifdef FIX_1228_HRTF_STATISTICS +#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 ) diff --git a/lib_com/options.h b/lib_com/options.h index af0ae671f6..059877b9b2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -164,7 +164,7 @@ #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 */ -#define FIX_1228_HRTF_STATISTICS /* VA: issue 1228: allocate 'HRTFstatistics' handle only when needed */ + /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 044c47e3bf..8ac62b87c3 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2867,7 +2867,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( } } -#ifdef FIX_1228_HRTF_STATISTICS +#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 ) -- GitLab