Commit 4746579c authored by multrus's avatar multrus
Browse files

[cleanup] accept USE_NEW_HRTF_BINARY_FILE_FORMAT

parent a4d9bca5
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -86,7 +86,6 @@

/* #################### Start BASOP porting switches ############################ */

#define USE_NEW_HRTF_BINARY_FILE_FORMAT                 /* Orange: to activate when decided to change the hrtf binary file format */
#define FIX_WARNING_RENDER_CONFIG                       /* Orange: fix warning on windows build */
#define FIX_1052_EXT_OUTPUT                             /* VA: issue 1052: define EXT decoder output configuration for stereo and MC formats */
#define NONBE_1215_FIX_JBM_MAX_SCALING                  /* FhG: issue 1215: Fix assert hit in a specific VoIP decoder config. Caused by integer overflow in max scaling calculation. */
+0 −116
Original line number Diff line number Diff line
@@ -191,7 +191,6 @@ static ivas_error check_hrtf_binary_header(
{
    /* Check the renderer type */

#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    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 ) &&
         ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM ) &&
@@ -199,15 +198,6 @@ static ivas_error check_hrtf_binary_header(
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Header of HRTF binary file not compliant (renderer type)" );
    }
#else
    if ( ( hrtf_header->rend_type != RENDERER_BINAURAL_MIXER_CONV ) && ( hrtf_header->rend_type != RENDERER_BINAURAL_MIXER_CONV_ROOM ) &&
         ( hrtf_header->rend_type != RENDERER_BINAURAL_FASTCONV ) && ( hrtf_header->rend_type != RENDERER_BINAURAL_FASTCONV_ROOM ) &&
         ( hrtf_header->rend_type != RENDERER_BINAURAL_PARAMETRIC ) && ( hrtf_header->rend_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) &&
         ( hrtf_header->rend_type != RENDERER_BINAURAL_OBJECTS_TD ) )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Header of HRTF binary file not compliant (renderer type)" );
    }
#endif
    /* Check the output format of the decoder */

    if ( ( hrtf_header->input_cfg != BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) && ( hrtf_header->input_cfg != BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) && ( hrtf_header->input_cfg != BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) && ( hrtf_header->input_cfg != BINAURAL_INPUT_AUDIO_CONFIG_FOA ) && ( hrtf_header->input_cfg != BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED ) )
@@ -361,9 +351,6 @@ static ivas_error LoadBSplineBinary(

    float f_tmp_latency_s;

#ifndef USE_NEW_HRTF_BINARY_FILE_FORMAT
    float f_tmp_lr_energy_and_iac_dyn[LR_IAC_LENGTH_NR_FC];
#endif

    fread( &f_tmp_latency_s, sizeof( float ), 1, f_hrtf );
    HrFiltSet_p->latency_s_fx = float_to_fix( f_tmp_latency_s, Q31 );
@@ -549,27 +536,6 @@ static ivas_error LoadBSplineBinary(
        LoadBSplineBinaryITD( &HrFiltSet_p->ModelParamsITD, f_hrtf );
    }

#ifndef USE_NEW_HRTF_BINARY_FILE_FORMAT
    /* left/right energy and interaural coherence for late reverb */
    FOR( i = 0; i < 3; i++ )
    {
        fread( f_tmp_lr_energy_and_iac_dyn, sizeof( const float ), LR_IAC_LENGTH_NR_FC, f_hrtf );
        HrFiltSet_p->lr_energy_and_iac_dyn_fx[i] = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) );
        if ( HrFiltSet_p->lr_energy_and_iac_dyn_fx[i] == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
        }
        IF( i == 2 )
        {
            floatToFixed_arr32( f_tmp_lr_energy_and_iac_dyn, HrFiltSet_p->lr_energy_and_iac_dyn_fx[i], Q27, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
        }
        ELSE
        {
            floatToFixed_arr32( f_tmp_lr_energy_and_iac_dyn, HrFiltSet_p->lr_energy_and_iac_dyn_fx[i], Q23, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q23 for i=0,1 */
        }
        HrFiltSet_p->lr_energy_and_iac_fx[i] = (const Word32 *) HrFiltSet_p->lr_energy_and_iac_dyn_fx[i];
    }
#endif

    return IVAS_ERR_OK;
}
@@ -645,11 +611,7 @@ static ivas_error load_reverb_from_binary(
            return header_check_result;
        }

#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
        is_reverb = ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_REVERB_ALL );
#else
        is_reverb = ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_REVERB_ALL );
#endif
        if ( !is_reverb )
        {
            if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size )
@@ -784,11 +746,7 @@ static ivas_error TDREND_MIX_LoadHRTF(
            return header_check_result;
        }

#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
        is_tdrend = ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_OBJECTS_TD );
#else
        is_tdrend = ( hrtf_header.rend_type == RENDERER_BINAURAL_OBJECTS_TD );
#endif
        if ( !is_tdrend )
        {
            if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size )
@@ -1095,7 +1053,6 @@ static ivas_error create_HRTF_from_rawdata(
    hrtf_data_rptr += sizeof( UWord16 );

    /* inv_diffuse_weight */
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ )
    {
        ( *hHRTF )->inv_diffuse_weight_fx[0][i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 );
@@ -1106,15 +1063,6 @@ static ivas_error create_HRTF_from_rawdata(
        ( *hHRTF )->inv_diffuse_weight_fx[1][i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 );
        hrtf_data_rptr += sizeof( float );
    }
#else
    /* inv_diffuse_weight */
    for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ )
    {
        ( *hHRTF )->inv_diffuse_weight_fx[0][i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 );
        ( *hHRTF )->inv_diffuse_weight_fx[1][i] = ( *hHRTF )->inv_diffuse_weight[0][i];
        hrtf_data_rptr += sizeof( float );
    }
#endif

    /* max_total_num_fsamp_per_iteration */
    max_total_num_fsamp_per_iteration = *( (UWord16 *) ( hrtf_data_rptr ) );
@@ -1259,11 +1207,7 @@ static ivas_error create_HRTF_from_rawdata(
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  */
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    HRTF_READER_RENDERER_TYPE rend_type, /* i  : Renderer type           */
#else
    RENDERER_TYPE rend_type, /* i  : Renderer type           */
#endif
    BINAURAL_INPUT_AUDIO_CONFIG input_cfg /* i  : Input binaural config   */
)
{
@@ -1273,13 +1217,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    float f_tmp_ntaps_max[BINAURAL_NTAPS_MAX];
    float f_tmp_brir_reverb[CLDFB_NO_CHANNELS_MAX];
    char *hrtf_data_rptr;
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    ivas_error error;
#endif

    ( *hHRTF )->allocate_init_flag = 0;

#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV )
    {
        if ( ( error = ivas_allocate_binaural_hrtf_fx( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK )
@@ -1298,38 +1239,21 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" );
    }
#else
    ivas_allocate_binaural_hrtf_fx( *hHRTF, 0, input_cfg, rend_type, ( *hHRTF )->allocate_init_flag );
#endif

    hrtf_data_rptr = hrtf_data;

#if !defined USE_NEW_HRTF_BINARY_FILE_FORMAT
    /* BINAURAL_CONVBANDS */
    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 );
#endif

/* HRIR */
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
#else
    if ( rend_type == RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
#endif
    {
        f_tmp = *( (float *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( float );
        ( *hHRTF )->FASTCONV_HRIR_latency_s_fx = (Word32) ( f_tmp * 1000000000 );
#if defined USE_NEW_HRTF_BINARY_FILE_FORMAT
        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 );
#endif

        if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
@@ -1380,24 +1304,18 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
            }
        }
    }
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 )
#else
    else if ( rend_type == RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 )
#endif
    {
        /* HRIR_HOA3 */
        f_tmp = *( (float *) ( hrtf_data_rptr ) );
        ( *hHRTF )->FASTCONV_HOA3_latency_s_fx = (Word32) ( f_tmp * 1000000000 );
        hrtf_data_rptr += sizeof( float );

#if defined USE_NEW_HRTF_BINARY_FILE_FORMAT
        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 );
#endif

        if ( HOA3_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
@@ -1447,24 +1365,18 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
            }
        }
    }
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 )
#else
    else if ( rend_type == RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 )
#endif
    {
        /* HRIR_HOA2 */
        f_tmp = *( (float *) ( hrtf_data_rptr ) );
        ( *hHRTF )->FASTCONV_HOA2_latency_s_fx = (Word32) ( f_tmp * 1000000000 );
        hrtf_data_rptr += sizeof( float );

#if defined USE_NEW_HRTF_BINARY_FILE_FORMAT
        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 );
#endif

        if ( HOA2_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
@@ -1515,24 +1427,18 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
            }
        }
    }
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA )
#else
    else if ( rend_type == RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA )
#endif
    {
        /* HRIR_FOA */
        f_tmp = *( (float *) ( hrtf_data_rptr ) );
        ( *hHRTF )->FASTCONV_FOA_latency_s_fx = (Word32) ( f_tmp * 1000000000 );
        hrtf_data_rptr += sizeof( float );

#if defined USE_NEW_HRTF_BINARY_FILE_FORMAT
        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 );
#endif

        if ( FOA_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
@@ -1584,23 +1490,17 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        }
    }
/* BRIR */
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
#else
    else if ( rend_type == RENDERER_BINAURAL_FASTCONV_ROOM && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
#endif
    {
        f_tmp = *( (float *) ( hrtf_data_rptr ) );
        ( *hHRTF )->FASTCONV_BRIR_latency_s_fx = (Word32) ( f_tmp * 1000000000 );
        hrtf_data_rptr += sizeof( float );

#if defined USE_NEW_HRTF_BINARY_FILE_FORMAT
        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 );
#endif

        if ( HRTF_LS_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
        {
@@ -1720,11 +1620,7 @@ ivas_error load_fastconv_HRTF_from_binary(
            free( hrtf_data );
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" );
        }
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
        if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) || ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) )
#else
        if ( ( hrtf_header.rend_type == RENDERER_BINAURAL_FASTCONV ) || ( hrtf_header.rend_type == RENDERER_BINAURAL_FASTCONV_ROOM ) )
#endif
        {
            if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size )
            {
@@ -1894,11 +1790,7 @@ ivas_error load_parambin_HRTF_from_binary(
        }


#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
        if ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Parametric binauralizer data is represented as single entity */
#else
        if ( hrtf_header.rend_type == 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 )
            {
@@ -1988,11 +1880,7 @@ ivas_error create_SetOfHRTF_from_binary(
        hHRTF = NULL;
        if ( hrtf_header.frequency == output_Fs )
        {
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
            if ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_MIXER_CONV )
#else
            if ( hrtf_header.rend_type == RENDERER_BINAURAL_MIXER_CONV )
#endif
            {
                if ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
                {
@@ -2011,11 +1899,7 @@ ivas_error create_SetOfHRTF_from_binary(
                    hHRTF = &( ( *hSetOfHRTF ).hHRTF_hrir_foa );
                }
            }
#ifdef USE_NEW_HRTF_BINARY_FILE_FORMAT
            else if ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_MIXER_CONV_ROOM )
#else
            else if ( hrtf_header.rend_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )
#endif
            {
                if ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
                {