Commit 7623c9f9 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

- add a script to directly generate the binary file consumed by the decoder,...

- add a script to directly generate the binary file consumed by the decoder, bypassing tables_format_converter
- update hrtf_file_reader.c with a minor change (BINAURAL_CONVBANDS stored per set of HRTF instead of a common value)
- add helper script to parse the IVAS enum values for writing to binary file
parent 6a49f7f3
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@

#define FIX_718_JBM_MD_UDPATE                           /* Fhg: fix issue #718, wrong setting of the update flag in the TD obj renderer in the JBM path */
#define FIX_719_CRASH_IN_CLEANUP                        /* VA: issue 719: fix Decoder crash after call to goto to cleanup */

#define FIX_312_FASTCONV_HRTF_LOAD                      /* FhG: update loading of FastConv HRTFs from binary data */

/* ################## End BE DEVELOPMENT switches ######################### */

+37 −0
Original line number Diff line number Diff line
@@ -925,11 +925,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(

    hrtf_data_rptr = hrtf_data;

#ifndef FIX_312_FASTCONV_HRTF_LOAD
    /* BINAURAL_CONVBANDS */
    if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
    }
#endif
    hrtf_data_rptr += sizeof( uint16_t );

    /* HRIR */
@@ -938,6 +940,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        ( *hHRTF )->FASTCONV_HRIR_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );

#ifdef FIX_312_FASTCONV_HRTF_LOAD

        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" );
@@ -989,6 +998,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        ( *hHRTF )->FASTCONV_HOA3_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );

#ifdef FIX_312_FASTCONV_HRTF_LOAD

        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HOA3_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA3_CHANNELS)" );
@@ -1038,6 +1054,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        /* HRIR_HOA2 */
        ( *hHRTF )->FASTCONV_HOA2_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );
#ifdef FIX_312_FASTCONV_HRTF_LOAD

        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HOA2_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA2_CHANNELS)" );
@@ -1088,6 +1111,14 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        /* HRIR_FOA */
        ( *hHRTF )->FASTCONV_FOA_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );
#ifdef FIX_312_FASTCONV_HRTF_LOAD


        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( FOA_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (FOA_CHANNELS)" );
@@ -1139,6 +1170,12 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        ( *hHRTF )->FASTCONV_BRIR_latency_s = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );

#ifdef FIX_312_FASTCONV_HRTF_LOAD
        if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" );
        }
#endif
        if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" );
+132 B

File added.

No diff preview for this file type.

+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ if ~exist('sofa_file','var') || isempty(sofa_file)
   sofa_file = fullfile(thispath,'..','BRIRs_sofa','IIS_BRIR_officialMPEG_Combined.sofa');
end
if ~exist('max_band', 'var') || isempty(max_band)
    max_band = 45;
    max_band = 50;
end

%% Load CLDFB protopyte
+83 −0
Original line number Diff line number Diff line
%
%   (C) 2022-2023 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 header = get_ivas_binary_header(renderer_type, bin_in_fmt)
%GET_IVAS_BINARY_HEADER Returns the values required to write the binary
% header by parsing the IVAS enum values
%
%   Header [Declaration of the HRTF]
%       Renderer type                               (int32_t) : See "RENDERER_TYPE"
%       Decoder output format / Binary input format (int32_t) : See "BINAURAL_INPUT_AUDIO_CONFIG"
%       Sampling Frequency                          (int32_t) : Depends on RENDERER_TYPE!
%       Raw data size                               (uint32_t): !!Not set by this function!!
%
%% placeholder values
header.renderer_type = 0;
header.in_fmt = 0;
header.fs = 48000; % TODO not relevant for FastConv/ParamBin
header.chunksize = 0;

%% parse IVAS enum
% read the file
ivas_cnst_path = '../../../lib_com/ivas_cnst.h'; % must be replaced if this file is moved
c = fileread(ivas_cnst_path);

% regex for RENDERER_TYPE
rt_expr = '^\s+(RENDERER\w+)';
rt_tok = regexp(c, rt_expr, 'tokens', 'dotexceptnewline', 'lineanchors');

renderer_types = convertCharsToStrings(cat(1,rt_tok{:}));
renderer_types = strip(renderer_types);
renderer_types = replace(renderer_types, ',', '');

header.renderer_type = find(renderer_type == renderer_types);
if header.renderer_type
    header.renderer_type = header.renderer_type - 1; % matlab index to c enum index 
else
    disp(renderer_types);
    error('Renderer type could not be matched to IVAS enum values!');
end

% regex for BINAURAL_INPUT_AUDIO_CONFIG
ic_expr = '^\s+(BINAURAL_INPUT\w+)';
ic_tok = regexp(c, ic_expr, 'tokens', 'dotexceptnewline', 'lineanchors');
in_configs = convertCharsToStrings(cat(1,ic_tok{:}));
in_configs = strip(in_configs);
in_configs = replace(in_configs, ',', '');

header.in_fmt = find(bin_in_fmt == in_configs);
if header.in_fmt
    header.in_fmt = header.in_fmt - 1; % matlab index to c enum index 
else
    disp(in_configs);
    error('Binaural input config could not be matched to IVAS enum values!');
end

end
Loading