Loading scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_old.mdeleted 100644 → 0 +0 −294 Original line number Diff line number Diff line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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 scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.mdeleted 100644 → 0 +0 −99 Original line number Diff line number Diff line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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); Loading
scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_old.mdeleted 100644 → 0 +0 −294 Original line number Diff line number Diff line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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
scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.mdeleted 100644 → 0 +0 −99 Original line number Diff line number Diff line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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);