Commit abad75ac authored by Devansh Kandpal's avatar Devansh Kandpal
Browse files

added function definitons in hrtf_file_reader.c

parent 0a5e6a0c
Loading
Loading
Loading
Loading
+75 −5
Original line number Diff line number Diff line
@@ -463,6 +463,7 @@ static ivas_error LoadBSplineBinary(
}

#ifdef FIX_638_ENERGIE_IAC_ROM_TABLES
#ifndef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
/*-------------------------------------------------------------------*
 * set_default_reverb_iac_energy()
 *
@@ -556,6 +557,7 @@ static ivas_error set_default_reverb_iac_energy(

    return IVAS_ERR_OK;
}
#endif

#ifdef FIX_638_ENERGIE_IAC_ROM_TABLES

@@ -566,11 +568,18 @@ static ivas_error set_default_reverb_iac_energy(
 --------------------------------------------------------------------*/

static ivas_error load_reverb_from_binary(
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    IVAS_DEC_HRTF_STATISTICS_HANDLE hHrtfStatistics, /* i/o: HRTF statistics handle          */
    int32_t sampleRate,                              /* i  : sample rate                     */
#else
    IVAS_DEC_HRTF_HANDLE HrFiltSet_p, /* i/o: HR filter model parameter structure */
#endif
    FILE *f_hrtf /* i  : HR filter data file handle          */
)
{
#ifndef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    int16_t i;
#endif
    bool is_reverb;
    ivas_error header_check_result;
    ivas_hrtfs_file_header_t hrtfs_file_header;
@@ -581,13 +590,21 @@ static ivas_error load_reverb_from_binary(
#ifdef NONBE_FIX_AVG_IAC_CLDFB_REVERB
    int16_t lr_iac_len;

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    if ( hHrtfStatistics == NULL )
#else
    if ( HrFiltSet_p == NULL )
#endif
	{
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    lr_iac_len = LR_IAC_LENGTH_NR_FC;
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    if ( sampleRate == 16000 )
#else
    if ( HrFiltSet_p->SampleRate == 16000 )
#endif    
	{
        lr_iac_len = LR_IAC_LENGTH_NR_FC_16KHZ;
    }
@@ -645,6 +662,21 @@ static ivas_error load_reverb_from_binary(

    if ( is_reverb )
    {
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
        hHrtfStatistics->average_energy_l = (float *) malloc( lr_iac_len * sizeof( float ) );
        hHrtfStatistics->average_energy_r = (float *) malloc( lr_iac_len * sizeof( float ) );
        hHrtfStatistics->inter_aural_coherence = (float *) malloc( lr_iac_len * sizeof( float ) );

        if ( hHrtfStatistics->average_energy_l == NULL || hHrtfStatistics->average_energy_r == NULL || hHrtfStatistics->inter_aural_coherence == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
        }
        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 );

        hHrtfStatistics->fromROM = FALSE;
#else
        /* left/right energy and interaural coherence for late reverb */
        for ( i = 0; i < 3; i++ )
        {
@@ -670,14 +702,17 @@ static ivas_error load_reverb_from_binary(
            HrFiltSet_p->lr_energy_and_iac[i] = (const float *) HrFiltSet_p->lr_energy_and_iac_dyn[i];
#endif
        }
#endif
    }
    else
    {
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
#else
        if ( ( header_check_result = set_default_reverb_iac_energy( HrFiltSet_p ) ) != IVAS_ERR_OK )
        {
            return header_check_result;
        }

#endif
        return IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA;
    }

@@ -692,13 +727,22 @@ static ivas_error load_reverb_from_binary(
 *---------------------------------------------------------------------*/

ivas_error load_reverb_binary(
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    IVAS_DEC_HRTF_STATISTICS_HANDLE hHrtfStatistics, /* i/o: HRTF statistics handle              */
    int32_t sampleRate,                              /* i  : sample rate                         */
#else
    IVAS_DEC_HRTF_HANDLE hHrtf, /* i/o: HRTF handle                         */
#endif
    const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle    */
)
{
    fseek( hrtfReader->file, 0, SEEK_SET );

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    return load_reverb_from_binary( hHrtfStatistics, sampleRate, hrtfReader->file );
#else
    return load_reverb_from_binary( hHrtf, hrtfReader->file );
#endif
}
#endif

@@ -954,10 +998,13 @@ void destroy_td_hrtf(
        free( ( *hHrtf )->ModelEval.hrfModL );
        free( ( *hHrtf )->ModelEval.hrfModR );


#ifndef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
        for ( i = 0; i < 3; i++ )
        {
            free( ( *hHrtf )->lr_energy_and_iac_dyn[i] );
        }
#endif
    }

    ivas_HRTF_binary_close( hHrtf );
@@ -2114,3 +2161,26 @@ void destroy_parambin_hrtf(

    return;
}


#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
/*---------------------------------------------------------------------*
 * destroy_hrtf_statistics()
 *
 * Destroy the HRTF statistics set.
 *---------------------------------------------------------------------*/

ivas_error destroy_hrtf_statistics(
    IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics /* i/o: HRTF statistics handle  */
)
{
    if ( hHrtfStatistics != NULL && ( *hHrtfStatistics )->fromROM == FALSE )
    {
        free( ( *hHrtfStatistics )->average_energy_l );
        free( ( *hHrtfStatistics )->average_energy_r );
        free( ( *hHrtfStatistics )->inter_aural_coherence );
    }
    ivas_HRTF_statistics_close( hHrtfStatistics );
    return IVAS_ERR_OK;
}
#endif