Commit fc5d48d3 authored by hmund's avatar hmund
Browse files

change interface, always assume reading the sofa file

parent ea43d5a4
Loading
Loading
Loading
Loading
+21 −23
Original line number Diff line number Diff line
@@ -25,11 +25,12 @@
%    the United Nations Convention on Contracts on the International Sales of Goods.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function IR_cldfb = SHD_2_ROM( rom_c_file, sofa_file, py_path )
% SHD_2_ROM( rom_c_file, sofa_file, py_path )
function IR_cldfb = SHD_2_ROM( py_path, rom_c_file, sofa_file )
% SHD_2_ROM( python_path, rom_c_file, sofa_file )
%
% converts Sphere-sampled Head Related Impulse Responses (HRIRs) to the Spherical Harmonics domain (SHD)  
% to the Complex Low Delay Filter Bank (CLDFB) domain to c-code ROM tables.
% - converts sphere-sampled Head Related Impulse Responses (HRIRs) given in sofa_file to the Spherical Harmonics domain (SHD)
% - converts SHD HRIRs to Complex Low Delay Filter Bank (CLDFB) domain
% - writes CLDFB HRIRs to c-code ROM tables.
% 
%   Processing chain: 
%   
@@ -40,28 +41,25 @@ function IR_cldfb = SHD_2_ROM( rom_c_file, sofa_file, py_path )
[thispath,~,~] = fileparts(mfilename('fullpath'));
thispath = [thispath,filesep];

%% Load SHD HRIRs
if 0 % exist('sofa_file','var') && exist('py_path','var')
   % Note: this path not yet functional!
   % requires
%py_path = 'C:\Users\xxxx\AppData\Local\Programs\Python\Python39\python.exe'; % may look like this
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

%% convert sphere-sampled HRIRs to SHD HRIRs
% requires:
% python -m pip install sofar
% python -m pip install numpy
   %py_path = 'C:\Users\xxxx\AppData\Local\Programs\Python\Python39\python.exe';
   %sofa_file = fullfile(thispath,'..','HRIRs_sofa',filesep,'HRIR_128_48000_dolby_SBA3.sofa'); % 'HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000.sofa'
   [sofa_path,sofa_name] = fileparts(sofa_file);

% convert sphere-sampled HRIRs to SHD HRIRs
hrir_len = 128;
   IR = generate_HOA_HRIRs_MOD_lens(1, py_path, sofa_path, sofa_name, hrir_len);
else
   % load pre-converted SHD HRIRs
   in_file = [thispath,'HRIR_128_48000_dolby_SBA3.mat'];
   disp(['Loading Spherical Harmonics Domain HRIRs from ',in_file])
   load(in_file,'IR');
end
[~,num_ears,num_ch] = size(IR);
ambi_order = 3;
[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);
% 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);
num_cldfb_taps = 3;
IR_cldfb = zeros(60,num_cldfb_taps,num_ears,num_ch); % 60 frequency bands
eval_flag = 0; % optional, = 1 requires signal processing toolbox (fftfilt)