Commit 441ff193 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Fixed point changes for NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO to address...

Fixed point changes for NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO to address potential division by zero in hq_classifier
parent b77818d5
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -81,4 +81,5 @@
#define FIX_QMETADATA_PENALTY /* Nokia: transform penalty calculation in qmetadata into integer operations */
#define FIX_1013_CRASH_HQ_CORE_DEC /* Ittiam: Saturation added on the lines of EVS */
#define NONE_BE_FIX_BASOP_1044_OSBA_PRERENDER_MIX_GAINS /* DLB: adjust prerendering and mixing gain in OSBA encoder. This is fix to float codes*/
#define NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO            /* Eri: issue 1233: Address possible division by zero in hf_spectrum_sparseness() */
#endif
+77 −55
Original line number Diff line number Diff line
@@ -57,9 +57,12 @@ static Word16 hf_spectrum_sparseness_fx(
    Word32 crest_mod_fx;
    const Word16 *p_num_fx;
    Word32 A_fx[960];
    int16_t result;
    Word16 result;
    Word32 *crest_lp_fx;
    Word32 *crest_mod_lp_fx;
    Word32 hq_crest_threshold, hq_crest_mod_threshold;
    Word16 inv_rms32_e = 0;
    move16();

    crest_lp_fx = &st->hHQ_core->crest_lp_fx;
    crest_mod_lp_fx = &st->hHQ_core->crest_mod_lp_fx;
@@ -81,6 +84,18 @@ static Word16 hf_spectrum_sparseness_fx(
        crest_mod_fx = 0;
        move32();
        maximum_l( A_fx, L_SPEC_HB, &Amax_fx );
#ifdef NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO
        IF( Amax_fx == 0 )
        {
            /* For all-zero input the crest is 1.0 */
            crest_fx = L_shl( 1, st->hHQ_core->crest_lp_q );
            crest_mod_fx = L_shl( 1, st->hHQ_core->crest_mod_lp_q );
            low_count_fx = 0;
            move16();
        }
        ELSE
        {
#endif
            thr_fx = Mpy_32_32( Amax_fx, PEAK_THRESHOLD_FX );
            movmean_fx = 0;                              /* avoid uninitialized warning */
                                                         // p_num = &inv_tbl[HALF_WIN_LENGTH + 1];       /* Table for division 1./(11:21) */
@@ -130,8 +145,6 @@ static Word16 hf_spectrum_sparseness_fx(
            Word16 l_shift = W_norm( inv_rms_fx );
            inv_rms32_fx = W_extract_h( W_shl( inv_rms_fx, l_shift ) ); // Q15+l_shift-32
            Word16 q_rms = sub( add( Q15, l_shift ), 32 );              // q_rms
        Word16 inv_rms32_e = 0;
        move16();
            inv_rms32_div_fx = BASOP_Util_Divide3232_Scale_cadence( inv_rms32_fx, L_SPEC_HB, &inv_rms32_e );
            inv_rms32_e = sub( 31, add( sub( Q31, inv_rms32_e ), q_rms ) );
            // inv_rms = 1.0f / (float) sqrtf( inv_rms / L_SPEC_HB );
@@ -142,12 +155,21 @@ static Word16 hf_spectrum_sparseness_fx(
            *crest_lp_fx = L_shr( *crest_lp_fx, sub( st->hHQ_core->crest_lp_q, sub( Q12, inv_rms32_e ) ) );
            move32();
            st->hHQ_core->crest_lp_q = sub( Q12, inv_rms32_e );
        *crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, ( *crest_lp_fx ) ), Mpy_32_32( ONE_IN_Q31 - HQ_CREST_FAC_SM_FX, crest_fx ) ); // Q12 - inv_rms32_e
            move16();
            *crest_mod_lp_fx = L_shr( *crest_mod_lp_fx, sub( st->hHQ_core->crest_mod_lp_q, sub( Q12, inv_rms32_e ) ) );
            move32();
            st->hHQ_core->crest_mod_lp_q = sub( Q12, inv_rms32_e );
        *crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, ( *crest_mod_lp_fx ) ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), crest_mod_fx ) ); // Q12 - inv_rms32_e
        Word32 hq_crest_threshold = L_shr( HQ_CREST_THRESHOLD_FX, sub( Q28, sub( Q12, inv_rms32_e ) ) );
        Word32 hq_crest_mod_threshold = L_shr( HQ_CREST_MOD_THRESHOLD_FX, sub( Q29, sub( Q12, inv_rms32_e ) ) );
            move16();
#ifdef NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO
        }
#endif
        *crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, ( *crest_lp_fx ) ), Mpy_32_32( ONE_IN_Q31 - HQ_CREST_FAC_SM_FX, crest_fx ) ); /* Q(st->hHQ_core->crest_lp_q) */
        move32();
        *crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, ( *crest_mod_lp_fx ) ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), crest_mod_fx ) ); /* Q(st->hHQ_core->crest_mod_lp_q) */
        move32();

        hq_crest_threshold = L_shr( HQ_CREST_THRESHOLD_FX, sub( Q28, st->hHQ_core->crest_lp_q ) );             /* Q(st->hHQ_core->crest_lp_q) */
        hq_crest_mod_threshold = L_shr( HQ_CREST_MOD_THRESHOLD_FX, sub( Q29, st->hHQ_core->crest_mod_lp_q ) ); /* Q(st->hHQ_core->crest_mod_lp_q) */
        test();
        test();
        if ( GT_32( ( *crest_lp_fx ), hq_crest_threshold ) && GT_32( ( *crest_mod_lp_fx ), hq_crest_mod_threshold ) && GT_16( low_count_fx, LOW_COUNT_THRESHOLD ) )