Commit 04440bc5 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'MLD_improvements_15' into 'main'

[allow regression] Changes to fix high MLD issues and precision improvements

See merge request !589
parents 01d549fe d1528ba8
Loading
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -5882,6 +5882,27 @@ void RefineTonalComponents(
#endif
);

void ivas_RefineTonalComponents_fx(
    Word16 indexOfTonalPeak[],
    Word16 lowerIndex[],
    Word16 upperIndex[],
    Word16 phaseDiff[],
    Word16 phases[],
    Word16 *pNumIndexes,
    const Word32 lastPitchLag,
    const Word32 currentPitchLag,
    const Word16 lastMDCTSpectrum[],
    const Word16 lastMDCTSpectrum_exp,
    const Word16 scaleFactors[],
    const Word16 scaleFactors_exp[],
    const Word16 scaleFactors_max_e,
    const Word32 secondLastPowerSpectrum[],
    const Word16 nSamples,
    const Word16 nSamplesCore,
    const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins  */
    Word16 element_mode,
    const PsychoacousticParameters *psychParamsCurrent );

ivas_error PsychoacousticParameters_Init(
    const int32_t sr_core,  /* i  : sampling rate of core-coder                                     */
    const int16_t nBins,    /* i  : Number of bins (spectral lines)                                 */
+87 −0
Original line number Diff line number Diff line
@@ -290,6 +290,93 @@ void RefineTonalComponents(
    return;
}

void ivas_RefineTonalComponents_fx(
    Word16 indexOfTonalPeak[],
    Word16 lowerIndex[],
    Word16 upperIndex[],
    Word16 phaseDiff[],
    Word16 phases[],
    Word16 *pNumIndexes,
    const Word32 lastPitchLag,
    const Word32 currentPitchLag,
    const Word16 lastMDCTSpectrum[],
    const Word16 lastMDCTSpectrum_exp,
    const Word16 scaleFactors[],
    const Word16 scaleFactors_exp[],
    const Word16 scaleFactors_max_e,
    const Word32 secondLastPowerSpectrum[],
    const Word16 nSamples,
    const Word16 nSamplesCore,
    const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins  */
    Word16 element_mode,
    const PsychoacousticParameters *psychParamsCurrent )
{
    Word16 newIndexOfTonalPeak[MAX_NUMBER_OF_IDX];
    Word16 newLowerIndex[MAX_NUMBER_OF_IDX];
    Word16 newUpperIndex[MAX_NUMBER_OF_IDX];
    Word16 newNumIndexes, nPreservedPeaks;
    Word16 iNew, iOld, j;
    Word16 *pOldPhase, *pNewPhase;


    ivas_DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum,
                                   lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, nSamples, nSamplesCore, floorPowerSpectrum,
                                   psychParamsCurrent, element_mode );

    nPreservedPeaks = 0;
    move16();
    iNew = 0;
    move16();
    pOldPhase = phases;
    pNewPhase = phases;

    FOR( iOld = 0; iOld < *pNumIndexes; iOld++ )
    {
        /* We don't want that the old peak index is at the border of the new peak region, that is why >= newUpperIndex and > newLowerIndex */
        test();
        WHILE( LT_16( iNew, newNumIndexes ) && GE_16( indexOfTonalPeak[iOld], newUpperIndex[iNew] ) )
        {
            iNew = add( iNew, 1 );
        }

        test();
        IF( LT_16( iNew, newNumIndexes ) && GT_16( indexOfTonalPeak[iOld], newLowerIndex[iNew] ) )
        {
            newIndexOfTonalPeak[nPreservedPeaks] = indexOfTonalPeak[iOld];
            move16();
            newLowerIndex[nPreservedPeaks] = lowerIndex[iOld];
            move16();
            newUpperIndex[nPreservedPeaks] = upperIndex[iOld];
            move16();
            phaseDiff[nPreservedPeaks] = phaseDiff[iOld];
            move16();

            FOR( j = lowerIndex[iOld]; j <= upperIndex[iOld]; j++ )
            {
                *pNewPhase++ = *pOldPhase++;
                move16();
            }
            nPreservedPeaks = add( nPreservedPeaks, 1 );
        }
        ELSE
        {
            pOldPhase += sub( upperIndex[iOld], add( lowerIndex[iOld], 1 ) );
        }
    }

    FOR( iNew = 0; iNew < nPreservedPeaks; iNew++ )
    {
        indexOfTonalPeak[iNew] = newIndexOfTonalPeak[iNew];
        move16();
        lowerIndex[iNew] = newLowerIndex[iNew];
        move16();
        upperIndex[iNew] = newUpperIndex[iNew];
        move16();
    }
    *pNumIndexes = nPreservedPeaks;
    move16();
    return;
}
/*-------------------------------------------------------------------*
 * Local functions
 *-------------------------------------------------------------------*/
+4 −1
Original line number Diff line number Diff line
@@ -1846,7 +1846,10 @@ void open_decoder_LPD_ivas_fx(
        move16();
        if ( hTcxDec != NULL )
        {
            hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/
            hTcxDec->conceal_eof_gain32 = ONE_IN_Q30; /*Q30*/
            hTcxDec->conceal_eof_gain_e = 1;
            move16();
            move32();
            move16();
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -2020,8 +2020,8 @@ ivas_error core_switching_post_dec_ivas_fx(
                    ptmp1 = &synth[delay_comp];
                    FOR( i = 0; i < NS2SA_FX2( st_fx->output_Fs, 3000000 ); i++ )
                    {
                        L_tmp = L_mult0( st_fx->hTcxDec->conceal_eof_gain, *ptmp2 );
                        L_tmp = L_shl( L_tmp, 1 );
                        L_tmp = Mpy_32_16_1( st_fx->hTcxDec->conceal_eof_gain32, *ptmp2 );
                        L_tmp = L_shl( L_tmp, st_fx->hTcxDec->conceal_eof_gain_e );
                        tmpV = round_fx( L_tmp );

                        *ptmp1 = add( mult_r( tmpF, *ptmp1 ), mult_r( sub( 32767, tmpF ), tmpV ) );
+64 −46
Original line number Diff line number Diff line
@@ -1623,6 +1623,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
    Word16 level_syn;
    Word16 level_syn_e;
    Word32 step;
    Word16 step_e;
    Word16 gainCNG, gainCNG_e;
    Word16 xn_buf[L_FRAME_MAX];
    Word16 tmp1, tmp2, s;
@@ -1768,8 +1769,8 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
     * PLC: fade-out in time domain */
    IF( bfi != 0 )
    {
        Word32 conceal_eof_gain32;
        Word32 conceal_eof_gainFB;
        Word16 conceal_eof_gainFB_e;
        move16();
        move16();
        gainCNG = 1;
@@ -1777,6 +1778,17 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
        IF( st_fx->tcxonly != 0 )
        {
            /*gainCNG = st_fx->conCngLevelBackgroundTrace/(tracingLevel+0.01f);*/
            IF( level_syn )
            {
                level_syn_e = BASOP_Util_Add_MantExp( level_syn, level_syn_e, 20992, -6, &level_syn ); /* 0.01 in Q21*/
            }
            ELSE
            {
                level_syn = 328; /* (1 / 0.01) in Q15 */
                level_syn_e = 0;
                move16();
                move16();
            }

            IF( level_syn != 0 )
            {
@@ -1807,6 +1819,18 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
        ELSE
        {
            /*gainCNG = st_fx->cngTDLevel/(tracingLevel+0.01f);*/
            IF( level_syn )
            {
                level_syn_e = BASOP_Util_Add_MantExp( level_syn, level_syn_e, 20992, -6, &level_syn ); /* 0.01 in Q21*/
            }
            ELSE
            {
                level_syn = 328; /* (1 / 0.01) in Q15 */
                level_syn_e = 0;
                move16();
                move16();
            }

            IF( level_syn != 0 )
            {
                BASOP_Util_Divide_MantExp(
@@ -1821,64 +1845,57 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,

        if ( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) )
        {
            hTcxDec->conceal_eof_gain = 16384 /*1.0f Q14*/; /*Q14*/
            hTcxDec->conceal_eof_gain32 = ONE_IN_Q30 /*1.0f Q30*/;
            move32();
            hTcxDec->conceal_eof_gain_e = 1;
            move16();
        }

        /* step = (st_fx->conceal_eof_gain - ( st_fx->conceal_eof_gain * st_fx->damping + gainCNG * (1 - st_fx->damping) )) / st_fx->L_frame; */
        tmp2 = BASOP_Util_Add_MantExp(
            mult_r( hTcxDec->conceal_eof_gain /*Q14*/,
        Word32 L_tmp = BASOP_Util_Add_Mant32Exp(
            Mpy_32_16_1( hTcxDec->conceal_eof_gain32,
                         hTcxDec->damping /*Q14*/ ),
            15 - 13 /*->Q15*/,
            mult_r( gainCNG /*Q15*/, sub( 0x4000, hTcxDec->damping /*Q14*/ ) ) /*Q14*/,
            add( 1, hTcxDec->conceal_eof_gain_e ) /*->Q15*/,
            L_mult( gainCNG /*Q15*/, sub( 0x4000, hTcxDec->damping /*Q14*/ ) ) /*Q14*/,
            add( gainCNG_e, 15 - 14 ) /*->Q15*/,
            &tmp1 );
        tmp2 = BASOP_Util_Add_MantExp( hTcxDec->conceal_eof_gain, 15 - 14, negate( tmp1 ), tmp2, &tmp1 );
            &tmp2 );

#ifdef BASOP_NOGLOB
        step = L_shl_o( L_mult( tmp1, getInvFrameLen( st_fx->L_frame ) ), sub( tmp2, 6 /*scaling from table lookup*/ + 1 /*go to Q30*/ ), &Overflow ); /*Q30*/
#else
        step = L_shl( L_mult( tmp1, getInvFrameLen( st_fx->L_frame ) ), sub( tmp2, 6 /*scaling from table lookup*/ + 1 /*go to Q30*/ ) ); /*Q30*/
#endif
        L_tmp = BASOP_Util_Add_Mant32Exp( hTcxDec->conceal_eof_gain32, hTcxDec->conceal_eof_gain_e, L_negate( L_tmp ), tmp2, &tmp2 );
        step = Mpy_32_16_1( L_tmp, getInvFrameLen( st_fx->L_frame ) );
        step_e = sub( tmp2, 6 );
        {
            Word32 stepFB;
            Word16 stepFB_e;
            UWord32 dmy;
            conceal_eof_gainFB = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/
            Word16 tmp_shift;
            conceal_eof_gainFB = hTcxDec->conceal_eof_gain32;
            conceal_eof_gainFB_e = hTcxDec->conceal_eof_gain_e;
            move32();
            move16();
            Mpy_32_32_ss( step, L_shl( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ), &stepFB, &dmy );
#ifdef BASOP_NOGLOB
            stepFB = L_shl_o( stepFB, 3 - 1, &Overflow ); /*Q30*/
#else
            stepFB = L_shl( stepFB, 3 - 1 );                                                                                              /*Q30*/
#endif
            stepFB_e = add( step_e, 2 );

            FOR( i = 0; i < hTcxDec->L_frameTCX; i++ )
            {
                synthFB[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) );
                tmp_shift = conceal_eof_gainFB_e;
                synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) );
                move16();
#ifdef BASOP_NOGLOB
                conceal_eof_gainFB = L_sub_o( conceal_eof_gainFB, stepFB, &Overflow );
#else
                conceal_eof_gainFB = L_sub( conceal_eof_gainFB, stepFB );
#endif
                conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e );
            }
        }
        conceal_eof_gain32 = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/
        FOR( i = 0; i < st_fx->L_frame; i++ )
        {
            xn_buf[i] = round_fx( L_shl( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) );
            xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( hTcxDec->conceal_eof_gain32, xn_buf[i] ), hTcxDec->conceal_eof_gain_e ) );
            move16();
#ifdef BASOP_NOGLOB
            conceal_eof_gain32 = L_sub_o( conceal_eof_gain32, step, &Overflow );
#else
            conceal_eof_gain32 = L_sub( conceal_eof_gain32, step );
#endif
            hTcxDec->conceal_eof_gain32 = BASOP_Util_Add_Mant32Exp( hTcxDec->conceal_eof_gain32, hTcxDec->conceal_eof_gain_e, L_negate( step ), step_e, &hTcxDec->conceal_eof_gain_e );
            move32();
        }
#ifdef BASOP_NOGLOB
        hTcxDec->conceal_eof_gain = round_fx_o( conceal_eof_gain32, &Overflow ); /*Q14*/
        move16();
#else
        hTcxDec->conceal_eof_gain = round_fx( conceal_eof_gain32 ); /*Q14*/
        move16();
#endif
        Word32 temp = 0;
        FOR( i = 0; i < hTcxDec->L_frameTCX; i++ )
        {
            temp = L_add_sat( temp, abs( synthFB[i] ) );
        }

        /* run lpc gain compensation not for waveform adjustment */
        test();
        IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) )
@@ -1901,12 +1918,12 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
        }
        st_fx->plcInfo.step_concealgain_fx =
#ifdef BASOP_NOGLOB
            round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( step ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 3 ) ); /*Q15*/
            round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( L_shr_sat( step, sub( 1, step_e ) ) ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 4 ) ); /*Q15*/
#else
            round_fx( L_shl( L_mult0(
                                 round_fx( step ),
                                 round_fx( L_shr( step, sub( 1, step_e ) ),
                                 round_fx( L_shl( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ),
                             3 ) ); /*Q15*/
                             4 ) ); /*Q15*/
#endif
        move16();
    }
@@ -2830,11 +2847,12 @@ void IMDCT_ivas_fx(
    test();
    IF( st->element_mode != EVS_MONO && ( frame_cnt == 0 ) && ( bfi == 0 ) && ( st->prev_bfi != 0 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && ( hTcxCfg->last_aldo == 0 ) )
    {
        Word16 fac;
        fac = shl_sat( mult_r( hTcxDec->conceal_eof_gain, st->last_concealed_gain_syn_deemph ), 1 );
        Word32 fac;
        // fac = shl_sat( mult_r( extract_h( L_shr_sat( hTcxDec->conceal_eof_gain32, sub( 1, hTcxDec->conceal_eof_gain_e ) ) ), st->last_concealed_gain_syn_deemph ), 1 );
        fac = Mpy_32_16_1( hTcxDec->conceal_eof_gain32, st->last_concealed_gain_syn_deemph ); // q = 31 - hTcxDec->conceal_eof_gain_e
        FOR( Word16 ind = 0; ind < overlap; ind++ )
        {
            old_syn_overl_fx[ind] = mult_r( old_syn_overl_fx[ind], fac );
            old_syn_overl_fx[ind] = extract_l( L_shl_sat( Mpy_32_32( old_syn_overl_fx[ind], fac ), hTcxDec->conceal_eof_gain_e ) );
            move16();
        }
    }
Loading