diff --git a/lib_com/options.h b/lib_com/options.h index 65657cb7e952fb28be4832b5389b649a06c671ea..247a24014b05f6612d01864bd5484849a94b2e72 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -161,6 +161,9 @@ #define FIX_1081_BINAURAL_SPLIT_PCM_SANITY_CHECK /* VA: issue 1081: correct error print-out when BINAURAL_SPLIT_PCM is requested */ #endif +//#define FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT /* Orange issue 1031 : new fix point hrtf binary file format */ +//#define FIX_CREND_SIMPLIFY_CODE /* Ora : simplify line code in crend */ +#define FLOAT_FIX_POINT_HRTF_FILE_FORMAT /* allows reading floation or fix point hrtf binary file format */ #define FIX_1053_REVERB_RECONFIGURATION /* Philips: issue 1053: fix for dynamic switching of acoustic environment */ #define CONF_DISTATT /* Eri: Make distance attenuation configurable */ #define FIX_1082_INSTRUM_FAILED_LC3PLUS /* VoiceAge: issue 1082: fix ambiguous syntax in LC3Plus code leading to fails of instrumented builds */ diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 0363ea645ba9599abf9e7d3fa441e50114273c2c..d7d24d1d5890d98e6f80190fe64c7150fd452488 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1642,7 +1642,11 @@ static ivas_error ivas_rend_crendConvolver( const float *pIn; float *pFreq_buf_re, *pFreq_buf_im; float *pFreq_buf2_re, *pFreq_buf2_im; +#ifdef FIX_CREND_SIMPLIFY_CODE + float *pFreq_filt_re, *pFreq_filt_im; +#else const float *pFreq_filt_re, *pFreq_filt_im; +#endif float pOut[L_FRAME48k * 2]; float tmp_out_re[L_FRAME48k], tmp_out_im[L_FRAME48k]; CREND_HANDLE hCrend; @@ -1694,6 +1698,23 @@ static ivas_error ivas_rend_crendConvolver( } i = 0; +#ifdef FIX_CREND_SIMPLIFY_CODE + if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + { + if ( pCrend->hHrtfCrend->same_inv_diffuse_weight ) + { + pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse]; + pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse]; + } + else + { + pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse]; + pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse]; + pFreq_buf2_re = &hCrend->freq_buffer_re_diffuse[1][offset_diffuse]; + pFreq_buf2_im = &hCrend->freq_buffer_im_diffuse[1][offset_diffuse]; + } + } +#endif for ( idx_in = 0; idx_in < nchan_in; idx_in++ ) { pIn = &pcm_in[idx_in][i_ts * subframe_length]; @@ -1703,8 +1724,10 @@ static ivas_error ivas_rend_crendConvolver( { if ( pCrend->hHrtfCrend->same_inv_diffuse_weight ) { +#ifndef FIX_CREND_SIMPLIFY_CODE pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse]; pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse]; +#endif pFreq_filt_re = &hCrend->freq_buffer_re[i][offset]; pFreq_filt_im = &hCrend->freq_buffer_im[i][offset]; @@ -1716,10 +1739,12 @@ static ivas_error ivas_rend_crendConvolver( } else { +#ifndef FIX_CREND_SIMPLIFY_CODE pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse]; pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse]; pFreq_buf2_re = &hCrend->freq_buffer_re_diffuse[1][offset_diffuse]; pFreq_buf2_im = &hCrend->freq_buffer_im_diffuse[1][offset_diffuse]; +#endif pFreq_filt_re = &hCrend->freq_buffer_re[i][offset]; pFreq_filt_im = &hCrend->freq_buffer_im[i][offset]; @@ -1732,11 +1757,17 @@ static ivas_error ivas_rend_crendConvolver( } } } +#ifdef FIX_CREND_SIMPLIFY_CODE + pFreq_filt_re = &hCrend->freq_buffer_re[i][offset]; + pFreq_filt_im = &hCrend->freq_buffer_im[i][offset]; + ivas_mdft( pIn, pFreq_filt_re, pFreq_filt_im, subframe_length, subframe_length ); +#else pFreq_buf_re = &hCrend->freq_buffer_re[i][offset]; pFreq_buf_im = &hCrend->freq_buffer_im[i][offset]; ivas_mdft( pIn, pFreq_buf_re, pFreq_buf_im, subframe_length, subframe_length ); +#endif i++; } } diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 69b466db7ed03de89e4b72f616c8282a9088cfbd..3f0393752566159ec4c1f4d82d27942d07c288f9 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -32,10 +32,12 @@ #include "hrtf_file_reader.h" #include +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT +#include +#endif #include "prot.h" #include "ivas_prot_rend.h" #include "ivas_prot.h" -#include "ivas_rom_binaural_crend_head.h" /*---------------------------------------------------------------------* * Local structures @@ -63,7 +65,9 @@ typedef struct ivas_hrtfs_file_header_t #define RESAMPLE_FACTOR_16_48 ( 16.0f / 48.0f ) #define RESAMPLE_FACTOR_32_48 ( 32.0f / 48.0f ) - +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT +#define DEFAULT_BIN_FILE_FX_FLAG 0x1000 +#endif /*---------------------------------------------------------------------* * Local function declarations *---------------------------------------------------------------------*/ @@ -189,7 +193,11 @@ static ivas_error check_hrtf_binary_header( /* Check the renderer type */ if ( ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_MIXER_CONV ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_MIXER_CONV_ROOM ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_FASTCONV ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) && +#else ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM ) && +#endif ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_OBJECTS_TD ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_REVERB_ALL ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Header of HRTF binary file not compliant (renderer type)" ); @@ -220,6 +228,9 @@ static ivas_error check_hrtf_binary_header( static ivas_error read_hrtf_binary_header( ivas_hrtfs_header_t *hrtf_header, +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t *is_fix_point, +#endif FILE *f_hrtf ) { /* HRTF Header */ @@ -227,9 +238,18 @@ static ivas_error read_hrtf_binary_header( /* Input configuration (4 bytes) : See "BINAURAL_INPUT_AUDIO_CONFIG" */ /* Sampling Frequency (4 bytes) */ /* Raw data size (4 bytes) */ - +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + *is_fix_point = 0; +#endif if ( ( fread( &( hrtf_header->rend_type ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->input_cfg ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->frequency ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->data_size ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) ) { +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( hrtf_header->rend_type & DEFAULT_BIN_FILE_FX_FLAG ) + { + *is_fix_point = 1; + hrtf_header->rend_type = hrtf_header->rend_type - DEFAULT_BIN_FILE_FX_FLAG; + } +#endif return IVAS_ERR_OK; } @@ -508,6 +528,13 @@ static ivas_error load_reverb_from_binary( int32_t hrtf_data_size_max; char *hrtf_data; int16_t lr_iac_len; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; + int16_t ind; + Word16 factorQ; + Word16 tmp16; + float factorQ_f; +#endif if ( hHrtfStatistics == NULL ) { @@ -545,7 +572,11 @@ static ivas_error load_reverb_from_binary( for ( hrtf_id = 0; ( hrtf_id < hrtfs_file_header.nb_hrtf ) && ( !is_reverb ); hrtf_id++ ) { +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( read_hrtf_binary_header( &hrtf_header, &is_fx, f_hrtf ) != IVAS_ERR_OK ) +#else if ( read_hrtf_binary_header( &hrtf_header, f_hrtf ) != IVAS_ERR_OK ) +#endif { free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "HRTF binary file not compliant (number of HRTF)" ); @@ -580,9 +611,38 @@ static ivas_error load_reverb_from_binary( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( is_fx ) + { + fread( &factorQ, sizeof( Word16 ), 1, f_hrtf ); + factorQ_f = powf( 2.f, -1.f * (float) factorQ ); + for ( ind = 0; ind < lr_iac_len; ind++ ) + { + fread( &tmp16, sizeof( Word16 ), 1, f_hrtf ); + hHrtfStatistics->average_energy_l[ind] = factorQ_f * (float) tmp16; + } + for ( ind = 0; ind < lr_iac_len; ind++ ) + { + fread( &tmp16, sizeof( Word16 ), 1, f_hrtf ); + hHrtfStatistics->average_energy_r[ind] = factorQ_f * (float) tmp16; + } + for ( ind = 0; ind < lr_iac_len; ind++ ) + { + fread( &tmp16, sizeof( Word16 ), 1, f_hrtf ); + hHrtfStatistics->inter_aural_coherence[ind] = factorQ_f * (float) tmp16; + } + } + else + { + fread( hHrtfStatistics->average_energy_l, sizeof( const float ), lr_iac_len, f_hrtf ); + fread( hHrtfStatistics->average_energy_r, sizeof( const float ), lr_iac_len, f_hrtf ); + fread( hHrtfStatistics->inter_aural_coherence, sizeof( const float ), lr_iac_len, f_hrtf ); + } +#else fread( hHrtfStatistics->average_energy_l, sizeof( const float ), lr_iac_len, f_hrtf ); fread( hHrtfStatistics->average_energy_r, sizeof( const float ), lr_iac_len, f_hrtf ); fread( hHrtfStatistics->inter_aural_coherence, sizeof( const float ), lr_iac_len, f_hrtf ); +#endif hHrtfStatistics->fromROM = FALSE; } @@ -631,6 +691,9 @@ static ivas_error TDREND_MIX_LoadHRTF( ivas_hrtfs_header_t hrtf_header; int32_t hrtf_data_size_max; char *hrtf_data; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; +#endif header_check_result = IVAS_ERR_OK; @@ -676,7 +739,11 @@ static ivas_error TDREND_MIX_LoadHRTF( for ( hrtf_id = 0; ( hrtf_id < hrtfs_file_header.nb_hrtf ) && ( !is_tdrend ); hrtf_id++ ) { +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( read_hrtf_binary_header( &hrtf_header, &is_fx, f_hrtf ) != IVAS_ERR_OK ) +#else if ( read_hrtf_binary_header( &hrtf_header, f_hrtf ) != IVAS_ERR_OK ) +#endif { return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "HRTF binary file not compliant (number of HRTF)" ); } @@ -893,7 +960,7 @@ static ivas_error create_HRTF_from_rawdata( { int16_t i, j, k; int16_t max_num_iterations_diffuse; - uint16_t max_total_num_fsamp_per_iteration, max_total_num_fsamp_per_iteration_diff; + uint32_t max_total_num_fsamp_per_iteration, max_total_num_fsamp_per_iteration_diff; uint32_t mem_size; char *hrtf_data_rptr; float *pOut_to_bin_wptr; @@ -1008,8 +1075,13 @@ static ivas_error create_HRTF_from_rawdata( } /* max_total_num_fsamp_per_iteration */ +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + max_total_num_fsamp_per_iteration = *( (uint32_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint32_t ); +#else max_total_num_fsamp_per_iteration = *( (uint16_t *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( uint16_t ); +#endif /* coeff_re (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1060,8 +1132,13 @@ static ivas_error create_HRTF_from_rawdata( } /* max_total_num_fsamp_per_iteration_diff */ +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + max_total_num_fsamp_per_iteration_diff = *( (uint32_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint32_t ); +#else max_total_num_fsamp_per_iteration_diff = *( (uint16_t *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( uint16_t ); +#endif if ( max_total_num_fsamp_per_iteration_diff != 0 ) { @@ -1111,161 +1188,1015 @@ static ivas_error create_HRTF_from_rawdata( return IVAS_ERR_OK; } +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT +/*---------------------------------------------------------------------* + * create_HRTF_from_rawdata_fx() + * + * Create HRTF from the raw data (to the HRTF CRend handle) + *---------------------------------------------------------------------*/ -static ivas_error create_fastconv_HRTF_from_rawdata( - HRTFS_FASTCONV_HANDLE *hHRTF, /* i/o: HRTF FastConv handle */ - char *hrtf_data, /* i : pointer to binary file */ - HRTF_READER_RENDERER_TYPE rend_type, /* i : Renderer type */ - BINAURAL_INPUT_AUDIO_CONFIG input_cfg /* i : Input binaural config */ +static ivas_error create_HRTF_from_rawdata_fx( + HRTFS_HANDLE *hHRTF, /* i/o: HRTF CRend handle */ + char *hrtf_data /* i : pointer to binary file */ ) { - int16_t i, j; + int16_t i, j, k; + int16_t max_num_iterations_diffuse; + uint32_t max_total_num_fsamp_per_iteration, max_total_num_fsamp_per_iteration_diff; + uint32_t mem_size, l; char *hrtf_data_rptr; + float *pOut_to_bin_wptr; ivas_error error; + Word16 factorQ; - ( *hHRTF )->allocate_init_flag = 0; - - if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) + if ( *hHRTF == NULL ) { - if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) + if ( ( ( *hHRTF ) = (HRTFS_HANDLE) malloc( sizeof( HRTFS_DATA ) ) ) == NULL ) { - return error; + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); } - } - else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) - { - if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV_ROOM, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) + + if ( ( error = ivas_hrtf_init( *hHRTF ) ) != IVAS_ERR_OK ) { return error; } } else { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" ); + return IVAS_ERR_INTERNAL; } + ( *hHRTF )->init_from_rom = 0; hrtf_data_rptr = hrtf_data; - /* HRIR */ - if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) - { - ( *hHRTF )->FASTCONV_HRIR_latency_s = *( (float *) ( hrtf_data_rptr ) ); - hrtf_data_rptr += sizeof( float ); + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); - if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); - } - hrtf_data_rptr += sizeof( uint16_t ); + /* latency_s */ + ( *hHRTF )->latency_s = (float) ( *( (Word32 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * (float) factorQ ); + hrtf_data_rptr += sizeof( Word32 ); - if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" ); - } - hrtf_data_rptr += sizeof( uint16_t ); + /* max_num_ir */ + ( *hHRTF )->max_num_ir = *( (uint16_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint16_t ); - if ( BINAURAL_NTAPS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS)" ); - } - hrtf_data_rptr += sizeof( uint16_t ); + /* BINAURAL_CHANNELS */ + if ( BINAURAL_CHANNELS != *( (int16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file format not compliant (BINAURAL_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + /* max_num_iterations */ + ( *hHRTF )->max_num_iterations = *( (int16_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( int16_t ); + + /* num_iterations */ + for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) + { + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) - { - memcpy( ( *hHRTF )->leftHRIRReal[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); - } + ( *hHRTF )->num_iterations[i][j] = *( (uint16_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint16_t ); } - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + } + + /* pIndex_frequency_max */ + for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) + { + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + mem_size = ( *hHRTF )->max_num_iterations * sizeof( uint16_t ); + ( *hHRTF )->pIndex_frequency_max[i][j] = (uint16_t *) malloc( mem_size ); + if ( ( *hHRTF )->pIndex_frequency_max[i][j] == NULL ) { - memcpy( ( *hHRTF )->leftHRIRImag[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for pIndex_frequency_max" ); } + memcpy( ( *hHRTF )->pIndex_frequency_max[i][j], hrtf_data_rptr, mem_size ); + hrtf_data_rptr += mem_size; } - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + } + + /* max_num_iterations_diffuse */ + max_num_iterations_diffuse = *( (int16_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( int16_t ); + + if ( max_num_iterations_diffuse != 0 ) + { + /* num_iterations_diffuse */ + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) - { - memcpy( ( *hHRTF )->rightHRIRReal[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); - } + ( *hHRTF )->num_iterations_diffuse[j] = *( (uint16_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint16_t ); } - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + + /* pIndex_frequency_max_diffuse (the size depends on num_iterations_diffuse) */ + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + mem_size = ( *hHRTF )->num_iterations_diffuse[j] * sizeof( uint16_t ); + ( *hHRTF )->pIndex_frequency_max_diffuse[j] = (uint16_t *) malloc( mem_size ); + if ( ( *hHRTF )->pIndex_frequency_max_diffuse[j] == NULL ) { - memcpy( ( *hHRTF )->rightHRIRImag[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for pIndex_frequency_max_diffuse" ); } + memcpy( ( *hHRTF )->pIndex_frequency_max_diffuse[j], hrtf_data_rptr, mem_size ); + hrtf_data_rptr += mem_size; } } - else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) + + /* index_frequency_max_diffuse */ + ( *hHRTF )->index_frequency_max_diffuse = *( (uint16_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint16_t ); + + /* inv_diffuse_weight Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + /* inv_diffuse_weight */ + for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { - /* HRIR_HOA3 */ - ( *hHRTF )->FASTCONV_HOA3_latency_s = *( (float *) ( hrtf_data_rptr ) ); - hrtf_data_rptr += sizeof( float ); + ( *hHRTF )->inv_diffuse_weight[0][i] = (float) ( *( (Word16 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * factorQ ); + hrtf_data_rptr += sizeof( Word16 ); + } - if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); - } - hrtf_data_rptr += sizeof( uint16_t ); + for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) + { + ( *hHRTF )->inv_diffuse_weight[1][i] = (float) ( *( (Word16 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * factorQ ); + hrtf_data_rptr += sizeof( Word16 ); + } - if ( HOA3_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA3_CHANNELS)" ); - } - hrtf_data_rptr += sizeof( uint16_t ); + /* max_total_num_fsamp_per_iteration */ + max_total_num_fsamp_per_iteration = *( (uint32_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint32_t ); + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); - if ( BINAURAL_NTAPS_SBA != *( (uint16_t *) ( hrtf_data_rptr ) ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS_SBA)" ); - } - hrtf_data_rptr += sizeof( uint16_t ); - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + /* coeff_re (the size depends on pIndex_frequency_max) */ + for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) + { + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - for ( j = 0; j < HOA3_CHANNELS; j++ ) + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + ( *hHRTF )->pOut_to_bin_re[i][j] = (float *) malloc( mem_size ); + if ( ( *hHRTF )->pOut_to_bin_re[i][j] == NULL ) { - memcpy( ( *hHRTF )->leftHRIRReal_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for Out_to_bin_re" ); } - } - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) - { - for ( j = 0; j < HOA3_CHANNELS; j++ ) + memset( ( *hHRTF )->pOut_to_bin_re[i][j], 0x00, mem_size ); + + pOut_to_bin_wptr = ( *hHRTF )->pOut_to_bin_re[i][j]; + + for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { - memcpy( ( *hHRTF )->leftHRIRImag_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); + memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + Word32 *ptW = (Word32 *) pOut_to_bin_wptr; + for ( l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + { + pOut_to_bin_wptr[l] = (float) ptW[l] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += mem_size; + pOut_to_bin_wptr += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + } + + /* coeff_im (the size depends on pIndex_frequency_max) */ + for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) + { + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - for ( j = 0; j < HOA3_CHANNELS; j++ ) + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + ( *hHRTF )->pOut_to_bin_im[i][j] = (float *) malloc( mem_size ); + if ( ( *hHRTF )->pOut_to_bin_im[i][j] == NULL ) { - memcpy( ( *hHRTF )->rightHRIRReal_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for Out_to_bin_im" ); } - } - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) - { - for ( j = 0; j < HOA3_CHANNELS; j++ ) + memset( ( *hHRTF )->pOut_to_bin_im[i][j], 0x00, mem_size ); + + pOut_to_bin_wptr = ( *hHRTF )->pOut_to_bin_im[i][j]; + for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { - memcpy( ( *hHRTF )->rightHRIRImag_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); - hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); + memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + Word32 *ptW = (Word32 *) pOut_to_bin_wptr; + for ( l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + { + pOut_to_bin_wptr[l] = (float) ptW[l] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += mem_size; + pOut_to_bin_wptr += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) - { - /* HRIR_HOA2 */ - ( *hHRTF )->FASTCONV_HOA2_latency_s = *( (float *) ( hrtf_data_rptr ) ); - hrtf_data_rptr += sizeof( float ); - if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + /* max_total_num_fsamp_per_iteration_diff */ + max_total_num_fsamp_per_iteration_diff = *( (uint32_t *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( uint32_t ); + + if ( max_total_num_fsamp_per_iteration_diff != 0 ) + { + // factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + // hrtf_data_rptr += sizeof( Word16 ); + /* coeff_diffuse_re : The size depends on pIndex_frequency_max_diffuse */ + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) + { + mem_size = max_total_num_fsamp_per_iteration_diff * sizeof( float ); + ( *hHRTF )->pOut_to_bin_diffuse_re[j] = (float *) malloc( mem_size ); + if ( ( *hHRTF )->pOut_to_bin_diffuse_re[j] == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for pOut_to_bin_diffuse_re" ); + } + memset( ( *hHRTF )->pOut_to_bin_diffuse_re[j], 0x00, mem_size ); + + pOut_to_bin_wptr = ( *hHRTF )->pOut_to_bin_diffuse_re[j]; + + for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) + { + mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); + memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + Word32 *ptW = (Word32 *) pOut_to_bin_wptr; + for ( l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + { + pOut_to_bin_wptr[l] = (float) ptW[l] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += mem_size; + pOut_to_bin_wptr += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; + } + } + + /* coeff_diffuse_im : The size depends on pIndex_frequency_max_diffuse */ + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) + { + mem_size = max_total_num_fsamp_per_iteration_diff * sizeof( float ); + ( *hHRTF )->pOut_to_bin_diffuse_im[j] = (float *) malloc( mem_size ); + if ( ( *hHRTF )->pOut_to_bin_diffuse_im[j] == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for pOut_to_bin_diffuse_im" ); + } + memset( ( *hHRTF )->pOut_to_bin_diffuse_im[j], 0x00, mem_size ); + + pOut_to_bin_wptr = ( *hHRTF )->pOut_to_bin_diffuse_im[j]; + for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) + { + mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); + memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + Word32 *ptW = (Word32 *) pOut_to_bin_wptr; + for ( l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + { + pOut_to_bin_wptr[l] = (float) ptW[l] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += mem_size; + pOut_to_bin_wptr += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; + } + } + } + + return IVAS_ERR_OK; +} + +static ivas_error create_fastconv_HRTF_from_rawdata_fx( + HRTFS_FASTCONV_HANDLE *hHRTF, /* i/o: HRTF FastConv handle */ + char *hrtf_data, /* i : pointer to binary file */ + HRTF_READER_RENDERER_TYPE rend_type, /* i : Renderer type */ + BINAURAL_INPUT_AUDIO_CONFIG input_cfg /* i : Input binaural config */ +) +{ + int16_t i, j, k; + char *hrtf_data_rptr; + ivas_error error; + Word16 factorQ; + int32_t *ptW32; + int16_t *ptW16; + + ( *hHRTF )->allocate_init_flag = 0; + + if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) + { + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) + { + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV_ROOM, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" ); + } + + hrtf_data_rptr = hrtf_data; + + /* HRIR */ + if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + { + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + /* latency_s */ + ( *hHRTF )->FASTCONV_HRIR_latency_s = (float) ( *( (Word32 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * (float) factorQ ); + hrtf_data_rptr += sizeof( Word32 ); + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( BINAURAL_NTAPS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS; k++ ) + { + ( *hHRTF )->leftHRIRReal[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS; k++ ) + { + ( *hHRTF )->leftHRIRImag[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS; k++ ) + { + ( *hHRTF )->rightHRIRReal[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS; k++ ) + { + ( *hHRTF )->rightHRIRImag[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( int32_t ); + } + } + } + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) + { + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + /* latency_s */ + ( *hHRTF )->FASTCONV_HOA3_latency_s = (float) ( *( (Word32 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * (float) factorQ ); + hrtf_data_rptr += sizeof( Word32 ); + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( HOA3_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA3_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( BINAURAL_NTAPS_SBA != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS_SBA)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->leftHRIRReal_HOA3[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->leftHRIRImag_HOA3[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->rightHRIRReal_HOA3[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->rightHRIRImag_HOA3[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + } + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) + { + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + /* latency_s */ + ( *hHRTF )->FASTCONV_HOA2_latency_s = (float) ( *( (Word32 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * (float) factorQ ); + hrtf_data_rptr += sizeof( Word32 ); + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( HOA2_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA2_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( BINAURAL_NTAPS_SBA != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS_SBA)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA2_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->leftHRIRReal_HOA2[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA2_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->leftHRIRImag_HOA2[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA2_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->rightHRIRReal_HOA2[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA2_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->rightHRIRImag_HOA2[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + } + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA ) + { + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + /* latency_s */ + ( *hHRTF )->FASTCONV_FOA_latency_s = (float) ( *( (Word32 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * (float) factorQ ); + hrtf_data_rptr += sizeof( Word32 ); + + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( FOA_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (FOA_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( BINAURAL_NTAPS_SBA != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS_SBA)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < FOA_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->leftHRIRReal_FOA[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < FOA_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->leftHRIRImag_FOA[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < FOA_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->rightHRIRReal_FOA[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < FOA_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_SBA; k++ ) + { + ( *hHRTF )->rightHRIRImag_FOA[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( int32_t ); + } + } + } + /* BRIR */ + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + { + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + /* latency_s */ + ( *hHRTF )->FASTCONV_BRIR_latency_s = (float) ( *( (Word32 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * (float) factorQ ); + hrtf_data_rptr += sizeof( Word32 ); + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( BINAURAL_NTAPS_MAX != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_MAX; k++ ) + { + ( *hHRTF )->leftBRIRReal[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_MAX * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_MAX; k++ ) + { + ( *hHRTF )->leftBRIRImag[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_MAX * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_MAX; k++ ) + { + ( *hHRTF )->rightBRIRReal[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_MAX * sizeof( int32_t ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + ptW32 = (Word32 *) hrtf_data_rptr; + for ( k = 0; k < BINAURAL_NTAPS_MAX; k++ ) + { + ( *hHRTF )->rightBRIRImag[i][j][k] = (float) ptW32[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += BINAURAL_NTAPS_MAX * sizeof( int32_t ); + } + } + + /* Reverb Parameters */ + if ( CLDFB_NO_CHANNELS_MAX != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (CLDFB_NO_CHANNELS_MAX)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + ptW16 = (int16_t *) hrtf_data_rptr; + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + ( *hHRTF )->fastconvReverberationTimes[j] = (float) ptW16[j] * powf( 2.f, -1.f * factorQ ); + } + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + + /* latency_s Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + ptW16 = (int16_t *) hrtf_data_rptr; + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + ( *hHRTF )->fastconvReverberationEneCorrections[j] = (float) ptW16[j] * powf( 2.f, -1.f * factorQ ); + } + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + } + + return IVAS_ERR_OK; +} + +/*---------------------------------------------------------------------* + * create_parambin_HRTF_from_rawdata_fx() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error create_parambin_HRTF_from_rawdata_fx( + HRTFS_PARAMBIN_HANDLE *hHRTF, /* i/o: Parametric binauralizer HRTF handle */ + char *hrtf_data /* i : pointer to binary file */ +) +{ + int16_t i, j, k; + char *hrtf_data_rptr; + uint32_t data_size_tmp; + Word16 factorQ; + int16_t *ptW16; + + hrtf_data_rptr = hrtf_data; + + /* HRTF_SH_CHANNELS */ + if ( HRTF_SH_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_SH_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* HRTF_NUM_BINS */ + if ( HRTF_NUM_BINS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_NUM_BINS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* HRTF */ + /* Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + data_size_tmp = HRTF_NUM_BINS * sizeof( int16_t ); + for ( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + for ( j = 0; j < HRTF_SH_CHANNELS; j++ ) + { + ptW16 = (int16_t *) hrtf_data_rptr; + for ( k = 0; k < HRTF_NUM_BINS; k++ ) + { + ( *hHRTF )->hrtfShCoeffsRe[i][j][k] = (float) ptW16[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += data_size_tmp; + } + } + for ( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + for ( j = 0; j < HRTF_SH_CHANNELS; j++ ) + { + ptW16 = (int16_t *) hrtf_data_rptr; + for ( k = 0; k < HRTF_NUM_BINS; k++ ) + { + ( *hHRTF )->hrtfShCoeffsIm[i][j][k] = (float) ptW16[k] * powf( 2.f, -1.f * (float) factorQ ); + } + hrtf_data_rptr += data_size_tmp; + } + } + + /* Reverb Parameters */ + if ( CLDFB_NO_CHANNELS_MAX != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (CLDFB_NO_CHANNELS_MAX)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + /* Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + ptW16 = (int16_t *) hrtf_data_rptr; + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + ( *hHRTF )->parametricReverberationTimes[j] = (float) ptW16[j] * powf( 2.f, -1.f * factorQ ); + } + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + + /* Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + ptW16 = (int16_t *) hrtf_data_rptr; + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + ( *hHRTF )->parametricReverberationEneCorrections[j] = (float) ptW16[j] * powf( 2.f, -1.f * factorQ ); + } + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + + /* Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + + ptW16 = (int16_t *) hrtf_data_rptr; + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + ( *hHRTF )->parametricEarlyPartEneCorrection[j] = (float) ptW16[j] * powf( 2.f, -1.f * factorQ ); + } + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + + return IVAS_ERR_OK; +} + +#endif + +static ivas_error create_fastconv_HRTF_from_rawdata( + HRTFS_FASTCONV_HANDLE *hHRTF, /* i/o: HRTF FastConv handle */ + char *hrtf_data, /* i : pointer to binary file */ + HRTF_READER_RENDERER_TYPE rend_type, /* i : Renderer type */ + BINAURAL_INPUT_AUDIO_CONFIG input_cfg /* i : Input binaural config */ +) +{ + int16_t i, j; + char *hrtf_data_rptr; + ivas_error error; + + ( *hHRTF )->allocate_init_flag = 0; + + if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) + { + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) + { + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV_ROOM, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" ); + } + + hrtf_data_rptr = hrtf_data; + + /* HRIR */ + if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + { + ( *hHRTF )->FASTCONV_HRIR_latency_s = *( (float *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( float ); + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( BINAURAL_NTAPS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->leftHRIRReal[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->leftHRIRImag[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->rightHRIRReal[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->rightHRIRImag[i][j], hrtf_data_rptr, BINAURAL_NTAPS * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS * sizeof( float ); + } + } + } + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) + { + /* HRIR_HOA3 */ + ( *hHRTF )->FASTCONV_HOA3_latency_s = *( (float *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( float ); + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( HOA3_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA3_CHANNELS)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + + if ( BINAURAL_NTAPS_SBA != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS_SBA)" ); + } + hrtf_data_rptr += sizeof( uint16_t ); + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->leftHRIRReal_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->leftHRIRImag_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->rightHRIRReal_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < HOA3_CHANNELS; j++ ) + { + memcpy( ( *hHRTF )->rightHRIRImag_HOA3[i][j], hrtf_data_rptr, BINAURAL_NTAPS_SBA * sizeof( float ) ); + hrtf_data_rptr += BINAURAL_NTAPS_SBA * sizeof( float ); + } + } + } + else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) + { + /* HRIR_HOA2 */ + ( *hHRTF )->FASTCONV_HOA2_latency_s = *( (float *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( float ); + + if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); } @@ -1467,6 +2398,9 @@ ivas_error load_fastconv_HRTF_from_binary( ivas_hrtfs_file_header_t hrtfs_file_header; int16_t hrtf_id; int16_t asFastconv = 0; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; +#endif f_hrtf = hrtfReader->file; @@ -1493,7 +2427,11 @@ ivas_error load_fastconv_HRTF_from_binary( /* Read & load */ for ( hrtf_id = 0; hrtf_id < hrtfs_file_header.nb_hrtf; hrtf_id++ ) { +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( read_hrtf_binary_header( &hrtf_header, &is_fx, f_hrtf ) != IVAS_ERR_OK ) +#else if ( read_hrtf_binary_header( &hrtf_header, f_hrtf ) != IVAS_ERR_OK ) +#endif { free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); @@ -1507,13 +2445,26 @@ ivas_error load_fastconv_HRTF_from_binary( return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } - /* Create the HRTF reading the raw data from the binary file */ - if ( ( create_fastconv_HRTF_from_rawdata( &hHrtfFastConv, hrtf_data, hrtf_header.rend_type, hrtf_header.input_cfg ) ) != IVAS_ERR_OK ) +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( is_fx ) { - free( hrtf_data ); - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + /* Create the HRTF reading the raw data from the binary file */ + if ( ( create_fastconv_HRTF_from_rawdata_fx( &hHrtfFastConv, hrtf_data, hrtf_header.rend_type, hrtf_header.input_cfg ) ) != IVAS_ERR_OK ) + { + free( hrtf_data ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + } } - + else + { + /* Create the HRTF reading the raw data from the binary file */ + if ( ( create_fastconv_HRTF_from_rawdata( &hHrtfFastConv, hrtf_data, hrtf_header.rend_type, hrtf_header.input_cfg ) ) != IVAS_ERR_OK ) + { + free( hrtf_data ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + } + } +#endif asFastconv = 1; } else @@ -1623,6 +2574,9 @@ ivas_error load_parambin_HRTF_from_binary( ivas_hrtfs_file_header_t hrtfs_file_header; int16_t hrtf_id; int16_t asParam = 0; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; +#endif f_hrtf = hrtfReader->file; @@ -1651,13 +2605,20 @@ ivas_error load_parambin_HRTF_from_binary( for ( hrtf_id = 0; hrtf_id < hrtfs_file_header.nb_hrtf; hrtf_id++ ) { +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( read_hrtf_binary_header( &hrtf_header, &is_fx, f_hrtf ) != IVAS_ERR_OK ) +#else if ( read_hrtf_binary_header( &hrtf_header, f_hrtf ) != IVAS_ERR_OK ) +#endif { free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); } - +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + if ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) /* Parametric binauralizer data is represented as single entity */ +#else if ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Parametric binauralizer data is represented as single entity */ +#endif { if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { @@ -1665,13 +2626,24 @@ ivas_error load_parambin_HRTF_from_binary( return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } - /* Create the HRTF reading the raw data from the binary file */ - if ( ( create_parambin_HRTF_from_rawdata( &hHrtfParamBin, hrtf_data ) ) != IVAS_ERR_OK ) + if ( is_fx == 1 ) { - free( hrtf_data ); - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + /* Create the HRTF reading the raw data from the binary file */ + if ( ( create_parambin_HRTF_from_rawdata_fx( &hHrtfParamBin, hrtf_data ) ) != IVAS_ERR_OK ) + { + free( hrtf_data ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + } + } + else + { + /* Create the HRTF reading the raw data from the binary file */ + if ( ( create_parambin_HRTF_from_rawdata( &hHrtfParamBin, hrtf_data ) ) != IVAS_ERR_OK ) + { + free( hrtf_data ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + } } - asParam = 1; } else @@ -1691,7 +2663,6 @@ ivas_error load_parambin_HRTF_from_binary( } } - /*---------------------------------------------------------------------* * create_SetOfHRTF_from_binary() * @@ -1711,6 +2682,9 @@ ivas_error create_SetOfHRTF_from_binary( ivas_error header_check_result; ivas_hrtfs_file_header_t hrtfs_file_header; int16_t hrtf_id; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; +#endif f_hrtf = hrtfReader->file; @@ -1740,7 +2714,11 @@ ivas_error create_SetOfHRTF_from_binary( for ( hrtf_id = 0; hrtf_id < hrtfs_file_header.nb_hrtf; hrtf_id++ ) { +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( read_hrtf_binary_header( &hrtf_header, &is_fx, f_hrtf ) != IVAS_ERR_OK ) +#else if ( read_hrtf_binary_header( &hrtf_header, f_hrtf ) != IVAS_ERR_OK ) +#endif { free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); @@ -1785,12 +2763,31 @@ ivas_error create_SetOfHRTF_from_binary( if ( hHRTF != NULL ) { - /* Create the HRTF reading the raw data from the binary file */ +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( is_fx ) + { + /* Create the HRTF reading the raw data from the binary file */ + if ( ( create_HRTF_from_rawdata_fx( hHRTF, hrtf_data ) ) != IVAS_ERR_OK ) + { + free( hrtf_data ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + } + } + else + { + if ( ( create_HRTF_from_rawdata( hHRTF, hrtf_data ) ) != IVAS_ERR_OK ) + { + free( hrtf_data ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); + } + } +#else if ( ( create_HRTF_from_rawdata( hHRTF, hrtf_data ) ) != IVAS_ERR_OK ) { free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create HRTF from binary file" ); } +#endif } } diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index ab3254806f681abf6f0cf1dd8fc23644b4630ef1..914489508a5e42365a7af90b75b069d881dc77aa 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -43,7 +43,9 @@ typedef enum HRTF_READER_RENDERER_BINAURAL_FASTCONV, HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM, HRTF_READER_RENDERER_BINAURAL_PARAMETRIC, +#ifndef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM, +#endif HRTF_READER_RENDERER_BINAURAL_OBJECTS_TD, HRTF_READER_RENDERER_BINAURAL_MIXER_CONV, HRTF_READER_RENDERER_BINAURAL_MIXER_CONV_ROOM, diff --git a/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c b/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c index 7e0d07685a8f6ed28b9483ae1172ab90b537d7af..eacfeaa06b8e10ee4cf4c644fc38fe806c823e14 100644 --- a/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c +++ b/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c @@ -40,6 +40,9 @@ #include "ivas_stat_dec.h" #include "hrtf_file_reader.h" #include "ivas_rom_rend.h" +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT +#include +#endif #define FILE_HEADER @@ -57,9 +60,13 @@ #define DEFAULT_BIN_FILE_EXT ".bin" +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT +#define DEFAULT_BIN_FILE_FX_FLAG 0x1000 +#endif + #define IVAS_NB_RENDERER_TYPE 7 -#define IVAS_NB_AUDIO_CONFIG 4 -#define IVAS_NB_SAMPLERATE 3 +#define IVAS_NB_AUDIO_CONFIG 4 +#define IVAS_NB_SAMPLERATE 3 const HRTF_READER_RENDERER_TYPE rend_types[IVAS_NB_RENDERER_TYPE] = { @@ -95,8 +102,13 @@ typedef struct _crend_hrtf_tables_dimensions int16_t max_num_ir; int16_t max_num_iterations; int16_t max_num_iterations_diffuse; +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + uint32_t max_total_num_fsamp_per_iteration; + uint32_t max_total_num_fsamp_per_iteration_diff; +#else uint16_t max_total_num_fsamp_per_iteration; uint16_t max_total_num_fsamp_per_iteration_diff; +#endif } crend_hrtf_tables_dimensions; @@ -138,7 +150,9 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD int16_t get_crend_hrtf_tables( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUDIO_CONFIG input_cfg, int32_t frequency, crend_hrtf_tables_pointers *hrtf_table_ptrs /*OUT*/, crend_hrtf_tables_dimensions *hrtf_table_dims /*OUT*/ ); int32_t compute_crend_hrtf_data_size( crend_hrtf_tables_pointers *hrtf_table_ptrs, crend_hrtf_tables_dimensions *hrtf_table_dims ); - +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT +int32_t compute_crend_hrtf_data_size_fx( crend_hrtf_tables_pointers *hrtf_table_ptrs, crend_hrtf_tables_dimensions *hrtf_table_dims ); +#endif /*---------------------------------------------------------------------* * usage_gen_crend_tables() * @@ -169,10 +183,10 @@ void usage_tables_format_converter( void ) fprintf( stdout, "-input_fastconv_file_name : if exist name of input fastconv file with extension.\n" ); fprintf( stdout, "-input_param_file_path : if exist path of binary file for parametric renderer.\n" ); fprintf( stdout, "-input_param_file_name : if exist name of input param file with extension.\n" ); - fprintf( stdout, "-input_mixerconv_file_hrir_path : if exist path of binary files for mixer_conv hrir renderer.\n" ); - fprintf( stdout, "-input_mixerconv_file_hrir_name : if exist common name of input mixer_conv hrir files.\n" ); - fprintf( stdout, "-input_mixerconv_file_brir_path : if exist path of binary files for mixer_conv brir renderer.\n" ); - fprintf( stdout, "-input_mixerconv_file_brir_name : if exist common name of input mixer_conv brir files.\n" ); + fprintf( stdout, "-input_mixerconv_hrir_file_path : if exist path of binary files for mixer_conv hrir renderer.\n" ); + fprintf( stdout, "-input_mixerconv_hrir_file_name : if exist common name of input mixer_conv hrir files.\n" ); + fprintf( stdout, "-input_mixerconv_brir_file_path : if exist path of binary files for mixer_conv brir renderer.\n" ); + fprintf( stdout, "-input_mixerconv_brir_file_name : if exist common name of input mixer_conv brir files.\n" ); fprintf( stdout, "\n" ); fprintf( stdout, "For example :\n" #ifdef _WIN32 @@ -613,7 +627,9 @@ char *create_hrtf_crend( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD { int32_t mixerconv_hrtf_header_size, mixerconv_hrtf_data_size; char *mixerconv_hrtf = NULL, *mixerconv_hrtf_wptr; - +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; +#endif char *full_in_mixerconv_path = NULL; FILE *input_mixerconv_bin_file = NULL; @@ -641,11 +657,35 @@ char *create_hrtf_crend( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD { configuration_name = "HOA3_HRIR"; } +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( strstr( input_mixerconv_bin_hrir_file_name, "_fx" ) ) + { + input_mixerconv_bin_hrir_file_name[strlen( input_mixerconv_bin_hrir_file_name ) - 3] = '\0'; + is_fx = 1; + } + full_in_mixerconv_path = malloc( strlen( input_mixerconv_bin_hrir_path ) + 1 + strlen( input_mixerconv_bin_hrir_file_name ) + 1 + strlen( configuration_name ) + 1 + 5 + strlen( DEFAULT_BIN_FILE_EXT ) + 1 + ( is_fx == 1 ? 3 : 0 ) ); +#ifdef _WIN32 + if ( is_fx == 1 ) + sprintf( full_in_mixerconv_path, "%s\\%s_%s_%dkHz_fx%s", input_mixerconv_bin_hrir_path, input_mixerconv_bin_hrir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); + else + sprintf( full_in_mixerconv_path, "%s\\%s_%s_%dkHz%s", input_mixerconv_bin_hrir_path, input_mixerconv_bin_hrir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#else + if ( is_fx == 1 ) + sprintf( full_in_mixerconv_path, "%s/%s_%s_%dkHz_fx%s", input_mixerconv_bin_hrir_path, input_mixerconv_bin_hrir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); + else + sprintf( full_in_mixerconv_path, "%s/%s_%s_%dkHz%s", input_mixerconv_bin_hrir_path, input_mixerconv_bin_hrir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#endif + if ( is_fx == 1 ) + { + input_mixerconv_bin_hrir_file_name[strlen( input_mixerconv_bin_hrir_file_name )] = '_'; + } +#else full_in_mixerconv_path = malloc( strlen( input_mixerconv_bin_hrir_path ) + 1 + strlen( input_mixerconv_bin_hrir_file_name ) + 1 + strlen( configuration_name ) + 1 + 5 + strlen( DEFAULT_BIN_FILE_EXT ) + 1 ); #ifdef _WIN32 sprintf( full_in_mixerconv_path, "%s\\%s_%s_%dkHz%s", input_mixerconv_bin_hrir_path, input_mixerconv_bin_hrir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); #else sprintf( full_in_mixerconv_path, "%s/%s_%s_%dkHz%s", input_mixerconv_bin_hrir_path, input_mixerconv_bin_hrir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#endif #endif } else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_MIXER_CONV_ROOM ) @@ -666,11 +706,35 @@ char *create_hrtf_crend( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD { return NULL; } +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( strstr( input_mixerconv_bin_brir_file_name, "_fx" ) ) + { + input_mixerconv_bin_brir_file_name[strlen( input_mixerconv_bin_brir_file_name ) - 3] = '\0'; + is_fx = 1; + } + full_in_mixerconv_path = malloc( strlen( input_mixerconv_bin_brir_path ) + 1 + strlen( input_mixerconv_bin_brir_file_name ) + 1 + strlen( configuration_name ) + 1 + 5 + strlen( DEFAULT_BIN_FILE_EXT ) + 1 ); +#ifdef _WIN32 + if ( is_fx == 1 ) + sprintf( full_in_mixerconv_path, "%s\\%s_%s_%dkHz_fx%s", input_mixerconv_bin_brir_path, input_mixerconv_bin_brir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); + else + sprintf( full_in_mixerconv_path, "%s\\%s_%s_%dkHz%s", input_mixerconv_bin_brir_path, input_mixerconv_bin_brir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#else + if ( is_fx == 1 ) + sprintf( full_in_mixerconv_path, "%s/%s_%s_%dkHz_fx%s", input_mixerconv_bin_brir_path, input_mixerconv_bin_brir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); + else + sprintf( full_in_mixerconv_path, "%s/%s_%s_%dkHz%s", input_mixerconv_bin_brir_path, input_mixerconv_bin_brir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#endif + if ( is_fx == 1 ) + { + input_mixerconv_bin_brir_file_name[strlen( input_mixerconv_bin_brir_file_name )] = '_'; + } +#else full_in_mixerconv_path = malloc( strlen( input_mixerconv_bin_brir_path ) + 1 + strlen( input_mixerconv_bin_brir_file_name ) + 1 + strlen( configuration_name ) + 1 + 5 + strlen( DEFAULT_BIN_FILE_EXT ) + 1 ); #ifdef _WIN32 sprintf( full_in_mixerconv_path, "%s\\%s_%s_%dkHz%s", input_mixerconv_bin_brir_path, input_mixerconv_bin_brir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); #else sprintf( full_in_mixerconv_path, "%s/%s_%s_%dkHz%s", input_mixerconv_bin_brir_path, input_mixerconv_bin_brir_file_name, configuration_name, frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#endif #endif } @@ -706,6 +770,12 @@ char *create_hrtf_crend( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD // Get the HRTF header // Renderer type +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( is_fx == 1 ) + { + rend_type = rend_type + DEFAULT_BIN_FILE_FX_FLAG; + } +#endif memcpy( mixerconv_hrtf_wptr, &( rend_type ), sizeof( int32_t ) ); mixerconv_hrtf_wptr += sizeof( int32_t ); @@ -722,8 +792,7 @@ char *create_hrtf_crend( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD mixerconv_hrtf_wptr += sizeof( uint32_t ); // Get the HRTF raw data - - if ( fread( mixerconv_hrtf_wptr, mixerconv_hrtf_data_size, 1, input_mixerconv_bin_file ) != 1 ) + if ( fread( mixerconv_hrtf_wptr, 1, mixerconv_hrtf_data_size, input_mixerconv_bin_file ) != mixerconv_hrtf_data_size ) { fprintf( stderr, "Reading of the mixer_conv hrtf failed!\n\n" ); fclose( input_mixerconv_bin_file ); @@ -866,9 +935,40 @@ char *create_reverb( int32_t frequency, int32_t *hrtf_size ) FILE *input_reverb_file = NULL; int32_t reverb_header_size, reverb_data_size; char *reverb = NULL, *reverb_wptr, *full_in_reverb_path = NULL; - +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; +#endif *hrtf_size = 0; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( strstr( input_reverb_file_name, "_fx" ) ) + { + input_reverb_file_name[strlen( input_reverb_file_name ) - 3] = '\0'; + is_fx = 1; + } + full_in_reverb_path = (char *) malloc( sizeof( char ) * ( strlen( input_reverb_file_path ) + 1 + strlen( input_reverb_file_name ) + 1 + strlen( "Reverb" ) + 1 + 5 + strlen( DEFAULT_BIN_FILE_EXT ) + 1 ) + ( is_fx == 1 ? 3 : 0 ) ); + if ( full_in_reverb_path == NULL ) + { + fprintf( stderr, "Memory issue for full input td path!\n\n" ); + rom2bin_terminat(); + return NULL; + } +#ifdef _WIN32 + if ( is_fx == 1 ) + sprintf( full_in_reverb_path, "%s\\%s_%s_%dkHz_fx%s", input_reverb_file_path, input_reverb_file_name, "Reverb", frequency / 1000, DEFAULT_BIN_FILE_EXT ); + else + sprintf( full_in_reverb_path, "%s\\%s_%s_%dkHz%s", input_reverb_file_path, input_reverb_file_name, "Reverb", frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#else + if ( is_fx == 1 ) + sprintf( full_in_reverb_path, "%s/%s_%s_%dkHz_fx%s", input_reverb_file_path, input_reverb_file_name, "Reverb", frequency / 1000, DEFAULT_BIN_FILE_EXT ); + else + sprintf( full_in_reverb_path, "%s/%s_%s_%dkHz%s", input_reverb_file_path, input_reverb_file_name, "Reverb", frequency / 1000, DEFAULT_BIN_FILE_EXT ); +#endif + if ( is_fx == 1 ) + { + input_reverb_file_name[strlen( input_reverb_file_name )] = '_'; + } +#else full_in_reverb_path = (char *) malloc( sizeof( char ) * ( strlen( input_reverb_file_path ) + 1 + strlen( input_reverb_file_name ) + 1 + strlen( "Reverb" ) + 1 + 5 + strlen( DEFAULT_BIN_FILE_EXT ) + 1 ) ); if ( full_in_reverb_path == NULL ) { @@ -882,6 +982,9 @@ char *create_reverb( int32_t frequency, int32_t *hrtf_size ) #else sprintf( full_in_reverb_path, "%s/%s_%s_%dkHz%s", input_reverb_file_path, input_reverb_file_name, "Reverb", frequency / 1000, DEFAULT_BIN_FILE_EXT ); #endif + +#endif + input_reverb_file = fopen( full_in_reverb_path, "rb" ); if ( input_reverb_file != NULL ) @@ -917,7 +1020,18 @@ char *create_reverb( int32_t frequency, int32_t *hrtf_size ) // Get the HRTF header // Renderer type +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( is_fx == 1 ) + { + *( (int32_t *) ( reverb_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_REVERB_ALL + DEFAULT_BIN_FILE_FX_FLAG; + } + else + { + *( (int32_t *) ( reverb_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_REVERB_ALL; + } +#else *( (int32_t *) ( reverb_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_REVERB_ALL; +#endif reverb_wptr += sizeof( int32_t ); // Decoder output format @@ -974,6 +1088,9 @@ char *create_hrtf_fastconv( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_ int32_t hrtf_total_file_size = 0, hrtf_data_size = 0; int16_t nbHrft = 0, ind; ivas_hrtfs_header_t hrtf_header; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + int16_t is_fx = 0; +#endif fastconv_hrtf_data_size = 0; @@ -1024,8 +1141,14 @@ char *create_hrtf_fastconv( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_ return NULL; } - // Get the HRTF raw data + // Get the HRTF raw data +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( strstr( input_fastconv_bin_file_name, "_fx" ) ) + { + is_fx = 1; + } +#endif full_in_fastconv_path = (char *) malloc( sizeof( char ) * ( strlen( input_fastconv_bin_path ) + strlen( input_fastconv_bin_file_name ) + 2 ) ); if ( full_in_fastconv_path == NULL ) { @@ -1158,6 +1281,12 @@ char *create_hrtf_fastconv( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_ // Get the HRTF header // Renderer type +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( is_fx == 1 ) + { + rend_type = rend_type + DEFAULT_BIN_FILE_FX_FLAG; + } +#endif memcpy( fastconv_hrtf_wptr, &( rend_type ), sizeof( int32_t ) ); fastconv_hrtf_wptr += sizeof( int32_t ); @@ -1175,7 +1304,7 @@ char *create_hrtf_fastconv( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_ // Get the HRTF raw data - if ( fread( fastconv_hrtf_wptr, fastconv_hrtf_data_size, 1, input_fastconv_bin_file ) != 1 ) + if ( fread( fastconv_hrtf_wptr, 1, fastconv_hrtf_data_size, input_fastconv_bin_file ) != fastconv_hrtf_data_size ) { fprintf( stderr, "Reading of the fastconv hrtf failed!\n\n" ); fclose( input_fastconv_bin_file ); @@ -1210,6 +1339,16 @@ char *create_hrtf_parametric( int32_t *hrtf_size ) uint32_t data_size_tmp; int16_t i, j; + FILE *input_param_bin_file = NULL; + +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + char hrtf_identifier[8] = ""; + int16_t is_fx = 0; + if ( strstr( input_param_bin_file_name, "_fx" ) ) + { + is_fx = 1; + } +#else uint8_t file_read_ok; float hrtfShCoeffsReFile[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; @@ -1218,8 +1357,7 @@ char *create_hrtf_parametric( int32_t *hrtf_size ) float parametricReverberationTimesFile[CLDFB_NO_CHANNELS_MAX]; float parametricReverberationEneCorrectionsFile[CLDFB_NO_CHANNELS_MAX]; float parametricEarlyPartEneCorrectionFile[CLDFB_NO_CHANNELS_MAX]; - - FILE *input_param_bin_file = NULL; +#endif full_in_param_bin_path = (char *) malloc( sizeof( char ) * ( strlen( input_param_bin_path ) + strlen( input_param_bin_file_name ) + 2 ) ); if ( full_in_param_bin_path == NULL ) @@ -1236,6 +1374,84 @@ char *create_hrtf_parametric( int32_t *hrtf_size ) hrtf_data_size = 0; +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + + input_param_bin_file = fopen( full_in_param_bin_path, "rb" ); + + if ( input_param_bin_file != NULL ) + { + uint16_t hrtf_sh_channels, hrtf_num_bins, cldfb_no_channels_max; + + fseek( input_param_bin_file, 0, SEEK_END ); + hrtf_data_size = ftell( input_param_bin_file ); + fseek( input_param_bin_file, 0, SEEK_SET ); + + // Allocate memory + *hrtf_size = sizeof( ivas_hrtfs_header_t ) + hrtf_data_size; + hrtf = (char *) malloc( *hrtf_size ); + if ( hrtf == NULL ) + { + fprintf( stderr, "Memory allocation for the block failed!\n\n" ); + fclose( input_param_bin_file ); + free( full_in_param_bin_path ); + *hrtf_size = -1; + return NULL; + } + + memset( hrtf, 0x00, *hrtf_size ); + hrtf_wptr = hrtf; + +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + if ( is_fx == 1 ) + { + *( (int32_t *) ( hrtf_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_PARAMETRIC + DEFAULT_BIN_FILE_FX_FLAG; + } + else + { + *( (int32_t *) ( hrtf_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_PARAMETRIC; + } +#else + if ( is_fx == 1 ) + { + *( (int32_t *) ( hrtf_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM + DEFAULT_BIN_FILE_FX_FLAG; + } + else + { + *( (int32_t *) ( hrtf_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM; + } +#endif + hrtf_wptr += sizeof( int32_t ); + + // Decoder output format - not relevant parametric binaural renderer + *( (int32_t *) ( hrtf_wptr ) ) = BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED; + hrtf_wptr += sizeof( int32_t ); + + // Sampling Frequency + *( (int32_t *) ( hrtf_wptr ) ) = 48000; + hrtf_wptr += sizeof( int32_t ); + + // Raw data size + memcpy( hrtf_wptr, &( hrtf_data_size ), sizeof( uint32_t ) ); + hrtf_wptr += sizeof( uint32_t ); + + // Get the HRTF raw data + + if ( fread( hrtf_wptr, 1, hrtf_data_size, input_param_bin_file ) != hrtf_data_size ) + { + fprintf( stderr, "Reading of the mixer_conv hrtf failed!\n\n" ); + fclose( input_param_bin_file ); + free( hrtf ); + *hrtf_size = -1; + return NULL; + } + + fclose( input_param_bin_file ); + input_param_bin_file = NULL; + free( full_in_param_bin_path ); + full_in_param_bin_path = NULL; + } + +#else /* Binary file - block description : HRTFs @@ -1334,7 +1550,6 @@ char *create_hrtf_parametric( int32_t *hrtf_size ) return NULL; } - // Write // Header [Declaration of the HRTF] @@ -1347,7 +1562,11 @@ char *create_hrtf_parametric( int32_t *hrtf_size ) hrtf_wptr = hrtf; // Renderer type - we use only parametric room type here to cover both cases +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + *( (int32_t *) ( hrtf_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_PARAMETRIC; +#else *( (int32_t *) ( hrtf_wptr ) ) = HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM; +#endif hrtf_wptr += sizeof( int32_t ); // Decoder output format - not relevant parametric binaural renderer @@ -1362,7 +1581,6 @@ char *create_hrtf_parametric( int32_t *hrtf_size ) memcpy( hrtf_wptr, &( hrtf_data_size ), sizeof( uint32_t ) ); hrtf_wptr += sizeof( uint32_t ); - // Write the HRTF raw data *( (uint16_t *) ( hrtf_wptr ) ) = HRTF_SH_CHANNELS; hrtf_wptr += sizeof( uint16_t ); @@ -1426,6 +1644,8 @@ char *create_hrtf_parametric( int32_t *hrtf_size ) memcpy( hrtf_wptr, &( parametricEarlyPartEneCorrection ), data_size_tmp ); // parametricEarlyPartEneCorrection hrtf_wptr += data_size_tmp; } +#endif + return hrtf; } @@ -1437,7 +1657,7 @@ int16_t get_crend_hrtf_tables( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INP { int16_t result = -1; uint16_t iChan, iIR, iIter, iIndex, max_num_iterations; - uint16_t total_num_fsamp_per_iteration, total_num_fsamp_per_iteration_diff; + uint32_t total_num_fsamp_per_iteration, total_num_fsamp_per_iteration_diff; crend_hrtf_tables_pointers hrtf_table_ptrs_out; crend_hrtf_tables_dimensions hrtf_table_dims_out; @@ -1844,6 +2064,82 @@ int16_t get_crend_hrtf_tables( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INP return result; } +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT +/*---------------------------------------------------------------------* + * compute_crend_hrtf_data_size_fx() + * + *---------------------------------------------------------------------*/ +int32_t compute_crend_hrtf_data_size_fx( crend_hrtf_tables_pointers *hrtf_table_ptrs, crend_hrtf_tables_dimensions *hrtf_table_dims ) +{ + int32_t hrtf_data_size = 0; + int32_t iChan, iIR, iIndex, iIter; + + if ( ( hrtf_table_ptrs == NULL ) || ( hrtf_table_dims == NULL ) ) + { + return 0; + } + + hrtf_data_size += sizeof( Word16 ); // latency_s factor Q + hrtf_data_size += sizeof( Word32 ); // latency_s + hrtf_data_size += sizeof( uint16_t ); // max_num_ir + hrtf_data_size += sizeof( uint16_t ); // BINAURAL_CHANNELS + hrtf_data_size += sizeof( int16_t ); // max_num_iterations + hrtf_data_size += hrtf_table_dims->max_num_ir * BINAURAL_CHANNELS * sizeof( uint16_t ); // num_iterations + hrtf_data_size += hrtf_table_dims->max_num_ir * BINAURAL_CHANNELS * hrtf_table_dims->max_num_iterations * sizeof( uint16_t ); // pIndex_frequency_max + + hrtf_data_size += sizeof( int16_t ); // max_num_iterations_diffuse + if ( hrtf_table_dims->max_num_iterations_diffuse != 0 ) + { + hrtf_data_size += BINAURAL_CHANNELS * sizeof( uint16_t ); // num_iterations_diffuse + // pIndex_frequency_max_diffuse : The size depends on num_iterations_diffuse + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + hrtf_data_size += hrtf_table_ptrs->num_iterations_diffuse[iChan] * sizeof( uint16_t ); + } + } + + hrtf_data_size += sizeof( uint16_t ); // index_frequency_max_diffuse + hrtf_data_size += sizeof( Word16 ); // inv_diffuse_weight factor Q + hrtf_data_size += hrtf_table_dims->max_num_ir * BINAURAL_CHANNELS * sizeof( Word16 ); // inv_diffuse_weight +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration +#else + hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration +#endif + + hrtf_data_size += sizeof( Word16 ); // filters factor Q + // coeff_re & coeff_im : The size depends on pIndex_frequency_max + for ( iIR = 0, iIndex = 0; iIR < hrtf_table_dims->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + for ( iIter = 0; iIter < hrtf_table_ptrs->num_iterations[iIR * BINAURAL_CHANNELS + iChan]; iIter++ ) + { + hrtf_data_size += 2 * hrtf_table_ptrs->pIndex_frequency_max[iIndex++] * sizeof( Word32 ); // 2* : re & im + } + } + } + +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration_diff +#else + hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration_diff +#endif + if ( hrtf_table_dims->max_total_num_fsamp_per_iteration_diff != 0 ) + { + // coeff_diffuse_re & coeff_diffuse_im : The size depends on pIndex_frequency_max + for ( iChan = 0, iIndex = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + for ( iIter = 0; iIter < hrtf_table_ptrs->num_iterations_diffuse[iChan]; iIter++ ) + { + hrtf_data_size += 2 * hrtf_table_ptrs->pIndex_frequency_max_diffuse[iIndex++] * sizeof( Word32 ); // 2* : re & im + } + } + } + + return hrtf_data_size; +} +#endif /*---------------------------------------------------------------------* * compute_crend_hrtf_data_size() * @@ -1876,9 +2172,13 @@ int32_t compute_crend_hrtf_data_size( crend_hrtf_tables_pointers *hrtf_table_ptr } } - hrtf_data_size += sizeof( uint16_t ); // index_frequency_max_diffuse + hrtf_data_size += sizeof( uint16_t ); // index_frequency_max_diffuse hrtf_data_size += hrtf_table_dims->max_num_ir * BINAURAL_CHANNELS * sizeof( float ); // inv_diffuse_weight +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration +#else hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration +#endif // coeff_re & coeff_im : The size depends on pIndex_frequency_max for ( iIR = 0, iIndex = 0; iIR < hrtf_table_dims->max_num_ir; iIR++ ) { @@ -1891,7 +2191,11 @@ int32_t compute_crend_hrtf_data_size( crend_hrtf_tables_pointers *hrtf_table_ptr } } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration_diff +#else hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration_diff +#endif if ( hrtf_table_dims->max_total_num_fsamp_per_iteration_diff != 0 ) { // coeff_diffuse_re & coeff_diffuse_im : The size depends on pIndex_frequency_max @@ -2038,7 +2342,11 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD if ( rend_type == HRTF_READER_RENDERER_BINAURAL_OBJECTS_TD || rend_type == HRTF_READER_RENDERER_BINAURAL_REVERB_ALL || rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM || +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) +#else rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC || rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM ) +#endif { return 0; } @@ -2062,7 +2370,14 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD return -1; } +#ifdef FLOAT_FIX_POINT_HRTF_FILE_FORMAT + if ( rend_type & DEFAULT_BIN_FILE_FX_FLAG ) + hrtf_data_size = compute_crend_hrtf_data_size_fx( &tabs_ptrs, &tabs_dims ); + else + hrtf_data_size = compute_crend_hrtf_data_size( &tabs_ptrs, &tabs_dims ); +#else hrtf_data_size = compute_crend_hrtf_data_size( &tabs_ptrs, &tabs_dims ); +#endif if ( hrtf_data_size != hrtf_size_in ) { fprintf( stderr, "check_hrtf_data of binary file failed: bad hrtf_data_size!\n\n" ); @@ -2073,13 +2388,21 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD hrtf_data_in_rptr = hrtf_data_in; - // latency_s +// latency_s +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + if ( ( *( tabs_ptrs.latency_s ) - ( *( (Word32 *) ( hrtf_data_in_rptr ) ) ) * powf( 2.f, -31.f ) ) > 1e-9f ) +#else if ( ( *( tabs_ptrs.latency_s ) - *( (float *) ( hrtf_data_in_rptr ) ) ) > 1e-9f ) +#endif { fprintf( stderr, "check_hrtf_data of binary file failed: bad latency_s!\n\n" ); return -1; } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + hrtf_data_in_rptr += sizeof( Word32 ); +#else hrtf_data_in_rptr += sizeof( float ); +#endif // max_num_ir if ( tabs_dims.max_num_ir != *( (uint16_t *) ( hrtf_data_in_rptr ) ) ) @@ -2164,7 +2487,11 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD hrtf_data_in_rptr += sizeof( uint16_t ); // inv_diffuse_weight +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ctrl_size = tabs_dims.max_num_ir * BINAURAL_CHANNELS * sizeof( Word16 ); +#else ctrl_size = tabs_dims.max_num_ir * BINAURAL_CHANNELS * sizeof( float ); +#endif if ( memcmp( tabs_ptrs.inv_diffuse_weight, hrtf_data_in_rptr, ctrl_size ) != 0 ) { fprintf( stderr, "check_hrtf_data of binary file failed: bad inv_diffuse_weight!\n\n" ); @@ -2180,8 +2507,12 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD }*/ hrtf_data_in_rptr += ctrl_size; - // max_total_num_fsamp_per_iteration +// max_total_num_fsamp_per_iteration +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + if ( tabs_dims.max_total_num_fsamp_per_iteration != *( (uint32_t *) ( hrtf_data_in_rptr ) ) ) +#else if ( tabs_dims.max_total_num_fsamp_per_iteration != *( (uint16_t *) ( hrtf_data_in_rptr ) ) ) +#endif { fprintf( stderr, "check_hrtf_data of binary file failed: bad max_total_num_fsamp_per_iteration!\n\n" ); return -1; @@ -2196,7 +2527,11 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD coeff_rptr = tabs_ptrs.coeff_re + ( iIR * BINAURAL_CHANNELS + iChan ) * tabs_dims.max_total_num_fsamp_per_iteration; for ( iIter = 0; iIter < tabs_ptrs.num_iterations[iIR * BINAURAL_CHANNELS + iChan]; iIter++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ctrl_size = tabs_ptrs.pIndex_frequency_max[iIndex] * sizeof( Word32 ); +#else ctrl_size = tabs_ptrs.pIndex_frequency_max[iIndex] * sizeof( float ); +#endif if ( memcmp( coeff_rptr, hrtf_data_in_rptr, ctrl_size ) != 0 ) { fprintf( stderr, "check_hrtf_data of binary file failed: bad coeff_re!\n\n" ); @@ -2225,7 +2560,11 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD coeff_rptr = tabs_ptrs.coeff_im + ( iIR * BINAURAL_CHANNELS + iChan ) * tabs_dims.max_total_num_fsamp_per_iteration; for ( iIter = 0; iIter < tabs_ptrs.num_iterations[iIR * BINAURAL_CHANNELS + iChan]; iIter++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ctrl_size = tabs_ptrs.pIndex_frequency_max[iIndex] * sizeof( Word32 ); +#else ctrl_size = tabs_ptrs.pIndex_frequency_max[iIndex] * sizeof( float ); +#endif if ( memcmp( coeff_rptr, hrtf_data_in_rptr, ctrl_size ) != 0 ) { fprintf( stderr, "check_hrtf_data of binary file failed: bad coeff_re!\n\n" ); @@ -2246,7 +2585,11 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD } // max_total_num_fsamp_per_iteration_diff +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + if ( tabs_dims.max_total_num_fsamp_per_iteration_diff != *( (uint32_t *) ( hrtf_data_in_rptr ) ) ) +#else if ( tabs_dims.max_total_num_fsamp_per_iteration_diff != *( (uint16_t *) ( hrtf_data_in_rptr ) ) ) +#endif { fprintf( stderr, "check_hrtf_data of binary file failed: bad max_total_num_fsamp_per_iteration_diff!\n\n" ); return -1; @@ -2261,7 +2604,11 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD coeff_rptr = tabs_ptrs.coeff_diffuse_re + iChan * tabs_dims.max_total_num_fsamp_per_iteration_diff; for ( iIter = 0; iIter < tabs_ptrs.num_iterations_diffuse[iChan]; iIter++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ctrl_size = tabs_ptrs.pIndex_frequency_max_diffuse[iIndex] * sizeof( Word32 ); +#else ctrl_size = tabs_ptrs.pIndex_frequency_max_diffuse[iIndex] * sizeof( float ); +#endif if ( memcmp( coeff_rptr, hrtf_data_in_rptr, ctrl_size ) != 0 ) { fprintf( stderr, "check_hrtf_data of binary file failed: bad coeff_diffuse_re!\n\n" ); @@ -2286,7 +2633,11 @@ int16_t check_hrtf_data( HRTF_READER_RENDERER_TYPE rend_type, BINAURAL_INPUT_AUD coeff_rptr = tabs_ptrs.coeff_diffuse_im + iChan * tabs_dims.max_total_num_fsamp_per_iteration_diff; for ( iIter = 0; iIter < tabs_ptrs.num_iterations_diffuse[iChan]; iIter++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ctrl_size = tabs_ptrs.pIndex_frequency_max_diffuse[iIndex] * sizeof( Word32 ); +#else ctrl_size = tabs_ptrs.pIndex_frequency_max_diffuse[iIndex] * sizeof( float ); +#endif if ( memcmp( coeff_rptr, hrtf_data_in_rptr, ctrl_size ) != 0 ) { fprintf( stderr, "check_hrtf_data of binary file failed: bad coeff_diffuse_im!\n\n" ); diff --git a/scripts/binauralRenderer_interface/clearButKeepNeededVariables.m b/scripts/binauralRenderer_interface/clearButKeepNeededVariables.m index f324edabb8f163f7407bc9a9e14221af27b9a346..49a020dcea7f49b85edf958c90c37920bd8d0e2d 100644 --- a/scripts/binauralRenderer_interface/clearButKeepNeededVariables.m +++ b/scripts/binauralRenderer_interface/clearButKeepNeededVariables.m @@ -1 +1 @@ -clear -regexp ^((?!writeRomFileOutput|writeBinaryOutput|writeEachRendererBinaryOutput|rom_file|bin_file|hrir_file|brir_file|ivas_path|binary_path|output_bin_name|param_bin_file|fastconv_bin_file|td_binary_file|binary_name|rom_path).)*$ +clear -regexp ^((?!writeRomFileOutput|writeBinaryOutput|generate_BE|generateBinaryFile_fx|generateCustomBinaryFile|writeEachRendererBinaryOutput|rom_file|bin_file|hrir_file|brir_file|ivas_path|binary_path|output_bin_name|param_bin_file|fastconv_bin_file|td_binary_file|binary_name|rom_path).)*$ diff --git a/scripts/binauralRenderer_interface/fastconv/generate_tables_for_fastconv.m b/scripts/binauralRenderer_interface/fastconv/generate_tables_for_fastconv.m index 75cb373cc96071b8b732883a6c58d9cdad1cdddc..37ec643f6351b3e1663b0e3daa817370fecbc6bd 100644 --- a/scripts/binauralRenderer_interface/fastconv/generate_tables_for_fastconv.m +++ b/scripts/binauralRenderer_interface/fastconv/generate_tables_for_fastconv.m @@ -49,6 +49,15 @@ end if ~exist("writeBinaryOutput",'var') writeBinaryOutput = true; end +if ~exist("generateCustomBinaryFile",'var') + generateCustomBinaryFile = false; +end +if ~exist("generateBinaryFile_fx",'var') + generateBinaryFile_fx = false; +end +if ~exist("generate_BE",'var') + generate_BE = true; +end if ~exist("rom_file",'var') rom_file = fullfile('.', 'ivas_rom_binauralRenderer.c'); end @@ -84,11 +93,32 @@ FastConv_SD_IR = SD_2_ROM(hrir_file); %% Generate C-code tables for RENDERER_BINAURAL_FASTCONV_ROOM (SD) disp('Processing BRIRs (SD) for FastConv renderer...'); FastConv_SD_BRIR = generate_BRIR_CLDFB_FASTCONV(brir_file); +if generateCustomBinaryFile == true + FastConv_SD_BRIR.rev_param.rt60 = FastConv_SD_BRIR.rev_param.rt60 * 2; + FastConv_SD_BRIR.rev_param.nrgLr = FastConv_SD_BRIR.rev_param.nrgLr * 2; +end -if writeRomFileOutput - write_fastconv_rom_table(rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR); +%% compute scaling factor and ste floating point precision to word32 +if generate_BE == false + [FastConv_SHD_IR_FOA.IR, FastConv_SHD_IR_FOA.factorQ] = make_be_with_fx(FastConv_SHD_IR_FOA.IR,31); + [FastConv_SHD_IR_HOA2.IR, FastConv_SHD_IR_HOA2.factorQ] = make_be_with_fx(FastConv_SHD_IR_HOA2.IR,31); + [FastConv_SHD_IR_HOA3.IR, FastConv_SHD_IR_HOA3.factorQ] = make_be_with_fx(FastConv_SHD_IR_HOA3.IR,31); + [FastConv_SD_IR.IR, FastConv_SD_IR.factorQ] = make_be_with_fx(FastConv_SD_IR.IR,31); + [FastConv_SD_BRIR.IR, FastConv_SD_BRIR.factorQ] = make_be_with_fx(FastConv_SD_BRIR.IR,31); + [FastConv_SD_BRIR.rev_param.rt60, FastConv_SD_BRIR.factorQ_rt60] = make_be_with_fx(FastConv_SD_BRIR.rev_param.rt60,15); + [FastConv_SD_BRIR.rev_param.nrgLr, FastConv_SD_BRIR.factorQ_nrgLr] = make_be_with_fx(FastConv_SD_BRIR.rev_param.nrgLr,15); + if writeRomFileOutput + write_fastconv_rom_table(rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR); + end +else + if writeRomFileOutput + write_fastconv_rom_table_BE(rom_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR); + end end if writeBinaryOutput 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); + if generateBinaryFile_fx + write_fastconv_binary_data_fx(ivas_path, bin_file, FastConv_SHD_IR_FOA, FastConv_SHD_IR_HOA2, FastConv_SHD_IR_HOA3, FastConv_SD_IR, FastConv_SD_BRIR); + end end diff --git a/scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_fx.m b/scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_fx.m new file mode 100644 index 0000000000000000000000000000000000000000..1fe83b038b968318ff7d52fdeeee5c30ada15def --- /dev/null +++ b/scripts/binauralRenderer_interface/fastconv/write_fastconv_binary_data_fx.m @@ -0,0 +1,333 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% (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_fx(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 +% factorQ => uint16_t +% latency_s => uint32_t +% BINAURAL_CONVBANDS => uint16_t +% num_channels => uint16_t +% BINAURAL_NTAPS => uint16_t +% factorQ => uint16_t +% leftHRIRReal => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% leftHRIRImag => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% rightHRIRReal => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% rightHRIRImag => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% +% BRIRs +% factorQ => uint16_t +% latency_s => float32 +% num_channels => uint16_t +% BINAURAL_NTAPS_MAX => uint16_t +% factorQ => uint16_t +% factorQ => uint16_t +% leftBRIRReal => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% leftBRIRImag => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% rightBRIRReal => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% rightBRIRImag => int32_t[BINAURAL_CONVBANDS][num_channels][num_taps] +% CLDFB_NO_CHANNELS_MAX => uint16_t +% factorQ => uint16_t +% fastConvReverberationTimes => int16_t[CLDFB_NO_CHANNELS_MAX] +% fastConvReverberationEneCorrections => int16_t[CLDFB_NO_CHANNELS_MAX] +% + +bin_file = [erase(bin_file,'.bin') '_fx.bin' ]; + +[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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +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 + 2; % factorQ +header.chunksize = header.chunksize + cldfb_no_channels_max * 2; % rt60 +header.chunksize = header.chunksize + 2; % factorQ +header.chunksize = header.chunksize + cldfb_no_channels_max * 2; % 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'); + + factorQ = int16(floor( double(31) - log( IR.latency_s ) / log( 2. ) )); + IR.latency_s = IR.latency_s .* (2.^double(factorQ)); + fwrite(f_id, int16(factorQ), 'uint16'); + fwrite(f_id, int32(IR.latency_s), 'int32'); + fwrite(f_id, binaural_convbands, 'uint16'); + fwrite(f_id, num_channels, 'uint16'); + fwrite(f_id, binaural_ntaps, 'uint16'); + + fwrite(f_id, IR.factorQ, 'uint16'); + IR.IR = IR.IR .* (2.^double(IR.factorQ)); + for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(real(squeeze(IR.IR(1, band, ch, :)))), 'int32'); + end + end + for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(imag(squeeze(IR.IR(1, band, ch, :)))), 'int32'); + end + end + for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(real(squeeze(IR.IR(2, band, ch, :)))), 'int32'); + end + end + for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(imag(squeeze(IR.IR(2, band, ch, :)))), 'int32'); + 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'); + +factorQ = int16(floor( double(31) - log( IR.latency_s ) / log( 2. ) )); +IR.latency_s = IR.latency_s .* (2.^double(factorQ)); +fwrite(f_id, factorQ, 'uint16'); +fwrite(f_id, int32(IR.latency_s), 'int32'); +fwrite(f_id, binaural_convbands, 'uint16'); +fwrite(f_id, num_channels, 'uint16'); +fwrite(f_id, binaural_ntaps, 'uint16'); +fwrite(f_id, IR.factorQ, 'uint16'); +IR.IR = IR.IR .* (2.^double(IR.factorQ)); +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(real(squeeze(IR.IR(1, band, ch, :)))), 'int32'); + end +end +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(imag(squeeze(IR.IR(1, band, ch, :)))), 'int32'); + end +end +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(real(squeeze(IR.IR(2, band, ch, :)))), 'int32'); + end +end +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(imag(squeeze(IR.IR(2, band, ch, :)))), 'int32'); + 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'); + +factorQ = int16(floor( double(31) - log( IR.rev_param.latency_s ) / log( 2. ) )); +IR.rev_param.latency_s = IR.rev_param.latency_s .* (2.^double(factorQ)); +fwrite(f_id, factorQ, 'uint16'); +fwrite(f_id, int32(IR.rev_param.latency_s), 'int32'); +fwrite(f_id, binaural_convbands, 'uint16'); +fwrite(f_id, num_channels, 'uint16'); +fwrite(f_id, IR.rev_param.NFilter, 'uint16'); +fwrite(f_id, IR.factorQ, 'uint16'); +IR.IR = IR.IR .* (2.^double(IR.factorQ)); +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(real(squeeze(IR.IR(1, band, ch, 1:IR.rev_param.NFilter)))), 'int32' ); + end +end +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(imag(squeeze(IR.IR(1, band, ch, 1:IR.rev_param.NFilter)))), 'int32' ); + end +end +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(real(squeeze(IR.IR(2, band, ch, 1:IR.rev_param.NFilter)))), 'int32' ); + end +end +for band = 1:binaural_convbands + for ch = 1:num_channels + fwrite(f_id, int32(imag(squeeze(IR.IR(2, band, ch, 1:IR.rev_param.NFilter)))), 'int32' ); + end +end + +fwrite(f_id, cldfb_no_channels_max, 'uint16'); +fwrite(f_id, IR.factorQ_rt60, 'uint16'); +IR.rev_param.rt60 = IR.rev_param.rt60 .* (2.^double(IR.factorQ_rt60)); +fwrite(f_id, int16(IR.rev_param.rt60), 'int16'); +fwrite(f_id, IR.factorQ_nrgLr, 'uint16'); +IR.rev_param.nrgLr = IR.rev_param.nrgLr .* (2.^double(IR.factorQ_nrgLr)); +fwrite(f_id, int16(IR.rev_param.nrgLr), 'int16'); + +fclose(f_id); + +end \ No newline at end of file diff --git a/scripts/binauralRenderer_interface/fastconv/write_fastconv_rom_table.m b/scripts/binauralRenderer_interface/fastconv/write_fastconv_rom_table.m index 5feeaf5459402d9c3b24c8dff7b295c1e5c04af6..53005fdd8165711f41b2a794464bf1799fd7371c 100644 --- a/scripts/binauralRenderer_interface/fastconv/write_fastconv_rom_table.m +++ b/scripts/binauralRenderer_interface/fastconv/write_fastconv_rom_table.m @@ -44,54 +44,54 @@ function write_fastconv_rom_table(output_file, FastConv_SHD_IR_FOA, FastConv_SHD %% HRIRs (SHD) % HOA3 - fprintf(fid, ['const float FASTCONV_' FastConv_SHD_IR_HOA3.order '_latency_s = %10.9ff;\n'], FastConv_SHD_IR_HOA3.latency_s); - writeData3L(fid, ['const float leftHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(FastConv_SHD_IR_HOA3.IR(1,:,:,:)))); - writeData3L(fid, ['const float leftHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(FastConv_SHD_IR_HOA3.IR(1,:,:,:)))); - writeData3L(fid, ['const float rightHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(FastConv_SHD_IR_HOA3.IR(2,:,:,:)))); - writeData3L(fid, ['const float rightHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(FastConv_SHD_IR_HOA3.IR(2,:,:,:)))); + fprintf(fid, ['const uint32_t FASTCONV_' FastConv_SHD_IR_HOA3.order '_latency_s = 0x%tx;\n'], FastConv_SHD_IR_HOA3.latency_s); + writeData3L(fid, ['const uint32_t leftHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx', real(squeeze(FastConv_SHD_IR_HOA3.IR(1,:,:,:)))); + writeData3L(fid, ['const uint32_t leftHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',imag(squeeze(FastConv_SHD_IR_HOA3.IR(1,:,:,:)))); + writeData3L(fid, ['const uint32_t rightHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',real(squeeze(FastConv_SHD_IR_HOA3.IR(2,:,:,:)))); + writeData3L(fid, ['const uint32_t rightHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',imag(squeeze(FastConv_SHD_IR_HOA3.IR(2,:,:,:)))); % HOA2 - fprintf(fid, ['const float FASTCONV_' FastConv_SHD_IR_HOA2.order '_latency_s = %10.9ff;\n'], FastConv_SHD_IR_HOA2.latency_s); - writeData3L(fid, ['const float leftHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(FastConv_SHD_IR_HOA2.IR(1,:,:,:)))); - writeData3L(fid, ['const float leftHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(FastConv_SHD_IR_HOA2.IR(1,:,:,:)))); - writeData3L(fid, ['const float rightHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(FastConv_SHD_IR_HOA2.IR(2,:,:,:)))); - writeData3L(fid, ['const float rightHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(FastConv_SHD_IR_HOA2.IR(2,:,:,:)))); + fprintf(fid, ['const uint32_t FASTCONV_' FastConv_SHD_IR_HOA2.order '_latency_s = 0x%tx;\n'], FastConv_SHD_IR_HOA2.latency_s); + writeData3L(fid, ['const uint32_t leftHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',real(squeeze(FastConv_SHD_IR_HOA2.IR(1,:,:,:)))); + writeData3L(fid, ['const uint32_t leftHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',imag(squeeze(FastConv_SHD_IR_HOA2.IR(1,:,:,:)))); + writeData3L(fid, ['const uint32_t rightHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'0x%tx', real(squeeze(FastConv_SHD_IR_HOA2.IR(2,:,:,:)))); + writeData3L(fid, ['const uint32_t rightHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',imag(squeeze(FastConv_SHD_IR_HOA2.IR(2,:,:,:)))); % FOA - fprintf(fid, ['const float FASTCONV_' FastConv_SHD_IR_FOA.order '_latency_s = %10.9ff;\n'], FastConv_SHD_IR_FOA.latency_s); - writeData3L(fid, ['const float leftHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(FastConv_SHD_IR_FOA.IR(1,:,:,:)))); - writeData3L(fid, ['const float leftHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(FastConv_SHD_IR_FOA.IR(1,:,:,:)))); - writeData3L(fid, ['const float rightHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], real(squeeze(FastConv_SHD_IR_FOA.IR(2,:,:,:)))); - writeData3L(fid, ['const float rightHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], imag(squeeze(FastConv_SHD_IR_FOA.IR(2,:,:,:)))); + fprintf(fid, ['const uint32_t FASTCONV_' FastConv_SHD_IR_FOA.order '_latency_s = 0x%tx;\n'], FastConv_SHD_IR_FOA.latency_s); + writeData3L(fid, ['const uint32_t leftHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',real(squeeze(FastConv_SHD_IR_FOA.IR(1,:,:,:)))); + writeData3L(fid, ['const uint32_t leftHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',imag(squeeze(FastConv_SHD_IR_FOA.IR(1,:,:,:)))); + writeData3L(fid, ['const uint32_t rightHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',real(squeeze(FastConv_SHD_IR_FOA.IR(2,:,:,:)))); + writeData3L(fid, ['const uint32_t rightHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '0x%tx',imag(squeeze(FastConv_SHD_IR_FOA.IR(2,:,:,:)))); %% HRIRs (SD) - fprintf(fid, 'const float FASTCONV_HRIR_latency_s = %10.9ff;\n', FastConv_SD_IR.latency_s); - writeData3L(fid, 'const float leftHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', real(squeeze(FastConv_SD_IR.IR(1,:,:,:)))); - writeData3L(fid, 'const float leftHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', imag(squeeze(FastConv_SD_IR.IR(1,:,:,:)))); - writeData3L(fid, 'const float rightHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', real(squeeze(FastConv_SD_IR.IR(2,:,:,:)))); - writeData3L(fid, 'const float rightHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', imag(squeeze(FastConv_SD_IR.IR(2,:,:,:)))); + fprintf(fid, 'const uint32_t FASTCONV_HRIR_latency_s = 0x%tx;\n', FastConv_SD_IR.latency_s); + writeData3L(fid, 'const uint32_t leftHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', '0x%tx',real(squeeze(FastConv_SD_IR.IR(1,:,:,:)))); + writeData3L(fid, 'const uint32_t leftHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', '0x%tx',imag(squeeze(FastConv_SD_IR.IR(1,:,:,:)))); + writeData3L(fid, 'const uint32_t rightHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', '0x%tx',real(squeeze(FastConv_SD_IR.IR(2,:,:,:)))); + writeData3L(fid, 'const uint32_t rightHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', '0x%tx',imag(squeeze(FastConv_SD_IR.IR(2,:,:,:)))); %% BRIRs (SD) fprintf(fid, '/* Binaural rendering data set based on BRIRs \n'); fprintf(fid, ' * Tables derived from Mozart IIS BRIRs.*/\n'); - fprintf(fid, 'const float FASTCONV_BRIR_latency_s = %10.9ff;\n', FastConv_SD_BRIR.rev_param.latency_s); - writeData3L(fid, 'const float leftBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', real(squeeze(FastConv_SD_BRIR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); - writeData3L(fid, 'const float leftBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', imag(squeeze(FastConv_SD_BRIR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); - writeData3L(fid, 'const float rightBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', real(squeeze(FastConv_SD_BRIR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); - writeData3L(fid, 'const float rightBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', imag(squeeze(FastConv_SD_BRIR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + fprintf(fid, 'const uint32_t FASTCONV_BRIR_latency_s = 0x%tx;\n', FastConv_SD_BRIR.rev_param.latency_s); + writeData3L(fid, 'const uint32_t leftBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]','0x%tx', real(squeeze(FastConv_SD_BRIR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + writeData3L(fid, 'const uint32_t leftBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', '0x%tx',imag(squeeze(FastConv_SD_BRIR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + writeData3L(fid, 'const uint32_t rightBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]','0x%tx', real(squeeze(FastConv_SD_BRIR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + writeData3L(fid, 'const uint32_t rightBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]','0x%tx', imag(squeeze(FastConv_SD_BRIR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); % RT60 - fprintf(fid,'const float fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX] = \n{'); + fprintf(fid,'const uint32_t fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX] = \n{'); fprintf(fid,'\n\t'); for bandIdx = 1:FastConv_SD_BRIR.rev_param.kAna - fprintf(fid,'%f%s, ', FastConv_SD_BRIR.rev_param.rt60(bandIdx),'f'); + fprintf(fid,'0x%tx, ', FastConv_SD_BRIR.rev_param.rt60(bandIdx)); end fprintf(fid,'\n};\n'); fprintf(fid,'\n\n'); % energyReverb - fprintf(fid,'const float fastconvReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = \n{'); + fprintf(fid,'const uint32_t fastconvReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = \n{'); fprintf(fid,'\n\t'); for bandIdx = 1:FastConv_SD_BRIR.rev_param.kAna - fprintf(fid,'%f%s, ', FastConv_SD_BRIR.rev_param.nrgLr(bandIdx),'f'); + fprintf(fid,'0x%tx, ', FastConv_SD_BRIR.rev_param.nrgLr(bandIdx)); end fprintf(fid,'\n};\n'); fprintf(fid,'\n\n'); diff --git a/scripts/binauralRenderer_interface/fastconv/write_fastconv_rom_table_BE.m b/scripts/binauralRenderer_interface/fastconv/write_fastconv_rom_table_BE.m new file mode 100644 index 0000000000000000000000000000000000000000..af255ab4f447d7e0014fa8824dbba2a05e135ed6 --- /dev/null +++ b/scripts/binauralRenderer_interface/fastconv/write_fastconv_rom_table_BE.m @@ -0,0 +1,101 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% (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 + fprintf(fid, ['const float FASTCONV_' FastConv_SHD_IR_HOA3.order '_latency_s = %10.9ff;\n'], FastConv_SHD_IR_HOA3.latency_s); + writeData3L(fid, ['const float leftHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', real(squeeze(FastConv_SHD_IR_HOA3.IR(1,:,:,:)))); + writeData3L(fid, ['const float leftHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '%+ff',imag(squeeze(FastConv_SHD_IR_HOA3.IR(1,:,:,:)))); + writeData3L(fid, ['const float rightHRIRReal_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', real(squeeze(FastConv_SHD_IR_HOA3.IR(2,:,:,:)))); + writeData3L(fid, ['const float rightHRIRImag_' FastConv_SHD_IR_HOA3.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA3.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', imag(squeeze(FastConv_SHD_IR_HOA3.IR(2,:,:,:)))); + % HOA2 + fprintf(fid, ['const float FASTCONV_' FastConv_SHD_IR_HOA2.order '_latency_s = %10.9ff;\n'], FastConv_SHD_IR_HOA2.latency_s); + writeData3L(fid, ['const float leftHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', real(squeeze(FastConv_SHD_IR_HOA2.IR(1,:,:,:)))); + writeData3L(fid, ['const float leftHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', imag(squeeze(FastConv_SHD_IR_HOA2.IR(1,:,:,:)))); + writeData3L(fid, ['const float rightHRIRReal_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', real(squeeze(FastConv_SHD_IR_HOA2.IR(2,:,:,:)))); + writeData3L(fid, ['const float rightHRIRImag_' FastConv_SHD_IR_HOA2.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_HOA2.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', imag(squeeze(FastConv_SHD_IR_HOA2.IR(2,:,:,:)))); + % FOA + fprintf(fid, ['const float FASTCONV_' FastConv_SHD_IR_FOA.order '_latency_s = %10.9ff;\n'], FastConv_SHD_IR_FOA.latency_s); + writeData3L(fid, ['const float leftHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', real(squeeze(FastConv_SHD_IR_FOA.IR(1,:,:,:)))); + writeData3L(fid, ['const float leftHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'],'%+ff', imag(squeeze(FastConv_SHD_IR_FOA.IR(1,:,:,:)))); + writeData3L(fid, ['const float rightHRIRReal_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '%+ff',real(squeeze(FastConv_SHD_IR_FOA.IR(2,:,:,:)))); + writeData3L(fid, ['const float rightHRIRImag_' FastConv_SHD_IR_FOA.order '[BINAURAL_CONVBANDS][' FastConv_SHD_IR_FOA.order '_CHANNELS][BINAURAL_NTAPS_SBA]'], '%+ff',imag(squeeze(FastConv_SHD_IR_FOA.IR(2,:,:,:)))); + + %% HRIRs (SD) + fprintf(fid, 'const float FASTCONV_HRIR_latency_s = %10.9ff;\n', FastConv_SD_IR.latency_s); + writeData3L(fid, 'const float leftHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]','%+ff', real(squeeze(FastConv_SD_IR.IR(1,:,:,:)))); + writeData3L(fid, 'const float leftHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]','%+ff', imag(squeeze(FastConv_SD_IR.IR(1,:,:,:)))); + writeData3L(fid, 'const float rightHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]', '%+ff',real(squeeze(FastConv_SD_IR.IR(2,:,:,:)))); + writeData3L(fid, 'const float rightHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]','%+ff', imag(squeeze(FastConv_SD_IR.IR(2,:,:,:)))); + + %% BRIRs (SD) + fprintf(fid, '/* Binaural rendering data set based on BRIRs \n'); + fprintf(fid, ' * Tables derived from Mozart IIS BRIRs.*/\n'); + fprintf(fid, 'const float FASTCONV_BRIR_latency_s = %10.9ff;\n', FastConv_SD_BRIR.rev_param.latency_s); + writeData3L(fid, 'const float leftBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]','%+ff', real(squeeze(FastConv_SD_BRIR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + writeData3L(fid, 'const float leftBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', '%+ff',imag(squeeze(FastConv_SD_BRIR.IR(1,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + writeData3L(fid, 'const float rightBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]', '%+ff',real(squeeze(FastConv_SD_BRIR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + writeData3L(fid, 'const float rightBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]','%+ff', imag(squeeze(FastConv_SD_BRIR.IR(2,:,:,1:FastConv_SD_BRIR.rev_param.NFilter)))); + + % RT60 + fprintf(fid,'const float fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX] = \n{'); + fprintf(fid,'\n\t'); + for bandIdx = 1:FastConv_SD_BRIR.rev_param.kAna + fprintf(fid,'%f%s, ', FastConv_SD_BRIR.rev_param.rt60(bandIdx),'f'); + end + fprintf(fid,'\n};\n'); + fprintf(fid,'\n\n'); + + % energyReverb + fprintf(fid,'const float fastconvReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = \n{'); + fprintf(fid,'\n\t'); + for bandIdx = 1:FastConv_SD_BRIR.rev_param.kAna + fprintf(fid,'%f%s, ', FastConv_SD_BRIR.rev_param.nrgLr(bandIdx),'f'); + end + fprintf(fid,'\n};\n'); + fprintf(fid,'\n\n'); + + fclose(fid); + +end \ No newline at end of file diff --git a/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c b/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c index 4a647690d8ce5de2efe2fb8c43a7b4ca5f11491f..03e23f345f2542985cc075910dee5a0d5347400e 100644 --- a/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c +++ b/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c @@ -68,13 +68,21 @@ * Constants *------------------------------------------------------------------------------------------*/ -#define MAX_DIFF_AZI 1 /* angle in degree */ -#define MAX_DIFF_ELE 10 /* angle in degree */ -#define DEFAULT_SAMPLERATE 48000 /* Hz */ -#define LAST_SAMPLERATE 16000 /* Hz */ -#define TEMPLTATE_C_ROM_FILE_NAME "ivas_license_header.template" -#define ROM_FILE_NAME "ivas_rom_binaural_crend_head" -#define FORMAT_FLOAT "%8.6f" +#define MAX_DIFF_AZI 1 /* angle in degree */ +#define MAX_DIFF_ELE 10 /* angle in degree */ +#define DEFAULT_SAMPLERATE 48000 /* Hz */ +#define LAST_SAMPLERATE 16000 /* Hz */ +#define TEMPLTATE_C_ROM_FILE_NAME "ivas_license_header.template" +#define ROM_FILE_NAME "ivas_rom_binaural_crend_head" +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT +#define FORMAT_FLOAT "%a" +#define FORMAT_FLOAT_REVERB "%a" +#define FORMAT_FLOAT_LATENCY "%a" +#else +#define FORMAT_FLOAT "%8.6f" +#define FORMAT_FLOAT_REVERB "%8.6f" +#define FORMAT_FLOAT_LATENCY "%10.9ff" +#endif #define NUM_SAMPLES_PER_LINES 96 #define NUM_SAMPLES_PER_LINES_REVERB 9 #define DECLARATION_NAME "CRendBin" @@ -82,11 +90,6 @@ #define NUM_ITERATIONS_TO_ALLOW_OPTIM_5_MS 5 /* no optimisation if hrir length is lower then 20 ms*/ #define NUM_ITERATIONS_TO_ALLOW_OPTIM_20_MS 1 /* no optimisation if hrir length is lower then 20 ms*/ -int32_t sample_rates[3] = { DEFAULT_SAMPLERATE, 32000, 16000 }; /* Hz */ /* 8000 Hz not supported by mdft */ - -char *binary_file_path = NULL; -char *lib_rend_path = NULL; - #define DEFAULT_BINARY_FILE_NAME "crend" #ifdef _WIN32 #define DEFAULT_BINARY_FILE_PATH ".\\bin" @@ -119,8 +122,13 @@ typedef struct _crend_hrtf_tables_dimensions int16_t max_num_ir; int16_t max_num_iterations; int16_t max_num_iterations_diffuse; +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + uint32_t max_total_num_fsamp_per_iteration; + uint32_t max_total_num_fsamp_per_iteration_diff; +#else uint16_t max_total_num_fsamp_per_iteration; uint16_t max_total_num_fsamp_per_iteration_diff; +#endif } crend_hrtf_tables_dimensions; @@ -132,16 +140,32 @@ void usage_gen_crend_tables( void ); void get_ls_layout_config( AUDIO_CONFIG ls_layout_config, struct ivas_layout_config *ls_struct ); int generate_crend_ivas_tables_from_sofa( const char *sofa_file_path, ConfigReader *cfgReader ); void update_h_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len ); +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT +void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len, int16_t factorQ[3] ); +void update_c_file_with_reverb( float *pEner_l, float *pEner_r, float *pCoherence, Word16 *pEner_l_fx, Word16 *pEner_r_fx, Word16 *pCoherence_fx, int16_t factorQ, const int32_t samplerate, const int16_t len ); +#else void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len ); -int generate_reverb_ivas_tables_from_sofa( const char *file_path ); -void update_h_file_with_reverb( const int32_t samplerate ); void update_c_file_with_reverb( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate, const int16_t len ); +#endif +void update_h_file_with_reverb( const int32_t samplerate ); +int generate_reverb_ivas_tables_from_sofa( const char *file_path ); +extern Word32 float2Word32( float, Word16 ); +extern Word16 float2Word16( float, Word16 ); void get_binary_tables_dimensions( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hrtf_table_dims /*OUT*/ ); uint32_t compute_binary_size( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hrtf_table_dims ); -void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len ); -void write_reverb_to_binary_file( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate ); +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT +uint32_t compute_binary_size_fx( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hrtf_table_dims ); +ivas_error make_fx_be( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len, int16_t factorQ[3] ); +ivas_error make_reverb_fx_be( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate, Word16 *factorQ ); +#endif +ivas_error write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len ); +ivas_error write_reverb_to_binary_file( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate ); +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT +ivas_error write_binary_file_fx( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len, int16_t factorQ[3] ); +ivas_error write_reverb_to_binary_file_fx( float *pEner_l, float *pEner_r, float *pCoherence, Word16 factorQ, const int32_t samplerate ); +#endif /*---------------------------------------------------------------------* * @@ -221,7 +245,6 @@ void usage_gen_crend_tables( void ) fprintf( stdout, "\n" ); } - /*------------------------------------------------------------------------------------------* * Global variables *------------------------------------------------------------------------------------------*/ @@ -231,6 +254,9 @@ char *c_file_path = NULL; char *h_file_path = NULL; char *rom_file_name = NULL; uint16_t frame_len_ms = 5; +int32_t sample_rates[3] = { DEFAULT_SAMPLERATE, 32000, 16000 }; /* Hz */ /* 8000 Hz not supported by mdft */ +char *binary_file_path = NULL; +char *lib_rend_path = NULL; /*------------------------------------------------------------------------------------------* * Standalone Renderer program @@ -854,6 +880,7 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c double *sofa_delay_val = NULL; double *sofa_src_pos_val = NULL; double *sofa_src_pos_cart_val = NULL; + int iIR, iChan, iIter, offset; long sofa_sample_rate = 0; double a[3] = { 0 }; @@ -1251,10 +1278,8 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c } else { - ivas_set_hrtf_fr( &hrtf_data, ivas_hrtf, frame_len - , - mdft_scale_fact - ); + ivas_set_hrtf_fr( &hrtf_data, ivas_hrtf, frame_len, + mdft_scale_fact ); } hrtf_data.latency_s += 0.000000001f; @@ -1272,15 +1297,45 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c latency_48k_optim = hrtf_data.latency_s; } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + int16_t factorQ[3]; + make_fx_be( &hrtf_data, lscfg, sample_rates[indSR], frame_len, factorQ ); +#endif + if ( lib_rend_path != NULL ) { update_h_file( &hrtf_data, lscfg, sample_rates[indSR], frame_len ); +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + update_c_file( &hrtf_data, lscfg, sample_rates[indSR], frame_len, factorQ ); +#else update_c_file( &hrtf_data, lscfg, sample_rates[indSR], frame_len ); +#endif } if ( binary_file_path != NULL ) { - write_binary_file( &hrtf_data, lscfg, sample_rates[indSR], frame_len ); + if ( write_binary_file( &hrtf_data, lscfg, sample_rates[indSR], frame_len ) != IVAS_ERR_OK ) + { + mxDestroyArray( sofa ); + fprintf( stderr, "Write binary file error\n" ); + free( sofa_file_path ); + free( index_pos ); + free( ivas_hrtf ); + ivas_hrtf_close( &hrtf_data ); + return -1; + } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + if ( write_binary_file_fx( &hrtf_data, lscfg, sample_rates[indSR], frame_len, factorQ ) != IVAS_ERR_OK ) + { + mxDestroyArray( sofa ); + fprintf( stderr, "Write binary file fx error\n" ); + free( sofa_file_path ); + free( index_pos ); + free( ivas_hrtf ); + ivas_hrtf_close( &hrtf_data ); + return -1; + } +#endif } if ( ivas_hrtf->latency_s[0] ) @@ -1316,7 +1371,6 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c } - #define IVAS_REVERB_FFT_SIZE_48K ( 512 ) #define IVAS_REVERB_FFT_SIZE_32K ( 512 ) #define IVAS_REVERB_FFT_SIZE_16K ( 256 ) @@ -1783,6 +1837,12 @@ int generate_reverb_ivas_tables_from_sofa( const char *file_path ) nr_fc_fft_filter = ( frame_len >> 1 ) + 1; float *p_avg_lr = NULL; float *pCoherence = NULL; +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + Word16 *p_avg_lr_fx = NULL; + Word16 *pCoherence_fx = NULL; + Word16 factorQ; +#endif + p_avg_lr = (float *) malloc( sizeof( float * ) * nr_fc_fft_filter * 2 ); pCoherence = (float *) malloc( sizeof( float * ) * nr_fc_fft_filter ); memset( p_avg_lr, 0, sizeof( float ) * nr_fc_fft_filter * 2 ); @@ -1828,14 +1888,30 @@ int generate_reverb_ivas_tables_from_sofa( const char *file_path ) ivas_reverb_get_hrtf_set_properties( pHrtf_set_l_re, pHrtf_set_l_im, pHrtf_set_r_re, pHrtf_set_r_im, IVAS_AUDIO_CONFIG_5_1, sofa_M, nr_fc_fft_filter, nr_fc_fft_filter, p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence ); +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + make_reverb_fx_be( p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence, sample_rates[indSR], &factorQ ); +#endif update_h_file_with_reverb( sample_rates[indSR] ); +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + update_c_file_with_reverb( p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence, p_avg_lr_fx, &p_avg_lr_fx[nr_fc_fft_filter], pCoherence_fx, factorQ, sample_rates[indSR], nr_fc_fft_filter ); +#else update_c_file_with_reverb( p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence, sample_rates[indSR], nr_fc_fft_filter ); - +#endif if ( binary_file_path != NULL ) { - write_reverb_to_binary_file( p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence, sample_rates[indSR] ); + if ( write_reverb_to_binary_file( p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence, sample_rates[indSR] ) != IVAS_ERR_OK ) + { + goto cleanup; + } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + if ( write_reverb_to_binary_file_fx( p_avg_lr, &p_avg_lr[nr_fc_fft_filter], pCoherence, factorQ, sample_rates[indSR] ) != IVAS_ERR_OK ) + { + goto cleanup; + } +#endif } + cleanup: for ( int i = 0; i < sofa_M; i++ ) { if ( pHrtf_set_l_re[i] ) @@ -1918,7 +1994,10 @@ void write_array_float_to_file( FILE *fp, float *vec, int32_t size_vec, int32_t for ( l = 0; l < sample_per_ligne; l++ ) { fprintf( fp, format, vec[k * sample_per_ligne + l] ); - fprintf( fp, "f, " ); + if ( strcmp( format, "%a" ) ) + fprintf( fp, "f, " ); + else + fprintf( fp, ", " ); } fprintf( fp, "\n" ); } @@ -1929,10 +2008,16 @@ void write_array_float_to_file( FILE *fp, float *vec, int32_t size_vec, int32_t for ( l = 0; l < remaining_samples - 1; l++ ) { fprintf( fp, format, vec[k * sample_per_ligne + l] ); - fprintf( fp, "f, " ); + if ( strcmp( format, "%a" ) ) + fprintf( fp, "f, " ); + else + fprintf( fp, ", " ); } fprintf( fp, format, vec[k * sample_per_ligne + l] ); - fprintf( fp, "f}" ); + if ( strcmp( format, "%a" ) ) + fprintf( fp, "f}" ); + else + fprintf( fp, "}" ); } /*---------------------------------------------------------------------* @@ -1989,10 +2074,122 @@ void write_array_uint16_to_file( FILE *fp, uint16_t *vec, int32_t size_vec, int3 fprintf( fp, "}" ); } +/*---------------------------------------------------------------------* + *write_array_word32_to_file(); + *---------------------------------------------------------------------*/ +void write_array_word32_to_file( FILE *fp, Word32 *vec, int32_t size_vec, int32_t sample_per_ligne, const int num_tab, const char *tab ) +{ + int32_t k, l, num_iter, remaining_samples; + int16_t i; + + num_iter = size_vec / sample_per_ligne; + remaining_samples = size_vec % sample_per_ligne; + if ( remaining_samples == 0 ) + { + num_iter--; + remaining_samples = sample_per_ligne; + } + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + + fprintf( fp, "{" ); + for ( k = 0; k < num_iter; k++ ) + { + if ( k != 0 ) + { + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + } + for ( l = 0; l < sample_per_ligne; l++ ) + { + fprintf( fp, "%d", vec[k * sample_per_ligne + l] ); + fprintf( fp, ", " ); + } + fprintf( fp, "\n" ); + } + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + for ( l = 0; l < remaining_samples - 1; l++ ) + { + fprintf( fp, "%d", vec[k * sample_per_ligne + l] ); + fprintf( fp, ", " ); + } + fprintf( fp, "%d", vec[k * sample_per_ligne + l] ); + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + fprintf( fp, "}" ); +} + +/*---------------------------------------------------------------------* + *write_array_word32_to_file(); + *---------------------------------------------------------------------*/ +void write_array_word16_to_file( FILE *fp, Word16 *vec, int32_t size_vec, int32_t sample_per_ligne, const int num_tab, const char *tab ) +{ + int32_t k, l, num_iter, remaining_samples; + int16_t i; + + num_iter = size_vec / sample_per_ligne; + remaining_samples = size_vec % sample_per_ligne; + if ( remaining_samples == 0 ) + { + num_iter--; + remaining_samples = sample_per_ligne; + } + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + + fprintf( fp, "{" ); + for ( k = 0; k < num_iter; k++ ) + { + if ( k != 0 ) + { + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + } + for ( l = 0; l < sample_per_ligne; l++ ) + { + fprintf( fp, "%d", vec[k * sample_per_ligne + l] ); + fprintf( fp, ", " ); + } + fprintf( fp, "\n" ); + } + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + for ( l = 0; l < remaining_samples - 1; l++ ) + { + fprintf( fp, "%d", vec[k * sample_per_ligne + l] ); + fprintf( fp, ", " ); + } + fprintf( fp, "%d", vec[k * sample_per_ligne + l] ); + for ( i = 0; i < num_tab; i++ ) + { + fprintf( fp, "%s", tab ); + } + fprintf( fp, "}" ); +} + /*---------------------------------------------------------------------* *update_c_file_with_reverb(); *---------------------------------------------------------------------*/ +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT +void update_c_file_with_reverb( float *pEner_l, float *pEner_r, float *pCoherence, Word16 *pEner_l_fx, Word16 *pEner_r_fx, Word16 *pCoherence_fx, int16_t factorQ, const int32_t samplerate, const int16_t len ) +#else void update_c_file_with_reverb( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate, const int16_t len ) +#endif { char len_str[26] = "LR_IAC_LENGTH_NR_FC"; if ( samplerate == 16000 ) @@ -2026,17 +2223,17 @@ void update_c_file_with_reverb( float *pEner_l, float *pEner_r, float *pCoherenc /* float *defaultHRIR_right_avg_power_[LR_IAC_LENGTH_NR_FC];*/ fprintf( fp, "\nconst float defaultHRIR_coherence_%dkHz[%s] = \n", samplerate / 1000, len_str ); - write_array_float_to_file( fp, pCoherence, len, NUM_SAMPLES_PER_LINES_REVERB, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, pCoherence, len, NUM_SAMPLES_PER_LINES_REVERB, FORMAT_FLOAT_REVERB, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ";\n" ); /* float *defaultHRIR_left_avg_power_[LR_IAC_LENGTH_NR_FC];*/ fprintf( fp, "\nconst float defaultHRIR_left_avg_power_%dkHz[%s] = \n", samplerate / 1000, len_str ); - write_array_float_to_file( fp, pEner_l, len, NUM_SAMPLES_PER_LINES_REVERB, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, pEner_l, len, NUM_SAMPLES_PER_LINES_REVERB, FORMAT_FLOAT_REVERB, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ";\n" ); /* float *defaultHRIR_right_avg_power_[LR_IAC_LENGTH_NR_FC];*/ fprintf( fp, "\nconst float defaultHRIR_right_avg_power_%dkHz[%s] = \n", samplerate / 1000, len_str ); - write_array_float_to_file( fp, pEner_r, len, NUM_SAMPLES_PER_LINES_REVERB, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, pEner_r, len, NUM_SAMPLES_PER_LINES_REVERB, FORMAT_FLOAT_REVERB, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ";\n" ); if ( fp ) @@ -2047,7 +2244,11 @@ void update_c_file_with_reverb( float *pEner_l, float *pEner_r, float *pCoherenc /*---------------------------------------------------------------------* *update_c_file(); *---------------------------------------------------------------------*/ +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT +void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len, int16_t factorQ[3] ) +#else void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len ) +#endif { if ( c_file_path == NULL ) @@ -2057,6 +2258,8 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int int16_t i, j; uint32_t *pTotalNumFreqSampPerIterations[2], maxTotalNumFreqSampPerIterations; uint32_t pTotalNumFreqSampPerIterationsDiffuse[2], maxTotalNumFreqSampPerIterationsDiffuse; + const char *format_float = FORMAT_FLOAT; + const char *format_float_latency = FORMAT_FLOAT_LATENCY; pTotalNumFreqSampPerIterations[0] = malloc( sizeof( float ) * hrtf->max_num_ir ); pTotalNumFreqSampPerIterations[1] = malloc( sizeof( float ) * hrtf->max_num_ir ); @@ -2070,7 +2273,9 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int { /* float latency_s; */ fprintf( fp, "\n\n/********************** %s_%s **********************/\n", DECLARATION_NAME, lscfg.name ); - fprintf( fp, "\nconst float %s_%s_latency_s = %10.9ff;", DECLARATION_NAME, lscfg.name, hrtf->latency_s ); + fprintf( fp, "\nconst float %s_%s_latency_s = ", DECLARATION_NAME, lscfg.name ); + fprintf( fp, format_float_latency, hrtf->latency_s ); + fprintf( fp, ";" ); } fprintf( fp, "\n\n/* Sample Rate = %ld */\n", (long) samplerate ); @@ -2155,9 +2360,9 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int /* float inv_diffuse_weight[BINAURAL_CHANNELS][MAX_INTERN_CHANNELS]; */ fprintf( fp, "\nconst float %s_%s_inv_diffuse_weight_%2dkHz[BINAURAL_CHANNELS][%s]=", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name ); fprintf( fp, "{" ); - write_array_float_to_file( fp, hrtf->inv_diffuse_weight[0], hrtf->max_num_ir, hrtf->max_num_ir, FORMAT_FLOAT, 0, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->inv_diffuse_weight[0], hrtf->max_num_ir, hrtf->max_num_ir, format_float, 0, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "," ); - write_array_float_to_file( fp, hrtf->inv_diffuse_weight[1], hrtf->max_num_ir, hrtf->max_num_ir, FORMAT_FLOAT, 0, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->inv_diffuse_weight[1], hrtf->max_num_ir, hrtf->max_num_ir, format_float, 0, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "}" ); fprintf( fp, ";" ); @@ -2180,15 +2385,15 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int for ( i = 0; i < hrtf->max_num_ir - 1; i++ ) { fprintf( fp, "\n%s{\n", TAB_WITH_SPACE_OR_NOT ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ",\n" ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n%s},", TAB_WITH_SPACE_OR_NOT ); } fprintf( fp, "\n%s{\n", TAB_WITH_SPACE_OR_NOT ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ",\n" ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_re[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n%s}", TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n};" ); @@ -2196,15 +2401,15 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int for ( i = 0; i < hrtf->max_num_ir - 1; i++ ) { fprintf( fp, "\n%s{\n", TAB_WITH_SPACE_OR_NOT ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ",\n" ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n%s},", TAB_WITH_SPACE_OR_NOT ); } fprintf( fp, "\n%s{\n", TAB_WITH_SPACE_OR_NOT ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][0], pTotalNumFreqSampPerIterations[0][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ",\n" ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_im[i][1], pTotalNumFreqSampPerIterations[1][i], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n%s}", TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n};" ); @@ -2216,9 +2421,9 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int else { fprintf( fp, "\nconst float %s_%s_coeff_diffuse_re_%2dkHz[BINAURAL_CHANNELS][%u]={", DECLARATION_NAME, lscfg.name, samplerate / 1000, maxTotalNumFreqSampPerIterationsDiffuse ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_re[0], pTotalNumFreqSampPerIterationsDiffuse[0], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_re[0], pTotalNumFreqSampPerIterationsDiffuse[0], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ",\n" ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_re[1], pTotalNumFreqSampPerIterationsDiffuse[1], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_re[1], pTotalNumFreqSampPerIterationsDiffuse[1], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n};" ); } @@ -2230,9 +2435,9 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int else { fprintf( fp, "\nconst float %s_%s_coeff_diffuse_im_%2dkHz[BINAURAL_CHANNELS][%u]={", DECLARATION_NAME, lscfg.name, samplerate / 1000, maxTotalNumFreqSampPerIterationsDiffuse ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_im[0], pTotalNumFreqSampPerIterationsDiffuse[0], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_im[0], pTotalNumFreqSampPerIterationsDiffuse[0], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, ",\n" ); - write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_im[1], pTotalNumFreqSampPerIterationsDiffuse[1], NUM_SAMPLES_PER_LINES, FORMAT_FLOAT, 2, TAB_WITH_SPACE_OR_NOT ); + write_array_float_to_file( fp, hrtf->pOut_to_bin_diffuse_im[1], pTotalNumFreqSampPerIterationsDiffuse[1], NUM_SAMPLES_PER_LINES, format_float, 2, TAB_WITH_SPACE_OR_NOT ); fprintf( fp, "\n};" ); } @@ -2378,6 +2583,7 @@ void update_h_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int /* float inv_diffuse_weight[BINAURAL_CHANNELS][MAX_INTERN_CHANNELS]; */ fprintf( fp, "\nextern float %s_%s_inv_diffuse_weight_%2dkHz[BINAURAL_CHANNELS][%s];", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name ); + /* uint16_t *pIndex_frequency_max_diffuse[BINAURAL_CHANNELS];*/ if ( hrtf->pIndex_frequency_max_diffuse[0] == NULL ) { @@ -2481,7 +2687,6 @@ void get_binary_tables_dimensions( HRTFS_DATA *hrtf, crend_hrtf_tables_dimension } } - /*---------------------------------------------------------------------* * compute_binary_size(); *---------------------------------------------------------------------*/ @@ -2511,10 +2716,14 @@ uint32_t compute_binary_size( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hr } } - hrtf_data_size += sizeof( uint16_t ); // index_frequency_max_diffuse + hrtf_data_size += sizeof( uint16_t ); // index_frequency_max_diffuse hrtf_data_size += hrtf->max_num_ir * sizeof( float ) * BINAURAL_CHANNELS; // inv_diffuse_weight +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration +#else hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration +#endif // The sizes of coeff_re & coeff_im depend on pIndex_frequency_max for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) @@ -2528,7 +2737,11 @@ uint32_t compute_binary_size( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hr } } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration_diff +#else hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration_diff +#endif if ( hrtf_table_dims->max_total_num_fsamp_per_iteration_diff != 0 ) { // The sizes of coeff_diffuse_re & coeff_diffuse_im depend on pIndex_frequency_max @@ -2544,83 +2757,725 @@ uint32_t compute_binary_size( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hr return hrtf_data_size; } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT /*---------------------------------------------------------------------* - * write_binary_file(); + * compute_binary_size_fx(); *---------------------------------------------------------------------*/ -void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len ) +uint32_t compute_binary_size_fx( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hrtf_table_dims ) { - FILE *output_binary_file; + int16_t iIR, iIter, iChan; + uint32_t hrtf_data_size; - int16_t iIR, iIter, iChan, iTap; - uint32_t data_size_tmp; - float *coeff_rptr; - char tmpStr[64]; + hrtf_data_size = 0; - crend_hrtf_tables_dimensions hrtf_table_dims; + hrtf_data_size += sizeof( Word16 ); // latency_s Q factor + hrtf_data_size += sizeof( Word32 ); // latency_s + hrtf_data_size += sizeof( uint16_t ); // max_num_ir + hrtf_data_size += sizeof( uint16_t ); // BINAURAL_CHANNELS + hrtf_data_size += sizeof( int16_t ); // max_num_iterations + hrtf_data_size += hrtf->max_num_ir * BINAURAL_CHANNELS * sizeof( uint16_t ); // num_iterations + hrtf_data_size += hrtf->max_num_ir * BINAURAL_CHANNELS * hrtf->max_num_iterations * sizeof( uint16_t ); // pIndex_frequency_max - uint32_t hrtf_data_size; - char *hrtf_bin = NULL, *hrtf_bin_wptr; + hrtf_data_size += sizeof( int16_t ); // max_num_iterations_diffuse - char *binary_file_full_path = NULL; + if ( hrtf_table_dims->max_num_iterations_diffuse != 0 ) + { + hrtf_data_size += BINAURAL_CHANNELS * sizeof( uint16_t ); // num_iterations_diffuse + // The size of pIndex_frequency_max_diffuse depends on num_iterations_diffuse + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + hrtf_data_size += hrtf->num_iterations_diffuse[iChan] * sizeof( uint16_t ); + } + } - if ( hrtf == NULL ) - return; + hrtf_data_size += sizeof( uint16_t ); // index_frequency_max_diffuse - if ( binary_file_path == NULL ) - return; + hrtf_data_size += sizeof( Word16 ); // Q factor inv_diffuse_weight - /* Binary file - block description : + hrtf_data_size += hrtf->max_num_ir * sizeof( Word16 ) * BINAURAL_CHANNELS; // inv_diffuse_weight - latency_s => float + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration - max_num_ir => uint16_t - BINAURAL_CHANNELS => uint16_t (BINAURAL_CHANNELS) + hrtf_data_size += sizeof( Word16 ); // Q factor + // The sizes of coeff_re & coeff_im depend on pIndex_frequency_max + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) + { + hrtf_data_size += 2 * hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( Word32 ); // 2* : re & im + } + } + } - max_num_iterations => int16_t - num_iterations => uint16_t[max_num_ir][BINAURAL_CHANNELS] - pIndex_frequency_max => uint16_t[max_num_ir][BINAURAL_CHANNELS][max_num_iterations] (Pointer) + hrtf_data_size += sizeof( uint32_t ); // max_total_num_fsamp_per_iteration_diff + if ( hrtf_table_dims->max_total_num_fsamp_per_iteration_diff != 0 ) + { + // The sizes of coeff_diffuse_re & coeff_diffuse_im depend on pIndex_frequency_max + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) + { + hrtf_data_size += 2 * hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( Word32 ); // 2* : re & im + } + } + } - max_num_iterations_diffuse => int16_t - num_iterations_diffuse => uint16_t[BINAURAL_CHANNELS] - pIndex_frequency_max_diffuse => uint16_t[BINAURAL_CHANNELS][max_num_iterations_diffuse] (Pointer) + return hrtf_data_size; +} - index_frequency_max_diffuse => uint16_t - inv_diffuse_weight => float[max_num_ir] - max_total_num_fsamp_per_iteration => uint16_t - coeff_re => float[max_num_ir][BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) - coeff_im => float[max_num_ir][BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) +/*---------------------------------------------------------------------* + * make_fx_be(); + *---------------------------------------------------------------------*/ +ivas_error make_fx_be( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len, int16_t factorQ[3] ) +{ + FILE *output_binary_file; - max_total_num_fsamp_per_iteration_diff => uint16_t - coeff_diffuse_re => float[BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) - coeff_diffuse_im => float[BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) - */ + int16_t iIR, iIter, iChan, iTap; + uint32_t data_size_tmp; + float *coeff_rptr; + float maxVal; + char tmpStr[64]; + float maxDiff = 0, diff, tmp, tmp2; + Word16 tmp16; + Word32 tmp32; + + crend_hrtf_tables_dimensions hrtf_table_dims; + + if ( hrtf == NULL ) + return IVAS_ERR_FAILED_ALLOC; get_binary_tables_dimensions( hrtf, &hrtf_table_dims ); - hrtf_data_size = compute_binary_size( hrtf, &hrtf_table_dims ); + // Write the HRTF raw data - hrtf_bin = NULL; - hrtf_bin = (char *) malloc( hrtf_data_size ); - if ( hrtf_bin == NULL ) - return; + maxDiff = 0; + + if ( hrtf->latency_s > 0 ) + { + factorQ[0] = (Word16) floorf( 31.f - logf( hrtf->latency_s ) / logf( 2.f ) ); + } + else + { + factorQ[0] = 0; + } + + tmp = hrtf->latency_s; + tmp32 = float2Word32( hrtf->latency_s, factorQ[0] ); + hrtf->latency_s = (float) tmp32 * powf( 2.f, -1.f * (float) factorQ[0] ); + maxDiff = fabsf( hrtf->latency_s - tmp ); + + maxVal = 0; + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + if ( maxVal < fabsf( hrtf->inv_diffuse_weight[0][iIR] ) ) + { + maxVal = fabsf( hrtf->inv_diffuse_weight[0][iIR] ); + } + if ( maxVal < fabsf( hrtf->inv_diffuse_weight[1][iIR] ) ) + { + maxVal = fabsf( hrtf->inv_diffuse_weight[1][iIR] ); + } + } + + if ( maxVal > 0 ) + { + factorQ[1] = (Word16) floorf( 15.f - logf( maxVal ) / logf( 2.f ) ); + } + else + { + factorQ[1] = 0; + } + + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + tmp = hrtf->inv_diffuse_weight[0][iIR]; + tmp16 = float2Word16( hrtf->inv_diffuse_weight[0][iIR], factorQ[1] ); + hrtf->inv_diffuse_weight[0][iIR] = (float) tmp16 * powf( 2.f, -1.f * factorQ[1] ); + diff = fabsf( hrtf->inv_diffuse_weight[0][iIR] - tmp ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + tmp = hrtf->inv_diffuse_weight[1][iIR]; + tmp16 = float2Word16( hrtf->inv_diffuse_weight[1][iIR], factorQ[1] ); + hrtf->inv_diffuse_weight[1][iIR] = (float) tmp16 * powf( 2.f, -1.f * factorQ[1] ); + diff = fabsf( hrtf->inv_diffuse_weight[1][iIR] - tmp ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + + // find max values + maxVal = 0; + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_re[iIR][iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) + { + if ( maxVal < fabsf( coeff_rptr[iTap] ) ) + { + maxVal = fabsf( coeff_rptr[iTap] ); + } + } + coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; + } + } + } + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_im[iIR][iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) + { + if ( maxVal < fabsf( coeff_rptr[iTap] ) ) + { + maxVal = fabsf( coeff_rptr[iTap] ); + } + } + coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; + } + } + } + + if ( hrtf_table_dims.max_total_num_fsamp_per_iteration_diff != 0 ) + { + // find max value + + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_diffuse_re[iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) + { + if ( maxVal < fabsf( coeff_rptr[iTap] ) ) + { + maxVal = fabsf( coeff_rptr[iTap] ); + } + } + coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; + } + } + + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_diffuse_im[iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) + { + if ( maxVal < fabsf( coeff_rptr[iTap] ) ) + { + maxVal = fabsf( coeff_rptr[iTap] ); + } + } + coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; + } + } + } + + if ( maxVal > 0 ) + { + factorQ[2] = (Word16) floorf( 31.f - logf( maxVal ) / logf( 2.f ) ); + } + else + { + factorQ[2] = 0; + } + + // pOut_to_bin_re (The size depends on pIndex_frequency_max) + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_re[iIR][iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + tmp32 = float2Word32( coeff_rptr[iTap], factorQ[2] ); + coeff_rptr[iTap] = (float) tmp32 * powf( 2.f, -1.f * (float) factorQ[2] ); + diff = fabsf( tmp - coeff_rptr[iTap] ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; + } + } + } + + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_im[iIR][iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + tmp32 = float2Word32( coeff_rptr[iTap], factorQ[2] ); + coeff_rptr[iTap] = (float) tmp32 * powf( 2.f, -1.f * (float) factorQ[2] ); + diff = fabsf( tmp - coeff_rptr[iTap] ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; + } + } + } + + + if ( hrtf_table_dims.max_total_num_fsamp_per_iteration_diff != 0 ) + { + // pOut_to_bin_diffuse_re : The size depends on pIndex_frequency_max_diffuse + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_diffuse_re[iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + tmp32 = float2Word32( coeff_rptr[iTap], factorQ[2] ); + coeff_rptr[iTap] = (float) tmp32 * powf( 2.f, -1.f * factorQ[2] ); + diff = fabsf( tmp - coeff_rptr[iTap] ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; + } + } + + // pOut_to_bin_diffuse_im : The size depends on pIndex_frequency_max_diffuse + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_diffuse_im[iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( float ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + tmp32 = float2Word32( coeff_rptr[iTap], factorQ[2] ); + coeff_rptr[iTap] = (float) tmp32 * powf( 2.f, -1.f * factorQ[2] ); + diff = fabsf( tmp - coeff_rptr[iTap] ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; + } + } + } + return IVAS_ERR_OK; +} + +/*---------------------------------------------------------------------* + * write_binary_file_fx(); + *---------------------------------------------------------------------*/ +ivas_error write_binary_file_fx( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len, int16_t factorQ[3] ) +{ + FILE *output_binary_file; + + int16_t iIR, iIter, iChan, iTap; + uint32_t data_size_tmp; + float *coeff_rptr; + float maxVal; + + char tmpStr[64]; + float maxDiff = 0, diff, tmp, tmp2; + + crend_hrtf_tables_dimensions hrtf_table_dims; + + uint32_t hrtf_data_size; + char *hrtf_bin = NULL, *hrtf_bin_wptr; + + char *binary_file_full_path = NULL; + + if ( hrtf == NULL ) + return IVAS_ERR_FAILED_ALLOC; + + if ( binary_file_path == NULL ) + return IVAS_ERR_FAILED_ALLOC; + + /* Binary file - block description : + + latency_s Q scaling factor => Wor16 + latency_s => Word32 + + max_num_ir => uint16_t + BINAURAL_CHANNELS => uint16_t (BINAURAL_CHANNELS) + + max_num_iterations => int16_t + num_iterations => uint16_t[max_num_ir][BINAURAL_CHANNELS] + pIndex_frequency_max => uint16_t[max_num_ir][BINAURAL_CHANNELS][max_num_iterations] (Pointer) + + max_num_iterations_diffuse => int16_t + num_iterations_diffuse => uint16_t[BINAURAL_CHANNELS] + pIndex_frequency_max_diffuse => uint16_t[BINAURAL_CHANNELS][max_num_iterations_diffuse] (Pointer) + + index_frequency_max_diffuse => uint16_t + inv_diffuse_weight Q scaling factor => Wor16 + inv_diffuse_weight => Word16[BINAURAL_CHANNELS][max_num_ir] + + max_total_num_fsamp_per_iteration => uint32_t + coeff Q scaling factor => Wor16 + coeff_re => Word32[max_num_ir][BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + coeff_im => Word32[max_num_ir][BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + + max_total_num_fsamp_per_iteration_diff => uint32_t + coeff_diffuse_re => Word32[BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + coeff_diffuse_im => Word32[BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + */ + + get_binary_tables_dimensions( hrtf, &hrtf_table_dims ); + + hrtf_data_size = compute_binary_size_fx( hrtf, &hrtf_table_dims ); + + hrtf_bin = NULL; + hrtf_bin = (char *) malloc( hrtf_data_size ); + if ( hrtf_bin == NULL ) + return IVAS_ERR_FAILED_ALLOC; + memset( hrtf_bin, 0x00, hrtf_data_size ); + hrtf_bin_wptr = hrtf_bin; + + // Write the HRTF raw data + ( (Word16 *) hrtf_bin_wptr )[0] = factorQ[0]; // factor Q for latency + hrtf_bin_wptr += sizeof( Word16 ); + + maxDiff = 0; + tmp = hrtf->latency_s; + ( (Word32 *) hrtf_bin_wptr )[0] = float2Word32( tmp, factorQ[0] ); + maxDiff = fabsf( tmp - (float) ( (Word32 *) hrtf_bin_wptr )[0] * powf( 2.f, -1.f * (float) factorQ[0] ) ); + hrtf_bin_wptr += sizeof( Word32 ); + + ( (uint16_t *) hrtf_bin_wptr )[0] = hrtf->max_num_ir; + hrtf_bin_wptr += sizeof( uint16_t ); + + ( (uint16_t *) hrtf_bin_wptr )[0] = BINAURAL_CHANNELS; + hrtf_bin_wptr += sizeof( uint16_t ); + + ( (int16_t *) hrtf_bin_wptr )[0] = hrtf->max_num_iterations; // max_num_iterations + hrtf_bin_wptr += sizeof( int16_t ); + + data_size_tmp = hrtf->max_num_ir * BINAURAL_CHANNELS * sizeof( uint16_t ); + memcpy( hrtf_bin_wptr, hrtf->num_iterations, data_size_tmp ); // num_iterations + hrtf_bin_wptr += data_size_tmp; + + // pIndex_frequency_max + data_size_tmp = hrtf->max_num_iterations * sizeof( uint16_t ); + for ( int iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + memcpy( hrtf_bin_wptr, hrtf->pIndex_frequency_max[iIR][iChan], data_size_tmp ); + hrtf_bin_wptr += data_size_tmp; + } + } + + memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_num_iterations_diffuse ), sizeof( int16_t ) ); // max_num_iterations_diffuse + hrtf_bin_wptr += sizeof( int16_t ); + + if ( hrtf_table_dims.max_num_iterations_diffuse != 0 ) + { + data_size_tmp = BINAURAL_CHANNELS * sizeof( uint16_t ); + memcpy( hrtf_bin_wptr, hrtf->num_iterations_diffuse, data_size_tmp ); // num_iterations_diffuse + hrtf_bin_wptr += data_size_tmp; + + // pIndex_frequency_max_diffuse (the size depends on num_iterations_diffuse) + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + data_size_tmp = hrtf->num_iterations_diffuse[iChan] * sizeof( uint16_t ); + memcpy( hrtf_bin_wptr, hrtf->pIndex_frequency_max_diffuse[iChan], data_size_tmp ); + hrtf_bin_wptr += data_size_tmp; + } + } + + ( (Word16 *) hrtf_bin_wptr )[0] = hrtf->index_frequency_max_diffuse; // index_frequency_max_diffuse + hrtf_bin_wptr += sizeof( uint16_t ); + + ( (Word16 *) hrtf_bin_wptr )[0] = factorQ[1]; // Q factor for filters + hrtf_bin_wptr += sizeof( Word16 ); + + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + tmp = hrtf->inv_diffuse_weight[0][iIR]; + ( (Word16 *) hrtf_bin_wptr )[iIR] = float2Word16( hrtf->inv_diffuse_weight[0][iIR], factorQ[1] ); + diff = fabsf( tmp - (float) ( (Word16 *) hrtf_bin_wptr )[iIR] * powf( 2.f, -1.f * factorQ[1] ) ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + + data_size_tmp = hrtf->max_num_ir * sizeof( Word16 ); + hrtf_bin_wptr += data_size_tmp; + + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + tmp = hrtf->inv_diffuse_weight[1][iIR]; + ( (Word16 *) hrtf_bin_wptr )[iIR] = float2Word16( hrtf->inv_diffuse_weight[1][iIR], factorQ[1] ); + diff = fabsf( tmp - (float) ( (Word16 *) hrtf_bin_wptr )[iIR] * powf( 2.f, -1.f * factorQ[1] ) ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + data_size_tmp = hrtf->max_num_ir * sizeof( Word16 ); + hrtf_bin_wptr += data_size_tmp; + + ( (uint32_t *) hrtf_bin_wptr )[0] = hrtf_table_dims.max_total_num_fsamp_per_iteration; // max_total_num_fsamp_per_iteration + hrtf_bin_wptr += sizeof( uint32_t ); + + ( (Word16 *) hrtf_bin_wptr )[0] = factorQ[2]; // Q factor for filters + hrtf_bin_wptr += sizeof( Word16 ); + + // pOut_to_bin_re (The size depends on pIndex_frequency_max) + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_re[iIR][iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( Word32 ); + // memcpy( hrtf_bin_wptr, coeff_rptr, data_size_tmp ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + ( (Word32 *) hrtf_bin_wptr )[iTap] = float2Word32( coeff_rptr[iTap], factorQ[2] ); + tmp2 = ( (float) ( ( (Word32 *) hrtf_bin_wptr )[iTap] ) ) * powf( 2.f, -1.f * (float) factorQ[2] ); + diff = fabsf( tmp - tmp2 ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + hrtf_bin_wptr += data_size_tmp; + coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; + } + } + } + + // pOut_to_bin_im (The size depends on pIndex_frequency_max) + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) + { + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_im[iIR][iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( Word32 ); + + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + ( (Word32 *) hrtf_bin_wptr )[iTap] = float2Word32( coeff_rptr[iTap], factorQ[2] ); + tmp2 = ( (float) ( ( (Word32 *) hrtf_bin_wptr )[iTap] ) ) * powf( 2.f, -1.f * (float) factorQ[2] ); + diff = fabsf( tmp - tmp2 ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + hrtf_bin_wptr += data_size_tmp; + coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; + } + } + } + + memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_total_num_fsamp_per_iteration_diff ), sizeof( uint32_t ) ); // max_total_num_fsamp_per_iteration_diff + hrtf_bin_wptr += sizeof( uint32_t ); + + if ( hrtf_table_dims.max_total_num_fsamp_per_iteration_diff != 0 ) + { + // pOut_to_bin_diffuse_re : The size depends on pIndex_frequency_max_diffuse + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_diffuse_re[iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( Word32 ); + + // memcpy( hrtf_bin_wptr, coeff_rptr, data_size_tmp ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + ( (Word32 *) hrtf_bin_wptr )[iTap] = float2Word32( coeff_rptr[iTap], factorQ[2] ); + tmp2 = ( (float) ( ( (Word32 *) hrtf_bin_wptr )[iTap] ) ) * powf( 2.f, -1.f * (float) factorQ[2] ); + diff = fabsf( tmp - tmp2 ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + hrtf_bin_wptr += data_size_tmp; + coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; + } + } + + // pOut_to_bin_diffuse_im : The size depends on pIndex_frequency_max_diffuse + for ( iChan = 0; iChan < BINAURAL_CHANNELS; iChan++ ) + { + coeff_rptr = hrtf->pOut_to_bin_diffuse_im[iChan]; + for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) + { + data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( Word32 ); + // memcpy( hrtf_bin_wptr, coeff_rptr, data_size_tmp ); + for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) + { + tmp = coeff_rptr[iTap]; + ( (Word32 *) hrtf_bin_wptr )[iTap] = float2Word32( coeff_rptr[iTap], factorQ[2] ); + tmp2 = ( (float) ( ( (Word32 *) hrtf_bin_wptr )[iTap] ) ) * powf( 2.f, -1.f * (float) factorQ[2] ); + diff = fabsf( tmp - tmp2 ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + hrtf_bin_wptr += data_size_tmp; + coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; + } + } + } + + if ( hrtf_bin_wptr - hrtf_bin != hrtf_data_size ) + { + free( hrtf_bin ); + return IVAS_ERR_FAILED_FILE_WRITE; + } + + binary_file_full_path = (char *) malloc( sizeof( char ) * ( strlen( binary_file_path ) + 1 + strlen( lscfg.name ) + 1 + 5 + 3 + 4 + 3 ) ); + sprintf( binary_file_full_path, "%s_%s_%ikHz_fx.bin", binary_file_path, lscfg.name, samplerate / 1000 ); + fprintf( stdout, "Write Binary file %s:\n", binary_file_full_path ); + + output_binary_file = fopen( binary_file_full_path, "wb" ); + if ( output_binary_file == NULL ) + { + free( hrtf_bin ); + return IVAS_ERR_FAILED_FILE_WRITE; + } + fwrite( hrtf_bin, hrtf_data_size, 1, output_binary_file ); + fclose( output_binary_file ); + + free( hrtf_bin ); + free( binary_file_full_path ); + return IVAS_ERR_OK; +} +#endif + +/*---------------------------------------------------------------------* + * write_binary_file(); + *---------------------------------------------------------------------*/ +ivas_error write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int32_t samplerate, const int16_t frame_len ) +{ + FILE *output_binary_file; + + int16_t iIR, iIter, iChan, iTap; + uint32_t data_size_tmp; + float *coeff_rptr; + char tmpStr[64]; + + crend_hrtf_tables_dimensions hrtf_table_dims; + + uint32_t hrtf_data_size; + char *hrtf_bin = NULL, *hrtf_bin_wptr; + + char *binary_file_full_path = NULL; + + if ( hrtf == NULL ) + return IVAS_ERR_FAILED_ALLOC; + + if ( binary_file_path == NULL ) + return IVAS_ERR_FAILED_ALLOC; + + /* Binary file - block description : + + latency_s => float + + max_num_ir => uint16_t + BINAURAL_CHANNELS => uint16_t (BINAURAL_CHANNELS) + + max_num_iterations => int16_t + num_iterations => uint16_t[max_num_ir][BINAURAL_CHANNELS] + pIndex_frequency_max => uint16_t[max_num_ir][BINAURAL_CHANNELS][max_num_iterations] (Pointer) + + max_num_iterations_diffuse => int16_t + num_iterations_diffuse => uint16_t[BINAURAL_CHANNELS] + pIndex_frequency_max_diffuse => uint16_t[BINAURAL_CHANNELS][max_num_iterations_diffuse] (Pointer) + + index_frequency_max_diffuse => uint16_t + inv_diffuse_weight => float[BINAURAL_CHANNELS][max_num_ir] + +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + max_total_num_fsamp_per_iteration => uint32_t +#else + max_total_num_fsamp_per_iteration => uint16_t +#endif + coeff_re => float[max_num_ir][BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + coeff_im => float[max_num_ir][BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + max_total_num_fsamp_per_iteration_diff => uint32_t +#else + max_total_num_fsamp_per_iteration_diff => uint16_t +#endif + coeff_diffuse_re => float[BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + coeff_diffuse_im => float[BINAURAL_CHANNELS][max_total_num_fsamp_per_iteration] (Pointer) + */ + + get_binary_tables_dimensions( hrtf, &hrtf_table_dims ); + + hrtf_data_size = compute_binary_size( hrtf, &hrtf_table_dims ); + + hrtf_bin = NULL; + hrtf_bin = (char *) malloc( hrtf_data_size ); + if ( hrtf_bin == NULL ) + return IVAS_ERR_FAILED_ALLOC; memset( hrtf_bin, 0x00, hrtf_data_size ); hrtf_bin_wptr = hrtf_bin; // Write the HRTF raw data - memcpy( hrtf_bin_wptr, &( hrtf->latency_s ), sizeof( float ) ); // latency_s + ( (float *) hrtf_bin_wptr )[0] = hrtf->latency_s; hrtf_bin_wptr += sizeof( float ); - memcpy( hrtf_bin_wptr, &( hrtf->max_num_ir ), sizeof( uint16_t ) ); // max_num_ir + ( (uint16_t *) hrtf_bin_wptr )[0] = hrtf->max_num_ir; hrtf_bin_wptr += sizeof( uint16_t ); - uint16_t nchan_bin = BINAURAL_CHANNELS; - memcpy( hrtf_bin_wptr, &nchan_bin, sizeof( uint16_t ) ); // BINAURAL_CHANNELS + ( (uint16_t *) hrtf_bin_wptr )[0] = BINAURAL_CHANNELS; hrtf_bin_wptr += sizeof( uint16_t ); - memcpy( hrtf_bin_wptr, &( hrtf->max_num_iterations ), sizeof( int16_t ) ); // max_num_iterations + + ( (int16_t *) hrtf_bin_wptr )[0] = hrtf->max_num_iterations; // max_num_iterations hrtf_bin_wptr += sizeof( int16_t ); data_size_tmp = hrtf->max_num_ir * BINAURAL_CHANNELS * sizeof( uint16_t ); @@ -2661,19 +3516,38 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iIR] = hrtf->inv_diffuse_weight[0][iIR]; +#else sprintf( tmpStr, FORMAT_FLOAT, hrtf->inv_diffuse_weight[0][iIR] ); sscanf( tmpStr, "%f", &( (float *) hrtf_bin_wptr )[iIR] ); +#endif } + + data_size_tmp = hrtf->max_num_ir * sizeof( float ); + hrtf_bin_wptr += data_size_tmp; + for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iIR] = hrtf->inv_diffuse_weight[1][iIR]; +#else sprintf( tmpStr, FORMAT_FLOAT, hrtf->inv_diffuse_weight[1][iIR] ); - sscanf( tmpStr, "%f", &( (float *) hrtf_bin_wptr )[hrtf->max_num_ir + iIR] ); + sscanf( tmpStr, "%f", &( (float *) hrtf_bin_wptr )[iIR] ); +#endif } - data_size_tmp = hrtf->max_num_ir * sizeof( float ) * BINAURAL_CHANNELS; + data_size_tmp = hrtf->max_num_ir * sizeof( float ); hrtf_bin_wptr += data_size_tmp; + +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_total_num_fsamp_per_iteration ), sizeof( uint32_t ) ); // max_total_num_fsamp_per_iteration + hrtf_bin_wptr += sizeof( uint32_t ); +#else memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_total_num_fsamp_per_iteration ), sizeof( uint16_t ) ); // max_total_num_fsamp_per_iteration hrtf_bin_wptr += sizeof( uint16_t ); +#endif + // pOut_to_bin_re (The size depends on pIndex_frequency_max) for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) @@ -2687,9 +3561,13 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const // memcpy( hrtf_bin_wptr, coeff_rptr, data_size_tmp ); for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; +#else //( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; sprintf( tmpStr, FORMAT_FLOAT, coeff_rptr[iTap] ); sscanf( tmpStr, "%f", &( ( (float *) hrtf_bin_wptr )[iTap] ) ); +#endif } hrtf_bin_wptr += data_size_tmp; coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; @@ -2706,12 +3584,15 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const for ( iIter = 0; iIter < hrtf->num_iterations[iIR][iChan]; iIter++ ) { data_size_tmp = hrtf->pIndex_frequency_max[iIR][iChan][iIter] * sizeof( float ); - // memcpy( hrtf_bin_wptr, coeff_rptr, data_size_tmp ); for ( iTap = 0; iTap < hrtf->pIndex_frequency_max[iIR][iChan][iIter]; iTap++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; +#else //( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; sprintf( tmpStr, FORMAT_FLOAT, coeff_rptr[iTap] ); sscanf( tmpStr, "%f", &( ( (float *) hrtf_bin_wptr )[iTap] ) ); +#endif } hrtf_bin_wptr += data_size_tmp; coeff_rptr += hrtf->pIndex_frequency_max[iIR][iChan][iIter]; @@ -2719,8 +3600,13 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const } } +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_total_num_fsamp_per_iteration_diff ), sizeof( uint32_t ) ); // max_total_num_fsamp_per_iteration_diff + hrtf_bin_wptr += sizeof( uint32_t ); +#else memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_total_num_fsamp_per_iteration_diff ), sizeof( uint16_t ) ); // max_total_num_fsamp_per_iteration_diff hrtf_bin_wptr += sizeof( uint16_t ); +#endif if ( hrtf_table_dims.max_total_num_fsamp_per_iteration_diff != 0 ) { @@ -2731,12 +3617,15 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) { data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( float ); - // memcpy( hrtf_bin_wptr, coeff_rptr, data_size_tmp ); for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; +#else //( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; sprintf( tmpStr, FORMAT_FLOAT, coeff_rptr[iTap] ); sscanf( tmpStr, "%f", &( ( (float *) hrtf_bin_wptr )[iTap] ) ); +#endif } hrtf_bin_wptr += data_size_tmp; coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; @@ -2750,12 +3639,15 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const for ( iIter = 0; iIter < hrtf->num_iterations_diffuse[iChan]; iIter++ ) { data_size_tmp = hrtf->pIndex_frequency_max_diffuse[iChan][iIter] * sizeof( float ); - // memcpy( hrtf_bin_wptr, coeff_rptr, data_size_tmp ); for ( iTap = 0; iTap < hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; iTap++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; +#else //( (float *) hrtf_bin_wptr )[iTap] = coeff_rptr[iTap]; sprintf( tmpStr, FORMAT_FLOAT, coeff_rptr[iTap] ); sscanf( tmpStr, "%f", &( ( (float *) hrtf_bin_wptr )[iTap] ) ); +#endif } hrtf_bin_wptr += data_size_tmp; coeff_rptr += hrtf->pIndex_frequency_max_diffuse[iChan][iIter]; @@ -2763,6 +3655,12 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const } } + if ( hrtf_bin_wptr - hrtf_bin != hrtf_data_size ) + { + free( hrtf_bin ); + return IVAS_ERR_FAILED_FILE_WRITE; + } + binary_file_full_path = (char *) malloc( sizeof( char ) * ( strlen( binary_file_path ) + 1 + strlen( lscfg.name ) + 1 + 5 + 3 + 4 ) ); sprintf( binary_file_full_path, "%s_%s_%ikHz.bin", binary_file_path, lscfg.name, samplerate / 1000 ); fprintf( stdout, "Write Binary file %s:\n", binary_file_full_path ); @@ -2771,74 +3669,302 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const if ( output_binary_file == NULL ) { free( hrtf_bin ); - return; + return IVAS_ERR_FAILED_FILE_WRITE; + } + fwrite( hrtf_bin, hrtf_data_size, 1, output_binary_file ); + fclose( output_binary_file ); + + free( hrtf_bin ); + free( binary_file_full_path ); + + return IVAS_ERR_OK; +} + +/*---------------------------------------------------------------------* + * make_fx_be(); + *---------------------------------------------------------------------*/ +ivas_error make_reverb_fx_be( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate, Word16 *factorQ ) +{ + FILE *output_binary_file; + uint32_t hrtf_data_size; + + + int16_t iTap; + float *coeff_rptr; + float maxVal; + char tmpStr[64]; + float maxDiff = 0, diff, tmp, tmp2; + Word16 tmp16; + + int16_t len = LR_IAC_LENGTH_NR_FC; + if ( samplerate == 16000 ) + { + len = LR_IAC_LENGTH_NR_FC_16KHZ; + } + + if ( pEner_l == NULL ) + return IVAS_ERR_FAILED_ALLOC; + + if ( pEner_r == NULL ) + return IVAS_ERR_FAILED_ALLOC; + + if ( pCoherence == NULL ) + return IVAS_ERR_FAILED_ALLOC; + + maxVal = 0; + for ( iTap = 0; iTap < len; iTap++ ) + { + if ( maxVal < fabsf( pEner_l[iTap] ) ) + { + maxVal = fabsf( pEner_l[iTap] ); + } + if ( maxVal < fabsf( pEner_r[iTap] ) ) + { + maxVal = fabsf( pEner_r[iTap] ); + } + if ( maxVal < fabsf( pCoherence[iTap] ) ) + { + maxVal = fabsf( pCoherence[iTap] ); + } + } + + if ( maxVal > 0 ) + { + factorQ[0] = (Word16) floorf( 15.f - logf( maxVal ) / logf( 2.f ) ); + } + else + { + factorQ[0] = 0; + } + + for ( iTap = 0; iTap < len; iTap++ ) + { + tmp = pEner_l[iTap]; + tmp16 = float2Word16( pEner_l[iTap], factorQ[0] ); + pEner_l[iTap] = (float) tmp16 * powf( 2.f, -1.f * (float) factorQ[0] ); + diff = fabsf( tmp - pEner_l[iTap] ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + for ( iTap = 0; iTap < len; iTap++ ) + { + tmp = pEner_r[iTap]; + tmp16 = float2Word16( pEner_r[iTap], factorQ[0] ); + pEner_r[iTap] = (float) tmp16 * powf( 2.f, -1.f * (float) factorQ[0] ); + diff = fabsf( tmp - pEner_r[iTap] ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + for ( iTap = 0; iTap < len; iTap++ ) + { + tmp = pCoherence[iTap]; + tmp16 = float2Word16( pCoherence[iTap], factorQ[0] ); + pCoherence[iTap] = (float) tmp16 * powf( 2.f, -1.f * (float) factorQ[0] ); + diff = fabsf( tmp - pCoherence[iTap] ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + return IVAS_ERR_OK; +} + +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT +/*---------------------------------------------------------------------* + * write_binary_file_fx(); + *---------------------------------------------------------------------*/ +ivas_error write_reverb_to_binary_file_fx( float *pEner_l, float *pEner_r, float *pCoherence, Word16 factorQ, const int32_t samplerate ) +{ + FILE *output_binary_file; + + int16_t iTap; + char tmpStr[64]; + uint32_t hrtf_data_size; + float maxDiff = 0, diff, tmp, tmp2; + Word16 tmp16; + + char *hrtf_bin = NULL, *hrtf_bin_wptr; + + char *binary_file_full_path = NULL; + + int16_t len = LR_IAC_LENGTH_NR_FC; + + if ( samplerate == 16000 ) + { + len = LR_IAC_LENGTH_NR_FC_16KHZ; + } + + if ( pEner_l == NULL ) + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + ; + + if ( pEner_r == NULL ) + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + + if ( pCoherence == NULL ) + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + + if ( binary_file_path == NULL ) + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + + hrtf_bin = NULL; + hrtf_data_size = sizeof( Word16 ) * 3 * len + sizeof( Word16 ); + hrtf_bin = (char *) malloc( hrtf_data_size ); + if ( hrtf_bin == NULL ) + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + memset( hrtf_bin, 0x00, hrtf_data_size ); + hrtf_bin_wptr = hrtf_bin; + + memcpy( hrtf_bin_wptr, &factorQ, sizeof( Word16 ) ); // Q factor for filters + hrtf_bin_wptr += sizeof( Word16 ); + + for ( iTap = 0; iTap < len; iTap++ ) + { + tmp = pEner_l[iTap]; + ( (Word16 *) hrtf_bin_wptr )[iTap] = float2Word16( pEner_l[iTap], factorQ ); + tmp2 = ( (float) ( ( (Word16 *) hrtf_bin_wptr )[iTap] ) ) * powf( 2.f, -1.f * (float) factorQ ); + diff = fabsf( tmp - tmp2 ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + hrtf_bin_wptr += sizeof( Word16 ) * len; + for ( iTap = 0; iTap < len; iTap++ ) + { + tmp = pEner_r[iTap]; + ( (Word16 *) hrtf_bin_wptr )[iTap] = float2Word16( pEner_r[iTap], factorQ ); + tmp2 = ( (float) ( ( (Word16 *) hrtf_bin_wptr )[iTap] ) ) * powf( 2.f, -1.f * (float) factorQ ); + diff = fabsf( tmp - tmp2 ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + hrtf_bin_wptr += sizeof( Word16 ) * len; + for ( iTap = 0; iTap < len; iTap++ ) + { + tmp = pCoherence[iTap]; + ( (Word16 *) hrtf_bin_wptr )[iTap] = float2Word16( pCoherence[iTap], factorQ ); + tmp2 = ( (float) ( ( (Word16 *) hrtf_bin_wptr )[iTap] ) ) * powf( 2.f, -1.f * (float) factorQ ); + diff = fabsf( tmp - tmp2 ); + if ( maxDiff < diff ) + { + maxDiff = diff; + } + } + hrtf_bin_wptr += sizeof( Word16 ) * len; + + if ( hrtf_bin_wptr - hrtf_bin != hrtf_data_size ) + { + free( hrtf_bin ); + return IVAS_ERR_FAILED_FILE_WRITE; + } + + binary_file_full_path = (char *) malloc( sizeof( char ) * ( strlen( binary_file_path ) + 1 + strlen( "Reverb" ) + 1 + 5 + 3 + 4 ) ); + sprintf( binary_file_full_path, "%s_%s_%ikHz_fx.bin", binary_file_path, "Reverb", samplerate / 1000 ); + fprintf( stdout, "Write Binary file %s:\n", binary_file_full_path ); + + output_binary_file = fopen( binary_file_full_path, "wb" ); + if ( output_binary_file == NULL ) + { + free( hrtf_bin ); + return IVAS_ERR_FAILED_FILE_WRITE; } fwrite( hrtf_bin, hrtf_data_size, 1, output_binary_file ); fclose( output_binary_file ); free( hrtf_bin ); free( binary_file_full_path ); + + return IVAS_ERR_OK; } + +#endif /*---------------------------------------------------------------------* * write_binary_file(); *---------------------------------------------------------------------*/ -void write_reverb_to_binary_file( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate ) +ivas_error write_reverb_to_binary_file( float *pEner_l, float *pEner_r, float *pCoherence, const int32_t samplerate ) { FILE *output_binary_file; int16_t iTap; char tmpStr[64]; uint32_t hrtf_data_size; + float maxVal; char *hrtf_bin = NULL, *hrtf_bin_wptr; char *binary_file_full_path = NULL; int16_t len = LR_IAC_LENGTH_NR_FC; + if ( samplerate == 16000 ) { len = LR_IAC_LENGTH_NR_FC_16KHZ; } if ( pEner_l == NULL ) - return; + return IVAS_ERR_UNEXPECTED_NULL_POINTER; if ( pEner_r == NULL ) - return; + return IVAS_ERR_UNEXPECTED_NULL_POINTER; if ( pCoherence == NULL ) - return; + return IVAS_ERR_UNEXPECTED_NULL_POINTER; if ( binary_file_path == NULL ) - return; + return IVAS_ERR_UNEXPECTED_NULL_POINTER; hrtf_bin = NULL; hrtf_data_size = sizeof( float ) * 3 * len; hrtf_bin = (char *) malloc( hrtf_data_size ); if ( hrtf_bin == NULL ) - return; + return IVAS_ERR_UNEXPECTED_NULL_POINTER; memset( hrtf_bin, 0x00, hrtf_data_size ); hrtf_bin_wptr = hrtf_bin; for ( iTap = 0; iTap < len; iTap++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iTap] = pEner_l[iTap]; +#else sprintf( tmpStr, FORMAT_FLOAT, pEner_l[iTap] ); sscanf( tmpStr, "%f", &( ( (float *) hrtf_bin_wptr )[iTap] ) ); +#endif } hrtf_bin_wptr += sizeof( float ) * len; for ( iTap = 0; iTap < len; iTap++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iTap] = pEner_r[iTap]; +#else sprintf( tmpStr, FORMAT_FLOAT, pEner_r[iTap] ); sscanf( tmpStr, "%f", &( ( (float *) hrtf_bin_wptr )[iTap] ) ); +#endif } hrtf_bin_wptr += sizeof( float ) * len; for ( iTap = 0; iTap < len; iTap++ ) { +#ifdef FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT + ( (float *) hrtf_bin_wptr )[iTap] = pCoherence[iTap]; +#else sprintf( tmpStr, FORMAT_FLOAT, pCoherence[iTap] ); sscanf( tmpStr, "%f", &( ( (float *) hrtf_bin_wptr )[iTap] ) ); +#endif } hrtf_bin_wptr += sizeof( float ) * len; + if ( hrtf_bin_wptr - hrtf_bin != hrtf_data_size ) + { + free( hrtf_bin ); + return IVAS_ERR_FAILED_FILE_WRITE; + } + binary_file_full_path = (char *) malloc( sizeof( char ) * ( strlen( binary_file_path ) + 1 + strlen( "Reverb" ) + 1 + 5 + 3 + 4 ) ); sprintf( binary_file_full_path, "%s_%s_%ikHz.bin", binary_file_path, "Reverb", samplerate / 1000 ); fprintf( stdout, "Write Binary file %s:\n", binary_file_full_path ); @@ -2847,13 +3973,15 @@ void write_reverb_to_binary_file( float *pEner_l, float *pEner_r, float *pCohere if ( output_binary_file == NULL ) { free( hrtf_bin ); - return; + return IVAS_ERR_FAILED_FILE_WRITE; } fwrite( hrtf_bin, hrtf_data_size, 1, output_binary_file ); fclose( output_binary_file ); free( hrtf_bin ); free( binary_file_full_path ); + + return IVAS_ERR_OK; } /*---------------------------------------------------------------------* diff --git a/scripts/binauralRenderer_interface/generate_ivas_binauralizer_tables_from_sofa.m b/scripts/binauralRenderer_interface/generate_ivas_binauralizer_tables_from_sofa.m index 491062b1aa6a9c6d98a5e5b58e593e8375be181c..05b68fc0d1f0e2a6cacdc7a8447b7cba3b52808c 100644 --- a/scripts/binauralRenderer_interface/generate_ivas_binauralizer_tables_from_sofa.m +++ b/scripts/binauralRenderer_interface/generate_ivas_binauralizer_tables_from_sofa.m @@ -53,15 +53,17 @@ normalizeSofaInputData = false; %% if true SOFA IR are nomalized ivas_path = ['..' filesep '..' filesep]; generateCustomBinaryFile = false; +generateBinaryFile_fx = false; +generate_BE = true; %% Set input files if generateCustomBinaryFile hrir_file_name_init = 'HRIR_128_Meth5_IRC_51_Q10_symL_Itrp1_48000.sofa'; - hrir_file_name = 'HRIR_128_Meth5_IRC_51_Q10_symL_Itrp1_48000_norm.sofa'; + hrir_file_name = 'HRIR_128_Meth5_IRC_51_Q10_symL_Itrp1_48000.sofa'; output_bin_name = 'ivas_binaural_51_brir-lc'; else hrir_file_name_init = 'HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000.sofa'; - hrir_file_name = 'HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000_norm.sofa'; + hrir_file_name = 'HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000.sofa'; output_bin_name = 'ivas_binaural'; end brir_file_name = 'IIS_BRIR_officialMPEG_Combined.sofa'; @@ -213,6 +215,37 @@ if writeBinaryOutput == true error(cmdout) return end + + if generateBinaryFile_fx + td_binary_file = ['td_' erase(hrir_file_name,'.sofa') '_model_v003']; + command = ['.' filesep() 'Table_Format_Converter' filesep() 'tables_format_converter']; + binary_name = [binary_name '_fx']; + output_bin_name = [output_bin_name '_fx']; + command = [command ... + ' -output_file_path ' binary_path ... + ' -output_file_name ' output_bin_name ... + ' -input_mixerconv_hrir_file_path ' binary_path ... + ' -input_mixerconv_hrir_file_name ' binary_name ... + ' -input_mixerconv_brir_file_path ' binary_path ... + ' -input_mixerconv_brir_file_name ' binary_name ... + ' -input_reverb_file_path ' binary_path ... + ' -input_reverb_file_name ' binary_name ... + ' -input_td_file_path ' fullfile(binary_path, 'IVAS_default') ... + ' -input_td_file_name ' td_binary_file ... + ' -input_param_file_path ' binary_path ... + ' -input_param_file_name ' param_bin_file ... + ' -input_fastconv_file_path ' binary_path ... + ' -input_fastconv_file_name ' fastconv_bin_file ... + ]; + + [status, cmdout] = system(command); + if status ~= 0 + 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 diff --git a/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c b/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c index 210eaffab3ef5fb2268a1198a25ef72140409336..13c2bcf028dc3e945086b205871f4665760e8735 100644 --- a/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c +++ b/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c @@ -171,6 +171,21 @@ static void printfAudioBufferOutFilterParams( } #endif +Word32 float2Word32( float val, Word16 Q ) +{ + Word32 retval; + float tmp = powf( 2.f, (float) Q ); + retval = (Word32) roundf( val * tmp ); + return retval; +} + +Word16 float2Word16( float val, Word16 Q ) +{ + Word16 retval; + float tmp = powf( 2.f, (float) Q ); + retval = (Word16) roundf( val * tmp ); + return retval; +} ivas_error ivas_hrtf_close( HRTFS_HANDLE hHRTF /* i/o: HRTF handle */ @@ -404,7 +419,6 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params( indBeginMini = *index_start = (int32_t) round( ( pFirData->latency_s[0][0] - (double) pParam->latency_s ) * (double) pFirData->sampling_rate ); } - /************************************************************************/ /* Case HRIR (len <= 1024) -> fill FilterParam struct and quit function */ /************************************************************************/ @@ -1220,6 +1234,7 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( { pParam->pOut_to_bin_diffuse_re[i_ear] = (float *) malloc( totSizeFreqDiffuse * sizeof( float ) ); pParam->pOut_to_bin_diffuse_im[i_ear] = (float *) malloc( totSizeFreqDiffuse * sizeof( float ) ); + offset = 0; for ( i_block = 0; i_block < pParam->num_iterations_diffuse[0]; ++i_block ) { @@ -1269,6 +1284,7 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( pParam->pOut_to_bin_diffuse_re[i_ear][offset + i_tap] = pBlockSpectrum_r[i_tap]; pParam->pOut_to_bin_diffuse_im[i_ear][offset + i_tap] = pBlockSpectrum_i[i_tap]; } + offset = offset + pParam->pIndex_frequency_max_diffuse[i_ear][i_block]; } } @@ -1304,16 +1320,13 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( ivas_error ivas_set_hrtf_fr( HRTFS_DATA *crend_hrtf, ivas_hrtf_t *hrtf, - const int16_t output_frame - , - float mdft_scale_fact -) + const int16_t output_frame, + float mdft_scale_fact ) { int32_t i, j, m, n; float data_ir_flt[L_FRAME48k] = { 0.0f }; int32_t tmp_ir_len, in_len, k; - crend_hrtf->max_num_ir = (int16_t) hrtf->m; crend_hrtf->latency_s = (float) hrtf->latency_s[0][0]; @@ -1332,6 +1345,7 @@ ivas_error ivas_set_hrtf_fr( { return IVAS_ERR_FAILED_ALLOC; } + n = 0; tmp_ir_len = 0; diff --git a/scripts/binauralRenderer_interface/make_be_with_fx.m b/scripts/binauralRenderer_interface/make_be_with_fx.m new file mode 100644 index 0000000000000000000000000000000000000000..ba023654405266635d562f710d52a30f70cab241 --- /dev/null +++ b/scripts/binauralRenderer_interface/make_be_with_fx.m @@ -0,0 +1,8 @@ +function [y,factorQ] = make_be_with_fx(x,Q) +y = x; +factorQ = int16(0); +valMax = max(max(abs(real(x)),[],"all"), max(abs(imag(y)),[],"all")); +if ( valMax > 0 ) + factorQ = int16(floor( double(Q) - log( valMax ) / log( 2. ) )); + y = double(int32(x .* (2.^double(factorQ)))).* (2.^double(-factorQ)); +end \ No newline at end of file diff --git a/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/compute_lr_energies_and_iac.m b/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/compute_lr_energies_and_iac.m deleted file mode 100644 index 625b6a1161af9f9dc5bcbf7367f4a012d8130c7a..0000000000000000000000000000000000000000 --- a/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/compute_lr_energies_and_iac.m +++ /dev/null @@ -1,101 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% (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 [left_avg_power, right_avg_power, ia_coherence] = compute_lr_energies_and_iac(HRTF_mdfts, in_freq_count, out_freq_count) - % Compute left/right and coherence of entire HRTF dataset - % - % HRTF_mdfts - HRTF dataset in frequency domain. - % in_freq_count - number of HRTF bins - % out_freq_count - number of bins in target for energies and coherence - % values - - hrtf_count = size(HRTF_mdfts,3); - - left_avg_power = zeros(1, out_freq_count); - right_avg_power = zeros(1, out_freq_count); - ia_coherence = zeros(1, out_freq_count); - - inp_freq_step = 0.5 / in_freq_count; - inp_freq_offset = 0.5 * inp_freq_step; - out_freq_step = 0.5 / (out_freq_count - 1); - - base_idx = 1; - relative_pos = 0; - - % loop over output frequency bins - for out_bin_idx=0:out_freq_count-1 - norm_freqs = out_freq_step * out_bin_idx; - tbl_index = ( norm_freqs - inp_freq_offset ) / inp_freq_step; - if (tbl_index <= 0.0) - base_idx = 0; - relative_pos = 0; - else - base_idx = int16(floor(tbl_index)); - relative_pos = tbl_index - double(base_idx); - % extrapolation (above last bin), choose nearest - if(base_idx > (in_freq_count-2)) - base_idx = in_freq_count-2; - relative_pos = 1; - end - end - - base_idx = base_idx +1; - IA_coherence = zeros(2,1); - avg_pwr_lr = zeros(2,2); - - for hrtf_idx=1:hrtf_count - lr_pair_0 = HRTF_mdfts(base_idx,:,hrtf_idx); - lr_pair_1 = HRTF_mdfts(base_idx + 1,:,hrtf_idx); - avg_pwr_lr(1,:) = avg_pwr_lr(1,:) + real(lr_pair_0).^2 + imag(lr_pair_0).^2; - avg_pwr_lr(2,:) = avg_pwr_lr(2,:) + real(lr_pair_1).^2 + imag(lr_pair_1).^2; - IA_coherence(1,1) = IA_coherence(1,1) + real(lr_pair_0(1)) * real(lr_pair_0(2)) + imag(lr_pair_0(1)) * imag(lr_pair_0(2)); - IA_coherence(2,1) = IA_coherence(2,1) + real(lr_pair_1(1)) * real(lr_pair_1(2)) + imag(lr_pair_1(1)) * imag(lr_pair_1(2)); - end - - % compute averages and IA coherence - avg_pwr_lr = avg_pwr_lr/hrtf_count; - IA_coherence = IA_coherence/hrtf_count; - IA_coherence(1,1) = IA_coherence(1,1) / sqrt((avg_pwr_lr(1,1) * avg_pwr_lr(1,2))); - IA_coherence(2,1) = IA_coherence(2,1) / sqrt((avg_pwr_lr(2,1) * avg_pwr_lr(2,2))); - - % Limiting to (0...1) range in case of small numerical errors or negative values - for i=1:2 - IA_coherence(i,1) = min(IA_coherence(i,1),1); - IA_coherence(i,1) = max(IA_coherence(i,1),0); - end - - % Computing weighted average of 2 nearest values (1 below + 1 above) for linear interpolation - weight_1st = 1 - relative_pos; - left_avg_power(out_bin_idx + 1) = weight_1st * avg_pwr_lr(1,1) + relative_pos * avg_pwr_lr(2,1); - right_avg_power(out_bin_idx + 1) = weight_1st * avg_pwr_lr(1,2) + relative_pos * avg_pwr_lr(2,2); - ia_coherence(out_bin_idx + 1) = weight_1st * IA_coherence(1,1) + relative_pos * IA_coherence(2,1); - end -end \ No newline at end of file diff --git a/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/generate_lr_energies_and_iac.m b/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/generate_lr_energies_and_iac.m deleted file mode 100644 index a67ba8267c9b9cd8309d546fd72ec52378c4b822..0000000000000000000000000000000000000000 --- a/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/generate_lr_energies_and_iac.m +++ /dev/null @@ -1,111 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% (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 data_struct = generate_lr_energies_and_iac(sofa_path, sofa_file_name) - % Generate left and right energies and coherence for late reverb from - % HRIRs. - % - % sofa_path - path to the directory that contains the sofa files to be - % converted. - % sofa_file - file name of the HRTFs to be converted - % - % Typical usage: - % generate_lr_energies_and_iac('../HRIRs_sofa', 'HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000.sofa') - % - -audio_format.names(1:4) = {'510'; '710'; '512'; '714'}; - -audio_format.az(1,1:4) = {[30 330 0 110 250]; ... - [30 330 0 110 250 135 225]; ... - [30 330 0 110 250 90 270]; ... - [30 330 0 110 250 135 225 45 315 135 225];}; -audio_format.el(1,1:4) = {[0 0 0 0 0]; ... - [0 0 0 0 0 0 0]; ... - [0 0 0 0 0 45 45]; ... - [0 0 0 0 0 0 0 45 45 45 45];}; - - data_struct = struct.empty(1,0); - sr = [48000, 32000, 16000]; - sr_short = [48, 32, 16]; - sr_dft_size = [240, 160, 80]; - - H = hrtf_library_loader(); - H.readSOFA(char(fullfile(sofa_path, sofa_file_name))); - -Az = squeeze(H.PosSpherical(1,:)) * 180 / pi; -El = squeeze(H.PosSpherical(2,:)) * 180 / pi; - - -indexEl0 = find(El == 0); -indexEl45 = find(El == 42); - -indFmt= 1; - - azis = cell2mat(audio_format.az(indFmt)); - eles = cell2mat(audio_format.el(indFmt)); - -indexPos = []; - -for ind2 = 1 : length(azis) - if (eles(ind2) == 0) - index = find(abs(Az(indexEl0) - azis(ind2)) < 0.0001); - indexPos = [indexPos indexEl0(index)]; - else - index = find(abs(Az(indexEl45) - azis(ind2)) < 0.0001); - indexPos = [indexPos indexEl45(index)]; - end -end - -SourcePosition = [Az(indexPos); El(indexPos); ones(1,length(azis)) * 2 ]'; - - - % 48kHz - IRs_all = permute(H.get_Discrete_HRTFs(), [1,3,2]); - % IRs = IRs_all(:,:,indexPos) * H.Gain; - IRs = IRs_all * H.Gain; - HRTF_mdfts = m_dft(IRs, sr_dft_size(1)); - [left_avg_power, right_avg_power, ia_coherence] = compute_lr_energies_and_iac(HRTF_mdfts, sr_dft_size(1), 257); - - % 32 kHz - % TODO - - % 16 kHz - % TODO - - % - data_struct(1).lr_energies_iac_48kHz = [left_avg_power; right_avg_power; ia_coherence]; - data_struct(1).lr_energies_iac_32kHz = []; - data_struct(1).lr_energies_iac_16kHz = []; - data_struct(1).sr = sr; - data_struct(1).sr_short = sr_short; - data_struct(1).sr_dft_size = sr_dft_size; - -end \ No newline at end of file diff --git a/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/writeData3L.m b/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/writeData3L.m index 56f6a3908199218390dd514e44d74c12c0271146..ff9a2950dac562e18936f83d0c66d9125e05c16d 100644 --- a/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/writeData3L.m +++ b/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/writeData3L.m @@ -29,7 +29,7 @@ % the United Nations Convention on Contracts on the International Sales of Goods. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function writeData3L(fid_source, startstring, data) +function writeData3L(fid_source, startstring, floatformat, data) indices=size(data); indent = 4; @@ -50,7 +50,7 @@ for A = 1:indices(1) end counter=1; for C = 1:indices(3) - fprintf(fid_source,'%+ff',real(data(A,B,C))); + fprintf(fid_source,floatformat,real(data(A,B,C))); if C < indices(3) if mod(counter,10) == 0 fprintf(fid_source,','); diff --git a/scripts/binauralRenderer_interface/param_bin/generate_BRIR_in_SHD_CLDFB_PARAMETRIC.m b/scripts/binauralRenderer_interface/param_bin/generate_BRIR_in_SHD_CLDFB_PARAMETRIC.m index c9190516bd909c3aa0d804c54b2cada1ef523b2b..17d76ed351df6b21a17392bc5478903f934eccb1 100644 --- a/scripts/binauralRenderer_interface/param_bin/generate_BRIR_in_SHD_CLDFB_PARAMETRIC.m +++ b/scripts/binauralRenderer_interface/param_bin/generate_BRIR_in_SHD_CLDFB_PARAMETRIC.m @@ -1,3 +1,4 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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., @@ -27,6 +28,8 @@ % 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 [T60, lateEnes, earlyEnes] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir_inputfile, SHhrtf) % diff --git a/scripts/binauralRenderer_interface/param_bin/generate_HRIR_in_SHD_CLDFB_PARAMETRIC.m b/scripts/binauralRenderer_interface/param_bin/generate_HRIR_in_SHD_CLDFB_PARAMETRIC.m index a6dd95a297ecfcef38b42083fdb20b966ed2dd3a..75b31a749f394a2dd16708df32a0c08a440ff57a 100644 --- a/scripts/binauralRenderer_interface/param_bin/generate_HRIR_in_SHD_CLDFB_PARAMETRIC.m +++ b/scripts/binauralRenderer_interface/param_bin/generate_HRIR_in_SHD_CLDFB_PARAMETRIC.m @@ -1,3 +1,4 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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., @@ -27,6 +28,7 @@ % 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 SHhrtf = generate_HRIR_in_SHD_CLDFB_PARAMETRIC(hrir_inputfile) % @@ -148,7 +150,7 @@ function FD = CLDFB(sig) % Modulate prototype by half bin, and scale to match C implementation proto = proto.*exp(-1j*[0.5:1:600]'/120*pi) / 0.75; numCh = size(sig, 2); - sig = sig(1:end-mod(size(sig),60), :); + sig = sig(1:end-mod(length(sig),60), :); FD = zeros(60, size(sig,1)/60, numCh); sig = [zeros(540, numCh); sig]; indices = [1:600]'; diff --git a/scripts/binauralRenderer_interface/param_bin/generate_tables_for_parametric_binauralizer.m b/scripts/binauralRenderer_interface/param_bin/generate_tables_for_parametric_binauralizer.m index ecea9035e9178d7984cc776da49edcf28ffd3d1d..bc14e5e6877673ee7ff3061dc5d12451ebed526e 100644 --- a/scripts/binauralRenderer_interface/param_bin/generate_tables_for_parametric_binauralizer.m +++ b/scripts/binauralRenderer_interface/param_bin/generate_tables_for_parametric_binauralizer.m @@ -1,3 +1,4 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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., @@ -27,6 +28,8 @@ % 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. % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % % Generate tables from given HRIRs and BRIRs for IVAS binaural renderers PARAMETRIC and FASTCONV @@ -51,6 +54,15 @@ end if ~exist("writeBinaryOutput",'var') writeBinaryOutput = true; end +if ~exist("generateCustomBinaryFile",'var') + generateCustomBinaryFile = false; +end +if ~exist("generateBinaryFile_fx",'var') + generateBinaryFile_fx = false; +end +if ~exist("generate_BE",'var') + generate_BE = true; +end if ~exist("rom_file",'var') rom_file = fullfile('.', 'ivas_rom_binauralRenderer.c'); end @@ -84,26 +96,60 @@ end disp('Processing HRIR for parametric renderer...'); SHhrtf = generate_HRIR_in_SHD_CLDFB_PARAMETRIC(hrir_file); +%% compute scaling factor and ste floating point precision to word32 +if generate_BE == false + [SHhrtf, factorQ_SHhrtf] = make_be_with_fx(SHhrtf,15); +end + if writeRomFileOutput - writeData3L(fid, 'const float hrtfShCoeffsRe[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', real(SHhrtf)); - writeData3L(fid, 'const float hrtfShCoeffsIm[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', imag(SHhrtf)); + if generate_BE + writeData3L(fid, 'const float hrtfShCoeffsRe[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]','%+ff', real(SHhrtf)); + writeData3L(fid, 'const float hrtfShCoeffsIm[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]','%+ff', imag(SHhrtf)); + else + writeData3L(fid, 'const uint32_t hrtfShCoeffsRe[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '0x%tx', real(SHhrtf)); + writeData3L(fid, 'const uint32_t hrtfShCoeffsIm[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]', '0x%tx',imag(SHhrtf)); + end end %% Generate C-code tables for RENDERER_BINAURAL_PARAMETRIC_ROOM (SHD) disp('Processing BRIR for parametric renderer...'); [T60, lateEnes, earlyEnes] = generate_BRIR_in_SHD_CLDFB_PARAMETRIC(brir_file, SHhrtf); +if generateCustomBinaryFile == true + T60 = T60 * 2; + lateEnes = lateEnes * 2; + earlyEnes = earlyEnes * 2; +end + +%% compute scaling factor and ste floating point precision to word32 +if generate_BE == false + [T60, factorQ_T60] = make_be_with_fx(T60,15); + [lateEnes, factorQ_lateEnes] = make_be_with_fx(lateEnes,15); + [earlyEnes, factorQ_earlyEnes] = make_be_with_fx(earlyEnes,15); +end if writeRomFileOutput % Write BRIR parameters to file - fprintf(fid, 'const float parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX] = {\n'); + if generate_BE + fprintf(fid, 'const float parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX] = {\n'); + else + fprintf(fid, 'const uint32_t parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX] = {\n'); + end for k = 1:60 if mod(k-1, 10)==0 fprintf(fid, ' '); end if k < 60 - fprintf(fid, '%ff,', T60(k)); + if generate_BE + fprintf(fid, '%+ff,', T60(k)); + else + fprintf(fid, '0x%tx,', T60(k)); + end else - fprintf(fid, '%ff\n};', T60(k)); + if generate_BE + fprintf(fid, '%+ff\n};', T60(k)); + else + fprintf(fid, '0x%tx\n};', T60(k)); + end end if k>1 && mod(k, 10)==0 fprintf(fid, '\n'); @@ -112,15 +158,27 @@ if writeRomFileOutput end end - fprintf(fid, '\n\nconst float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = {\n'); + if generate_BE + fprintf(fid, '\n\nconst float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = {\n'); + else + fprintf(fid, '\n\nconst uint32_t parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX] = {\n'); + end for k = 1:60 if mod(k-1, 10)==0 fprintf(fid,' '); end if k < 60 - fprintf(fid, '%ff,', lateEnes(k)); + if generate_BE + fprintf(fid, '%+ff,', lateEnes(k)); + else + fprintf(fid, '0x%tx,', lateEnes(k)); + end else - fprintf(fid, '%ff\n};', lateEnes(k)); + if generate_BE + fprintf(fid, '%+ff\n};', lateEnes(k)); + else + fprintf(fid, '0x%tx\n};', lateEnes(k)); + end end if k>1 && mod(k, 10)==0 fprintf(fid, '\n'); @@ -129,15 +187,27 @@ if writeRomFileOutput end end - fprintf(fid, '\n\nconst float parametricEarlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX] = {\n'); + if generate_BE + fprintf(fid, '\n\nconst float parametricEarlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX] = {\n'); + else + fprintf(fid, '\n\nconst uint32_t parametricEarlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX] = {\n'); + end for k = 1:60 if mod(k-1, 10)==0 fprintf(fid, ' '); end if k < 60 - fprintf(fid, '%ff,', earlyEnes(k)); + if generate_BE + fprintf(fid, '%+ff,', earlyEnes(k)); + else + fprintf(fid, '0x%tx,', earlyEnes(k)); + end else - fprintf(fid, '%ff\n};', earlyEnes(k)); + if generate_BE + fprintf(fid, '%+ff\n};', earlyEnes(k)); + else + fprintf(fid, '0x%tx\n};', earlyEnes(k)); + end end if k>1 && mod(k, 10)==0 fprintf(fid, '\n'); @@ -154,5 +224,8 @@ end %% if writeBinaryOutput write_parametric_binauralizer_binary_data(bin_file, SHhrtf, T60, lateEnes, earlyEnes); + if generateBinaryFile_fx + write_parametric_binauralizer_binary_data_fx(bin_file, SHhrtf, factorQ_SHhrtf, T60, factorQ_T60, lateEnes, factorQ_lateEnes,earlyEnes, factorQ_earlyEnes); + end %save('parambin_binary_rom.mat', 'SHhrtf', 'T60', 'lateEnes', 'earlyEnes'); % debug saving end diff --git a/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m b/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m index 27045b7a29e4c8d269a6b3b8e09fc913529da7a3..21c013120aa56957b1311a330feaba46aeca7ca6 100644 --- a/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m +++ b/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data.m @@ -1,3 +1,4 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % (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., @@ -27,6 +28,8 @@ % 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_parametric_binauralizer_binary_data(filename, SHhrtf, T60, late_enes, early_enes) % diff --git a/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data_fx.m b/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data_fx.m new file mode 100644 index 0000000000000000000000000000000000000000..cb3434500bdcac6a9be0ca6fb288ab83a094c076 --- /dev/null +++ b/scripts/binauralRenderer_interface/param_bin/write_parametric_binauralizer_binary_data_fx.m @@ -0,0 +1,113 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% (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_parametric_binauralizer_binary_data_fx(filename, SHhrtf, factorQ_SHhrtf, T60, factorQ_T60, late_enes, factorQ_lateEnes,early_enes, factorQ_earlyEnes) +% +% Writes HRIR & BRIR based data for parametric binauralizer into a binary file. +% +% write_parametric_binauralizer_binary_data(filename, SHhrtf, T60, late_enes, early_enes) +% +% filename : string +% name of the file to be written +% SHhrtf : array of shape (2, 16, 60) i.e., (BINAURAL_CHANNELS, HRTF_SH_CHANNELS, HRTF_NUM_BINS), complex-valued +% HRTF coefficients +% T60 : array of shape (60, 1), i.e., (CLDFB_NO_CHANNELS_MAX, 1), double +% late_enes : array of shape (1, 60), i.e., (1, CLDFB_NO_CHANNELS_MAX), double +% early_enes : array of shape (1, 60), i.e., (1, CLDFB_NO_CHANNELS_MAX), double +% +% +% Output file format: +% HRTFs +% HRTF_SH_CHANNELS => uint16_t +% HRTF_NUM_BINS => uint16_t +% hrtfShCoeffsRe => int16_t[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; +% hrtfShCoeffsIm => int16_t[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; +% +% BRIR-based reverb +% CLDFB_NO_CHANNELS_MAX => uint16_t +% parametricReverberationTimes => int16_t[CLDFB_NO_CHANNELS_MAX]; +% parametricReverberationEneCorrections => int16_t[CLDFB_NO_CHANNELS_MAX]; +% parametricEarlyPartEneCorrection => int16_t[CLDFB_NO_CHANNELS_MAX]; +% + +filename = [erase(filename,'.bin') '_fx.bin' ]; + +[f_id, err_msg] = fopen(filename, 'wb'); + +if f_id == -1 + error('Could not open file %s for writing. Error message:\n%s', filename, err_msg); +end + +% HRTFs +n_chnls_bin = 2; +hrtf_sh_channels = size(SHhrtf, 2); +hrtf_num_bins = size(SHhrtf, 3); + +fwrite(f_id, hrtf_sh_channels, 'uint16'); +fwrite(f_id, hrtf_num_bins, 'uint16'); + +SHhrtf = SHhrtf .* (2.^double(factorQ_SHhrtf)); +fwrite(f_id, factorQ_SHhrtf, 'uint16'); + +% hrtfShCoeffsRe +for bin_chnl_idx = 1:n_chnls_bin + for hrtf_chnl_idx = 1:hrtf_sh_channels + fwrite(f_id, real(SHhrtf(bin_chnl_idx, hrtf_chnl_idx, :)), 'int16'); % HRTF_NUM_BINS elements + end +end + +% hrtfShCoeffsIm +for bin_chnl_idx = 1:n_chnls_bin + for hrtf_chnl_idx = 1:hrtf_sh_channels + fwrite(f_id, imag(SHhrtf(bin_chnl_idx, hrtf_chnl_idx, :)), 'int16'); % HRTF_NUM_BINS elements + end +end + +% BRIR-based reverb +cldfb_no_channels_max = size(T60, 1); + +fwrite(f_id, cldfb_no_channels_max, 'uint16'); + +T60 = T60 .* (2.^double(factorQ_T60)); +fwrite(f_id, factorQ_T60, 'uint16'); +fwrite(f_id, int16(T60), 'int16'); % parametricReverberationTimes + +late_enes = late_enes .* (2.^double(factorQ_lateEnes)); +fwrite(f_id, factorQ_lateEnes, 'uint16'); +fwrite(f_id, int16(late_enes), 'int16'); % parametricReverberationEneCorrections + +early_enes = early_enes .* (2.^double(factorQ_earlyEnes)); +fwrite(f_id, factorQ_earlyEnes, 'uint16'); +fwrite(f_id, int16(early_enes), 'int16'); % parametricEarlyPartEneCorrection + +fclose(f_id); diff --git a/scripts/patch_code_headers.sh b/scripts/patch_code_headers.sh index 4705e684cb9aaff55b7375d3457e566f84b2bcea..4127c80acab4d2dbcbbdaf20473adab2a6766793 100755 --- a/scripts/patch_code_headers.sh +++ b/scripts/patch_code_headers.sh @@ -56,14 +56,23 @@ if [ $help -ne 0 ]; then fi +date="May 14, 2024" +version="IVAS-FL-2.0" + + # # C-Code # c_header_new=\ -'/*==================================================================================== - 3GPP TS26.258 May 14, 2024. IVAS Codec Version IVAS-FL-2.0 - ====================================================================================*/' +"/*==================================================================================== + 3GPP TS26.258 $date. IVAS Codec Version $version + ====================================================================================*/" + +matlab_header_new=\ +"% ==================================================================================== +% 3GPP TS26.258 $date. IVAS Codec Version $version +% ====================================================================================" #### @@ -139,8 +148,71 @@ rm -f $tmpfile # Patch Printout # -sed -i.bak -e "s/IVAS\ Codec\ Baseline/IVAS\ Codec\ Version\ IVAS-FL-2\.0/g" $WORKDIR/lib_com/disclaimer.c +sed -i.bak -e "s/IVAS\ Codec\ Baseline/IVAS\ Codec\ Version\ $version/g" $WORKDIR/lib_com/disclaimer.c + +# +# Patch Matlab Scripts +# +find $WORKDIR -name "*.m" -exec sed -i.bak -e "/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/,+31d" \{\} \; + +# add new header +tmpfile=`mktemp` +rm -f $tmpfile +touch $tmpfile +echo "$matlab_header_new" >> $tmpfile +find $WORKDIR -name "*.m" -exec sed -i.bak -e "1 e cat $tmpfile" \{\} \; +rm -f $tmpfile + + +# +# Patch Output of Matlab Scripts +# + +sed -i.bak -e "/\/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/,+30d" $WORKDIR/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/generate_rom_tables.m +sed -i.bak -e "/copyright_str\ =\ string[(]join[(]/a \ \ \ \ \'/*====================================================================================\'\n\ \ \ \ \'\ \ \ \ \ 3GPP\ TS26\.258\ $date\.\ IVAS\ Codec\ Version\ $version\'\n\ \ \ \ \'\ \ ====================================================================================*/\'" $WORKDIR/scripts/binauralRenderer_interface/matlab_hrir_generation_scripts/generate_rom_tables.m + +sed -i.bak -e "/\/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/,+30d" $WORKDIR/scripts/td_object_renderer/modeling_tool/Gen_Hrf_IVAS_Binary.m +sed -i.bak -e "/copyright_str\ =\ string[(]join[(]/a \ \ \ \ \'/*====================================================================================\'\n\ \ \ \ \'\ \ \ \ \ 3GPP\ TS26\.258\ $date\.\ IVAS\ Codec\ Version\ $version\'\n\ \ \ \ \'\ \ ====================================================================================*/\'" $WORKDIR/scripts/td_object_renderer/modeling_tool/Gen_Hrf_IVAS_Binary.m + + +# +# Patch header template for files generated by scripts +# + +truncate -s 0 $WORKDIR/scripts/binauralRenderer_interface/ivas_license_header.template +echo echo "$c_header_new" >> $WORKDIR/scripts/binauralRenderer_interface/ivas_license_header.template + + +# +# Various Readmes in scripts directory +# + +# C-style header +sed -i.bak -e "1,/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\//d" $WORKDIR/scripts/binauralRenderer_interface/Table_Format_Converter/tables_format_converter_readme.txt +sed -i.bak -e "1,/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\//d" $WORKDIR/scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt +# add new header +tmpfile=`mktemp` +rm -f $tmpfile +touch $tmpfile +echo "$c_header_new" >> $tmpfile +sed -i.bak -e "1 e cat $tmpfile" $WORKDIR/scripts/binauralRenderer_interface/Table_Format_Converter/tables_format_converter_readme.txt +sed -i.bak -e "1 e cat $tmpfile" $WORKDIR/scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt +rm -f $tmpfile + +# *.md-style header +sed -i.bak -e "1,/-->/d" $WORKDIR/scripts/binauralRenderer_interface/README.md +sed -i.bak -e "1,/-->/d" $WORKDIR/scripts/td_object_renderer/modeling_tool/README.md +# add new header +tmpfile=`mktemp` +rm -f $tmpfile +touch $tmpfile +echo '' >> $tmpfile +sed -i.bak -e "1 e cat $tmpfile" $WORKDIR/scripts/binauralRenderer_interface/README.md +sed -i.bak -e "1 e cat $tmpfile" $WORKDIR/scripts/td_object_renderer/modeling_tool/README.md +rm -f $tmpfile # # Remove License file diff --git a/scripts/prepare_delivery.sh b/scripts/prepare_delivery.sh index 2448445c146ff7d09b64bf79a3e767274d89e94f..ac93a91043c90ec4b741136373aba7bfcf6486bb 100755 --- a/scripts/prepare_delivery.sh +++ b/scripts/prepare_delivery.sh @@ -112,6 +112,11 @@ rm -f ${OUTDIR}/Workspace_msvc/lib_debug.vcxproj.bak rm -f ${OUTDIR}/lib_util/tsm_scale_file_reader.[ch] sed -i.bak -e "/lib_util\\\tsm_scale_file_reader.[ch]/d" ${OUTDIR}/Workspace_msvc/lib_util.vcxproj +# scripts for custom HRIR/BRIR ROM table/file generation +mkdir $OUTDIR/scripts +cp -R ${ROOT}/scripts/binauralRenderer_interface $OUTDIR/scripts +cp -R ${ROOT}/scripts/td_object_renderer $OUTDIR/scripts + # readme cp ${ROOT}/readme.txt ${OUTDIR} recode lat1..ibmpc ${OUTDIR}/readme.txt # unix2dos ... diff --git a/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_16kHz.bin b/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_16kHz.bin deleted file mode 100644 index ad94d8a930b76924dd1bf81d5ad740c2b85b8633..0000000000000000000000000000000000000000 --- a/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_16kHz.bin +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8bb531aa8b9c7d0ab5fbc90e183dc58886b2751ca831aae4088d3d244a6c424a -size 167368 diff --git a/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_32kHz.bin b/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_32kHz.bin deleted file mode 100644 index b0090299d11a794427878d37a859a1998fe6461b..0000000000000000000000000000000000000000 --- a/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_32kHz.bin +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4d23072cbae281edcf6cacd7d7099dfb6a28324b069e4572d868a16dc37ec41b -size 329048 diff --git a/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_48kHz.bin b/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_48kHz.bin deleted file mode 100644 index 08ecb4c98be61da868037beb44a65349100725f1..0000000000000000000000000000000000000000 --- a/scripts/td_object_renderer/hrtf_data/IVAS_default/hrfilter_model_v003_48kHz.bin +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:65a57c54ef0f5d5affb6e2a785a0570511baea3426acb0486a9cae2fbfc95370 -size 486968 diff --git a/scripts/td_object_renderer/modeling_tool/Gen_Hrf_IVAS_Binary.m b/scripts/td_object_renderer/modeling_tool/Gen_Hrf_IVAS_Binary.m index 660cedafd8a8377cc59af372abad23292b95c331..d25700ad76b7793a8867114d015bb4efb0099adc 100644 --- a/scripts/td_object_renderer/modeling_tool/Gen_Hrf_IVAS_Binary.m +++ b/scripts/td_object_renderer/modeling_tool/Gen_Hrf_IVAS_Binary.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 Gen_Hrf_IVAS_Binary(dataSpec, modSpec, info) diff --git a/scripts/td_object_renderer/modeling_tool/HrfModBsp_Config.m b/scripts/td_object_renderer/modeling_tool/HrfModBsp_Config.m index 87eb2a4bb8f9f43c44699ce500944826a61817a7..cef47b278626a714fbd44418ec4c986d5d28692e 100644 --- a/scripts/td_object_renderer/modeling_tool/HrfModBsp_Config.m +++ b/scripts/td_object_renderer/modeling_tool/HrfModBsp_Config.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 [dataSpec, modSpec] = HrfModBsp_Config(dataSpec) %% HRF directory diff --git a/scripts/td_object_renderer/modeling_tool/HrfModBsp_InitPath.m b/scripts/td_object_renderer/modeling_tool/HrfModBsp_InitPath.m index 2f604d4ef032768648922c6bf62bc7efb7124222..2c3f621328176822bdde9fefc56ef453ddc81e53 100644 --- a/scripts/td_object_renderer/modeling_tool/HrfModBsp_InitPath.m +++ b/scripts/td_object_renderer/modeling_tool/HrfModBsp_InitPath.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 HrfModBsp_InitPath(dataSpec) % Initialize Matlab paths diff --git a/scripts/td_object_renderer/modeling_tool/Mod_Hrf_Itd_Main.m b/scripts/td_object_renderer/modeling_tool/Mod_Hrf_Itd_Main.m index ad84430e3808913efc2e64856b250558f56f4a2d..534a438a2911a3488b70d8768ae1c3bb9716c410 100644 --- a/scripts/td_object_renderer/modeling_tool/Mod_Hrf_Itd_Main.m +++ b/scripts/td_object_renderer/modeling_tool/Mod_Hrf_Itd_Main.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 Mod_Hrf_Itd_Main( varargin ) clc diff --git a/scripts/td_object_renderer/modeling_tool/evaluation/HrfModBspTdFir_InterpHrf.m b/scripts/td_object_renderer/modeling_tool/evaluation/HrfModBspTdFir_InterpHrf.m index 2e69140c492ebeb18f63b385ffc5c43dd010d3a7..fc708e7c8d26e9e370714662d9f08df3eb9a60ec 100644 --- a/scripts/td_object_renderer/modeling_tool/evaluation/HrfModBspTdFir_InterpHrf.m +++ b/scripts/td_object_renderer/modeling_tool/evaluation/HrfModBspTdFir_InterpHrf.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 hrfHat = HrfModBspTdFir_InterpHrf(interp, elev, azim) diff --git a/scripts/td_object_renderer/modeling_tool/evaluation/evaluation_BspTdFir.m b/scripts/td_object_renderer/modeling_tool/evaluation/evaluation_BspTdFir.m index 5b1c068d1bb056998e3d6121c57d67689a59307a..8faa413e5e9c14d9a6bdffcfa29581dc487c7a2b 100644 --- a/scripts/td_object_renderer/modeling_tool/evaluation/evaluation_BspTdFir.m +++ b/scripts/td_object_renderer/modeling_tool/evaluation/evaluation_BspTdFir.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% classdef evaluation_BspTdFir < handle diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngCircFun.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngCircFun.m index 50c364b1b98981303b0e0cd713c765a27bb79d4d..5f113c48915e8c88083abc842e9dcb3ae03b6c63 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngCircFun.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngCircFun.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 [Bf, kmSeq] = BSplineAngCircFun( P, kSeq ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngFun.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngFun.m index 847e20047e44cf63f66472c64c8bbec44aa6ddb7..d831c54d7d2ac61bbc0d65ada31bcdbe52187a8b 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngFun.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineAngFun.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 [Bf, kmSeq] = BSplineAngFun( P, kSeq ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineFunc.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineFunc.m index 6a5e94f7370ec491dafa0cea6882bb6fa9af37f5..9755423b77fa897ff8141f2e72168caacb86b582 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineFunc.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineFunc.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 Bf = BSplineFunc( P, kmSeq ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineItdFun.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineItdFun.m index 5e48ec60c68ab9aca61c626449743e09919f3baf..3f72fe33aa114bfc3fbd88655db0d622c6097caf 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineItdFun.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineItdFun.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 [Bf, kmSeq] = BSplineItdFun( P, kSeq ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_HrfInterpTdFir.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_HrfInterpTdFir.m index 63eb1b4ffdacb4fe028c6f69ce05458d6f0e5a40..30f866fa5be8ebf731fa6a4798f2ce1ee197cc41 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_HrfInterpTdFir.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_HrfInterpTdFir.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 interp = BSplineLSMod_HrfInterpTdFir( dat, mod, interp, flag ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_ItdInterpTdFir.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_ItdInterpTdFir.m index 5722bb0e0b1a0c726f893f19dd27f270f7512949..7917b4b53130dd19b447e622a4b128680ad3d59c 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_ItdInterpTdFir.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineLSMod_ItdInterpTdFir.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 interp = BSplineLSMod_ItdInterpTdFir( dat, mod, interp ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineRemoveZeroBasis.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineRemoveZeroBasis.m index d39e02e66ac6bfc449a25ddfbf449c52888f1689..20b7b2aecbd17464d1ed0db3a5913d84714246fe 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineRemoveZeroBasis.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineRemoveZeroBasis.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 Bf = BSplineRemoveZeroBasis( Bf ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampMat.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampMat.m index 01598215e51bc2ca3b0b4425b4b0e8e345b97975..658d30c78022e6b262002f5529c1f98d1bc276cf 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampMat.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampMat.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 BfMat = BSplineSampMat( Bf, kmSeq, sampVec) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVec.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVec.m index 9a4e519e57b90de984d22523f2e9e547ea1c5caf..d7c0c604c3efb5b95c3667b0cd9e68bf080aa01f 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVec.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVec.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 BfVec = BSplineSampVec( Bf, kmSeq, t) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVecITD.m b/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVecITD.m index 67717ada325a4c0206b2fb721c7c10489f0b401f..b46f4a6f8b95a79c8aa48b490ca847a597bdc1da 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVecITD.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/BSplineSampVecITD.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 BfVec = BSplineSampVecITD( Bf, kmSeq, t) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/Mod_Hrf_Itd.m b/scripts/td_object_renderer/modeling_tool/modeling/Mod_Hrf_Itd.m index fbeefcc30b79de16d3b9d0b72f86b76a39573555..decd39cb0586cd00c4d1b104c7e1abb18ef2dc24 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/Mod_Hrf_Itd.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/Mod_Hrf_Itd.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 [mod, evalHrf, info] = Mod_Hrf_Itd(dataSpec, modSpec) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/SplitAngleData.m b/scripts/td_object_renderer/modeling_tool/modeling/SplitAngleData.m index 58c0c971bc5fa2657c9f6810c51ed65159e1a471..9d997896ef56f38001a79ef3797afd974a76ca99 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/SplitAngleData.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/SplitAngleData.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 split = SplitAngleData( trainSetSpec, dat ) diff --git a/scripts/td_object_renderer/modeling_tool/modeling/frac_delay.m b/scripts/td_object_renderer/modeling_tool/modeling/frac_delay.m index ced912f83f3b85eba7630b4825d34d0034978335..6f473926015d8186266e9b8c8ee25a2dbd9572bd 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/frac_delay.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/frac_delay.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 y = frac_delay(x,d,out_len,h_len) % Fractional delay diff --git a/scripts/td_object_renderer/modeling_tool/modeling/modeling_BspTdFir.m b/scripts/td_object_renderer/modeling_tool/modeling/modeling_BspTdFir.m index 3a39357c3a52b1f904d5e430cfa731d84ec058d2..71a91ccd0c8415e3165b43aa54b493bd73ff83b1 100644 --- a/scripts/td_object_renderer/modeling_tool/modeling/modeling_BspTdFir.m +++ b/scripts/td_object_renderer/modeling_tool/modeling/modeling_BspTdFir.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% classdef modeling_BspTdFir < handle % MODELING creates a modeling object which can be used to diff --git a/scripts/td_object_renderer/modeling_tool/preprocessing/EstDelay.m b/scripts/td_object_renderer/modeling_tool/preprocessing/EstDelay.m index d31b89c617e7872aa8c2f4cc51ba6d1a62c8decf..e6344345d4623d21d1cceb5f531cb6179a307bab 100644 --- a/scripts/td_object_renderer/modeling_tool/preprocessing/EstDelay.m +++ b/scripts/td_object_renderer/modeling_tool/preprocessing/EstDelay.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 delay = EstDelay( left, right ) % Estimate delay diff --git a/scripts/td_object_renderer/modeling_tool/preprocessing/data_SOFA.m b/scripts/td_object_renderer/modeling_tool/preprocessing/data_SOFA.m index bf8763c943b9029d64f4db2ed316d2ff72f62227..974ccf2ab59795e420a7e790d0331ecf83b0c40a 100644 --- a/scripts/td_object_renderer/modeling_tool/preprocessing/data_SOFA.m +++ b/scripts/td_object_renderer/modeling_tool/preprocessing/data_SOFA.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% classdef data_SOFA < handle diff --git a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalElevAzimSet.m b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalElevAzimSet.m index 27b17bace094f186398b076682480ad21d669be8..536b8469aeaf9bc5c3abfc1ab45745f64ccb2545 100644 --- a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalElevAzimSet.m +++ b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalElevAzimSet.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 elevAzimSet = SpatArea_EvalElevAzimSet( elevSeq, azimSeq ) diff --git a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalInnProdWeights.m b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalInnProdWeights.m index 0a8ef73336ee13f1b8725e82d878b18a487696c5..a575bc4b5c0762f5da5f3a6928e6e34b9028d68a 100644 --- a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalInnProdWeights.m +++ b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalInnProdWeights.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 innProdWeightSet = SpatArea_EvalInnProdWeights( spatAreaSet, elevAzimSet ) diff --git a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSetDistr.m b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSetDistr.m index 568df7d4f5e3d6723d8458efe33ba6b590b73373..b1c7de874db7b9c372686dbcb2dc691221430328 100644 --- a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSetDistr.m +++ b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSetDistr.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 theSet = SpatArea_EvalSetDistr( theSet ) diff --git a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSpatArea.m b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSpatArea.m index 83bef9a543a8930a65cb417e6a421fefb0b602e2..34944091ee5e56a09cbd91acab49841a0e132b6a 100644 --- a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSpatArea.m +++ b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalSpatArea.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 spatAreaSet = SpatArea_EvalSpatArea( evalAzimSet ) diff --git a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalTrainTestSets.m b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalTrainTestSets.m index a85e3fc4c2ac24d9935d8c8ebb8b6593efafb825..01afbedba8c7e497b65bbfdb4f4ecea09eace038 100644 --- a/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalTrainTestSets.m +++ b/scripts/td_object_renderer/modeling_tool/spat_area/SpatArea_EvalTrainTestSets.m @@ -1,3 +1,5 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % (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, @@ -25,6 +27,8 @@ % 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 split = SpatArea_EvalTrainTestSets( split, spatAreaSet, ... elevAzimSet ) diff --git a/tests/hrtf_binary_loading/constants.py b/tests/hrtf_binary_loading/constants.py index 1524e9bf57edc72a71b434bde9c7245311c000a8..e0facd538c89101994374c0efcc67eb6cce5b1a4 100644 --- a/tests/hrtf_binary_loading/constants.py +++ b/tests/hrtf_binary_loading/constants.py @@ -51,11 +51,18 @@ DECODER_CMD = [str(TESTS_DIR.parent.parent.joinpath("IVAS_dec"))] RENDERER_CMD = [str(TESTS_DIR.parent.parent.joinpath("IVAS_rend"))] HRTF_BINARY_FILE_SAME_AS_ROM = "ivas_binaural_{}kHz.bin" +HRTF_BINARY_FILE_SAME_AS_ROM_FX = "ivas_binaural_fx_{}kHz.bin" HRTF_BINARY_FILE_DIFF_FROM_ROM = "ivas_binaural_51_brir-lc_{}kHz.bin" +HRTF_BINARY_FILE_DIFF_FROM_ROM_FX = "ivas_binaural_51_brir-lc_fx_{}kHz.bin" +# HRTF_FILES = [HRTF_BINARY_FILE_SAME_AS_ROM,HRTF_BINARY_FILE_SAME_AS_ROM_FX, HRTF_BINARY_FILE_DIFF_FROM_ROM, HRTF_BINARY_FILE_DIFF_FROM_ROM_FX] HRTF_FILES = [HRTF_BINARY_FILE_SAME_AS_ROM, HRTF_BINARY_FILE_DIFF_FROM_ROM] +DEFAULT_BIN_FILE_FX_FLAG = 0x1000 HRTF_TAG_SAME_AS_ROM = "hrtf_same_as_rom" +HRTF_TAG_SAME_AS_ROM_FX = "hrtf_same_as_rom_fx" HRTF_TAG_DIFF_FROM_ROM = "hrtf_diff_from_rom" +HRTF_TAG_DIFF_FROM_ROM_FX = "hrtf_diff_from_rom_fx" +# HRTF_TAGS = [HRTF_TAG_SAME_AS_ROM, HRTF_TAG_SAME_AS_ROM_FX, HRTF_TAG_DIFF_FROM_ROM, HRTF_TAG_DIFF_FROM_ROM_FX] HRTF_TAGS = [HRTF_TAG_SAME_AS_ROM, HRTF_TAG_DIFF_FROM_ROM] HRTF_FILE_FOR_TAG = dict(zip(HRTF_TAGS, HRTF_FILES)) @@ -162,6 +169,15 @@ with open( globals()[biace_c[biacid1 : biacid1 + biacid2]] = enumid enumid += 1 +# HRTF_READER_RENDERER_BINAURAL_INVALID = 0 +# HRTF_READER_RENDERER_BINAURAL_FASTCONV = 1 +# HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM = 2 +# HRTF_READER_RENDERER_BINAURAL_PARAMETRIC = 3 +# HRTF_READER_RENDERER_BINAURAL_OBJECTS_TD = 4 +# HRTF_READER_RENDERER_BINAURAL_MIXER_CONV = 5 +# HRTF_READER_RENDERER_BINAURAL_MIXER_CONV_ROOM = 6 +# HRTF_READER_RENDERER_BINAURAL_REVERB_ALL = 7 + HRTF_READER_RENDERER_BINAURAL_INVALID = 0 HRTF_READER_RENDERER_BINAURAL_FASTCONV = 1 HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM = 2 diff --git a/tests/hrtf_binary_loading/utils.py b/tests/hrtf_binary_loading/utils.py index c1b34c57cd14daf9ba57940c2e7cde5d7c8a2690..1d77e14b033e5a310cfa371978a30ba0fe359e38 100644 --- a/tests/hrtf_binary_loading/utils.py +++ b/tests/hrtf_binary_loading/utils.py @@ -187,6 +187,8 @@ def check_binary_file(hrtf_tag, out_fs): hrtf_header = binary_data[read_bid : read_bid + 16] renderer_type = int.from_bytes(hrtf_header[:4], byteorder="little") + if (renderer_type > DEFAULT_BIN_FILE_FX_FLAG): + renderer_type = renderer_type - DEFAULT_BIN_FILE_FX_FLAG input_configuration = int.from_bytes(hrtf_header[4:8], byteorder="little") sampling_frequency = int.from_bytes(hrtf_header[8:12], byteorder="little") raw_data_size = int.from_bytes(hrtf_header[12:16], byteorder="little") @@ -293,7 +295,7 @@ def compare_rom_vs_binary( hrtf_file = HRTF_FILE_FOR_TAG[hrtf_tag] - xfail = hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM + xfail = (hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM) or (hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM_FX) input_path = TESTV_DIR.joinpath(in_file).with_suffix(".wav") bitstream_path = BITSTREAM_DIR.joinpath(in_file + file_ext) @@ -349,7 +351,7 @@ def compare_renderer_vs_renderer_with_binary_hrir( keep_file=False, ): hrtf_file = HRTF_FILE_FOR_TAG[hrtf_tag] - xfail = hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM + xfail = (hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM) or (hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM_FX) hrtf_file_dir = SCRIPTS_DIR.joinpath( "binauralRenderer_interface/binaural_renderers_hrtf_data"