Commit 326b0ee0 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'bug_fixes_igf_swb_tbe_tcx_core' into 'main'

Bug fixes in igf, swb_tbe and tcx_core

See merge request !1042
parents d08351b3 c4bb367f
Loading
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -10830,8 +10830,8 @@ void ProcessStereoIGF_fx(
    Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV],        /* i  : inverse spectrum                        */
    const Word16 frameno,                                 /* i  : flag indicating index of current subfr. */
    const Word16 sp_aud_decision0,                        /* i  : sp_aud_decision0                        */
    const Word32 element_brate                            /* i  : element bitrate                         */
);
    const Word32 element_brate,                           /* i  : element bitrate                         */
    const Word16 mct_on );
/*igf_enc.c*/
void IGFEncApplyStereo_fx(
    STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct,              /* i/o: MDCT stereo encoder structure           */
@@ -10844,8 +10844,8 @@ void IGFEncApplyStereo_fx(
    Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV],        /* i  : inverse spectrum                        */
    const Word16 frameno,                                 /* i  : flag indicating index of current subfr. */
    const Word16 sp_aud_decision0,                        /* i  : sp_aud_decision0                        */
    const Word32 element_brate                            /* i  : element bitrate                         */
);
    const Word32 element_brate,                           /* i  : element bitrate                         */
    const Word16 mct_on );
void IGFSaveSpectrumForITF_ivas_fx(
    IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder  */
+1 −1
Original line number Diff line number Diff line
@@ -3753,7 +3753,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    IF( LT_32( bitrate, ACELP_24k40 ) )
#endif
    {
        syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 );
        Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 );
        /* i: exc16kWhtnd in Q_bwe_exc */
        /* o: excSHB in Q_bwe_exc */
    }
+5 −5
Original line number Diff line number Diff line
@@ -703,7 +703,7 @@ static void IGF_CalculateEnvelope_ivas_fx(
                        BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb], negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &diffSFM );

                        test();
                        IF( diffSFM > 0 && LT_32( hPrivateData->SFM_tb_fx[sfb], L_shr( 3277 /*0.1 Q15*/, tmp_tb_e ) ) ) /* check whether target SFB is more tonal than source SFB */
                        IF( diffSFM > 0 && LT_32( hPrivateData->SFM_tb_fx[sfb], L_shr( 3277 /*0.1 Q15*/, hPrivateData->sfb_tb_e[sfb] ) ) ) /* check whether target SFB is more tonal than source SFB */
                        {
                            Word16 currDampingFactor, dampingFactor;
                            Word16 slope, threshold;
@@ -2668,7 +2668,7 @@ void IGFEncApplyMono_ivas_fx(
            move16();
        }
    }
    IGF_ErodeSpectrum( &highPassEner_exp, st->hIGFEnc, pMDCTSpectrum_fx, pPowerSpectrumParameter_fx, common_pPowerSpectrum_exp, igfGridIdx );
    IGF_ErodeSpectrum_ivas_fx( &highPassEner_exp, st->hIGFEnc, pMDCTSpectrum_fx, pPowerSpectrumParameter_fx, common_pPowerSpectrum_exp, igfGridIdx, 0 );
}


@@ -2689,8 +2689,8 @@ void IGFEncApplyStereo_fx(
    Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV],        /* i  : inverse spectrum                        */
    const Word16 frameno,                                 /* i  : flag indicating index of current subfr. */
    const Word16 sp_aud_decision0,                        /* i  : sp_aud_decision0                        */
    const Word32 element_brate                            /* i  : element bitrate                         */
)
    const Word32 element_brate,                           /* i  : element bitrate                         */
    const Word16 mct_on )
{
    Word16 highPassEner_exp;
    Word32 *pPowerSpectrumParameter_fx[NB_DIV]; /* If it is NULL it informs a function that specific handling is needed */
@@ -2766,7 +2766,7 @@ void IGFEncApplyStereo_fx(

        IGF_Whitening_ivas_fx( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], &exp_pPowerSpectrum[0], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode );

        IGF_ErodeSpectrum( &highPassEner_exp, hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], sts[ch]->hTcxEnc->spectrum_e[frameno], igfGridIdx );
        IGF_ErodeSpectrum_ivas_fx( &highPassEner_exp, hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], sts[ch]->hTcxEnc->spectrum_e[frameno], igfGridIdx, mct_on );
    }
    return;
}
+193 −0
Original line number Diff line number Diff line
@@ -516,6 +516,199 @@ void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< ou
    }
}

void IGF_ErodeSpectrum_ivas_fx( Word16 *highPassEner_exp,                /**< out:    | exponent of highPassEner       */
                                const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in:     | instance handle of IGF Encoder */
                                Word32 *pSpectrum,                       /**< in/out: | MDCT spectrum                  Qx*/
                                Word32 *pPowerSpectrum,                  /**< in/out: | power spectrum                 */
                                Word16 pPowerSpectrum_exp,               /**< in:     | exponent of power spectrum     */
                                const Word16 igfGridIdx,                 /**< in: Q0  | IGF grid index                 */
                                const Word16 mct_on )
{
    IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData;
    H_IGF_GRID hGrid;
    Word16 i;
    Word16 igfBgn;
    Word16 igfEnd;
    Word32 highPassEner; /* Q31 */
    Word32 lastLine;
    Word32 nextLine;
    Word32 L_c;
    Word32 highPassEner_Ovfl;
    Word16 s;
    Word16 tmploop;
    Word16 *swb_offset;
    Word16 sfb;
    Word16 startSfb;
    Word16 stopSfb;
    Word16 line;
    Word16 flag;
    Word16 *igfScaleF;
    Word16 tmp;
    Word32 L_tmp;

#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    Flag Carry = 0;
    move32();
    move32();
#endif

    hPrivateData = &hInstance->igfData;
    hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
    igfBgn = hGrid->startLine;
    move16();
    igfEnd = hGrid->stopLine;
    move16();
    swb_offset = hGrid->swb_offset;
    move16();
    startSfb = hGrid->startSfb;
    move16();
    stopSfb = hGrid->stopSfb;
    move16();
    igfScaleF = hPrivateData->igfScfQuantized;
    move16();
    *highPassEner_exp = 0;
    move16();
    highPassEner = 0;
    move32();

    IF( NULL == pPowerSpectrum )
    {
        FOR( i = igfBgn; i < hGrid->infoGranuleLen; i++ )
        {
            pSpectrum[i] = 0;
            move32();
        }
        return;
    }

    IF( igfBgn > 0 )
    {
        L_c = 0;
        move32();
        FOR( i = 0; i < igfBgn; i++ )
        {
            Carry = 0;
            highPassEner = L_add_co( highPassEner, Mpy_32_16_1( pPowerSpectrum[i], shl( i, 4 ) /*Q4*/ ) /*Q20, pPowerSpectrum_exp*/, &Carry, &Overflow );
            Overflow = 0;
            L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow );
        }

        highPassEner = norm_llQ31( L_c, highPassEner, highPassEner_exp ); /*Q20, highPassEner_exp*/
        *highPassEner_exp = add( *highPassEner_exp, pPowerSpectrum_exp );
        test();
        test();
        test();
        test();
        test();
        IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_9600 ) ||
            EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_RF_SWB_13200 ) ||
            EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_13200 ) ||
            EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_16400_CPE ) )
        {
            igfBgn = shl( igfBgn, 0 );
        }
        ELSE IF( mct_on && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) ) )
        {
            igfBgn = imult1616( igfBgn, 45 /*0.7.Q6*/ );
            igfBgn = shr( igfBgn, 7 );
        }
        ELSE
        {
            igfBgn = shl( igfBgn, 1 );
        }
        highPassEner = L_deposit_l( BASOP_Util_Divide3216_Scale( highPassEner /*Q20, highPassEner_exp*/, igfBgn /*Q0*/, &s ) ); /*Q15, highPassEner_exp+11-16+s*/
        *highPassEner_exp = add( add( *highPassEner_exp, s ), 12 - 16 + ( 31 - 15 ) );                                          /*Q15->Q31,highPassEner_exp*/
        lastLine = pSpectrum[i - 1];
        move32();
        nextLine = 0;
        move32();

        /* May overflow - just for threshold comparison                                                   */
        /* negate because the negated may be 1 larger in abs,                                             */
        /* so whenever compared to the negation of a maximum possible pPowerspectrum, it is still larger  */
        highPassEner_Ovfl = L_shl_o( L_negate( highPassEner ), sub( *highPassEner_exp, pPowerSpectrum_exp ), &Overflow );
        L_tmp = L_add_o( pPowerSpectrum[i - 1], highPassEner_Ovfl, &Overflow );

        if ( L_tmp >= 0 )
        {
            nextLine = pSpectrum[i];
            move32();
        }
        tmploop = sub( igfEnd, 1 );
        FOR( /*i*/; i < tmploop; i++ )
        {
            /* May overflow - just for threshold comparison */
            BASOP_SATURATE_WARNING_OFF_EVS
            L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl );
            BASOP_SATURATE_WARNING_ON_EVS;

            IF( L_tmp < 0 )
            {
                lastLine = pSpectrum[i];
                move32();
                pSpectrum[i] = nextLine;
                move32();
                nextLine = 0;
                move32();
            }
            ELSE
            {
                pSpectrum[i - 1] = lastLine;
                move32();
                lastLine = pSpectrum[i];
                move32();
                nextLine = pSpectrum[i + 1];
                move32();
            }
        }

        /* May overflow - just for threshold comparison */
        BASOP_SATURATE_WARNING_OFF_EVS
        L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl );
        BASOP_SATURATE_WARNING_ON_EVS
        if ( L_tmp < 0 )
        {
            pSpectrum[i] = 0;
            move32();
        }
    }

    /* delete spectrum above igfEnd: */
    FOR( i = igfEnd; i < hGrid->infoGranuleLen; i++ )
    {
        pSpectrum[i] = 0;
        pPowerSpectrum[i] = 0;
        move32();
        move32();
    }

    FOR( sfb = startSfb; sfb < stopSfb; sfb++ )
    {
        flag = 0;
        move16();
        FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ )
        {
            if ( pSpectrum[line] != 0 )
            {
                flag = 1;
                move16();
            }
        }
        tmp = igfScaleF[sfb];
        move16();
        IF( flag )
        {
            tmp = sub( igfScaleF[sfb], 1 );
        }
        if ( igfScaleF[sfb] )
        {
            igfScaleF[sfb] = tmp;
            move16();
        }
    }
}

/**********************************************************************/ /*
crest factor calculation
**************************************************************************/
+1 −1
Original line number Diff line number Diff line
@@ -1088,7 +1088,7 @@ void mctStereoIGF_enc_fx(

                ProcessStereoIGF_fx( hMCT->hBlockData[b]->hStereoMdct, p_st, hMCT->hBlockData[b]->mask,
                                     p_orig_spectrum_fx, q_origSpec, q_origSpec,
                                     p_powerSpec_fx, p_powerSpecMsInv_fx, p_inv_spectrum_fx, n, sp_aud_decision0[ch1], p_st[0]->total_brate );
                                     p_powerSpec_fx, p_powerSpecMsInv_fx, p_inv_spectrum_fx, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 );
            }
            ELSE
            {
Loading