Commit 519d8489 authored by Anjaneyulu Sana's avatar Anjaneyulu Sana
Browse files

Merge branch 'ltv_crash_fixes_apr_15' into 'main'

Fixes for crashes observed on LTV pipeline

See merge request !1420
parents 3f91f622 2700c956
Loading
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1171,13 +1171,13 @@ static void IGF_CalculateStereoEnvelope_fx(
                    move16();

                    // tmp_tb = IGF_getSFM_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]);
                    sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] );
                    sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] );
                    crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] );
                    tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e );
                    tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/

                    // tmp_sb = IGF_getSFM_ivas(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest_ivas(tileSrcSpec, 0, strt_cpy - tmp);
                    sfm = IGF_getSFM( &sfm_exp, tileSrcSpec_fx, &tileSrcSpec_e, 0, sub( strt_cpy, tmp ) );
                    sfm = IGF_getSFM_ivas_fx( &sfm_exp, tileSrcSpec_fx, &tileSrcSpec_e, 0, sub( strt_cpy, tmp ) );
                    crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) );
                    tmp_sb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e );
                    tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_sb_fx*/
@@ -1322,7 +1322,7 @@ static void IGF_CalculateStereoEnvelope_fx(
                        {
                            Word16 shift = shr( width, 1 );
                            // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift );
                            sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) );
                            sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) );
                            crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) );
                            shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e );
                        }
@@ -1331,7 +1331,7 @@ static void IGF_CalculateStereoEnvelope_fx(
                            Word16 shift;
                            shift = shr( width, 1 );
                            // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift );
                            sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) );
                            sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) );
                            crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) );
                            shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e );
                        }
+97 −0
Original line number Diff line number Diff line
@@ -895,6 +895,103 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value
    return SFM /*Q15*/;
}

/*************************************************************************
calculates spectral flatness measurment
**************************************************************************/
Word16 IGF_getSFM_ivas_fx(                           /**< out: Q15| SFM value              */
                           Word16 *SFM_exp,          /**< out:    | exponent of SFM Factor */
                           const Word32 *energy,     /**< in:  Q31| energies               */
                           const Word16 *energy_exp, /**< in:     | exponent of energies   */
                           const Word16 start,       /**< in:  Q0 | start subband index    */
                           const Word16 stop         /**< in:  Q0 | stop subband index     */
)
{
    Word16 n, i, s;
    Word32 num;
    Word32 denom;
    Word16 denom_exp;
    Word16 invDenom_exp, numf_exp;
    Word16 numf;
    Word32 SFM32;
    Word16 invDenom, SFM;

    num = 0;
    move32();
    denom = 65536; // 1.f in Q16
    denom_exp = 15;
    *SFM_exp = 0;
    move16();
    SFM = 32767 /*1.0f Q15*/;
    move16();

    FOR( i = start; i < stop; i++ )
    {
        /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/

        /* n       = sub(sub(31,norm_l(tmp32)),1);  */ /*<- ld    */
        /* n       = sub(n,31);                     */ /*<- -Qx   */
        /* n       = add(n,*energy_exp);            */ /*<- +xExp */

        n = sub( sub( *energy_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/

        if ( energy[i] == 0 ) /*special case: energy is zero*/
        {
            n = 0;
            move16();
        }

        n = s_max( 0, n );
        num = L_add( num, L_deposit_l( n ) ); /*Q0*/

        denom = BASOP_Util_Add_Mant32Exp( energy[i], *energy_exp, denom, denom_exp, &denom_exp );
    }

    /* calculate SFM only if signal is present */
    IF( denom != 0 )
    {
        /*numf   = (float)num / (float)(stop - start);*/
        numf = BASOP_Util_Divide3216_Scale( num,                /*Q0*/
                                            sub( stop, start ), /*Q0*/
                                            &s );               /*Q-1 s*/
        numf_exp = add( s, 16 );                                /*-> numf Q15 numf_exp*/
        /*denom /= (float)(stop - start);*/
        /*return ((float)pow(2.0, numf + 0.5f) / denom);*/

        /*SFM= ((float)pow(2.0, numf + 0.5f) * invDenom);*/
        invDenom = BASOP_Util_Divide3232_uu_1616_Scale( L_deposit_l( sub( stop, start ) ) /*Q0*/,
                                                        denom /*Q31, denom_exp*/,
                                                        &s ); /*Q-16, s-denom_exp*/
        invDenom_exp = add( sub( s, denom_exp ), 31 );        /*invDenom: Q15, invDenom_exp*/

        /*add .5f to numf*/
        SFM32 = L_add( L_shl( L_deposit_l( numf ), numf_exp ) /*16Q15*/, 16384l /*.5f Q15*/ ); /*16Q15*/
        s = norm_l( SFM32 );
        SFM32 = L_shl( SFM32, s );
        s = sub( 16, s ); /*SFM32(numf) is Q31 now*/

        /*do the pow2 and the mult*/
        SFM32 = BASOP_util_Pow2( SFM32, s, &s );
        SFM32 = Mpy_32_16_1( SFM32, invDenom );
        *SFM_exp = add( s, invDenom_exp );

        /*Transform to Q15*/
        s = norm_l( SFM32 );
        SFM = round_fx_sat( L_shl_sat( SFM32, s ) );
        *SFM_exp = sub( *SFM_exp, s );
        move16();
        /**SFM_exp = s_min(*SFM_exp, 0);*/
        IF( *SFM_exp > 0 )
        {
            *SFM_exp = 0;
            move16();
            SFM = 32767 /*1.0f Q15*/;
            move16();
        }
    }

    return SFM /*Q15*/;
}

/**********************************************************************/ /*
calculates the IGF whitening levels by SFM and crest
**************************************************************************/
+7 −0
Original line number Diff line number Diff line
@@ -3066,6 +3066,13 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value
                   const Word16 start,       /**< in:  Q0 | start subband index    */
                   const Word16 stop         /**< in:  Q0 | stop subband index     */
);
Word16 IGF_getSFM_ivas_fx(                           /**< out: Q15| SFM value              */
                           Word16 *SFM_exp,          /**< out:    | exponent of SFM Factor */
                           const Word32 *energy,     /**< in:  Q31| energies               */
                           const Word16 *energy_exp, /**< in:     | exponent of energies   */
                           const Word16 start,       /**< in:  Q0 | start subband index    */
                           const Word16 stop         /**< in:  Q0 | stop subband index     */
);
/* IGFEnc.c */
void IGF_ErodeSpectrum( Word16 *highPassEner_exp,                /**< out:    | exponent of highPassEner       */
                        const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in:     | instance handle of IGF Encoder */
+17 −2
Original line number Diff line number Diff line
@@ -1937,6 +1937,7 @@ Word16 ivas_smc_gmm_fx(
    /* calculation of differential normalized power spectrum */
    sum_PS_fx = 0;
    move32();
    Word16 q_temp32;
    Word16 sum_PS_e = 0;
    move16();
    Word64 sum = W_shl( 21475 /* 1e-5 in Q31 */, sub( Qfact_PS, 30 ) ); // Qfact_PS+1
@@ -1962,7 +1963,21 @@ Word16 ivas_smc_gmm_fx(
    FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ )
    {
        temp32 = BASOP_Util_Divide3232_Scale_cadence( PS_fx[i], sum_PS_fx, &temp_exp ); // 31-temp_exp
        PS_norm_fx[i] = L_shl( temp32, sub( Qfact_PS_past, add( sub( 31, temp_exp ), sub( Qfact_PS, sub( 31, sum_PS_e ) ) ) ) ); // Qfact_PS_past
        q_temp32 = add( sub( 31, temp_exp ), sub( Qfact_PS, sub( 31, sum_PS_e ) ) );
        test();
        if ( temp32 == 0 )
        {
            q_temp32 = 31;
            move16();
        }
        IF( LT_16( q_temp32, 31 ) && EQ_32( temp32, L_shl( 1, q_temp32 ) ) )
        {
            temp32 = ONE_IN_Q31;
            move32();
            q_temp32 = Q31;
            move16();
        }
        PS_norm_fx[i] = L_shl( temp32, sub( Qfact_PS_past, q_temp32 ) ); // Qfact_PS_past
        move32();
        dPS_fx[i] = L_abs( L_sub( PS_norm_fx[i], hSpMusClas->past_PS_fx[i - LOWEST_FBIN] ) );
        move32();