Loading scripts/binauralRenderer_interface/CMakeLists.txt +4 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,9 @@ set(SOURCE_FILES_C ${IVAS_TRUNK_COM_PATH}/tools.c ${IVAS_TRUNK_COM_PATH}/tns_base.c ${IVAS_TRUNK_UTIL_PATH}/cmdl_tools.c ${IVAS_TRUNK_REND_PATH}/ivas_reverb_filter_design.c ${IVAS_TRUNK_REND_PATH}/ivas_reverb_fft_filter.c ${IVAS_TRUNK_REND_PATH}/ivas_rom_rend.c ) set(SOURCE_FILES_H Loading @@ -139,6 +142,7 @@ set(SOURCE_FILES_H ${IVAS_TRUNK_COM_PATH}/prot.h ${IVAS_TRUNK_COM_PATH}/ivas_prot.h ${IVAS_TRUNK_COM_PATH}/common_api_types.h ${IVAS_TRUNK_REND_PATH}/ivas_rom_rend.h ) add_library(${PROJECT_NAME}_lib STATIC ${SOURCE_FILES_C} ${SOURCE_FILES_H}) Loading scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c +1 −1 Original line number Diff line number Diff line Loading @@ -1036,7 +1036,7 @@ char *create_hrtf_tdrend( int32_t frequency, int32_t *hrtf_size ) char *create_hrtf_fastconv( RENDERER_TYPE rend_type, BINAURAL_INPUT_AUDIO_CONFIG input_cfg, int32_t frequency, int32_t *hrtf_size ) { char *fastconv_hrtf = NULL, *fastconv_hrtf_wptr; uint32_t fastconv_hrtf_data_size, fastconv_hrtf_header_size; int32_t fastconv_hrtf_data_size; char hrtf_identifier[8] = ""; int32_t hrtf_total_file_size = 0, hrtf_data_size = 0; int16_t nbHrft = 0, ind; Loading scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c +71 −2 Original line number Diff line number Diff line Loading @@ -44,9 +44,11 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" #include "lib_dec.h" #include "ivas_rom_com.h" #include "ivas_rom_rend.h" #include "cmdl_tools.h" #include "ivas_crend_binaural_filter_design.h" #ifdef M Loading Loading @@ -101,6 +103,7 @@ char *binary_file_path = NULL; struct ivas_layout_config { AUDIO_CONFIG audio_config; char name[32]; int nb_channel; float azi[MAX_CICP_CHANNELS]; Loading Loading @@ -989,7 +992,7 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, bool no_optim ) #else struct MYSOFA_ARRAY *latency_s = NULL; int err; int err, ui; struct MYSOFA_EASY *hrtf = (struct MYSOFA_EASY *) malloc( sizeof( struct MYSOFA_EASY ) ); if ( !hrtf ) return 1234; Loading Loading @@ -1560,6 +1563,70 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, bool no_optim ) ivas_set_hrtf_fr( &hrtf_data, ivas_hrtf, frame_len ); } int16_t nr_out_ch, hrtf_idx, offset, iter_idx; float *pHrtf_set_l_re[MAX_INTERN_CHANNELS] = { 0 }; float *pHrtf_set_l_im[MAX_INTERN_CHANNELS] = { 0 }; float *pHrtf_set_r_re[MAX_INTERN_CHANNELS] = { 0 }; float *pHrtf_set_r_im[MAX_INTERN_CHANNELS] = { 0 }; int16_t nr_fc_fft_filter = LR_IAC_LENGTH_NR_FC; float p_avg_lr[LR_IAC_LENGTH_NR_FC * 2] = { 0 }; float pCoherence[LR_IAC_LENGTH_NR_FC] = { 0 }; /* use crend hrtf filters */ /* Compute HRTF set properties: average left/right energies, IA coherence */ /* First, find the offset of the frequency-domain data for the 1st frame and assign HRTF pointers */ if ( lscfg.isloudspeaker ) { AUDIO_CONFIG inConfig = AUDIO_CONFIG_5_1; int tmp, numIr = 5; for ( nr_out_ch = 0; nr_out_ch < BINAURAL_CHANNELS; nr_out_ch++ ) { for ( hrtf_idx = 0; hrtf_idx < numIr; hrtf_idx++ ) { if ( inConfig == AUDIO_CONFIG_5_1 ) { tmp = channelIndex_CICP6[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_7_1 ) { tmp = channelIndex_CICP12[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_5_1_2 ) { tmp = channelIndex_CICP14[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_5_1_4 ) { tmp = channelIndex_CICP16[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_7_1_4 ) { tmp = channelIndex_CICP19[hrtf_idx]; } offset = 0; for ( iter_idx = 0; iter_idx < hrtf_data.num_iterations[tmp][nr_out_ch] - 1; iter_idx++ ) { offset += hrtf_data.pIndex_frequency_max[tmp][nr_out_ch][iter_idx]; } if ( nr_out_ch == 0 ) { pHrtf_set_l_re[hrtf_idx] = &hrtf_data.pOut_to_bin_re[tmp][0][offset]; pHrtf_set_l_im[hrtf_idx] = &hrtf_data.pOut_to_bin_im[tmp][0][offset]; } else { pHrtf_set_r_re[hrtf_idx] = &hrtf_data.pOut_to_bin_re[tmp][1][offset]; pHrtf_set_r_im[hrtf_idx] = &hrtf_data.pOut_to_bin_im[tmp][1][offset]; } } } ivas_reverb_get_hrtf_set_properties( pHrtf_set_l_re, pHrtf_set_l_im, pHrtf_set_r_re, pHrtf_set_r_im, inConfig, numIr, frame_len, nr_fc_fft_filter, p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence ); } hrtf_data.latency_s += 0.000000001f; if ( ( hrtf_data.num_iterations[0][0] > 2 ) ) Loading Loading @@ -2470,6 +2537,8 @@ void get_ls_layout_config( AUDIO_CONFIG ls_layout_config, struct ivas_layout_con memset( ls_struct, 0, sizeof( struct ivas_layout_config ) ); ls_struct->audio_config = ls_layout_config; switch ( ls_layout_config ) { case AUDIO_CONFIG_FOA: Loading scripts/binauralRenderer_interface/generate_ivas_binauralizer_tables_from_sofa.m +2 −0 Original line number Diff line number Diff line Loading @@ -70,7 +70,9 @@ end hrir_file = fullfile( hrir_path, hrir_file_name); brir_file = fullfile( brir_path, brir_file_name); %% generate reverb rom values data_struct = generate_lr_energies_and_iac(hrir_path, hrir_file_name); %% generate td binauralizer rom values Loading scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/compute_lr_energies_and_iac.m 0 → 100644 +101 −0 Original line number Diff line number Diff line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (C) 2022-2023 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 [left_avg_power, right_avg_power, ia_coherence] = compute_lr_energies_and_iac(HRTF_mdfts, in_freq_count, out_freq_count) % Compute left/right and coherence of entire HRTF dataset % % HRTF_mdfts - HRTF dataset in frequency domain. % in_freq_count - number of HRTF bins % out_freq_count - number of bins in target for energies and coherence % values hrtf_count = size(HRTF_mdfts,3); left_avg_power = zeros(1, out_freq_count); right_avg_power = zeros(1, out_freq_count); ia_coherence = zeros(1, out_freq_count); inp_freq_step = 0.5 / in_freq_count; inp_freq_offset = 0.5 * inp_freq_step; out_freq_step = 0.5 / (out_freq_count - 1); base_idx = 1; relative_pos = 0; % loop over output frequency bins for out_bin_idx=0:out_freq_count-1 norm_freqs = out_freq_step * out_bin_idx; tbl_index = ( norm_freqs - inp_freq_offset ) / inp_freq_step; if (tbl_index <= 0.0) base_idx = 0; relative_pos = 0; else base_idx = int16(floor(tbl_index)); relative_pos = tbl_index - double(base_idx); % extrapolation (above last bin), choose nearest if(base_idx > (in_freq_count-2)) base_idx = in_freq_count-2; relative_pos = 1; end end base_idx = base_idx +1; IA_coherence = zeros(2,1); avg_pwr_lr = zeros(2,2); for hrtf_idx=1:hrtf_count lr_pair_0 = HRTF_mdfts(base_idx,:,hrtf_idx); lr_pair_1 = HRTF_mdfts(base_idx + 1,:,hrtf_idx); avg_pwr_lr(1,:) = avg_pwr_lr(1,:) + real(lr_pair_0).^2 + imag(lr_pair_0).^2; avg_pwr_lr(2,:) = avg_pwr_lr(2,:) + real(lr_pair_1).^2 + imag(lr_pair_1).^2; IA_coherence(1,1) = IA_coherence(1,1) + real(lr_pair_0(1)) * real(lr_pair_0(2)) + imag(lr_pair_0(1)) * imag(lr_pair_0(2)); IA_coherence(2,1) = IA_coherence(2,1) + real(lr_pair_1(1)) * real(lr_pair_1(2)) + imag(lr_pair_1(1)) * imag(lr_pair_1(2)); end % compute averages and IA coherence avg_pwr_lr = avg_pwr_lr/hrtf_count; IA_coherence = IA_coherence/hrtf_count; IA_coherence(1,1) = IA_coherence(1,1) / sqrt((avg_pwr_lr(1,1) * avg_pwr_lr(1,2))); IA_coherence(2,1) = IA_coherence(2,1) / sqrt((avg_pwr_lr(2,1) * avg_pwr_lr(2,2))); % Limiting to (0...1) range in case of small numerical errors or negative values for i=1:2 IA_coherence(i,1) = min(IA_coherence(i,1),1); IA_coherence(i,1) = max(IA_coherence(i,1),0); end % Computing weighted average of 2 nearest values (1 below + 1 above) for linear interpolation weight_1st = 1 - relative_pos; left_avg_power(out_bin_idx + 1) = weight_1st * avg_pwr_lr(1,1) + relative_pos * avg_pwr_lr(2,1); right_avg_power(out_bin_idx + 1) = weight_1st * avg_pwr_lr(1,2) + relative_pos * avg_pwr_lr(2,2); ia_coherence(out_bin_idx + 1) = weight_1st * IA_coherence(1,1) + relative_pos * IA_coherence(2,1); end end No newline at end of file Loading
scripts/binauralRenderer_interface/CMakeLists.txt +4 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,9 @@ set(SOURCE_FILES_C ${IVAS_TRUNK_COM_PATH}/tools.c ${IVAS_TRUNK_COM_PATH}/tns_base.c ${IVAS_TRUNK_UTIL_PATH}/cmdl_tools.c ${IVAS_TRUNK_REND_PATH}/ivas_reverb_filter_design.c ${IVAS_TRUNK_REND_PATH}/ivas_reverb_fft_filter.c ${IVAS_TRUNK_REND_PATH}/ivas_rom_rend.c ) set(SOURCE_FILES_H Loading @@ -139,6 +142,7 @@ set(SOURCE_FILES_H ${IVAS_TRUNK_COM_PATH}/prot.h ${IVAS_TRUNK_COM_PATH}/ivas_prot.h ${IVAS_TRUNK_COM_PATH}/common_api_types.h ${IVAS_TRUNK_REND_PATH}/ivas_rom_rend.h ) add_library(${PROJECT_NAME}_lib STATIC ${SOURCE_FILES_C} ${SOURCE_FILES_H}) Loading
scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c +1 −1 Original line number Diff line number Diff line Loading @@ -1036,7 +1036,7 @@ char *create_hrtf_tdrend( int32_t frequency, int32_t *hrtf_size ) char *create_hrtf_fastconv( RENDERER_TYPE rend_type, BINAURAL_INPUT_AUDIO_CONFIG input_cfg, int32_t frequency, int32_t *hrtf_size ) { char *fastconv_hrtf = NULL, *fastconv_hrtf_wptr; uint32_t fastconv_hrtf_data_size, fastconv_hrtf_header_size; int32_t fastconv_hrtf_data_size; char hrtf_identifier[8] = ""; int32_t hrtf_total_file_size = 0, hrtf_data_size = 0; int16_t nbHrft = 0, ind; Loading
scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c +71 −2 Original line number Diff line number Diff line Loading @@ -44,9 +44,11 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" #include "lib_dec.h" #include "ivas_rom_com.h" #include "ivas_rom_rend.h" #include "cmdl_tools.h" #include "ivas_crend_binaural_filter_design.h" #ifdef M Loading Loading @@ -101,6 +103,7 @@ char *binary_file_path = NULL; struct ivas_layout_config { AUDIO_CONFIG audio_config; char name[32]; int nb_channel; float azi[MAX_CICP_CHANNELS]; Loading Loading @@ -989,7 +992,7 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, bool no_optim ) #else struct MYSOFA_ARRAY *latency_s = NULL; int err; int err, ui; struct MYSOFA_EASY *hrtf = (struct MYSOFA_EASY *) malloc( sizeof( struct MYSOFA_EASY ) ); if ( !hrtf ) return 1234; Loading Loading @@ -1560,6 +1563,70 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, bool no_optim ) ivas_set_hrtf_fr( &hrtf_data, ivas_hrtf, frame_len ); } int16_t nr_out_ch, hrtf_idx, offset, iter_idx; float *pHrtf_set_l_re[MAX_INTERN_CHANNELS] = { 0 }; float *pHrtf_set_l_im[MAX_INTERN_CHANNELS] = { 0 }; float *pHrtf_set_r_re[MAX_INTERN_CHANNELS] = { 0 }; float *pHrtf_set_r_im[MAX_INTERN_CHANNELS] = { 0 }; int16_t nr_fc_fft_filter = LR_IAC_LENGTH_NR_FC; float p_avg_lr[LR_IAC_LENGTH_NR_FC * 2] = { 0 }; float pCoherence[LR_IAC_LENGTH_NR_FC] = { 0 }; /* use crend hrtf filters */ /* Compute HRTF set properties: average left/right energies, IA coherence */ /* First, find the offset of the frequency-domain data for the 1st frame and assign HRTF pointers */ if ( lscfg.isloudspeaker ) { AUDIO_CONFIG inConfig = AUDIO_CONFIG_5_1; int tmp, numIr = 5; for ( nr_out_ch = 0; nr_out_ch < BINAURAL_CHANNELS; nr_out_ch++ ) { for ( hrtf_idx = 0; hrtf_idx < numIr; hrtf_idx++ ) { if ( inConfig == AUDIO_CONFIG_5_1 ) { tmp = channelIndex_CICP6[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_7_1 ) { tmp = channelIndex_CICP12[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_5_1_2 ) { tmp = channelIndex_CICP14[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_5_1_4 ) { tmp = channelIndex_CICP16[hrtf_idx]; } else if ( inConfig == AUDIO_CONFIG_7_1_4 ) { tmp = channelIndex_CICP19[hrtf_idx]; } offset = 0; for ( iter_idx = 0; iter_idx < hrtf_data.num_iterations[tmp][nr_out_ch] - 1; iter_idx++ ) { offset += hrtf_data.pIndex_frequency_max[tmp][nr_out_ch][iter_idx]; } if ( nr_out_ch == 0 ) { pHrtf_set_l_re[hrtf_idx] = &hrtf_data.pOut_to_bin_re[tmp][0][offset]; pHrtf_set_l_im[hrtf_idx] = &hrtf_data.pOut_to_bin_im[tmp][0][offset]; } else { pHrtf_set_r_re[hrtf_idx] = &hrtf_data.pOut_to_bin_re[tmp][1][offset]; pHrtf_set_r_im[hrtf_idx] = &hrtf_data.pOut_to_bin_im[tmp][1][offset]; } } } ivas_reverb_get_hrtf_set_properties( pHrtf_set_l_re, pHrtf_set_l_im, pHrtf_set_r_re, pHrtf_set_r_im, inConfig, numIr, frame_len, nr_fc_fft_filter, p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence ); } hrtf_data.latency_s += 0.000000001f; if ( ( hrtf_data.num_iterations[0][0] > 2 ) ) Loading Loading @@ -2470,6 +2537,8 @@ void get_ls_layout_config( AUDIO_CONFIG ls_layout_config, struct ivas_layout_con memset( ls_struct, 0, sizeof( struct ivas_layout_config ) ); ls_struct->audio_config = ls_layout_config; switch ( ls_layout_config ) { case AUDIO_CONFIG_FOA: Loading
scripts/binauralRenderer_interface/generate_ivas_binauralizer_tables_from_sofa.m +2 −0 Original line number Diff line number Diff line Loading @@ -70,7 +70,9 @@ end hrir_file = fullfile( hrir_path, hrir_file_name); brir_file = fullfile( brir_path, brir_file_name); %% generate reverb rom values data_struct = generate_lr_energies_and_iac(hrir_path, hrir_file_name); %% generate td binauralizer rom values Loading
scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/compute_lr_energies_and_iac.m 0 → 100644 +101 −0 Original line number Diff line number Diff line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (C) 2022-2023 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 [left_avg_power, right_avg_power, ia_coherence] = compute_lr_energies_and_iac(HRTF_mdfts, in_freq_count, out_freq_count) % Compute left/right and coherence of entire HRTF dataset % % HRTF_mdfts - HRTF dataset in frequency domain. % in_freq_count - number of HRTF bins % out_freq_count - number of bins in target for energies and coherence % values hrtf_count = size(HRTF_mdfts,3); left_avg_power = zeros(1, out_freq_count); right_avg_power = zeros(1, out_freq_count); ia_coherence = zeros(1, out_freq_count); inp_freq_step = 0.5 / in_freq_count; inp_freq_offset = 0.5 * inp_freq_step; out_freq_step = 0.5 / (out_freq_count - 1); base_idx = 1; relative_pos = 0; % loop over output frequency bins for out_bin_idx=0:out_freq_count-1 norm_freqs = out_freq_step * out_bin_idx; tbl_index = ( norm_freqs - inp_freq_offset ) / inp_freq_step; if (tbl_index <= 0.0) base_idx = 0; relative_pos = 0; else base_idx = int16(floor(tbl_index)); relative_pos = tbl_index - double(base_idx); % extrapolation (above last bin), choose nearest if(base_idx > (in_freq_count-2)) base_idx = in_freq_count-2; relative_pos = 1; end end base_idx = base_idx +1; IA_coherence = zeros(2,1); avg_pwr_lr = zeros(2,2); for hrtf_idx=1:hrtf_count lr_pair_0 = HRTF_mdfts(base_idx,:,hrtf_idx); lr_pair_1 = HRTF_mdfts(base_idx + 1,:,hrtf_idx); avg_pwr_lr(1,:) = avg_pwr_lr(1,:) + real(lr_pair_0).^2 + imag(lr_pair_0).^2; avg_pwr_lr(2,:) = avg_pwr_lr(2,:) + real(lr_pair_1).^2 + imag(lr_pair_1).^2; IA_coherence(1,1) = IA_coherence(1,1) + real(lr_pair_0(1)) * real(lr_pair_0(2)) + imag(lr_pair_0(1)) * imag(lr_pair_0(2)); IA_coherence(2,1) = IA_coherence(2,1) + real(lr_pair_1(1)) * real(lr_pair_1(2)) + imag(lr_pair_1(1)) * imag(lr_pair_1(2)); end % compute averages and IA coherence avg_pwr_lr = avg_pwr_lr/hrtf_count; IA_coherence = IA_coherence/hrtf_count; IA_coherence(1,1) = IA_coherence(1,1) / sqrt((avg_pwr_lr(1,1) * avg_pwr_lr(1,2))); IA_coherence(2,1) = IA_coherence(2,1) / sqrt((avg_pwr_lr(2,1) * avg_pwr_lr(2,2))); % Limiting to (0...1) range in case of small numerical errors or negative values for i=1:2 IA_coherence(i,1) = min(IA_coherence(i,1),1); IA_coherence(i,1) = max(IA_coherence(i,1),0); end % Computing weighted average of 2 nearest values (1 below + 1 above) for linear interpolation weight_1st = 1 - relative_pos; left_avg_power(out_bin_idx + 1) = weight_1st * avg_pwr_lr(1,1) + relative_pos * avg_pwr_lr(2,1); right_avg_power(out_bin_idx + 1) = weight_1st * avg_pwr_lr(1,2) + relative_pos * avg_pwr_lr(2,2); ia_coherence(out_bin_idx + 1) = weight_1st * IA_coherence(1,1) + relative_pos * IA_coherence(2,1); end end No newline at end of file