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

add missing files

parent c3195969
Loading
Loading
Loading
Loading
+294 −0
Original line number Original line Diff line number Diff line
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   (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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function write_fastconv_binary_data(ivas_path, bin_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR)
%
% Writes HRIR & BRIR based data for FastConv binaural renderer into a binary file. 
%
% write_fastconv_binary_data(rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR)
%
% filename : string
%   name of the file to be written
%
%
% Output file format:
%   Header [Declaration of the HRTF]
%       Renderer type          (int32_t) : See "RENDERER_TYPE"
%       Decoder output format  (int32_t) : See "BINAURAL_INPUT_AUDIO_CONFIG"
%       Sampling Frequency     (int32_t)
%       Raw data size          (uint32_t)
%
%   HRIRs
%       latency_s           => float32
%       BINAURAL_CONVBANDS  => uint16_t
%       num_channels        => uint16_t
%       BINAURAL_NTAPS      => uint16_t
%       leftHRIRReal        => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%       leftHRIRImag        => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%       rightHRIRReal       => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%       rightHRIRImag       => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%
%   BRIRs
%       latency_s                           => float32
%       num_channels                        => uint16_t
%       BINAURAL_NTAPS_MAX                  => uint16_t
%       leftBRIRReal                        => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%       leftBRIRImag                        => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%       rightBRIRReal                       => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%       rightBRIRImag                       => float32[BINAURAL_CONVBANDS][num_channels][num_taps]
%       CLDFB_NO_CHANNELS_MAX               => uint16_t
%       fastConvReverberationTimes          => float32[CLDFB_NO_CHANNELS_MAX]
%       fastConvReverberationEneCorrections => float32[CLDFB_NO_CHANNELS_MAX]
%

[f_id, err_msg] = fopen(bin_file, 'wb');

if f_id == -1
    error('Could not open file %s for writing. Error message:\n%s', filename, err_msg);
end

%% File header
% We need to get the chunksize of all IRs to get total size
% SHD HRIRs
% FOA
IR = FastConv_SHD_IR_FOA;
[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR);

header = get_ivas_binary_header(ivas_path,'HRTF_READER_RENDERER_BINAURAL_FASTCONV', ['BINAURAL_INPUT_AUDIO_CONFIG_' IR.order]);
header.chunksize = header.chunksize + 4; % latency_s
header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS
header.chunksize = header.chunksize + 2; % num_channels
header.chunksize = header.chunksize + 2; % num_taps
header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im

IR.header = header;
FastConv_SHD_IR_FOA = IR;

% HOA2
IR = FastConv_SHD_IR_HOA2;
[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR);

header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV', ['BINAURAL_INPUT_AUDIO_CONFIG_' IR.order]);
header.chunksize = header.chunksize + 4; % latency_s
header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS
header.chunksize = header.chunksize + 2; % num_channels
header.chunksize = header.chunksize + 2; % num_taps
header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im

IR.header = header;
FastConv_SHD_IR_HOA2 = IR;

% HOA3
IR = FastConv_SHD_IR_HOA3;
[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR);

header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV', ['BINAURAL_INPUT_AUDIO_CONFIG_' IR.order]);
header.chunksize = header.chunksize + 4; % latency_s
header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS
header.chunksize = header.chunksize + 2; % num_channels
header.chunksize = header.chunksize + 2; % num_taps
header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im

IR.header = header;
FastConv_SHD_IR_HOA3 = IR;

% SD HRIRs
IR = FastConv_SD_IR;
[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR);

header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV', 'BINAURAL_INPUT_AUDIO_CONFIG_COMBINED');
header.chunksize = header.chunksize + 4; % latency_s
header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS
header.chunksize = header.chunksize + 2; % num_channels
header.chunksize = header.chunksize + 2; % num_taps
header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * binaural_ntaps * 4 ); % HRTF L/R Re/Im

IR.header = header;
FastConv_SD_IR = IR;
    
% SD BRIRs
IR = FastConv_SD_BRIR;
[~, binaural_convbands, num_channels, ~] = size(IR.IR);
cldfb_no_channels_max = IR.rev_param.kAna;

header = get_ivas_binary_header(ivas_path, 'HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM', 'BINAURAL_INPUT_AUDIO_CONFIG_COMBINED');
header.chunksize = header.chunksize + 4; % latency_s
header.chunksize = header.chunksize + 2; % BINAURAL_CONVBANDS
header.chunksize = header.chunksize + 2; % num_channels
header.chunksize = header.chunksize + 2; % num_taps
header.chunksize = header.chunksize + 4 * (binaural_convbands * num_channels * IR.rev_param.NFilter * 4 ); % HRTF L/R Re/Im
header.chunksize = header.chunksize + 2; % CLDFB_NO_CHANNELS_MAX
header.chunksize = header.chunksize + cldfb_no_channels_max * 4; % rt60
header.chunksize = header.chunksize + cldfb_no_channels_max * 4; % nrgLr

IR.header = header;
FastConv_SD_BRIR = IR;

% calculate the size of all chunks
HRTFs = {FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR};
hrtf_data_size = 0;
total_file_size = 0;
for i = 1:length(HRTFs)
    hrtf_data_size = hrtf_data_size + HRTFs{i}.header.chunksize;
    total_file_size = total_file_size + 4 * 4; % chunk header 4 (u)int32 values
end

total_file_size = total_file_size + 8; % 'IVASHRTF' (char[8])
total_file_size = total_file_size + 4; % file size (int32)
total_file_size = total_file_size + 2; % number of HRTFs in file (int16)
total_file_size = total_file_size + 4; % HRTF size (int32)
total_file_size = total_file_size + hrtf_data_size;      % size of all HRTF data chunks 

fwrite(f_id, 'IVASHRTF', 'char'); % identifier
fwrite(f_id, total_file_size, 'int32'); % file size
fwrite(f_id, length(HRTFs), 'int16'); % number of HRTFs
fwrite(f_id, hrtf_data_size, 'int32'); % max data size (bytes to read after this header)

%% HRIRs

%  SHD HRIRs
SHD_HRIRs = {FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3};
for i = 1:length(SHD_HRIRs)
    IR = SHD_HRIRs{i};
    [~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR);
    
    % write header for this chunk
    fwrite(f_id, IR.header.renderer_type, 'int32');
    fwrite(f_id, IR.header.in_fmt, 'int32');
    fwrite(f_id, IR.header.fs, 'int32');
    fwrite(f_id, IR.header.chunksize, 'uint32');
    
    fwrite(f_id, IR.latency_s, 'float32');
    fwrite(f_id, binaural_convbands, 'uint16');
    fwrite(f_id, num_channels, 'uint16');
    fwrite(f_id, binaural_ntaps, 'uint16');

    for band = 1:binaural_convbands
        for ch = 1:num_channels
            fwrite(f_id, real(squeeze(IR.IR(1, band, ch, :))), 'float32');
        end
    end
    for band = 1:binaural_convbands
        for ch = 1:num_channels
            fwrite(f_id, imag(squeeze(IR.IR(1, band, ch, :))), 'float32');
        end
    end
    for band = 1:binaural_convbands
        for ch = 1:num_channels
            fwrite(f_id, real(squeeze(IR.IR(2, band, ch, :))), 'float32');
        end
    end
    for band = 1:binaural_convbands
        for ch = 1:num_channels
            fwrite(f_id, imag(squeeze(IR.IR(2, band, ch, :))), 'float32');
        end
    end
end

%   SD HRIRs
IR = FastConv_SD_IR;
[~, binaural_convbands, num_channels, binaural_ntaps] = size(IR.IR);

% write header for this chunk
fwrite(f_id, IR.header.renderer_type, 'int32');
fwrite(f_id, IR.header.in_fmt, 'int32');
fwrite(f_id, IR.header.fs, 'int32');
fwrite(f_id, IR.header.chunksize, 'uint32');
    
fwrite(f_id, IR.latency_s, 'float32');
fwrite(f_id, binaural_convbands, 'uint16');
fwrite(f_id, num_channels, 'uint16');
fwrite(f_id, binaural_ntaps, 'uint16');
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, real(squeeze(IR.IR(1, band, ch, :))), 'float32');
    end
end
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, imag(squeeze(IR.IR(1, band, ch, :))), 'float32');
    end
end
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, real(squeeze(IR.IR(2, band, ch, :))), 'float32');
    end
end
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, imag(squeeze(IR.IR(2, band, ch, :))), 'float32');
    end
end


%   SD BRIRs
IR = FastConv_SD_BRIR;
[~, binaural_convbands, num_channels, ~] = size(IR.IR);
cldfb_no_channels_max = IR.rev_param.kAna;

% write header for this chunk
fwrite(f_id, IR.header.renderer_type, 'int32');
fwrite(f_id, IR.header.in_fmt, 'int32');
fwrite(f_id, IR.header.fs, 'int32');
fwrite(f_id, IR.header.chunksize, 'uint32');
    
fwrite(f_id, IR.rev_param.latency_s, 'float32');
fwrite(f_id, binaural_convbands, 'uint16');
fwrite(f_id, num_channels, 'uint16');
fwrite(f_id, IR.rev_param.NFilter, 'uint16');
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, real(squeeze(IR.IR(1, band, ch, 1:IR.rev_param.NFilter))), 'float32' );
    end
end
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, imag(squeeze(IR.IR(1, band, ch, 1:IR.rev_param.NFilter))), 'float32' );
    end
end
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, real(squeeze(IR.IR(2, band, ch, 1:IR.rev_param.NFilter))), 'float32' );
    end
end
for band = 1:binaural_convbands
    for ch = 1:num_channels
        fwrite(f_id, imag(squeeze(IR.IR(2, band, ch, 1:IR.rev_param.NFilter))), 'float32' );
    end
end

fwrite(f_id, cldfb_no_channels_max, 'uint16');
fwrite(f_id, IR.rev_param.rt60, 'float32');
fwrite(f_id, IR.rev_param.nrgLr, 'float32');

fclose(f_id);

end
 No newline at end of file
+152 −0
Original line number Original line Diff line number Diff line
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   (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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function write_fastconv_rom_table(output_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR)
    % TODO move this to common script that writes all tables?
    %% Open file and write header
    if ismac
        username = getenv('USER');
    else
        username = getenv('username');
    end
    fid = fopen(output_file, 'at');
    fprintf(fid, '/*\n');
    fprintf(fid, ' * Generated on %s with Matlab version %s by %s on %s\n', datetime("today"), version, username, computer);
    fprintf(fid, '*/\n\n\n');
    
    %% HRIRs (SHD)
    % HOA3
    IR = FastConv_SHD_IR_HOA3;
    factorQ = int16(floor( double(15) - log( IR.latency_s ) / log( 2. ) ));
    latency_s = int16(IR.latency_s .* (2.^double(factorQ)));
    fprintf(fid, ['const uint16_t FASTCONV_' FastConv_SHD_IR_HOA3.order '_latency_s_Q = %d;\n'], factorQ);
    fprintf(fid, ['const int16_t FASTCONV_' FastConv_SHD_IR_HOA3.order '_latency_s = %d;\n'], latency_s);
    
    fprintf(fid, ['const uint16_t FASTCONV_' FastConv_SHD_IR_HOA3.order '_Q = %d;\n'], IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t leftHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t leftHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t rightHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(IR.IR(2,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t rightHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(IR.IR(2,:,:,:))), IR.factorQ);

    % HOA2
    IR = FastConv_SHD_IR_HOA2;
    factorQ = int16(floor( double(15) - log( IR.latency_s ) / log( 2. ) ));
    latency_s = int16(IR.latency_s .* (2.^double(factorQ)));
    fprintf(fid, ['const uint16_t FASTCONV_' FastConv_SHD_IR_HOA2.order '_latency_s_Q = %d;\n'], factorQ);
    fprintf(fid, ['const int16_t FASTCONV_' FastConv_SHD_IR_HOA2.order '_latency_s = %d;\n'], latency_s);

    fprintf(fid, ['const uint16_t FASTCONV_' FastConv_SHD_IR_HOA2.order '_Q = %d;\n'], IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t leftHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t leftHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t rightHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(IR.IR(2,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t rightHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(IR.IR(2,:,:,:))), IR.factorQ);

    % FOA
    IR = FastConv_SHD_IR_FOA;
    factorQ = int16(floor( double(15) - log( IR.latency_s ) / log( 2. ) ));
    latency_s = int16(IR.latency_s .* (2.^double(factorQ)));
    fprintf(fid, ['const uint16_t FASTCONV_' FastConv_SHD_IR_FOA.order '_latency_s_Q = %d;\n'], factorQ);
    fprintf(fid, ['const int16_t FASTCONV_' FastConv_SHD_IR_FOA.order '_latency_s = %d;\n'], latency_s);
    
    fprintf(fid, ['const uint16_t FASTCONV_' FastConv_SHD_IR_FOA.order '_Q = %d;\n'], IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t leftHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t leftHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t rightHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(IR.IR(2,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, ['const int16_t rightHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(IR.IR(2,:,:,:))), IR.factorQ);


    %% HRIRs (SD)
    IR = FastConv_SD_IR;
    factorQ = int16(floor( double(15) - log( IR.latency_s ) / log( 2. ) ));
    latency_s = int16(IR.latency_s .* (2.^double(factorQ)));
    fprintf(fid, 'const uint16_t FASTCONV_HRIR_latency_s_Q = %d;\n', factorQ);
    fprintf(fid, 'const int16_t FASTCONV_HRIR_latency_s = %d;\n', latency_s);

    fprintf(fid, 'const uint16_t FASTCONV_HRIR_Q = %d;\n', IR.factorQ);
    writeData3L_fx_16(fid, 'const Word32 leftHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', real(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, 'const Word32 leftHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', imag(squeeze(IR.IR(1,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, 'const Word32 rightHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', real(squeeze(IR.IR(2,:,:,:))), IR.factorQ);
    writeData3L_fx_16(fid, 'const Word32 rightHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', imag(squeeze(IR.IR(2,:,:,:))), IR.factorQ);

    %% BRIRs (SD)
    IR = FastConv_SD_BRIR;
    factorQ = int16(floor( double(15) - log( IR.rev_param.latency_s ) / log( 2. ) ));
    latency_s = int16(IR.rev_param.latency_s .* (2.^double(factorQ)));
    fprintf(fid, 'const uint16_t FASTCONV_BRIR_latency_s_Q = %d;\n', factorQ);
    fprintf(fid, 'const int16_t FASTCONV_BRIR_latency_s = %d;\n', latency_s);

    fprintf(fid, 'const uint16_t FASTCONV_BRIR_Q = %d;\n', IR.factorQ);
    writeData3L_fx_16(fid, 'const int16_t leftBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', real(squeeze(IR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter))), IR.factorQ);
    writeData3L_fx_16(fid, 'const int16_t leftBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', imag(squeeze(IR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter))), IR.factorQ);
    writeData3L_fx_16(fid, 'const int16_t rightBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', real(squeeze(IR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter))), IR.factorQ);
    writeData3L_fx_16(fid, 'const int16_t rightBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', imag(squeeze(IR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter))), IR.factorQ);

    % RT60
    rt60 = IR.rev_param.rt60 .* (2.^double(IR.factorQ_rt60));
    fprintf(fid, 'const uint16_t fastconvReverberationTimes_Q = %d;\n', IR.factorQ_rt60);
    fprintf(fid, 'const int16_t fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX] = \n{\n');
    for bandIdx = 1:FastConv_SD_BRIR.rev_param.kAna
        if mod(bandIdx-1, 10)==0
            fprintf(fid, '    ');
        end

        fprintf(fid,'%d, ', int16(rt60(bandIdx)));

        if bandIdx>1 && mod(bandIdx,10)==0
            fprintf(fid, '\n')
        end
    end
    fprintf(fid,'\n};\n');
    fprintf(fid,'\n\n');

    % energyReverb
    nrgLr = IR.rev_param.nrgLr .* (2.^double(IR.factorQ_nrgLr));
    fprintf(fid, 'const uint16_t fastconvReverberationEneCorrections_Q = %d;\n', IR.factorQ_rt60);
    fprintf(fid, 'const int16_t fastconvReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX] = \n{\n');
    for bandIdx = 1:FastConv_SD_BRIR.rev_param.kAna
        if mod(bandIdx-1, 10)==0
            fprintf(fid, '    ');
        end

        fprintf(fid,'%d,', int16(nrgLr(bandIdx)));
        
        if bandIdx>1 && mod(bandIdx,10)==0
            fprintf(fid, '\n')
        else
            fprintf(fid, ' ')
        end
    end
    fprintf(fid,'\n};\n');
    fprintf(fid,'\n\n');

    fclose(fid);

end
+101 −0

File added.

Preview size limit exceeded, changes collapsed.

+87 −0

File added.

Preview size limit exceeded, changes collapsed.

+87 −0

File added.

Preview size limit exceeded, changes collapsed.