Commit e2f6a0b2 authored by emerit's avatar emerit
Browse files

bug fix on fastconv binaural memory allocation when reading hrtf binary file

parent 7435b447
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -565,8 +565,7 @@ ivas_error ivas_allocate_binaural_hrtf(
    HRTFS_FASTCONV *HrtfFastConv,                       /* i/o: FASTCONV HRTF structure     */
    const AUDIO_CONFIG input_config,                    /* i  : input audio configuration   */
    const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i  : binaural input audio config */
    const RENDERER_TYPE renderer_type                   /* i  : renderer type               */
    ,
    const RENDERER_TYPE renderer_type,                  /* i  : renderer type               */
    const int16_t allocate_init_flag                    /* i  : Memory allocation flag      */
)
{
+94 −6
Original line number Diff line number Diff line
@@ -1881,6 +1881,9 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
#ifdef FIX_1123_FASTCONV_16BIT_FMT
    float scaleFactor;
    int16_t *ptW16;
    float latency_s;
    uint16_t ntaps;
    uint16_t nbchan;
#else
    int32_t *ptW32;
#endif
@@ -1892,6 +1895,85 @@ static ivas_error create_fastconv_HRTF_from_rawdata(

    ( *hHRTF )->allocate_init_flag = 0;

#ifdef FIX_1123_FASTCONV_16BIT_FMT
    hrtf_data_rptr = hrtf_data;

    /* latency_s Q factor*/
    factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
    hrtf_data_rptr += sizeof( Word16 );

    /* latency_s */
    latency_s = ( *( (Word32 *) ( hrtf_data_rptr ) ) ) * powf( 2.f, -1.f * factorQ );
    hrtf_data_rptr += sizeof( Word32 );

    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 );

    nbchan = *( (uint16_t *) ( hrtf_data_rptr ) );
    hrtf_data_rptr += sizeof( uint16_t );

    ntaps = *( (uint16_t *) ( hrtf_data_rptr ) );
    hrtf_data_rptr += sizeof( uint16_t );

    if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
    {
        if ( HRTF_LS_CHANNELS != nbchan )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" );
        }
        ( *hHRTF )->ntaps_hrir = ntaps;
        ( *hHRTF )->FASTCONV_HRIR_latency_s = latency_s;
    }
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 )
    {
        if ( HOA3_CHANNELS != nbchan )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA3_CHANNELS)" );
        }
        ( *hHRTF )->ntaps_hrir_hoa3 = ntaps;
        ( *hHRTF )->FASTCONV_HOA3_latency_s = latency_s;
    }
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 )
    {
        if ( HOA2_CHANNELS != nbchan )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA2_CHANNELS)" );
        }
        ( *hHRTF )->ntaps_hrir_hoa2 = ntaps;
        ( *hHRTF )->FASTCONV_HOA2_latency_s = latency_s;
    }
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA )
    {
        if ( FOA_CHANNELS != nbchan )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (FOA_CHANNELS)" );
        }
        ( *hHRTF )->ntaps_hrir_foa = ntaps;
        ( *hHRTF )->FASTCONV_FOA_latency_s = latency_s;
    }
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
    {
        if ( HRTF_LS_CHANNELS != nbchan )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" );
        }
        ( *hHRTF )->ntaps_brir = ntaps;
        ( *hHRTF )->FASTCONV_BRIR_latency_s = latency_s;
    }
    else
    {
        return IVAS_ERROR( IVAS_ERR_BITSTREAM_READER_INVALID_FORMAT, "Can not read hrtf binary file : wrong render type and input config couple " );
    }
#else
    if ( BINAURAL_NTAPS != *( (uint16_t *) ( hrtf_data_rptr ) ) )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_NTAPS)" );
    }
#endif

    if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV )
    {
        if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK )
@@ -1910,11 +1992,13 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" );
    }
#ifndef FIX_1123_FASTCONV_16BIT_FMT
    hrtf_data_rptr = hrtf_data;

#endif
    /* HRIR */
    if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
    {
#ifndef FIX_1123_FASTCONV_16BIT_FMT
        /* latency_s Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( Word16 );
@@ -1944,7 +2028,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        }
#endif
        hrtf_data_rptr += sizeof( uint16_t );

#endif

        /* HRIR Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
@@ -2056,6 +2140,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    }
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 )
    {
#ifndef FIX_1123_FASTCONV_16BIT_FMT
        /* latency_s Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( Word16 );
@@ -2085,6 +2170,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        }
#endif
        hrtf_data_rptr += sizeof( uint16_t );
#endif


        /* HRIR Q factor*/
@@ -2197,6 +2283,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    }
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 )
    {
#ifndef FIX_1123_FASTCONV_16BIT_FMT
        /* latency_s Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( Word16 );
@@ -2216,7 +2303,6 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA2_CHANNELS)" );
        }
        hrtf_data_rptr += sizeof( uint16_t );

#ifdef FIX_1123_FASTCONV_16BIT_FMT
        ( *hHRTF )->ntaps_hrir_hoa2 = *( (uint16_t *) ( hrtf_data_rptr ) );
#else
@@ -2226,7 +2312,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        }
#endif
        hrtf_data_rptr += sizeof( uint16_t );

#endif

        /* HRIR Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
@@ -2338,6 +2424,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    }
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA )
    {
#ifndef FIX_1123_FASTCONV_16BIT_FMT
        /* latency_s Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( Word16 );
@@ -2368,7 +2455,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        }
#endif
        hrtf_data_rptr += sizeof( uint16_t );

#endif

        /* HRIR Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
@@ -2481,6 +2568,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
    /* BRIR */
    else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED )
    {
#ifndef FIX_1123_FASTCONV_16BIT_FMT
        /* latency_s Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );
        hrtf_data_rptr += sizeof( Word16 );
@@ -2510,7 +2598,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata(
        }
#endif
        hrtf_data_rptr += sizeof( uint16_t );

#endif

        /* BRIR Q factor*/
        factorQ = *( (Word16 *) ( hrtf_data_rptr ) );