diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 9934f6e465062deab8088ea1bb920284b4e5a832..ec26cdf06ccb2e60862d7d12e370dcc453eaefce 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5962,63 +5962,59 @@ void ivas_mct_enc_close_fx( ); ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ - const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ - const Word16 input_frame, /* i : frame length Q0*/ - const Word16 n, /* i : channel number Q0*/ - Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1*/ - Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ - Word16 *relE_fx, /* o : frame relative energy Q8*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ - Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ - Word16 *epsP_fx_q, - Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ - Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ - Word16 *attack_flag, /* o : flag signaling attack Q0*/ - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ - Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ - Word16 *q_old_wsp, - Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ - Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ - Word16 *loc_harm, /* o : harmonicity flag Q0*/ - Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ - Word16 *enerBuffer_fx_exp, /* o : energy buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ - Word16 *fft_buff_fx_q, /* o : FFT buffer */ - const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ - const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ - const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ - Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) fr_bands_LR_fx_q*/ - Word16 fr_bands_LR_fx_q[CPE_CHANNELS], - const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ - Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q)*/ - Word16 lf_E_LR_fx_q, - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q)*/ - Word16 band_energies_LR_fx_q, - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ - const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ - const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ - Word16 *Q_new -#ifdef DEBUG_MODE_INFO - , - const Word16 ch_idx -#endif + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 n, /* i : channel number Q0*/ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal (st->Q_inp until preemph, then Q_new, then Q_new-1 towards the end)*/ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 *relE_fx, /* o : frame relative energy Q8*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* o : Q factor of LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ + Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ + Word16 *attack_flag, /* o : flag signaling attack Q0*/ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 *q_old_wsp, /* o : Q factor of weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ + Word16 *loc_harm, /* o : harmonicity flag Q0*/ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ + const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands fr_bands_LR_fx_q*/ + Word16 fr_bands_LR_fx_q[CPE_CHANNELS], /* i : Q factors of energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels lf_E_LR_fx_q*/ + const Word16 lf_E_LR_fx_q, /* i : Q factor of per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN band_energies_LR_fx_q*/ + const Word16 band_energies_LR_fx_q, /* o : Q factors of energy in critical bands without minimum noise floor */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ + const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ + Word16 *Q_new /* i/o : Q factor of speech buffers */ ); ivas_error pre_proc_ivas_fx( @@ -6040,17 +6036,17 @@ ivas_error pre_proc_ivas_fx( Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ - Word16 e_old_wsp, + const Word16 e_old_wsp, /* i : Q value of weighted input signal buffer */ const Word16 loc_harm, /* i : harmonicity flag Q0*/ const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* e_enerBuffer */ - Word16 e_enerBuffer, - Word16 fft_buff_fx[2 * L_FFT], /* Qx */ - Word16 cor_map_sum_fx, /* Q8 */ - Word16 *Q_new + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer e_enerBuffer */ + const Word16 e_enerBuffer, /* i : Q value of energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 cor_map_sum_fx, /* i : speech/music clasif. parameter Q8*/ + Word16 *Q_new /* i/o : Q factor of speech buffers */ ); void ivas_initialize_handles_enc_fx( diff --git a/lib_com/options.h b/lib_com/options.h index a884d61ec7b505ad65665d3b7e013a20a3a02a20..ffac0ff4ef892f1a9bb848163586767fc6ef7490 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -100,6 +100,7 @@ #define OPT_BE_2311_HARM_GSC_GAIN /* VA: issue 2311: BE part of the GSC gain harmonization pipeline #70380 shows the BE */ #define HARM_CORECODER_UPDT /* VA: basop issue 2342: Remove duplicated code in core-coder common update functions */ #define HARM_CORE_SW /* VA: basop issue 2314: Remove duplicated code in the core switching */ +#define HARM_PREPROC /* VA: basop issue 2339: Remove duplicated code in the core-coder DTX */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index d2a32baaee726d02b34be52bb49775e9507da73f..72f981259c934f9c3d38d8392f94085125eb43a9 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -314,7 +314,11 @@ void amr_wb_enc_fx( } /* apply DTX hangover for CNG analysis */ +#ifdef HARM_PREPROC + vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, &vad_hover_flag, NULL, NULL, NULL ); +#else vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, &vad_hover_flag, NULL, NULL ); +#endif /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled @@ -336,7 +340,11 @@ void amr_wb_enc_fx( move16(); } +#ifdef HARM_PREPROC + dtx_fx( st, -1, -1, vad_flag_dtx, inp, Q_new ); +#else dtx_fx( st, vad_flag_dtx, inp, Q_new ); +#endif /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 483304cdedf36ced3b85cb458bcec935acadf4fd..b9ec0c8727e1900bfaa4d15c7e3a60206a1a0720 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -43,7 +43,7 @@ static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, /*==================================================================================*/ -/* FUNCTION : dtx_ivas_fx() */ +/* FUNCTION : dtx_fx() */ /*----------------------------------------------------------------------------------*/ /* PURPOSE : Discontinuous transmission operation */ /*----------------------------------------------------------------------------------*/ @@ -58,27 +58,45 @@ static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, /* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ /* _ (Encoder_State_Fx) st_fx : encoder state structure */ /*----------------------------------------------------------------------------------*/ - /*----------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*==================================================================================*/ + +#ifdef HARM_PREPROC +void dtx_fx( +#else void dtx_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ const Word16 vad, /* i : vad flag for DTX Q0*/ const Word16 speech[], /* i : Pointer to the speech frame Q_speech*/ - Word16 Q_speech /* i : Q factor for speech */ + const Word16 Q_speech /* i : Q factor for speech */ ) { Word16 alpha, i, j, Q_speech2; Word32 L_tmp; DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; Word32 total_brate_ref; +#ifdef HARM_PREPROC + Word16 flag_lp_noise; + + flag_lp_noise = 0; + move16(); + test(); + test(); + test(); + IF( ( st_fx->element_mode == EVS_MONO && LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) ) || + ( st_fx->element_mode != EVS_MONO && LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ) ) ) + { + flag_lp_noise = 1; + move16(); + } +#endif total_brate_ref = st_fx->total_brate; move32(); @@ -95,15 +113,23 @@ void dtx_ivas_fx( test(); test(); test(); +#ifdef HARM_PREPROC + last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || flag_lp_noise || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) ); +#else last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) ); +#endif test(); test(); test(); - + test(); last_br_flag = ( st_fx->element_mode == EVS_MONO && LE_32( st_fx->last_total_brate, MAX_BRATE_DTX_EVS ) ) || ( st_fx->element_mode != EVS_MONO && LE_32( last_ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || +#ifdef HARM_PREPROC + flag_lp_noise; +#else LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ); +#endif } /* Initialization */ @@ -114,6 +140,7 @@ void dtx_ivas_fx( st_fx->cng_type = FD_CNG; move16(); + test(); test(); test(); @@ -123,6 +150,7 @@ void dtx_ivas_fx( move16(); } } + test(); test(); test(); @@ -142,12 +170,14 @@ void dtx_ivas_fx( { st_fx->total_brate = st_fx->last_total_brate_cng; move32(); + test(); if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) { st_fx->Opt_SC_VBR = 0; move16(); } + st_fx->rf_mode = st_fx->last_rf_mode_cng; move16(); st_fx->bwidth = st_fx->last_bwidth_cng; @@ -155,13 +185,14 @@ void dtx_ivas_fx( st_fx->codec_mode = st_fx->last_codec_mode_cng; move16(); } + test(); test(); IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag ) - { st_fx->total_brate = st_fx->last_total_brate; move32(); + test(); if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) { @@ -179,10 +210,12 @@ void dtx_ivas_fx( st_fx->Opt_RF_ON = 1; move16(); } + st_fx->rf_mode = st_fx->Opt_RF_ON; move16(); st_fx->bwidth = st_fx->last_bwidth; move32(); + IF( st_fx->element_mode > EVS_MONO ) { st_fx->codec_mode = MODE1; @@ -211,8 +244,13 @@ void dtx_ivas_fx( test(); br_dtx_flag = ( ( st_fx->element_mode == EVS_MONO ) && LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) ) || ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || +#ifdef HARM_PREPROC + flag_lp_noise; +#else LT_16( extract_h( st_fx->lp_noise_32fx ), DTX_THR * 256 ); +#endif } + test(); test(); test(); @@ -272,12 +310,14 @@ void dtx_ivas_fx( st_fx->core_brate = SID_2k40; move32(); } + test(); test(); IF( ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->cng_type, FD_CNG ) ) && EQ_16( st_fx->dtx_sce_sba, 1 ) ) { st_fx->cng_type = FD_CNG; move16(); + test(); test(); test(); @@ -320,6 +360,7 @@ void dtx_ivas_fx( move16(); } } + /* reset the bitstream (IVAS format signalling was already written) */ test(); IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL ) @@ -337,7 +378,7 @@ void dtx_ivas_fx( /*------------------------------------------------------------------------* * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame) *------------------------------------------------------------------------*/ - /* NB core bit rate can be "-1" at startup , so one can not use core_brate_fx <=2400 */ + test(); test(); IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( st_fx->core_brate != FRAME_NO_DATA ) ) @@ -428,6 +469,7 @@ void dtx_ivas_fx( move16(); } } + st_fx->last_total_brate_cng = -1; move16(); } @@ -436,6 +478,7 @@ void dtx_ivas_fx( st_fx->cng_type = LP_CNG; move16(); } + st_fx->active_cnt = add( st_fx->active_cnt, 1 ); move16(); st_fx->active_cnt = s_min( st_fx->active_cnt, 200 ); @@ -445,6 +488,7 @@ void dtx_ivas_fx( /*------------------------------------------------------------------------* * Update speech and background noise long-term energy *------------------------------------------------------------------------*/ + IF( hDtxEnc != NULL ) { hDtxEnc->frame_ener_fx = L_deposit_l( 0 ); @@ -467,7 +511,6 @@ void dtx_ivas_fx( } /* Active speech (voiced) */ - IF( EQ_16( st_fx->clas, VOICED_CLAS ) ) { alpha = ALPHA_ENER_SLOW_FX; /*Q15 */ @@ -524,7 +567,6 @@ void dtx_ivas_fx( test(); IF( st_fx->Opt_DTX_ON && ( EQ_32( st_fx->core_brate, SID_2k40 ) || ( st_fx->core_brate == FRAME_NO_DATA ) ) ) { - st_fx->bwidth = st_fx->last_bwidth; move16(); test(); @@ -561,7 +603,6 @@ void dtx_ivas_fx( IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { Word16 n, bits_frame_nominal; - UWord16 lsb; Word16 tmpbandwidthMin; @@ -575,17 +616,20 @@ void dtx_ivas_fx( BREAK; } } - IF( EQ_16( n, FRAME_SIZE_NB ) ) + if ( n == FRAME_SIZE_NB ) { assert( !"Bitrate not supported: not part of EVS" ); } + tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min; move16(); + if ( EQ_16( st_fx->rf_mode, 1 ) ) { tmpbandwidthMin = WB; move16(); } + st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin ); move16(); } @@ -594,6 +638,7 @@ void dtx_ivas_fx( return; } +#ifndef HARM_PREPROC /*==================================================================================*/ /* FUNCTION : dtx_fx() */ /*----------------------------------------------------------------------------------*/ @@ -1052,6 +1097,7 @@ void dtx_fx( return; } +#endif /*---------------------------------------------------------------------* * update_SID_cnt() @@ -1201,6 +1247,12 @@ static void update_SID_cnt_fx( } +/*-------------------------------------------------------------------* + * dtx_hangover_control() + * + * + *-------------------------------------------------------------------*/ + void dtx_hangover_control_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 lsp_new_fx[M] /* i : current frame LSPs Q15*/ @@ -1480,6 +1532,7 @@ void dtx_hangover_control_fx( return; } + /*-------------------------------------------------------------------* * td_cng_enc_init_fx() * @@ -1491,6 +1544,7 @@ void td_cng_enc_init_fx( const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation Q0*/ const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ ) +#ifndef HARM_PREPROC { hTdCngEnc->cng_seed = RANDOM_INITSEED; @@ -1580,8 +1634,8 @@ void td_cng_enc_init_ivas_fx( const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation Q0*/ const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ ) +#endif { - hTdCngEnc->cng_seed = RANDOM_INITSEED; move16(); hTdCngEnc->cng_ener_seed = RANDOM_INITSEED; @@ -1672,6 +1726,7 @@ void td_cng_enc_init_ivas_fx( return; } + /*-------------------------------------------------------------------* * dtx_enc_init_fx() * @@ -1734,5 +1789,6 @@ void dtx_enc_init_fx( move16(); } } + return; } diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 7c29b4e06757134f1092b24d5013ee6ce1b86719..07ae94937b3bbacd0e38a077776d041c6acae1b0 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -686,6 +686,9 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } +#ifdef HARM_PREPROC + td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); +#else IF( st->element_mode == EVS_MONO ) { td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); @@ -694,6 +697,7 @@ ivas_error init_encoder_fx( { td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); } +#endif } ELSE { diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 38c5abd23a5cf11a56b4c852e1c7bfbda47410f6..d17b4d35800d5a9a622a767a4cad5ba83dcdbd36 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -50,15 +50,13 @@ #define SCE_SMC_THR 16000 -static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, Word32 enerBuffer_dft[], const Word16 no_channels, const Word32 input_Fs, Word16 enerBuffer_dft_e[] ); - /*-------------------------------------------------------------------* - * pre_proc_front_ivas() - * - * Front Pre-processing for IVAS - * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) + * Local function prototypes *--------------------------------------------------------------------*/ -static Word16 get_zero_flag( Word32 arr[], Word16 len ) + +static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, Word32 enerBuffer_dft[], const Word16 no_channels, const Word32 input_Fs, Word16 enerBuffer_dft_e[] ); + +static Word16 get_zero_flag( const Word32 arr[], const Word16 len ) { FOR( Word16 j = 0; j < len; j++ ) { @@ -70,76 +68,71 @@ static Word16 get_zero_flag( Word32 arr[], Word16 len ) return 0; } + +/*-------------------------------------------------------------------* + * pre_proc_front_ivas() + * + * Front Pre-processing for IVAS + * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) + *--------------------------------------------------------------------*/ + ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ - const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ - const Word16 input_frame, /* i : frame length Q0*/ - const Word16 n, /* i : channel number Q0*/ - Word16 old_inp_12k8_fx[], /* o : buffer of old input signal (st->Q_inp until preemph, then Q_new, then Q_new-1 towards the end)*/ - Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ - Word16 *relE_fx, /* o : frame relative energy Q8*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ - Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ - Word16 *epsP_fx_q, - Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ - Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ - Word16 *attack_flag, /* o : flag signaling attack Q0*/ - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ - Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ - Word16 *q_old_wsp, - Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ - Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ - Word16 *loc_harm, /* o : harmonicity flag Q0*/ - Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ - Word16 *enerBuffer_fx_exp, /* o : energy buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ - Word16 *fft_buff_fx_q, /* o : FFT buffer */ - const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ - const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ - const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ - Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) fr_bands_LR_fx_q*/ - Word16 fr_bands_LR_fx_q[CPE_CHANNELS], - const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ - Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q)*/ - Word16 lf_E_LR_fx_q, - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q)*/ - Word16 band_energies_LR_fx_q, - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ - const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ - const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ - Word16 *Q_new -#ifdef DEBUG_MODE_INFO - , - const Word16 ch_idx -#endif + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 n, /* i : channel number Q0*/ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal (st->Q_inp until preemph, then Q_new, then Q_new-1 towards the end)*/ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 *relE_fx, /* o : frame relative energy Q8*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* o : Q factor of LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ + Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ + Word16 *attack_flag, /* o : flag signaling attack Q0*/ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 *q_old_wsp, /* o : Q factor of weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ + Word16 *loc_harm, /* o : harmonicity flag Q0*/ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ + const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands fr_bands_LR_fx_q*/ + Word16 fr_bands_LR_fx_q[CPE_CHANNELS], /* i : Q factors of energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels lf_E_LR_fx_q*/ + const Word16 lf_E_LR_fx_q, /* i : Q factor of per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN band_energies_LR_fx_q*/ + const Word16 band_energies_LR_fx_q, /* o : Q factors of energy in critical bands without minimum noise floor */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ + const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ + Word16 *Q_new /* i/o : Q factor of speech buffers */ ) { Encoder_State *st; - IF( hSCE != NULL ) - { - st = hSCE->hCoreCoder[n]; - } - ELSE - { - st = hCPE->hCoreCoder[n]; - } - Word16 q_tmpN_LR[CPE_CHANNELS]; Word16 q_tmpE_LR[CPE_CHANNELS]; Word16 q_tmpN; @@ -165,22 +158,23 @@ ivas_error pre_proc_front_ivas_fx( Word16 old_pitch1; /* previous frame OL pitch[1] @12.8 kHz */ Word16 LR_localVAD; ivas_error error; - - push_wmops( "pre_proc_front" ); - Word16 *signal_in_fx; Word32 *signal32_in_fx; Word16 *inp_12k8_fx, *new_inp_12k8_fx; /* pointers to current frame and new data */ CLDFB_SCALE_FACTOR cldfbScale; +#ifdef HARM_PREPROC + Word16 temp1F_icatdmResampBuf_fx[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ + Word16 mem_decim_dummy_fx[2 * L_FILT_MAX]; /* dummy decimation filter memory */ +#else Word16 *temp1F_icatdmResampBuf_fx; - Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ +#endif Word32 tmpF_fx[STEREO_DFT_BAND_MAX]; Word32 *res_cod_SNR_M_fx; Word16 snr_sum_he_fx; /* HE SAD parameters */ Word16 new_inp_out_size; Word16 Q_new_inp; Word16 mem_decim_size; - Word16 dummy_fx; Word16 ncharX_fx; Word16 ncharX_LR_fx; /* noise character for sp/mus classifier */ @@ -214,59 +208,21 @@ ivas_error pre_proc_front_ivas_fx( Word16 Qfact_PS, q_lf_E_fx; Word16 enerBuffer_fx_exp_buf[CLDFB_NO_CHANNELS_MAX]; Word32 bckr_temp[NB_BANDS]; -#ifdef DEBUG_MODE_INFO - Word32 *in_buff_temp; - Word16 in_q_temp; -#endif - +#ifndef HARM_PREPROC mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); set16_fx( fft_buff_fx, 0, 512 ); - - Word16 Q_min = add( sub( 15, st->exp_old_inp_12k8 ), norm_arr( st->old_inp_12k8_fx, L_INP_MEM ) ); - Word16 input_frame_full = shl( input_frame, 1 ); //(old frame input length + new frame input length) - Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 ) ); - Q_min = s_max( -2, Q_min ); - Copy_Scale_sig_32_16( st->input32_fx - input_frame, st->input_fx - input_frame, input_frame_full, sub( Q_min, st->q_inp32 ) ); // Q_min - st->q_inp = Q_min; - move16(); - st->q_old_inp = Q_min; - move16(); - -#ifdef DEBUG_MODE_INFO - IF( hSCE != NULL ) - { - in_buff_temp = hSCE->hCoreCoder[n]->input32_fx; - in_q_temp = hSCE->hCoreCoder[n]->q_inp32; - } - ELSE - { - in_buff_temp = hCPE->hCoreCoder[n]->input32_fx; - in_q_temp = hCPE->hCoreCoder[n]->q_inp32; - } -#endif - - -#ifdef DEBUG_MODE_INFO - if ( !( hCPE != NULL && hCPE->hStereoTD != NULL && ch_idx > 0 ) ) - { - /* for TD stereo only write out first channel. The existence of a second channel can vary, this is just easier to handle */ - int16_t tmpF[L_FRAME48k]; - for ( int16_t isample = 0; isample < input_frame; isample++ ) - { - tmpF[isample] = (int16_t) ( (float) in_buff_temp[isample - NS2SA( st->input_Fs, ACELP_LOOK_NS )] / ( (float) ( 1 << in_q_temp ) ) ); - } - dbgwrite( &tmpF, sizeof( int16_t ), input_frame, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, ch_idx + 1, ENC ), ".pcm" ) ); - } #endif - + Word16 Q_min; + Word16 input_frame_full; +#ifndef HARM_PREPROC FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) { set32_fx( realBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( imagBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); } +#endif Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; - Word16 Q_inp_const = -1; move16(); Word16 headroom = 0, preemp_len = 0, inp_max = 0; @@ -276,6 +232,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 *preemp_start_idx = NULL; Word32 sig_out[960], max_32; + push_wmops( "pre_proc_front" ); /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ @@ -283,8 +240,8 @@ ivas_error pre_proc_front_ivas_fx( error = IVAS_ERR_OK; move32(); - cldfbScale.lb_scale = 31; - cldfbScale.hb_scale = 31; + cldfbScale.lb_scale = Q31; + cldfbScale.hb_scale = Q31; move16(); move16(); @@ -297,12 +254,6 @@ ivas_error pre_proc_front_ivas_fx( LR_localVAD = 0; move16(); - IF( st->cldfbAnaEnc != NULL ) - { - scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ), sub( Q11, st->cldfbAnaEnc->Q_cldfb_state ) ); /* Q11 */ - st->cldfbAnaEnc->Q_cldfb_state = Q11; - move16(); - } IF( hSCE != NULL ) { @@ -413,6 +364,16 @@ ivas_error pre_proc_front_ivas_fx( move16(); } + Q_min = add( sub( 15, st->exp_old_inp_12k8 ), norm_arr( st->old_inp_12k8_fx, L_INP_MEM ) ); + input_frame_full = shl( input_frame, 1 ); //(old frame input length + new frame input length) + Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 ) ); + Q_min = s_max( -2, Q_min ); + Copy_Scale_sig_32_16( st->input32_fx - input_frame, st->input_fx - input_frame, input_frame_full, sub( Q_min, st->q_inp32 ) ); // Q_min + st->q_inp = Q_min; + move16(); + st->q_old_inp = Q_min; + move16(); + L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ move16(); @@ -448,6 +409,13 @@ ivas_error pre_proc_front_ivas_fx( last_core_orig = st->last_core; /* Q0 */ move16(); + IF( st->cldfbAnaEnc != NULL ) + { + scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ), sub( Q11, st->cldfbAnaEnc->Q_cldfb_state ) ); /* Q11 */ + st->cldfbAnaEnc->Q_cldfb_state = Q11; + move16(); + } + /*--------------------------------------------------------------* * energy analysis *---------------------------------------------------------------*/ @@ -490,6 +458,7 @@ ivas_error pre_proc_front_ivas_fx( * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) *----------------------------------------------------------------*/ + Scale_sig( st->mem_decim_fx_q_inp, 2 * L_FILT_MAX, sub( st->q_inp, st->mem_q ) ); /* st->q_inp */ test(); @@ -501,8 +470,8 @@ ivas_error pre_proc_front_ivas_fx( move16(); Copy( st->mem_decim_fx_q_inp, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* Q(-1) */ set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); - new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ + new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ + Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -586,6 +555,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); st->mem_preemph_DFT_fx_q_inp = shl_sat( st->mem_preemph_DFT_fx_q_inp, sub( st->q_inp, st->mem_preemph_q ) ); /*st->q_inp*/ move16(); + test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { @@ -765,16 +735,6 @@ ivas_error pre_proc_front_ivas_fx( st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, fr_bands_fx_q, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float move16(); -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &st->vad_flag, sizeof( int16_t ), 1, fname( st->force_dir, "force_vad_flag.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, 1, "res/force_vad_flag.enf" ); - } -#endif test(); IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_flag, 1 ) ) @@ -790,7 +750,11 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( ( hCPE != NULL && !( lr_vad_enabled && st->idchan == 0 ) ) || hSCE != NULL ) { +#ifdef HARM_PREPROC + *vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, extract_h( L_sub( st->lp_speech_32fx, st->lp_noise_32fx ) ), 0, vad_hover_flag, NULL, NULL, NULL ); /* Q0 */ +#else *vad_flag_dtx = ivas_dtx_hangover_addition_fx( st, st->vad_flag, extract_h( L_sub( st->lp_speech_32fx, st->lp_noise_32fx ) ), 0, vad_hover_flag, NULL, NULL, NULL ); /* Q0 */ +#endif move16(); } ELSE @@ -801,7 +765,6 @@ ivas_error pre_proc_front_ivas_fx( *vad_flag_dtx = *vad_flag_dtx || st->vad_flag; /* Q0 */ move16(); - /* Determine hangover flag status based on LR localVAD and downmix localVAD */ test(); test(); @@ -858,7 +821,6 @@ ivas_error pre_proc_front_ivas_fx( set_bw_fx( element_mode, element_brate, st, MODE1 ); } - /* set the BW of the TD secondary channel in LRTD mode same as BW of the primary channel (only at higher bitrates) */ test(); test(); @@ -869,18 +831,6 @@ ivas_error pre_proc_front_ivas_fx( move16(); } -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &st->bwidth, sizeof( int16_t ), 1, fname( st->force_dir, "force_bwidth.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &st->bwidth, sizeof( int16_t ), 1, 1, "res/force_bwidth.enf" ); - } -#endif - - /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation * Long-term energies and relative frame energy updates @@ -907,6 +857,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * FD-CNG Noise Estimator *----------------------------------------------------------------*/ + IF( st->hFdCngEnc != NULL ) { resetFdCngEnc_fx( st ); @@ -958,6 +909,7 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ + test(); test(); if ( hCPE != NULL && NE_16( element_mode, IVAS_CPE_DFT ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) @@ -976,7 +928,11 @@ ivas_error pre_proc_front_ivas_fx( move16(); } +#ifdef HARM_PREPROC + dtx_fx( st, last_ivas_total_brate, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, *Q_new ); +#else dtx_ivas_fx( st, last_ivas_total_brate, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, *Q_new ); +#endif test(); test(); @@ -990,6 +946,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ + test(); test(); test(); @@ -1006,7 +963,9 @@ ivas_error pre_proc_front_ivas_fx( { total_brate = imult3216( FRAMES_PER_SEC, st->bits_frame_nominal ); /* Q0 */ } + configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate ); + IF( hCPE != NULL ) { st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); /* Q0 */ @@ -1063,6 +1022,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * LP analysis *----------------------------------------------------------------*/ + Word16 stab_fac_fx; Word16 Q_r[2]; set16_fx( Q_r, 0, 2 ); @@ -1111,6 +1071,7 @@ ivas_error pre_proc_front_ivas_fx( * Comparison of the LP coefficents to determine if it is possible * to reuse the primary channel LP coefficients in the secondary channel *----------------------------------------------------------------*/ + Word32 speech_buff[L_FRAME + M]; Copy_Scale_sig_16_32_DEPREC( inp_12k8_fx - M, speech_buff, L_FRAME + M, Q12 ); /* Q_new + 12 */ hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( *Q_new, 12 ) ); /* Q0 */ @@ -1163,6 +1124,7 @@ ivas_error pre_proc_front_ivas_fx( pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, *relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR, Q_wsp ); + /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; /* Q0 */ move16(); @@ -1176,8 +1138,13 @@ ivas_error pre_proc_front_ivas_fx( move16(); Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); /* Q7 */ + /* Detection of very short stable pitch period */ +#ifdef HARM_PREPROC + StableHighPitchDetect_fx( element_mode, &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *q_old_wsp, st->lgBin_E_fx ); +#else StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *q_old_wsp, st->lgBin_E_fx ); +#endif /* 1/4 pitch precision improvement */ IF( LE_32( element_brate, IVAS_32k ) ) @@ -1212,6 +1179,7 @@ ivas_error pre_proc_front_ivas_fx( /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ + Word16 scale = s_min( Q31, add( st->hNoiseEst->ave_enr_q, s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) ) ) ); scale = s_min( scale, add( q_tmpE, L_norm_arr( tmpE_fx, NB_BANDS ) ) ); scale = sub( scale, 1 ); // guard bits @@ -1281,6 +1249,7 @@ ivas_error pre_proc_front_ivas_fx( /*------------------------------------------------------------------* * Update parameters used in the VAD and DTX *-----------------------------------------------------------------*/ + vad_param_updt_fx( st, old_pitch1, corr_shift_fx, corr_shift_fx, A_fx, NULL, 1 ); test(); @@ -1288,6 +1257,7 @@ ivas_error pre_proc_front_ivas_fx( { vad_param_updt_fx( st, old_pitch1, corr_shiftL_fx, corr_shiftR_fx, A_fx, &hCPE->hFrontVad[0], CPE_CHANNELS ); } + /*-----------------------------------------------------------------* * Find spectral tilt * UC and VC frame selection @@ -1306,20 +1276,6 @@ ivas_error pre_proc_front_ivas_fx( &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, fr_bands_fx_q ); // Q0 Copy_Scale_sig_16_32_no_sat( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &st->coder_type, sizeof( int16_t ), 1, fname( st->force_dir, "force_coder_type.enf", -1, -1, -1 ) ); - dbgread( &st->coder_type_raw, sizeof( int16_t ), 1, fname( st->force_dir, "force_coder_type_raw.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &st->coder_type, sizeof( int16_t ), 1, 1, "res/force_coder_type.enf" ); - dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, 1, "res/force_coder_type_raw.enf" ); - } -#endif - - /*-----------------------------------------------------------------* * channel aware mode configuration * *-----------------------------------------------------------------*/ @@ -1348,6 +1304,7 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Collect stereo classifier features *-----------------------------------------------------------------*/ + IF( hStereoClassif != NULL ) { Word16 max_e_Etot; @@ -1362,6 +1319,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); move16(); move16(); + stereo_classifier_features_ivas_fx( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new_fx, epsP_fx, st->pitch, st->voicing_fx, *cor_map_sum_fx, non_staX_fx, sp_div_fx, st->clas, sub( 31, *epsP_fx_q ), ( 31 - Q8 ) /* exp of cor_map_sum */, ( 31 - Q20 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); @@ -1378,17 +1336,6 @@ ivas_error pre_proc_front_ivas_fx( smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, extract_h( Etot_fx ), lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, hSpMusClas->past_PS_Q ); /* Q0 */ -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc1.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc1.enf" ); - } -#endif - #ifdef DEBUGGING if ( st->idchan == 0 ) { @@ -1436,6 +1383,7 @@ ivas_error pre_proc_front_ivas_fx( st->GSC_IVAS_mode = 0; move16(); + test(); IF( EQ_16( st->idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { @@ -1492,6 +1440,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); st->hTcxEnc->spectrum_e[1] = 16; move16(); + IF( flag_16k_smc ) { Word16 Q_old_inp_16k = -1; @@ -1525,15 +1474,14 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_old_inp_12k8 = *Q_new; move16(); + /* Compute core-coder buffers at internal sampling rate */ - error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx, - A_fx, Aw_fx, - epsP_fx, - lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); + error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } + *epsP_fx_q = add( Q_r[0], 1 ); move16(); @@ -1594,23 +1542,6 @@ ivas_error pre_proc_front_ivas_fx( ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, extract_h( Etot_fx ), attack_flag, inp_12k8_fx, *Q_new, S_map_fx, flag_spitch ); } -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc2.enf", -1, -1, -1 ) ); - dbgread( &st->sp_aud_decision0, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision0.enf", -1, -1, -1 ) ); - dbgread( &st->sp_aud_decision1, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision1.enf", -1, -1, -1 ) ); - dbgread( &st->sp_aud_decision2, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision2.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc2.enf" ); - dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision0.enf" ); - dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision1.enf" ); - dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision2.enf" ); - } -#endif - /*----------------------------------------------------------------* * Final VAD correction (when HE-SAD is used instead of the normal VAD, * rewrite the VAD flag by VAD flag with DTX hangover for further processing) @@ -1626,26 +1557,30 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Update old input signal buffer *-----------------------------------------------------------------*/ + shift = getScaleFactor16( &old_inp_12k8_fx[L_FRAME], L_INP_MEM ); Copy_Scale_sig( &old_inp_12k8_fx[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM, shift ); /* Q_new + shift */ st->exp_old_inp_12k8 = sub( Q15, add( *Q_new, shift ) ); move16(); - *Q_new = sub( *Q_new, Q_inp_const ); // ivas_core_enc will assume inp signal (12k8 and 16k) in Q_new - 1 move16(); +#ifndef HARM_PREPROC free( mem_decim_dummy_fx ); free( temp1F_icatdmResampBuf_fx ); +#endif pop_wmops(); return error; } + /*-------------------------------------------------------------------* * calculate_energy_buffer() * * calculate DFT-based energies *--------------------------------------------------------------------*/ + static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ Word32 enerBuffer_dft_fx[], /* o : energy buffer() exp(enerBuffer_dft_e)*/ @@ -1715,5 +1650,6 @@ static void calculate_energy_buffer_ivas_fx( enerBuffer_dft_e[i] = 0; move16(); } + return; } diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 9857c3e1298835392a7c810be5476acb6e7b4d2d..7e13ed80ac318ff333f926c89e99f4006f3e3d4a 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -45,36 +45,38 @@ * Pre-processing (Selection of internal Fs, classification, SC VBR decision, * Decision matrix, Preprocessing at other Fs, core switching decision, ...) *--------------------------------------------------------------------*/ + ivas_error pre_proc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 last_element_mode, /* i : last element mode Q0*/ - const Word32 element_brate, /* i : element bitrate Q0*/ - const Word32 last_element_brate, /* i : last element bitrate Q0*/ - const Word16 input_frame, /* i : frame length Q0*/ - Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ - Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ - Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame Q_new*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ - Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q*/ - Word16 *epsP_fx_q, /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ - Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ - Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ - Word16 e_old_wsp, - const Word16 loc_harm, /* i : harmonicity flag Q0*/ - const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* e_enerBuffer */ - Word16 e_enerBuffer, - Word16 fft_buff_fx[2 * L_FFT], /* Qx */ - Word16 cor_map_sum_fx, /* Q8 */ - Word16 *Q_new ) + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 last_element_brate, /* i : last element bitrate Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ + Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame Q_new*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ + Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* i : LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ + Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ + Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ + const Word16 e_old_wsp, /* i : Q value of weighted input signal buffer */ + const Word16 loc_harm, /* i : harmonicity flag Q0*/ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer e_enerBuffer */ + const Word16 e_enerBuffer, /* i : Q value of energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 cor_map_sum_fx, /* i : speech/music clasif. parameter Q8*/ + Word16 *Q_new /* i/o : Q factor of speech buffers */ +) { Word16 L_look, element_mode, lMemRecalc_12k8; Word16 *inp_16k_fx, *new_inp_12k8_fx, *inp_12k8_fx; /* pointers to current frame and new data */ @@ -111,6 +113,7 @@ ivas_error pre_proc_ivas_fx( lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS ); move16(); } + /*----------------------------------------------------------------* * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) *----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 813cae04bed7c4f0bd26e5e3ede69a73407ba208..f0ba8fc26ed9aeba1a0b2f9313af23d172563428 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -923,18 +923,13 @@ ivas_error ivas_cpe_enc_fx( &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD, - band_energies_LR_fx, q_band_energies_LR, 0, front_vad_flag, 0, 0, ivas_format, st_ivas->hMCT != NULL, st_ivas->hEncoderConfig->last_ivas_total_brate, ivas_total_brate, &Q_new[n] -#ifdef DEBUG_MODE_INFO - , - ( st_ivas->nSCE + ( cpe_id * CPE_CHANNELS ) + n ) -#endif - ); - e_old_wsp[n] = sub( Q15, q_old_wsp ); - move16(); + band_energies_LR_fx, q_band_energies_LR, 0, front_vad_flag, 0, 0, ivas_format, st_ivas->hMCT != NULL, st_ivas->hEncoderConfig->last_ivas_total_brate, ivas_total_brate, &Q_new[n] ); IF( error != IVAS_ERR_OK ) { return error; } + e_old_wsp[n] = sub( Q15, q_old_wsp ); + move16(); } /*making Q common*/ diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index 6323f8cde8d2b94162238b6baad73d90ba8c3c91..1e68a3905903778a2a56938904ca18a07be6f627 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -286,7 +286,12 @@ ivas_error front_vad_fx( sts[1]->last_coder_type = sts[0]->last_coder_type; /* Q0 */ move16(); } + +#ifdef HARM_PREPROC + vad_flag_dtx[n] = dtx_hangover_addition_fx( sts[n], hFrontVad->hVAD->vad_flag, sub( hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ), 0 /* <- no cldfb addition */, &vad_hover_flag[n], hFrontVad->hVAD, hFrontVad->hNoiseEst, &hFrontVads[n]->rem_dtx_ho ); /* Q0 */ +#else vad_flag_dtx[n] = ivas_dtx_hangover_addition_fx( sts[n], hFrontVad->hVAD->vad_flag, sub( hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ), 0 /* <- no cldfb addition */, &vad_hover_flag[n], hFrontVad->hVAD, hFrontVad->hNoiseEst, &hFrontVads[n]->rem_dtx_ho ); /* Q0 */ +#endif move16(); if ( EQ_16( n_chan, 1 ) ) @@ -599,7 +604,11 @@ ivas_error front_vad_spar_fx( corr_shift_fx = correlation_shift_fx( extract_h( hFrontVad->hNoiseEst->totalNoise_32fx ) ); /* Q15 */ +#ifdef HARM_PREPROC + dtx_fx( st, hEncoderConfig->last_ivas_total_brate, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); +#else dtx_ivas_fx( st, hEncoderConfig->last_ivas_total_brate, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); +#endif /* linear prediction analysis */ alw_pitch_lag_12k8[0] = st->old_pitch_la; /* Q0 */ @@ -684,7 +693,12 @@ ivas_error front_vad_spar_fx( st->old_pitch_la = st->pitch[2]; /* Q0 */ move16(); +#ifdef HARM_PREPROC + StableHighPitchDetect_fx( IVAS_SCE /* needs to be other than EVS_MONO */, &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q_wsp, st->lgBin_E_fx ); +#else StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q_wsp, st->lgBin_E_fx ); +#endif + IF( st->hSpMusClas != NULL ) { Word16 dummy_int; diff --git a/lib_enc/ivas_ism_enc_fx.c b/lib_enc/ivas_ism_enc_fx.c index 6a1d1e676c216fad45623c06bfc1e4bfce34bacf..be2e223f31c9ab064b512f53ac06cf2c37a5d3df 100644 --- a/lib_enc/ivas_ism_enc_fx.c +++ b/lib_enc/ivas_ism_enc_fx.c @@ -252,18 +252,13 @@ ivas_error ivas_ism_enc_fx( error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0], &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], - fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0] -#ifdef DEBUG_MODE_INFO - , - st->id_element -#endif - ); - e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp ); - move16(); + fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0] ); IF( error != IVAS_ERR_OK ) { return error; } + e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp ); + move16(); IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index 2457fef6eaecb5a07271b118889a33d89a4fdf15..144e86643e6322f51107bd8fe7360e93dc3d4b7e 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -245,6 +245,7 @@ ivas_error ivas_sce_enc_fx( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ + set16_fx( old_wsp_fx[0], 0, L_WSP ); q_old_wsp = Q15; move16(); @@ -254,18 +255,13 @@ ivas_error ivas_sce_enc_fx( &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc, - st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0] -#ifdef DEBUG_MODE_INFO - , - st->id_element -#endif - ); - e_old_wsp[0] = sub( Q15, q_old_wsp ); - move16(); + st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0] ); IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } + e_old_wsp[0] = sub( Q15, q_old_wsp ); + move16(); /* sanity check -> DTX not supported for more than one SCEs/CPEs */ IF( sub( add( st_ivas->nSCE, st_ivas->nCPE ), 1 ) > 0 ) diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 107fb9681e09f49eea06b087308350d856ef8d6d..8507bc58cc62a04b6c96994b815b5deeb47417cd 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -385,7 +385,11 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } +#ifdef HARM_PREPROC + td_cng_enc_init_fx( hCPE->hCoreCoder[0]->hTdCngEnc, hCPE->hCoreCoder[0]->Opt_DTX_ON, hCPE->hCoreCoder[0]->max_bwidth ); +#else td_cng_enc_init_ivas_fx( hCPE->hCoreCoder[0]->hTdCngEnc, hCPE->hCoreCoder[0]->Opt_DTX_ON, hCPE->hCoreCoder[0]->max_bwidth ); +#endif } /* allocate TCA data structure */ diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index 49566e31d08b26bf5ae71ffb331f8ac087f6bdc0..51cda9c13d94898aa7539df5c4d2b150bc7c026f 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -26,6 +26,7 @@ * The pitch is searched in the interval vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), cldfb_addition, vad_hover_flag, hVAD, hNoiseEst, NULL ); +#else vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), cldfb_addition, vad_hover_flag, hVAD, hNoiseEst ); +#endif /*----------------------------------------------------------------* * NB/WB/SWB/FB bandwidth detector @@ -325,17 +329,23 @@ void pre_proc_fx( *----------------------------------------------------------------*/ resetFdCngEnc_fx( st ); + perform_noise_estimation_enc_fx( st->band_energies, st->band_energies_exp, enerBuffer, enerBuffer_exp, st->hFdCngEnc ); /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ +#ifdef HARM_PREPROC + dtx_fx( st, -1, -1, vad_flag_dtx, inp_12k8, *Q_new ); +#else dtx_fx( st, vad_flag_dtx, inp_12k8, *Q_new ); +#endif /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ + test(); IF( ( NE_32( st->last_total_brate, st->total_brate ) ) || ( NE_16( st->last_bwidth, st->bwidth ) ) ) { @@ -349,6 +359,7 @@ void pre_proc_fx( } configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, L_tmp ); } + test(); IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { @@ -447,8 +458,13 @@ void pre_proc_fx( move16(); /* Detection of very short stable st->pitch period (MODE1 bit-rates) */ +#ifdef HARM_PREPROC + StableHighPitchDetect_fx( EVS_MONO, &flag_spitch, st->pitch, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, + &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *Q_new, st->lgBin_E_fx ); +#else StableHighPitchDetect_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *Q_new, st->lgBin_E_fx ); +#endif /* 1/4 pitch precision improvement */ IF( LE_32( st->total_brate, ACELP_24k40 ) ) @@ -493,6 +509,7 @@ void pre_proc_fx( /*------------------------------------------------------------------* * Update parameters used in the VAD and DTX *-----------------------------------------------------------------*/ + vad_param_updt_fx( st, old_pitch1, corr_shift, corr_shift, A, NULL, 1 ); /*-----------------------------------------------------------------* @@ -506,9 +523,10 @@ void pre_proc_fx( st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig ); - /*----------------------------------------------------------------* + /*-----------------------------------------------------------------* * channel aware mode configuration * *-----------------------------------------------------------------*/ + test(); test(); IF( !st->Opt_RF_ON ) @@ -562,6 +580,7 @@ void pre_proc_fx( hSC_VBR->Local_VAD = st->localVAD; move16(); } + /*----------------------------------------------------------------* * Speech/music classification * AC frame selection @@ -769,6 +788,7 @@ void pre_proc_fx( /*---------------------------------------------------------------------* * Decision matrix (selection of technologies) *---------------------------------------------------------------------*/ + IF( EQ_16( st->codec_mode, MODE1 ) ) { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 0d3a67b9e367d5eb61cf87a6dad811c960f9b60b..82443f0440252e9d4d233070d48584b030dc6b68 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -144,6 +144,7 @@ Word16 correlation_shift_fx( ); void dtx_fx( +#ifndef HARM_PREPROC Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad, /* i : vad flag Q0*/ const Word16 speech[], /* i : Pointer to the speech frame Q_speech*/ @@ -151,15 +152,17 @@ void dtx_fx( ); void dtx_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ const Word16 vad, /* i : vad flag for DTX Q0*/ const Word16 speech[], /* i : Pointer to the speech frame Q_speech*/ - Word16 Q_speech /* i : Q factor for speech */ + const Word16 Q_speech /* i : Q factor for speech */ ); Word16 dtx_hangover_addition_fx( +#ifndef HARM_PREPROC Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad_flag, /* i Q0 */ const Word16 lp_snr, /* i Q8 */ @@ -170,6 +173,7 @@ Word16 dtx_hangover_addition_fx( ); Word16 ivas_dtx_hangover_addition_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad_flag, /* i Q0 */ const Word16 lp_snr, /* i Q8 */ @@ -577,6 +581,9 @@ void speech_music_classif_fx( ); void StableHighPitchDetect_fx( +#ifdef HARM_PREPROC + const Word16 element_mode, /* i : element mode */ +#endif Word16 *flag_spitch, /* o : flag to indicate very short stable pitch*/ Word16 pitch[], /* i/o: OL pitch buffer */ const Word16 voicing[], /* i : OL pitch gains */ @@ -590,6 +597,7 @@ void StableHighPitchDetect_fx( Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency */ Word16 Q_new, Word16 EspecdB[] ); +#ifndef HARM_PREPROC void StableHighPitchDetect_ivas_fx( Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ @@ -606,6 +614,7 @@ void StableHighPitchDetect_ivas_fx( Word16 Q_new, Word16 EspecdB[] /* Q7 */ ); +#endif void swb_bwe_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -1183,12 +1192,13 @@ void td_cng_enc_init_fx( const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ ); +#ifndef HARM_PREPROC void td_cng_enc_init_ivas_fx( TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation Q0*/ const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ ); - +#endif void dtx_enc_init_fx( Encoder_State *st, /* i : Encoder state handle */ const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate Q0*/ diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 4335225cac66e2b1e65e986785a76cbebd14ab0e..2e03bc59edd04158dac8291236ce68b9a85d25dd 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -229,6 +229,7 @@ static void sign_thr_snr_acc_fx( *-----------------------------------------------------------------*/ Word16 dtx_hangover_addition_fx( +#ifndef HARM_PREPROC Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad_flag, /* i Q0 */ const Word16 lp_snr, /* i Q8 */ @@ -425,6 +426,7 @@ Word16 dtx_hangover_addition_fx( return flag_dtx; } Word16 ivas_dtx_hangover_addition_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad_flag, /* i Q0 */ const Word16 lp_snr, /* i Q8 */ @@ -437,6 +439,7 @@ Word16 ivas_dtx_hangover_addition_fx( Word16 hangover_short_dtx; /* Q0 */ Word16 flag_dtx; /* Q0 */ Word16 tmp; /* Q0 */ + if ( hNoiseEst == NULL ) { hNoiseEst = st_fx->hNoiseEst; @@ -449,7 +452,6 @@ Word16 ivas_dtx_hangover_addition_fx( hVAD = st_fx->hVAD; } - flag_dtx = 0; move16(); @@ -484,7 +486,6 @@ Word16 ivas_dtx_hangover_addition_fx( } /* Only allow short HO if not sufficient active frames in clean speech*/ - tmp = 3; move16(); /* default for EVS*/ if ( EQ_16( st_fx->core, AMR_WB_CORE ) ) @@ -503,7 +504,7 @@ Word16 ivas_dtx_hangover_addition_fx( move16(); } - /* limit dtx hangover addition up to "tmp" frames in clean cond */ + /* limit dtx hangover addition up to "tmp" frames in clean cond */ IF( tmp != 0 ) { test(); @@ -517,13 +518,13 @@ Word16 ivas_dtx_hangover_addition_fx( } } - /* hangover adjustment from combined FFT+CLDFBVAD */ IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); /*Q0*/ hangover_short_dtx = s_max( hangover_short_dtx, 0 ); } + IF( vad_flag != 0 ) /* Speech present */ { flag_dtx = 1; @@ -548,13 +549,29 @@ Word16 ivas_dtx_hangover_addition_fx( move16(); /* float fix FIX_HO_TERMINATE */ /* Music hangover when music detected */ +#ifdef HARM_PREPROC test(); test(); test(); - if ( ( GT_16( hVAD->prim_act_he_fx, 32113 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ + IF( st_fx->element_mode == EVS_MONO ) { - hVAD->hangover_cnt_music = 0; - move16(); + if ( ( GT_16( hVAD->prim_act_he_fx, 31129 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ + { + hVAD->hangover_cnt_music = 0; + move16(); + } + } + ELSE +#endif + { + test(); + test(); + test(); + if ( ( GT_16( hVAD->prim_act_he_fx, 32113 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ + { + hVAD->hangover_cnt_music = 0; + move16(); + } } /* inside Music HO period */ @@ -609,9 +626,7 @@ Word16 ivas_dtx_hangover_addition_fx( } } - test(); - IF( flag_dtx != 0 && st_fx->localVAD == 0 ) { *vad_hover_flag_ptr = 1; @@ -625,6 +640,8 @@ Word16 ivas_dtx_hangover_addition_fx( return flag_dtx; } + + /*-----------------------------------------------------------------* * wb_vad() *