Commit 050dd68f authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'ltv_crash_fix_bug_and_warning_fix' into 'main'

LTV crash fix for -10dB OMASA, warning fix and bug fix in swb_tbe_enc

See merge request !990
parents 6331b380 fa1ef3d9
Loading
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -585,9 +585,14 @@ ivas_error pre_proc_ivas_fx(
        {
            return error;
        }

        test();
        IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
        {
            *epsP_fx_q = add( Q_r[0], 1 );
            move16();
        }
    }
    test();
    IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) )
    {
+260 −12
Original line number Diff line number Diff line
@@ -63,6 +63,16 @@ static void EstimateSHBFrameGain_fx( const Word16 length,
                                     const Word16 *subwin_shb,
                                     const Word16 n_subfr_saturation );

static void EstimateSHBFrameGain_ivas_fx( const Word16 length,
                                          const Word16 *oriSHB,
                                          const Word16 Q_oriSHB,
                                          const Word16 *synSHB,
                                          const Word16 Q_synSHB,
                                          Word16 *subgain,
                                          Word32 *GainFrame,
                                          const Word16 *win_shb,
                                          const Word16 *subwin_shb,
                                          const Word16 n_subfr_saturation );

static void EstimateSHBGainShape_fx( const Word16 length,
                                     const Word16 *oriSHB,
@@ -1243,6 +1253,7 @@ void wb_tbe_enc_fx(

    /* Adjust the subframe and frame gain of the synthesized SHB signal */
    /* Scale the shaped excitation*/

    ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx,
                       &Q_bwe_exc_ext, &dummy, dummy, dummy );

@@ -1377,7 +1388,7 @@ void wb_tbe_enc_ivas_fx(
    /* convert into lsps and calculate weights */
    FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ )
    {
        lpc_wb_32_fx[i] = L_negate( L_deposit_h( L_shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27
        lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27
        move32();
    }

@@ -1704,7 +1715,11 @@ void wb_tbe_enc_ivas_fx(

    Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp );
    L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */
#ifdef BASOP_NOGLOB
    shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */
#else
    shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */
#endif
    move16();

    /* Update WB excitation */
@@ -1825,7 +1840,7 @@ void wb_tbe_enc_ivas_fx(
    }

    /* Estimate the gain parameter */
    EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape,
    EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape,
                                  &GainFrame, window_wb_fx, subwin_wb_fx, 0 );


@@ -1909,9 +1924,14 @@ void wb_tbe_enc_ivas_fx(

    /* Adjust the subframe and frame gain of the synthesized SHB signal */
    /* Scale the shaped excitation*/

    scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 );
    scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 );
    Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 );
    ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx,
                       &Q_bwe_exc_ext, &dummy, dummy, dummy );

    Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 );
    st_fx->prev_Q_bwe_exc = Q_bwe_exc;
    move16();

@@ -4122,7 +4142,7 @@ void swb_tbe_enc_ivas_fx(
    }

    /* Estimate the gain parameter */
    EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc,
    EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc,
                                  GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation );

    IF( EQ_16( st_fx->tec_tfa, 1 ) )
@@ -4475,7 +4495,6 @@ void swb_tbe_enc_ivas_fx(
/* RETURN ARGUMENTS : */
/* _ None */
/*--------------------------------------------------------------------------*/

static void EstimateSHBFrameGain_fx(
    const Word16 length,            /* i : SHB overlap length                                                  */
    const Word16 *oriSHB,           /* i : target original SHB frame                               Q(Q_oriSHB) */
@@ -4705,6 +4724,235 @@ static void EstimateSHBFrameGain_fx(
    return;
}

static void EstimateSHBFrameGain_ivas_fx(
    const Word16 length,            /* i : SHB overlap length                                                  */
    const Word16 *oriSHB,           /* i : target original SHB frame                               Q(Q_oriSHB) */
    const Word16 Q_oriSHB,          /* i : Q of arget original SHB frame                                       */
    const Word16 *synSHB,           /* i : shaped SHB excitation                                   Q(Q_synSHB) */
    const Word16 Q_synSHB,          /* i : Q of shaped SHB excitation                                          */
    Word16 *subgain,                /* i : estimate of gain shape                                          Q15 */
    Word32 *GainFrame,              /* o : estimat of gain frame                                           Q18 */
    const Word16 *win_shb,          /* i : SHB window                                                      Q15 */
    const Word16 *subwin_shb_local, /* i : SHB subframe window                                             Q15 */
    const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */
)
{
    const Word16 *skip;
    Word16 i, j, k, l_shb_lahead, l_frame;
    Word16 join_length, num_join, sig;
    Word32 mod_syn[L_FRAME16k + L_SHB_LAHEAD];
    Word32 oriNrg, synNrg;
    Word16 sum_gain;
    Word32 frame_gain;
    Word32 L_tmp;
    Word16 exp_out;
    Word16 tmp;
    Word16 scaling = 0;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
    move16();

    /* initilaization */
    l_frame = L_FRAME16k;
    move16();
    l_shb_lahead = L_SHB_LAHEAD;
    move16();
    skip = skip_bands_SWB_TBE;

    IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) )
    {
        skip = skip_bands_WB_TBE;
        l_frame = L_FRAME16k / 4;
        move16();
        l_shb_lahead = L_SHB_LAHEAD / 4;
        move16();
    }

    /* apply gain for each subframe, and store noise output signal using overlap-add*/
    set32_fx( mod_syn, 0, l_frame + l_shb_lahead );

    IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) )
    {
        sum_gain = 0;
        move16();
        j = skip[0];
        move16();
        FOR( k = 0; k < length / 2; k++ )
        {
            sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */
            mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain );
            move32(); /* Q(16+Q_synSHB) */
            mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] );
            move32(); /* Q(16+Q_synSHB) */
        }

        FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ )
        {
            j = skip[i];
            move16();
            FOR( k = 0; k < length; k++ )
            {
                L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] );                                   /* Q30 */
                sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */
                mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] );
                move32(); /* Q(16+Q_synSHB) */
            }
        }
        FOR( k = 0; k < length / 2; k++ )
        {
            j = skip[i];
            move16();
            sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */
            mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain );
            move32(); /* Q(16+Q_synSHB) */
        }
    }
    ELSE
    {
        num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS;
        move16();
        join_length = i_mult2( num_join, length );
        j = 0;
        move16();
        FOR( k = 0; k < length; k++ )
        {
            sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */
            mod_syn[j] = L_mult0( synSHB[j], sum_gain );
            move32(); /* Q(16+Q_synSHB) */
            j = add( j, 1 );
        }
        FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ )
        {
            FOR( k = 0; k < join_length - length; k++ )
            {
                mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] );
                move32(); /* Q(16+Q_synSHB) */
                j = add( j, 1 );
            }

            FOR( k = 0; k < length; k++ )
            {
                L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] );
                tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */
                mod_syn[j] = L_mult( tmp, synSHB[j] );
                move32(); /* Q(16+Q_synSHB) */
                j = add( j, 1 );
            }
        }
        FOR( k = 0; k < join_length - length; k++ )
        {
            mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] );
            move32(); /* Q(16+Q_synSHB)*/
            j = add( j, 1 );
        }
        FOR( k = 0; k < length; k++ )
        {
            tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */
            mod_syn[j] = L_mult0( tmp, synSHB[j] );
            move32(); /* Q(16+Q_synSHB ) */
            j = add( j, 1 );
        }
    }
    /* adjust frame energy */
    oriNrg = L_deposit_l( 0 );
    synNrg = L_deposit_l( 0 );

    FOR( i = 0; i < l_shb_lahead; i++ )
    {
#ifdef BASOP_NOGLOB
        sig = mult_ro( oriSHB[i], win_shb[i], &Overflow );                   /* Q_oriSHB */
        oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow );                    /* 2*Q_orisHB*/
        sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[i] ), &Overflow ); /*Q_synSHB */
        synNrg = L_mac0_o( synNrg, sig, sig, &Overflow );                    /* 2*Q_synSHB - 2*/
#else
        sig = mult_r( oriSHB[i], win_shb[i] );                              /* Q_oriSHB */
        oriNrg = L_mac0( oriNrg, sig, sig );                                /* 2*Q_orisHB*/
        sig = round_fx( Mult_32_16( mod_syn[i], win_shb[i] ) );             /*Q_synSHB */
        synNrg = L_mac0( synNrg, sig, sig );                                /* 2*Q_synSHB */
#endif
    }

    FOR( ; i < l_frame; i++ )
    {
#ifdef BASOP_NOGLOB
        oriNrg = L_mac0_o( oriNrg, oriSHB[i], oriSHB[i], &Overflow ); /* 2*Q_oriSHB */
        sig = round_fx_o( mod_syn[i], &Overflow );                    /* Q_oriSHB */
        synNrg = L_mac0_o( synNrg, sig, sig, &Overflow );             /* 2*Q_oriSHB - 2*/
#else
        oriNrg = L_mac0( oriNrg, oriSHB[i], oriSHB[i] );                    /* 2*Q_oriSHB */
        sig = round_fx( mod_syn[i] );                                       /* Q_oriSHB */
        synNrg = L_mac0( synNrg, sig, sig );                                /* 2*Q_oriSHB */
#endif
    }

    tmp = add( l_frame, l_shb_lahead );
    FOR( ; i < tmp; i++ )
    {
#ifdef BASOP_NOGLOB
        sig = mult_ro( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i], &Overflow ); /* Q_oriSHB */
        oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow );                               /* 2*Q_oriSHB */

        sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ), &Overflow ); /* Q_oriSHB */
        synNrg = L_mac0_o( synNrg, sig, sig, &Overflow );                                                 /* 2*Q_oriSHB - 2*/
#else
        sig = mult_r( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */
        oriNrg = L_mac0( oriNrg, sig, sig );                                /* 2*Q_oriSHB */

        sig = round_fx( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */
        synNrg = L_mac0( synNrg, sig, sig );                                                 /* 2*Q_oriSHB */
#endif
    }
    IF( EQ_32( oriNrg, MAX_32 ) )
    {
        scaling = negate( add( shr( n_subfr_saturation, 1 ), 1 ) );
        oriNrg = 0;
        move32();
        FOR( i = 0; i < l_shb_lahead; i++ )
        {
#ifdef BASOP_NOGLOB
            sig = mult_r( shl_o( oriSHB[i], scaling, &Overflow ), win_shb[i] );
            oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */
#else
            sig = mult_r( shl( oriSHB[i], scaling ), win_shb[i] );
            oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */
#endif
        }
        FOR( ; i < l_frame; i++ )
        {
#ifdef BASOP_NOGLOB
            sig = shl_o( oriSHB[i], scaling, &Overflow );
            oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */
#else
            sig = shl( oriSHB[i], scaling );
            oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */
#endif
        }
        FOR( ; i < tmp; i++ )
        {
#ifdef BASOP_NOGLOB
            sig = mult_r( shl_o( oriSHB[i], scaling, &Overflow ), win_shb[l_frame + l_shb_lahead - 1 - i] );
            oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */
#else
            sig = mult_r( shl( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] );
            oriNrg = L_mac0( oriNrg, sig, sig );                      /* 2*Q_oriSHB + 2*scaling */
#endif
        }
    }
    L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out );
    exp_out = sub( exp_out, scaling );
#ifdef BASOP_NOGLOB
    frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */
#else
    frame_gain = L_shl( L_tmp, sub( exp_out, 13 ) );                  /* Q18 */
#endif
    *GainFrame = frame_gain;
    move32();

    return;
}


static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step )
{