Commit 969f73f7 authored by emerit's avatar emerit
Browse files

fix optim cfg reader

parent c0644a75
Loading
Loading
Loading
Loading
+57 −62
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ static ivas_error read_txt_bool(
        return IVAS_ERR_INVALID_RENDER_CONFIG;
    }

    to_upper( value );
    if ( strcmp( value, "TRUE" ) == 0 )
    {
        *pTarget = TRUE;
@@ -83,13 +84,33 @@ static ivas_error read_txt_bool(
    return IVAS_ERR_INVALID_RENDER_CONFIG;
}

/*-----------------------------------------------------------------------------------------*
 * Function read_txt_float()
 * Reads a float value from a line
 *-----------------------------------------------------------------------------------------*/
static ivas_error read_txt_float(
    const char *pLine, /* i  : String to read from  */
    float *pTarget     /* o  : Output pointer       */
)
{
    float val = 0.f;
    if ( sscanf( pLine, "%f", &val ) != 1 )
    {
        return IVAS_ERR_INVALID_RENDER_CONFIG;
    }

    *pTarget = val;

    return IVAS_ERR_OK;
}

/*-----------------------------------------------------------------------------------------*
 * Function read_txt_vector()
 *
 * Reads a vector value from a line
 *-----------------------------------------------------------------------------------------*/

static int16_t read_txt_vector(
static ivas_error read_txt_vector(
    char *pLine,           /* i  : String to read from                */
    const uint32_t length, /* i  : Number of expected vector elements */
    float *pTarget         /* o  : Output vector pointer              */
@@ -102,7 +123,7 @@ static int16_t read_txt_vector(
    n = (int16_t) sscanf( pLine, "[%s", pLine );
    if ( n == 0 )
    {
        return 1;
        return IVAS_ERR_INVALID_RENDER_CONFIG;
    }

    /* Additional comma to make parsing easier */
@@ -120,7 +141,7 @@ static int16_t read_txt_vector(
    /* Check for maximum vector length */
    if ( n != length )
    {
        return 1;
        return IVAS_ERR_INVALID_RENDER_CONFIG;
    }

    for ( n = 0; n < count; n++ )
@@ -133,7 +154,7 @@ static int16_t read_txt_vector(
        tmp = strchr( tmp, ',' ) + 1;
    }

    return 0;
    return IVAS_ERR_OK;
}

/*-----------------------------------------------------------------------------------------*
@@ -201,7 +222,7 @@ static int32_t errorHandler(
 *------------------------------------------------------------------------------------------*/

ivas_error ConfigReader_read(
    const char *pConfigPath,         /* i  : Renderer configuration file path       */
    char *pConfigPath,               /* i  : Renderer configuration file path       */
    ConfigReaderHandle hRenderConfig /* o  : Renderer configuration handle          */
)
{
@@ -239,6 +260,19 @@ ivas_error ConfigReader_read(
    pParams = (char *) calloc( file_size + 1, sizeof( char ) );
    pTemp = (char *) calloc( file_size + 1, sizeof( char ) );

    hRenderConfig->optimize = 0;
    hRenderConfig->harmonizeLateReverbBinauralGain = 0;
    for ( idx = 0; idx < MAX_INTERN_CHANNELS; idx++ )
    {
        hRenderConfig->lateReverbCompensationGain[idx] = 1.f;
    }
    hRenderConfig->beginEnergyThreshold = DEFAULT_BEGIN_ENERGY_THRESHOLD;
    hRenderConfig->endEnergyThreshold = DEFAULT_END_ENERGY_THRESHOLD;
    hRenderConfig->directEnergyThreshold = DEFAULT_DIRECT_ENERGY_THRESHOLD;
    hRenderConfig->diffuseEnergyThreshold = DEFAULT_DIFFUSE_ENERGY_THRESHOLD;
    hRenderConfig->diffuseCutOffFreqThreshold = DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD;
    hRenderConfig->directCutOffFreqThreshold = DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD;

    /* read file line by line */
    while ( fgets( pConfig_str, file_size, pConfigFile ) != NULL )
    {
@@ -273,7 +307,7 @@ ivas_error ConfigReader_read(

            /* interpret params */
            pToken = strtok( chapter, ":" );
            if ( strcmp( chapter, "BRIR_OPTIMISATION_SETTING" ) == 0 && strlen( pParams ) != 0 )
            if ( strcmp( chapter, "BRIROPTIMISATIONSETTINGS" ) == 0 && strlen( pParams ) != 0 )
            {
                params_idx = 0;
                pValue = (char *) calloc( strlen( pParams ), sizeof( char ) );
@@ -287,114 +321,75 @@ ivas_error ConfigReader_read(
                    if ( strcmp( item, "OPTIMIZE" ) == 0 )
                    {
                        /* Read the number of directivity chapters */
                        if ( read_txt_bool( pValue, &hRenderConfig->harmonize_late_reverb_binaural_gain ) )
                        if ( read_txt_bool( pValue, &hRenderConfig->optimize ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->optimize = 0;
                        }
                    }
                    else if ( strcmp( item, "HARMONIZE_LATE_REVERB_BINAURAL_GAIN" ) == 0 )
                    else if ( strcmp( item, "HARMONIZELATEREVERBBINAURALGAIN" ) == 0 )
                    {
                        if ( read_txt_bool( pValue, &hRenderConfig->harmonize_late_reverb_binaural_gain ) )
                        if ( read_txt_bool( pValue, &hRenderConfig->harmonizeLateReverbBinauralGain ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->harmonize_late_reverb_binaural_gain = 0;
                    }
                    }
                    else if ( strcmp( item, "LATE_REVERB_COMPENSATION_GAIN" ) == 0 )
                    else if ( strcmp( item, "LATEREVERBCOMPENSATIONGAIN" ) == 0 )
                    {
                        if ( read_txt_vector( pValue, MAX_INTERN_CHANNELS, hRenderConfig->late_reverb_compensation_gain ) )
                        if ( read_txt_vector( pValue, MAX_INTERN_CHANNELS, hRenderConfig->lateReverbCompensationGain ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            for ( idx = 0; idx < MAX_INTERN_CHANNELS; idx++ )
                            {
                                hRenderConfig->late_reverb_compensation_gain[idx] = 1.f;
                            }
                        }
                    }
                    else if ( strcmp( item, "BEGIN_ENERGY_THRESHOLD" ) == 0 )
                    else if ( strcmp( item, "BEGINENERGYTHRESHOLD" ) == 0 )
                    {
                        if ( read_txt_vector( pValue, 1, &hRenderConfig->begin_energy_threshold ) )
                        if ( read_txt_float( pValue, &( hRenderConfig->beginEnergyThreshold ) ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->begin_energy_threshold = DEFAULT_BEGIN_ENERGY_THRESHOLD;
                    }
                    }
                    else if ( strcmp( item, "END_ENERGY_THRESHOLD" ) == 0 )
                    else if ( strcmp( item, "ENDENERGYTHRESHOLD" ) == 0 )
                    {
                        if ( read_txt_vector( pValue, 1, &hRenderConfig->end_energy_threshold ) )
                        if ( read_txt_float( pValue, &hRenderConfig->endEnergyThreshold ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->end_energy_threshold = DEFAULT_END_ENERGY_THRESHOLD;
                    }
                    }
                    else if ( strcmp( item, "DIRECT_ENERGY_THRESHOLD" ) == 0 )
                    else if ( strcmp( item, "DIRECTENERGYTHRESHOLD" ) == 0 )
                    {
                        if ( read_txt_vector( pValue, 1, &hRenderConfig->direct_energy_threshold ) )
                        if ( read_txt_float( pValue, &hRenderConfig->directEnergyThreshold ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->direct_energy_threshold = DEFAULT_DIRECT_ENERGY_THRESHOLD;
                        }
                    }
                    else if ( strcmp( item, "DIFFUSE_ENERGY_THRESHOLD" ) == 0 )
                    else if ( strcmp( item, "DIFFUSEENERGYTHRESHOLD" ) == 0 )
                    {
                        if ( read_txt_vector( pValue, 1, &hRenderConfig->diffuse_energy_threshold ) )
                        if ( read_txt_float( pValue, &hRenderConfig->diffuseEnergyThreshold ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->direct_energy_threshold = DEFAULT_DIFFUSE_ENERGY_THRESHOLD;
                        }
                    }
                    else if ( strcmp( item, "DIFFUSE_ENERGY_THRESHOLD" ) == 0 )
                    else if ( strcmp( item, "DIFFUSECUTOFFFREQTHRESHOLD" ) == 0 )
                    {
                        if ( read_txt_vector( pValue, 1, &hRenderConfig->diffuse_cut_off_freq_threshold ) )
                        if ( read_txt_float( pValue, &hRenderConfig->diffuseCutOffFreqThreshold ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->diffuse_cut_off_freq_threshold = DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD;
                        }
                    }
                    else if ( strcmp( item, "DIFFUSE_ENERGY_THRESHOLD" ) == 0 )
                    else if ( strcmp( item, "DIRECTCUTOFFFREQTHRESHOLD" ) == 0 )
                    {
                        if ( read_txt_vector( pValue, 1, &hRenderConfig->direct_cut_off_freq_threshold ) )
                        if ( read_txt_float( pValue, &hRenderConfig->directCutOffFreqThreshold ) != IVAS_ERR_OK )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                            return IVAS_ERR_INVALID_RENDER_CONFIG;
                        }
                        else
                        {
                            hRenderConfig->direct_cut_off_freq_threshold = DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD;
                        }
                    }
                }
                free( pValue );
+9 −9
Original line number Diff line number Diff line
@@ -47,14 +47,14 @@
typedef struct ConfigReader
{
    uint32_t optimize;                                     /* optimise HRIR/BRIR or not ie reduce renderer complexity */
    uint32_t harmonize_late_reverb_binaural_gain;             /* average left/right late reveberation energy or not */
    float late_reverb_compensation_gain[MAX_INTERN_CHANNELS]; /* user design additional compensation gain for late reverberation */
    float begin_energy_threshold;                             /* use to find beginning of HRIR/BRIR. ratio between HRIR/BRIR energy before begin sample and after begin sample is = BeginEnergyThld. Remove zero at the beginning of the HRIR */
    float end_energy_threshold;                               /* use to find end of HRIR. ratio between HRIR energy after end sample and before end sample is = EndEnergyThld. Remove zero at the end of the HRIR */
    float direct_energy_threshold;                            /* use to find the length direct and early part of HRIR/BRIR. ratio between HRIR/BRIR energy of diffuse part and complete HRIR/BRIR energy = BeginEnergyThld. Energy left in diffuse part */
    float diffuse_energy_threshold;                           /* use to find the length diffuse part of HRIR/BRIR. Energy removed at the end of the diffuse part = DiffuseEnergyThld of total energy of whole diffuse part */
    float diffuse_cut_off_freq_threshold;                     /* thresold to determine the cut off frequency for each slice of the diffuse IR*/
    float direct_cut_off_freq_threshold;                      /* thresold to determine the cut off frequency for each slice of the Direct of IR*/
    uint32_t harmonizeLateReverbBinauralGain;              /* average left/right late reveberation energy or not */
    float lateReverbCompensationGain[MAX_INTERN_CHANNELS]; /* user design additional compensation gain for late reverberation */
    float beginEnergyThreshold;                            /* use to find beginning of HRIR/BRIR. ratio between HRIR/BRIR energy before begin sample and after begin sample is = BeginEnergyThld. Remove zero at the beginning of the HRIR */
    float endEnergyThreshold;                              /* use to find end of HRIR. ratio between HRIR energy after end sample and before end sample is = EndEnergyThld. Remove zero at the end of the HRIR */
    float directEnergyThreshold;                           /* use to find the length direct and early part of HRIR/BRIR. ratio between HRIR/BRIR energy of diffuse part and complete HRIR/BRIR energy = BeginEnergyThld. Energy left in diffuse part */
    float diffuseEnergyThreshold;                          /* use to find the length diffuse part of HRIR/BRIR. Energy removed at the end of the diffuse part = DiffuseEnergyThld of total energy of whole diffuse part */
    float diffuseCutOffFreqThreshold;                      /* thresold to determine the cut off frequency for each slice of the diffuse IR*/
    float directCutOffFreqThreshold;                       /* thresold to determine the cut off frequency for each slice of the Direct of IR*/

} ConfigReader, *ConfigReaderHandle;

+9 −9
Original line number Diff line number Diff line
@@ -324,17 +324,17 @@ int main( int argc, char *argv[] )
    char *sofa_name = NULL;

    int i;
    cfgBrirOptim.begin_energy_threshold = DEFAULT_BEGIN_ENERGY_THRESHOLD;
    cfgBrirOptim.diffuse_cut_off_freq_threshold = DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD;
    cfgBrirOptim.diffuse_energy_threshold = DEFAULT_DIFFUSE_ENERGY_THRESHOLD;
    cfgBrirOptim.direct_cut_off_freq_threshold = DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD;
    cfgBrirOptim.direct_energy_threshold = DEFAULT_DIRECT_ENERGY_THRESHOLD;
    cfgBrirOptim.end_energy_threshold = DEFAULT_END_ENERGY_THRESHOLD;
    cfgBrirOptim.harmonize_late_reverb_binaural_gain = 1;
    cfgBrirOptim.beginEnergyThreshold = DEFAULT_BEGIN_ENERGY_THRESHOLD;
    cfgBrirOptim.diffuseCutOffFreqThreshold = DEFAULT_DIFFUSE_CUT_OFF_FREQ_THRESHOLD;
    cfgBrirOptim.diffuseEnergyThreshold = DEFAULT_DIFFUSE_ENERGY_THRESHOLD;
    cfgBrirOptim.directCutOffFreqThreshold = DEFAULT_DIRECT_CUT_OFF_FREQ_THRESHOLD;
    cfgBrirOptim.directEnergyThreshold = DEFAULT_DIRECT_ENERGY_THRESHOLD;
    cfgBrirOptim.endEnergyThreshold = DEFAULT_END_ENERGY_THRESHOLD;
    cfgBrirOptim.harmonizeLateReverbBinauralGain = 1;
    cfgBrirOptim.optimize = 1;
    for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
    {
        cfgBrirOptim.late_reverb_compensation_gain[i] = 1.f;
        cfgBrirOptim.lateReverbCompensationGain[i] = 1.f;
    }

    i = 1;
@@ -414,7 +414,7 @@ int main( int argc, char *argv[] )
            }
            brir_optim_config_path = malloc( strlen( argv[i] ) + 1 );
            strcpy( brir_optim_config_path, argv[i] );
            if ( ConfigReader_read( brir_optim_config_path, &cfgBrirOptim ) == false )
            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();
+10 −20
Original line number Diff line number Diff line
@@ -290,10 +290,10 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params(

    if ( cfgReader != NULL )
    {
        BeginEnergyThld = cfgReader->begin_energy_threshold;
        EndEnergyThld = cfgReader->end_energy_threshold;
        DirectEnergyThld = cfgReader->direct_energy_threshold;
        DiffuseEnergyThld = cfgReader->diffuse_energy_threshold;
        BeginEnergyThld = cfgReader->beginEnergyThreshold;
        EndEnergyThld = cfgReader->endEnergyThreshold;
        DirectEnergyThld = cfgReader->directEnergyThreshold;
        DiffuseEnergyThld = cfgReader->directEnergyThreshold;
    }

    memset( indDirectMaxi, 0, sizeof( int32_t ) * MAX_INTERN_CHANNELS );
@@ -679,7 +679,6 @@ ivas_error ivas_crend_binaural_filter_design_compute_filters_params(
 *
 *   @return    0 if no error, 1 otherwise
 */
#ifdef FIX_INV_DIFFUSE_WEIGHT
ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(
    ivas_hrtf_t *pFirData,
    const int16_t frame_len,
@@ -688,15 +687,6 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(
    int32_t index_end,
    int32_t *max_ir_len,
    ConfigReader *cfgReader )
#else
ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(
    ivas_hrtf_t *pFirData,
    const int16_t frame_len,
    HRTFS_DATA *pParam,
    int32_t index_start,
    int32_t index_end,
    int32_t *max_ir_len )
#endif
{
    /* Parameters */
    float DiffuseFcThld = -20; /* thresold to determine the cut off frequency for each slice of the diffuse IR*/
@@ -723,8 +713,8 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(

    if ( cfgReader != NULL )
    {
        DiffuseFcThld = cfgReader->diffuse_cut_off_freq_threshold;
        DirectFcThld = cfgReader->direct_cut_off_freq_threshold;
        DiffuseFcThld = cfgReader->diffuseCutOffFreqThreshold;
        DirectFcThld = cfgReader->directCutOffFreqThreshold;
    }

    if ( pFirData->N <= frame_len )
@@ -1081,15 +1071,15 @@ ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr(
#ifdef FIX_INV_DIFFUSE_WEIGHT
                    if ( cfgReader != NULL )
                    {
                        if ( cfgReader->harmonize_late_reverb_binaural_gain )
                        if ( cfgReader->harmonizeLateReverbBinauralGain )
                        {
                            pParam->inv_diffuse_weight[0][i_chan] = cfgReader->late_reverb_compensation_gain[i_chan] * 2.f / ( ppDiffuseWeight[i_chan][0] + ppDiffuseWeight[i_chan][1] );
                            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->late_reverb_compensation_gain[i_chan] * 1.f / ppDiffuseWeight[i_chan][0];
                            pParam->inv_diffuse_weight[1][i_chan] = cfgReader->late_reverb_compensation_gain[i_chan] * 1.f / ppDiffuseWeight[i_chan][1];
                            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
+0 −5
Original line number Diff line number Diff line
@@ -64,13 +64,8 @@ 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_set_hrtf_fr( HRTFS_DATA *crend_hrtf, ivas_hrtf_t *hrtf, const int16_t frame_len );

#ifdef FIX_INV_DIFFUSE_WEIGHT
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, HRTFS_DATA *pParam, int32_t index_start, int32_t index_end, int32_t *max_ir_len, ConfigReader *cfgReader );
#else
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 );
ivas_error ivas_crend_binaural_filter_design_set_hrtf_fr( ivas_hrtf_t *pFirData, const int16_t frame_len, HRTFS_DATA *pParam, int32_t index_start, int32_t index_end, int32_t *max_ir_len );
#endif

ivas_error ivas_hrtf_close( HRTFS_HANDLE hHRTF );

Loading