Commit 70490df6 authored by vaclav's avatar vaclav
Browse files

formatting in vad_fx.c

parent a0df0ffb
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
#define inv_T0_res InvIntTable

static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Word16 *T0_min_frac, Word16 *T0_max, Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, Word16 i_subfr );
#ifdef HARMONIZE_FUNC
static void norm_corr_ivas_fx( const Word16 exc[], const Word16 xn[], const Word16 h[], const Word16 t_min, const Word16 t_max, Word16 ncorr[], const Word16 L_subfr, Word16 Q_new );
#endif


/*==============================================================================*/
/* FUNCTION : pit_encode_fx()                                                   */
@@ -951,7 +955,11 @@ Word16 pitch_fr4_fx(
 * excitation)
 *---------------------------------------------------------------------*/

#ifdef HARMONIZE_FUNC
static void norm_corr_ivas_fx(
#else
void norm_corr_ivas_fx(
#endif
    const Word16 exc[],   /* i  : excitation buffer                          Q_new                */
    const Word16 xn[],    /* i  : target signal                              Q_new-1              */
    const Word16 h[],     /* i  : weighted synthesis filter impulse response Q(14 - norm_s(h[0])) */
+2 −1
Original line number Diff line number Diff line
@@ -831,6 +831,7 @@ void norm_corr_fx(
    const Word16 L_subfr /* i  : subframe size                              */
);

#ifndef HARMONIZE_FUNC
void norm_corr_ivas_fx(
    const Word16 exc[],   /* i  : excitation buffer                          Q_new                */
    const Word16 xn[],    /* i  : target signal                              Q_new-1              */
@@ -841,7 +842,7 @@ void norm_corr_ivas_fx(
    const Word16 L_subfr, /* i  : subframe size                                                   */
    Word16 Q_new          /* i                                                                    */
);

#endif
Word16 peak_avrg_ratio_fx(
    const Word32 total_brate,  /* Q0 */
    const Word32 *input_hi_fx, /* i  : i   signal        Q_coeff*/
+50 −83
Original line number Diff line number Diff line
@@ -13,17 +13,13 @@
/*-----------------------------------------------------------------*
 * Local constants
 *-----------------------------------------------------------------*/
/* old fx constants */
#define HANGOVER_LONG    10 /* Hangover for CNG */
#define HANGOVER_LONG_HE 20 /* Hangover of CNG */
#define HANGOVER_LONG_NB 8  /* Hangover for CNG */
#define ACTIVE_FRAMES    3  /* Number of consecutive active SPEECH frames necessary to trigger HO */

/* SNR threshold curve constants for WB input */
#define SK16_2_FX 16930 /* Q14  (1.0333f)-> Linear function for clean speech */
#define SC16_2_FX -4608 /* Q8   (-18)*/
#define NK16_2_FX 13529 /* Q15  (.41287)-> Linear function for noisy speech  */
#define NC16_2_FX 3394  /* Q8   (13.259625)*/

/* SNR threshold curve constants for NB input */
#define NK8_1_FX    3509  /*Q15 (0.1071f) Linear function for noisy speech  */
#define NC8_1_FX    4224  /*Q8  (16.5f) */
@@ -32,14 +28,12 @@
#define SIGN_THR_FX 40    /*Q4   (2.5f)  Significanse threshold for per band snr calculation */
#define MIN_SNR_FX  2     /*Q4   Minimum snr used for per band snr calculation */


#define THR_M0_FX       3379  /*   Q8 (13.2)  Zero ofset for threshod */
#define THR_K_BG_FX     -8192 /*   Q15(-0.25) Coefficient for dependence on background level */
#define THR_K_BG_OFS_FX 5120  /*   Q8 (20.0f) Zero offset for background level */
#define THR_K_SNR_FX    3277  /*   Q15 (0.1f) Coefficient for dependence on SNR */
#define THR_K_EV_FX     18022 /*   Q15 (0.55) Coefficient for dependence on noise variations */


#define HO_DTX_CLEAN   1  /* Hangover for dtx in clean conditions */
#define HO_DTX_NOISY   10 /* Hangover for dtx in noisy conditions */
#define HO_DTX_NOISY2  4  /* Hangover for dtx in very noisy conditions */
@@ -47,7 +41,6 @@

#define ONE_LG10 2466 /*  1.0*log10(2)  in Q13 */


#define HANGOVER_LONG_FX       10 /* Hangover for CNG */
#define HANGOVER_LONG_MUSIC_FX 20 /* Hangover of CNG */
#define HANGOVER_LONG_HE_FX    20 /* Hangover of CNG */
@@ -61,7 +54,6 @@
#define TH16_2_NFLAG_FX 8960 /* Q8 (35) */
#define TH8_1_NFLAG_FX  8960 /* Q8 (35) */


#define SNR_OUTLIER_WGHT_1_FX 16384 /* Q14  (1.00)*/
#define SNR_OUTLIER_WGHT_2_FX 16548 /* Q14  (1.01)*/
#define SNR_OUTLIER_WGHT_3_FX 16712 /* Q14  (1.02)*/
@@ -74,7 +66,12 @@
#define MAX_SNR_OUTLIER_3_FX   800 /*Q4 (50.0f)*/


/* snr_sum  =   "scale"   * (float)log10( L_snr_sum ) ;*/
/*-----------------------------------------------------------------*
 * vad_snr_log_fx()
 *
 * snr_sum  =   "scale"  * (float)log10( L_snr_sum ) ;
 *-----------------------------------------------------------------*/

/* o: Q8        */
static Word16 vad_snr_log_fx(
    Word32 L_snr, /* i  : Q4        */
@@ -88,6 +85,7 @@ static Word16 vad_snr_log_fx(
    f_snr = Log2_norm_lc( L_shl( L_snr, e_snr ) );
    e_snr = sub( 30 - 4, e_snr );
    L_tmp = Mpy_32_16( e_snr, f_snr, scale );

    return round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */
}

@@ -169,14 +167,17 @@ void wb_vad_init_fx(
    move16();
    hVAD->hangover_terminate_flag = 0;
    move16();

    return;
}


/*-----------------------------------------------------------------*
 * sign_thr_snr_acc_fx()
 *
 * accumulate snr_sum with significance thresholds
 *-----------------------------------------------------------------*/

static void sign_thr_snr_acc_ivas_fx(
    Word32 *L_snr_sum, /* o  : q_snr_sum */
    Word16 *q_snr_sum,
@@ -199,8 +200,11 @@ static void sign_thr_snr_acc_ivas_fx(
    *q_snr_sum = sub( 31, exp_snr_sum );
    move32();
    move32();

    return;
}


static void sign_thr_snr_acc_fx(
    Word32 *L_snr_sum, /* o  : Q4 */
    Word32 L_snr,      /* i  : Q4 */
@@ -221,8 +225,11 @@ static void sign_thr_snr_acc_fx(
    /* Q4 */
    move32();
    BASOP_SATURATE_WARNING_ON_EVS

    return;
}


/*-----------------------------------------------------------------*
 * dtx_hangover_addition_fx()
 *
@@ -447,7 +454,7 @@ Word16 dtx_hangover_addition_fx(
 *
 * Voice Activity Detector
 *-----------------------------------------------------------------*/
/* new simplified and harmonized code  */

Word16 wb_vad_fx(
    Encoder_State *st_fx,          /* i/o: encoder state structure                    */
    const Word32 fr_bands[],       /* i  : per band input energy (contains 2 vectors) Q_new+QSCALE*/
@@ -455,8 +462,8 @@ Word16 wb_vad_fx(
    Word16 *clean_speech_HO,       /* o  : SC-VBR clean speech HO flag                */
    Word16 *NB_speech_HO,          /* o  : SC-VBR NB speech HO flag                   */
    Word16 *snr_sum_he,            /* o  : Output snr_sum as weighted spectral measure*/
    Word16 *localVAD_HE_SAD,
    Word16 *flag_noisy_speech_snr, /* o  :   */
    Word16 *localVAD_HE_SAD,       /* o  : HE-SAD flag without hangover               */
    Word16 *flag_noisy_speech_snr, /* o  : encoder detector for noisy speech          */
    const Word16 Q_new,            /* i  : scaling factor                             Q0 */
    VAD_HANDLE hVAD,               /* i/o: VAD data handle                            */
    NOISE_EST_HANDLE hNoiseEst,    /* i  : Noise estimation handle                    */
@@ -500,7 +507,6 @@ Word16 wb_vad_fx(
    Word16 snr_sum_HE_SAD;   /*Q8 log */
    Word16 sign_thr_HE_SAD, min_snr_HE_SAD;


    Word16 thr1_ol;
    Word32 L_snr_sum_ol;
    Word16 snr_sum_ol; /* Q8 log */
@@ -572,11 +578,12 @@ Word16 wb_vad_fx(
        last_7k2_coder_type = -1;
        move16();
    }

    /*---------------------------------------------------------------------*
     * set SNR thresholds depending on the input bandwitdh
     *---------------------------------------------------------------------*/
    IF( EQ_16( st_fx->max_band, 19 ) )
    /* WB input */ /* or SWB input */

    IF( EQ_16( st_fx->max_band, 19 ) ) /* WB input or SWB input */
    {
        nk = 3277;
        move16(); /*0.1 Q15 */
@@ -606,10 +613,8 @@ Word16 wb_vad_fx(

        sign_thr_HE_SAD = 40;
        move16(); /* 2.5f Q4 */
        ;
        min_snr_HE_SAD = 3;
        move16(); /* 0.2f Q4 */
        ;
    }
    ELSE /* NB input */
    {
@@ -630,23 +635,19 @@ Word16 wb_vad_fx(
        move16(); /* .25 *Q4  MIN_SNR */
        sign_thr_HE_SAD = 42;
        move16(); /* 2.65f Q4 */
        ;
        min_snr_HE_SAD = 1;
        move16(); /* 0.05f Q4 */
        ;
    }

    hangover_short = 0;
    move16();

    /* IF( st_fx->Opt_SC_VBR != 0 ) */
    *noisy_speech_HO = 0;
    move16();
    *clean_speech_HO = 0;
    move16();
    *NB_speech_HO = 0;
    move16();
    /* } */

    /*---------------------------------------------------------------------*
     * compute SNR for each band & total
@@ -667,7 +668,6 @@ Word16 wb_vad_fx(
        move16();
    }


    IF( snr_idx == 0 )
    {
        stmp = 6;
@@ -681,7 +681,6 @@ Word16 wb_vad_fx(
        delta4 = 0;
        move16();


        /*vad_thr = 2.4f*lp_snr - 42.2f;
          vad_thr = min(vad_thr,  80 ); */

@@ -749,7 +748,6 @@ Word16 wb_vad_fx(
    snr_sum_HE_SAD = 0;
    move16();


    FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ )
    {
        ftmp = L_add( *pt1++, 0 );
@@ -835,14 +833,12 @@ Word16 wb_vad_fx(
        }
        L_snr = L_max( L_snr, 1 * ( 1 << 4 ) ); /* if ( snr[i] < 1 ){snr[i] = 1;}*/


        /* snr[i] = (float)log10(snr[i]);  */
        snr = vad_snr_log_fx( L_snr, ONE_LG10 );

        /* snr_sumt += snr[i];*/
        snr_sumt = add( snr_sumt, shr( snr, 4 ) ); /*Q4 */


        tmp = shl_sat( snr, 5 ); /* Q8 -> Q13 */
        IF( LT_16( i, 2 ) )
        {
@@ -929,7 +925,6 @@ Word16 wb_vad_fx(
            L_snr = L_shr( snr_tmp, shift_snr ); /*L_snr in Q4*/
        }


        /* conditional snrsum, snr_sum = snr_sum + snr[i];*/
        sign_thr_snr_acc_fx( &L_snr_sum_HE_SAD, L_snr, sign_thr_HE_SAD, min_snr_HE_SAD );
        sign_thr_snr_acc_fx( &L_snr_sum, L_snr, sign_thr, min_snr );
@@ -992,7 +987,6 @@ Word16 wb_vad_fx(
        }
    }


    /* Separated  SNR_SUM outlier modification  */
    L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum;  */

@@ -1003,7 +997,6 @@ Word16 wb_vad_fx(
    {
        /* Update the total SNR only for WB signals */


        /*    corresponding float section
             if( (accum_ener_L > OUTLIER_THR_1 * accum_ener_H ) || (snr_outlier < MAX_SNR_OUTLIER_1) )
             {
@@ -1023,7 +1016,6 @@ Word16 wb_vad_fx(
        test();
        IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float::  (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H  )  !!!  */
            || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_1_FX ) )

        {
            /* as weight1 is 1.0  we do not need to multiply here ,  i.e. no need to loose any precisison */
            L_snr_sum_ol = L_sub( L_snr_sum_ol, L_snr_outlier ); /*Q4 */
@@ -1062,10 +1054,10 @@ Word16 wb_vad_fx(
    *snr_sum_he = snr_sum_HE_SAD;
    move16(); /* *snr_sum_he=snr_sum_HE_SAD; */


    /*---------------------------------------------------------------------*
     * compute thr1 for SAD decision
     *---------------------------------------------------------------------*/

    lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/

    sub( 0, 0 );
@@ -1103,7 +1095,6 @@ Word16 wb_vad_fx(
        }
    }


    /*---------------------------------------------------------------------*
     * WB input
     * SNR threshold computing
@@ -1112,7 +1103,6 @@ Word16 wb_vad_fx(

    IF( NE_16( vad_bwidth_fx, NB ) )
    {

        /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of
           modyfying thr1 and snr_sum */

@@ -1215,7 +1205,6 @@ Word16 wb_vad_fx(
            move16();
        }


        IF( GT_16( hVAD->voiced_burst, 3 ) )
        {
            IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */
@@ -1230,14 +1219,12 @@ Word16 wb_vad_fx(
            }
        }


        hangover_hd = hangover_hd_tbl[snr_idx];
        move16();

        IF( LT_16( hVAD->bcg_flux_fx, 640 ) )
        {
            hangover_hd = add( shr( hangover_hd, 1 ), 1 );
            // move16();
        }

        /* VAD hangover for he1 */
@@ -1274,7 +1261,6 @@ Word16 wb_vad_fx(
            move16();
        }


        /* Calculate background stationarity */
        test();
        IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 )
@@ -1419,7 +1405,6 @@ Word16 wb_vad_fx(
            }
        }


        /* localVAD and vad_flag for HE-SAD - in parallel with normal localVAD and vad_flag */

        *localVAD_HE_SAD = 0;
@@ -1492,7 +1477,6 @@ Word16 wb_vad_fx(
            }
        }


        thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */

        /*    -dtx  condition  dependency   in noisy speech */
@@ -1508,7 +1492,6 @@ Word16 wb_vad_fx(
            thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/
        }


        flag = 0;
        move16();
        if ( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1   */
@@ -1517,7 +1500,6 @@ Word16 wb_vad_fx(
            move16();
        }


        test();
        IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */
        {
@@ -1536,7 +1518,6 @@ Word16 wb_vad_fx(
        move16(); /* needed for  st_fx->vadnoise_fx update below */
    } /* end of NB */


    /* *flag_noisy_speech_snr is a  Word8 parameter  */
    *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */
    move16();
@@ -1647,7 +1628,6 @@ Word16 wb_vad_fx(
        move16();
    }


    IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */
    {
        hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 );
@@ -1675,8 +1655,8 @@ Word16 wb_vad_ivas_fx(
    Word16 *clean_speech_HO,       /* o  : SC-VBR clean speech HO flag                */
    Word16 *NB_speech_HO,          /* o  : SC-VBR NB speech HO flag                   */
    Word16 *snr_sum_he,            /* o  : Output snr_sum as weighted spectral measure*/
    Word16 *localVAD_HE_SAD,
    Word16 *flag_noisy_speech_snr, /* o  :   */
    Word16 *localVAD_HE_SAD,       /* o  : HE-SAD flag without hangover               */
    Word16 *flag_noisy_speech_snr, /* o  : encoder detector for noisy speech          */
    VAD_HANDLE hVAD,               /* i/o: VAD data handle                            */
    NOISE_EST_HANDLE hNoiseEst,    /* i  : Noise estimation handle                    */
    Word16 lp_speech_fx,           /* i  : long term active speech energy average     Q8 */
@@ -1807,11 +1787,12 @@ Word16 wb_vad_ivas_fx(
        last_7k2_coder_type = -1;
        move16();
    }

    /*---------------------------------------------------------------------*
     * set SNR thresholds depending on the input bandwitdh
     *---------------------------------------------------------------------*/
    IF( EQ_16( st_fx->max_band, 19 ) )
    /* WB input */ /* or SWB input */

    IF( EQ_16( st_fx->max_band, 19 ) ) /* WB input or SWB input */
    {
        nk = 3277;
        move16(); /*0.1 Q15 */
@@ -1846,7 +1827,6 @@ Word16 wb_vad_ivas_fx(
    }
    ELSE /* NB input */
    {
        // move16();
        nk = 3277;
        move16(); /*  0.1 Q15 */
        nc = 268435456;
@@ -1899,7 +1879,6 @@ Word16 wb_vad_ivas_fx(
        move16();
    }


    IF( snr_idx == 0 )
    {
        stmp = 6;
@@ -1913,7 +1892,6 @@ Word16 wb_vad_ivas_fx(
        delta4 = 0;
        move32(); /*0.0f in Q16 */


        /*vad_thr = 2.4f*lp_snr - 42.2f;
          vad_thr = min(vad_thr,  80 ); */

@@ -2271,7 +2249,6 @@ Word16 wb_vad_ivas_fx(
        test();
        IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float::  (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H  )  !!!  */
            || LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_1_FX ) )

        {
            /* snr_sum_ol = SNR_OUTLIER_WGHT_1 * ( snr_sum_ol - snr_outlier );
              As SNR_OUTLIER_WGHT_1 is 1.0f  we do not need to multiply here ,  i.e. no need to loose any precisison */
@@ -2318,10 +2295,10 @@ Word16 wb_vad_ivas_fx(
    *snr_sum_he = snr_sum_HE_SAD;
    move16(); /* *snr_sum_he=snr_sum_HE_SAD; */


    /*---------------------------------------------------------------------*
     * compute thr1 for SAD decision
     *---------------------------------------------------------------------*/

    lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/

    IF( LT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) )
@@ -2369,7 +2346,6 @@ Word16 wb_vad_ivas_fx(
        }
    }


    /*---------------------------------------------------------------------*
     * WB input
     * SNR threshold computing
@@ -2378,7 +2354,6 @@ Word16 wb_vad_ivas_fx(

    IF( vad_bwidth_fx != NB )
    {

        /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of
           modyfying thr1 and snr_sum */

@@ -2490,7 +2465,6 @@ Word16 wb_vad_ivas_fx(
            move16();
        }


        IF( GT_16( hVAD->voiced_burst, 3 ) )
        {
            IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */
@@ -2505,7 +2479,6 @@ Word16 wb_vad_ivas_fx(
            }
        }


        hangover_hd = hangover_hd_tbl[snr_idx];
        move16();

@@ -2548,7 +2521,6 @@ Word16 wb_vad_ivas_fx(
            move16();
        }


        /* Calculate background stationarity */
        test();
        IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 )
@@ -2767,7 +2739,6 @@ Word16 wb_vad_ivas_fx(
            }
        }


        thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */

        /*    -dtx  condition  dependency   in noisy speech */
@@ -2783,7 +2754,6 @@ Word16 wb_vad_ivas_fx(
            thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/
        }


        flag = 0;
        move16();
        IF( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1   */
@@ -2792,7 +2762,6 @@ Word16 wb_vad_ivas_fx(
            move16();
        }


        test();
        IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */
        {
@@ -2811,7 +2780,6 @@ Word16 wb_vad_ivas_fx(
        move16(); /* needed for  st_fx->vadnoise_fx update below */
    } /* end of NB */


    /* *flag_noisy_speech_snr is a  Word8 parameter  */
    *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */
    move16();
@@ -2923,7 +2891,6 @@ Word16 wb_vad_ivas_fx(
        move16();
    }


    IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */
    {
        hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); /*Q0*/