Commit 217b72ea authored by Adam Mills's avatar Adam Mills
Browse files

Fixing delay properly and moving things into the right positions

parent cbc671c9
Loading
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
@@ -5482,25 +5482,6 @@ void ivas_lfe_lpf_enc_apply(
    const int16_t input_frame                                   /* i  : input frame length per channel          */
);

/*----------------------------------------------------------------------------------*
 * LFE decoder low pass filter prototypes
 *----------------------------------------------------------------------------------*/

ivas_error ivas_create_lfe_lpf_dec(
    ivas_filters_process_state_t **hLfeLpf,                     /* o  : LFE LPF handle                          */
    const int32_t input_Fs                                      /* i  : input sampling rate                     */
);

void ivas_lfe_lpf_dec_close(
    ivas_filters_process_state_t **hLfeLpf                      /* i/o: LFE LPF handle                          */
);

void ivas_lfe_lpf_dec_apply(
    ivas_filters_process_state_t *hLfeLpf,                      /* i/o: LFE LPF handle                          */
    float data_lfe_ch[],                                        /* i/o: LFE signal                              */
    const int16_t input_frame                                   /* i  : input frame length per channel          */
);


/*----------------------------------------------------------------------------------*
 * LFE Coding prototypes
+42 −47
Original line number Diff line number Diff line
@@ -1785,11 +1785,6 @@ ivas_error ivas_init_decoder(
        }
        else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
        {
            if ( ( error = ivas_create_lfe_lpf_dec( &st_ivas->hLfeLpf, hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            /* init EFAP for custom LS setup */
            if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
            {
@@ -2198,6 +2193,42 @@ ivas_error ivas_init_decoder(
        }
    }

    /*-----------------------------------------------------------------*
     * CLDFB handles for rendering
     *-----------------------------------------------------------------*/

    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses );

    for ( i = 0; i < numCldfbAnalyses; i++ )
    {
        if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
    for ( ; i < MAX_INTERN_CHANNELS; i++ )
    {
        st_ivas->cldfbAnaDec[i] = NULL;
    }

    for ( i = 0; i < numCldfbSyntheses; i++ )
    {
        if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
    for ( ; i < MAX_OUTPUT_CHANNELS; i++ )
    {
        st_ivas->cldfbSynDec[i] = NULL;
    }

    /* CLDFB Interpolation weights */
    if ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !st_ivas->sba_dirac_stereo_flag && st_ivas->hDecoderConfig->nchan_out != 1 )
    {
        ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig );
    }

    /*-----------------------------------------------------------------*
     * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay
     *-----------------------------------------------------------------*/
@@ -2223,11 +2254,14 @@ ivas_error ivas_init_decoder(
            }
        }
        else
        {
            if ( ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) && ( st_ivas->cldfbSynDec[0] != NULL ) )
            {
                delay_ns = IVAS_FB_DEC_DELAY_NS;
            if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
            }
            else
            {
                delay_ns += 3500000L; /* 3.5 ms */
                delay_ns = 0;
            }
        }

@@ -2240,42 +2274,6 @@ ivas_error ivas_init_decoder(
        set_zero( st_ivas->hLFE->prior_out_buffer, L_FRAME48k );
    }

    /*-----------------------------------------------------------------*
     * CLDFB handles for rendering
     *-----------------------------------------------------------------*/

    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses );

    for ( i = 0; i < numCldfbAnalyses; i++ )
    {
        if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
    for ( ; i < MAX_INTERN_CHANNELS; i++ )
    {
        st_ivas->cldfbAnaDec[i] = NULL;
    }

    for ( i = 0; i < numCldfbSyntheses; i++ )
    {
        if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
    for ( ; i < MAX_OUTPUT_CHANNELS; i++ )
    {
        st_ivas->cldfbSynDec[i] = NULL;
    }

    /* CLDFB Interpolation weights */
    if ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !st_ivas->sba_dirac_stereo_flag && st_ivas->hDecoderConfig->nchan_out != 1 )
    {
        ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig );
    }

    /*-----------------------------------------------------------------*
     * Allocate and initialize limiter struct
     *-----------------------------------------------------------------*/
@@ -2708,9 +2706,6 @@ void ivas_destroy_dec(
    /* LFE handle */
    ivas_lfe_dec_close( &( st_ivas->hLFE ) );

    /* LFE low pass filter state */
    ivas_lfe_lpf_dec_close( &( st_ivas->hLfeLpf ) );

    /* Param-Upmix MC handle */
    ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) );

+0 −3
Original line number Diff line number Diff line
@@ -647,9 +647,6 @@ ivas_error ivas_jbm_dec_tc(
            {
                ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, output_frame, p_output, p_output );
            }

            /* LFE low pass filter */
            ivas_lfe_lpf_dec_apply( st_ivas->hLfeLpf, p_output[LFE_CHANNEL], output_frame );
        }
        else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
        {
+35 −74
Original line number Diff line number Diff line
@@ -252,6 +252,29 @@ static int16_t ivas_lfe_dec_dequant(
}




/*-------------------------------------------------------------------------
 * ivas_create_lfe_lpf_dec()
 *
 * Create, allocate and initialize IVAS decoder LFE low pass filter state handle
 *-------------------------------------------------------------------------*/

static ivas_error ivas_create_lfe_lpf_dec(
    ivas_filters_process_state_t *hLfeLpf, /* o  : LFE LPF handle          */
    const int32_t input_Fs                  /* i  : input sampling rate     */
)
{
    const float *filt_coeff;

    ivas_lfe_lpf_select_filt_coeff( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff );

    ivas_filters_init( hLfeLpf, filt_coeff, IVAS_FILTER_ORDER_4 );

    return IVAS_ERR_OK;
}


/*-----------------------------------------------------------------------------------------*
 * Function ivas_lfe_dec()
 *
@@ -361,6 +384,7 @@ ivas_error ivas_create_lfe_dec(
    float lfe_addl_delay_s;
    int16_t i, j;
    int16_t add_delay_sa;
    ivas_error error;

    low_pass_delay_dec_out = 0;
    block_offset_s = 0;
@@ -401,8 +425,19 @@ ivas_error ivas_create_lfe_dec(
    hLFE->lfe_block_delay_s = ( IVAS_LFE_FADE_NS / 1000000000.f ) + ivas_lfe_lpf_delay[IVAS_FILTER_ORDER_4 - 3];

    block_offset_s = BLOCK_OFFSET_MS * 0.001f;
    
    filt_order = 0;
    low_pass_delay_dec_out = 0;
    if ( ( delay_ns / 1000000000.f ) > ivas_lfe_lpf_delay[IVAS_FILTER_ORDER_4 - 3] ) 
    {
        filt_order = 4;
        low_pass_delay_dec_out = 3500000L;
        if ( ( error = ivas_create_lfe_lpf_dec( &( hLFE->filter_state ), output_Fs ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }

    hLFE->filter_state.order = filt_order;
    hLFE->lfe_block_delay_s = hLFE->lfe_block_delay_s + low_pass_delay_dec_out;
    hLFE->lfe_prior_buf_len = NS2SA( output_Fs, IVAS_LFE_FADE_NS );
@@ -473,77 +508,3 @@ void ivas_lfe_dec_close(

    return;
}

/*-------------------------------------------------------------------------
 * ivas_create_lfe_lpf_dec()
 *
 * Create, allocate and initialize IVAS decoder LFE low pass filter state handle
 *-------------------------------------------------------------------------*/

ivas_error ivas_create_lfe_lpf_dec(
    ivas_filters_process_state_t **hLfeLpf, /* o  : LFE LPF handle          */
    const int32_t input_Fs                  /* i  : input sampling rate     */
)
{
    const float *filt_coeff;

    if ( hLfeLpf == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Can not allocate memory for LFE LPF\n" ) );
    }

    /*-----------------------------------------------------------------*
     * Allocate LFE LPF handle
     *-----------------------------------------------------------------*/

    if ( ( *hLfeLpf = (ivas_filters_process_state_t *) malloc( sizeof( ivas_filters_process_state_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE LPF\n" ) );
    }

    ivas_lfe_lpf_select_filt_coeff( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff );

    ivas_filters_init( *hLfeLpf, filt_coeff, IVAS_FILTER_ORDER_4 );

    return IVAS_ERR_OK;
}


/*-------------------------------------------------------------------------
 * ivas_lfe_lpf_dec_close()
 *
 * Destroy IVAS decoder LFE low pass filter state
 *-------------------------------------------------------------------------*/

void ivas_lfe_lpf_dec_close(
    ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */
)
{
    if ( hLfeLpf == NULL || *hLfeLpf == NULL )
    {
        return;
    }

    free( ( *hLfeLpf ) );
    ( *hLfeLpf ) = NULL;

    return;
}


/*-------------------------------------------------------------------------
 * ivas_lfe_lpf_dec_apply()
 *
 * Apply IVAS decoder LFE low pass filter
 *-------------------------------------------------------------------------*/

void ivas_lfe_lpf_dec_apply(
    ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle                   */
    float data_lfe_ch[],                   /* i/o: LFE signal                       */
    const int16_t input_frame              /* i  : input frame length per channel   */
)
{
    ivas_filter_process( hLfeLpf, data_lfe_ch, input_frame );

    return;
}