Commit bded6de5 authored by emerit's avatar emerit
Browse files

fix scripts

parent bce7e068
Loading
Loading
Loading
Loading
+34 −31
Original line number Diff line number Diff line
/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   (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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   (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,6 +53,9 @@ addpath(genpath('../td_object_renderer/modeling_tool/'));

%% Set arguments
generateCustomBinaryFile = 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 
+133 −64
Original line number Diff line number Diff line
@@ -46,7 +46,11 @@ addpath(genpath('../td_object_renderer/modeling_tool/'));


%% Set arguments
writeRomFileOutput = false; %% generation of rom files if true
generateCustomBinaryFile = 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 = true; %% generation of binary split files each containing binary data for individual renderer 

@@ -54,46 +58,86 @@ writeEachRendererBinaryOutput = true; %% generation of binary split files each c
ivas_path = ['..' filesep '..' filesep];

%% Set input files
%hrir_file_name = 'D1_48K_24bit_256tap_FIR_SOFA.sofa';
if generateCustomBinaryFile
    % output_bin_name = 'ivas_binaural_custom';
    % hrir_file_name = 'HRIR_128_Meth5_IRC_51_Q10_symL_Itrp1_48000.sofa';
    % brir_file_name = 'BRIR_Auditorium_S1_R1_CICP19.sofa';
    %brirOptimCfgFile = 'brir_low_complexity_optim.cfg';

    % output_bin_name = 'ivas_binaural_custom_fabian_hrir';
    % hrir_file_name = 'FABIAN_HRIR_measured_HATO_0_norm.sofa';
    % brir_file_name = 'bbcrdlr_all_speakers.sofa'; 
    % brirOptimCfgFile = 'brir_low_complexity_optim.cfg';

    output_bin_name = 'ivas_binaural_custom_no_optim';
    hrir_file_name = 'HRIR_128_Meth5_IRC_51_Q10_symL_Itrp1_48000.sofa'; % fail for TD renderer
    brir_file_name = 'bbcrdlr_all_speakers.sofa';    
    brirOptimCfgFile = 'brir_no_optim.cfg';
    
    %    hrir_file_name = 'ari-dtf_nh2.sofa'; % fail for TD renderer
%     hrir_file_name = 'BiLi-IRC_1101_C_HRIR_96000.sofa'; % fail for TD renderer
    % hrir_file_name = 'cipic-subject_003.sofa'; % fail for TD renderer
    % hrir_file_name = 'Listen-IRC_1002_C_44100.sofa'; % fail for TD renderer
    % hrir_file_name = 'mit_kemar_normal_pinna.sofa'; % fail for TD renderer
    %hrir_file_name = 'RIEC_hrir_subject_001.sofa'; % fail for TD renderer
   % output_bin_name = 'ivas_binaural_custom_no_optim';
    %brir_file_name = 'IIS_BRIR_officialMPEG_Combined.sofa'    
else 
    hrir_file_name = 'HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000.sofa';
% hrir_file_name = 'IRC_1100_I_HRIR_48000.sofa';
% hrir_file_name = 'IRC_1002_C_44100.sofa';

    output_bin_name = 'ivas_binaural';
    brir_file_name = 'IIS_BRIR_officialMPEG_Combined.sofa';
end
hrir_path = fullfile ('.','HRIRs_sofa');
brir_path = fullfile ('.','BRIRs_sofa');
%% Set output files
rom_path = [ivas_path 'lib_rend'];
rom_path = './';
binary_path = fullfile ('.','binaural_renderers_hrtf_data');
binary_name = [erase(hrir_file_name,'.sofa') '+' erase(brir_file_name, '.sofa') ];
output_bin_name = 'ivas_binaural_irc_1002';
if(exist(binary_path, 'dir')==0)
  mkdir(binary_path);
end
rom_path_fx = './';
output_binary_path = fullfile ('.','binaural_renderers_hrtf_data');

hrir_file = fullfile( hrir_path, hrir_file_name);
brir_file = fullfile( brir_path, brir_file_name);

binary_path = fullfile (output_binary_path,'temp');
binary_name = [erase(hrir_file_name,'.sofa') '+' erase(brir_file_name, '.sofa') ];
if ~(exist(binary_path, 'dir'))
  mkdir(binary_path);
end

%% generate td binauralizer rom  or binary values

dataSpec.dataBase = 'IVAS';
if generateCustomBinaryFile
    dataSpec.subjId = 'custom';
else
    dataSpec.subjId = 'default';
end
% specify HR filter directory
dataSpec.hrfInDir = hrir_file;
dataSpec.hrfOutDir = binary_path;
dataSpec.genRomFile = writeRomFileOutput;
dataSpec.genRomFileFx = true;
dataSpec.genBinaryFile = writeBinaryOutput;
dataSpec.makeFxFltBE = true;
dataSpec.romOutDir = rom_path;
dataSpec.romOutDir_fx = rom_path_fx;
Mod_Hrf_Itd_Main(dataSpec);

%% generate crend rom  or binary values
convert_SD2SHD_HRIRs(hrir_path,hrir_file_name,128);
SOFA_save_to_mat(hrir_file);
SOFA_save_to_mat(brir_file,'Combined');

if generateCustomBinaryFile
    convert_SD2SHD_HRIRs(hrir_path,hrir_file_name,-1,normalize);
else
    convert_SD2SHD_HRIRs(hrir_path,hrir_file_name,128,normalize);
end


command = ['.' filesep() 'generate_crend_ivas_tables'];

if writeRomFileOutput == true
    command = [command ' -lib_rend_path ' rom_path];
    command = [command ' -lib_rend_path_fx ' rom_path_fx];
end
if writeBinaryOutput == true
    command = [command ...
@@ -102,15 +146,21 @@ if writeBinaryOutput == true
                ];
end

if generateCustomBinaryFile && exist('brirOptimCfgFile', 'var') && isempty(brirOptimCfgFile)==false
    command = [command ...
                    ' -brir_optim_config_path ' ...
                    ' ' brirOptimCfgFile ' ' ...
                    ];
end                     
command = [command ...
                    ' -compute_reverb_rom ' ...
                    hrir_file ' ' ...
                    erase(hrir_file,'.sofa') '.mat ' ...
                    ' 5 ' ...
                    hrir_file ' ' ...
                    erase(hrir_file,'.sofa') '_FOA.sofa ' ... 
                    erase(hrir_file,'.sofa') '_HOA2.sofa ' ... 
                    erase(hrir_file,'.sofa') '_HOA3.sofa ' ... 
                    brir_file ];
                    erase(hrir_file,'.sofa') '.mat ' ...
                    erase(hrir_file,'.sofa') '_FOA.mat ' ... 
                    erase(hrir_file,'.sofa') '_HOA2.mat ' ... 
                    erase(hrir_file,'.sofa') '_HOA3.mat ' ... 
                    erase(brir_file,'.sofa') '.mat ' ];

%display(command);

@@ -124,7 +174,10 @@ end

fastconv_bin_file = ['fastconv_' erase(hrir_file_name, '.sofa') '_' erase(brir_file_name, '.sofa') '.bin'];
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_fx, 'ivas_rom_binauralRenderer_fx.c');
    
    copyfile('ivas_license_header.template',rom_file,'f');
    
@@ -139,24 +192,39 @@ fprintf(fp,"\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
    '#include "ivas_cnst.h"', ...
    '#include "wmc_auto.h"', ...
    '/* clang-format off */', ...
'#define WMC_TOOL_SKIP', ...
'/*-------------------------------------------------------------------------', ...
' * Binaural rendering related ROM tables', ...
' *------------------------------------------------------------------------*/', ...
'/* Binaural rendering data set based on HRIRs */', ...
'/* Tables generated by the script at "scripts/binauralRenderer_interface/fastconv/generate_tables_for_fastconv.m */', ...
'/* Can be replaced by your own generated HRIR tables */');
    '#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

%% generate parametric binauralizer rom values

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
    rom_file = fullfile(rom_path, 'ivas_rom_binauralRenderer.c');
    
    fp = fopen(rom_file,'at');
@@ -165,16 +233,22 @@ fprintf(fp,"\n%s\n\n%s\n", '#undef WMC_TOOL_SKIP', '/* clang-format on */');
    
    fclose(fp);

    fx_rom_file = fullfile(rom_path_fx, '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

if writeBinaryOutput == true
    td_binary_file = ['td_' erase(hrir_file_name,'.sofa') '_model_v003'];
    % sampleRates = ['48' ; '32' ; '16' ];
    % for ind = 1 : length(sampleRates)
 %       command = ['.' filesep() 'Table_Format_Converter' filesep() 'tables_format_converter' ' -' sampleRates(ind,:) ' '];
        command = ['.' filesep() 'Table_Format_Converter' filesep() 'tables_format_converter'];
        command = [command ...
                    ' -output_file_path ' binary_path ...
                    ' -output_file_path ' output_binary_path ...
                    ' -output_file_name ' output_bin_name ...
                    ' -input_mixerconv_hrir_file_path ' binary_path ...
                    ' -input_mixerconv_hrir_file_name ' binary_name ...
@@ -195,14 +269,12 @@ if writeBinaryOutput == true
            error(cmdout)
            return
        end
%    end
end

%% Foa all previously generated binary files, convert to binary files for IVAS decoder or renderer. One per sample rates and per renderers

if writeBinaryOutput == true && writeEachRendererBinaryOutput == true  
    td_binary_file = ['td_' erase(hrir_file_name,'.sofa') '_model_v003'];
%    sampleRates = ['48' ; '32' ; '16' ];
    command = ['.' filesep() 'Table_Format_Converter' filesep() 'tables_format_converter'];
    commandRendererList = [...
                " -input_mixerconv_hrir_file_path " binary_path ...
@@ -218,13 +290,11 @@ if writeBinaryOutput == true && writeEachRendererBinaryOutput == true
                " -input_fastconv_file_path " binary_path ...
                " -input_fastconv_file_name " fastconv_bin_file ...      
                ];
 %   for ind = 1 : length(sampleRates)
        for indList = 3 : 4 : length(commandRendererList)
        pos = strfind(commandRendererList{indList},"_");
        pos(2) = strfind(commandRendererList{indList},"_file_name");
        output_bin_name_list = [output_bin_name commandRendererList{indList}(pos(1):pos(2)-1) ];
%        cmdl = [command ' -output_file_path ' binary_path ' -output_file_name ' output_bin_name_list ' -' sampleRates(ind,:) ' '];
        cmdl = [command ' -output_file_path ' binary_path ' -output_file_name ' output_bin_name_list];
        cmdl = [command ' -output_file_path ' output_binary_path ' -output_file_name ' output_bin_name_list];
            cmdl2 = [cmdl ...
                         commandRendererList{indList - 2} ...
                         commandRendererList{indList - 1} ...
@@ -237,5 +307,4 @@ if writeBinaryOutput == true && writeEachRendererBinaryOutput == true
                return
            end
        end
%    end
 end
+30 −30

File changed.

Preview size limit exceeded, changes collapsed.