Commit 1a7a6d77 authored by emerit's avatar emerit
Browse files

version ok can generate in one pass fx and float binary

parent 510e5e33
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@
/* Tables generated by the script at "scripts/binauralRenderer_interface/fastconv/generate_tables_for_fastconv.m */
/* Can be replaced by your own generated HRIR tables */
/*
 * Generated on 27-May-2024 with Matlab version 9.3.0.713579 (R2017b) by marcemerit on PCWIN64
 * Generated on 03-Jun-2024 with Matlab version 24.1.0.2578822 (R2024a) Update 2 by marcemerit on MACA64
*/
@@ -1615,7 +1615,7 @@ const uint32_t leftHRIRImag_HOA3[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTA
        {0x3eabe2f6, 0xbb2641d8, 0xba739680},
        {0x3bdb748c, 0x3c30a0ff, 0x3a8a81e8},
        {0x3e95e5c1, 0x3c6c9c12, 0xbb1132c8},
        {0x3e316018, 0xbb171134, 0xbb856a06},
        {0x3e316018, 0xbb171134, 0xbb856a04},
        {0xbdad563b, 0x3af7afe8, 0x3b487d68},
        {0xbe81d627, 0xbcd43974, 0x3b118660},
        {0x3e974ce0, 0x3b6d87c8, 0xbae94450},
@@ -3423,7 +3423,7 @@ const uint32_t rightHRIRImag_HOA3[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NT
        {0xbeabe2f6, 0x3b2641d8, 0x3a739680},
        {0x3bdb748c, 0x3c30a0ff, 0x3a8a81e8},
        {0x3e95e5c1, 0x3c6c9c12, 0xbb1132c8},
        {0xbe316018, 0x3b171134, 0x3b856a06},
        {0xbe316018, 0x3b171134, 0x3b856a04},
        {0x3dad563b, 0xbaf7afe8, 0xbb487d68},
        {0xbe81d627, 0xbcd43974, 0x3b118660},
        {0x3e974ce0, 0x3b6d87c8, 0xbae94450},
@@ -46944,18 +46944,18 @@ const uint32_t rightBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAP
const uint32_t fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX] = 
{
	0x3ed53c00,    0x3e52bc00,    0x3e4f3400,    0x3e554000,    0x3e5c5800,    0x3e72d400,    0x3e6ca000,    0x3e6a6000,    0x3e69d000,    0x3e613c00,    0x3e675c00,    0x3e61f000,    0x3e62d400,    0x3e64cc00,    0x3e653000,    0x3e691000,    0x3e697400,    0x3e64f400,    0x3e611c00,    0x3e5fd400,    0x3e61b400,    0x3e5f7c00,    0x3e5a6000,    0x3e576000,    0x3e546400,    0x3e4b8400,    0x3e48f400,    0x3e479800,    0x3e42e800,    0x3e3cec00,    0x3e38a800,    0x3e346400,    0x3e34bc00,    0x3e35d800,    0x3e3bfc00,    0x3e48a000,    0x3e502000,    0x3e556c00,    0x3e5bd000,    0x3e614800,    0x3e644400,    0x3e6bf400,    0x3e6f8c00,    0x3e6f4000,    0x3e720000,    0x3e732000,    0x3e776c00,    0x3e76e800,    0x3e749400,    0x3e783400,    0x3e7b7000,    0x3e7bd800,    0x3e7d1400,    0x3e7b4800,    0x3e79d000,    0x3e79fc00,    0x3e750800,    0x3e783400,    0x3e707400,    0x3e818e00,    
	0x3ed67400,    0x3e544000,    0x3e4fe000,    0x3e541c00,    0x3e5db800,    0x3e71b800,    0x3e6c1000,    0x3e6aa400,    0x3e697800,    0x3e612800,    0x3e66fc00,    0x3e622c00,    0x3e651000,    0x3e645000,    0x3e64f800,    0x3e68c800,    0x3e68ec00,    0x3e651c00,    0x3e617400,    0x3e600000,    0x3e61b400,    0x3e5f7c00,    0x3e5a6000,    0x3e576000,    0x3e546400,    0x3e4b8400,    0x3e48f400,    0x3e479800,    0x3e42e800,    0x3e3cec00,    0x3e38a800,    0x3e346400,    0x3e34bc00,    0x3e35d800,    0x3e3bfc00,    0x3e48a000,    0x3e502000,    0x3e556c00,    0x3e5bd000,    0x3e614800,    0x3e644400,    0x3e6bf400,    0x3e6f8c00,    0x3e6f4000,    0x3e720000,    0x3e732000,    0x3e776c00,    0x3e76e800,    0x3e749400,    0x3e783400,    0x3e7d3000,    0x3e7bd800,    0x3e7e2c00,    0x3e7b4800,    0x3e79d000,    0x3e79fc00,    0x3e749c00,    0x3e787000,    0x3e707400,    0x3e818e00,    
};
const uint32_t fastconvReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = 
{
	0x3a191800,    0x395c2000,    0x3973e000,    0x395e8000,    0x3986d000,    0x3ac6f800,    0x3a975400,    0x3a8fd400,    0x3aa5d400,    0x3aaa1400,    0x3b181000,    0x3b1f5c00,    0x3b301000,    0x3b311000,    0x3b2c7e00,    0x3b280400,    0x3b330600,    0x3b32bc00,    0x3b2afe00,    0x3b256600,    0x3b5fee00,    0x3ae9b800,    0x3a816400,    0x3a372000,    0x3a1ef000,    0x3a0c7000,    0x3a05f000,    0x3a152000,    0x3a1d4000,    0x3a0e5000,    0x3aa4bc00,    0x3a9e7400,    0x3a7ac800,    0x3a1d8000,    0x398fc000,    0x38df4000,    0x38960000,    0x38548000,    0x38280000,    0x38000000,    0x37c90000,    0x37970000,    0x37680000,    0x37540000,    0x374a0000,    0x373a0000,    0x371e0000,    0x37140000,    0x370a0000,    0x37040000,    0x36e40000,    0x36cc0000,    0x36980000,    0x36600000,    0x36200000,    0x35e00000,    0x35800000,    0x35200000,    0x34c00000,    0x34800000,    
	0x3a191800,    0x395c2000,    0x3973e000,    0x395e8000,    0x3986d000,    0x3ac6fc00,    0x3a975400,    0x3a8fd400,    0x3aa5d400,    0x3aaa1800,    0x3b181000,    0x3b1f5c00,    0x3b301000,    0x3b311000,    0x3b2c7e00,    0x3b280400,    0x3b330600,    0x3b32bc00,    0x3b2afe00,    0x3b256600,    0x3b5fee00,    0x3ae9b800,    0x3a816400,    0x3a372000,    0x3a1ef000,    0x3a0c7000,    0x3a05f000,    0x3a152000,    0x3a1d4000,    0x3a0e5000,    0x3aa4bc00,    0x3a9e7400,    0x3a7ac800,    0x3a1d8000,    0x398fc000,    0x38df4000,    0x38960000,    0x38548000,    0x38280000,    0x38000000,    0x37c90000,    0x37970000,    0x37680000,    0x37540000,    0x374a0000,    0x373a0000,    0x371e0000,    0x37140000,    0x370a0000,    0x37040000,    0x36e40000,    0x36cc0000,    0x36980000,    0x36600000,    0x36200000,    0x35e00000,    0x35800000,    0x35200000,    0x34c00000,    0x34800000,    
};
/*
 * Generated on 27-May-2024 with Matlab version 9.3.0.713579 (R2017b) by marcemerit on PCWIN64
 * Generated on 03-Jun-2024 with Matlab version 24.1.0.2578822 (R2024a) Update 2 by marcemerit on MACA64
 * Binaural rendering data set based on BRIRs 
 Tables derived from Mozart IIS BRIRs.*/
+6557 −6557

File changed.

Preview size limit exceeded, changes collapsed.

+0 −17
Original line number Diff line number Diff line
@@ -92,20 +92,6 @@ end

%% generate td binauralizer rom  or binary values

dataSpec.dataBase = 'IVAS';
dataSpec.subjId = 'custom';
% specify HR filter directory
dataSpec.hrfInDir = hrir_file;
dataSpec.hrfOutDir = binary_path;
dataSpec.genRomFile = false;
dataSpec.fx_binary = generateBinaryFile_fx & writeBinaryOutput;
dataSpec.fx = true;
dataSpec.float_binary = writeBinaryOutput;
dataSpec.be = generate_BE;
dataSpec.romOutDir = rom_path;
Mod_Hrf_Itd_Main(dataSpec);


dataSpec.dataBase = 'IVAS';
dataSpec.subjId = 'custom';
% specify HR filter directory
@@ -113,14 +99,11 @@ dataSpec.hrfInDir = hrir_file;
dataSpec.hrfOutDir = binary_path;
dataSpec.genRomFile = writeRomFileOutput;
dataSpec.fx_binary = generateBinaryFile_fx & writeBinaryOutput;
dataSpec.fx = false;
dataSpec.float_binary = writeBinaryOutput;
dataSpec.be = generate_BE;
dataSpec.romOutDir = rom_path;
Mod_Hrf_Itd_Main(dataSpec);



%% generate crend rom  or binary values
SOFA_save_to_mat(hrir_file);
SOFA_save_to_mat(brir_file);
+154 −111
Original line number Diff line number Diff line
@@ -210,9 +210,10 @@ end
for fs = [48000 32000 16000]    
    fs_khz = fs/1000;
%    outputBinaryFileName = sprintf('hrfilter_model_v%03d_%dkHz.bin',modelVersion,fs_khz);
    if dataSpec.fx
        outputBinaryFileName = sprintf(['td_' erase(info.fileNameHrf,'.sofa') '_model_v%03d_fx_%dkHz.bin'],modelVersion,fs_khz);
    else
    if dataSpec.fx_binary
        outputBinaryFileName_fx = sprintf(['td_' erase(info.fileNameHrf,'.sofa') '_model_v%03d_fx_%dkHz.bin'],modelVersion,fs_khz);
    end
    if dataSpec.float_binary
        outputBinaryFileName = sprintf(['td_' erase(info.fileNameHrf,'.sofa') '_model_v%03d_%dkHz.bin'],modelVersion,fs_khz);
    end
        
@@ -407,18 +408,48 @@ for fs = [48000 32000 16000]
    if(exist(filePath, 'dir')==0)
      mkdir(filePath);
    end

    if dataSpec.float_binary
        fileID = fopen(fullfile(filePath,outputBinaryFileName),'w');
    end
    if dataSpec.fx_binary
        fileID_fx = fopen(fullfile(filePath,outputBinaryFileName_fx),'w');
    end

    % Header
    % Format for file:
    if dataSpec.fx_binary
        % 0 = BSpline model
        fwrite(fileID_fx, useModel, 'short');
        fwrite(fileID_fx, QLatency, "int16");
        fwrite(fileID_fx, integerLatency, "int32");
        % ITD model active/inactive:
        % 1 = ITD model is used
        % 0 = ITD model is not usedclc
        fwrite(fileID_fx, useITD, 'short');
        % The sampling frequency in kHz of the HR filter set:
        fwrite(fileID_fx, fs_khz, 'short');
    
        % General - model-specific parts
        fwrite(fileID_fx, size(mod_hrf.WR{1}, 2), 'short');                % K, filter length
        fwrite(fileID_fx, elevDim3, 'short');                              % elevDim3 = P
        fwrite(fileID_fx, Q_elevKSeq, "int16");
        fwrite(fileID_fx, integer_elevKSeq, 'int16');
        % Azimuth model structure
        azim_start_idx = 0;
        for i = 1:elevDim3
            azimDim3 = size(mod_hrf.azimBf{i}, 3);
            fwrite(fileID_fx, azimDim3, 'short');                          % azimDim3 = Q
            fwrite(fileID_fx, azim_start_idx, 'short');                    % start azim index per elevation
            azim_start_idx = azim_start_idx + azimDim3;
            fwrite(fileID_fx, Q_azimKSeq{i}, "int16");
            fwrite(fileID_fx, integer_azimKSeq{i}, "int16");
        end        
    end
    if dataSpec.float_binary
        % 0 = BSpline model
        fwrite(fileID, useModel, 'short');
    if dataSpec.fx
        fwrite(fileID, QLatency, "int16");
        fwrite(fileID, integerLatency, "int32");
    else
        fwrite(fileID, single(mod.dat.hrf.hrf_latency), 'float');
    end
        % ITD model active/inactive:
        % 1 = ITD model is used
        % 0 = ITD model is not usedclc
@@ -429,11 +460,16 @@ for fs = [48000 32000 16000]
        % General - model-specific parts
        fwrite(fileID, size(mod_hrf.WR{1}, 2), 'short');                % K, filter length
        fwrite(fileID, elevDim3, 'short');                              % elevDim3 = P
    if dataSpec.fx
        fwrite(fileID, Q_elevKSeq, "int16");
        fwrite(fileID, integer_elevKSeq, 'int16');
    else
        fwrite(fileID, single(mod_hrf.elevKSeq{1}), 'float');                   % length = elevDim3-2
        % Azimuth model structure
        azim_start_idx = 0;
        for i = 1:elevDim3
            azimDim3 = size(mod_hrf.azimBf{i}, 3);
            fwrite(fileID, azimDim3, 'short');                          % azimDim3 = Q
            fwrite(fileID, azim_start_idx, 'short');                    % start azim index per elevation
            azim_start_idx = azim_start_idx + azimDim3;
            fwrite(fileID, single(mod_hrf.azimKSeq{i}),       'float');         % length = azimDim3+1
        end
    end
    % Azimuth model structure
    azim_start_idx = 0;
@@ -451,17 +487,9 @@ for fs = [48000 32000 16000]
    for i = 1:elevDim3
        azimDim2 = size(mod_hrf.azimBf{i}, 2);
        azimDim3 = size(mod_hrf.azimBf{i}, 3);
        fwrite(fileID, azimDim3, 'short');                          % azimDim3 = Q
        content_dim3 = [content_dim3 int2str(azimDim3) ', '];
        fwrite(fileID, azim_start_idx, 'short');                    % start azim index per elevation
        content_start_idx = [content_start_idx int2str(azim_start_idx) ', '];
        azim_start_idx = azim_start_idx + azimDim3;
        if dataSpec.fx
            fwrite(fileID, Q_azimKSeq{i}, "int16");
            fwrite(fileID, integer_azimKSeq{i}, "int16");
        else
            fwrite(fileID, single(mod_hrf.azimKSeq{i}),       'float');         % length = azimDim3+1
        end
    end
    if fs == fs_orig && dataSpec.genRomFile 
        fileID_c = fopen(c_file_name,'at');
@@ -573,28 +601,42 @@ for fs = [48000 32000 16000]

    end

    if dataSpec.fx_binary
        % Weights
        fwrite(fileID_fx, size(mod_hrf.WL{1},1), 'short');                 % (P*Q)
        fwrite(fileID_fx, Q_WL, "int16");
        fwrite(fileID_fx, integer_WL, 'int32');                         % (P*Q) by K
        fwrite(fileID_fx, Q_WR, "int16");
        fwrite(fileID_fx, integer_WR, 'int32');                         % (P*Q) by K
        % Azimuth basis functions
        fwrite(fileID_fx, num_unique_splines, 'short');                    % number of unique spline functions
        for i = 1:num_unique_splines 
            fwrite(fileID_fx, len_a_shapes{i}, 'short');                   % length of azimuth shape
            fwrite(fileID_fx, Q_azimSplineShape{i}, "int16");
            fwrite(fileID_fx, integer_azimSplineShape{i}, 'int32');                % azimuth shape
            fwrite(fileID_fx, a_num_points(i), 'short');                   % samples between knot points
        end
        fwrite(fileID_fx, azimShapeIdx, 'short');                          % indices for spline functions to use
        fwrite(fileID_fx, azimShapeSampFactor, 'short');                   % decimation factor for spline functions
    
        % Elevation basis functions
        fwrite(fileID_fx, len_e, 'short');                                 % length of elevation shapes
        fwrite(fileID_fx, start_e, 'short');                               % start idx (C indexing) of elevation shapes
        fwrite(fileID_fx, length(elevSplineShape_all), 'short');           % total length elevation shapes
        fwrite(fileID_fx, Q_elevSplineShape_all, "int16");
        fwrite(fileID_fx, integer_elevSplineShape_all, 'int32');                % azimuth shape
        fwrite(fileID_fx, e_num_points, 'short');                          % samples between knot points
    end
    if dataSpec.float_binary
        % Weights
        fwrite(fileID, size(mod_hrf.WL{1},1), 'short');                 % (P*Q)
    if dataSpec.fx
        fwrite(fileID, Q_WL, "int16");
        fwrite(fileID, integer_WL, 'int32');                         % (P*Q) by K
        fwrite(fileID, Q_WR, "int16");
        fwrite(fileID, integer_WR, 'int32');                         % (P*Q) by K
    else
        fwrite(fileID, single(mod_hrf.WL{1}), 'float');                         % (P*Q) by K
        fwrite(fileID, single(mod_hrf.WR{1}), 'float');                         % (P*Q) by K
    end

        % Azimuth basis functions
        fwrite(fileID, num_unique_splines, 'short');                    % number of unique spline functions
        for i = 1:num_unique_splines 
            fwrite(fileID, len_a_shapes{i}, 'short');                   % length of azimuth shape
        if dataSpec.fx
            fwrite(fileID, Q_azimSplineShape{i}, "int16");
            fwrite(fileID, integer_azimSplineShape{i}, 'int32');                % azimuth shape
        else
            fwrite(fileID, single(azimSplineShape{i}), 'float');                % azimuth shape
        end
            fwrite(fileID, a_num_points(i), 'short');                   % samples between knot points
        end
        fwrite(fileID, azimShapeIdx, 'short');                          % indices for spline functions to use
@@ -604,13 +646,9 @@ for fs = [48000 32000 16000]
        fwrite(fileID, len_e, 'short');                                 % length of elevation shapes
        fwrite(fileID, start_e, 'short');                               % start idx (C indexing) of elevation shapes
        fwrite(fileID, length(elevSplineShape_all), 'short');           % total length elevation shapes
    if dataSpec.fx
        fwrite(fileID, Q_elevSplineShape_all, "int16");
        fwrite(fileID, integer_elevSplineShape_all, 'int32');                % azimuth shape
    else
        fwrite(fileID, single(elevSplineShape_all), 'float');                   % elevation shapes
    end
        fwrite(fileID, e_num_points, 'short');                          % samples between knot points
    end

    if fs == fs_orig && dataSpec.genRomFile 

@@ -803,57 +841,56 @@ for fs = [48000 32000 16000]

        % Elevation model structure
        elevDim3 = size(mod_itd.elevBf, 3);        
        fwrite(fileID, elevDim3, 'short');                          % elevDim3 = P
        if dataSpec.fx
            fwrite(fileID, Q_elevKSeq_itd, "int16");
            fwrite(fileID, integer_elevKSeq_itd, 'int16');
        else
            fwrite(fileID, single(mod_itd.elevKSeq),'float');               % length = elevDim3-2
        end
        
        % Azimuth model structure
        azimDim3 = size(mod_itd.azimBf{2}, 3);        
        if dataSpec.fx_binary
            fwrite(fileID_fx, elevDim3, 'short');                          % elevDim3 = P
            fwrite(fileID_fx, Q_elevKSeq_itd, "int16");
            fwrite(fileID_fx, integer_elevKSeq_itd, 'int16');
            fwrite(fileID_fx, azimDim3, 'short');                          % azimDim3 = Q
            fwrite(fileID_fx, Q_itd_azimKSeq, "int16");
            fwrite(fileID_fx, integer_itd_azimKSeq, 'int16');
            % Weights
            fwrite(fileID_fx, size(mod_itd.W,1), 'short');                 % (P*Q)
            fwrite(fileID_fx, Q_itd_W, "int16");
            fwrite(fileID_fx, integer_itd_W, 'int32');
            % Azimuth basis functions
            fwrite(fileID_fx, len_a_ITD, 'short');                         % length of azimuth shapes
            fwrite(fileID_fx, start_a_ITD, 'short');                       % start idx (C indexing) of azimuth shapes
            fwrite(fileID_fx, length(azimSplineShapeITD_all), 'short');    % total length azimuth shapes
            fwrite(fileID_fx, Q_azimSplineShapeITD_all, "int16");
            fwrite(fileID_fx, integer_azimSplineShapeITD_all, 'int32');                       % azimuth shape
            fwrite(fileID_fx, a_num_points_ITD, 'short');                  % samples between knot points
            % Elevation basis functions
            fwrite(fileID_fx, len_e_ITD, 'short');                         % length of elevation shapes
            fwrite(fileID_fx, start_e_ITD, 'short');                       % start idx (C indexing) of elevation shapes
            fwrite(fileID_fx, length(elevSplineShapeITD_all), 'short');    % total length elevation shapes
            fwrite(fileID_fx, Q_elevSplineShapeITD_all, "int16");
            fwrite(fileID_fx, integer_elevSplineShapeITD_all, 'int32');                       % elevation shapes
            fwrite(fileID_fx, e_num_points_ITD, 'short');                  % samples between knot points
        end
        if dataSpec.float_binary
            fwrite(fileID, elevDim3, 'short');                          % elevDim3 = P
            fwrite(fileID, single(mod_itd.elevKSeq),'float');               % length = elevDim3-2
            fwrite(fileID, azimDim3, 'short');                          % azimDim3 = Q
        
        if dataSpec.fx
            fwrite(fileID, Q_itd_azimKSeq, "int16");
            fwrite(fileID, integer_itd_azimKSeq, 'int16');
        else
            fwrite(fileID, single(mod_itd.azimKSeq{2}), 'float');           % length = azimDim3+1
        end
        
            % Weights
            fwrite(fileID, size(mod_itd.W,1), 'short');                 % (P*Q)
        if dataSpec.fx
            fwrite(fileID, Q_itd_W, "int16");
            fwrite(fileID, integer_itd_W, 'int32');
        else
            fwrite(fileID, single(mod_itd.W), 'float');                     % (P*Q) by K
        end

            % Azimuth basis functions
            fwrite(fileID, len_a_ITD, 'short');                         % length of azimuth shapes
            fwrite(fileID, start_a_ITD, 'short');                       % start idx (C indexing) of azimuth shapes
            fwrite(fileID, length(azimSplineShapeITD_all), 'short');    % total length azimuth shapes
        if dataSpec.fx
            fwrite(fileID, Q_azimSplineShapeITD_all, "int16");
            fwrite(fileID, integer_azimSplineShapeITD_all, 'int32');                       % azimuth shape
        else
            fwrite(fileID, single(azimSplineShapeITD_all), 'float');        % azimuth shape
        end
            fwrite(fileID, a_num_points_ITD, 'short');                  % samples between knot points

            % Elevation basis functions
            fwrite(fileID, len_e_ITD, 'short');                         % length of elevation shapes
            fwrite(fileID, start_e_ITD, 'short');                       % start idx (C indexing) of elevation shapes
            fwrite(fileID, length(elevSplineShapeITD_all), 'short');    % total length elevation shapes
        if dataSpec.fx
            fwrite(fileID, Q_elevSplineShapeITD_all, "int16");
            fwrite(fileID, integer_elevSplineShapeITD_all, 'int32');                       % elevation shapes
        else
            fwrite(fileID, single(elevSplineShapeITD_all), 'float');        % elevation shapes
        end
            fwrite(fileID, e_num_points_ITD, 'short');                  % samples between knot points
        end
                
        if fs == fs_last && dataSpec.genRomFile 

@@ -1023,8 +1060,14 @@ for fs = [48000 32000 16000]
        end

    end

    % Close file
    if dataSpec.float_binary
        fclose(fileID);
    end
    if dataSpec.fx_binary
        fclose(fileID_fx);
    end

    fprintf("Wrote model parameters to: %s\n",fullfile(filePath,outputBinaryFileName));
end % fs loop