Commit 3bc474c0 authored by vaclav's avatar vaclav
Browse files

accept FIX_I59_CREND

parent fde8382b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -146,7 +146,6 @@
#define BRATE_SWITCHING_RENDERING                       /* Bitrate switching changes related to the renderers */
#define FIX_I59_DELAY_ROUNDING                          /* Issue 59: rounding in sample domain instead of nanosec for IVAS_ENC_GetDelay() and IVAS_DEC_GetDelay() */
#define FIX_FIX_I59                                     /* Issue 59:  small fix concerning LFE delay rounding */
#define FIX_I59_CREND                                   /* Issue 59: Fixes for gcc compiler warnings in ivas_crend_utest_utils.c */
#define LOW_RATE_TRANS                                  /* Eri: Contribution 20: low rate encoding of transients */
#define MC_BITRATE_SWITCHING                            /* Issue 116: support bitrate switching in MC format  */
#define SIMPLIFY_TD_BWE_RESET                           /* Issue 250: Resolve "TB-BWE state memories reset simplification"  */
+14 −118
Original line number Diff line number Diff line
@@ -83,60 +83,38 @@ static int32_t ivas_check_rounding( float binaural_latencys_s[3], int16_t use_ro
    *err_lfe = 0;
    *err_dec = 0;

#ifdef FIX_I59_CREND
    for ( int ind1 = 0; ind1 < 3; ind1++ )
#else
    for ( int ind1 = 0; ind1 < sizeof( sampleRates ) / sizeof( float ); ind1++ )
#endif
    {
        if ( verbose )
            printf( "\nsample rate = %f", sampleRates[ind1] );

#ifdef FIX_I59_CREND
        for ( int ind2 = 0; ind2 < 3; ind2++ )
#else
        for ( int ind2 = 0; ind2 < sizeof( binaural_latencys_s ) / sizeof( float ); ind2++ )
#endif
        {
            wanted = (int32_t) roundf( binaural_latencys_s[ind2] * sampleRates[ind1] );
            if ( verbose )
#ifdef FIX_I59_CREND
                printf( "\nbinaural_latencys_s = %f wanted = %d", binaural_latencys_s[ind2], wanted );
#else            
                printf( "\nbinaural_latencys_s = %f wanted = %ld", binaural_latencys_s[ind2], wanted );
#endif
            if ( use_round_latency )
                delay_ns[ind2] = (int32_t) roundf( binaural_latencys_s[ind2] * 1000000000.f );
            else
                delay_ns[ind2] = (int32_t) ( binaural_latencys_s[ind2] * 1000000000.f );
            if ( verbose )
#ifdef FIX_I59_CREND            
                printf( "\n delay_ns[%d] = %d \n", ind2, delay_ns[ind2] );
#else
                printf( "\n delay_ns[%d] = %ld \n", ind2, delay_ns[ind2] );
#endif

            if ( use_round_for_lfe )
                delay_lfe[ind1][ind2] = (int32_t) roundf( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f );
            else
                delay_lfe[ind1][ind2] = (int32_t) NS2SA( sampleRates[ind1], delay_ns[ind2] );
            if ( verbose )
#ifdef FIX_I59_CREND                        
                printf( "\ndelay_lfe[%d][%d] = %d\n", ind1, ind2, delay_lfe[ind1][ind2] );
#else
                printf( "\ndelay_lfe[%d][%d] = %ld\n", ind1, ind2, delay_lfe[ind1][ind2] );
#endif

            *err_lfe += abs( delay_lfe[ind1][ind2] - wanted );

            delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] + 0.5f );
            //         delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] );
            /*         delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] );*/

            if ( verbose )
#ifdef FIX_I59_CREND
                printf( "\ndelay_dec[%d][%d] = %d \n", ind1, ind2, delay_dec[ind1][ind2] );
#else
                printf( "\ndelay_dec[%d][%d] = %ld \n", ind1, ind2, delay_dec[ind1][ind2] );
#endif

            *err_dec += abs( delay_dec[ind1][ind2] - wanted );
        }
    }
@@ -1176,85 +1154,38 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
    float binaural_latencys_td_s[3] = { BINAURAL_TD_LATENCY_S, BINAURAL_TD_LATENCY_S + 1.f / 48000.f, BINAURAL_TD_LATENCY_S + 2.f / 48000.f };

    int32_t err = 0, err_lfe = 0, err_dec = 0;

    binaural_latencys_fastconv_s[0] = FASTCONV_HRIR_latency_s;
    binaural_latencys_fastconv_s[1] = FASTCONV_BRIR_latency_s;
    binaural_latencys_fastconv_s[2] = FASTCONV_BRIR_latency_s;

    err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 0, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else    
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif
    err += ivas_check_rounding( binaural_latencys_crend_s, 0, 0, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else    
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif
    err += ivas_check_rounding( binaural_latencys_td_s, 0, 0, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec );
#else
    printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec );
#endif

    err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 1, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else    
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif
    err += ivas_check_rounding( binaural_latencys_crend_s, 0, 1, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else    
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif
    err += ivas_check_rounding( binaural_latencys_td_s, 0, 1, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec );
#else    
    printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec );
#endif

    err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 0, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif
    err += ivas_check_rounding( binaural_latencys_crend_s, 1, 0, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else    
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif    
    err += ivas_check_rounding( binaural_latencys_td_s, 1, 0, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec );
#else        
    printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec );
#endif

    err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 1, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else        
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif    
    err += ivas_check_rounding( binaural_latencys_crend_s, 1, 1, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec );
#else    
    printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec );
#endif    
    err += ivas_check_rounding( binaural_latencys_td_s, 1, 1, &err_lfe, &err_dec, 0 );
#ifdef FIX_I59_CREND
    printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec );
#else    
    printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec );
#endif    


    ivas_render_config_open( &st_ivas.hRenderConfig );
    ivas_render_config_init_from_rom( &st_ivas.hRenderConfig, 0 );
@@ -1292,28 +1223,16 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
            {
                st_ivas.renderer_type = RENDERER_BINAURAL_FASTCONV_ROOM;
                st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL_ROOM;
#ifdef FIX_FIX_I59
                pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ) );
#else
                pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_BRIR_latency_s;
#endif
            }
            else
            {
                st_ivas.renderer_type = RENDERER_BINAURAL_FASTCONV;
                st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL;
                if ( st_ivas.ivas_format == MC_FORMAT )
#ifdef FIX_FIX_I59
                    pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_HRIR_latency_s * 1000000000.f ) );
#else
                    pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_HRIR_latency_s;
#endif
                else
#ifdef FIX_FIX_I59
                    pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f ) );
#else
                    pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_HOA3_latency_s;
#endif
            }
        }
        else if ( pIo_params->test == TD_BIN_TEST )
@@ -1334,11 +1253,8 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
                st_ivas.renderer_type = RENDERER_BINAURAL_OBJECTS_TD;
                st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL;
            }
#ifdef FIX_FIX_I59

            pIo_params->latency_ns = (int32_t) ( BINAURAL_TD_LATENCY_S * 1000000000.f );
#else
            pIo_params->latency_s = BINAURAL_TD_LATENCY_S;
#endif
        }
        else if ( pIo_params->test == PARAM_BIN_TEST )
        {
@@ -1352,11 +1268,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
                st_ivas.renderer_type = RENDERER_BINAURAL_PARAMETRIC;
                st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL;
            }
#ifdef FIX_FIX_I59
            pIo_params->latency_ns = IVAS_FB_DEC_DELAY_NS;
#else
            pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate;
#endif
        }
        else if ( pIo_params->test == CREND_BIN_TEST )
        {
@@ -1496,19 +1408,13 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl

    if ( pIo_params->test == CREND_BIN_TEST )
    {
#ifdef FIX_FIX_I59
        pIo_params->latency_ns = (int32_t) ( st_ivas.hHrtf->latency_s * 1000000000.f );
#else
        pIo_params->latency_s = st_ivas.hHrtf->latency_s;
#endif
    }

    if ( st_ivas.ivas_format == MC_FORMAT )
    {
#ifdef FIX_FIX_I59
        ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_ns );
#else
        ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_s );
#endif

        if ( st_ivas.hLFE->lfe_addl_delay > 0 )
        {
            if ( st_ivas.hLFE->lfe_delay_buf != NULL )
@@ -1516,15 +1422,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
                free( st_ivas.hLFE->lfe_delay_buf );
                st_ivas.hLFE->lfe_delay_buf = NULL;
            }
#ifdef FIX_FIX_I59

            if ( pIo_params->latency_ns > 0 )
            {
                st_ivas.hLFE->lfe_addl_delay = (int16_t) roundf( (float) pIo_params->latency_ns * (float) dec_io_params.out_sample_rate / 1000000000.f );
#else
            if ( pIo_params->latency_s > 0 )
            {
                st_ivas.hLFE->lfe_addl_delay = (int16_t) roundf( pIo_params->latency_s * dec_io_params.out_sample_rate );
#endif

                if ( st_ivas.hLFE->lfe_addl_delay > 0 )
                {
                    if ( ( st_ivas.hLFE->lfe_delay_buf = (float *) malloc( st_ivas.hLFE->lfe_addl_delay * sizeof( float ) ) ) == NULL )
@@ -1540,6 +1442,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
                st_ivas.hLFE->lfe_addl_delay = 0;
            }
        }

        /* delay input channel of latency of lp filter*/
        if ( pIo_params->lfe_lp_enable )
        {
@@ -1555,11 +1458,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
            }
            ivas_lfe_lpf_select_filt_coeff( pIo_params->sample_rate, IVAS_FILTER_ORDER_4, &filt_coeff );
            ivas_filters_init( &st_ivas.hLFE->filter_state, filt_coeff, IVAS_FILTER_ORDER_4 );
#ifdef FIX_FIX_I59
            pIo_params->latency_ns = pIo_params->latency_ns + (int32_t) ( ivas_lfe_lpf_delay[1] * 1000000000.f );
#else
            pIo_params->latency_s = pIo_params->latency_s + ivas_lfe_lpf_delay[1];
#endif
        }
        else
        {
@@ -1589,13 +1488,10 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl
    int32_t skip_samples = 0;
    int32_t skipped_samples = 0;
    int16_t write_flag = 0;

    if ( ( pIo_params->out_fmt == BIN_2 ) && ( pIo_params->no_delay_cmp == 0 ) )
    {
#ifdef FIX_FIX_I59
        skip_samples = (int32_t) roundf( (float) pIo_params->latency_ns * pIo_params->sample_rate / 1000000000.f );
#else
        skip_samples = NS2SA( pIo_params->sample_rate, (int32_t) ( pIo_params->latency_s * 1000000000.f ) );
#endif
    }
    fprintf( stdout, "IVAS Common Renderer skip samples = %d\n", (int) skip_samples );