Commit c997a2c5 authored by emerit's avatar emerit
Browse files

code correction for fix only

parent 1b4918b6
Loading
Loading
Loading
Loading
+22 −262
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function Gen_Hrf_IVAS_Binary(dataSpec, modSpec, info)
function Gen_Hrf_IVAS_Binary_fx(dataSpec, modSpec, info)

%% Config
filePath = modSpec.folderMod; % Path for outputs
@@ -101,8 +101,8 @@ if dataSpec.genRomFile
    h_file_content = string(join({
        ''
        ''
        '#ifndef _IVAS_ROM_TDBINAURALRENDERER_NEW_'
        '#define _IVAS_ROM_TDBINAURALRENDERER_NEW_'
        '#ifndef _IVAS_ROM_TDBINAURALRENDERER_'
        '#define _IVAS_ROM_TDBINAURALRENDERER_'
        ''
        '#include <stdint.h>'
        '#include "options.h"'
@@ -229,9 +229,7 @@ if dataSpec.genRomFile
    c_file_content = string(join({
        [ ... 
        'const Word16 defaultHRIR_rom_latency_s_Q_fx = ' num2str(Q_latency) ';' newline ...
        'const Word32 defaultHRIR_rom_latency_s_fx = ' num2str(integer_latency) ';' newline ...
        'const float defaultHRIR_rom_latency_s = ' num2str(single(mod.dat.hrf.hrf_latency),'%.9f') 'f;']
        ''
        'const Word32 defaultHRIR_rom_latency_s_fx = ' num2str(integer_latency) ';' newline ]
        }, newline));
    fprintf(fileID_c,'%s', c_file_content);
    
@@ -466,10 +464,10 @@ for fs = [48000 32000 16000]
    azim_start_idx = 0;
    
    c_file_content_dim3 = {
        ['const int16_t defaultHRIR_rom_azimDim3[' num2str(elevDim3) '] = {']
        ['const Word16 defaultHRIR_rom_azimDim3[' num2str(elevDim3) '] = {']
        };
    c_file_content_start_idx = {
        ['const int16_t defaultHRIR_rom_azim_start_idx[' num2str(elevDim3) '] = {']
        ['const Word16 defaultHRIR_rom_azim_start_idx[' num2str(elevDim3) '] = {']
        };
    
    content_dim2 = '';
@@ -492,7 +490,7 @@ for fs = [48000 32000 16000]
        c_file_content_start_idx{size(c_file_content_start_idx,2)+1} = '';
        
        c_file_content = ...
            ['const int16_t defaultHRIR_rom_model_configuration[6] = {' newline ];
            ['const Word16 defaultHRIR_rom_model_configuration[6] = {' newline ];
        fprintf(fileID_c,'%s', c_file_content);
        c_file_content = [ num2str(useITD) ', /* UseItdModel */' newline ];
        fprintf(fileID_c,'%s', c_file_content);
@@ -515,7 +513,7 @@ for fs = [48000 32000 16000]
        arr_str = replace(arr_str, ";",',');
        arr_str = replace(arr_str, " ",', ');
        c_file_content = ...
            ['const int16_t defaultHRIR_rom_elevBsLen[' num2str(length(len_e)) '] = {' newline ...
            ['const Word16 defaultHRIR_rom_elevBsLen[' num2str(length(len_e)) '] = {' newline ...
            arr_str ...
            newline '};' newline ...
            ];
@@ -527,7 +525,7 @@ for fs = [48000 32000 16000]
        arr_str = replace(arr_str, ";",',');
        arr_str = replace(arr_str, " ",', ');
        c_file_content = ...
            ['const int16_t defaultHRIR_rom_elevBsStart[' num2str(length(start_e)) '] = {' newline ...
            ['const Word16 defaultHRIR_rom_elevBsStart[' num2str(length(start_e)) '] = {' newline ...
            arr_str ...
            newline '};' newline ...
            ];
@@ -548,7 +546,7 @@ for fs = [48000 32000 16000]
        else
            arr_str(end+1) = ',';
        end
        c_file_content = ['const int16_t defaultHRIR_rom_azimSegSamples[' num2str(num_unique_splines) '] = {' newline arr_str newline '};' newline];
        c_file_content = ['const Word16 defaultHRIR_rom_azimSegSamples[' num2str(num_unique_splines) '] = {' newline arr_str newline '};' newline];
        fprintf(fileID_c,'%s', c_file_content);
        
        arr_str = mat2str(azimShapeIdx);
@@ -556,7 +554,7 @@ for fs = [48000 32000 16000]
        arr_str(end) = ';';
        arr_str = replace(arr_str,';', ', ');
        c_file_content = ...
            ['const int16_t defaultHRIR_rom_azimShapeIdx[' num2str(length(azimShapeIdx)) '] = {' newline ...
            ['const Word16 defaultHRIR_rom_azimShapeIdx[' num2str(length(azimShapeIdx)) '] = {' newline ...
            arr_str ...
            newline '};' newline ...
            ];
@@ -567,7 +565,7 @@ for fs = [48000 32000 16000]
        arr_str(end) = ';';
        arr_str = replace(arr_str,';', ', ');
        c_file_content = ...
            ['const int16_t defaultHRIR_rom_azimShapeSampFactor[' num2str(length(azimShapeSampFactor)) '] = {' newline ...
            ['const Word16 defaultHRIR_rom_azimShapeSampFactor[' num2str(length(azimShapeSampFactor)) '] = {' newline ...
            arr_str ...
            newline '};' newline ...
            ];
@@ -587,9 +585,7 @@ for fs = [48000 32000 16000]
        arr_str_fx = replace(arr_str_fx,' ', ', ');
        
        c_file_content = ...
            ['const float defaultHRIR_rom_elevKSeq[' num2str(length(mod_hrf.elevKSeq{1})) '] = {' newline ...
            arr_str ...
            newline '};' newline ...
            [ ...
            'const Word16 defaultHRIR_rom_elevKSeq_Q_fx = ' num2str(Q_elevKSeq) ';' newline ...
            'const Word16 defaultHRIR_rom_elevKSeq_fx [' num2str(length(mod_hrf.elevKSeq{1})) '] = {' newline ...
            arr_str_fx ...
@@ -646,8 +642,6 @@ for fs = [48000 32000 16000]
        arr_str_fx(end) = ';';
        arr_str_fx = replace(arr_str_fx, ";",', ');
        c_file_content = [...
            'const uint32_t defaultHRIR_rom_elevBsShape[' num2str(length(elevSplineShape_all)) '] = {' newline ...
            arr_str newline '};' newline ...
            'const Word16 defaultHRIR_rom_elevBsShape_Q_fx = ' num2str(Q_elevSplineShape_all) ';' newline ...
            'const Word16 defaultHRIR_rom_elevBsShape_fx[' num2str(length(elevSplineShape_all)) '] = {' newline ...
            arr_str_fx newline '};' newline ...
@@ -668,8 +662,6 @@ for fs = [48000 32000 16000]
        arr_str_fx(end) = ';';
        arr_str_fx = replace(arr_str_fx, ";",', ');
        c_file_content = [...
            'const uint32_t defaultHRIR_rom_azimBsShape[' num2str(length(azimSplineShape{n})) '] = {' newline ...
            arr_str newline '};' newline ...
            'const Word16 defaultHRIR_rom_azimBsShape_Q_fx = ' num2str(Q_azimSplineShape{n}) ';' newline ...
            'const Word16 defaultHRIR_rom_azimBsShape_fx[' num2str(length(azimSplineShape{n})) '] = {' newline ...
            arr_str_fx newline '};' newline ...
@@ -683,35 +675,6 @@ for fs = [48000 32000 16000]
        
        fileID_c = fopen(c_file_name,'at');
                    
        if dataSpec.makeFxFltBE
            arr_str_all = num2hex(single(float_WL));
        else
            arr_str_all = num2hex(single(mod_hrf.WL{1}));
        end
        
        numCol = 25;
        numIter = floor(size(mod_hrf.WL{1},1)*size(mod_hrf.WL{1},2)/numCol);
        numRemain = size(mod_hrf.WL{1},1)*size(mod_hrf.WL{1},2) - numCol * numIter;
        c_file_content = ...
            ['const uint32_t defaultHRIR_rom_AlphaL' num2str(fs/1000) '[' int2str(size(mod_hrf.WL{1}, 1)) ' * ' int2str(size(mod_hrf.WL{1}, 2)) '] = {' newline ];
        fprintf(fileID_c,'%s', c_file_content);
        for ind = 1: numIter
            arr_str = join(mat2str(arr_str_all((ind-1) * numCol + 1 :ind * numCol, : )));
            arr_str = arr_str(2:end);
            arr_str(end) = ';';
            arr_str = replace(arr_str, "';",',');
            arr_str = replace(arr_str, "'",'0x');
            c_file_content = [ arr_str newline];
            fprintf(fileID_c,'%s', c_file_content);
        end
        arr_str = join(mat2str(arr_str_all(ind * numCol + 1 :ind * numCol + numRemain, : )));
        arr_str = arr_str(2:end);
        arr_str(end) = ';';
        arr_str = replace(arr_str, "';",',');
        arr_str = replace(arr_str, "'",'0x');
        c_file_content = [ arr_str newline '};' newline];
        fprintf(fileID_c,'%s', c_file_content);
    
        arr_str_all_fx = reshape(integer_WL,[],1);
        numCol = 25;
        numIter = floor(size(mod_hrf.WL{1},1)*size(mod_hrf.WL{1},2)/numCol);
@@ -736,37 +699,6 @@ for fs = [48000 32000 16000]
        c_file_content = [ arr_str newline '};' newline];
        fprintf(fileID_c,'%s', c_file_content);
          
        
        if dataSpec.makeFxFltBE
            arr_str_all = num2hex(single(float_WR));
        else
            arr_str_all = num2hex(single(mod_hrf.WR{1}));
        end
        numCol = 25;
        numIter = floor(size(mod_hrf.WR{1},1)*size(mod_hrf.WR{1},2)/numCol);
        numRemain = size(mod_hrf.WR{1},1)*size(mod_hrf.WR{1},2) - numCol * numIter;
        c_file_content = ...
            [ ...
            'const uint32_t defaultHRIR_rom_AlphaR' num2str(fs/1000) '[' int2str(size(mod_hrf.WR{1}, 1)) ' * ' int2str(size(mod_hrf.WR{1}, 2)) '] = {' newline ];
        fprintf(fileID_c,'%s', c_file_content);
        for ind = 1: numIter
            arr_str = join(mat2str(arr_str_all((ind-1) * numCol + 1 :ind * numCol, : )));
            arr_str = arr_str(2:end);
            arr_str(end) = ';';
            arr_str = replace(arr_str, "';",',');
            arr_str = replace(arr_str, "'",'0x');
            c_file_content = [ arr_str newline];
            fprintf(fileID_c,'%s', c_file_content);
        end
        arr_str = join(mat2str(arr_str_all(ind * numCol + 1 :ind * numCol + numRemain, : )));
        arr_str = arr_str(2:end);
        arr_str(end) = ';';
        arr_str = replace(arr_str, "';",',');
        arr_str = replace(arr_str, "'",'0x');
        c_file_content = [ arr_str newline '};' newline];
        fprintf(fileID_c,'%s', c_file_content);

        
        arr_str_all_fx = reshape(integer_WR,[],1);
        numCol = 25;
        numIter = floor(size(mod_hrf.WR{1},1)*size(mod_hrf.WR{1},2)/numCol);
@@ -851,33 +783,6 @@ for fs = [48000 32000 16000]
        
        fileID_c = fopen(c_file_name,'at');
        
        if dataSpec.makeFxFltBE
            arr_str_all = num2hex(float_EL);
        else
            arr_str_all = num2hex(single(EL));
        end
        numCol = 25;
        numIter = floor(HRTF_MODEL_N_SECTIONS*size(mod_hrf.WL{1},1)/numCol);
        numRemain = HRTF_MODEL_N_SECTIONS*size(mod_hrf.WL{1},1) - numCol * numIter;
        c_file_content = [...
            'const uint32_t defaultHRIR_rom_EL' num2str(fs/1000) '[HRTF_MODEL_N_SECTIONS * ' int2str(size(mod_hrf.WL{1}, 1)) '] = {' newline ];
        fprintf(fileID_c,'%s', c_file_content);
        for ind = 1: numIter
            arr_str = join(mat2str(arr_str_all((ind-1) * numCol + 1 :ind * numCol, : )));
            arr_str = arr_str(2:end);
            arr_str(end) = ';';
            arr_str = replace(arr_str, "';",',');
            arr_str = replace(arr_str, "'",'0x');
            c_file_content = [ arr_str newline];
            fprintf(fileID_c,'%s', c_file_content);
        end
        arr_str = join(mat2str(arr_str_all(ind * numCol + 1 :ind * numCol + numRemain, : )));
        arr_str = arr_str(2:end);
        arr_str(end) = ';';
        arr_str = replace(arr_str, "';",',');
        arr_str = replace(arr_str, "'",'0x');
        c_file_content = [ arr_str newline '};' newline];
        fprintf(fileID_c,'%s', c_file_content);
       
        arr_str_all_fx = reshape(integer_EL,[],1);
        numCol = 25;
@@ -904,37 +809,6 @@ for fs = [48000 32000 16000]
        ];
        fprintf(fileID_c,'%s', c_file_content);


        if dataSpec.makeFxFltBE
            arr_str_all = num2hex(float_ER);
        else
            arr_str_all = num2hex(single(ER));
        end
        
        numCol = 25;
        numIter = floor(HRTF_MODEL_N_SECTIONS*size(mod_hrf.WR{1},1)/numCol);
        numRemain = HRTF_MODEL_N_SECTIONS*size(mod_hrf.WR{1},1) - numCol * numIter;
        
        c_file_content = [...
            newline 'const uint32_t defaultHRIR_rom_ER' num2str(fs/1000) '[HRTF_MODEL_N_SECTIONS * ' int2str(size(mod_hrf.WR{1}, 1)) '] = {' newline ];
        fprintf(fileID_c,'%s', c_file_content);
        for ind = 1: numIter
            arr_str = join(mat2str(arr_str_all((ind-1) * numCol + 1 :ind * numCol, : )));
            arr_str = arr_str(2:end);
            arr_str(end) = ';';
            arr_str = replace(arr_str, "';",',');
            arr_str = replace(arr_str, "'",'0x');
            c_file_content = [ arr_str newline];
            fprintf(fileID_c,'%s', c_file_content);
        end
        arr_str = join(mat2str(arr_str_all(ind * numCol + 1 :ind * numCol + numRemain, : )));
        arr_str = arr_str(2:end);
        arr_str(end) = ';';
        arr_str = replace(arr_str, "';",',');
        arr_str = replace(arr_str, "'",'0x');
        c_file_content = [ arr_str newline '};' newline];
        fprintf(fileID_c,'%s', c_file_content);

        arr_str_all_fx = reshape(integer_ER,[],1);

        numCol = 25;
@@ -1010,34 +884,6 @@ for fs = [48000 32000 16000]
            
            fileID_c = fopen(c_file_name,'at');
            
            if dataSpec.makeFxFltBE
                arr_str_all = num2hex(single(float_itd_W));
            else
                arr_str_all = num2hex(single(mod_itd.W));
            end
            numCol = 25;
            numIter = floor(length(mod_itd.W)/numCol);
            numRemain = length(mod_itd.W) - numCol * numIter;
            c_file_content = [...
                'const uint32_t defaultHRIR_rom_ITD_W[' num2str(length(mod_itd.W)) '] = {' newline ];
            fprintf(fileID_c,'%s', c_file_content);
            for ind = 1: numIter
                arr_str = join(mat2str(arr_str_all((ind-1) * numCol + 1 :ind * numCol, : )));
                arr_str = arr_str(2:end);
                arr_str(end) = ';';
                arr_str = replace(arr_str, "';",',');
                arr_str = replace(arr_str, "'",'0x');
                c_file_content = [ arr_str newline];
                fprintf(fileID_c,'%s', c_file_content);
            end
            arr_str = join(mat2str(arr_str_all(ind * numCol + 1 :ind * numCol + numRemain, : )));
            arr_str = arr_str(2:end);
            arr_str(end) = ';';
            arr_str = replace(arr_str, "';",',');
            arr_str = replace(arr_str, "'",'0x');
            c_file_content = [ arr_str newline '};' newline];
            fprintf(fileID_c,'%s', c_file_content);

            arr_str_all_fx = reshape(integer_itd_W,[], 1);
            numCol = 25;
            numIter = floor(length(mod_itd.W)/numCol);
@@ -1064,7 +910,7 @@ for fs = [48000 32000 16000]
            fprintf(fileID_c,'%s', c_file_content);

            c_file_content = ...  
                ['const int16_t defaultHRIR_rom_ITD_model_configuration[4] = {' newline ];
                ['const Word16 defaultHRIR_rom_ITD_model_configuration[4] = {' newline ];
            fprintf(fileID_c,'%s', c_file_content);
            c_file_content = [ num2str(elevDim3) ', /* elevDim3 */' newline ];
            fprintf(fileID_c,'%s', c_file_content);
@@ -1083,7 +929,7 @@ for fs = [48000 32000 16000]
            arr_str = replace(arr_str, ";",',');
            arr_str = replace(arr_str, " ",', ');
            c_file_content = ...
                ['const int16_t defaultHRIR_rom_ITD_elevBsLen[' num2str(length(len_e_ITD)) '] = {' newline ...
                ['const Word16 defaultHRIR_rom_ITD_elevBsLen[' num2str(length(len_e_ITD)) '] = {' newline ...
                arr_str ...
                newline '};' newline ...
                ];
@@ -1095,7 +941,7 @@ for fs = [48000 32000 16000]
            arr_str = replace(arr_str, ";",',');
            arr_str = replace(arr_str, " ",', ');
            c_file_content = ...
                ['const int16_t defaultHRIR_rom_ITD_elevBsStart[' num2str(length(start_e_ITD)) '] = {' newline ...
                ['const Word16 defaultHRIR_rom_ITD_elevBsStart[' num2str(length(start_e_ITD)) '] = {' newline ...
                arr_str ...
                newline '};' newline ...
                ];
@@ -1107,7 +953,7 @@ for fs = [48000 32000 16000]
            arr_str = replace(arr_str, ";",',');
            arr_str = replace(arr_str, " ",', ');
            c_file_content = ...
                ['const int16_t defaultHRIR_rom_ITD_azimBsLen[' num2str(length(len_a_ITD)) '] = {' newline ...
                ['const Word16 defaultHRIR_rom_ITD_azimBsLen[' num2str(length(len_a_ITD)) '] = {' newline ...
                arr_str ...
                newline '};' newline ...
                ];
@@ -1119,40 +965,12 @@ for fs = [48000 32000 16000]
            arr_str = replace(arr_str, ";",',');
            arr_str = replace(arr_str, " ",', ');
            c_file_content = ...
                ['const int16_t defaultHRIR_rom_ITD_azimBsStart[' num2str(length(start_a_ITD)) '] = {' newline ...
                ['const Word16 defaultHRIR_rom_ITD_azimBsStart[' num2str(length(start_a_ITD)) '] = {' newline ...
                arr_str ...
                newline '};' newline ...
                ];
            fprintf(fileID_c,'%s', c_file_content);
                       
            if dataSpec.makeFxFltBE
                arr_str_all = num2hex(single(float_azimSplineShapeITD_all));
            else
                arr_str_all = num2hex(single(azimSplineShapeITD_all));
            end
            numCol = 25;
            numIter = floor(length(azimSplineShapeITD_all)/numCol);
            numRemain = length(azimSplineShapeITD_all) - numCol * numIter;
            c_file_content = [...
                'const uint32_t defaultHRIR_rom_ITD_azimBsShape[' num2str(length(azimSplineShapeITD_all)) '] = {' newline ];
            fprintf(fileID_c,'%s', c_file_content);
            for ind = 1: numIter
                arr_str = join(mat2str(arr_str_all((ind-1) * numCol + 1 :ind * numCol, : )));
                arr_str = arr_str(2:end);
                arr_str(end) = ';';
                arr_str = replace(arr_str, "';",',');
                arr_str = replace(arr_str, "'",'0x');
                c_file_content = [ arr_str newline];
                fprintf(fileID_c,'%s', c_file_content);
            end
            arr_str = join(mat2str(arr_str_all(ind * numCol + 1 :ind * numCol + numRemain, : )));
            arr_str = arr_str(2:end);
            arr_str(end) = ';';
            arr_str = replace(arr_str, "';",',');
            arr_str = replace(arr_str, "'",'0x');
            c_file_content = [ arr_str newline '};' newline];
            fprintf(fileID_c,'%s', c_file_content);
            
            arr_str_all_fx = reshape(integer_azimSplineShapeITD_all, [], 1);
            numCol = 25;
            numIter = floor(length(azimSplineShapeITD_all)/numCol);
@@ -1178,21 +996,6 @@ for fs = [48000 32000 16000]
            ];
            fprintf(fileID_c,'%s', c_file_content);

            if dataSpec.makeFxFltBE
                arr_str = mat2str(single(float_itd_azimKSeq));
            else
                arr_str = mat2str(mod_itd.azimKSeq{2});
            end
            arr_str = arr_str(2:end);
            arr_str(end) = ' ';
            arr_str = replace(arr_str,' ', '.000000f, ');
            c_file_content = ...
                ['const float defaultHRIR_rom_ITD_azimKSeq[' num2str(length(mod_itd.azimKSeq{2})) '] = {' newline ...
                arr_str ...
                newline '};' newline ...
             ];
            fprintf(fileID_c,'%s', c_file_content);

            arr_str = mat2str(integer_itd_azimKSeq);
            arr_str = arr_str(2:end);
            arr_str(end) = ' ';
@@ -1207,34 +1010,6 @@ for fs = [48000 32000 16000]
             ];
            fprintf(fileID_c,'%s', c_file_content);

            if dataSpec.makeFxFltBE
                arr_str_all = num2hex(single(float_elevSplineShapeITD_all));
            else
                arr_str_all = num2hex(single(elevSplineShapeITD_all));
            end
            numCol = 25;
            numIter = floor(length(elevSplineShapeITD_all)/numCol);
            numRemain = length(elevSplineShapeITD_all) - numCol * numIter;

            c_file_content = ['const uint32_t defaultHRIR_rom_ITD_elevBsShape[' num2str(length(elevSplineShapeITD_all)) '] = {' newline ];
            fprintf(fileID_c,'%s', c_file_content);
            for ind = 1: numIter
                arr_str = join(mat2str(arr_str_all((ind-1) * numCol + 1 :ind * numCol, : )));
                arr_str = arr_str(2:end);
                arr_str(end) = ';';
                arr_str = replace(arr_str, "';",',');
                arr_str = replace(arr_str, "'",'0x');
                c_file_content = [ arr_str newline];
                fprintf(fileID_c,'%s', c_file_content);
            end
            arr_str = join(mat2str(arr_str_all(ind * numCol + 1 :ind * numCol + numRemain, : )));
            arr_str = arr_str(2:end);
            arr_str(end) = ';';
            arr_str = replace(arr_str, "';",',');
            arr_str = replace(arr_str, "'",'0x');
            c_file_content = [ arr_str newline '};' newline];
            fprintf(fileID_c,'%s', c_file_content);

            arr_str_all_fx = reshape(integer_elevSplineShapeITD_all, [], 1);
            numCol = 25;
            numIter = floor(length(elevSplineShapeITD_all)/numCol);
@@ -1260,21 +1035,6 @@ for fs = [48000 32000 16000]
            ];
            fprintf(fileID_c,'%s', c_file_content);
            
            if dataSpec.makeFxFltBE
                arr_str = mat2str(float_elevKSeq_itd);
            else
                arr_str = mat2str(mod_itd.elevKSeq);
            end
            arr_str = arr_str(2:end);
            arr_str(end) = ' ';
            arr_str = replace(arr_str,' ', '.000000f, ');
            c_file_content = ...
                ['const float defaultHRIR_rom_ITD_elevKSeq[' num2str(length(mod_itd.elevKSeq)) '] = {' newline ...
                arr_str ...
                newline '};' newline ...
             ];
            fprintf(fileID_c,'%s', c_file_content);

            arr_str_fx = mat2str(integer_elevKSeq_itd);
            arr_str_fx = arr_str_fx(2:end);
            arr_str_fx(end) = ' ';