Commit 0935725a authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

Merge branch '242-issues-with-tcx-ltp-and-delay-alignment-for-mono-output' into 'main'

[rend-non-BE][non-BE] fix issues with mono output for MDCT Stereo and multi-channel

See merge request !327
parents 45d22d97 da427177
Loading
Loading
Loading
Loading
Loading

lib_com/options.h

100644 → 100755
+1 −2
Original line number Diff line number Diff line
@@ -161,8 +161,7 @@
#define FIX_VBR_COMPLEXITY                              /* Issue 234: fix extremely high complexity numbers for IVAS EVS mode */
#define FIX_ISM_INACTIVE_BITS                           /* Issue 230: fix bitbudget distribution in inactive frames in ISM format */
#define IMPROVE_CMDLINE_ROBUSTNESS                      /* Issue 233: Improve robustness of command-line parameters */

#define FIX_ITD_CNG                                     /* Eri: Fix for CNG ITD */
#define FIX_MDCT_AND_MC_MONO_ISSUES                     /* Issue 242: Fix some issues with TCX-LTP and delay alignement for mono output */


/* ################## End DEVELOPMENT switches ######################### */
+13 −0
Original line number Diff line number Diff line
@@ -444,10 +444,12 @@ ivas_error ivas_cpe_dec(
            }
        }
    }
#ifndef FIX_MDCT_AND_MC_MONO_ISSUES
    else if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->nchan_out == 1 && ( is_DTXrate( ivas_total_brate ) == 0 || ( is_DTXrate( ivas_total_brate ) == 1 && is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ) == 0 ) ) )
    {
        applyDmxMdctStereo( hCPE, output, output_frame );
    }
#endif

    /*----------------------------------------------------------------*
     * Update parameters for stereo CNA
@@ -461,6 +463,13 @@ ivas_error ivas_cpe_dec(

    synchro_synthesis( ivas_total_brate, hCPE, output, output_frame, 0 );

#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
    if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->nchan_out == 1 && ( is_DTXrate( ivas_total_brate ) == 0 || ( is_DTXrate( ivas_total_brate ) == 1 && is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ) == 0 ) ) )
    {
        applyDmxMdctStereo( hCPE, output, output_frame );
    }
#endif

#ifndef DEBUG_STEREO_DFT_OUTRESPRED
    /*----------------------------------------------------------------*
     * IC-BWE: output LB and HB mix in ACELP mode
@@ -581,7 +590,11 @@ ivas_error create_cpe_dec(
    hCPE->lt_es_em = 0.0f;

    /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */
#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
    if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MC_FORMAT )
#else
    if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) )
#endif
    {
        hCPE->nchan_out = CPE_CHANNELS;
    }
+4 −0
Original line number Diff line number Diff line
@@ -655,7 +655,11 @@ void applyDmxMdctStereo(
        fade = 0.f;
        dmx_len = crossfade_len;
    }
#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
    else if ( hCPE->last_element_mode == IVAS_CPE_DFT && hCPE->last_element_brate <= IVAS_32k )
#else
    else if ( hCPE->last_element_mode == IVAS_CPE_DFT && hCPE->last_element_brate <= IVAS_24k4 )
#endif
    {
        crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS );
        step /= crossfade_len;
+41 −0
Original line number Diff line number Diff line
@@ -716,8 +716,19 @@ ivas_error stereo_memory_dec(

            if ( hCPE->last_element_mode == IVAS_CPE_DFT )
            {
#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
                if ( hCPE->nchan_out == 1 )
                {
                    cpy_tcx_ltp_data( hCPE->hCoreCoder[0]->hTcxLtpDec, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs );
                }
                else
                {
                    cpy_tcx_ltp_data( &tcxLtpTmp, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs );
                }
#else
                cpy_tcx_ltp_data( &tcxLtpTmp, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs );
#endif
            }

            if ( hCPE->last_element_mode == IVAS_CPE_TD )
            {
@@ -975,6 +986,9 @@ void synchro_synthesis(
    int16_t dft_mono_brate_switch;
    int16_t delay_diff;
    float tmpF;
#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
    int16_t nChannels;
#endif

    sts = hCPE->hCoreCoder;
    output_Fs = sts[0]->output_Fs;
@@ -1044,6 +1058,14 @@ void synchro_synthesis(
            }
        }

#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
        if ( hCPE->nchan_out == 1 && hCPE->last_element_mode == IVAS_CPE_MDCT )
        {
            v_add( sts[0]->prev_synth_buffer, sts[1]->prev_synth_buffer, sts[0]->prev_synth_buffer, delay_comp_DFT );
            v_multc( sts[0]->prev_synth_buffer, INV_SQRT_2, sts[0]->prev_synth_buffer, delay_comp_DFT );
        }
#endif

        if ( use_cldfb_for_last_dft )
        {
            /* delay CLDFB-based mono output (<= 24.4 kbps) to be aligned with DFT-based mono output (32 kbps), needed to avoid discontinuities with TCX-LTP. */
@@ -1139,6 +1161,16 @@ void synchro_synthesis(
            }
        }

#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
        /* if previous frame had only one channel copy buffers to other channel */
        if ( hCPE->nchan_out == 1 && hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_DFT )
        {
            mvr2r( sts[0]->prev_synth_buffer, sts[1]->prev_synth_buffer, delay_comp_TD );
            mvr2r( tmp_out[0], tmp_out[1], delay_cldfb );
            mvr2r( p_output_mem[0], p_output_mem[1], delay_diff );
        }
#endif

        /*----------------------------------------------------------------*
         * update DFT synthesis overlap memory @output_Fs; needed for TD->DFT stereo switching
         *----------------------------------------------------------------*/
@@ -1222,7 +1254,12 @@ void synchro_synthesis(
            }
        }

#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
        nChannels = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? 2 : hCPE->nchan_out;
        for ( n = 0; n < nChannels; n++ )
#else
        for ( n = 0; n < hCPE->nchan_out; n++ )
#endif
        {
            if ( hCPE->element_mode == IVAS_CPE_MDCT )
            {
@@ -1255,7 +1292,11 @@ void synchro_synthesis(
            }

            /* cross-fading between DFT OLA memory and TD output */
#ifdef FIX_MDCT_AND_MC_MONO_ISSUES
            for ( n = 0; n < nChannels; n++ )
#else
            for ( n = 0; n < hCPE->nchan_out; n++ )
#endif
            {
                if ( hCPE->element_mode == IVAS_CPE_MDCT )
                {
+6 −0
Original line number Diff line number Diff line
@@ -1220,6 +1220,12 @@ static ivas_error initMcPanGainsWithMonoOut(
            inputMc->panGains[i][0] = 1.f;
        }
    }
    else if ( inputMc->base.inConfig == IVAS_REND_AUDIO_CONFIG_STEREO )
    {
        /* Special case for STEREO to MONO: Passive downmix (L+R)/2 */
        inputMc->panGains[0][0] = 0.5;
        inputMc->panGains[1][0] = 0.5;
    }
    else
    {
        /* ls_conversion_cicpX_stereo contains gains for side speakers.
Loading