Commit b52ecbbb authored by vaclav's avatar vaclav
Browse files

fix for OMASA - load also TD renderer HRTF data

parent f91cfc66
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -173,6 +173,8 @@ typedef struct

    IVAS_BIN_RENDERER_TYPE binaural_renderer;
    IVAS_BIN_RENDERER_TYPE binaural_renderer_old;
    IVAS_BIN_RENDERER_TYPE binaural_renderer_sec;
    IVAS_BIN_RENDERER_TYPE binaural_renderer_sec_old;

    IVAS_AUDIO_CONFIG intern_audio_config;
    int16_t room_reverb_flag;
@@ -769,6 +771,7 @@ int main(
        hHrtfBinary.hrtfReader = hrtfReader;
        hHrtfBinary.hrtfFileName = arg.hrtfFileName;
        hHrtfBinary.binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE;
        hHrtfBinary.binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_NONE;
        hHrtfBinary.room_reverb_flag = 0;
        hHrtfBinary.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID;
#else
@@ -918,7 +921,11 @@ int main(
    }
    else
    {
#ifdef FIX_HRTF_LOAD
        fprintf( stderr, "\nDecoding finished prematurely: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
#else
        fprintf( stdout, "Decoding finished prematurely\n\n" );
#endif
        goto cleanup;
    }

@@ -2540,7 +2547,8 @@ static ivas_error decodeG192(
#ifdef FIX_HRTF_LOAD
                /* Read main parameters from the bitstream to set-up the decoder */
                hHrtfBinary->binaural_renderer_old = hHrtfBinary->binaural_renderer;
                if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->room_reverb_flag, &hHrtfBinary->intern_audio_config ) ) != IVAS_ERR_OK )
                hHrtfBinary->binaural_renderer_sec_old = hHrtfBinary->binaural_renderer_sec;
                if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->binaural_renderer_sec, &hHrtfBinary->room_reverb_flag, &hHrtfBinary->intern_audio_config ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
@@ -3512,7 +3520,8 @@ static ivas_error decodeVoIP(
            {
                /* Read main parameters from the bitstream to set-up the decoder */
                hHrtf->binaural_renderer_old = hHrtf->binaural_renderer;
                if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK )
                hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec;
                if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
@@ -3860,7 +3869,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile(
    const int32_t output_Fs )
{
    ivas_error error;
    IVAS_BIN_RENDERER_TYPE binaural_renderer;
    IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec;

    if ( hHrtfBinary == NULL || hIvasDec == NULL )
    {
@@ -3868,19 +3877,22 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile(
    }

    binaural_renderer = hHrtfBinary->binaural_renderer;
    binaural_renderer_sec = hHrtfBinary->binaural_renderer_sec;

    if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
    if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) ||
         ( binaural_renderer_sec != hHrtfBinary->binaural_renderer_sec_old ) ||
         ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
    {
        /*------------------------------------------------------------------------------------------*
         * Release HRTF binary data
         *------------------------------------------------------------------------------------------*/

        if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
        if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL )
        {
            destroy_td_hrtf( hHrtfBinary->hHrtfTD );
        }

        if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
        if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && hHrtfBinary->hSetOfHRTF != NULL )
        {
            destroy_SetOfHRTF( hHrtfBinary->hSetOfHRTF );
        }
@@ -3899,7 +3911,12 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile(
            return error;
        }

        if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT )
        if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer_sec ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT )
        {
            if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK )
            {
+9 −0
Original line number Diff line number Diff line
@@ -61,6 +61,15 @@ ivas_error ivas_td_binaural_open(
        num_src = st_ivas->nchan_ism;
    }

#ifdef FIX_HRTF_LOAD
    if ( st_ivas->hHrtfTD == NULL && st_ivas->hDecoderConfig->Opt_HRTF_binary &&
         ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #xx
    )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in TD renderer" );
    }
#endif

    return ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, num_src, st_ivas->ivas_format,
                                         st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hRenderConfig->distAtt, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns );
}
+15 −7
Original line number Diff line number Diff line
@@ -1065,6 +1065,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
ivas_error IVAS_DEC_ReadFormat(
    IVAS_DEC_HANDLE hIvasDec,                      /* i/o: IVAS decoder handle              */
    IVAS_BIN_RENDERER_TYPE *binaural_renderer,     /* o  : binaural renderer type           */
    IVAS_BIN_RENDERER_TYPE *binaural_renderer_sec, /* o  : secondary binaural renderer type */
    int16_t *room_reverb_flag,                     /* o  : room reverb flag                 */
    IVAS_AUDIO_CONFIG *intern_audio_config         /* o  : internal audio configuration     */
)
@@ -1141,6 +1142,12 @@ ivas_error IVAS_DEC_ReadFormat(
                break;
        }

        *binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_NONE;
        if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL )
        {
            *binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_TDREND;
        }

        *intern_audio_config = st_ivas->intern_config;

        if ( ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) ||
@@ -3105,9 +3112,11 @@ ivas_error IVAS_DEC_HRTF_binary_close(
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    if ( st_ivas->hDecoderConfig->Opt_HRTF_binary )
    if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->ini_frame > 0 )
    {
        if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
        if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) &&
             ( hIvasDec->st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #xx
        )
        {
            ivas_HRTF_binary_close( &st_ivas->hHrtfTD );
        }
@@ -3120,7 +3129,6 @@ ivas_error IVAS_DEC_HRTF_binary_close(

        if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
        {

            /* Fastconv HRTF memories */
            ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv );

+2 −1
Original line number Diff line number Diff line
@@ -163,6 +163,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
ivas_error IVAS_DEC_ReadFormat(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    IVAS_BIN_RENDERER_TYPE *binaural_renderer,  /* o  : binaural renderer type                                                  */
    IVAS_BIN_RENDERER_TYPE *binaural_renderer_sec,/* o: secondary binaural renderer type                                        */
    int16_t *room_reverb_flag,                  /* o  : room reverb flag                                                        */
    IVAS_AUDIO_CONFIG *intern_audio_config      /* o  : internal audio configuration                                            */
);