Skip to content
...@@ -104,6 +104,27 @@ static ivas_error read_txt_float( ...@@ -104,6 +104,27 @@ static ivas_error read_txt_float(
return IVAS_ERR_OK; return IVAS_ERR_OK;
} }
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
/*-----------------------------------------------------------------------------------------*
* Function read_txt_uint32()
* Reads a float value from a line
*-----------------------------------------------------------------------------------------*/
static ivas_error read_txt_int32(
const char *pLine, /* i : String to read from */
int32_t *pTarget /* o : Output pointer */
)
{
int32_t val = 0;
if ( sscanf( pLine, "%d", &val ) != 1 )
{
return IVAS_ERR_INVALID_RENDER_CONFIG;
}
*pTarget = val;
return IVAS_ERR_OK;
}
#endif
/*-----------------------------------------------------------------------------------------* /*-----------------------------------------------------------------------------------------*
* Function read_txt_vector() * Function read_txt_vector()
...@@ -273,6 +294,10 @@ ivas_error ConfigReader_read( ...@@ -273,6 +294,10 @@ ivas_error ConfigReader_read(
hRenderConfig->diffuseEnergyThreshold = DEFAULT_DIFFUSE_ENERGY_THRESHOLD; hRenderConfig->diffuseEnergyThreshold = DEFAULT_DIFFUSE_ENERGY_THRESHOLD;
hRenderConfig->diffuseCutOffFreqThreshold = DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD; hRenderConfig->diffuseCutOffFreqThreshold = DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD;
hRenderConfig->directCutOffFreqThreshold = DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD; hRenderConfig->directCutOffFreqThreshold = DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD;
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
hRenderConfig->maxNumDirectBlocks = DEFAULT_MAX_NUM_DIRECT_BLOCKS;
hRenderConfig->maxNumDiffuseBlocks = DEFAULT_MAX_NUM_DIFFUSE_BLOCKS;
#endif
/* read file line by line */ /* read file line by line */
while ( fgets( pConfig_str, file_size, pConfigFile ) != NULL ) while ( fgets( pConfig_str, file_size, pConfigFile ) != NULL )
{ {
...@@ -391,6 +416,24 @@ ivas_error ConfigReader_read( ...@@ -391,6 +416,24 @@ ivas_error ConfigReader_read(
return IVAS_ERR_INVALID_RENDER_CONFIG; return IVAS_ERR_INVALID_RENDER_CONFIG;
} }
} }
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
else if ( strcmp( item, "MAXNUMDIRECTBLOCKS" ) == 0 )
{
if ( read_txt_int32( pValue, &hRenderConfig->maxNumDirectBlocks ) != IVAS_ERR_OK )
{
errorHandler( item, ERROR_VALUE_INVALID );
return IVAS_ERR_INVALID_RENDER_CONFIG;
}
}
else if ( strcmp( item, "MAXNUMDIFFUSEBLOCKS" ) == 0 )
{
if ( read_txt_int32( pValue, &hRenderConfig->maxNumDiffuseBlocks ) != IVAS_ERR_OK )
{
errorHandler( item, ERROR_VALUE_INVALID );
return IVAS_ERR_INVALID_RENDER_CONFIG;
}
}
#endif
} }
free( pValue ); free( pValue );
} }
......
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
#define DEFAULT_DIFFUSE_ENERGY_THRESHOLD ( -25.f ) #define DEFAULT_DIFFUSE_ENERGY_THRESHOLD ( -25.f )
#define DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD ( -20.f ) #define DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD ( -20.f )
#define DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD ( -20.f ) #define DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD ( -20.f )
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
#define DEFAULT_MAX_NUM_DIRECT_BLOCKS ( 40 )
#define DEFAULT_MAX_NUM_DIFFUSE_BLOCKS ( 40 )
#endif
typedef struct ConfigReader typedef struct ConfigReader
...@@ -57,6 +61,10 @@ typedef struct ConfigReader ...@@ -57,6 +61,10 @@ typedef struct ConfigReader
float diffuseEnergyThreshold; /* use to find the time end limit of the diffuse part (te). diffuse part. It is a ratio in dB between diffuse part after te and complete diffuse HRIR/BRIR energies. The more the value is near zero the smallest is te, complexity decrease. */ float diffuseEnergyThreshold; /* use to find the time end limit of the diffuse part (te). diffuse part. It is a ratio in dB between diffuse part after te and complete diffuse HRIR/BRIR energies. The more the value is near zero the smallest is te, complexity decrease. */
float diffuseCutOffFreqThreshold; /* threshold in dB to determine the cut off (fcdiff) frequency for each slice of the diffuse IR. ratio in dB between the energy after fcdiff and the total energy. The more the value is near zero the smallest is fcdiff, complexity decrease */ float diffuseCutOffFreqThreshold; /* threshold in dB to determine the cut off (fcdiff) frequency for each slice of the diffuse IR. ratio in dB between the energy after fcdiff and the total energy. The more the value is near zero the smallest is fcdiff, complexity decrease */
float directCutOffFreqThreshold; /* threshold in dB to determine the cut off (fcdirect) frequency for each slice of the direct IR. Do not applied to first slice. ratio in dB between the energy after fcdirect and the total energy. The more the value is near zero the smallest is fcdirect, complexity decrease */ float directCutOffFreqThreshold; /* threshold in dB to determine the cut off (fcdirect) frequency for each slice of the direct IR. Do not applied to first slice. ratio in dB between the energy after fcdirect and the total energy. The more the value is near zero the smallest is fcdirect, complexity decrease */
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
int32_t maxNumDirectBlocks; /* max number of direct blocks */
int32_t maxNumDiffuseBlocks; /* max number of diffuse blocks */
#endif
} ConfigReader, *ConfigReaderHandle; } ConfigReader, *ConfigReaderHandle;
typedef enum typedef enum
......
...@@ -276,6 +276,10 @@ int main( int argc, char *argv[] ) ...@@ -276,6 +276,10 @@ int main( int argc, char *argv[] )
cfgBrirOptim.endEnergyThreshold = DEFAULT_END_ENERGY_THRESHOLD; cfgBrirOptim.endEnergyThreshold = DEFAULT_END_ENERGY_THRESHOLD;
cfgBrirOptim.harmonizeLateReverbBinauralGain = 1; cfgBrirOptim.harmonizeLateReverbBinauralGain = 1;
cfgBrirOptim.optimize = 1; cfgBrirOptim.optimize = 1;
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
cfgBrirOptim.maxNumDirectBlocks = DEFAULT_MAX_NUM_DIRECT_BLOCKS;
cfgBrirOptim.maxNumDiffuseBlocks = DEFAULT_MAX_NUM_DIFFUSE_BLOCKS;
#endif
for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
{ {
...@@ -345,6 +349,27 @@ int main( int argc, char *argv[] ) ...@@ -345,6 +349,27 @@ int main( int argc, char *argv[] )
strcpy( binary_common_file_name, argv[i] ); strcpy( binary_common_file_name, argv[i] );
i++; i++;
} }
#ifdef FIX_INV_DIFFUSE_WEIGHT
else if ( strcmp( to_upper( argv[i] ), "-BRIR_OPTIM_CONFIG_PATH" ) == 0 )
{
i++;
if ( strlen( argv[i] ) == 0 )
{
fprintf( stderr, "Wrong file path: %s\n\n", argv[i] );
usage_gen_crend_tables();
return -1;
}
brir_optim_config_path = malloc( strlen( argv[i] ) + 1 );
strcpy( brir_optim_config_path, argv[i] );
if ( ConfigReader_read( brir_optim_config_path, &cfgBrirOptim ) != IVAS_ERR_OK )
{
fprintf( stderr, "cannot read file : %s\n\n", argv[i] );
usage_gen_crend_tables();
return -1;
}
i++;
}
#endif
else if ( strcmp( to_upper( argv[i] ), "-ADD_DEFINE" ) == 0 ) else if ( strcmp( to_upper( argv[i] ), "-ADD_DEFINE" ) == 0 )
{ {
add_define = true; add_define = true;
...@@ -1118,6 +1143,9 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c ...@@ -1118,6 +1143,9 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c
{ {
uint16_t frame_len = L_FRAME48k; uint16_t frame_len = L_FRAME48k;
int32_t maxDel = maxDel48kHz * DEFAULT_SAMPLERATE / sample_rates[indSR]; int32_t maxDel = maxDel48kHz * DEFAULT_SAMPLERATE / sample_rates[indSR];
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
float mdft_scale_fact;
#endif
switch ( sample_rates[indSR] ) switch ( sample_rates[indSR] )
{ {
case 8000: case 8000:
...@@ -1134,9 +1162,15 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c ...@@ -1134,9 +1162,15 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c
frame_len = L_FRAME48k; frame_len = L_FRAME48k;
break; break;
} }
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
mdft_scale_fact = (float) L_FRAME48k / (float) frame_len;
#endif
if ( frame_len_ms == 5 ) if ( frame_len_ms == 5 )
{ {
frame_len = frame_len >> 2; frame_len = frame_len >> 2;
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
mdft_scale_fact = (float) ( L_FRAME48k * 0.25f ) / (float) frame_len;
#endif
} }
data_IR_current = sofa_data_IR_val_48k; data_IR_current = sofa_data_IR_val_48k;
...@@ -1252,11 +1286,19 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c ...@@ -1252,11 +1286,19 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c
{ {
ivas_crend_binaural_filter_design_compute_filters_params( ivas_hrtf, frame_len, &hrtf_data, &index_start, &index_end, &max_ir_len, cfgReader ); ivas_crend_binaural_filter_design_compute_filters_params( ivas_hrtf, frame_len, &hrtf_data, &index_start, &index_end, &max_ir_len, cfgReader );
ivas_crend_binaural_filter_design_set_hrtf_fr( ivas_hrtf, frame_len, ivas_crend_binaural_filter_design_set_hrtf_fr( ivas_hrtf, frame_len,
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
mdft_scale_fact,
#endif
&hrtf_data, index_start, index_end, &max_ir_len, cfgReader ); &hrtf_data, index_start, index_end, &max_ir_len, cfgReader );
} }
else else
{ {
ivas_set_hrtf_fr( &hrtf_data, ivas_hrtf, frame_len ); ivas_set_hrtf_fr( &hrtf_data, ivas_hrtf, frame_len
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
,
mdft_scale_fact
#endif
);
} }
hrtf_data.latency_s += 0.000000001f; hrtf_data.latency_s += 0.000000001f;
...@@ -2206,10 +2248,27 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int ...@@ -2206,10 +2248,27 @@ void update_c_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int
/* uint16_t index_frequency_max_diffuse; */ /* uint16_t index_frequency_max_diffuse; */
fprintf( fp, "\nconst uint16_t %s_%s_index_frequency_max_diffuse_%2dkHz = %d;", DECLARATION_NAME, lscfg.name, samplerate / 1000, hrtf->index_frequency_max_diffuse ); fprintf( fp, "\nconst uint16_t %s_%s_index_frequency_max_diffuse_%2dkHz = %d;", DECLARATION_NAME, lscfg.name, samplerate / 1000, hrtf->index_frequency_max_diffuse );
#ifdef FIX_INV_DIFFUSE_WEIGHT
/* float inv_diffuse_weight[BINAURAL_CHANNELS][MAX_INTERN_CHANNELS]; */
fprintf( fp, "\n#ifdef FIX_INV_DIFFUSE_WEIGHT" );
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 );
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 );
fprintf( fp, "}" );
fprintf( fp, ";" );
fprintf( fp, "\n#else" );
fprintf( fp, "\nconst float %s_%s_inv_diffuse_weight_%2dkHz[%s]=", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name );
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, ";" );
fprintf( fp, "\n#endif" );
#else
/* float inv_diffuse_weight[MAX_INTERN_CHANNELS]; */ /* float inv_diffuse_weight[MAX_INTERN_CHANNELS]; */
fprintf( fp, "\nconst float %s_%s_inv_diffuse_weight_%2dkHz[%s]=", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name ); fprintf( fp, "\nconst float %s_%s_inv_diffuse_weight_%2dkHz[%s]=", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name );
write_array_float_to_file( fp, hrtf->inv_diffuse_weight, 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, hrtf->max_num_ir, hrtf->max_num_ir, FORMAT_FLOAT, 0, TAB_WITH_SPACE_OR_NOT );
fprintf( fp, ";" ); fprintf( fp, ";" );
#endif
/* uint16_t *pIndex_frequency_max_diffuse[BINAURAL_CHANNELS];*/ /* uint16_t *pIndex_frequency_max_diffuse[BINAURAL_CHANNELS];*/
if ( hrtf->pIndex_frequency_max_diffuse[0] == NULL ) if ( hrtf->pIndex_frequency_max_diffuse[0] == NULL )
...@@ -2447,8 +2506,17 @@ void update_h_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int ...@@ -2447,8 +2506,17 @@ void update_h_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const int
/* uint16_t index_frequency_max_diffuse; */ /* uint16_t index_frequency_max_diffuse; */
fprintf( fp, "\nextern uint16_t %s_%s_index_frequency_max_diffuse_%2dkHz;", DECLARATION_NAME, lscfg.name, samplerate / 1000 ); fprintf( fp, "\nextern uint16_t %s_%s_index_frequency_max_diffuse_%2dkHz;", DECLARATION_NAME, lscfg.name, samplerate / 1000 );
#ifdef FIX_INV_DIFFUSE_WEIGHT
/* float inv_diffuse_weight[BINAURAL_CHANNELS][MAX_INTERN_CHANNELS]; */
fprintf( fp, "\n#ifdef FIX_INV_DIFFUSE_WEIGHT" );
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 );
fprintf( fp, "\n#else" );
fprintf( fp, "\nextern float %s_%s_inv_diffuse_weight_%2dkHz[%s];", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name );
fprintf( fp, "\n#endif" );
#else
/* float inv_diffuse_weight[MAX_INTERN_CHANNELS]; */ /* float inv_diffuse_weight[MAX_INTERN_CHANNELS]; */
fprintf( fp, "\nextern float %s_%s_inv_diffuse_weight_%2dkHz[%s];", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name ); fprintf( fp, "\nextern float %s_%s_inv_diffuse_weight_%2dkHz[%s];", DECLARATION_NAME, lscfg.name, samplerate / 1000, lscfg.output_config_num_channel_name );
#endif
/* uint16_t *pIndex_frequency_max_diffuse[BINAURAL_CHANNELS];*/ /* uint16_t *pIndex_frequency_max_diffuse[BINAURAL_CHANNELS];*/
if ( hrtf->pIndex_frequency_max_diffuse[0] == NULL ) if ( hrtf->pIndex_frequency_max_diffuse[0] == NULL )
{ {
...@@ -2583,7 +2651,11 @@ uint32_t compute_binary_size( HRTFS_DATA *hrtf, crend_hrtf_tables_dimensions *hr ...@@ -2583,7 +2651,11 @@ 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
#ifdef FIX_INV_DIFFUSE_WEIGHT
hrtf_data_size += hrtf->max_num_ir * sizeof( float ) * BINAURAL_CHANNELS; // inv_diffuse_weight
#else
hrtf_data_size += hrtf->max_num_ir * sizeof( float ); // inv_diffuse_weight hrtf_data_size += hrtf->max_num_ir * sizeof( float ); // inv_diffuse_weight
#endif
hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration hrtf_data_size += sizeof( uint16_t ); // max_total_num_fsamp_per_iteration
...@@ -2730,12 +2802,26 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const ...@@ -2730,12 +2802,26 @@ void write_binary_file( HRTFS_DATA *hrtf, struct ivas_layout_config lscfg, const
memcpy( hrtf_bin_wptr, &( hrtf->index_frequency_max_diffuse ), sizeof( uint16_t ) ); // index_frequency_max_diffuse memcpy( hrtf_bin_wptr, &( hrtf->index_frequency_max_diffuse ), sizeof( uint16_t ) ); // index_frequency_max_diffuse
hrtf_bin_wptr += sizeof( uint16_t ); hrtf_bin_wptr += sizeof( uint16_t );
#ifdef FIX_INV_DIFFUSE_WEIGHT
for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ )
{
sprintf( tmpStr, FORMAT_FLOAT, hrtf->inv_diffuse_weight[0][iIR] );
sscanf( tmpStr, "%f", &( (float *) hrtf_bin_wptr )[iIR] );
}
for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ )
{
sprintf( tmpStr, FORMAT_FLOAT, hrtf->inv_diffuse_weight[1][iIR] );
sscanf( tmpStr, "%f", &( (float *) hrtf_bin_wptr )[hrtf->max_num_ir + iIR] );
}
data_size_tmp = hrtf->max_num_ir * sizeof( float ) * BINAURAL_CHANNELS;
#else
for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ ) for ( iIR = 0; iIR < hrtf->max_num_ir; iIR++ )
{ {
sprintf( tmpStr, FORMAT_FLOAT, hrtf->inv_diffuse_weight[iIR] ); sprintf( tmpStr, FORMAT_FLOAT, hrtf->inv_diffuse_weight[iIR] );
sscanf( tmpStr, "%f", &( (float *) hrtf_bin_wptr )[iIR] ); sscanf( tmpStr, "%f", &( (float *) hrtf_bin_wptr )[iIR] );
} }
data_size_tmp = hrtf->max_num_ir * sizeof( float ); data_size_tmp = hrtf->max_num_ir * sizeof( float );
#endif
hrtf_bin_wptr += data_size_tmp; hrtf_bin_wptr += data_size_tmp;
memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_total_num_fsamp_per_iteration ), sizeof( uint16_t ) ); // max_total_num_fsamp_per_iteration memcpy( hrtf_bin_wptr, &( hrtf_table_dims.max_total_num_fsamp_per_iteration ), sizeof( uint16_t ) ); // max_total_num_fsamp_per_iteration
......
...@@ -146,7 +146,12 @@ static void printfAudioBufferOutFilterParams( ...@@ -146,7 +146,12 @@ static void printfAudioBufferOutFilterParams(
printf( "\nmax Diffuse Fc : %u", pParam->index_frequency_max_diffuse ); printf( "\nmax Diffuse Fc : %u", pParam->index_frequency_max_diffuse );
printf( "\n" ); printf( "\n" );
printf( "\nInverse Diffuse Weights :" ); printf( "\nInverse Diffuse Weights :" );
#ifdef FIX_INV_DIFFUSE_WEIGHT
printBuf_float32( pParam->inv_diffuse_weight[0], pParam->max_num_ir );
printBuf_float32( pParam->inv_diffuse_weight[1], pParam->max_num_ir );
#else
printBuf_float32( pParam->inv_diffuse_weight, pParam->max_num_ir ); printBuf_float32( pParam->inv_diffuse_weight, pParam->max_num_ir );
#endif
printf( "\n" ); printf( "\n" );
/*if (pParam->numDiffuseBlock > 0) /*if (pParam->numDiffuseBlock > 0)
...@@ -558,11 +563,20 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params( ...@@ -558,11 +563,20 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params(
{ {
pParam->num_iterations[i_chan][0]++; pParam->num_iterations[i_chan][0]++;
} }
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
/* max MAX_LENGTH_DIRECT_FILTER */
if ( pParam->num_iterations[i_chan][0] > cfgReader->maxNumDirectBlocks )
{
pParam->num_iterations[i_chan][0] = cfgReader->maxNumDirectBlocks;
}
pParam->num_iterations[i_chan][1] = pParam->num_iterations[i_chan][0];
#else
pParam->num_iterations[i_chan][1] = pParam->num_iterations[i_chan][0]; pParam->num_iterations[i_chan][1] = pParam->num_iterations[i_chan][0];
if ( pParam->num_iterations[i_chan][0] > IVAS_MAX_NUM_DIRECT_BLOCKS ) if ( pParam->num_iterations[i_chan][0] > IVAS_MAX_NUM_DIRECT_BLOCKS )
{ {
pParam->num_iterations[i_chan][0] = IVAS_MAX_NUM_DIRECT_BLOCKS; pParam->num_iterations[i_chan][0] = IVAS_MAX_NUM_DIRECT_BLOCKS;
} }
#endif
} }
pParam->max_num_iterations = 0; pParam->max_num_iterations = 0;
...@@ -652,10 +666,17 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params( ...@@ -652,10 +666,17 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params(
} }
/* max MAX_NUM_DIFFUSE_BLOCKS */ /* max MAX_NUM_DIFFUSE_BLOCKS */
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
if ( numDiffuseBlock > cfgReader->maxNumDiffuseBlocks )
{
numDiffuseBlock = cfgReader->maxNumDiffuseBlocks;
}
#else
if ( numDiffuseBlock > IVAS_MAX_NUM_DIFFUSE_BLOCKS ) if ( numDiffuseBlock > IVAS_MAX_NUM_DIFFUSE_BLOCKS )
{ {
numDiffuseBlock = IVAS_MAX_NUM_DIFFUSE_BLOCKS; numDiffuseBlock = IVAS_MAX_NUM_DIFFUSE_BLOCKS;
} }
#endif
for ( i_ear = 0; i_ear < 2; ++i_ear ) for ( i_ear = 0; i_ear < 2; ++i_ear )
{ {
...@@ -685,6 +706,9 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params( ...@@ -685,6 +706,9 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params(
ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(
ivas_hrtf_t *pFirData, ivas_hrtf_t *pFirData,
const int16_t frame_len, const int16_t frame_len,
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
float mdft_scale_fact,
#endif
HRTFS_DATA *pParam, HRTFS_DATA *pParam,
int32_t index_start, int32_t index_start,
int32_t index_end, int32_t index_end,
...@@ -712,7 +736,9 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( ...@@ -712,7 +736,9 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(
float ppEnergyDiffuseFilter[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS] = { { 0 } }; /* diffuse filter energies ( ppEnergyDiffuseFilter[ear][channel] ) */ float ppEnergyDiffuseFilter[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS] = { { 0 } }; /* diffuse filter energies ( ppEnergyDiffuseFilter[ear][channel] ) */
float ppDiffuseWeight[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS] = { { 0 } }; /* diffuse weights ( ppDiffuseWeight[ear][channel] ) */ float ppDiffuseWeight[MAX_INTERN_CHANNELS][BINAURAL_CHANNELS] = { { 0 } }; /* diffuse weights ( ppDiffuseWeight[ear][channel] ) */
float delayf; float delayf;
#ifndef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
float mdft_scale_fact = ( (float) L_FRAME48k * 0.25f ) / frame_len; float mdft_scale_fact = ( (float) L_FRAME48k * 0.25f ) / frame_len;
#endif
if ( cfgReader != NULL ) if ( cfgReader != NULL )
{ {
...@@ -1071,11 +1097,37 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( ...@@ -1071,11 +1097,37 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(
{ {
if ( ppDiffuseWeight[i_chan][0] != -1 && ppDiffuseWeight[i_chan][1] != -1 ) if ( ppDiffuseWeight[i_chan][0] != -1 && ppDiffuseWeight[i_chan][1] != -1 )
{ {
#ifdef FIX_INV_DIFFUSE_WEIGHT
if ( cfgReader != NULL )
{
if ( cfgReader->harmonizeLateReverbBinauralGain )
{
pParam->inv_diffuse_weight[0][i_chan] = cfgReader->lateReverbCompensationGain[i_chan] * 2.f / ( ppDiffuseWeight[i_chan][0] + ppDiffuseWeight[i_chan][1] );
pParam->inv_diffuse_weight[1][i_chan] = pParam->inv_diffuse_weight[0][i_chan];
}
else
{
pParam->inv_diffuse_weight[0][i_chan] = cfgReader->lateReverbCompensationGain[i_chan] * 1.f / ppDiffuseWeight[i_chan][0];
pParam->inv_diffuse_weight[1][i_chan] = cfgReader->lateReverbCompensationGain[i_chan] * 1.f / ppDiffuseWeight[i_chan][1];
}
}
else
{
pParam->inv_diffuse_weight[0][i_chan] = 2.f / ( ppDiffuseWeight[i_chan][0] + ppDiffuseWeight[i_chan][1] );
pParam->inv_diffuse_weight[1][i_chan] = pParam->inv_diffuse_weight[0][i_chan];
}
#else
pParam->inv_diffuse_weight[i_chan] = 2.f / ( ppDiffuseWeight[i_chan][0] + ppDiffuseWeight[i_chan][1] ); pParam->inv_diffuse_weight[i_chan] = 2.f / ( ppDiffuseWeight[i_chan][0] + ppDiffuseWeight[i_chan][1] );
#endif
} }
else else
{ {
#ifdef FIX_INV_DIFFUSE_WEIGHT
pParam->inv_diffuse_weight[0][i_chan] = 0; /* pathological case ppEnergyDiffuseFilter[i_ear][i_chan]=0 */
pParam->inv_diffuse_weight[1][i_chan] = 0; /* pathological case ppEnergyDiffuseFilter[i_ear][i_chan]=0 */
#else
pParam->inv_diffuse_weight[i_chan] = 0; /* pathological case ppEnergyDiffuseFilter[i_ear][i_chan]=0 */ pParam->inv_diffuse_weight[i_chan] = 0; /* pathological case ppEnergyDiffuseFilter[i_ear][i_chan]=0 */
#endif
} }
} }
...@@ -1285,13 +1337,19 @@ ivas_error ivas_set_hrtf_fr( ...@@ -1285,13 +1337,19 @@ ivas_error ivas_set_hrtf_fr(
HRTFS_DATA *crend_hrtf, HRTFS_DATA *crend_hrtf,
ivas_hrtf_t *hrtf, ivas_hrtf_t *hrtf,
const int16_t output_frame const int16_t output_frame
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
,
float mdft_scale_fact
#endif
) )
{ {
int32_t i, j, m, n; int32_t i, j, m, n;
float data_ir_flt[L_FRAME48k] = { 0.0f }; float data_ir_flt[L_FRAME48k] = { 0.0f };
int32_t tmp_ir_len, in_len, k; int32_t tmp_ir_len, in_len, k;
#ifndef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
float mdft_scale_fact = ( (float) L_FRAME48k * 0.25f ) / output_frame; float mdft_scale_fact = ( (float) L_FRAME48k * 0.25f ) / output_frame;
#endif
crend_hrtf->max_num_ir = (int16_t) hrtf->m; crend_hrtf->max_num_ir = (int16_t) hrtf->m;
......
...@@ -40,8 +40,10 @@ ...@@ -40,8 +40,10 @@
#define IVAS_SOFA_MAX_VAL_R ( 2 ) #define IVAS_SOFA_MAX_VAL_R ( 2 )
#define IVAS_SOFA_MAX_VAL_N ( 48000 ) #define IVAS_SOFA_MAX_VAL_N ( 48000 )
#define IVAS_SOFA_MAX_VAL_I ( 1 ) #define IVAS_SOFA_MAX_VAL_I ( 1 )
#ifndef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
#define IVAS_MAX_NUM_DIRECT_BLOCKS ( 40 ) /* max number of direct blocks */ #define IVAS_MAX_NUM_DIRECT_BLOCKS ( 40 ) /* max number of direct blocks */
#define IVAS_MAX_NUM_DIFFUSE_BLOCKS ( 40 ) /* max number of diffuse blocks */ #define IVAS_MAX_NUM_DIFFUSE_BLOCKS ( 40 ) /* max number of diffuse blocks */
#endif
#define IVAS_MAX_HRTF_LATENCY_MS ( 0.1 ) /* max hrtf latency */ #define IVAS_MAX_HRTF_LATENCY_MS ( 0.1 ) /* max hrtf latency */
typedef struct ivas_hrtf_t typedef struct ivas_hrtf_t
...@@ -61,10 +63,17 @@ typedef struct ivas_hrtf_t ...@@ -61,10 +63,17 @@ typedef struct ivas_hrtf_t
ivas_error ivas_get_hrtf_lens( ivas_hrtf_t *hrtf, HRTFS_DATA *crend_hrtf, const int16_t frame_len ); ivas_error ivas_get_hrtf_lens( ivas_hrtf_t *hrtf, HRTFS_DATA *crend_hrtf, const int16_t frame_len );
ivas_error ivas_set_hrtf_fr( HRTFS_DATA *crend_hrtf, ivas_hrtf_t *hrtf, const int16_t frame_len ivas_error ivas_set_hrtf_fr( HRTFS_DATA *crend_hrtf, ivas_hrtf_t *hrtf, const int16_t frame_len
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
,
float mdft_scale_fact
#endif
); );
ivas_error ivas_crend_binaural_filter_design_compute_filters_params( ivas_hrtf_t *pFirData, const int16_t framelen, HRTFS_DATA *pParam, int32_t *index_start, int32_t *index_end, int32_t *max_ir_len, ConfigReader *cfgReader ); ivas_error ivas_crend_binaural_filter_design_compute_filters_params( ivas_hrtf_t *pFirData, const int16_t framelen, HRTFS_DATA *pParam, int32_t *index_start, int32_t *index_end, int32_t *max_ir_len, ConfigReader *cfgReader );
ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( ivas_hrtf_t *pFirData, const int16_t frame_len, ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( ivas_hrtf_t *pFirData, const int16_t frame_len,
#ifdef FIX_20_MS_FRAME_LEN_TABLES_CONVERTER
float mdft_scale_fact,
#endif
HRTFS_DATA *pParam, HRTFS_DATA *pParam,
int32_t index_start, int32_t index_start,
int32_t index_end, int32_t index_end,
......