Commit 33470ef2 authored by emerit's avatar emerit
Browse files

remove bug, merge with step 2, improve code

parent 0ae13f71
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -715,7 +715,6 @@ int main(
#ifndef NONBE_FIX_BINARY_BINAURAL_READING
        IVAS_DEC_HRTF_HANDLE hHrtfTD = NULL;
#endif

        if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
@@ -730,11 +729,13 @@ int main(
#ifdef FIX_OLD_BINARY_FORMAT
                hrtfFileReader_close( &hrtfReader );
                strcat( arg.hrtfFileName, "new" );

                if ( hrtfFileReader_open( arg.hrtfFileName, &hrtfReader ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", arg.hrtfFileName );
                    goto cleanup;
                }

                if ( ( error = load_HRTF_binary( *hHrtfTD, hrtfReader ) ) != IVAS_ERR_OK )
                {
                    if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA )
@@ -785,7 +786,7 @@ int main(
#endif

#ifndef NONBE_FIX_BINARY_BINAURAL_READING
        IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF = NULL;
        IVAS_DEC_HRTF_CREND_HANDLE hSetOfHRTF = NULL;
#endif
        if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hSetOfHRTF ) ) != IVAS_ERR_OK )
        {
@@ -807,7 +808,7 @@ int main(
            }
        }
#else
        if ( ( error = create_SetOfHRTF_from_binary( *hSetOfHRTF, hrtfReader, arg.output_Fs ) ) != IVAS_ERR_OK )
        if ( ( error = create_SetOfHRTF_from_binary( hSetOfHRTF, hrtfReader, arg.output_Fs ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in loading HRTF binary file %s for CRend \n\n", arg.hrtfFileName );
            goto cleanup;
@@ -960,18 +961,14 @@ cleanup:
#ifdef NONBE_FIX_BINARY_BINAURAL_READING
        destroy_td_hrtf( hHrtfTD );
#else
        dealloc_HRTF_binary( *hHrtfTD );
        dealloc_HRTF_binary( hHrtfTD );
#endif

#ifndef NONBE_FIX_BINARY_BINAURAL_READING
        IVAS_DEC_HRTF_CREND_HANDLE hSetOfHRTF = NULL;
#endif
        IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hSetOfHRTF );
#ifdef NONBE_FIX_BINARY_BINAURAL_READING
        destroy_SetOfHRTF( hSetOfHRTF );
#else
        destroy_SetOfHRTF( *hSetOfHRTF );
#endif
    }

    IVAS_DEC_Close( &hIvasDec );
+1 −1
Original line number Diff line number Diff line
@@ -1031,7 +1031,7 @@ static ivas_error ivas_rend_initCrend(
    {
        if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
        {
            if ( hHrtf->inv_diffuse_weight[0][i] != hHrtf->inv_diffuse_weight[0][i] )
            if ( hHrtf->inv_diffuse_weight[0][i] != hHrtf->inv_diffuse_weight[1][i] )
            {
                hHrtf->same_inv_diffuse_weight = 0;
            }
+64 −41
Original line number Diff line number Diff line
@@ -670,7 +670,11 @@ static ivas_error load_reverb_from_binary(
    }
    else
    {
        set_default_reverb_iac_energy( HrFiltSet_p );
        if ( ( error = set_default_reverb_iac_energy( HrFiltSet_p ) ) != IVAS_ERR_OK )
        {
            return error;
        }

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
        return IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA;
#else
@@ -712,7 +716,9 @@ static ivas_error TDREND_MIX_LoadHRTF(
)
{
    int16_t tmp;
#ifndef NONBE_FIX_BINARY_BINAURAL_READING
    ivas_error error;
#endif
    bool is_tdrend;
    ivas_error header_check_result;
    ivas_hrtfs_file_header_t hrtfs_file_header;
@@ -721,33 +727,34 @@ static ivas_error TDREND_MIX_LoadHRTF(
    int32_t hrtf_data_size_max;
    char *hrtf_data;

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
    header_check_result = IVAS_ERR_OK;
#else
    error = IVAS_ERR_OK;
#endif

    if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK )
    {
#ifdef NONBE_FIX_BINARY_BINAURAL_READING
        error = header_check_result;

        /* try if it is old format for BE tests*/
        fseek( f_hrtf, 0, SEEK_SET );
        if ( fread( &tmp, 1, sizeof( int16_t ), f_hrtf ) == 0 )
        {
            error = IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" );
            header_check_result = IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" );
        }

        HrFiltSet_p->FilterMethod = (TDREND_HRFILT_Method_t) tmp;

        if ( HrFiltSet_p->FilterMethod != TDREND_HRFILT_Method_BSplineModel )
        {
            error = IVAS_ERROR( IVAS_ERR_INVALID_HRTF, "The HR filter set file is not a supported type." );
            header_check_result = IVAS_ERROR( IVAS_ERR_INVALID_HRTF, "The HR filter set file is not a supported type." );
        }
        else
        {
            error = LoadBSplineBinary( HrFiltSet_p, f_hrtf );
            header_check_result = LoadBSplineBinary( HrFiltSet_p, f_hrtf );
        }

        return error;
#else
        return header_check_result;
#endif
    }
@@ -807,11 +814,19 @@ static ivas_error TDREND_MIX_LoadHRTF(

        if ( HrFiltSet_p->FilterMethod != TDREND_HRFILT_Method_BSplineModel )
        {
#ifdef NONBE_FIX_BINARY_BINAURAL_READING
            header_check_result = IVAS_ERROR( IVAS_ERR_INVALID_HRTF, "The HR filter set file is not a supported type." );
#else
            error = IVAS_ERROR( IVAS_ERR_INVALID_HRTF, "The HR filter set file is not a supported type." );
#endif
        }
        else
        {
#ifdef NONBE_FIX_BINARY_BINAURAL_READING
            header_check_result = LoadBSplineBinary( HrFiltSet_p, f_hrtf );
#else
            error = LoadBSplineBinary( HrFiltSet_p, f_hrtf );
#endif
        }
    }
    else
@@ -822,8 +837,11 @@ static ivas_error TDREND_MIX_LoadHRTF(
        return IVAS_ERROR( IVAS_ERR_INVALID_HRTF, "HR filter not found in binary file." );
#endif
    }

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
    return header_check_result;
#else
    return error;
#endif
}


@@ -913,17 +931,15 @@ static void HRTF_energy_sections_precalc(
 * Deallocated memory allocated by load_HRTF_binary
 *---------------------------------------------------------------------*/

ivas_error destroy_td_hrtf(
void destroy_td_hrtf(
    IVAS_DEC_HRTF_HANDLE *hHrtf /* i/o: HRTF handle */
)
{
    int16_t i;
    ivas_error error;
    error = IVAS_ERR_OK;

    if ( ( hHrtf == NULL ) || ( *hHrtf == NULL ) )
    {
        return error;
        return;
    }

    if ( !( *hHrtf )->ModelParams.modelROM )
@@ -975,7 +991,7 @@ ivas_error destroy_td_hrtf(

    ivas_HRTF_binary_close( hHrtf );

    return error;
    return;
}
#else
/*---------------------------------------------------------------------*
@@ -1308,7 +1324,9 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
{
    int16_t i, j;
    char *hrtf_data_rptr;
#ifdef FIX_638_ENERGIE_IAC_ROM_TABLES
    ivas_error error;
#endif

    ( *hHRTF )->allocate_init_flag = 0;

@@ -1329,7 +1347,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    }
    else
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "render type not compliant" );
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" );
    }
#else
    ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, rend_type, ( *hHRTF )->allocate_init_flag );
@@ -1842,10 +1860,6 @@ static ivas_error create_parambin_HRTF_from_rawdata(
    memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) );
    hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( float );

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
    ( *hHRTF )->allocatedFromFile = 1;
#endif

    return IVAS_ERR_OK;
}

@@ -2078,7 +2092,11 @@ ivas_error create_SetOfHRTF_from_binary(
 * Destroy the HRTF CRend handle
 *---------------------------------------------------------------------*/

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
static void destroy_HRTF(
#else
static ivas_error destroy_HRTF(
#endif
    HRTFS_HANDLE *hHRTF /* i/o: HRTF CRend handle */
)
{
@@ -2128,9 +2146,14 @@ static ivas_error destroy_HRTF(
        *hHRTF = NULL;
    }

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
    return;
#else
    return IVAS_ERR_OK;
#endif
}


/*---------------------------------------------------------------------*
 * destroy_SetOfHRTF()
 *
@@ -2138,7 +2161,7 @@ static ivas_error destroy_HRTF(
 *---------------------------------------------------------------------*/

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
ivas_error destroy_SetOfHRTF(
void destroy_SetOfHRTF(
    HRTFS_CREND_HANDLE *hSetOfHRTF /* i/o: Set of HRTF CRend handle */
)
{
@@ -2150,36 +2173,20 @@ ivas_error destroy_SetOfHRTF(
        destroy_HRTF( &( ( *hSetOfHRTF )->hHRTF_hrir_foa ) );
        destroy_HRTF( &( ( *hSetOfHRTF )->hHRTF_brir_combined ) );
    }

    ivas_HRTF_CRend_binary_close( hSetOfHRTF );
    return IVAS_ERR_OK;
}
#else
ivas_error destroy_SetOfHRTF(
    HRTFS_CREND_HANDLE hSetOfHRTF /* i/o: Set of HRTF CRend handle              */
)
{
    if ( hSetOfHRTF != NULL )
    {
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_combined ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_hoa3 ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_hoa2 ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_foa ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_brir_combined ) );
    }

    return IVAS_ERR_OK;
    return;
}
#endif


#ifdef NONBE_FIX_BINARY_BINAURAL_READING
/*---------------------------------------------------------------------*
 * destroy_fastconv_hrtf()
 *
 * Destroy the HRTF data set.
 *---------------------------------------------------------------------*/

ivas_error destroy_fastconv_hrtf(
void destroy_fastconv_hrtf(
    IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv /* i/o: FastConv HRTF handle   */
)
{
@@ -2189,7 +2196,7 @@ ivas_error destroy_fastconv_hrtf(
    /* Fastconv HRTF filters */
    ivas_HRTF_fastconv_binary_close( hHrtfFastConv );

    return IVAS_ERR_OK;
    return;
}


@@ -2199,12 +2206,28 @@ ivas_error destroy_fastconv_hrtf(
 * Destroy the HRTF data set.
 *---------------------------------------------------------------------*/

ivas_error destroy_parambin_hrtf(
void destroy_parambin_hrtf(
    IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin /* i/o: Parambin HRTF handle   */
)
{
    ivas_HRTF_parambin_binary_close( hHrtfParambin );
    return IVAS_ERR_OK;

    return;
}
#else
ivas_error destroy_SetOfHRTF(
    HRTFS_CREND_HANDLE hSetOfHRTF /* i/o: Set of HRTF CRend handle              */
)
{
    if ( hSetOfHRTF != NULL )
    {
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_combined ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_hoa3 ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_hoa2 ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_hrir_foa ) );
        destroy_HRTF( &( hSetOfHRTF->hHRTF_brir_combined ) );
    }

    return IVAS_ERR_OK;
}
#endif
+5 −6
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ ivas_error create_SetOfHRTF_from_binary(
 *---------------------------------------------------------------------*/

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
ivas_error destroy_SetOfHRTF(
void destroy_SetOfHRTF(
    IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF /* i/o: Set of HRTF CRend handle              */
);
#else
@@ -153,7 +153,7 @@ ivas_error load_fastconv_HRTF_from_binary(
 * free memory allocated for FastConv HRTF binary data into the handle
 *---------------------------------------------------------------------*/

ivas_error destroy_fastconv_hrtf(
void destroy_fastconv_hrtf(
    IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv /* i/o: FastConv HRTF handle               */
);
#endif
@@ -177,21 +177,20 @@ ivas_error load_parambin_HRTF_from_binary(
 * free memory allocated for Parambin HRTF binary data into the handle
 *---------------------------------------------------------------------*/

ivas_error destroy_parambin_hrtf(
void destroy_parambin_hrtf(
    IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin /* i/o: Parambin HRTF handle               */
);
#endif

#ifdef NONBE_FIX_BINARY_BINAURAL_READING
/*---------------------------------------------------------------------*
 * destroy_td_hrtf()
 *
 * Destroy the HRTF TD handle
 *---------------------------------------------------------------------*/

ivas_error destroy_td_hrtf(
void destroy_td_hrtf(
    IVAS_DEC_HRTF_HANDLE *hHRTF /* i/o: HRTF handle */
);

#else
/*---------------------------------------------------------------------*
 * dealloc_HRTF_binary()
+26 −99
Original line number Diff line number Diff line
@@ -1070,10 +1070,6 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c
    fprintf( stderr, "Database: %s\n", sofaDataBaseName );
    fprintf( stderr, "Listener: %s\n", sofaListenerName );

    if ( lscfg.isloudspeaker && ( lscfg.nb_channel > 11 ) )
    {
        long nearest = 0;
    }
    /* get index to a position given in t (in spherical) */
    int *index_pos = (int *) malloc( sizeof( int ) * lscfg.nb_channel );
    uint32_t maxDel48kHz = 0;
@@ -1180,37 +1176,6 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c
        data_IR_current = sofa_data_IR_val_48k;
        sofa_N = sofa_N_48k;


        if ( sample_rates[indSR] != DEFAULT_SAMPLERATE )
        {
            char *file_path = (char *) malloc( sizeof( char ) * ( strlen( sofa_file_path ) + 1 ) );
            strcpy( file_path, sofa_file_path );
            char *fstr = strstr( file_path, "48000" );
            if ( fstr )
            {
                switch ( sample_rates[indSR] )
                {
                    case 32000:
                        strncpy( fstr, "32000", 5 );
                        break;
                    case 16000:
                        strncpy( fstr, "16000", 5 );
                        break;
                    default:
                        break;
                }
            }
            else
            {
                strcpy( file_path, "" );
            }
            FILE *fp = fopen( file_path, "rb" );
            if ( fp )
            {
                fclose( fp );
            }
            else
            {
        switch ( sample_rates[indSR] )
        {
            case 32000:
@@ -1226,10 +1191,6 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, ConfigReader *c
                sofa_N = sofa_N_48k;
                break;
        }
            }
            if ( file_path )
                free( file_path );
        }

        struct ivas_hrtf_t *ivas_hrtf = NULL;
        ivas_hrtf = malloc( sizeof( ivas_hrtf_t ) );
@@ -1835,36 +1796,6 @@ int generate_reverb_ivas_tables_from_sofa( const char *file_path )
        data_IR_current = sofa_data_IR_val_48k;
        sofa_N = sofa_N_48k;

        if ( sample_rates[indSR] != DEFAULT_SAMPLERATE )
        {
            char *file_path = (char *) malloc( sizeof( char ) * ( strlen( sofa_file_path ) + 1 ) );
            strcpy( file_path, sofa_file_path );
            char *fstr = strstr( file_path, "48000" );
            if ( fstr )
            {
                switch ( sample_rates[indSR] )
                {
                    case 32000:
                        strncpy( fstr, "32000", 5 );
                        break;
                    case 16000:
                        strncpy( fstr, "16000", 5 );
                        break;
                    default:
                        break;
                }
            }
            else
            {
                strcpy( file_path, "" );
            }
            FILE *fp = fopen( file_path, "rb" );
            if ( fp )
            {
                fclose( fp );
            }
            else
            {
        switch ( sample_rates[indSR] )
        {
            case 32000:
@@ -1880,10 +1811,6 @@ int generate_reverb_ivas_tables_from_sofa( const char *file_path )
                sofa_N = sofa_N_48k;
                break;
        }
            }
            if ( file_path )
                free( file_path );
        }

        if ( frame_len < sofa_N )
        {