Commit 8dc3f9cf authored by vaillancour's avatar vaillancour
Browse files

fix more encoder possible saturation

parent 00e70364
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -1171,8 +1171,13 @@ AnalysisPostSpectrumScaling_Fx (HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle
    {
        FOR (j=0; j < cldfbBank->no_channels; j++)
        {
#ifdef BASOP_NOGLOB
            rSubband16[i][j] = round_fx_sat( L_shl_sat( rSubband32[i][j], headRoom ) );
            iSubband16[i][j] = round_fx_sat(L_shl_sat(iSubband32[i][j], headRoom));
#else
            rSubband16[i][j] = round_fx( L_shl( rSubband32[i][j], headRoom ) );
            iSubband16[i][j] = round_fx(L_shl(iSubband32[i][j], headRoom));
#endif
        }
    }

+16 −1
Original line number Diff line number Diff line
@@ -78,6 +78,20 @@ Word16 E_ACELP_toeplitz_mul_fx(
        L_maxloc = L_shr(L_maxloc, 2);
        /* Do not warn saturation of L_tot, since its for headroom estimation. */
        BASOP_SATURATE_WARNING_OFF_EVS
#ifdef BASOP_NOGLOB
        L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */
        L_maxloc = L_shr(L_maxloc, 1);
        L_tot = L_add_sat(L_tot, L_maxloc);           /* +max/8 */
        if ( highrate )
        {
            L_tot = L_add_sat(L_tot, L_maxloc);       /* +max/8 */
        }
        L_maxloc = L_shr(L_maxloc, 1);
        if ( highrate )
        {
            L_tot = L_add_sat(L_tot, L_maxloc);       /* +max/16 */
        }
#else
        L_tot = L_add( L_tot, L_maxloc ); /* +max/4 */
        L_maxloc = L_shr(L_maxloc, 1);
        L_tot = L_add(L_tot, L_maxloc);           /* +max/8 */
@@ -90,6 +104,7 @@ Word16 E_ACELP_toeplitz_mul_fx(
        {
            L_tot = L_add(L_tot, L_maxloc);       /* +max/16 */
        }
#endif
        BASOP_SATURATE_WARNING_ON_EVS
    }

+6 −1
Original line number Diff line number Diff line
@@ -399,8 +399,13 @@ Word16 bass_pf_enc_fx(
        /* *gain_factor_param = (int)(-2.f*(cross_n_d/nrg_n)+0.5f); */
        tmp16 = BASOP_Util_Divide3232_Scale(cross_n_d, nrg_n, &st); /* Q15-st-s3+s4 */
        BASOP_SATURATE_WARNING_OFF_EVS;
#ifdef BASOP_NOGLOB
        tmp16 = shl_sat( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */
        tmp16 = shr(add_sat(tmp16, 1), 1); /* Q0 */
#else
        tmp16 = shl( negate( tmp16 ), add( sub( add( st, s3 ), s4 ), 1 - 14 ) ); /* Q1 */
        tmp16 = shr(add(tmp16, 1), 1); /* Q0 */
#endif
        BASOP_SATURATE_WARNING_ON_EVS;

        *gain_factor_param = tmp16;
+34 −6
Original line number Diff line number Diff line
@@ -657,19 +657,31 @@ void CNG_enc_fx(
                    FOR ( j=0; j<m1; j++ )
                    {
                        /* env[i] += tmp_env[j*NUM_ENV_CNG+i]; */
#ifdef BASOP_NOGLOB
                        L_tmp = L_add_sat( L_tmp, tmp_env[j * NUM_ENV_CNG + i] );
#else
                        L_tmp = L_add( L_tmp, tmp_env[j * NUM_ENV_CNG + i] );
#endif
                    }
                    /*    env[i] /= (float)m1;  */
                    /*    env[i] = env[i] - 2*hTdCngEnc->lp_ener_fx; */
                    IF(EQ_16(m1,1))
                    {
#ifdef BASOP_NOGLOB
                        L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) );
#else
                        L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) );
#endif
                    }
                    ELSE
                    {
                        tmp1 = div_s(1,m1);
                        L_tmp = Mult_32_16(L_tmp,tmp1);
#ifdef BASOP_NOGLOB
                        L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) );
#else
                        L_tmp = L_sub( L_tmp, L_add( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) );
#endif
                    }

                    env[i] = L_tmp;
@@ -795,9 +807,15 @@ void CNG_enc_fx(
            L_tmp = L_mult0(tmpv, tmpv);
            pt_res++;
            tmpv = shl(*pt_res,scale);
#ifdef BASOP_NOGLOB
            L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */
            pt_res++;
            L_ener = L_add_sat(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */
#else
            L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */
            pt_res++;
            L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */
#endif
        }
    }
    ELSE /* L_FRAME16k */
@@ -808,9 +826,15 @@ void CNG_enc_fx(
            L_tmp = L_mult0(tmpv, tmpv);
            pt_res++;
            tmpv = shl(*pt_res,scale);
#ifdef BASOP_NOGLOB
            L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */
            pt_res++;
            L_ener = L_add_sat(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */
#else
            L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */
            pt_res++;
            L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */
#endif
        }
    }
    /* convert log2 of residual signal energy */
@@ -1365,7 +1389,11 @@ static Word16 shb_DTX_fx(
    shb_ener_fx = L_deposit_l(0);
    FOR ( i=0; i<L_FRAME16k; i++ )
    {
#ifdef BASOP_NOGLOB
        shb_ener_fx = L_mac_sat( shb_ener_fx, shb_old_speech_fx[i], shb_old_speech_fx[i] );
#else
        shb_ener_fx = L_mac( shb_ener_fx, shb_old_speech_fx[i], shb_old_speech_fx[i] );
#endif
    }

    shb_ener_fx = L_add(Mpy_32_16_1(shb_ener_fx, 102), 1); /* 102 in Q15, shb_ener_fx in Q1 */
+10 −2
Original line number Diff line number Diff line
@@ -2304,7 +2304,11 @@ void QuantizeSpectrum_fx(
                        /* add part of current sub-window overlapping with previous window */
                        FOR (i = 0; i < L_ola; i++)
                        {
#ifdef BASOP_NOGLOB
                            tmpP16[i] = add_sat( tmpP16[i], win[i] );
#else
                            tmpP16[i] = add( tmpP16[i], win[i] );
#endif
                            move16();
                        }
                        /* copy new sub-window region not overlapping with previous window */
@@ -2387,7 +2391,11 @@ void QuantizeSpectrum_fx(
                    /* add part of current sub-window overlapping with previous window */
                    FOR (i = 0; i < L_ola; i++)
                    {
#ifdef BASOP_NOGLOB
                        tmpP16[i] = add_sat( tmpP16[i], win[i] );
#else
                        tmpP16[i] = add( tmpP16[i], win[i] );
#endif
                        move16();
                    }

Loading