Commit 133e1356 authored by hmund's avatar hmund
Browse files

add ambisonics order and hrir length as optional input arguments

parent e17d385b
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -25,13 +25,13 @@
%    the United Nations Convention on Contracts on the International Sales of Goods.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function IR_cldfb = SHD_2_ROM( py_path, rom_c_file, sofa_file )
% SHD_2_ROM( python_path, rom_c_file, sofa_file )
function IR_cldfb = SHD_2_ROM( py_path, rom_c_file, sofa_file, ambi_order, hrir_len )
% SHD_2_ROM( python_path, rom_c_file, sofa_file, ambisonics_order, hrir_length )
%
% - converts sphere-sampled Head Related Impulse Responses (HRIRs) given in sofa_file to the Spherical Harmonics domain (SHD) using generate_HOA_HRIRs_MOD_lens.m
% - converts SHD HRIRs to Complex Low Delay Filter Bank (CLDFB) domain
% - converts sphere-sampled Head Related Impulse Responses (HRIRs) given in sofa_file 
%   to the Spherical Harmonics domain (SHD) using generate_HOA_HRIRs_MOD_lens.m
% - converts SHD HRIRs to Complex Low Delay Filter Bank (CLDFB) domain using fir_to_cldfb_fir.m
% - writes CLDFB HRIRs to c-code ROM tables.

[thispath,~,~] = fileparts(mfilename('fullpath'));
thispath = [thispath,filesep];

@@ -39,19 +39,21 @@ thispath = [thispath,filesep];
if ~exist('sofa_file','var') || isempty(sofa_file)
   sofa_file = fullfile(thispath,'..','HRIRs_sofa','HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000.sofa');
end

if ~exist('ambi_order','var')
   ambi_order = 3;
end
if ~exist('hrir_len','var')
   hrir_len = 128;
end
%% convert sphere-sampled HRIRs to SHD HRIRs
% requires:
% python -m pip install sofar
% python -m pip install numpy

% convert sphere-sampled HRIRs to SHD HRIRs
hrir_len = 128;
ambi_order = 3;
write_out_sofa = 0;
[sofa_path,sofa_name, sofa_ext] = fileparts(sofa_file);
IR = generate_HOA_HRIRs_MOD_lens(ambi_order, py_path, sofa_path, [sofa_name,sofa_ext], hrir_len, write_out_sofa);
% load([thispath,'HRIR_128_48000_dolby_SBA3.mat'],'IR'); gives the same data as the above with default sofa file

%% SHD -> CLDFB via least squares error optimization
[~,num_ears,num_ch] = size(IR);
@@ -72,11 +74,10 @@ max_band = 50; % Compute 60 bands, but only use 50 in ROM t

IR_cldfb_rom = permute(IR_cldfb, [3 1 4 2]); % after permute: [ears(2), bands(60), chans(16), taps(3)]
IR_cldfb_rom = IR_cldfb_rom(:,1:max_band,:,:);
order_int = (round(sqrt(size(IR_cldfb_rom,3))-1));
if order_int == 1
if ambi_order == 1
    order = 'FOA';
else
    order = ['HOA' int2str(order_int)];
    order = ['HOA' int2str(ambi_order)];
end
if ~exist('rom_c_file','var') || isempty(rom_c_file)
   rom_c_file = [thispath,'ivas_rom_binauralRenderer_',order,'.c']; % fullfile(thispath,'..','..','..','lib_rend',['ivas_rom_binauralRenderer_',order,'.c']);