From 76fb415dcca502717ea19bde58359b8880ae47ae Mon Sep 17 00:00:00 2001 From: marc emerit Date: Wed, 3 Dec 2025 16:57:04 +0100 Subject: [PATCH 1/4] ready to merge --- lib_com/options.h | 2 +- lib_rend/ivas_crend.c | 29 +++++++++++++++--- lib_util/hrtf_file_reader.c | 59 ++++++++++++++++++++++++++++++++----- lib_util/hrtf_file_reader.h | 2 +- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 11f9b1f26e..b693d06fa4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,7 +162,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ - +#define FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND /* OR : Fix issue basop 2201 hrtf_file_reader crend differs between basop ivas-main and ivas-float-update */ /* #################### End BE switches ################################## */ diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 9134667502..d7a5b8db2d 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -65,9 +65,14 @@ ivas_error ivas_Crend_hrtf_init( } hHrtf->latency_s = 0; +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + hHrtf->gain_lfe = 0; +#endif hHrtf->max_num_ir = 0; hHrtf->max_num_iterations = 0; +#ifndef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND hHrtf->gain_lfe = 0; +#endif hHrtf->index_frequency_max_diffuse = 0; hHrtf->same_inv_diffuse_weight = 1; @@ -80,6 +85,11 @@ ivas_error ivas_Crend_hrtf_init( hHrtf->pIndex_frequency_max[i][j] = NULL; hHrtf->pOut_to_bin_re[i][j] = NULL; hHrtf->pOut_to_bin_im[i][j] = NULL; +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + hHrtf->pOut_to_bin_re_dyn[i][j] = NULL; + hHrtf->pOut_to_bin_im_dyn[i][j] = NULL; + hHrtf->pIndex_frequency_max_dyn[i][j] = NULL; +#endif } } @@ -89,6 +99,11 @@ ivas_error ivas_Crend_hrtf_init( hHrtf->pIndex_frequency_max_diffuse[j] = NULL; hHrtf->pOut_to_bin_diffuse_re[j] = NULL; hHrtf->pOut_to_bin_diffuse_im[j] = NULL; +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + hHrtf->pIndex_frequency_max_diffuse_dyn[j] = NULL; + hHrtf->pOut_to_bin_diffuse_re_dyn[j] = NULL; + hHrtf->pOut_to_bin_diffuse_im_dyn[j] = NULL; +#endif } hHrtf->init_from_rom = 1; @@ -818,6 +833,9 @@ static ivas_error ivas_rend_initCrend( if ( hHrtf->inv_diffuse_weight[0][i] != hHrtf->inv_diffuse_weight[1][i] ) { hHrtf->same_inv_diffuse_weight = 0; +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + break; +#endif } } } @@ -1264,8 +1282,11 @@ ivas_error ivas_rend_openCrend( hCrend->freq_buffer_re_diffuse[1] = NULL; hCrend->freq_buffer_im_diffuse[1] = NULL; } - +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + max_total_ir_len = (int32_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length; +#else max_total_ir_len = (int16_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length; +#endif if ( max_total_ir_len > 0 ) { if ( ( hCrend->lfe_delay_line = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL ) @@ -1798,9 +1819,9 @@ ivas_error ivas_rend_crendProcessSubframe( if ( hDecoderConfig && combinedOrientationEnabled ) { /* Rotation in SHD for: - MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL - SBA SPAR -> BINAURAL or BINAURAL_ROOM - */ + MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL + SBA SPAR -> BINAURAL or BINAURAL_ROOM + */ if ( inConfig == IVAS_AUDIO_CONFIG_FOA || inConfig == IVAS_AUDIO_CONFIG_HOA2 || inConfig == IVAS_AUDIO_CONFIG_HOA3 ) { rotateFrame_shd( hCombinedOrientationData, tc_local, subframe_len, *hIntSetup, 0 ); diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 164120d79d..6458e22489 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -803,6 +803,9 @@ static ivas_error load_reverb_from_binary( { if ( hrtf_header.frequency != sampleRate ) { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } } @@ -815,8 +818,7 @@ static ivas_error load_reverb_from_binary( hHrtfStatistics->average_energy_l_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->average_energy_r_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->inter_aural_coherence_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); - - if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_r_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) + if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } @@ -895,16 +897,21 @@ static ivas_error TDREND_MIX_LoadHRTF( ivas_hrtfs_header_t hrtf_header; int32_t hrtf_data_size_max; char *hrtf_data; - +#ifndef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND header_check_result = IVAS_ERR_OK; - +#endif if ( f_hrtf == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + header_check_result = IVAS_ERR_OK; +#endif 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 ) { @@ -938,6 +945,9 @@ static ivas_error TDREND_MIX_LoadHRTF( hrtf_data = (char *) malloc( hrtf_data_size_max ); if ( hrtf_data == NULL ) { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } @@ -945,11 +955,17 @@ static ivas_error TDREND_MIX_LoadHRTF( { if ( read_hrtf_binary_header( &hrtf_header, f_hrtf ) != IVAS_ERR_OK ) { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "HRTF binary file not compliant (number of HRTF)" ); } if ( ( header_check_result = check_hrtf_binary_header( &hrtf_header ) ) != IVAS_ERR_OK ) { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return header_check_result; } @@ -958,6 +974,9 @@ static ivas_error TDREND_MIX_LoadHRTF( { if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } } @@ -965,6 +984,9 @@ static ivas_error TDREND_MIX_LoadHRTF( { if ( hrtf_header.frequency != sampleRate ) { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } } @@ -1748,6 +1770,9 @@ ivas_error load_fastconv_HRTF_from_binary( { if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } @@ -1757,6 +1782,7 @@ ivas_error load_fastconv_HRTF_from_binary( return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } + /* Create the HRTF reading the raw data from the binary file */ if ( ( create_fastconv_HRTF_from_rawdata( &hHrtfFastConv, hrtf_data, hrtf_header.rend_type, hrtf_header.input_cfg ) ) != IVAS_ERR_OK ) { free( hrtf_data ); @@ -1845,6 +1871,9 @@ ivas_error load_parambin_HRTF_from_binary( { if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } @@ -1902,6 +1931,9 @@ ivas_error load_Crend_HRTF_from_binary( ivas_hrtfs_file_header_t hrtfs_file_header; int16_t hrtf_id; bool load = false; +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + int16_t asCrend = 0; +#endif BINAURAL_INPUT_AUDIO_CONFIG hrtf_set_binaural_cfg; /* convert audio config. to HRTF binaural config */ @@ -1962,6 +1994,9 @@ ivas_error load_Crend_HRTF_from_binary( { if ( hrtf_header.frequency != sampleRate ) { +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + free( hrtf_data ); +#endif return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } @@ -1976,7 +2011,9 @@ ivas_error load_Crend_HRTF_from_binary( free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); } - +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + asCrend = 1; +#endif break; /* read just one set */ } else @@ -1986,8 +2023,16 @@ ivas_error load_Crend_HRTF_from_binary( } free( hrtf_data ); - - return IVAS_ERR_OK; +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND + if ( asCrend ) + { + return IVAS_ERR_OK; + } + else + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + } +#endif } diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index 938b5c1595..3088d38315 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -105,7 +105,7 @@ ivas_error load_TDrend_HRTF_binary( ); /*---------------------------------------------------------------------* - * load_reverb_from_binary() + * load_reverb_binary() * * Load reverb binary data into the HRTF handle *---------------------------------------------------------------------*/ -- GitLab From 2b2ecd92dbe11192bdd7c1d2b76aea3e2c4a881d Mon Sep 17 00:00:00 2001 From: marc emerit Date: Thu, 4 Dec 2025 11:17:49 +0100 Subject: [PATCH 2/4] bug fix --- lib_util/hrtf_file_reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 6458e22489..f7cd778bbf 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -818,7 +818,7 @@ static ivas_error load_reverb_from_binary( hHrtfStatistics->average_energy_l_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->average_energy_r_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->inter_aural_coherence_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); - if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) + if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_r_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } -- GitLab From b89b867472f47e361dde5b78a541d36c8eb657a1 Mon Sep 17 00:00:00 2001 From: marc emerit Date: Thu, 4 Dec 2025 11:21:13 +0100 Subject: [PATCH 3/4] add missing switch --- lib_util/hrtf_file_reader.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index f7cd778bbf..9985632dd2 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -818,7 +818,11 @@ static ivas_error load_reverb_from_binary( hHrtfStatistics->average_energy_l_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->average_energy_r_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); hHrtfStatistics->inter_aural_coherence_dyn = (float *) malloc( lr_iac_len * sizeof( float ) ); +#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_r_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) +#else + if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } -- GitLab From e2981fb44b68d4c64a618b55ff4960e41323075f Mon Sep 17 00:00:00 2001 From: marc emerit Date: Thu, 4 Dec 2025 14:27:46 +0100 Subject: [PATCH 4/4] fix unncessary free --- lib_util/hrtf_file_reader.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 9985632dd2..cb445dacab 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -949,9 +949,6 @@ static ivas_error TDREND_MIX_LoadHRTF( hrtf_data = (char *) malloc( hrtf_data_size_max ); if ( hrtf_data == NULL ) { -#ifdef FIX_BASOP_2201_HARMONIZE_HRTF_FILE_READER_CREND - free( hrtf_data ); -#endif return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } -- GitLab