Skip to content
clear -regexp ^((?!writeRomFileOutput|writeBinaryOutput|writeRomFileFx|makeFxFltBEgenerateBinaryFile|generateBinaryFile|generateCustomBinaryFile|writeEachRendererBinaryOutput|rom_file|bin_file|hrir_file|brir_file|ivas_path|binary_path|output_bin_name|param_bin_file|fastconv_bin_file|td_binary_file|binary_name|rom_path).)*$
clear -regexp ^((?!writeRomFileOutput|makeBE|performDiffuseFieldEq|normalize|writeBinaryOutput|writeRomFileFx|makeFxFltBE|generateBinaryFile|generateCustomBinaryFile|writeEachRendererBinaryOutput|fx_rom_file|rom_file|bin_file|hrir_file|brir_file|ivas_path|binary_path|output_bin_name|param_bin_file|fastconv_bin_file|td_binary_file|binary_name|rom_path).)*$
......@@ -46,6 +46,9 @@ end
if ~exist("writeRomFileOutput",'var')
writeRomFileOutput = true;
end
if ~exist("normalize",'var')
normalize = true;
end
if ~exist("writeRomFileFx",'var')
writeRomFileFx = false;
end
......@@ -61,6 +64,9 @@ end
if ~exist("rom_file",'var')
rom_file = fullfile('.', 'ivas_rom_binauralRenderer.c');
end
if ~exist("fx_rom_file",'var')
fx_rom_file = fullfile('.', 'ivas_rom_binauralRenderer_fx.c');
end
if ~exist("bin_file",'var')
bin_file = fullfile('.', 'fastconv_rom.bin');
end
......@@ -79,30 +85,30 @@ end
%% Generate C-code tables for RENDERER_BINAURAL_FASTCONV (SHD)
if generateCustomBinaryFile
disp('Processing HRIRs (FOA) for FastConv renderer...');
FastConv_SHD_IR_FOA_float = SHD_2_ROM(hrir_file, 1, -1, 5);
FastConv_SHD_IR_FOA_float = SHD_2_ROM(hrir_file, 1, -1, 5, normalize);
disp('Processing HRIRs (HOA2) for FastConv renderer...');
FastConv_SHD_IR_HOA2_float = SHD_2_ROM(hrir_file, 2, -1, 5);
FastConv_SHD_IR_HOA2_float = SHD_2_ROM(hrir_file, 2, -1, 5, normalize);
disp('Processing HRIRs (HOA3) for FastConv renderer...');
FastConv_SHD_IR_HOA3_float = SHD_2_ROM(hrir_file, 3, -1, 5);
FastConv_SHD_IR_HOA3_float = SHD_2_ROM(hrir_file, 3, -1, 5, normalize);
%% Generate C-code tables for RENDERER_BINAURAL_FASTCONV (SD)
disp('Processing HRIRs (SD) for FastConv renderer...');
FastConv_SD_IR_float = SD_2_ROM(hrir_file, 5);
FastConv_SD_IR_float = SD_2_ROM(hrir_file, 5, normalize);
else
disp('Processing HRIRs (FOA) for FastConv renderer...');
FastConv_SHD_IR_FOA_float = SHD_2_ROM(hrir_file, 1, 128);
FastConv_SHD_IR_FOA_float = SHD_2_ROM(hrir_file, 1, 128,3, normalize);
disp('Processing HRIRs (HOA2) for FastConv renderer...');
FastConv_SHD_IR_HOA2_float = SHD_2_ROM(hrir_file, 2, 128);
FastConv_SHD_IR_HOA2_float = SHD_2_ROM(hrir_file, 2, 128, 3,normalize);
disp('Processing HRIRs (HOA3) for FastConv renderer...');
FastConv_SHD_IR_HOA3_float = SHD_2_ROM(hrir_file, 3, 128);
FastConv_SHD_IR_HOA3_float = SHD_2_ROM(hrir_file, 3, 128,3, normalize);
%% Generate C-code tables for RENDERER_BINAURAL_FASTCONV (SD)
disp('Processing HRIRs (SD) for FastConv renderer...');
FastConv_SD_IR_float = SD_2_ROM(hrir_file);
FastConv_SD_IR_float = SD_2_ROM(hrir_file,3,normalize);
end
......@@ -111,6 +117,7 @@ disp('Processing BRIRs (SD) for FastConv renderer...');
FastConv_SD_BRIR_float = generate_BRIR_CLDFB_FASTCONV(brir_file);
if generateCustomBinaryFile == false
FastConv_SD_BRIR_float.rev_param.rt60 = [0.420013, 0.206696, 0.203613, 0.207458, 0.217255, 0.236176, 0.230164, 0.228912, 0.228210, 0.219788, 0.225983, 0.220184, 0.222015, 0.223114, 0.223572, 0.227478, 0.227905, 0.223450, 0.219910, 0.218597, 0.220428, 0.218262, 0.213257, 0.210327, 0.207428, 0.198761, 0.196259, 0.194916, 0.190338, 0.184509, 0.180328, 0.176178, 0.176514, 0.177582, 0.183594, 0.195923, 0.203247, 0.208405, 0.214661, 0.220001, 0.222931, 0.230408, 0.233917, 0.233643, 0.236328, 0.237427, 0.241638, 0.241119, 0.238861, 0.242371, 0.247253, 0.245941, 0.248566, 0.245392, 0.243958, 0.244110, 0.239014, 0.241791, 0.234833, 0.253052];
FastConv_SD_BRIR_float.rev_param.nrgLr = [0.000579833984, 0.000213623047, 0.000244140625, 0.000213623047, 0.000244140625, 0.00152587891, 0.00115966797, 0.00109863281, 0.0012512207, 0.00131225586, 0.00231933594, 0.00244140625, 0.00268554688, 0.00271606445, 0.00262451172, 0.00256347656, 0.00274658203, 0.00271606445, 0.00259399414, 0.00253295898, 0.00341796875, 0.00177001953, 0.0009765625, 0.000701904296, 0.000610351563, 0.000549316406, 0.000518798828, 0.000579833984, 0.000610351563, 0.000549316406, 0.0012512207, 0.00122070313, 0.000946044921, 0.000610351563, 0.000274658203, 0.0000915527343, 0.0000610351563, 0.0000610351563, 0.0000305175781, 0.0000305175781, 0.0000305175781, 0.0000305175781, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
end
%% compute scaling factor and set floating point precision to int16_t
......@@ -134,16 +141,13 @@ FastConv_SD_BRIR = FastConv_SD_BRIR_float;
[FastConv_SD_BRIR.rev_param.nrgLr, FastConv_SD_BRIR.rev_param.factorQ_nrgLr] = make_be_with_fx(FastConv_SD_BRIR_float.rev_param.nrgLr,15);
if writeRomFileOutput
if writeRomFileFx
write_fastconv_rom_table_fx(rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR);
else
write_fastconv_rom_table_fx(fx_rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR);
if makeFxFltBE
write_fastconv_rom_table_flt(rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR);
else
write_fastconv_rom_table_flt(rom_file, FastConv_SHD_IR_FOA_float, FastConv_SHD_IR_HOA2_float, FastConv_SHD_IR_HOA3_float, FastConv_SD_IR_float, FastConv_SD_BRIR_float);
end
end
end
% binary format is always FX
if writeBinaryOutput
......
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% (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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(C) 2022-2025 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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/
%
......
......@@ -53,7 +53,9 @@ addpath(genpath('../td_object_renderer/modeling_tool/'));
%% Set arguments
generateCustomBinaryFile = false;
writeRomFileFx = true;
normalize = true; % put a true to normalize input HRTF file. Diffuse field spectrum will be equal to one at 1 khz. Shall not be used with BRIR
makeBE = true; % put at true to generate BE rom table and at false to support more type of sofa file
performDiffuseFieldEq = true; % at true perform diffuse field equalization during param bin taps computation. Should not by used when HRIR are alredy diffuse field equalized
writeRomFileOutput = true & ~generateCustomBinaryFile; %% generation of rom files if true
writeBinaryOutput = true; %% generation of binary files if true. Always true for TD renderer
writeEachRendererBinaryOutput = false; %% generation of binary split files each containing binary data for individual renderer
......@@ -118,7 +120,7 @@ end
dataSpec.hrfInDir = hrir_file;
dataSpec.hrfOutDir = binary_path;
dataSpec.genRomFile = writeRomFileOutput;
dataSpec.genRomFileFx = writeRomFileFx;
dataSpec.genRomFileFx = true;
dataSpec.genBinaryFile = writeBinaryOutput;
dataSpec.makeFxFltBE = true;
dataSpec.romOutDir = rom_path;
......@@ -129,9 +131,9 @@ SOFA_save_to_mat(hrir_file);
SOFA_save_to_mat(brir_file,'Combined');
if generateCustomBinaryFile
convert_SD2SHD_HRIRs(hrir_path,hrir_file_name,-1);
convert_SD2SHD_HRIRs(hrir_path,hrir_file_name,-1,normalize);
else
convert_SD2SHD_HRIRs(hrir_path,hrir_file_name,128);
convert_SD2SHD_HRIRs(hrir_path,hrir_file_name,128,normalize);
end
command = ['.' filesep() 'generate_crend_ivas_tables'];
......@@ -177,6 +179,7 @@ bin_file = fullfile('.',binary_path, fastconv_bin_file );
if writeRomFileOutput == true
rom_file = fullfile(rom_path, 'ivas_rom_binauralRenderer.c');
fx_rom_file = fullfile(rom_path, 'ivas_rom_binauralRenderer_fx.c');
copyfile('ivas_license_header.template',rom_file,'f');
......@@ -194,6 +197,24 @@ if writeRomFileOutput == true
'#define WMC_TOOL_SKIP');
fclose(fp);
copyfile('ivas_license_header.template',fx_rom_file,'f');
fp_fx = fopen(fx_rom_file,'at');
fprintf(fp_fx,"\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s\n\n%s\n\n%s\n%s\n%s\n\n%s\n%s\n%s\n", ...
'#include <stdint.h>', ...
'#include "options.h"', ...
'#ifdef DEBUGGING', ...
'#include "debug.h"', ...
'#endif', ...
'#include "cnst.h"', ...
'#include "ivas_cnst.h"', ...
'#include "wmc_auto.h"', ...
'/* clang-format off */', ...
'#define WMC_TOOL_SKIP');
fclose(fp_fx);
end
generate_tables_for_fastconv
......@@ -202,6 +223,7 @@ generate_tables_for_fastconv
param_bin_file = ['parambin_' erase(hrir_file_name, '.sofa') '_' erase(brir_file_name, '.sofa') '.bin'];
bin_file = fullfile('.',binary_path, param_bin_file );
generate_tables_for_parametric_binauralizer
if writeRomFileOutput == true
......@@ -212,6 +234,14 @@ if writeRomFileOutput == true
fprintf(fp,"\n%s\n\n%s\n", '#undef WMC_TOOL_SKIP', '/* clang-format on */');
fclose(fp);
fx_rom_file = fullfile(rom_path, 'ivas_rom_binauralRenderer_fx.c');
fp_fx = fopen(fx_rom_file,'at');
fprintf(fp_fx,"\n%s\n\n%s\n", '#undef WMC_TOOL_SKIP', '/* clang-format on */');
fclose(fp_fx);
end
%% concatenate all previously generated binary files to binary file for IVAS decoder or renderer. One per sample rates
......
......@@ -29,7 +29,7 @@
% the United Nations Convention on Contracts on the International Sales of Goods.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function FastConv_SD_IR = SD_2_ROM(sofa_file, num_cldfb_taps)
function FastConv_SD_IR = SD_2_ROM(sofa_file, num_cldfb_taps, normalize)
% SD_2_ROM( rom_c_file, sofa_file, ambisonics_order, hrir_length )
%
% Derived from SHD_2_ROM.m
......@@ -46,7 +46,7 @@ if ~exist('num_cldfb_taps','var')
end
%% load SD HRIRs
H = hrtf_library_loader();
H.readSOFA(char(sofa_file),'',false);
H.readSOFA(char(sofa_file),'',normalize);
ls_struct = get_ls_layout_config('Combined');
IR_SD = H.XYZ_to_IR_SD([deg2rad(ls_struct.azi); deg2rad(ls_struct.ele)]);
......
......@@ -29,7 +29,7 @@
% the United Nations Convention on Contracts on the International Sales of Goods.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function FastConv_SHD_IR = SHD_2_ROM( sofa_file, ambi_order, hrir_len , num_cldfb_taps)
function FastConv_SHD_IR = SHD_2_ROM( sofa_file, ambi_order, hrir_len , num_cldfb_taps, normalize)
% SHD_2_ROM( sofa_file, ambisonics_order, hrir_length )
%
% - converts sphere-sampled Head Related Impulse Responses (HRIRs) given in sofa_file
......@@ -53,7 +53,7 @@ if ~exist('num_cldfb_taps','var')
end
%% convert sphere-sampled HRIRs to SHD HRIRs
[sofa_path,sofa_name, sofa_ext] = fileparts(sofa_file);
IR = generate_HOA_HRIRs_MOD_lens(ambi_order, sofa_path, [sofa_name,sofa_ext], hrir_len);
IR = generate_HOA_HRIRs_MOD_lens(ambi_order, sofa_path, [sofa_name,sofa_ext], hrir_len,normalize);
%% SHD -> CLDFB via least squares error optimization
[~,num_ears,num_ch] = size(IR);
......
......@@ -29,7 +29,7 @@
% the United Nations Convention on Contracts on the International Sales of Goods.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function convert_SD2SHD_HRIRs(sofa_path, sofa_file, IR_size)
function convert_SD2SHD_HRIRs(sofa_path, sofa_file, IR_size, normalize)
data_struct = struct.empty(3,0);
......@@ -38,7 +38,7 @@ sr_short = [48, 32, 16];
sr_dft_size = [240, 160, 80];
% FOA
data_struct(1).IR_data = generate_HOA_HRIRs_MOD_lens(1, sofa_path, sofa_file, IR_size);
data_struct(1).IR_data = generate_HOA_HRIRs_MOD_lens(1, sofa_path, sofa_file, IR_size,normalize);
data_struct(1).HOA_name = 'FOA';
data_struct(1).n_HOA_ch = 4;
data_struct(1).sr = sr;
......@@ -48,7 +48,7 @@ SOFA_save(data_struct(1).IR_data, sr(1), 1/sr(1), [sofa_path filesep() sofa_file
SOFA_save_to_mat([sofa_path filesep() erase(sofa_file, '.sofa') '_' data_struct(1).HOA_name '.sofa']);
% HOA2
data_struct(2).IR_data = generate_HOA_HRIRs_MOD_lens(2, sofa_path, sofa_file, IR_size);
data_struct(2).IR_data = generate_HOA_HRIRs_MOD_lens(2, sofa_path, sofa_file, IR_size,normalize);
data_struct(2).HOA_name = 'HOA2';
data_struct(2).n_HOA_ch = 9;
data_struct(2).sr = sr;
......@@ -58,7 +58,7 @@ SOFA_save(data_struct(2).IR_data, sr(1), 1/sr(1), [sofa_path filesep() sofa_file
SOFA_save_to_mat([sofa_path filesep() erase(sofa_file, '.sofa') '_' data_struct(2).HOA_name '.sofa']);
% HOA3
data_struct(3).IR_data = generate_HOA_HRIRs_MOD_lens(3, sofa_path, sofa_file, IR_size);
data_struct(3).IR_data = generate_HOA_HRIRs_MOD_lens(3, sofa_path, sofa_file, IR_size,normalize);
data_struct(3).HOA_name = 'HOA3';
data_struct(3).n_HOA_ch = 16;
data_struct(3).sr = sr;
......
......@@ -29,7 +29,7 @@
% the United Nations Convention on Contracts on the International Sales of Goods.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function IR_data = generate_HOA_HRIRs_MOD_lens(order, sofa_path, sofa_file_name, ir_len)
function IR_data = generate_HOA_HRIRs_MOD_lens(order, sofa_path, sofa_file_name, ir_len, normalize)
% HRIR convertor - Takes sphere sampled HRIRs and converts them to
% HOA HRIRs.
%
......@@ -56,7 +56,7 @@ Vs_hi_res = Vs_hi_res.Vs_hi_res;
N = 512;
H = hrtf_library_loader();
H.readSOFA(char(fullfile(sofa_path, sofa_file_name)),'',false);
H.readSOFA(char(fullfile(sofa_path, sofa_file_name)),'',normalize);
if (ir_len == -1)
ir_len = size(H.Data.IR,3);
end
......
......@@ -31,7 +31,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [T60, lateEnes, earlyEnes] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir_inputfile, SHhrtf)
function [T60, lateEnes, earlyEnes] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir_inputfile, SHhrtf,normalize, makeBE)
%
% [T60, lateEnes, earlyEnes] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir_inputfile, SHhrtf)
%
......@@ -41,7 +41,7 @@ function [T60, lateEnes, earlyEnes] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir
%% Load BRIR input file
sofaData = hrtf_library_loader();
sofaData.readSOFA(brir_inputfile,'Combined',false);
sofaData.readSOFA(brir_inputfile,'Combined',normalize);
%% Get data and format it for us
......@@ -150,6 +150,10 @@ end
% Determine T60, early energies, and late energies
T60 = zeros(nFFT/2,1);
for band = 1:nFFT/2
if makeBE
[~, lateStart] = max(enes(band, 5:15));
eneDb = 10*log10(enes(band, :));
else
eneBackwardSum = zeros(1,length(enes(band, :)));
eneBackwardSum(end) = enes(band,end);
for indt = length(eneBackwardSum)-1:-1:1
......@@ -158,6 +162,7 @@ for band = 1:nFFT/2
[~, lateStart] = max(eneBackwardSum(5:15));
eneDb = 10*log10(eneBackwardSum);
end
indices = [lateStart:maxIndexInRangeSmooth(band)];
% Linear fitting a line, determining T60 based on it
......
......@@ -30,7 +30,7 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function SHhrtf = generate_HRIR_in_SHD_CLDFB_PARAMETRIC(hrir_inputfile, performDiffuseFieldEq)
function SHhrtf = generate_HRIR_in_SHD_CLDFB_PARAMETRIC(hrir_inputfile, performDiffuseFieldEq, normalize)
%
% SHhrtf = generate_HRIR_in_SHD_CLDFB_PARAMETRIC(hrir_inputfile)
%
......@@ -43,7 +43,7 @@ end
%% Load HRIR input file
sofaData = hrtf_library_loader();
sofaData.readSOFA(hrir_inputfile,'',false);
sofaData.readSOFA(hrir_inputfile,'',normalize);
%% Get data and format it for us
% Input HRIR data from SOFA. After permuation, in order (ear, dirIndex, response)
......
......@@ -51,6 +51,15 @@ end
if ~exist("writeRomFileOutput",'var')
writeRomFileOutput = true;
end
if ~exist("normalize",'var')
normalize = true;
end
if ~exist("makeBE",'var')
makeBE = true;
end
if ~exist("performDiffuseFieldEq",'var')
performDiffuseFieldEq = true;
end
if ~exist("writeRomFileFx",'var')
writeRomFileFx = false;
end
......@@ -66,6 +75,9 @@ end
if ~exist("rom_file",'var')
rom_file = fullfile('.', 'ivas_rom_binauralRenderer.c');
end
if ~exist("fx_rom_file",'var')
fx_rom_file = fullfile('.', 'ivas_rom_binauralRenderer_fx.c');
end
if ~exist("bin_file",'var')
bin_file = fullfile('.', 'parambin_binary_rom.bin');
end
......@@ -88,23 +100,27 @@ if writeRomFileOutput
fprintf(fid, '#ifdef DEBUGGING\n');
fprintf(fid, '/* Generated on %s with Matlab version %s by %s on %s */\n', datetime("today"), version, username, computer);
fprintf(fid, '#endif\n\n\n');
fid_fx = fopen(fullfile('.', fx_rom_file), 'at');
fprintf(fid_fx, '#ifdef DEBUGGING\n');
fprintf(fid_fx, '/* Generated on %s with Matlab version %s by %s on %s */\n', datetime("today"), version, username, computer);
fprintf(fid_fx, '#endif\n\n\n');
end
%% Generate C-code tables for RENDERER_BINAURAL_PARAMETRIC (SHD)
disp('Processing HRIR for parametric renderer...');
SHhrtf_float = generate_HRIR_in_SHD_CLDFB_PARAMETRIC(hrir_file, false);
SHhrtf_float = generate_HRIR_in_SHD_CLDFB_PARAMETRIC(hrir_file, performDiffuseFieldEq, normalize);
%% compute scaling factor and set floating point precision to Word16
[SHhrtf, factorQ_SHhrtf] = make_be_with_fx(SHhrtf_float,15);
SHhrtf_fx = SHhrtf .* (2.^double(factorQ_SHhrtf));
if writeRomFileOutput
if writeRomFileFx
fprintf(fid, 'const Word16 hrtfShCoeffs_factorQ_fx = %d;\n', factorQ_SHhrtf);
writeData3L(fid, 'const Word16 hrtfShCoeffsRe_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '%d', real(SHhrtf_fx));
writeData3L(fid, 'const Word16 hrtfShCoeffsIm_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '%d', imag(SHhrtf_fx));
else
fprintf(fid_fx, 'const Word16 hrtfShCoeffs_factorQ_fx = %d;\n', factorQ_SHhrtf);
writeData3L(fid_fx, 'const Word16 hrtfShCoeffsRe_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '%d', real(SHhrtf_fx));
writeData3L(fid_fx, 'const Word16 hrtfShCoeffsIm_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '%d', imag(SHhrtf_fx));
if makeFxFltBE
writeData3L(fid, 'const float hrtfShCoeffsRe[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '%a', real(SHhrtf));
writeData3L(fid, 'const float hrtfShCoeffsIm[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '%a', imag(SHhrtf));
......@@ -113,11 +129,10 @@ if writeRomFileOutput
writeData3L(fid, 'const float hrtfShCoeffsIm[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '%a', imag(SHhrtf_float));
end
end
end
%% Generate C-code tables for RENDERER_BINAURAL_PARAMETRIC_ROOM (SHD)
disp('Processing BRIR for parametric renderer...');
[T60_float, lateEnes_float, earlyEnes_float] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir_file, SHhrtf);
[T60_float, lateEnes_float, earlyEnes_float] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir_file, SHhrtf, normalize, makeBE);
%% compute scaling factor and ste floating point precision to Word32
[T60, factorQ_T60] = make_be_with_fx(T60_float,15);
......@@ -129,37 +144,28 @@ earlyEnes_fx = earlyEnes .* (2.^double(factorQ_earlyEnes));
if writeRomFileOutput
% Write BRIR parameters to file
if writeRomFileFx
fprintf(fid, 'const Word16 parametricReverberationTimes_factorQ_fx = %d;\n', factorQ_T60);
fprintf(fid, 'const Word16 parametricReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX] = {\n');
else
fprintf(fid_fx, 'const Word16 parametricReverberationTimes_factorQ_fx = %d;\n', factorQ_T60);
fprintf(fid_fx, 'const Word16 parametricReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX] = {\n');
fprintf(fid, 'const float parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX] = {\n');
end
for k = 1:60
if mod(k-1, 10)==0
fprintf(fid, ' ');
end
if k < 60
if writeRomFileFx
fprintf(fid, '%d,', T60_fx(k));
else
fprintf(fid_fx, '%d,', T60_fx(k));
if makeFxFltBE
fprintf(fid, '%s,', flt2hex(T60(k)));
else
fprintf(fid, '%s,', flt2hex(T60_float(k)));
end
end
else
if writeRomFileFx
fprintf(fid, '%d\n};', T60_fx(k));
else
fprintf(fid_fx, '%d\n};', T60_fx(k));
if makeFxFltBE
fprintf(fid, '%s\n};', flt2hex(T60(k)));
else
fprintf(fid, '%s\n};', flt2hex(T60_float(k)));
end
end
end
if k>1 && mod(k, 10)==0
fprintf(fid, '\n');
else
......@@ -167,37 +173,28 @@ if writeRomFileOutput
end
end
if writeRomFileFx
fprintf(fid, '\n\nconst Word16 parametricReverberationEneCorrections_factorQ_fx = %d;\n', factorQ_lateEnes);
fprintf(fid, 'const Word16 parametricReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX] = {\n');
else
fprintf(fid_fx, '\n\nconst Word16 parametricReverberationEneCorrections_factorQ_fx = %d;\n', factorQ_lateEnes);
fprintf(fid_fx, 'const Word16 parametricReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX] = {\n');
fprintf(fid, '\n\nconst float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = {\n');
end
for k = 1:60
if mod(k-1, 10)==0
fprintf(fid,' ');
end
if k < 60
if writeRomFileFx
fprintf(fid, '%d,', lateEnes_fx(k));
else
fprintf(fid_fx, '%d,', lateEnes_fx(k));
if makeFxFltBE
fprintf(fid, '%s,', flt2hex(lateEnes(k)));
else
fprintf(fid, '%s,', flt2hex(lateEnes_float(k)));
end
end
else
if writeRomFileFx
fprintf(fid, '%d\n};', lateEnes_fx(k));
else
fprintf(fid_fx, '%d\n};', lateEnes_fx(k));
if makeFxFltBE
fprintf(fid, '%s\n};', flt2hex(lateEnes(k)));
else
fprintf(fid, '%s\n};', flt2hex(lateEnes_float(k)));
end
end
end
if k>1 && mod(k, 10)==0
fprintf(fid, '\n');
else
......@@ -205,37 +202,28 @@ if writeRomFileOutput
end
end
if writeRomFileFx
fprintf(fid, '\n\nconst Word16 parametricEarlyPartEneCorrection_factorQ_fx = %d;\n', factorQ_earlyEnes);
fprintf(fid, 'const Word16 parametricEarlyPartEneCorrection_fx[CLDFB_NO_CHANNELS_MAX] = {\n');
else
fprintf(fid_fx, '\n\nconst Word16 parametricEarlyPartEneCorrection_factorQ_fx = %d;\n', factorQ_earlyEnes);
fprintf(fid_fx, 'const Word16 parametricEarlyPartEneCorrection_fx[CLDFB_NO_CHANNELS_MAX] = {\n');
fprintf(fid, '\n\nconst float parametricEarlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX] = {\n');
end
for k = 1:60
if mod(k-1, 10)==0
fprintf(fid, ' ');
end
if k < 60
if writeRomFileFx
fprintf(fid, '%d,', earlyEnes_fx(k));
else
fprintf(fid_fx, '%d,', earlyEnes_fx(k));
if makeFxFltBE
fprintf(fid, '%s,', flt2hex(earlyEnes(k)));
else
fprintf(fid, '%s,', flt2hex(earlyEnes_float(k)));
end
end
else
if writeRomFileFx
fprintf(fid, '%d\n};', earlyEnes_fx(k));
else
fprintf(fid_fx, '%d\n};', earlyEnes_fx(k));
if makeFxFltBE
fprintf(fid, '%s\n};', flt2hex(earlyEnes(k)));
else
fprintf(fid, '%s\n};', flt2hex(earlyEnes_float(k)));
end
end
end
if k>1 && mod(k, 10)==0
fprintf(fid, '\n');
else
......@@ -246,6 +234,7 @@ end
if writeRomFileOutput
fclose(fid);
fclose(fid_fx);
end
%%
......
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
% (C) 2022-2025 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
......@@ -62,7 +62,7 @@ if dataSpec.genRomFile
copyright_str = string(join({
'/******************************************************************************************************'
''
' (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,'
' (C) 2022-2025 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'
......