From a8fb397f84c12a3242804a0d5e97d603b9dbaab0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 10 Jul 2024 12:26:21 +0530 Subject: [PATCH 1/2] Preprocess front ivas and acelp core encoder functions converted --- lib_com/cldfb.c | 606 +++++++++- lib_com/cldfb_evs.c | 2 +- lib_com/cng_exc_fx.c | 5 +- lib_com/cnst.h | 3 + lib_com/ivas_mdct_imdct_fx.c | 4 +- lib_com/ivas_prot.h | 51 +- lib_com/ivas_prot_fx.h | 6 + lib_com/ivas_rom_com.c | 4 +- lib_com/ivas_rom_com.h | 17 + lib_com/modif_fs_fx.c | 17 +- lib_com/prot.h | 23 + lib_com/prot_fx2.h | 46 +- lib_com/rom_com.c | 629 ++++++++++- lib_com/rom_com.h | 28 +- lib_com/rom_com_fx.h | 8 + lib_com/stat_com.h | 1 + lib_dec/ivas_lfe_plc_fx.c | 5 +- lib_enc/acelp_core_enc.c | 1466 ++++++++++++++++++++++++ lib_enc/amr_wb_enc_fx.c | 6 +- lib_enc/bw_detect_fx.c | 12 +- lib_enc/cng_enc_fx.c | 3 +- lib_enc/init_enc.c | 111 +- lib_enc/ivas_core_pre_proc_front.c | 1261 ++++++++++++++++++++- lib_enc/ivas_cpe_enc.c | 19 +- lib_enc/ivas_enc.c | 26 + lib_enc/ivas_init_enc.c | 7 + lib_enc/ivas_ism_enc.c | 8 +- lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 2 +- lib_enc/ivas_sce_enc.c | 9 +- lib_enc/ivas_stereo_dft_enc.c | 3 + lib_enc/ivas_stereo_switching_enc.c | 6 +- lib_enc/ivas_stereo_td_enc.c | 4 +- lib_enc/lsf_enc.c | 3 + lib_enc/lsf_enc_fx.c | 1614 ++++++++++++++++++++++++--- lib_enc/mslvq_enc_fx.c | 368 ++++++ lib_enc/nois_est_fx.c | 107 +- lib_enc/pre_proc_fx.c | 6 +- lib_enc/prot_fx_enc.h | 90 ++ lib_enc/stat_enc.h | 19 +- lib_enc/vad_fx.c | 1236 ++++++++++++++++++++ 41 files changed, 7516 insertions(+), 327 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index b2022f725..6a4062a98 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -60,6 +60,8 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); +static void cldfb_init_proto_and_twiddles_enc( HANDLE_CLDFB_FILTER_BANK hs ); + static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead, float **realValues, float **imagValues, const int16_t numberBands, int16_t numberCols, TEC_ENC_HANDLE hTecEnc ); /*-------------------------------------------------------------------* @@ -1596,6 +1598,28 @@ void configureCldfb_ivas( return; } +void configureCldfb_ivas_enc( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ + const int32_t sampling_rate /* i : sampling rate */ +) +{ + + h_cldfb->no_col = CLDFB_NO_COL_MAX; + h_cldfb->bandsToZero = 0; + h_cldfb->nab = 0; + + h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); + h_cldfb->p_filter_length = 10 * h_cldfb->no_channels; +#ifdef IVAS_FLOAT_FIXED + h_cldfb->zeros = 0; + h_cldfb->anaScalefactor = 0; + h_cldfb->synScalefactor = 0; + h_cldfb->filterScale = 1; +#endif + cldfb_init_proto_and_twiddles_enc( h_cldfb ); + + return; +} #ifdef IVAS_FLOAT_FIXED void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ @@ -1612,7 +1636,9 @@ void configureCldfb_ivas_fx( Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 /* INV_CLDFB_BANDWIDTH in Q15 */ ), 1 ); val = L_shr( val, 1 ); h_cldfb->no_channels = extract_l( val ); - + h_cldfb->zeros = 0; + h_cldfb->anaScalefactor = 0; + h_cldfb->synScalefactor = 0; h_cldfb->p_filter_length = 10 * h_cldfb->no_channels; cldfb_init_proto_and_twiddles( h_cldfb ); @@ -1626,7 +1652,71 @@ void configureCldfb_ivas_fx( * open and configures a CLDFB handle *--------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error openCldfb_ivas( +ivas_error openCldfb_ivas_fx( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + const Word32 sampling_rate, /* i : sampling rate */ + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ +) +{ + HANDLE_CLDFB_FILTER_BANK hs; + Word16 buf_len; + + IF( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } + + hs->type = type; + move16(); + hs->prototype = prototype; + move16(); + + // configureCldfb_ivas( hs, sampling_rate ); + configureCldfb_ivas_fx( hs, sampling_rate ); + hs->memory_flt = NULL; + hs->memory_length = 0; + move16(); + + IF( EQ_32( type, CLDFB_ANALYSIS ) ) + { + buf_len = sub( hs->p_filter_length, hs->no_channels ); + hs->FilterStates = (Word16 *) malloc( ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; + } + ELSE + { + buf_len = hs->p_filter_length; + move16(); + hs->FilterStates = (Word16 *) malloc( 2 * ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; + } + + IF( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } + + hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + set32_fx( hs->cldfb_state_fx, 0, buf_len ); + hs->Q_cldfb_state = Q11; + /* TODO: remove the floating point dependency */ + + IF( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } + + set_f( hs->cldfb_state, 0.0f, buf_len ); + + *h_cldfb = hs; + move16(); + + return IVAS_ERR_OK; +} + +ivas_error openCldfb_ivas_enc( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ const int32_t sampling_rate, /* i : sampling rate */ @@ -1644,17 +1734,25 @@ ivas_error openCldfb_ivas( hs->type = type; hs->prototype = prototype; - configureCldfb_ivas( hs, sampling_rate ); + configureCldfb_ivas_enc( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; if ( type == CLDFB_ANALYSIS ) { buf_len = hs->p_filter_length - hs->no_channels; +#ifdef IVAS_FLOAT_FIXED + hs->FilterStates = (Word16 *) malloc( ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; +#endif } else { buf_len = hs->p_filter_length; +#ifdef IVAS_FLOAT_FIXED + hs->FilterStates = (Word16 *) malloc( 2 * ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; +#endif } if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) @@ -1670,7 +1768,8 @@ ivas_error openCldfb_ivas( hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ set32_fx( hs->cldfb_state_fx, 0, buf_len ); - hs->Q_cldfb_state = Q11; + set16_fx( hs->FilterStates, 0, i_mult( 9 + 16, hs->no_channels ) ); + set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); #endif // IVAS_FLOAT_FIXED @@ -1678,7 +1777,6 @@ ivas_error openCldfb_ivas( return IVAS_ERR_OK; } -#else ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ @@ -1714,63 +1812,56 @@ ivas_error openCldfb_ivas( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - set_f( hs->cldfb_state, 0.0f, buf_len ); +#ifdef IVAS_FLOAT_FIXED + if ( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } + hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + set32_fx( hs->cldfb_state_fx, 0, buf_len ); + hs->Q_cldfb_state = Q11; +#endif // IVAS_FLOAT_FIXED + *h_cldfb = hs; return IVAS_ERR_OK; } -#endif -#ifdef IVAS_FLOAT_FIXED -ivas_error openCldfb_ivas_fx( +#else +ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ - const Word32 sampling_rate, /* i : sampling rate */ + const int32_t sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ) { HANDLE_CLDFB_FILTER_BANK hs; - Word16 buf_len; + int16_t buf_len; - IF( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) + if ( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } hs->type = type; - move16(); hs->prototype = prototype; - move16(); - // configureCldfb_ivas( hs, sampling_rate ); - configureCldfb_ivas_fx( hs, sampling_rate ); + configureCldfb_ivas( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; - move16(); - IF( EQ_32( type, CLDFB_ANALYSIS ) ) + if ( type == CLDFB_ANALYSIS ) { - buf_len = sub( hs->p_filter_length, hs->no_channels ); + buf_len = hs->p_filter_length - hs->no_channels; } - ELSE + else { buf_len = hs->p_filter_length; - move16(); - } - - IF( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer - hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ - set32_fx( hs->cldfb_state_fx, 0, buf_len ); - hs->Q_cldfb_state = Q11; - /* TODO: remove the floating point dependency */ - - IF( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) + if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } @@ -1778,12 +1869,10 @@ ivas_error openCldfb_ivas_fx( set_f( hs->cldfb_state, 0.0f, buf_len ); *h_cldfb = hs; - move16(); return IVAS_ERR_OK; } #endif - /*-------------------------------------------------------------------* * resampleCldfb_ivas() * @@ -1862,6 +1951,44 @@ void analysisCldfbEncoder_ivas( return; } +void analysisCldfbEncoder_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *timeIn, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 *ppBuf_Ener, + Word16 *enerBuffSum_exp, + CLDFB_SCALE_FACTOR *scale ) +{ + Word16 i; + CLDFB_SCALE_FACTOR enerScale; + Word32 *ppBuf_Real[CLDFB_NO_COL_MAX]; + Word32 *ppBuf_Imag[CLDFB_NO_COL_MAX]; + Word16 *ppBuf_Real16[CLDFB_NO_COL_MAX]; + Word16 *ppBuf_Imag16[CLDFB_NO_COL_MAX]; + Word32 workBuffer[256]; + + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + ppBuf_Real[i] = &realBuffer[i][0]; + ppBuf_Imag[i] = &imagBuffer[i][0]; + ppBuf_Real16[i] = &realBuffer16[i][0]; + ppBuf_Imag16[i] = &imagBuffer16[i][0]; + } + + cldfbAnalysisFiltering( st->cldfbAnaEnc, ppBuf_Real, ppBuf_Imag, scale, timeIn, 0, CLDFB_NO_COL_MAX, workBuffer ); + + enerScale.lb_scale = negate( scale->lb_scale ); + enerScale.lb_scale16 = negate( scale->lb_scale ); + + AnalysisPostSpectrumScaling_Fx( st->cldfbAnaEnc, ppBuf_Real, ppBuf_Imag, ppBuf_Real16, ppBuf_Imag16, &enerScale.lb_scale16 ); + + GetEnergyCldfb( &st->energyCoreLookahead_Fx, &st->sf_energyCoreLookahead_Fx, 1, ppBuf_Real16, ppBuf_Imag16, enerScale.lb_scale16, st->cldfbAnaEnc->no_channels, st->cldfbAnaEnc->no_col, &st->currEnergyHF_fx, &st->currEnergyHF_e_fx, ppBuf_Ener, enerBuffSum_exp, st->hTECEnc ); + + return; +} /*-------------------------------------------------------------------* * GetEnergyCldfb_ivas() * @@ -2390,7 +2517,416 @@ static void cldfb_init_proto_and_twiddles( return; } +static void cldfb_init_proto_and_twiddles_enc( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +) +{ + /*find appropriate set of rotVecs*/ + switch ( hs->no_channels ) + { + case 10: + hs->rot_vec_ana_re = rot_vec_ana_re_L10; + hs->rot_vec_ana_im = rot_vec_ana_im_L10; + hs->rot_vec_syn_re = rot_vec_syn_re_L10; + hs->rot_vec_syn_im = rot_vec_syn_im_L10; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L10_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L10_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L10_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L10_fx; + hs->rRotVctr = rRotVectr_10; + hs->iRotVctr = iRotVectr_10; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_10_flt; + hs->scale_flt = CLDFB80_10_SCALE; + hs->ds = 10; + hs->da = 10; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17036; + hs->scale = cldfb_scale_2_5ms[0]; + hs->p_filter = cldfb_protoFilter_2_5ms[0]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_10; + hs->scale_flt = LDQMF_10_SCALE; + hs->ds = 40; + hs->da = -20; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15388; + hs->p_filter = cldfb_protoFilter_5_0ms[0]; + hs->scale = cldfb_scale_5_0ms[0]; +#endif + } + break; + case 16: + hs->rot_vec_ana_re = rot_vec_ana_re_L16; + hs->rot_vec_ana_im = rot_vec_ana_im_L16; + hs->rot_vec_syn_re = rot_vec_syn_re_L16; + hs->rot_vec_syn_im = rot_vec_syn_im_L16; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L16_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L16_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L16_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L16_fx; + hs->rRotVctr = rRotVectr_16; + hs->iRotVctr = iRotVectr_16; + { + hs->anaScalefactor = add( cldfb_anaScale[1], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_16_flt; + hs->scale_flt = CLDFB80_16_SCALE; + hs->ds = 20; + hs->da = 20; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17051; + hs->p_filter = cldfb_protoFilter_2_5ms[1]; + hs->scale = cldfb_scale_2_5ms[1]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_16; + hs->scale_flt = LDQMF_16_SCALE; + hs->ds = 80; + hs->da = -40; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15388; + hs->p_filter = cldfb_protoFilter_5_0ms[1]; + hs->scale = cldfb_scale_5_0ms[1]; +#endif + } + break; + + case 20: + hs->rot_vec_ana_re = rot_vec_ana_re_L20; + hs->rot_vec_ana_im = rot_vec_ana_im_L20; + hs->rot_vec_syn_re = rot_vec_syn_re_L20; + hs->rot_vec_syn_im = rot_vec_syn_im_L20; +#ifdef IVAS_FLOAT_FIXED + hs->rRotVctr = rRotVectr_20; + hs->iRotVctr = iRotVectr_20; + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L20_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L20_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L20_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L20_fx; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_20_flt; + hs->scale_flt = CLDFB80_20_SCALE; + hs->ds = 20; + hs->da = 20; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17050; + hs->p_filter = cldfb_protoFilter_2_5ms[2]; + hs->scale = cldfb_scale_2_5ms[2]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_20; + hs->scale_flt = LDQMF_20_SCALE; + hs->ds = 80; + hs->da = -40; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15390; + hs->p_filter = cldfb_protoFilter_5_0ms[2]; + hs->scale = cldfb_scale_5_0ms[2]; +#endif + } + break; + + case 30: + hs->rot_vec_ana_re = rot_vec_ana_re_L30; + hs->rot_vec_ana_im = rot_vec_ana_im_L30; + hs->rot_vec_syn_re = rot_vec_syn_re_L30; + hs->rot_vec_syn_im = rot_vec_syn_im_L30; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L30_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L30_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L30_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L30_fx; + hs->rRotVctr = rRotVectr_30; + hs->iRotVctr = iRotVectr_30; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[6], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[6], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_30_flt; + hs->scale_flt = CLDFB80_30_SCALE; + hs->ds = 30; + hs->da = 30; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17051; + hs->scale = cldfb_scale_2_5ms[6]; + hs->p_filter = cldfb_protoFilter_2_5ms[6]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_30; + hs->scale_flt = LDQMF_30_SCALE; + hs->ds = 120; + hs->da = -60; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15388; + hs->scale = cldfb_scale_5_0ms[6]; + hs->p_filter = cldfb_protoFilter_5_0ms[6]; +#endif + } + break; + + case 32: + hs->rot_vec_ana_re = rot_vec_ana_re_L32; + hs->rot_vec_ana_im = rot_vec_ana_im_L32; + hs->rot_vec_syn_re = rot_vec_syn_re_L32; + hs->rot_vec_syn_im = rot_vec_syn_im_L32; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L32_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L32_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L32_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L32_fx; + hs->rRotVctr = rRotVectr_32; + hs->iRotVctr = iRotVectr_32; + { + hs->anaScalefactor = add( cldfb_anaScale[3], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_32_flt; + hs->scale_flt = CLDFB80_32_SCALE; + hs->ds = 32; + hs->da = 32; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17050; + hs->p_filter = cldfb_protoFilter_2_5ms[3]; + hs->scale = cldfb_scale_2_5ms[3]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_32; + hs->scale_flt = LDQMF_32_SCALE; + hs->ds = 160; + hs->da = -80; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15392; + hs->scale = cldfb_scale_5_0ms[3]; + hs->p_filter = cldfb_protoFilter_5_0ms[3]; +#endif + } + break; + + case 40: + hs->rot_vec_ana_re = rot_vec_ana_re_L40; + hs->rot_vec_ana_im = rot_vec_ana_im_L40; + hs->rot_vec_syn_re = rot_vec_syn_re_L40; + hs->rot_vec_syn_im = rot_vec_syn_im_L40; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L40_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L40_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L40_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L40_fx; + hs->rRotVctr = rRotVectr_40; + hs->iRotVctr = iRotVectr_40; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_40_flt; + hs->scale_flt = CLDFB80_40_SCALE; + hs->ds = 40; + hs->da = 40; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17051; + hs->q_scale = norm_s( (Word16) CLDFB80_40_SCALE ); + hs->scale = cldfb_scale_2_5ms[4]; + hs->p_filter = cldfb_protoFilter_2_5ms[4]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_40; + hs->scale_flt = LDQMF_40_SCALE; + hs->ds = 160; + hs->da = -80; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15391; + hs->p_filter = cldfb_protoFilter_5_0ms[4]; + hs->scale = cldfb_scale_5_0ms[4]; +#endif + } + break; + + case 60: + hs->rot_vec_ana_re = rot_vec_ana_re_L60; + hs->rot_vec_ana_im = rot_vec_ana_im_L60; + hs->rot_vec_syn_re = rot_vec_syn_re_L60; + hs->rot_vec_syn_im = rot_vec_syn_im_L60; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L60_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L60_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L60_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L60_fx; + hs->rRotVctr = rRotVectr_60; + hs->iRotVctr = iRotVectr_60; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_60_flt; + hs->scale_flt = CLDFB80_60_SCALE; + hs->ds = 60; + hs->da = 60; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17051; + hs->p_filter = cldfb_protoFilter_2_5ms[5]; + hs->scale = cldfb_scale_2_5ms[5]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_60; + hs->scale_flt = LDQMF_60_SCALE; + hs->ds = 240; + hs->da = -120; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15391; + hs->p_filter = cldfb_protoFilter_5_0ms[5]; + hs->scale = cldfb_scale_5_0ms[5]; +#endif + } + break; + } + + return; +} /*-------------------------------------------------------------------* * cldfb_save_memory_ivas() * diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 59c8df221..9fa073106 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -1286,7 +1286,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) } } - IF( GE_16( numberBands, freqTable[1] ) ) + IF( GE_16( numberBands, freqTable[1] ) && hTecEnc != NULL) { Word32 *tempEnergyValuesArry[CLDFB_NO_COL_MAX]; Word16 ScaleX2; diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index e8e69432f..c43d08014 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -307,9 +307,10 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) /* calculate the spectrum of random excitation signal */ Copy( exc2, fft_io, L_frame ); + Word16 Q_new_inp, mem_decim_size; // TO be removed IF( EQ_16( L_frame, L_FRAME16k ) ) { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem1, 0 ); + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem1, 0, &Q_new_inp, &mem_decim_size ); } /* fft_rel(fft_io, L_FFT, LOG2_L_FFT); */ @@ -443,7 +444,7 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) IF( EQ_16( L_frame, L_FRAME16k ) ) { - modify_Fs_fx( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0 ); + modify_Fs_fx( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0, &Q_new_inp, &mem_decim_size ); } /* enr1 = dotp( fft_io, fft_io, L_frame ) / L_frame; */ diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 55eafef53..e5dfef089 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -2881,6 +2881,7 @@ typedef enum SIGNAL_CLASSIFER_MODE #define SCALE_GAIN_ANA_16 ( 3 ) #define SCALE_GAIN_ANA_20 ( 3 ) #define SCALE_GAIN_ANA_32 ( 2 ) +#define SCALE_GAIN_ANA_30 ( 2 ) #define SCALE_GAIN_ANA_40 ( 2 ) #define SCALE_GAIN_ANA_60 ( 1 ) @@ -2892,6 +2893,7 @@ typedef enum SIGNAL_CLASSIFER_MODE #define SCALE_CLDFB_ANA_32 ( SCALE_MODULATION + SCALE_GAIN_ANA_32 ) #define SCALE_CLDFB_ANA_40 ( SCALE_MODULATION + SCALE_GAIN_ANA_40 ) #define SCALE_CLDFB_ANA_60 ( SCALE_MODULATION + SCALE_GAIN_ANA_60 ) +#define SCALE_CLDFB_ANA_30 ( SCALE_MODULATION + SCALE_GAIN_ANA_30 ) #define SCALE_CLDFB_SYN_10 ( SCALE_MODULATION + SCALE_GAIN_SYN ) #define SCALE_CLDFB_SYN_16 ( SCALE_MODULATION + SCALE_GAIN_SYN ) @@ -2899,6 +2901,7 @@ typedef enum SIGNAL_CLASSIFER_MODE #define SCALE_CLDFB_SYN_32 ( SCALE_MODULATION + SCALE_GAIN_SYN ) #define SCALE_CLDFB_SYN_40 ( SCALE_MODULATION + SCALE_GAIN_SYN ) #define SCALE_CLDFB_SYN_60 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_30 ( SCALE_MODULATION + SCALE_GAIN_SYN ) /************************************************************************/ /* FFT */ diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index 730a2fe7e..486f3a8db 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -355,7 +355,7 @@ void ivas_imdct_fx( * * Sets/Maps the fft twiddle tables based on fft length *-----------------------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_get_twid_factors_fx1( const Word16 length, const Word16 **pTwid_re, @@ -388,7 +388,7 @@ void ivas_get_twid_factors_fx1( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_get_mdct_scaling_gain_fx() diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 06a1d8d1e..ffb1b6014 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -162,8 +162,8 @@ ivas_error ivas_sce_enc( ivas_error ivas_cpe_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ - const float data_f_ch0[], /* i : input signal for channel 0 */ - const float data_f_ch1[], /* i : input signal for channel 1 */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ const int16_t input_frame, /* i : input frame length per channel */ const int16_t nb_bits_metadata /* i : number of metadata bits */ ); @@ -221,6 +221,51 @@ ivas_error pre_proc_front_ivas( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); +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 int32_t element_brate, /* i : SCE/CPE element bitrate */ + const int16_t nb_bits_metadata, /* i : number of metadata bits */ + const int16_t input_frame, /* i : frame length */ + const int16_t n, /* i : channel number */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float *relE, /* o : frame relative energy */ + float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* o : LP prediction errors */ + float lsp_new[M], /* o : LSPs at the end of the frame */ + float lsp_mid[M], /* o : LSPs in the middle of the frame */ + int16_t *vad_hover_flag, /* o : VAD hangover flag */ + int16_t *attack_flag, /* o : flag signaling attack */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ + float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ + int16_t *loc_harm, /* o : harmonicity flag */ + float *cor_map_sum, /* o : speech/music clasif. parameter */ + int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ + const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ + const float currFlatness, /* i : flatness parameter */ + const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const float Etot_LR[], /* i : total energy Left & Right channel */ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const int16_t force_front_vad, /* i : flag to force VAD decision */ + const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +); ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ const int16_t last_element_mode, /* i : last element mode */ @@ -2575,7 +2620,6 @@ void tdm_low_rate_dec( float *bwe_exc, /* o : excitation for SWB TBE */ const float *lsf_new /* i : ISFs at the end of the frame */ ); - #ifdef IVAS_FLOAT_FIXED void tdm_SCh_LSF_intra_pred_fx( const Word32 element_brate, /* i : element bitrate */ @@ -2583,7 +2627,6 @@ void tdm_SCh_LSF_intra_pred_fx( Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ ); #endif - void tdm_SCh_LSF_intra_pred( const int32_t element_brate, /* i : element bitrate */ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 7a8054ca1..12a8e69c8 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2417,4 +2417,10 @@ void copy_masa_descriptive_meta_fx( void efap_free_data_fx( EFAP_HANDLE *hEFAPdata /* i/o: EFAP handle to be freed */ ); + +void tdm_SCh_LSF_intra_pred_fx( + const Word32 element_brate, /* i : element bitrate */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ +); #endif diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index cc37a8565..ace600eab 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -6835,6 +6835,4 @@ const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[9] = 0, /* offset */ { +0.000000e+000f, +5.937500e-002f, +1.375000e-001f, +2.343750e-001f, +3.500000e-001f, +4.843750e-001f, +6.375000e-001f, +8.093750e-001f, +1.000000e+000f } /* data */ } -}; - -/* clang-format on */ +}; \ No newline at end of file diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 85bd01c21..a89745452 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -106,6 +106,23 @@ extern const float tdm_den_ratio_tabl[]; extern const int16_t tdm_bit_allc_tbl[5][6]; /* LSFs Intra-frame prediction tables */ +#ifdef IVAS_FLOAT_FIXED +extern const Word16 tdm_LSF_MEAN_RE_USE_OUT_fx[M]; +extern const Word16 tdm_LSF_MEAN_RE_USE_IN_fx[M]; +extern const Word16 tdm_LSF_MEAN_RE_USE_fx[M]; + +extern const Word16 tdm_Beta_Q1bit_re_use_13k2_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_16k4_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_24k4_32k_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_48k_fx[2]; + +extern const Word16 tdm_RE_USE_adaptive_beta_prd_diag_3_fx[15 + 16 + 15]; + +extern const Word16 tdm_LSF_MEAN_PRED_QNT_OUT_fx[M]; +extern const Word16 tdm_LSF_MEAN_PRED_QNT_IN_fx[M]; +extern const Word16 tdm_LSF_MEAN_PRED_QNT_fx[M]; +extern const Word16 tdm_PRED_QNT_fixed_beta_prd_diag_3_fx[15 + 16 + 15]; +#endif extern const float tdm_LSF_MEAN_RE_USE_OUT[M]; extern const float tdm_LSF_MEAN_RE_USE_IN[M]; extern const float tdm_LSF_MEAN_RE_USE[M]; diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index fa12252ad..1845bcde2 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -47,7 +47,9 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Word16 sigOut_fx[], /* o : decimated signal Q0 */ const Word32 fout, /* i : frequency of output Q0 */ Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp /* i : flag indicating if NB low-pass is applied */ + const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ + Word16 *Q_new_inp, // TO be removed + Word16 *mem_decim_size // TO be removed ) { Word16 i; @@ -79,13 +81,14 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ /*-------------------------------------------------------------------* * Find the resampling configuration *-------------------------------------------------------------------*/ - + *Q_new_inp = 0; /* check if fin and fout are the same */ IF( EQ_32( fin, fout ) ) { /* just copy the signal_fx and quit */ Copy( sigIn_fx, sigOut_fx, lg ); - + *mem_decim_size = 0; + *Q_new_inp = 0; return lg; } ELSE @@ -150,6 +153,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ } mem_len = shl( filt_len, 1 ); + *mem_decim_size = mem_len; signal_fx = signal_tab_fx + 2 * L_FILT_MAX + sub( L_FRAME48k, add( mem_len, lg ) ); signal_ana_fx = signal_fx; mem_len_ana = mem_len; @@ -254,6 +258,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ } /* rescaling */ test(); + IF( ( GT_16( fac_num, fac_den ) ) == ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) { IF( LT_16( fac_num, fac_den ) ) @@ -266,6 +271,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR( i = 0; i < lg_out; i++ ) { sigOut_fx[i] = round_fx( L_shl( L_mult( sigOut_fx[i], num_den ), 1 ) ); /*Q0*/ + *Q_new_inp = -1; } } ELSE @@ -277,6 +283,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { #ifdef BASOP_NOGLOB num_den = shl_o( num_den, 1, &Overflow ); + //*Q_new_inp = 2; #else num_den = shl( num_den, 1 ); #endif @@ -286,6 +293,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], num_den ); /*Q0*/ move16(); } + *Q_new_inp = -1; } } ELSE @@ -298,6 +306,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = mult_r( sigOut_fx[i], num_den ); /*Q-1*/ move16(); + *Q_new_inp = -2; } } ELSE @@ -306,6 +315,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR( i = 0; i < lg_out; i++ ) { sigOut_fx[i] = round_fx( L_mac( L_deposit_h( sigOut_fx[i] ), sigOut_fx[i], num_den ) ); /*Q0*/ + *Q_new_inp = -1; } } } @@ -316,6 +326,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = mult_r( sigOut_fx[i], 16384 ); move16(); /*Q-1*/ + *Q_new_inp = -2; } } /* update the filter memory */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 03ce573b9..7bfe52d3e 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -9347,6 +9347,11 @@ void configureCldfb_ivas( const int32_t sampling_rate /* i : sampling rate */ ); +void configureCldfb_ivas_enc( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ + const int32_t sampling_rate /* i : sampling rate */ +); + void analysisCldfbEncoder_ivas( Encoder_State *st, /* i/o: encoder state structure */ const float *timeIn, @@ -9355,6 +9360,17 @@ void analysisCldfbEncoder_ivas( float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float *ppBuf_Ener ); +void analysisCldfbEncoder_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *timeIn, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 *ppBuf_Ener, + Word16 *enerBuffSum_exp, + CLDFB_SCALE_FACTOR *scale ); + ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ @@ -9362,6 +9378,13 @@ ivas_error openCldfb_ivas( CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ); +ivas_error openCldfb_ivas_enc( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + const int32_t sampling_rate, /* i : sampling rate */ + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ +); + void resampleCldfb_ivas( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ const int32_t newSamplerate /* i : new samplerate to operate */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 131a12285..7975ff65f 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -220,6 +220,14 @@ void deindex_lvq_SHB_fx( const Word16 nbits, const Word16 mode ); +Word16 deindex_lvq_ivas_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits /* i : number of bits for lattice */ +); + void permute_fx( Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ @@ -881,6 +889,13 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability const Word16 L_frame /* i : frame length */ ); +Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ +); + void reorder_isf_fx( Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ const Word16 min_dist, /* i : minimum required distance */ @@ -925,6 +940,17 @@ Word16 vq_dec_lvq_fx( Word16 *p_no_scales, Word16 *p_no_scales_p ); +Word16 vq_dec_lvq_ivas_fx( + Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ + Word16 no_bits /* (i): no. bits for lattice */ +); +void a2rc_fx( const Word16 *a, Word16 *refl, Word16 lpcorder ); + Word16 vq_dec_lvq_ivas_fx( Word16 sf_flag, /* i : safety net flag */ Word16 x[], /* o : Decoded vector Q(x2.56)*/ @@ -2263,15 +2289,17 @@ Word32 Interpol_lc_fx( /* o : interpolated value ); -// modif_fs_fx.c -Word16 modify_Fs_fx( /* o : length of output Q0 */ - const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ - const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp /* i : flag indicating if NB low-pass is applied */ +//modif_fs_fx.c +Word16 modify_Fs_fx( /* o : length of output Q0 */ + const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ + Word16 lg, /* i : length of input Q0 */ + const Word32 fin, /* i : frequency of input Q0 */ + Word16 sigOut_fx[], /* o : decimated signal Q0 */ + const Word32 fout, /* i : frequency of output Q0 */ + Word16 mem_fx[], /* i/o: filter memory Q0 */ + const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ + Word16 *Q_new_inp, //TO be removed + Word16 *mem_decim_size //TO be removed ); Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 22589b96f..58be1cf3f 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -2627,9 +2627,21 @@ const float interpol_frac2_mid[NB_SUBFR*3] = { 0.0f, 0.25f, 0.75f }; +const Word16 interpol_frac2_mid_fx[NB_SUBFR * 3] = { + 8191, 24575, 0, + 8191, 24575, 0, + 0, 8191, 24575, + 0, 8191, 24575 +}; + const float interpol_frac_12k8[NB_SUBFR] = { 0.25f, 0.5f, 0.75f, 1.0f }; + +const Word16 interpol_frac_12k8_fx[NB_SUBFR] = { + 8191, 16383, 24575, 32767 +}; + const Word16 interpol_frac_fx[NB_SUBFR] = { 8192, 16384, 24576,32767 }; const float interpol_isp_amr_wb[NB_SUBFR] = { @@ -10093,6 +10105,512 @@ const Word16 CLDFB80_60[] = W16(0x0002), W16(0x0020), W16(0xff00), W16(0xe05e), W16(0x00a9) }; +const Word16 CLDFB80_30[] = +{ + 0, -5, -30, 278, 8546, + 0, -4, -33, 306, 9141, + 0, -2, -29, 334, 9735, + 0, -1, -17, 363, 10324, + 0, -1, -13, 397, 10904, + 0, -1, -9, 435, 11474, + 0, -1, -2, 478, 12028, + 0, 0, 6, 525, 12566, + 0, 0, 12, 578, 13083, + 0, 0, 19, 637, 13579, + 0, 0, 26, 701, 14050, + 0, 0, 28, 771, 14493, + 0, 0, 30, 846, 14906, + 0, 0, 28, 927, 15285, + 0, 0, 4, 1012, 15630, + 0, -1, 27, 1105, 15937, + 0, -1, 26, 1201, 16209, + 0, 0, 29, 1299, 16442, + 0, 1, 31, 1399, 16638, + 0, 0, 36, 1498, 16794, + 0, 0, 41, 1594, 16911, + 0, -1, 45, 1687, 16990, + 0, 0, 46, 1774, 17036, + 0, 0, 49, 1853, 17052, + 0, 0, 50, 1922, 17040, + 0, 0, 50, 1981, 16999, + 0, 0, 45, 2027, 16924, + 0, -1, 39, 2061, 16809, + 0, -4, 27, 2080, 16651, + 0, -10, 12, 2084, 16463, + 0, -17, -10, 2075, 16161, + 0, -16, -23, 2054, 15746, + 0, -10, -31, 2012, 15307, + 0, -4, -32, 1949, 14834, + 0, -2, -26, 1862, 14334, + 0, -3, -15, 1752, 13816, + 0, -2, -1, 1616, 13288, + 0, 0, 13, 1454, 12753, + 0, -1, 25, 1267, 12212, + 0, 0, 35, 1054, 11663, + 0, 0, 42, 815, 11104, + 0, 1, 45, 552, 10536, + 0, -2, 42, 263, 9960, + 0, -3, 37, -51, 9379, + 0, 9, 33, -391, 8795, + 0, -12, 25, -755, 8207, + 0, 3, 4, -1144, 7616, + 0, 2, -14, -1557, 7022, + 0, -2, -34, -1992, 6427, + 0, 0, -54, -2449, 5833, + 0, 1, -73, -2927, 5244, + 0, 1, -90, -3425, 4659, + 0, 0, -107, -3942, 4072, + 0, 1, -123, -4476, 3479, + 0, 1, -139, -5026, 2877, + 0, -1, -156, -5590, 2272, + 0, 0, -176, -6167, 1684, + 0, 6, -199, -6754, 1144, + 0, 18, -223, -7348, 682, + 0, 32, -249, -7947, 282 +}; + +const Word16 LDQMF_10_enc_fx[] = +{ + 2, -21, 79, -1890, 8640, + 1, -35, -5, -3186, 7299, + -1, -49, -126, -4597, 5995, + -3, -62, -285, -6085, 4767, + -5, -74, -484, -7607, 3646, + -6, -84, -721, -9114, 2656, + -7, -92, -989, -10557, 1815, + -7, -99, -1279, -11885, 1125, + -8, -104, -1579, -13052, 583, + -10, -108, -1869, -14017, 175, + -15, -112, -2129, -14742, -104, + -21, -117, -2336, -15204, -267, + -27, -123, -2462, -15389, -354, + -31, -132, -2482, -15293, -380, + -33, -144, -2370, -14926, -359, + -32, -156, -2104, -14306, -304, + -27, -166, -1668, -13461, -230, + -18, -169, -1049, -12429, -152, + -7, -160, -246, -11250, -82, + 6, -132, 739, -9972, -31 +}; + +const Word16 LDQMF_16_enc_fx[] = +{ + 2, -18, 91, -1662, 8892, + 2, -27, 46, -2441, 8051, + 1, -36, -12, -3271, 7216, + 0, -45, -84, -4146, 6396, + -2, -53, -171, -5056, 5602, + -3, -61, -274, -5991, 4841, + -5, -69, -392, -6940, 4121, + -6, -76, -526, -7892, 3449, + -6, -82, -674, -8835, 2831, + -7, -88, -835, -9756, 2270, + -7, -93, -1007, -10643, 1767, + -7, -97, -1187, -11485, 1324, + -7, -101, -1373, -12269, 941, + -8, -104, -1560, -12985, 613, + -9, -106, -1744, -13622, 338, + -11, -109, -1921, -14172, 111, + -14, -111, -2084, -14626, -64, + -17, -114, -2228, -14977, -185, + -21, -117, -2346, -15223, -274, + -25, -121, -2433, -15361, -334, + -28, -126, -2481, -15389, -368, + -31, -132, -2484, -15307, -380, + -33, -139, -2436, -15119, -373, + -33, -146, -2332, -14828, -350, + -32, -154, -2167, -14440, -316, + -30, -161, -1935, -13962, -273, + -26, -166, -1635, -13402, -225, + -21, -169, -1263, -12769, -176, + -15, -168, -818, -12074, -128, + -8, -161, -301, -11328, -86, + 0, -147, 286, -10541, -50, + 9, -124, 942, -9725, -23 +}; + +const Word16 LDQMF_20_enc_fx[] = +{ + 2, -17, 95, -1588, 8976, + 2, -24, 61, -2202, 8303, + 1, -32, 19, -2850, 7632, + 1, -39, -32, -3530, 6968, + 0, -46, -92, -4236, 6316, + -2, -53, -162, -4964, 5680, + -3, -59, -241, -5708, 5065, + -4, -65, -331, -6464, 4475, + -5, -71, -431, -7226, 3914, + -6, -76, -540, -7987, 3385, + -6, -81, -658, -8741, 2890, + -7, -86, -785, -9482, 2432, + -7, -90, -919, -10205, 2011, + -7, -94, -1060, -10901, 1628, + -7, -97, -1205, -11566, 1283, + -7, -100, -1354, -12194, 976, + -7, -103, -1504, -12778, 706, + -8, -105, -1653, -13314, 470, + -9, -107, -1798, -13797, 266, + -11, -109, -1938, -14222, 90, + -14, -111, -2068, -14585, -49, + -16, -113, -2187, -14883, -153, + -19, -115, -2290, -15114, -234, + -22, -118, -2376, -15276, -295, + -25, -121, -2439, -15369, -338, + -28, -125, -2478, -15391, -365, + -30, -130, -2488, -15343, -378, + -32, -135, -2467, -15226, -378, + -33, -141, -2411, -15042, -368, + -33, -147, -2319, -14794, -347, + -32, -153, -2186, -14483, -320, + -31, -159, -2012, -14114, -286, + -28, -164, -1794, -13691, -249, + -25, -167, -1531, -13219, -210, + -21, -169, -1221, -12702, -171, + -16, -168, -866, -12146, -133, + -10, -164, -464, -11556, -98, + -4, -155, -16, -10938, -67, + 3, -141, 476, -10298, -41, + 9, -121, 1012, -9642, -21, +}; +const Word16 LDQMF_30_enc_fx[] = +{ + 2, -16, 100, -1489, 9088, + 2, -21, 79, -1890, 8640, + 2, -26, 55, -2307, 8191, + 2, -30, 27, -2740, 7744, + 1, -35, -5, -3186, 7299, + 0, -40, -41, -3646, 6858, + 0, -45, -81, -4116, 6423, + -1, -49, -126, -4597, 5995, + -2, -54, -174, -5087, 5576, + -3, -58, -227, -5583, 5166, + -3, -62, -285, -6085, 4767, + -4, -66, -347, -6591, 4380, + -5, -70, -413, -7099, 4006, + -5, -74, -484, -7607, 3646, + -6, -77, -559, -8113, 3300, + -6, -81, -638, -8616, 2970, + -6, -84, -721, -9114, 2656, + -7, -87, -807, -9604, 2359, + -7, -89, -896, -10086, 2078, + -7, -92, -989, -10557, 1815, + -7, -94, -1084, -11015, 1568, + -7, -97, -1181, -11458, 1338, + -7, -99, -1279, -11885, 1125, + -7, -101, -1379, -12294, 929, + -7, -102, -1479, -12684, 748, + -8, -104, -1579, -13052, 583, + -8, -105, -1677, -13398, 433, + -9, -107, -1774, -13720, 297, + -10, -108, -1869, -14017, 175, + -11, -109, -1960, -14287, 63, + -13, -110, -2047, -14529, -30, + -15, -112, -2129, -14742, -104, + -17, -113, -2205, -14926, -168, + -19, -115, -2274, -15080, -222, + -21, -117, -2336, -15204, -267, + -23, -118, -2388, -15296, -303, + -25, -121, -2430, -15358, -332, + -27, -123, -2462, -15389, -354, + -28, -126, -2482, -15388, -369, + -30, -129, -2489, -15356, -377, + -31, -132, -2482, -15293, -380, + -32, -136, -2460, -15200, -377, + -33, -140, -2423, -15078, -370, + -33, -144, -2370, -14926, -359, + -33, -148, -2299, -14746, -343, + -33, -152, -2211, -14539, -325, + -32, -156, -2104, -14306, -304, + -31, -160, -1979, -14047, -281, + -29, -163, -1833, -13765, -256, + -27, -166, -1668, -13461, -230, + -24, -168, -1482, -13136, -204, + -22, -169, -1276, -12791, -177, + -18, -169, -1049, -12429, -152, + -15, -168, -802, -12050, -127, + -11, -165, -534, -11657, -103, + -7, -160, -246, -11250, -82, + -3, -153, 63, -10833, -62, + 1, -144, 391, -10406, -45, + 6, -132, 739, -9972, -31, + 11, -117, 1105, -9532, -17 +}; + +const Word16 LDQMF_32_enc_fx[] = +{ + 2, -16, 101, -1477, 9102, + 2, -20, 81, -1852, 8682, + 2, -25, 59, -2241, 8261, + 2, -29, 33, -2644, 7841, + 1, -34, 4, -3059, 7424, + 1, -38, -28, -3486, 7009, + 0, -43, -64, -3924, 6599, + -1, -47, -104, -4371, 6195, + -1, -51, -148, -4826, 5798, + -2, -55, -195, -5288, 5408, + -3, -59, -247, -5755, 5027, + -4, -63, -302, -6227, 4657, + -4, -67, -361, -6702, 4297, + -5, -71, -424, -7178, 3948, + -5, -74, -491, -7654, 3613, + -6, -77, -561, -8129, 3290, + -6, -80, -635, -8600, 2980, + -6, -83, -713, -9067, 2685, + -7, -86, -793, -9528, 2404, + -7, -89, -877, -9981, 2138, + -7, -91, -963, -10425, 1887, + -7, -94, -1051, -10859, 1651, + -7, -96, -1141, -11280, 1430, + -7, -98, -1233, -11687, 1223, + -7, -100, -1326, -12079, 1031, + -7, -101, -1420, -12455, 854, + -7, -103, -1513, -12813, 690, + -8, -104, -1606, -13152, 540, + -9, -106, -1699, -13471, 402, + -9, -107, -1789, -13768, 277, + -10, -108, -1878, -14043, 164, + -12, -109, -1963, -14295, 60, + -13, -110, -2045, -14522, -27, + -15, -112, -2122, -14724, -97, + -17, -113, -2194, -14899, -158, + -18, -114, -2260, -15049, -211, + -20, -116, -2319, -15172, -255, + -22, -118, -2371, -15268, -292, + -24, -120, -2414, -15337, -321, + -26, -122, -2449, -15378, -344, + -27, -124, -2473, -15392, -361, + -29, -127, -2486, -15379, -373, + -30, -130, -2488, -15338, -379, + -31, -133, -2477, -15270, -380, + -32, -137, -2453, -15176, -376, + -33, -140, -2416, -15056, -369, + -33, -144, -2364, -14910, -357, + -33, -148, -2297, -14740, -343, + -33, -152, -2214, -14546, -325, + -32, -156, -2115, -14329, -306, + -31, -159, -1999, -14089, -284, + -29, -162, -1867, -13829, -261, + -27, -165, -1716, -13549, -237, + -25, -167, -1548, -13250, -213, + -23, -169, -1362, -12933, -188, + -20, -169, -1158, -12601, -164, + -17, -169, -936, -12253, -140, + -13, -167, -696, -11892, -117, + -10, -163, -437, -11518, -96, + -6, -158, -161, -11134, -76, + -2, -151, 133, -10741, -58, + 2, -142, 444, -10339, -43, + 6, -131, 772, -9931, -29, + 11, -117, 1117, -9518, -17 +}; + +const Word16 LDQMF_40_enc_fx[] = +{ + 2, -15, 102, -1440, 9144, + 2, -19, 87, -1738, 8808, + 2, -22, 70, -2045, 8472, + 2, -26, 51, -2361, 8135, + 2, -30, 30, -2685, 7800, + 1, -33, 7, -3017, 7465, + 1, -37, -18, -3357, 7133, + 0, -41, -46, -3704, 6804, + 0, -44, -76, -4057, 6477, + -1, -48, -108, -4416, 6155, + -1, -51, -143, -4780, 5837, + -2, -54, -181, -5148, 5524, + -3, -57, -220, -5521, 5216, + -3, -61, -263, -5896, 4915, + -4, -64, -308, -6274, 4620, + -4, -67, -355, -6654, 4332, + -5, -69, -405, -7035, 4052, + -5, -72, -457, -7416, 3779, + -6, -75, -512, -7797, 3514, + -6, -78, -569, -8176, 3258, + -6, -80, -628, -8553, 3011, + -6, -83, -689, -8928, 2772, + -6, -85, -753, -9299, 2543, + -7, -87, -818, -9665, 2323, + -7, -89, -885, -10026, 2113, + -7, -91, -954, -10381, 1912, + -7, -93, -1024, -10730, 1720, + -7, -95, -1096, -11071, 1538, + -7, -96, -1169, -11403, 1366, + -7, -98, -1242, -11727, 1203, + -7, -99, -1317, -12041, 1050, + -7, -101, -1391, -12344, 905, + -7, -102, -1466, -12636, 770, + -8, -103, -1541, -12917, 644, + -8, -104, -1616, -13185, 526, + -8, -106, -1690, -13440, 416, + -9, -107, -1762, -13681, 314, + -10, -107, -1834, -13909, 219, + -11, -108, -1904, -14121, 132, + -12, -109, -1971, -14319, 50, + -13, -110, -2037, -14501, -20, + -14, -111, -2099, -14666, -77, + -16, -112, -2158, -14815, -129, + -17, -113, -2214, -14947, -175, + -19, -115, -2266, -15063, -215, + -20, -116, -2314, -15161, -251, + -22, -117, -2356, -15242, -281, + -23, -119, -2394, -15306, -307, + -25, -120, -2426, -15352, -329, + -26, -122, -2451, -15381, -346, + -27, -124, -2471, -15392, -360, + -29, -126, -2483, -15386, -370, + -30, -129, -2488, -15362, -376, + -31, -131, -2486, -15320, -379, + -32, -134, -2475, -15262, -379, + -32, -136, -2456, -15187, -377, + -33, -139, -2429, -15095, -371, + -33, -142, -2392, -14986, -363, + -33, -145, -2345, -14862, -353, + -33, -148, -2289, -14722, -341, + -33, -151, -2223, -14566, -327, + -32, -154, -2147, -14396, -312, + -31, -157, -2059, -14212, -295, + -30, -160, -1961, -14013, -277, + -29, -163, -1852, -13802, -259, + -28, -165, -1732, -13578, -240, + -26, -167, -1601, -13342, -220, + -24, -168, -1458, -13094, -200, + -22, -169, -1303, -12835, -181, + -20, -169, -1137, -12567, -161, + -17, -169, -959, -12288, -142, + -14, -167, -770, -12002, -124, + -12, -165, -569, -11707, -106, + -9, -162, -356, -11404, -90, + -6, -158, -132, -11095, -74, + -2, -152, 103, -10780, -60, + 1, -145, 349, -10460, -47, + 4, -137, 606, -10136, -36, + 8, -127, 874, -9808, -26, + 11, -115, 1152, -9476, -15 +}; + +const Word16 LDQMF_60_enc_fx[] = +{ + 2, -14, 105, -1391, 9200, + 2, -17, 95, -1588, 8976, + 2, -19, 85, -1788, 8752, + 2, -22, 73, -1993, 8528, + 2, -24, 61, -2202, 8303, + 2, -27, 48, -2414, 8079, + 2, -29, 34, -2630, 7855, + 1, -32, 19, -2850, 7632, + 1, -34, 3, -3073, 7410, + 1, -36, -14, -3300, 7188, + 1, -39, -32, -3530, 6968, + 0, -41, -51, -3762, 6749, + 0, -44, -71, -3998, 6531, + 0, -46, -92, -4236, 6316, + -1, -48, -114, -4476, 6102, + -1, -50, -137, -4719, 5890, + -2, -53, -162, -4964, 5680, + -2, -55, -187, -5210, 5472, + -2, -57, -214, -5458, 5267, + -3, -59, -241, -5708, 5065, + -3, -61, -270, -5959, 4865, + -4, -63, -300, -6211, 4669, + -4, -65, -331, -6464, 4475, + -4, -67, -363, -6718, 4285, + -5, -69, -396, -6972, 4098, + -5, -71, -431, -7226, 3914, + -5, -73, -466, -7480, 3734, + -5, -75, -502, -7733, 3558, + -6, -76, -540, -7987, 3385, + -6, -78, -578, -8239, 3216, + -6, -80, -618, -8491, 3051, + -6, -81, -658, -8741, 2890, + -6, -83, -700, -8990, 2733, + -6, -84, -742, -9237, 2581, + -7, -86, -785, -9482, 2432, + -7, -87, -829, -9726, 2287, + -7, -89, -874, -9966, 2147, + -7, -90, -919, -10205, 2011, + -7, -91, -966, -10440, 1879, + -7, -93, -1012, -10672, 1751, + -7, -94, -1060, -10901, 1628, + -7, -95, -1108, -11127, 1509, + -7, -96, -1156, -11349, 1394, + -7, -97, -1205, -11566, 1283, + -7, -98, -1255, -11780, 1177, + -7, -99, -1304, -11989, 1075, + -7, -100, -1354, -12194, 976, + -7, -101, -1404, -12394, 882, + -7, -102, -1454, -12589, 792, + -7, -103, -1504, -12778, 706, + -8, -104, -1554, -12962, 623, + -8, -104, -1603, -13141, 545, + -8, -105, -1653, -13314, 470, + -9, -106, -1702, -13481, 398, + -9, -106, -1750, -13642, 330, + -9, -107, -1798, -13797, 266, + -10, -108, -1845, -13945, 204, + -11, -108, -1892, -14087, 146, + -11, -109, -1938, -14222, 90, + -12, -110, -1982, -14351, 38, + -13, -110, -2026, -14472, -9, + -14, -111, -2068, -14585, -49, + -14, -111, -2109, -14692, -86, + -15, -112, -2149, -14791, -121, + -16, -113, -2187, -14883, -153, + -17, -114, -2223, -14967, -182, + -18, -114, -2258, -15044, -209, + -19, -115, -2290, -15114, -234, + -20, -116, -2321, -15176, -256, + -21, -117, -2350, -15230, -277, + -22, -118, -2376, -15276, -295, + -23, -119, -2399, -15315, -311, + -24, -120, -2421, -15346, -326, + -25, -121, -2439, -15369, -338, + -26, -123, -2455, -15384, -349, + -27, -124, -2468, -15391, -358, + -28, -125, -2478, -15391, -365, + -29, -127, -2485, -15383, -371, + -30, -128, -2488, -15367, -375, + -30, -130, -2488, -15343, -378, + -31, -132, -2485, -15312, -380, + -31, -133, -2478, -15273, -380, + -32, -135, -2467, -15226, -378, + -32, -137, -2452, -15172, -376, + -33, -139, -2434, -15111, -372, + -33, -141, -2411, -15042, -368, + -33, -143, -2385, -14967, -362, + -33, -145, -2354, -14884, -355, + -33, -147, -2319, -14794, -347, + -33, -149, -2279, -14697, -339, + -33, -151, -2235, -14593, -330, + -32, -153, -2186, -14483, -320, + -32, -155, -2133, -14366, -309, + -32, -157, -2075, -14243, -298, + -31, -159, -2012, -14114, -286, + -30, -161, -1944, -13979, -274, + -29, -162, -1871, -13838, -262, + -28, -164, -1794, -13691, -249, + -27, -165, -1711, -13539, -236, + -26, -166, -1623, -13382, -223, + -25, -167, -1531, -13219, -210, + -24, -168, -1433, -13051, -197, + -22, -169, -1330, -12879, -184, + -21, -169, -1221, -12702, -171, + -19, -169, -1108, -12521, -158, + -18, -169, -990, -12335, -145, + -16, -168, -866, -12146, -133, + -14, -167, -737, -11953, -121, + -12, -166, -603, -11756, -109, + -10, -164, -464, -11556, -98, + -8, -161, -320, -11353, -87, + -6, -158, -170, -11147, -77, + -4, -155, -16, -10938, -67, + -2, -151, 143, -10727, -58, + 0, -146, 307, -10514, -49, + 3, -141, 476, -10298, -41, + 5, -135, 650, -10081, -34, + 7, -129, 829, -9862, -27, + 9, -121, 1012, -9642, -21, + 12, -113, 1199, -9421, -13 +}; /*! * \brief CLDFB rRotVectr @@ -10170,6 +10688,29 @@ const Word16 iRotVectr_20[] = W16(0xbec1), W16(0xb5bf), W16(0xae90), W16(0xa963), W16(0xa658) }; +/*! + * \brief CLDFB rRotVectr + * + * cldfb bands: 30 + * global gain: 2.50 + * scale: sqrt(1.0/4.00) + */ +const Word16 rRotVectr_30[] = +{ + 25902, 25725, 25265, 24529, 23525, 22262, 20756, 19022, 17080, 14950, 12657, 10226, 7682, 5054, 2370 +}; + +/*! + * \brief CLDFB iRotVectr + * + * cldfb bands: 30 + * global gain: 2.50 + * scale: sqrt(1.0/4.00) + */ +const Word16 iRotVectr_30[] = +{ + -339, -3045, -5717, -8327, -10845, -13245, -15499, -17584, -19476, -21154, -22601, -23801, -24739, -25406, -25796 +}; /*! * \brief CLDFB rRotVectr * @@ -10266,11 +10807,11 @@ const Word16 iRotVectr_60[] = const Word16 cldfb_anaScale[] = { - SCALE_CLDFB_ANA_10, SCALE_CLDFB_ANA_16, SCALE_CLDFB_ANA_20, SCALE_CLDFB_ANA_32, SCALE_CLDFB_ANA_40, SCALE_CLDFB_ANA_60 + SCALE_CLDFB_ANA_10, SCALE_CLDFB_ANA_16, SCALE_CLDFB_ANA_20, SCALE_CLDFB_ANA_32, SCALE_CLDFB_ANA_40, SCALE_CLDFB_ANA_60, SCALE_CLDFB_ANA_30 }; const Word16 cldfb_synScale[] = { - SCALE_CLDFB_SYN_10, SCALE_CLDFB_SYN_16, SCALE_CLDFB_SYN_20, SCALE_CLDFB_SYN_32, SCALE_CLDFB_SYN_40, SCALE_CLDFB_SYN_60 + SCALE_CLDFB_SYN_10, SCALE_CLDFB_SYN_16, SCALE_CLDFB_SYN_20, SCALE_CLDFB_SYN_32, SCALE_CLDFB_SYN_40, SCALE_CLDFB_SYN_60, SCALE_CLDFB_SYN_30 }; const Word16 cldfb_synGain[] = { @@ -10284,8 +10825,14 @@ const Word16 cldfb_synGain[] = const Word16 *cldfb_protoFilter_2_5ms[] = { - CLDFB80_10, CLDFB80_16, CLDFB80_20, CLDFB80_32, CLDFB80_40, CLDFB80_60 + CLDFB80_10, CLDFB80_16, CLDFB80_20, CLDFB80_32, CLDFB80_40, CLDFB80_60, CLDFB80_30 +}; +#ifdef IVAS_FLOAT_FIXED +const Word16 *cldfb_protoFilter_5_0ms[] = +{ + LDQMF_10_enc_fx, LDQMF_16_enc_fx, LDQMF_20_enc_fx, LDQMF_32_enc_fx, LDQMF_40_enc_fx, LDQMF_60_enc_fx, LDQMF_30_enc_fx }; +#endif const Word16 cldfb_scale_2_5ms[7] = { 22603/*88.293854 Q8*/, /* 10 bands */ @@ -10293,8 +10840,22 @@ const Word16 cldfb_scale_2_5ms[7] = 22605/*88.300926 Q8*/, /* 20 bands */ 22606/*88.303848 Q8*/, /* 32 bands */ 22606/*88.304718 Q8*/, /* 40 bands */ - 22535/*88.028412 Q8*/ /* 60 bands */ + 22535/*88.028412 Q8*/, /* 60 bands */ + 22588/*88.234489 Q8*/ /* 30 bands */ }; + +#ifdef IVAS_FLOAT_FIXED +const Word16 cldfb_scale_5_0ms[7] = +{ + 21649/*88.293854 Q8*/, /* 10 bands */ + 21649/*88.299622 Q8*/, /* 16 bands */ + 21649/*88.300926 Q8*/, /* 20 bands */ + 21649/*88.303848 Q8*/, /* 32 bands */ + 21649/*88.304718 Q8*/, /* 40 bands */ + 22535/*88.028412 Q8*/, /* 60 bands */ + 21581/*88.028412 Q8*/ /* 30 bands */ +}; +#endif const float rot_vec_syn_re_L10[5] = { 0.1117172025f,0.1048929802f,0.0878011021f,0.0621146404f,0.0303479649f, @@ -19813,7 +20374,6 @@ const float SVWB2_SN1[256] = { -91.02f, -115.23f, -227.34f, -448.05f, -339.84f, 30.08f, 56.25f, 130.86f, 105.08f, 196.09f, 249.22f, 280.86f, 240.23f, 146.88f, 85.55f, 67.19f }; -/* An 16-by-16 matrix */ const Word16 SVWB2_SN1_fx[256] = { -257, -385, -673, 926, 1408, 874, 735, 512, 624, 587, 493, 688, 845, 521, 428, 95, -32, -90, 1046, 666, 329, -59, -324, -282, -712, -783, -229, 28, -354, -434, -497, -351, @@ -19896,6 +20456,30 @@ const float SVWB2_AR2[128] = { 0.78f, -1.17f, 28.91f, 67.19f, 26.56f, -1.56f, -13.67f, -9.77f, -60.94f, -85.55f, -168.75f, -112.50f, -71.09f, -14.06f, 44.53f, 44.14f }; +/* SVWB2_AR1 * 2.56f */ +const Word16 SVWB2_AR1_fx[128] = { + -28, -38, -122, 74, 296, 148, 146, 120, 148, 36, -11, -163, -223, -299, -290, -320, + -22, -30, -138, -319, -385, 159, 124, 51, 32, -44, -15, -78, -96, -53, 40, 64, + -96, -144, -205, -96, 80, 96, 152, 246, 206, 193, 265, 333, 320, 232, 131, 32, + 108, 106, 102, 37, -14, -17, -61, -144, -161, -160, -257, -404, -540, -316, -124, 18, + 22, 12, 34, -14, -52, -106, -144, -266, -346, -472, -401, -30, -4, -43, -88, -10, + -52, -117, -203, 415, 324, 171, 121, -31, 48, -31, -60, -65, 128, 193, 141, 67, + -47, -86, 430, 334, 193, 136, 85, 82, 1, -34, 47, 84, 2, -30, -77, -45, + -4, -14, -9, -38, -136, -242, -217, -54, -38, 179, 191, 61, 42, -3, 5, -37 +}; + +/* SVWB2_AR2 * 2.56f */ +const Word16 SVWB2_AR2_fx[128] = { + 12, 16, -46, -156, -329, -293, 43, 141, 61, 15, -9, 29, -74, -41, -37, 16, + -47, -81, -136, 82, -33, -111, -268, -293, 109, 136, 53, -58, -51, 62, 64, 14, + -15, -19, -171, -347, 258, 161, 88, 13, -57, -26, -59, 24, 10, 14, -41, -8, + 33, 38, 139, 157, 31, 65, -14, 52, 63, 30, -8, -1, -182, -341, -344, -258, + 14, 16, 46, 6, -54, -64, -136, -132, -318, -303, 261, 146, -19, -57, -30, 30, + -34, -34, 21, 93, 163, 201, 290, 257, 225, 296, 209, 197, 72, 26, 57, 1, + 33, 66, 73, -8, -104, 44, 31, -13, 70, 72, -17, -48, 430, 373, 218, 92, + 1, -2, 74, 172, 67, -3, -34, -25, -156, -219, -432, -288, -181, -35, 113, 112 +}; + /*----------------------------------------------------------------------------------* * LSF quantization - LSF mode/codebook selection tables *----------------------------------------------------------------------------------*/ @@ -20649,30 +21233,6 @@ const Word16 AUWB2_MA1_fx[512] = -19, 43, 35, 40, 42, 55, 63, 101, 133, 194, 222, 152, 117, 145, 133, 213 }; -/* SVWB2_AR1 * 2.56f */ -const Word16 SVWB2_AR1_fx[128] = { - -28, -38, -122, 74, 296, 148, 146, 120, 148, 36, -11, -163, -223, -299, -290, -320, - -22, -30, -138, -319, -385, 159, 124, 51, 32, -44, -15, -78, -96, -53, 40, 64, - -96, -144, -205, -96, 80, 96, 152, 246, 206, 193, 265, 333, 320, 232, 131, 32, - 108, 106, 102, 37, -14, -17, -61, -144, -161, -160, -257, -404, -540, -316, -124, 18, - 22, 12, 34, -14, -52, -106, -144, -266, -346, -472, -401, -30, -4, -43, -88, -10, - -52, -117, -203, 415, 324, 171, 121, -31, 48, -31, -60, -65, 128, 193, 141, 67, - -47, -86, 430, 334, 193, 136, 85, 82, 1, -34, 47, 84, 2, -30, -77, -45, - -4, -14, -9, -38, -136, -242, -217, -54, -38, 179, 191, 61, 42, -3, 5, -37 -}; - -/* SVWB2_AR2 * 2.56f */ -const Word16 SVWB2_AR2_fx[128] = { - 12, 16, -46, -156, -329, -293, 43, 141, 61, 15, -9, 29, -74, -41, -37, 16, - -47, -81, -136, 82, -33, -111, -268, -293, 109, 136, 53, -58, -51, 62, 64, 14, - -15, -19, -171, -347, 258, 161, 88, 13, -57, -26, -59, 24, 10, 14, -41, -8, - 33, 38, 139, 157, 31, 65, -14, 52, 63, 30, -8, -1, -182, -341, -344, -258, - 14, 16, 46, 6, -54, -64, -136, -132, -318, -303, 261, 146, -19, -57, -30, 30, - -34, -34, 21, 93, 163, 201, 290, 257, 225, 296, 209, 197, 72, 26, 57, 1, - 33, 66, 73, -8, -104, 44, 31, -13, 70, 72, -17, -48, 430, 373, 218, 92, - 1, -2, 74, 172, 67, -3, -34, -25, -156, -219, -432, -288, -181, -35, 113, 112 -}; - const Word16 *const Quantizers_fx[] = { SVNB_SN1_fx, SVNB_SN2_fx, GETRNB_SN1_fx, GETRNB_SN2_fx, AUNB_SN1_fx,SVWB_SN1_fx, SVWB_SN2_fx, GETRWB_SN1_fx, GETRWB_SN2_fx, AUWB_SN1_fx,/* U13, */ TRWB2_SN1_fx, TRWB2_SN2_fx, AUWB2_SN1_fx, CNG_SN1_fx, SVWB2_SN1_fx, SVWB2_SN2_fx @@ -21626,6 +22186,7 @@ const Word16 scales_fx[][6] = {2267, 5315, 0, 2666, 1237, 1802}, /* CNG */ };/* An 6-by-146 matrix in Scale = 2048.00f */ + const Word16 scales_p_fx[][6] = { {2998, 4862, 0, 0, 0, 0, }, @@ -21785,7 +22346,6 @@ const Word16 scales_p_fx[][6] = }; - /* An 16-by-34 matrix in Scale = 20.48f */ const float sigma_MSLVQ[][16] = { @@ -22751,7 +23311,7 @@ const Word16 min_lat_bits_SN_fx[] = { -1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17 const int16_t min_lat_bits_pred[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16}; -const Word16 min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, -1, 26, -1, 26, 16 }; +const Word16 min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16 }; const int16_t offset_lvq_modes_SN[] = {-1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135, 112 @@ -37923,6 +38483,13 @@ const Word32 sigma_BWE_fx[] = { 19499580, 20916386, 22705246, 39204284, 40792208 }; /* for 3 bits first stage */ +const Word16 sigma_BWE16_fx[] = { +260, 255, 268, +267, 294, 315, 598, +622, 289, 288, 297, +298, 319, 346, 598, +622 }; /* for 3 bits first stage */ + const float inv_sigma_BWE[] = { 126.2392994665869f, 128.5766227364854f, 122.2856952550425f, 122.8889356808437f, 111.5502335749417f, 104.0176806054527f, 54.7767591108706f, 52.6444584512409f, /* for 4 bits first stage */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 0d5c159c5..a4d78c03a 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -236,10 +236,12 @@ extern const Word32 lag_window_16k_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_48k_32[16]; -extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ -extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ +extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ +extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ +extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ +extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */ +extern const Word16 interpol_frac2_mid_fx[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ +extern const Word16 interpol_frac_12k8_fx[]; /* LPC interpolation coefficients */ extern const Word16 interpol_frac_fx[NB_SUBFR]; extern const float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */ @@ -638,6 +640,8 @@ extern const Word16 inv_sigma_p_fx[][16]; extern const float scales[][MAX_NO_SCALES * 2]; extern const float scales_p[][MAX_NO_SCALES * 2]; extern const Word16 scales_fx[][MAX_NO_SCALES * 2]; +extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; +extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; extern const Word16 scales_p_fx[][MAX_NO_SCALES * 2]; extern const int16_t predmode_tab_float[][6]; extern const Word16 predmode_tab[][6]; @@ -1611,7 +1615,16 @@ extern const Word16 CLDFB80_20[200]; extern const Word16 CLDFB80_32[320]; extern const Word16 CLDFB80_40[400]; extern const Word16 CLDFB80_60[600]; - +extern const Word16 CLDFB80_30[300]; +#ifdef IVAS_FLOAT_FIXED +extern const Word16 LDQMF_10_enc_fx[100]; +extern const Word16 LDQMF_16_enc_fx[160]; +extern const Word16 LDQMF_20_enc_fx[200]; +extern const Word16 LDQMF_30_enc_fx[300]; +extern const Word16 LDQMF_32_enc_fx[320]; +extern const Word16 LDQMF_40_enc_fx[400]; +extern const Word16 LDQMF_60_enc_fx[600]; +#endif extern const Word16 rRotVectr_10[]; extern const Word16 iRotVectr_10[]; @@ -1625,12 +1638,16 @@ extern const Word16 rRotVectr_40[]; extern const Word16 iRotVectr_40[]; extern const Word16 rRotVectr_60[]; extern const Word16 iRotVectr_60[]; +extern const Word16 rRotVectr_30[]; +extern const Word16 iRotVectr_30[]; extern const Word16 cldfb_anaScale[]; extern const Word16 cldfb_synScale[]; extern const Word16 cldfb_synGain[]; extern const Word16 *cldfb_protoFilter_2_5ms[]; +extern const Word16 *cldfb_protoFilter_5_0ms[]; extern const Word16 cldfb_scale_2_5ms[7]; +extern const Word16 cldfb_scale_5_0ms[7]; extern const float rot_vec_syn_re_L10[5]; @@ -1990,6 +2007,7 @@ extern const Word16 tcx_mdct_window_trans_48_fx[60]; extern const float sigma_BWE[]; extern const Word32 sigma_BWE_fx[]; +extern const Word16 sigma_BWE16_fx[]; extern const float inv_sigma_BWE[]; extern const float scales_BWE[]; extern const Word8 no_lead_BWE[]; diff --git a/lib_com/rom_com_fx.h b/lib_com/rom_com_fx.h index a07774106..ac6a0ef46 100644 --- a/lib_com/rom_com_fx.h +++ b/lib_com/rom_com_fx.h @@ -85,6 +85,14 @@ extern const Word16 LDQMF_32_fx[320]; extern const Word16 LDQMF_40_fx[400]; extern const Word16 LDQMF_60_fx[600]; +extern const Word16 LDQMF_10_enc_fx[100]; +extern const Word16 LDQMF_16_enc_fx[160]; +extern const Word16 LDQMF_20_enc_fx[200]; +extern const Word16 LDQMF_30_enc_fx[300]; +extern const Word16 LDQMF_32_enc_fx[320]; +extern const Word16 LDQMF_40_enc_fx[400]; +extern const Word16 LDQMF_60_enc_fx[600]; + extern const Word32 rot_vec_delay_re_LDQMF_fx[60]; extern const Word32 rot_vec_delay_im_LDQMF_fx[60]; diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 05fd4b643..d9baadc35 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -782,6 +782,7 @@ typedef struct cldfb_filter_bank_struct float scale_flt; /* scaling of frequency domain */ Word16 scale; /* scaling of frequency domain */ /* Q8 */ + Word16 q_scale; } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index 003392ca9..f878ecf16 100644 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -964,8 +964,9 @@ void ivas_lfe_tdplc_fx( Copy_Scale_sig_32_16( prevsynth_fx, prevsynth_16_fx, LFE_PLC_BUFLEN, -16 ); // Q5 = Q21 - Q16 Copy_Scale_sig_32_16( rec_frame_fx, rec_frame_16_fx, LFE_PLC_RECLEN, 0 ); // Q5 - modify_Fs_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0 ); - modify_Fs_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0 ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); + modify_Fs_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); /*samples are generated with 48k sampling rate and then converted to required sampling rate by simple decimation as signal is already bandlimited*/ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 771e0bc9e..c5359b781 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -44,6 +44,7 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "prot_fx2.h" +#include "prot_fx_enc.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -52,7 +53,1471 @@ * * ACELP core encoder *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error acelp_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float inp[], /* i : input signal of the current frame */ + const float ener, /* i : residual energy from Levinson-Durbin*/ + float A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/ + float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ + const float epsP[M + 1], /* i : LP prediction errors */ + float lsp_new[M], /* i : LSPs at the end of the frame */ + float lsp_mid[M], /* i : LSPs in the middle of the frame */ + const int16_t vad_hover_flag, /* i : VAD hangover flag */ + const int16_t attack_flag, /* i : attack flag (GSC or TC) */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + int16_t *unbits, /* o : number of unused bits */ + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +) +{ + int16_t i, nBits; /* reserved bits */ + LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ + float old_exc_flt[L_EXC], *exc; /* excitation signal buffer */ + float lsf_new[M]; /* ISFs at the end of the frame */ + float Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ + float syn[L_FRAME16k]; /* synthesis signal buffer */ + float res[L_FRAME16k]; /* Residual signal for FER protection */ + float exc2[L_FRAME16k]; /* enhanced excitation */ + float Es_pred; /* predicited scaled innovation energy */ + float tmp_noise; /* NB post-filter long-term noise energy*/ + int16_t tc_subfr; /* TC sub-frame indication */ + float old_bwe_exc[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ + float *bwe_exc; /* excitation for SWB TBE */ + int16_t allow_cn_step; + int32_t int_fs; + float att; + int16_t nb_bits; /* parameters handling */ + + /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ + int16_t pstreaklen; + float mem_MA[M], mem_AR[M], Bin_E[L_FFT], Bin_E_old[L_FFT / 2], lsp_new_bck[M], lsp_mid_bck[M], mem_syn_bck[M]; + float clip_var, mem_w0_bck, streaklimit; + + float q_env[NUM_ENV_CNG]; + int16_t sid_bw = -1; + float exc3[L_FRAME16k]; + float syn1[L_FRAME16k]; + + float tilt_code_bck; + float gc_threshold_bck; + float clip_var_bck[6]; + int16_t next_force_sf_bck; + int16_t uc_two_stage_flag; + int16_t position; + float tmpF; + int16_t ppp_mode, nelp_mode; + int16_t tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; + float *tdm_Pri_pitch_buf; + + /* bitstream */ + BSTR_ENC_HANDLE hBstr = st->hBstr; +#if 0 + //Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ + Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ + Word16 Aq_fx[NB_SUBFR16k*(M + 1)]; /* A(z) quantized for the 4 subframes */ + Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ + Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ + Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ + Word16 Es_pred_fx; /* predicited scaled innovation energy */ + Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ + Word16 tc_subfr_fx; /* TC sub-frame indication */ + Word16 old_bwe_exc_fx[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ + Word16 *bwe_exc_fx; /* excitation for SWB TBE */ + Word16 allow_cn_step_fx; + Word16 int_fs_fx; + Word32 L_epsP[2]; + /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ + Word16 mCb1_fx, pstreaklen_fx; + Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; + Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2]; + Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; + Word16 indice; + Word16 tmp16; + Word16 enr_index; + Word16 enr; + + Word16 tilt_code_bck_fx; + Word32 gc_threshold_bck_fx; + Word16 clip_var_bck_fx[6]; + Word16 next_force_sf_bck_fx; + Word32 q_env_fx[NUM_ENV_CNG]; + Word16 coder_type; + Word16 exc3_fx[L_FRAME16k]; + Word16 syn1_fx[L_FRAME16k]; + Word16* tdm_Pri_pitch_buf_fx; + Word16 att_fx; + + Word16 lsp_new_fx[M]; /* i : LSPs at the end of the frame */ + Word16 lsp_mid_fx[M]; /* i : LSPs in the middle of the frame */ + Word16 old_syn_12k8_16k_fx[L_FRAME16k]; +#endif + ivas_error error; + + error = IVAS_ERR_OK; + + if ( st->element_mode == IVAS_CPE_MDCT && st->core_brate <= SID_2k40 ) + { + /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */ + return error; + } + + push_wmops( "acelp_core_enc" ); + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + hLPDmem = st->hLPDmem; + + Es_pred = 0; + + exc = old_exc_flt + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + mvr2r( hLPDmem->old_exc_flt, old_exc_flt, L_EXC_MEM ); + + if ( st->hBWE_TD != NULL ) + { + bwe_exc = old_bwe_exc + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ + mvr2r( st->hBWE_TD->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 ); + } + else + { + bwe_exc = NULL; + } + + st->bpf_off = 0; + if ( st->last_core == HQ_CORE || st->last_codec_mode == MODE2 || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) + { + /* in case of HQ->ACELP switching, do not apply BPF */ + st->bpf_off = 1; + /* reset the GSC pre echo energy threshold in case of switching */ + if ( st->hGSCEnc != NULL ) + { + st->hGSCEnc->Last_frame_ener = (float) MAX_32; + } + } + + /* force safety-net LSFQ in the first frames after CNG segment */ + if ( st->last_core_brate <= SID_2k40 ) + { + st->Nb_ACELP_frames = 0; + } + st->Nb_ACELP_frames++; + + if ( st->L_frame == L_FRAME ) + { + int_fs = INT_FS_12k8; + } + else + { + int_fs = INT_FS_16k; + } + + tmp_noise = 0; + tc_subfr = -1; + position = -1; + + /* SC-VBR temporary variables */ + pstreaklen = 0; + clip_var = 0; + mem_w0_bck = 0; + streaklimit = 0; + + /* channel-aware mode */ + reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write ); + + /* VBR modes */ + if ( st->Opt_SC_VBR ) + { + ppp_mode = st->hSC_VBR->ppp_mode; + nelp_mode = st->hSC_VBR->nelp_mode; + } + else + { + ppp_mode = 0; + nelp_mode = 0; + } + + /* TD stereo */ + if ( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) + { + tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; + tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; + tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; + tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf; + } + else + { + tdm_lp_reuse_flag = 0; + tdm_low_rate_mode = 0; + if ( st->element_mode == IVAS_SCE && st->low_rate_mode ) + { + tdm_low_rate_mode = 1; + } + tdm_Pitch_reuse_flag = 0; + tdm_Pri_pitch_buf = NULL; + } + + /*-----------------------------------------------------------------* + * ACELP@12k8 / ACELP@16k switching + *-----------------------------------------------------------------*/ + + if ( st->last_L_frame != st->L_frame && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) + { + /* in case of switching, do not apply BPF (flag employed also in updt_enc()) */ + st->bpf_off = 1; + + /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */ + st->Nb_ACELP_frames = 1; + + /* convert old quantized LSP vector */ + if ( st->L_frame == L_FRAME ) + { + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); + } + else + { + st->rate_switching_reset = st->rate_switching_reset_16kHz; + mvr2r( st->lsp_old16k, st->lsp_old, M ); + } + + /* convert old quantized LSF vector */ + lsp2lsf( st->lsp_old, st->lsf_old, M, int_fs ); + + /* interpolation of unquantized ISPs */ + if ( st->rate_switching_reset ) + { + /*extrapolation in case of unstable LSP*/ + int_lsp4( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); + } + else + { + int_lsp4( st->L_frame, st->lsp_old, lsp_mid, lsp_new, A, M, 0 ); + } + + /* Reset LPC mem */ + mvr2r( GEWB_Ave, st->mem_AR, M ); + set_zero( st->mem_MA, M ); + + /* update synthesis filter memories */ + synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC ); + mvr2r( hLPDmem->old_exc_flt, old_exc_flt, L_EXC_MEM ); + mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn1_flt, M ); + mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn3_flt, M ); + + /* update Aw[] coefficients */ + weight_a_subfr( st->L_frame / L_SUBFR, A, Aw, st->gamma_flt, M ); + } + + if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) + { + st->rate_switching_reset = 1; + } + + /*----------------------------------------------------------------* + * Encoding of CNG frames + *----------------------------------------------------------------*/ + + if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + { + if ( st->cng_type == LP_CNG ) + { + /* Run CNG post parameter update */ + cng_params_postupd( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); + + /* encode CNG parameters */ + CNG_enc( st, Aq, inp, ener, lsp_mid, lsp_new, lsf_new, &allow_cn_step, q_env, &sid_bw ); + + /* comfort noise generation */ + CNG_exc( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew, &st->hTdCngEnc->cng_seed, exc, exc2, &st->hTdCngEnc->lp_ener, st->last_core_brate, &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, st->hTdCngEnc->num_ho, q_env, st->hTdCngEnc->lp_env, st->hTdCngEnc->old_env, st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem1, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, EVS_MONO ); + } + else + { + if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) + { + FdCng_encodeSID( st ); + st->hDtxEnc->last_CNG_L_frame = st->L_frame; + } + + generate_comfort_noise_enc( st ); + + FdCng_exc_flt( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG, Aq, lsp_new, lsf_new, exc, exc2, bwe_exc ); + mvr2r( exc2, exc3, st->L_frame ); + + if ( st->core_brate == SID_2k40 ) + { + if ( st->hTdCngEnc != NULL ) + { + tmpF = cng_energy( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att, exc, st->L_frame ); + i = (int16_t) ( ( tmpF + 2.0f ) * STEP_SID ); + i = min( max( i, 0 ), 127 ); + st->hTdCngEnc->old_enr_index = i; + } + } + } + + /* Reset HO counter in the first SID frame */ + if ( st->hTdCngEnc != NULL ) + { + st->hTdCngEnc->burst_ho_cnt = 0; + } + + /* synthesis at 12.8kHz sampling rate */ + syn_12k8( st->L_frame, Aq, exc3, syn1, hLPDmem->mem_syn3_flt, 1 ); + + /* reset the encoder */ + CNG_reset_enc( st, pitch_buf, voice_factors, 0 ); + + /* update st->mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn1_flt, M ); + + /* update ACELP core synthesis filter memory */ + mvr2r( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn_flt, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn1 + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + /* save and delay synthesis to be used by SWB BWE */ + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn1, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } + + /*Update MODE2 core switching memory*/ + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + } + + /*----------------------------------------------------------------* + * Encoding of all other frames + *----------------------------------------------------------------*/ +#if 0 + ELSE + { +#if 1 + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + + nb_bits = 0; + st->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; + + if ( !nelp_mode && !ppp_mode ) + { + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ + + if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) + { + mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M ); + lsp2lsf( st->hDtxEnc->lspCNG, st->lsf_old, M, int_fs ); + } + + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ + + if ( !st->use_acelp_preq ) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + /*-----------------------------------------------------------------* + * LSF Quantization + * A[z] calculation + *-----------------------------------------------------------------*/ + + /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ + lsf_syn_mem_backup( st, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen ); + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 Q_new = 0; + IF ( !tdm_lp_reuse_flag ) + { +#if 1 + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + FOR(Word16 idx = 0; idx < M; idx++) + { + st->lsf_old_fx[idx] = st->lsf_old[idx] * 2.56; + lsf_new_fx[idx] = lsf_new_fx[idx] * 2.56; + st->lsf_adaptive_mean_fx[idx] = st->lsf_adaptive_mean[idx] * 2.56; + st->mem_MA_fx[idx] = st->mem_MA[idx] * 2.56; + st->mem_AR_fx[idx] = st->mem_AR[idx] * 2.56; + tdm_lsfQ_PCh_fx[idx] = tdm_lsfQ_PCh[idx] * 2.56; + st->lsfoldbfi1_fx[idx] = st->lsfoldbfi1[idx] * 2.56; + st->lsfoldbfi0_fx[idx] = st->lsfoldbfi0[idx] * 2.56; + } + + FOR(Word16 idx = 0; idx < 6; idx++) + { + st->clip_var_fx[idx] = st->clip_var[idx] * 2.56; + } + + Q_new = Q_factor_arr(st->Bin_E, 256); + + floatToFixed_arrL(st->Bin_E_old, st->Bin_E_old_fx, 0, L_FFT ); + floatToFixed_arrL(st->Bin_E, st->Bin_E_fx, Q_new, L_FFT); + floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M); + floatToFixed_arr(lsp_mid, lsp_mid_fx, 15, M); + + st->stab_fac_fx = st->stab_fac * (1 << 15); + st->streaklimit_fx = st->streaklimit * (1 << 15); + st->pstreaklen_fx = st->pstreaklen; + + lsf_enc_ivas_fx(st, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh_fx, Q_new); + + Scale_sig(Aq_fx, NB_SUBFR16k * (M + 1), 14 - norm_l(Aq_fx[0])); + fixedToFloat_arr(Aq_fx, Aq, 12, NB_SUBFR16k * (M + 1)); + fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); + fixedToFloat_arr(lsp_mid_fx, lsp_mid, 15, M); + st->stab_fac = (float)st->stab_fac_fx / (1 << 15); + for (int i = 0; i < M; i++) { + + lsf_new[i] = lsf_new_fx[i] / 2.56; + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56; + st->mem_MA[i] = st->mem_MA_fx[i] / 2.56; + st->mem_AR[i] = st->mem_AR_fx[i] / 2.56; + st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56; + st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56; + } + st->streaklimit = (float)st->streaklimit_fx / (1 << 15); + st->pstreaklen = st->pstreaklen_fx; +#else + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh ); +#endif + } + ELSE + { + const float *pt_interp_2; + + IF ( NE_16(st->active_cnt, 1 )) + { +#if 0 + Word16 beta_index; + Word16 lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf_fx(lsp_new_fx, lsf_new_fx, M, 12800); + + Unified_weighting_fx(&st->Bin_E_fx[L_FFT / 2], Q_new, lsf_new_fx, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M); + + tdm_SCh_lsf_reuse_fx(ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts, &beta_index); +#else + int16_t beta_index; + float lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf( lsp_new, lsf_new, M, 12800 ); + + Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); + + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); +#endif + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); + } + + pt_interp_2 = interpol_frac_12k8; + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) + { + pt_interp_2 = interpol_frac2; + } + + if ( st->active_cnt == 1 ) + { + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); + } + + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + tmpF = hLPDmem->old_exc_flt[0]; + preemph( hLPDmem->old_exc_flt, st->preemph_fac_flt, st->L_frame, &tmpF ); + mvr2r( hLPDmem->old_exc_flt + st->L_frame - M, hLPDmem->mem_syn_flt, M ); + residu( Aq, M, hLPDmem->old_exc_flt, old_exc_flt, st->L_frame ); + } + + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + if ( st->L_frame == L_FRAME ) + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + else + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + } + } + + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ + + calc_residu( inp, res, Aq, st->L_frame ); + + calculate_hangover_attenuation_gain( st, &att, vad_hover_flag ); + if ( att != 1.0f ) + { + v_multc( res, att, res, st->L_frame ); + } + + /*-----------------------------------------------------------------* + * Determine TC subframe classification + *-----------------------------------------------------------------*/ + + if ( st->coder_type == TRANSITION ) + { + tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); + + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*---------------------------------------------------------------* + * Calculation of prediction for scaled innovation energy + * (for memory-less gain quantizer) + *---------------------------------------------------------------*/ + + if ( nb_bits > 0 ) + { + Es_pred_enc( &Es_pred, &i, st->L_frame, L_SUBFR, res, st->voicing, nb_bits, uc_two_stage_flag ); + push_indice( hBstr, IND_ES_PRED, i, nb_bits ); + } + + /*------------------------------------------------------------* + * Encode excitation according to coding type + *------------------------------------------------------------*/ + + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + if ( st->coder_type <= UNVOICED ) + { + tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise ); + } + else /* GENERIC */ + { + encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp( st, inp, Aw, Aq, res, syn, &tmp_noise, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == UNVOICED ) + { + /* UNVOICED frames (Gauss. excitation) */ + encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == TRANSITION ) + { + encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + } + else if ( ppp_mode ) + { + /* SC-VBR - PPP frames */ + if ( ( error = encod_ppp( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ) ) != IVAS_ERR_OK ) + { + return error; + } + + + if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ + { + /* restore memories of LSF quantizer and synthesis filter */ + lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); + + /* Configure ACELP bit allocation */ + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + + /* redo LSF quantization */ + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); + + /* recalculation of LP residual (filtering through A[z] filter) */ + calc_residu( inp, res, Aq, st->L_frame ); + st->hTdCngEnc->burst_ho_cnt = 0; + + /* VOICED frames in SC-VBR */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + + + /* update mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + /* save and delay synthesis to be used by SWB BWE */ + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } + + /*Update MODE2 core switching memory*/ + mvr2r( syn, syn1, st->L_frame ); + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + + if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + } + + /*--------------------------------------------------------------------------------------* + * Modify the excitation signal when the noise is stationary + *--------------------------------------------------------------------------------------*/ + + if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + mvr2r( exc, exc2, st->L_frame ); + stat_noise_uv_enc( st, epsP, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag ); + } + + /*-----------------------------------------------------------------* + * Encode supplementary information for Frame Error Concealment + *-----------------------------------------------------------------*/ + + FEC_encode( hBstr, st->acelp_cfg, syn, st->coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate ); + + if ( st->hBWE_TD != NULL ) + { + if ( st->L_frame == L_FRAME ) + { + mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + else + { + mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + } +#else + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + + nb_bits = 0; + st->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; +#if 0 // Both are in fixed point, but 1st one giveing crash for one file. + IF ( !nelp_mode && !ppp_mode ) + { + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } +#else + if (!nelp_mode && !ppp_mode) + { + config_acelp1_IVAS(ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &(st->acelp_cfg), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode); + } +#endif + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ +#if 0 + floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M); + + IF(EQ_32(st->last_core_brate, FRAME_NO_DATA) || EQ_32(st->last_core_brate, SID_2k40)) + { + Copy(st->hDtxEnc->lspCNG_fx, st->lsp_old_fx, M); + lsp2lsf_fx(st->hDtxEnc->lspCNG_fx, st->lsf_old_fx, M, int_fs); + } + for (int i = 0; i < M; i++) { + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + } +#else + if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) + { + mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M ); + lsp2lsf( st->hDtxEnc->lspCNG, st->lsf_old, M, int_fs ); + } +#endif + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ +#if 1 + IF (!st->use_acelp_preq) + { + st->mem_deemp_preQ_fx = 0; + st->mem_preemp_preQ_fx = 0; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + if (!st->use_acelp_preq) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } +#else + if ( !st->use_acelp_preq ) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; +#endif + /*-----------------------------------------------------------------* + * LSF Quantization + * A[z] calculation + *-----------------------------------------------------------------*/ + + /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ +#if 0 + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + floatToFixed_arr(lsp_mid, lsp_mid_fx, 15, M); + floatToFixed_arr(st->Bin_E_old, st->Bin_E_old_fx, 15, L_FFT / 2); + floatToFixed_arr(st->clip_var, st->clip_var_fx, 8, 6); + FOR(Word16 idx = 0; idx < M; idx++) + { + + st->lsf_old_fx[idx] = st->lsf_old[idx] * 2.56; + st->lsf_adaptive_mean_fx[idx] = st->lsf_adaptive_mean[idx] * 2.56; + st->mem_MA_fx[idx] = st->mem_MA[idx] * 2.56; + st->mem_AR_fx[idx] = st->mem_AR[idx] * 2.56; + } + hLPDmem->tilt_code = hLPDmem->tilt_code_flt; + hLPDmem->gc_threshold = hLPDmem->gc_threshold_flt; + st->next_force_safety_net_fx = st->next_force_safety_net; + + lsf_syn_mem_backup_fx(st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck, lsp_new_fx, lsf_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx); + + fixedToFloat_arr(clip_var_bck_fx, clip_var_bck, 8, 6); + fixedToFloat_arr(lsp_new_bck_fx, lsp_new_bck, 15, M); + fixedToFloat_arr(lsp_mid_bck_fx, lsp_mid_bck, 15, M); + fixedToFloat_arr(lsp_mid_bck_fx, lsp_mid_bck, 15, M); + fixedToFloat_arr(Bin_E_fx, Bin_E, 15, L_FFT); + fixedToFloat_arr(Bin_E_old_fx, Bin_E_old, 15, L_FFT / 2); + fixedToFloat_arr(mem_syn_bck_fx, mem_syn_bck, 15, M); + + for (int i = 0; i < M; i++) { + + lsf_new[i] = lsf_new_fx[i] / 2.56; + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56; + st->mem_MA[i] = st->mem_MA_fx[i] / 2.56; + st->mem_AR[i] = st->mem_AR_fx[i] / 2.56; + mem_MA[i] = mem_MA_fx[i] / 2.56; + mem_AR[i] = mem_AR_fx[i] / 2.56; + } + + clip_var = (float)clip_var_fx / (1 << 8); + mem_w0_bck = mem_w0_bck_fx; + streaklimit = streaklimit_fx; + mem_w0_bck = mem_w0_bck_fx; +#else + lsf_syn_mem_backup( st, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen ); +#endif + if ( !tdm_lp_reuse_flag ) + { +#if 1 + Word16 Q_new = 0; + Word16 tdm_lsfQ_PCh_fx[M]; + + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + FOR(Word16 idx = 0; idx < M; idx++) + { + st->lsf_old_fx[idx] = st->lsf_old[idx] * 2.56; + lsf_new_fx[idx] = lsf_new_fx[idx] * 2.56; + st->lsf_adaptive_mean_fx[idx] = st->lsf_adaptive_mean[idx] * 2.56; + st->mem_MA_fx[idx] = st->mem_MA[idx] * 2.56; + st->mem_AR_fx[idx] = st->mem_AR[idx] * 2.56; + tdm_lsfQ_PCh_fx[idx] = tdm_lsfQ_PCh[idx] * 2.56; + } + + FOR(Word16 idx = 0; idx < 6; idx++) + { + st->clip_var_fx[idx] = st->clip_var[idx] * 2.56; + } + + floatToFixed_arrL(st->Bin_E_old, st->Bin_E_old_fx, 0, L_FFT / 2); + floatToFixed_arrL(st->Bin_E, st->Bin_E_fx, 0, L_FFT / 2); + floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M); + floatToFixed_arr(lsp_mid, lsp_mid_fx, 15, M); + + st->stab_fac_fx = st->stab_fac * (1 << 15); + + lsf_enc_ivas_fx(st, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh_fx, Q_new); + + Scale_sig(Aq_fx, NB_SUBFR16k * (M + 1), 14 - norm_l(Aq_fx[0])); + fixedToFloat_arr(Aq_fx, Aq, 12, NB_SUBFR16k * (M + 1)); + fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); + fixedToFloat_arr(lsp_mid_fx, lsp_mid, 15, M); + st->stab_fac = (float)st->stab_fac_fx / (1 << 15); + for (int i = 0; i < M; i++) { + + lsf_new[i] = lsf_new_fx[i] / 2.56; + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56; + st->mem_MA[i] = st->mem_MA_fx[i] / 2.56; + st->mem_AR[i] = st->mem_AR_fx[i] / 2.56; + } +#else + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh ); +#endif + } + else + { + const float *pt_interp_2; + + if ( st->active_cnt != 1 ) + { + int16_t beta_index; + float lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf( lsp_new, lsf_new, M, 12800 ); + + Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); + + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); + + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); + } + + pt_interp_2 = interpol_frac_12k8; + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) + { + pt_interp_2 = interpol_frac2; + } + + if ( st->active_cnt == 1 ) + { + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); + } + + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + tmpF = hLPDmem->old_exc_flt[0]; + preemph( hLPDmem->old_exc_flt, st->preemph_fac_flt, st->L_frame, &tmpF ); + mvr2r( hLPDmem->old_exc_flt + st->L_frame - M, hLPDmem->mem_syn_flt, M ); + residu( Aq, M, hLPDmem->old_exc_flt, old_exc_flt, st->L_frame ); + } + + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + if ( st->L_frame == L_FRAME ) + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + else + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + } + } + + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ +#if 0 + floatToFixed_arr(Aq, Aq_fx, 12, NB_SUBFR16k*(M + 1)); + calc_residu_fx(st, inp_fx, res_fx, Aq_fx); +#else + calc_residu( inp, res, Aq, st->L_frame ); +#endif + calculate_hangover_attenuation_gain( st, &att, vad_hover_flag ); + if ( att != 1.0f ) + { + v_multc( res, att, res, st->L_frame ); + } + + /*-----------------------------------------------------------------* + * Determine TC subframe classification + *-----------------------------------------------------------------*/ + + if ( st->coder_type == TRANSITION ) + { + tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); + + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*---------------------------------------------------------------* + * Calculation of prediction for scaled innovation energy + * (for memory-less gain quantizer) + *---------------------------------------------------------------*/ +#if 0 + Es_pred_fx = Es_pred * (1 << 8); + IF(nb_bits > 0) + { + Es_pred_enc_fx(&Es_pred_fx, &i, st->L_frame, res_fx, st->voicing_fx, nb_bits, uc_two_stage_flag, 0); + push_indice(hBstr, IND_ES_PRED, i, nb_bits); + } + + Es_pred = (float)Es_pred_fx / (1 << 8); +#else + if ( nb_bits > 0 ) + { + Es_pred_enc( &Es_pred, &i, st->L_frame, L_SUBFR, res, st->voicing, nb_bits, uc_two_stage_flag ); + push_indice( hBstr, IND_ES_PRED, i, nb_bits ); + } +#endif + /*------------------------------------------------------------* + * Encode excitation according to coding type + *------------------------------------------------------------*/ + + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + if ( st->coder_type <= UNVOICED ) + { + tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise ); + } + else /* GENERIC */ + { + encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp( st, inp, Aw, Aq, res, syn, &tmp_noise, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == UNVOICED ) + { + /* UNVOICED frames (Gauss. excitation) */ + encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == TRANSITION ) + { + encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + } + else if ( ppp_mode ) + { + /* SC-VBR - PPP frames */ + if ( ( error = encod_ppp( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ) ) != IVAS_ERR_OK ) + { + return error; + } + + + if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ + { + /* restore memories of LSF quantizer and synthesis filter */ + lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); + + /* Configure ACELP bit allocation */ + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + + /* redo LSF quantization */ + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); + + /* recalculation of LP residual (filtering through A[z] filter) */ + calc_residu( inp, res, Aq, st->L_frame ); + st->hTdCngEnc->burst_ho_cnt = 0; + + /* VOICED frames in SC-VBR */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + + /* update mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); + + Copy(hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + Copy(syn_fx + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM); + /* save and delay synthesis to be used by SWB BWE */ +#if 1 + floatToFixed_arr(hLPDmem->mem_syn_r, hLPDmem->mem_syn_r_flt, 0, L_SYN_MEM); + floatToFixed_arr(hLPDmem->mem_syn1_fx, hLPDmem->mem_syn1_flt, 0, M); +#endif +#if 0 + floatToFixed_arr(st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, 0, 36); + floatToFixed_arr(syn, syn_fx, -1, L_FRAME16k); + st->hBWE_FD->mem_deemph_old_syn_fx = st->hBWE_FD->mem_deemph_old_syn; + st->preemph_fac = st->preemph_fac_flt * (1 << 15); + + save_old_syn_fx(st->L_frame, syn_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx); + + fixedToFloat_arr(old_syn_12k8_16k_fx, old_syn_12k8_16k, -1, 320); + fixedToFloat_arr(st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, 0, 36); + st->hBWE_FD->mem_deemph_old_syn = st->hBWE_FD->mem_deemph_old_syn_fx; +#else + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } +#endif + /*Update MODE2 core switching memory*/ + mvr2r( syn, syn1, st->L_frame ); +#if 0 + deemph(syn1, st->preemph_fac_flt, st->L_frame, &(hLPDmem->syn_flt[M])); +#else + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); +#endif + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + + if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + } + + /*--------------------------------------------------------------------------------------* + * Modify the excitation signal when the noise is stationary + *--------------------------------------------------------------------------------------*/ + + if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + mvr2r( exc, exc2, st->L_frame ); + stat_noise_uv_enc( st, epsP, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag ); + } + + /*-----------------------------------------------------------------* + * Encode supplementary information for Frame Error Concealment + *-----------------------------------------------------------------*/ + + FEC_encode( hBstr, st->acelp_cfg, syn, st->coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate ); + + if ( st->hBWE_TD != NULL ) + { + if ( st->L_frame == L_FRAME ) + { + mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + else + { + mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + } + +#endif + } /* end of active inp coding */ +#else + else + { + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + + nb_bits = 0; + st->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; + + if ( !nelp_mode && !ppp_mode ) + { + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ + + if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) + { + mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M ); + lsp2lsf( st->hDtxEnc->lspCNG, st->lsf_old, M, int_fs ); + } + + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ + + if ( !st->use_acelp_preq ) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + /*-----------------------------------------------------------------* + * LSF Quantization + * A[z] calculation + *-----------------------------------------------------------------*/ + + /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ + lsf_syn_mem_backup( st, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen ); + + if ( !tdm_lp_reuse_flag ) + { + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh ); + } + else + { + const float *pt_interp_2; + + if ( st->active_cnt != 1 ) + { + int16_t beta_index; + float lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf( lsp_new, lsf_new, M, 12800 ); + + Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); +#ifdef IVAS_FLOAT_FIXED + Word16 lsf_new_fx[M]; + Word16 lsp_new_fx[M]; + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 lsf_wgts_fx[M]; + for ( int ii = 0; ii < M; ii++ ) + { + lsf_new_fx[ii] = (Word16) ( ( lsf_new[ii] ) * 2.56f ); + tdm_lsfQ_PCh_fx[ii] = (Word16) ( ( tdm_lsfQ_PCh[ii] ) * 2.56f ); + lsf_wgts_fx[ii] = (Word16) ( ( lsf_wgts[ii] ) * 2.56f ); + } + floatToFixed_arr( lsp_new, lsp_new_fx, 15, M ); + + tdm_SCh_lsf_reuse_fx( ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts_fx, &beta_index ); + + for ( int ii = 0; ii < M; ii++ ) + { + lsf_new[ii] = (Word16) ( ( lsf_new_fx[ii] ) / 2.56f ); + lsf_wgts[ii] = (Word16) ( ( lsf_wgts_fx[ii] ) / 2.56f ); + } + fixedToFloat_arr( lsp_new_fx, lsp_new, 15, M ); +#else + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); +#endif + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); + } + + pt_interp_2 = interpol_frac_12k8; + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) + { + pt_interp_2 = interpol_frac2; + } + + if ( st->active_cnt == 1 ) + { + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); + } + + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + tmpF = hLPDmem->old_exc_flt[0]; + preemph( hLPDmem->old_exc_flt, st->preemph_fac_flt, st->L_frame, &tmpF ); + mvr2r( hLPDmem->old_exc_flt + st->L_frame - M, hLPDmem->mem_syn_flt, M ); + residu( Aq, M, hLPDmem->old_exc_flt, old_exc_flt, st->L_frame ); + } + + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + if ( st->L_frame == L_FRAME ) + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + else + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + } + } + + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ + + calc_residu( inp, res, Aq, st->L_frame ); + + calculate_hangover_attenuation_gain( st, &att, vad_hover_flag ); + if ( att != 1.0f ) + { + v_multc( res, att, res, st->L_frame ); + } + + /*-----------------------------------------------------------------* + * Determine TC subframe classification + *-----------------------------------------------------------------*/ + + if ( st->coder_type == TRANSITION ) + { + tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); + + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*---------------------------------------------------------------* + * Calculation of prediction for scaled innovation energy + * (for memory-less gain quantizer) + *---------------------------------------------------------------*/ + + if ( nb_bits > 0 ) + { + Es_pred_enc( &Es_pred, &i, st->L_frame, L_SUBFR, res, st->voicing, nb_bits, uc_two_stage_flag ); + push_indice( hBstr, IND_ES_PRED, i, nb_bits ); + } + + /*------------------------------------------------------------* + * Encode excitation according to coding type + *------------------------------------------------------------*/ + + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + if ( st->coder_type <= UNVOICED ) + { + tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise ); + } + else /* GENERIC */ + { + encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp( st, inp, Aw, Aq, res, syn, &tmp_noise, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == UNVOICED ) + { + /* UNVOICED frames (Gauss. excitation) */ + encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == TRANSITION ) + { + encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + } + else if ( ppp_mode ) + { + /* SC-VBR - PPP frames */ + if ( ( error = encod_ppp( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ) ) != IVAS_ERR_OK ) + { + return error; + } + + + if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ + { + /* restore memories of LSF quantizer and synthesis filter */ + lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); + + /* Configure ACELP bit allocation */ + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + + /* redo LSF quantization */ + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); + + /* recalculation of LP residual (filtering through A[z] filter) */ + calc_residu( inp, res, Aq, st->L_frame ); + st->hTdCngEnc->burst_ho_cnt = 0; + + /* VOICED frames in SC-VBR */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + + + /* update mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + /* save and delay synthesis to be used by SWB BWE */ + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } + + /*Update MODE2 core switching memory*/ + mvr2r( syn, syn1, st->L_frame ); + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + + if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + } + + /*--------------------------------------------------------------------------------------* + * Modify the excitation signal when the noise is stationary + *--------------------------------------------------------------------------------------*/ + + if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + mvr2r( exc, exc2, st->L_frame ); + stat_noise_uv_enc( st, epsP, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag ); + } + + /*-----------------------------------------------------------------* + * Encode supplementary information for Frame Error Concealment + *-----------------------------------------------------------------*/ + + FEC_encode( hBstr, st->acelp_cfg, syn, st->coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate ); + + if ( st->hBWE_TD != NULL ) + { + if ( st->L_frame == L_FRAME ) + { + mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + else + { + mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + } + + + } /* end of active inp coding */ +#endif + + /*-----------------------------------------------------------------* + * Write ACELP unused bits + *-----------------------------------------------------------------*/ + + if ( st->core_brate != SID_2k40 && st->core_brate != FRAME_NO_DATA && st->core_brate != PPP_NELP_2k80 ) + { + nBits = st->acelp_cfg.ubits; + + while ( nBits > 0 ) + { + i = min( nBits, 16 ); + push_indice( hBstr, IND_UNUSED, 0, i ); + nBits -= i; + } + } + + /*-----------------------------------------------------------------* + * Apply non linearity in case of SWB TBE + *-----------------------------------------------------------------*/ + + if ( st->hBWE_TD != NULL ) + { + if ( ( st->last_Opt_SC_VBR == 1 && st->Opt_SC_VBR == 0 ) || ( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag ) ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + } + + if ( !st->Opt_SC_VBR && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) + { + /* Apply a non linearity to the SHB excitation */ + non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); + } + + if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + } + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + updt_enc( st, old_exc_flt, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, old_bwe_exc ); + + if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && st->core_brate > SID_2k40 ) + { + /* update CNG parameters in active frames */ + cng_params_upd( lsp_new, exc, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ, ENC, st->hTdCngEnc->ho_env_circ, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); + + if ( st->L_frame == L_FRAME ) + { + /* store LSPs@16k, potentially to be used in CNG@16k */ + mvr2r( st->lsp_old16k, &( st->hTdCngEnc->ho_lsp_circ2[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); + } + + /* set LSP@16k flag for the first buffer */ + st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); + + /* efficient DTX hangover control */ + if ( st->hTdCngEnc->burst_ho_cnt > 1 ) + { + dtx_hangover_control( st, lsp_new ); + } + } + + /* SC-VBR update of average data rate */ + if ( st->vad_flag == 1 ) + { + /* reset in case of bitrate switching in EVS */ + if ( st->hSC_VBR != NULL ) + { + update_average_rate( st->hSC_VBR, st->core_brate ); + } + } + + pop_wmops(); + return error; +} +#else ivas_error acelp_core_enc( Encoder_State *st, /* i/o: encoder state structure */ const float inp[], /* i : input signal of the current frame */ @@ -726,3 +2191,4 @@ ivas_error acelp_core_enc( return error; } +#endif \ No newline at end of file diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 3f5ddbb4b..0fd37dd5d 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -255,8 +255,8 @@ void amr_wb_enc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - - modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0 ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); /* update signal buffer */ Copy( new_inp, st->buf_speech_enc + L_FRAME, L_FRAME ); @@ -459,7 +459,7 @@ void amr_wb_enc_fx( } ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { - modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k_fx, 0 ); + modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k_fx, 0, &Q_new_inp, &mem_decim_size ); } /*----------------------------------------------------------------* diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index eb3e62ddf..2496d54d3 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -312,16 +312,14 @@ void bw_detect_fx( } ELSE { -#ifdef IVAS_CODE_DFT - l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); - if ( st->core == TCX_10_CORE ) + Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); + IF( EQ_16( st->core, TCX_10_CORE ) ) { - l_frame /= 2; + l_frame = shr( l_frame, 1 ); } - bin_width *= ( l_frame / BWD_TOTAL_WIDTH ); - mvr2r( spectrum, spect, l_frame ); -#endif + bin_width = i_mult( bin_width, l_frame / BWD_TOTAL_WIDTH ); + Copy( spectrum, spect, l_frame ); } /*---------------------------------------------------------------------* * compute energy per spectral bins diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 401eb6412..c037a4c34 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -759,7 +759,8 @@ void CNG_enc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0 ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0, &Q_new_inp, &mem_decim_size ); } fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index c5d5a39a5..02550d2bb 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -41,6 +41,7 @@ #include "rom_enc.h" #include "prot.h" #include "ivas_prot.h" +#include "prot_fx2.h" #include "ivas_cnst.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED @@ -162,7 +163,11 @@ ivas_error init_encoder( st->mem_preemph = 0.0f; st->mem_preemph16k = 0.0f; st->mem_preemph_enc_flt = 0.0; - +#ifdef IVAS_FLOAT_FIXED + st->mem_preemph_fx = 0; + st->mem_preemph16k_fx = 0; + st->mem_preemph_enc = 0; +#endif /* AVQ pre-quantizer memory */ st->mem_preemp_preQ = 0.0f; st->mem_deemp_preQ = 0.0f; @@ -233,9 +238,13 @@ ivas_error init_encoder( set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); st->mem_preemph16k_DFT = 0.0f; set_f( st->inp_16k_mem_stereo_sw, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - +#ifdef IVAS_FLOAT_FIXED + st->mem_preemph_DFT_fx = 0; + set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); + st->mem_preemph16k_DFT_fx = 0; + set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); st->sharpFlag = 0; - +#endif /* Stationary noise UV modification */ st->ge_sm = 10; st->uv_count = 0; @@ -284,25 +293,53 @@ ivas_error init_encoder( } st->Bin_E_old = st->hSignalBuf->Bin_E_old_flt; +#ifdef IVAS_FLOAT_FIXED + st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; +#endif st->mem_decim = st->hSignalBuf->mem_decim_flt; st->mem_decim16k = st->hSignalBuf->mem_decim16k_flt; st->old_inp_12k8 = st->hSignalBuf->old_inp_12k8_flt; st->old_inp_16k = st->hSignalBuf->old_inp_16k_flt; +#ifdef IVAS_FLOAT_FIXED + st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; + st->old_inp_12k8_fx = st->hSignalBuf->old_inp_12k8_fx; + st->old_inp_16k_fx = st->hSignalBuf->old_inp_16k_fx; + st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; +#endif st->buf_speech_enc_pe_flt = st->hSignalBuf->buf_speech_enc_pe_flt; st->buf_synth_flt = st->hSignalBuf->buf_synth_flt; st->buf_speech_enc_flt = st->hSignalBuf->buf_speech_enc_flt; st->buf_wspeech_enc_flt = st->hSignalBuf->buf_wspeech_enc_flt; +#ifdef IVAS_FLOAT_FIXED + st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; + st->buf_synth = st->hSignalBuf->buf_synth; + st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; + st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; +#endif /* initializations */ set_f( st->Bin_E_old, 0, L_FFT / 2 ); +#ifdef IVAS_FLOAT_FIXED + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); +#endif set_f( st->mem_decim, 0, 2 * L_FILT_MAX ); set_f( st->mem_decim16k, 0, 2 * L_FILT_MAX ); set_f( st->old_inp_12k8, 0, L_INP_MEM ); set_f( st->old_inp_16k, 0, L_INP_MEM ); - +#ifdef IVAS_FLOAT_FIXED + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); + set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); + set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); + set16_fx( st->mem_decim_fx, 0, 2 * L_FILT_MAX ); +#endif st->input_buff = st->hSignalBuf->input_buff_flt; set_zero( st->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); st->old_input_signal = st->input_buff; +#ifdef IVAS_FLOAT_FIXED + st->input_buff_fx = st->hSignalBuf->input_buff; + set16_fx( st->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + st->old_input_signal_fx = st->input_buff_fx; +#endif if ( st->element_mode == EVS_MONO ) { st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC + NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ); @@ -310,6 +347,9 @@ ivas_error init_encoder( else { st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC; +#ifdef IVAS_FLOAT_FIXED + st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC; +#endif } } else @@ -317,12 +357,18 @@ ivas_error init_encoder( st->hSignalBuf = NULL; st->Bin_E_old = NULL; st->mem_decim = NULL; +#ifdef IVAS_FLOAT_FIXED + st->mem_decim_fx = NULL; +#endif st->mem_decim16k = NULL; st->old_inp_12k8 = NULL; st->old_inp_16k = NULL; st->buf_speech_enc_pe_flt = NULL; st->buf_synth_flt = NULL; st->buf_speech_enc_flt = NULL; +#ifdef IVAS_FLOAT_FIXED + st->buf_speech_enc = NULL; +#endif st->buf_wspeech_enc_flt = NULL; st->input_buff = NULL; } @@ -504,7 +550,7 @@ ivas_error init_encoder( if ( ( st->element_mode != IVAS_CPE_MDCT && idchan == 0 ) || ( st->element_mode == IVAS_CPE_MDCT && st->Opt_DTX_ON ) ) { - if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -513,7 +559,10 @@ ivas_error init_encoder( { st->cldfbAnaEnc = NULL; } - +#ifdef IVAS_FLOAT_FIXED + st->energyCoreLookahead_Fx = 0; + st->sf_energyCoreLookahead_Fx = 0; +#endif st->currEnergyLookAhead = 6.1e-5f; /*-----------------------------------------------------------------* @@ -605,7 +654,7 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -841,7 +890,9 @@ ivas_error init_encoder( } initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); - +#ifdef IVAS_FLOAT_FIXED + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); +#endif /* initialization for IVAS modes happens in first frame pre-processing */ if ( st->element_mode == EVS_MONO ) { @@ -879,7 +930,22 @@ ivas_error init_encoder( st->cng_sba_flag = 0; st->bits_frame_channel = 0; st->side_bits_frame_channel = 0; - +#ifdef IVAS_FLOAT_FIXED + st->Q_syn2 = 0; + move16(); + st->Q_syn = 0; + move16(); + set16_fx( st->Q_max, Q_MAX, L_Q_MEM ); + set16_fx( st->Q_max_16k, Q_MAX, L_Q_MEM ); + st->Q_old = 15; + move16(); + st->old_wsp_max = 0; + move16(); + st->old_wsp_shift = 0; + move16(); + st->sharpFlag = 0; + move16(); +#endif return error; } #ifdef IVAS_FLOAT_FIXED @@ -1058,9 +1124,9 @@ ivas_error init_encoder_ivas_fx( /* stereo switching memories */ st->mem_preemph_DFT_fx = 0; - set32_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); + set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); st->mem_preemph16k_DFT_fx = 0; - set32_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); + set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); st->sharpFlag = 0; @@ -1335,7 +1401,7 @@ ivas_error init_encoder_ivas_fx( IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( idchan, 0 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - IF( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -1436,7 +1502,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - IF( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -1694,8 +1760,9 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - /* (int16_t) ( st->input_Fs / FRAMES_PER_SEC ) */ - Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + Word16 temp; + Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); + frame_length = shr( frame_length, sub( 15, temp ) ); IF( GT_16( st->element_mode, EVS_MONO ) ) { @@ -1714,6 +1781,20 @@ ivas_error init_encoder_ivas_fx( st->cng_sba_flag = 0; st->bits_frame_channel = 0; st->side_bits_frame_channel = 0; + st->Q_syn2 = 0; + move16(); + st->Q_syn = 0; + move16(); + set16_fx( st->Q_max, Q_MAX, L_Q_MEM ); + set16_fx( st->Q_max_16k, Q_MAX, L_Q_MEM ); + st->Q_old = 15; + move16(); + st->old_wsp_max = 0; + move16(); + st->old_wsp_shift = 0; + move16(); + st->sharpFlag = 0; + move16(); return error; } diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index d08241540..b103282e9 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -37,6 +37,9 @@ #include "rom_enc.h" #include "rom_com.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" +#include "prot_fx_enc.h" #include "ivas_prot.h" #include "wmc_auto.h" #include @@ -52,7 +55,16 @@ /*-------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------*/ - +#if 0 +static void change_q( Word16 *buff, Word16 size, Word16 Q ) +{ + Flag Overflow; + for ( Word16 i = 0; i < size; i++ ) + { + buff[i] = shr_o( buff[i], Q, &Overflow ); + } +} +#endif static void calculate_energy_buffer( CPE_ENC_HANDLE hCPE, float enerBuffer_dft[], const int16_t no_channels, const int32_t input_Fs ); #ifdef IVAS_FIXED_ENC static void calculate_energy_buffer_fx( CPE_ENC_HANDLE hCPE, Word64 enerBuffer_dft_fx[], Word16 *enerBuffer_dft_q_fx, const Word16 no_channels, const Word32 input_Fs ); @@ -64,7 +76,6 @@ static void calculate_energy_buffer_fx( CPE_ENC_HANDLE hCPE, Word64 enerBuffer_d * Front Pre-processing for IVAS * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) *--------------------------------------------------------------------*/ - ivas_error pre_proc_front_ivas( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ @@ -836,8 +847,1254 @@ ivas_error pre_proc_front_ivas( pop_wmops(); return error; } +#ifdef IVAS_FLOAT_FIXED +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 int32_t element_brate, /* i : SCE/CPE element bitrate */ + const int16_t nb_bits_metadata, /* i : number of metadata bits */ + const int16_t input_frame, /* i : frame length */ + const int16_t n, /* i : channel number */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float *relE, /* o : frame relative energy */ + float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* o : LP prediction errors */ + float lsp_new[M], /* o : LSPs at the end of the frame */ + float lsp_mid[M], /* o : LSPs in the middle of the frame */ + int16_t *vad_hover_flag, /* o : VAD hangover flag */ + int16_t *attack_flag, /* o : flag signaling attack */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ + float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ + int16_t *loc_harm, /* o : harmonicity flag */ + float *cor_map_sum, /* o : speech/music clasif. parameter */ + int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ + const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ + const float currFlatness, /* i : flatness parameter */ + const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const float Etot_LR[], /* i : total energy Left & Right channel Q8*/ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const int16_t force_front_vad, /* i : flag to force VAD decision */ + const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ +) +{ + float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ + float *wsp; /* weighted input signal buffer */ + float Etot; /* total energy */ + float fr_bands[2 * NB_BANDS]; /* energy in frequency bands */ + float lf_E[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + float tmpN[NB_BANDS]; /* Temporary noise update */ + float tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + float tmpN_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ + float tmpE_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + float cor_map_sum_LR[CPE_CHANNELS]; /* speech/music clasif. parameter */ + float non_staX_LR; /* non-stationarity for sp/mus classifier */ + float ncharX_LR; /* noise character for sp/mus classifier */ + float sp_div_LR; /* spectral diversity feature */ + float S_map_LR[L_FFT / 2]; /* short-term correlation map */ + float corr_shiftL; /* correlation shift */ + float corr_shiftR; /* correlation shift */ + int16_t loc_harmLR[CPE_CHANNELS]; /* harmonicity flag */ + int16_t lr_vad_enabled; /* LR VAD indicator */ + float ee[2]; /* Spectral tilt */ + float corr_shift; /* correlation shift */ + float sp_div, PS[128]; /* speech/music clasif. parameters */ + int16_t L_look; /* length of look-ahead */ +#if 1 + float snr_sum_he; /* HE SAD parameters */ +#endif + float mem_decim_dummy[2 * L_FILT_MAX]; /* dummy decimation filter memory */ + float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ + float hp_E[2]; /* Energy in HF */ + int16_t flag_spitch; + int16_t high_lpn_flag; + float lsf_new[M]; + float band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ + int16_t localVAD_HE_SAD; + float non_staX; + float stab_fac; + int16_t alw_pitch_lag_12k8[2]; + float alw_voicing[2]; + int16_t last_core_orig; + float dummy; + float S_map[L_FFT / 2]; + int16_t i, lMemRecalc, lMemRecalc_12k8; + int16_t smc_dec; + float ncharX, dE1X; + Encoder_State *st; + float *signal_in; + int16_t element_mode; + int32_t input_Fs, last_element_brate; + int16_t *tdm_SM_last_clas, tmpS; + float *res_cod_SNR_M, tmpF[STEREO_DFT_BAND_MAX]; + STEREO_CLASSIF_HANDLE hStereoClassif; + int16_t old_pitch1; /* previous frame OL pitch[1] @12.8 kHz */ + int16_t LR_localVAD; + ivas_error error; + + push_wmops( "pre_proc_front" ); + +#ifdef IVAS_FLOAT_FIXED + Word16 *signal_in_fx; + Word16 *new_inp_12k8_fx; /* pointers to current frame and new data */ + CLDFB_SCALE_FACTOR cldfbScale; + Word32 *enerBuffer_fx; + Word16 enerBuffer_exp; /*[CLDFB_NO_CHANNELS_MAX];*/ + Word16 *temp1F_icatdmResampBuf_fx; + Word16 *old_inp_12k8_fx; + Word16 *old_inp_16k_fx; + Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word32 Etot_fx; /* total energy */ +#if 0 + Word32 fr_bands_fx[2 * NB_BANDS]; /* energy in frequency bands */ + Word16 Q_new; + Word16 new_inp_out_size, mem_decim_size; + Word16 snr_sum_he_fx; /* HE SAD parameters */ + Word16 Q_new_inp; + Word16 corr_shift_fx; + Word16 dummy_fx; + Word16 Etot_LR_fx[2]; + Word16 Q_exp; + Word32 Le_min_scaled; + Word32 fr_bands_LR_fx[2][2 * NB_BANDS]; + Word16 relE_fx; + Word32 tmpN_fx[NB_BANDS]; /* Temporary noise update */ + Word32 tmpE_fx[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + Word32 tmpN_LR_fx[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ + Word32 tmpE_LR_fx[CPE_CHANNELS][NB_BANDS]; /* Temporary averaged energy of 2 sf. */ +#endif + + signal_in_fx = (Word16 *) malloc( 2 * 1965 * sizeof( Word16 * ) ); + enerBuffer_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) ); + old_inp_12k8_fx = (Word16 *) malloc( 496 * sizeof( Word16 * ) ); + old_inp_16k_fx = (Word16 *) malloc( 880 * sizeof( Word16 * ) ); + mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); + temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); + + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; + + floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, 0, 496 ); +#endif + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + error = IVAS_ERR_OK; + + tmpS = 0; + tdm_SM_last_clas = &tmpS; + set_f( tmpF, 0, STEREO_DFT_BAND_MAX ); + res_cod_SNR_M = tmpF; + + LR_localVAD = 0; + + if ( hSCE != NULL ) + { + st = hSCE->hCoreCoder[n]; + signal_in = hSCE->hCoreCoder[n]->input; + element_mode = IVAS_SCE; + last_element_brate = hSCE->last_element_brate; + hStereoClassif = NULL; + lr_vad_enabled = 0; + } + else /* CPE */ + { + st = hCPE->hCoreCoder[n]; + signal_in = hCPE->hCoreCoder[n]->input; + element_mode = hCPE->element_mode; + last_element_brate = hCPE->last_element_brate; + hStereoClassif = hCPE->hStereoClassif; + lr_vad_enabled = 0; + if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) + { + lr_vad_enabled = 1; + } + + if ( lr_vad_enabled && n == 0 ) + { + /* Combine localVAD and vad_flag from LR processing */ + LR_localVAD = hCPE->hCoreCoder[0]->localVAD || hCPE->hCoreCoder[1]->localVAD; + } + + if ( hCPE->hStereoTD != NULL ) + { + tdm_SM_last_clas = &hCPE->hStereoTD->tdm_SM_last_clas[n]; + mvs2s( hCPE->hStereoTD->tdm_SM_last_clas, hCPE->hStereoTD->tdm_SM_last2_clas, CPE_CHANNELS ); + } + + if ( hCPE->hStereoDft != NULL ) + { + res_cod_SNR_M = hCPE->hStereoDft->res_cod_SNR_M; + } + } +#if 0 + set32_fx( tmpF_fx, 0, STEREO_DFT_BAND_MAX ); + res_cod_SNR_M_fx = tmpF_fx; + + LR_localVAD = 0; + + IF ( hSCE != NULL ) + { + st = hSCE->hCoreCoder[n]; + signal_in_fx = hSCE->hCoreCoder[n]->input_fx; + element_mode = IVAS_SCE; + last_element_brate = hSCE->last_element_brate; + hStereoClassif = NULL; + lr_vad_enabled = 0; + } + ELSE /* CPE */ + { + st = hCPE->hCoreCoder[n]; + signal_in_fx = hCPE->hCoreCoder[n]->input_fx; + element_mode = hCPE->element_mode; + last_element_brate = hCPE->last_element_brate; + hStereoClassif = hCPE->hStereoClassif; + lr_vad_enabled = 0; + IF ( hCPE->hFrontVad[0] != NULL && NE_16(hCPE->element_mode, IVAS_CPE_MDCT )) + { + lr_vad_enabled = 1; + } + + IF ( lr_vad_enabled && EQ_16(n, 0 )) + { + /* Combine localVAD and vad_flag from LR processing */ + LR_localVAD = hCPE->hCoreCoder[0]->localVAD || hCPE->hCoreCoder[1]->localVAD; + } + + IF ( hCPE->hStereoTD != NULL ) + { + tdm_SM_last_clas = &hCPE->hStereoTD->tdm_SM_last_clas[n]; + Copy( hCPE->hStereoTD->tdm_SM_last_clas, hCPE->hStereoTD->tdm_SM_last2_clas, CPE_CHANNELS ); + } + + IF ( hCPE->hStereoDft != NULL ) + { + res_cod_SNR_M_fx = hCPE->hStereoDft->res_cod_SNR_M_fx; + } + } +#endif + lMemRecalc_12k8 = 0; + lMemRecalc = 0; + IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + lMemRecalc = NS2SA( st->input_Fs, L_MEM_RECALC_NS ); + lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS ); + } + + input_Fs = st->input_Fs; + + localVAD_HE_SAD = 0; +#if 1 + snr_sum_he = 0; +#endif + corr_shiftL = 0; + corr_shiftR = 0; +#if 0 + snr_sum_he_fx = 0; +#endif + IF( hSCE != NULL ) + { + *vad_hover_flag = 0; + } + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + st->coder_type = GENERIC; + IF( st->hGSCEnc != NULL ) + { + st->hGSCEnc->noise_lev = NOISE_LEVEL_SP0; + } + *attack_flag = 0; + + IF( st->Opt_SC_VBR ) + { + st->hSC_VBR->bump_up = 0; + st->hSC_VBR->ppp_mode = 0; + st->hSC_VBR->nelp_mode = 0; + st->hSC_VBR->avoid_HQ_VBR_NB = 0; + } + + L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ + + new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ +#ifdef IVAS_FLOAT_FIXED + new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ +#if 0 + inp_12k8_fx = new_inp_12k8_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ +#endif +#endif + if ( element_mode != IVAS_CPE_DFT ) + { + new_inp_12k8 -= L_FILT; + } + + if ( element_mode == IVAS_CPE_DFT ) + { + mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - STEREO_DFT_OVL_12k8 ); + } + else if ( element_mode == IVAS_CPE_TD ) + { + mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - lMemRecalc_12k8 - L_FILT ); + } + else + { + mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - L_FILT ); + } + + mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + IF( NE_16( element_mode, IVAS_CPE_DFT ) ) + { + new_inp_12k8_fx -= L_FILT; + } +#if 0 + IF(EQ_16(element_mode, IVAS_CPE_DFT)) + { + Copy(st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - STEREO_DFT_OVL_12k8); + } + ELSE IF(EQ_16(element_mode, IVAS_CPE_TD)) + { + Copy(st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - lMemRecalc_12k8 - L_FILT); + } + ELSE + { + Copy(st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - L_FILT); + } + Copy(st->old_wsp, old_wsp, L_WSP_MEM); + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ +#endif + st->rf_mode = st->Opt_RF_ON; + + last_core_orig = st->last_core; + + /*--------------------------------------------------------------* + * energy analysis + *---------------------------------------------------------------*/ + + floatToFixed_arr( signal_in - (Word16) ( input_Fs / 50 ), signal_in_fx, 0, (Word16) ( input_Fs / 25 ) ); + signal_in_fx = signal_in_fx + input_Fs / 50; + IF( EQ_16( element_mode, IVAS_SCE ) || ( EQ_16( element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + { + analysisCldfbEncoder_ivas_fx( st, signal_in_fx, realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, &enerBuffer_exp, &cldfbScale ); + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + realBuffer[i][j] = (float) realBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + imagBuffer[i][j] = (float) imagBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + } + } + cldfbScale.hb_scale = cldfbScale.lb_scale; + fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); + } + ELSE IF( ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 0 ) ) || ( EQ_16( st->idchan, 1 ) && st->tdm_LRTD_flag ) ) + { + /* cldfb analysis only for pri. channel */ + analysisCldfbEncoder_ivas_fx( st, signal_in_fx - NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ), realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, &enerBuffer_exp, &cldfbScale ); + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + realBuffer[i][j] = (float) realBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + imagBuffer[i][j] = (float) imagBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + } + } + cldfbScale.hb_scale = cldfbScale.lb_scale; + fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + calculate_energy_buffer( hCPE, enerBuffer, st->cldfbAnaEnc->no_channels, input_Fs ); + f2me_buf( enerBuffer, enerBuffer_fx, &enerBuffer_exp, 60 ); + } + ELSE + { + set32_fx( enerBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX ); + enerBuffer_exp = 31; + } + + /*----------------------------------------------------------------* + * Change the sampling frequency to 12.8 kHz + * (if not available from downsampled DMX) + *----------------------------------------------------------------*/ +#if 0 // Disabled due to high mld -- Scaling needs to be handled. + IF( element_mode == IVAS_SCE ) + { + new_inp_out_size = modify_Fs_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); + + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, Q_new_inp, new_inp_out_size ); // To be removed + fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, 0, mem_decim_size ); // To be removed + + change_q( new_inp_12k8_fx, new_inp_out_size, Q_new_inp ); + + Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); + + set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); + + new_inp_out_size = modify_Fs_fx( temp1F_icatdmResampBuf_fx, NS2SA( 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 ); + + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, Q_new_inp, new_inp_out_size ); // To be removed + change_q( new_inp_12k8_fx + L_FRAME, new_inp_out_size, Q_new_inp ); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + /* reconstruct past segment of the Secondary channel input signal when switching from DFT stereo */ + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + { + Word16 length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS ); + Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + + new_inp_out_size = modify_Fs_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); + + fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, 0, mem_decim_size ); // To be removed + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, Q_new_inp, new_inp_out_size ); // To be removed + + change_q( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, Q_new_inp ); + } + + new_inp_out_size = modify_Fs_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); + Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, Q_new_inp, new_inp_out_size ); // To be removed + fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, 0, mem_decim_size ); // To be removed + + change_q( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, Q_new_inp ); + + IF( GT_16( lMemRecalc, 0 ) ) + { + new_inp_out_size = modify_Fs_fx( signal_in_fx + input_frame - lMemRecalc, lMemRecalc, input_Fs, new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, new_inp_12k8 + L_FRAME - lMemRecalc_12k8, Q_new_inp, new_inp_out_size ); // To be removed + + change_q( new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, new_inp_out_size, Q_new_inp ); + } + set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); + new_inp_out_size = modify_Fs_fx( temp1F_icatdmResampBuf_fx, NS2SA( 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 ); + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, Q_new_inp, new_inp_out_size ); // To be removed + + change_q( new_inp_12k8_fx + L_FRAME, new_inp_out_size, Q_new_inp ); + } + ELSE /* DFT stereo */ + { + /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ + Copy( signal_in_fx + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); + mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); // To be removed + } +#else + if ( element_mode == IVAS_SCE ) + { + modify_Fs( signal_in, input_frame, input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); + + mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); + set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); + modify_Fs( temp1F_icatdmResampBuf, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + /* reconstruct past segment of the Secondary channel input signal when switching from DFT stereo */ + if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) + { + int16_t length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS ); + int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + + modify_Fs( signal_in - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim, 0 ); + } + + modify_Fs( signal_in - lMemRecalc, input_frame, input_Fs, new_inp_12k8 - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); + mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); + + if ( lMemRecalc > 0 ) + { + modify_Fs( signal_in + input_frame - lMemRecalc, lMemRecalc, input_Fs, new_inp_12k8 + L_FRAME - lMemRecalc_12k8, INT_FS_12k8, mem_decim_dummy, ( st->max_bwidth == NB ) ); + } + set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); + modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); + } + else /* DFT stereo */ + { + /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ + mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); + } +#endif + /* save input resampled at 12.8kHz, non-preemhasised */ + if ( element_mode == IVAS_CPE_DFT ) + { + mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8, st->buf_speech_enc_flt + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + mvr2r( new_inp_12k8 - lMemRecalc_12k8, st->buf_speech_enc_flt + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT ); + } + else + { + mvr2r( new_inp_12k8, st->buf_speech_enc_flt + L_FRAME32k, L_FRAME ); + } +#if 1 + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); + Scale_sig( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8, 1 ); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + Copy( new_inp_12k8_fx - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT ); + Scale_sig( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT, 1 ); + } + ELSE + { + Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); + Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); + } +#endif + /*------------------------------------------------------------------* + * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 + *-----------------------------------------------------------------*/ +#if 0 // Disabled due to high mld +#if 0 // EVS-Version + Word16 headroom = 1; + IF( ( ( EQ_16( st->bwidth, NB ) ) || ( EQ_16( st->max_bwidth, NB ) ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) + { + headroom = add( headroom, 1 ); + } + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + + Preemph_scaled( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); + + fixedToFloat_arr( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, new_inp_12k8 - STEREO_DFT_OVL_12k8, Q_new, L_FRAME ); // To be removed + dummy_fx = st->mem_preemph_fx; + Preemph_scaled( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, &Q_new, &dummy_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, STEREO_DFT_OVL_12k8, st->last_coder_type, 1 ); + + st->mem_preemph = (float) st->mem_preemph_fx; + fixedToFloat_arr( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, Q_new, STEREO_DFT_OVL_12k8 ); // To be removed + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( EQ_16( st->idchan, 0 ) ) + { + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) + { + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + Preemph_scaled( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, st->last_coder_type, 1 ); + + st->mem_preemph = (float) st->mem_preemph_fx; + fixedToFloat_arr( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), Q_new, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); // To be removed + } + + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + { + Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + Preemph_scaled( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, length_12k8, st->last_coder_type, 1 ); + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, Q_new, length_12k8 ); // To be removed + } + + Preemph_scaled( new_inp_12k8_fx - lMemRecalc_12k8, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); + dummy_fx = st->mem_preemph_fx; + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, Q_new, L_FRAME ); // To be removed + + Preemph_scaled( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, &Q_new, &dummy_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, lMemRecalc_12k8 + L_FILT, st->last_coder_type, 1 ); + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, new_inp_12k8 - lMemRecalc_12k8 + L_FRAME, Q_new, lMemRecalc_12k8 + L_FILT ); // To be removed + } + ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ + { + floatToFixed_arr( new_inp_12k8, new_inp_12k8_fx, 0, L_FRAME + L_FILT ); // To be removed + + Preemph_scaled( new_inp_12k8_fx, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); + dummy_fx = st->mem_preemph_fx; + + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, Q_new, L_FRAME ); // To be removed + floatToFixed_arr( new_inp_12k8, new_inp_12k8_fx, 0, L_FRAME + L_FILT ); // To be removed + + Preemph_scaled( new_inp_12k8_fx + L_FRAME, &Q_new, &dummy_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FILT, st->last_coder_type, 1 ); + st->mem_preemph = (float) st->mem_preemph_fx; + + fixedToFloat_arr( new_inp_12k8_fx + 256, new_inp_12k8 + 256, Q_new, 12 ); // To be removed + } + + Q_exp = sub( Q_new, st->Q_old ); + st->prev_Q_old = st->Q_old; + move16(); + st->Q_old = Q_new; + move16(); +#else // IVAS-Version + + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + floatToFixed_arr( new_inp_12k8 - STEREO_DFT_OVL_12k8, new_inp_12k8_fx - STEREO_DFT_OVL_12k8, 0, L_FRAME + STEREO_DFT_OVL_12k8 ); // To be removed + st->mem_preemph_fx = (Word16) st->mem_preemph; + st->mem_preemph_DFT_fx = (Word16) st->mem_preemph_DFT; + + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ +#if 1 // TOBE removed later + mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; +#endif + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + + preemph_fx( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + preemph_fx( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC_FLT, STEREO_DFT_OVL_12k8, &dummy_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, new_inp_12k8 - STEREO_DFT_OVL_12k8, 0, L_FRAME + STEREO_DFT_OVL_12k8 ); // To be removed + st->mem_preemph = (float) st->mem_preemph_fx; + st->mem_preemph_DFT = (float) st->mem_preemph_DFT_fx; + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( EQ_16( st->idchan, 0 ) ) + { + + st->mem_preemph_fx = (Word16) st->mem_preemph; + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) + { +#if 1 // TOBE removed later + + floatToFixed_arr( new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); // To be removed + st->mem_preemph_DFT_fx = (Word16) st->mem_preemph_DFT; + + mvr2r( st->inp_12k8_mem_stereo_sw, new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); +#endif + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + preemph_fx( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); // To be removed + } + + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ +#if 1 // TOBE removed later + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ // TO be remove later +#endif + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + { + Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + + floatToFixed_arr( new_inp_12k8 - lMemRecalc_12k8 - length_12k8, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, 0, length_12k8 ); // To be removed + + preemph_fx( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, 0, length_12k8 ); // To be removed + } + + floatToFixed_arr( new_inp_12k8 - lMemRecalc_12k8, new_inp_12k8_fx - lMemRecalc_12k8, 0, L_FRAME + lMemRecalc_12k8 + L_FILT ); // To be removed + + preemph_fx( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + preemph_fx( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, 0, L_FRAME + lMemRecalc_12k8 + L_FILT ); // To be removed + } + ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ + { + floatToFixed_arr( new_inp_12k8, new_inp_12k8_fx, 0, L_FRAME + L_FILT ); // To be removed + st->mem_preemph_fx = (Word16) st->mem_preemph; + + preemph_fx( new_inp_12k8_fx, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + preemph_fx( new_inp_12k8_fx + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); + + st->mem_preemph = (float) st->mem_preemph_fx; + dummy = (float) dummy_fx; + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, 0, L_FRAME + L_FILT ); // To be removed + } +#endif +#else + if ( element_mode == IVAS_CPE_DFT ) + { + mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + + st->mem_preemph = st->mem_preemph_DFT; + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + + preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8, PREEMPH_FAC_FLT, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC_FLT, STEREO_DFT_OVL_12k8, &dummy ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + if ( st->idchan == 0 ) + { + if ( hCPE->last_element_mode == IVAS_CPE_DFT ) + { + st->mem_preemph = st->mem_preemph_DFT; + mvr2r( st->inp_12k8_mem_stereo_sw, new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + preemph( new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC_FLT, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph ); + } + + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) + { + int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + preemph( new_inp_12k8 - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC_FLT, length_12k8, &st->mem_preemph ); + } + + preemph( new_inp_12k8 - lMemRecalc_12k8, PREEMPH_FAC_FLT, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC_FLT, lMemRecalc_12k8 + L_FILT, &dummy ); + } + else /* IVAS_SCE or IVAS_CPE_MDCT */ + { + preemph( new_inp_12k8, PREEMPH_FAC_FLT, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 + L_FRAME, PREEMPH_FAC_FLT, L_FILT, &dummy ); + } +#endif + +#if 0 + /*------------------------------------------------------------------* + * Scaling of memories + *-----------------------------------------------------------------*/ + Q_new = 0; + floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->ave_enr2, st->hNoiseEst->ave_enr2_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->fr_bands1, st->hNoiseEst->fr_bands1_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->fr_bands2, st->hNoiseEst->fr_bands2_fx, Q_new + QSCALE, 20 ); + + Le_min_scaled = Scale_mem_pre_proc( st->ini_frame, Q_exp, &Q_new, old_inp_12k8_fx, &( st->mem_wsp_fx ), st->hNoiseEst->enrO_fx, st->hNoiseEst->bckr_fx, + st->hNoiseEst->ave_enr_fx, st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->fr_bands1_fx, st->hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); +#endif + /*-------------------------------------------------------------------------* + * Spectral analysis + *--------------------------------------------------------------------------*/ + analy_sp( element_mode, hCPE, input_Fs, inp_12k8, st->Bin_E, st->Bin_E_old, fr_bands, lf_E, &Etot, st->min_band, st->max_band, band_energies, PS, fft_buff ); + + if ( hStereoClassif != NULL ) + { + if ( st->lp_speech - Etot > 25 ) + { + hStereoClassif->silence_flag = 2; + } + else + { + hStereoClassif->silence_flag = hStereoClassif->silence_flag - 1; + } + hStereoClassif->silence_flag = max( 0, hStereoClassif->silence_flag ); + } + + /*----------------------------------------------------------------* + * SAD (1-signal, 0-noise) + *----------------------------------------------------------------*/ + + Etot_fx = (Word32) ( Etot * ( 1 << 24 ) ); + st->hNoiseEst->Etot_h_32fx = (Word32) ( st->hNoiseEst->Etot_h * 16777216.0 ); + st->hNoiseEst->Etot_l_32fx = (Word32) ( st->hNoiseEst->Etot_l * 16777216.0 ); + st->hNoiseEst->Etot_l_lp_32fx = (Word32) ( st->hNoiseEst->Etot_l_lp * 16777216.0 ); + st->hNoiseEst->Etot_last_32fx = (Word32) ( st->hNoiseEst->Etot_last * 16777216.0 ); + st->hNoiseEst->Etot_v_h2_32fx = (Word32) ( st->hNoiseEst->Etot_v_h2 * 16777216.0 ); + st->hNoiseEst->Etot_lp_32fx = (Word32) ( st->hNoiseEst->Etot_lp * 16777216.0 ); + st->hNoiseEst->sign_dyn_lp_32fx = (Word32) ( st->hNoiseEst->sign_dyn_lp * 16777216.0 ); + + noise_est_pre_32fx( Etot_fx, st->ini_frame, st->hNoiseEst, st->idchan, element_mode, hCPE != NULL ? hCPE->last_element_mode : element_mode ); + + st->hNoiseEst->Etot_h = (float) ( st->hNoiseEst->Etot_h_32fx / 16777216.0 ); + st->hNoiseEst->Etot_l = (float) ( st->hNoiseEst->Etot_l_32fx / 16777216.0 ); + st->hNoiseEst->Etot_l_lp = (float) ( st->hNoiseEst->Etot_l_lp_32fx / 16777216.0 ); + st->hNoiseEst->Etot_last = (float) ( st->hNoiseEst->Etot_last_32fx / 16777216.0 ); + st->hNoiseEst->Etot_v_h2 = (float) ( st->hNoiseEst->Etot_v_h2_32fx / 16777216.0 ); + st->hNoiseEst->Etot_lp = (float) ( st->hNoiseEst->Etot_lp_32fx / 16777216.0 ); + st->hNoiseEst->sign_dyn_lp = (float) ( st->hNoiseEst->sign_dyn_lp_32fx / 16777216.0 ); + + IF( EQ_16( element_mode, IVAS_CPE_TD ) && ( ( abs( hCPE->hStereoTD->tdm_last_ratio_idx - tdm_ratio_idx ) > 5 && EQ_16( st->idchan, 1 ) ) || abs( hCPE->hStereoTD->tdm_last_inst_ratio_idx - hCPE->hStereoTD->tdm_inst_ratio_idx ) > 10 ) ) + { + st->ini_frame = 1; + } +#if 0 // Disbaled due to high MLD + Q_new = Q_factor_arr( fr_bands, 40 ); + floatToFixed_arrL( fr_bands, fr_bands_fx, Q_new + QSCALE, 40 ); + st->lp_noise_fx = (Word16) ( st->lp_noise * ( 1 << 8 ) ); + st->lp_speech_fx = (Word16) ( st->lp_speech * ( 1 << 8 ) ); + floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); + st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; + st->hVAD->bcg_flux_fx = (Word16) st->hVAD->bcg_flux * ( 1 << 4 ); + st->hNoiseEst->Etot_v_h2_fx = (Word16) ( st->hNoiseEst->Etot_v_h2 * ( 1 << 8 ) ); + st->hNoiseEst->sign_dyn_lp_fx = (Word16) ( st->hNoiseEst->sign_dyn_lp * ( 1 << 8 ) ); + st->hVAD->snr_sum_vad_fx = (Word16) ( st->hVAD->snr_sum_vad * 32767 ); + st->hVAD->prim_act_quick_fx = (Word16) ( st->hVAD->prim_act_quick * 32767 ); + st->hVAD->prim_act_slow_fx = (Word16) ( st->hVAD->prim_act_slow * 32767 ); + st->hVAD->prim_act_fx = (Word16) ( st->hVAD->prim_act * 32767 ); + st->hVAD->prim_act_quick_he_fx = (Word16) ( st->hVAD->prim_act_quick_he * 32767 ); + st->hVAD->prim_act_slow_he_fx = (Word16) ( st->hVAD->prim_act_slow_he * 32767 ); + st->hVAD->prim_act_he_fx = (Word16) ( st->hVAD->prim_act_he * 32767 ); + + + st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float + + st->hNoiseEst->Etot_v_h2 = (float) ( st->hNoiseEst->Etot_v_h2_fx / ( 256.0 ) ); + st->hNoiseEst->sign_dyn_lp = (float) ( st->hNoiseEst->sign_dyn_lp_fx / ( 256.0 ) ); + st->hVAD->bcg_flux = (float) ( st->hVAD->bcg_flux_fx / ( 16.0 ) ); + st->flag_noisy_speech_snr = (Word16) st->flag_noisy_speech_snr_fx; + st->hVAD->snr_sum_vad = (float) ( st->hVAD->snr_sum_vad_fx / 32767.0 ); + st->hVAD->prim_act_quick = (float) ( st->hVAD->prim_act_quick_fx / 32767.0 ); + st->hVAD->prim_act_slow = (float) ( st->hVAD->prim_act_slow_fx / 32767.0 ); + st->hVAD->prim_act = (float) ( st->hVAD->prim_act_fx / 32767.0 ); + st->hVAD->prim_act_quick_he = (float) ( st->hVAD->prim_act_quick_he_fx / 32767.0 ); + st->hVAD->prim_act_slow_he = (float) ( st->hVAD->prim_act_slow_he_fx / 32767.0 ); + st->hVAD->prim_act_he = (float) ( st->hVAD->prim_act_he_fx / 32767.0 ); +#else + st->vad_flag = wb_vad( st, fr_bands, &i, &i, &i, &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), NULL, NULL, -1000.0f, -1000.0f ); +#endif + + IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_flag, 1 ) ) + { + /* overwrite VAD decision with front-VAD decision if external VAD is set to 1*/ + st->vad_flag = front_vad_flag; + st->localVAD = front_vad_flag; + } + IF( ( hCPE != NULL && !( lr_vad_enabled && EQ_16( st->idchan, 0 ) ) ) || hSCE != NULL ) + { + st->lp_noise_fx = (Word16) ( st->lp_noise * ( 1 << 8 ) ); + st->lp_speech_fx = (Word16) ( st->lp_speech * ( 1 << 8 ) ); + st->hVAD->prim_act_he_fx = (Word16) ( st->hVAD->prim_act_he * MAX_16 ); + st->hNoiseEst->Etot_lp_fx = (Word16) ( st->hNoiseEst->Etot_lp * ( 1 << 8 ) ); + + *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 ); + } + ELSE + { + /* This only applies to st->idchan==0 now */ + /* Add down mix stereo activity to LR vad_flag_dtx */ + *vad_flag_dtx = *vad_flag_dtx || st->vad_flag; + + + /* Determine hangover flag status based on LR localVAD and downmix localVAD */ + *vad_hover_flag = *vad_flag_dtx && !( LR_localVAD || st->localVAD ); + } + + IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_dtx_flag, 1 ) ) + { + /* overwrite VAD decision with front-VAD decision if external VAD is set to 1*/ + *vad_flag_dtx = front_vad_dtx_flag; + } + + /*----------------------------------------------------------------* + * NB/WB/SWB/FB bandwidth detector + *----------------------------------------------------------------*/ + FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + sf_energySum[i] = enerBuffer_exp; + move16(); + } + + IF( EQ_16( st->idchan, 0 ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + { + st->cldfbAnaEnc->scale = (Word16) ( st->cldfbAnaEnc->scale_flt * ( 1 << 8 ) ); + floatToFixed_arr( st->input, st->input_fx, 0, 480 ); + + bw_detect_fx( st, st->input_fx, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0 ); + + st->lt_mean_NB = (float) st->lt_mean_NB_fx / ( 1 << 11 ); + st->lt_mean_WB = (float) st->lt_mean_WB_fx / ( 1 << 11 ); + st->lt_mean_SWB = (float) st->lt_mean_SWB_fx / ( 1 << 11 ); + } + + IF( NE_16( element_mode, IVAS_CPE_MDCT ) ) /* in MDCT stereo, set_bw_stereo() is used instead */ + { + set_bw( 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) */ + IF( EQ_16( st->idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->tdm_LRTD_flag, 1 ) && st->bits_frame_channel >= IVAS_16k4 / FRAMES_PER_SEC ) + { + st->bwidth = hCPE->hCoreCoder[0]->bwidth; + } + + /*----------------------------------------------------------------* + * Noise energy down-ward update and total noise energy estimation + * Long-term energies and relative frame energy updates + * Correlation correction as a function of total noise level + *----------------------------------------------------------------*/ + + noise_est_down( fr_bands, st->hNoiseEst->bckr, tmpN, tmpE, st->min_band, st->max_band, &st->hNoiseEst->totalNoise, Etot, &st->hNoiseEst->Etot_last, &st->hNoiseEst->Etot_v_h2 ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + noise_est_down( fr_bands_LR[0], hCPE->hFrontVad[0]->hNoiseEst->bckr, tmpN_LR[0], tmpE_LR[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise, Etot_LR[0], &hCPE->hFrontVad[0]->hNoiseEst->Etot_last, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2 ); + noise_est_down( fr_bands_LR[1], hCPE->hFrontVad[1]->hNoiseEst->bckr, tmpN_LR[1], tmpE_LR[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise, Etot_LR[1], &hCPE->hFrontVad[1]->hNoiseEst->Etot_last, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2 ); + corr_shiftL = correlation_shift( hCPE->hFrontVad[0]->hNoiseEst->totalNoise ); + corr_shiftR = correlation_shift( hCPE->hFrontVad[1]->hNoiseEst->totalNoise ); + } + + *relE = Etot - st->lp_speech; + + corr_shift = correlation_shift( st->hNoiseEst->totalNoise ); + + /*----------------------------------------------------------------* + * FD-CNG Noise Estimator + *----------------------------------------------------------------*/ + if ( st->hFdCngEnc != NULL ) + { + resetFdCngEnc( st ); + + if ( st->idchan == 0 || element_mode == IVAS_CPE_MDCT ) + { + if ( element_mode == IVAS_CPE_TD && lr_vad_enabled && band_energies_LR != NULL ) + { + perform_noise_estimation_enc( band_energies_LR, enerBuffer, st->hFdCngEnc, input_Fs, hCPE ); + } + else + { + perform_noise_estimation_enc( band_energies, enerBuffer, st->hFdCngEnc, input_Fs, hCPE ); + } + } + } + + /*-----------------------------------------------------------------* + * Select SID or FRAME_NO_DATA frame if DTX enabled + *-----------------------------------------------------------------*/ + + if ( hCPE != NULL && element_mode != IVAS_CPE_DFT && element_mode != IVAS_CPE_MDCT ) + { + *vad_flag_dtx = 1; + } + + if ( st->Opt_DTX_ON == 1 && *vad_flag_dtx == 0 && element_mode == IVAS_CPE_DFT && element_brate <= ACELP_16k40 && hCPE->hStereoDft->hConfig->force_mono_transmission == 1 ) /* force LP_CNG usage for MASA DTX when mono tranmission */ + { + st->cng_type = LP_CNG; + } + + dtx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8 ); + + if ( hCPE != NULL && hCPE->hStereoDft != NULL && st->core_brate == SID_2k40 ) + { + /* Add another period of expected xcorr updates */ + hCPE->hStereoDft->expectedNumUpdates += st->hDtxEnc->max_SID; + } + + /*----------------------------------------------------------------* + * Adjust FD-CNG Noise Estimator + *----------------------------------------------------------------*/ + + if ( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || last_element_brate != element_brate || st->last_bwidth != st->bwidth ) ) + { + int32_t total_brate; + + total_brate = ( element_mode == IVAS_SCE ) ? st->total_brate : st->bits_frame_nominal * FRAMES_PER_SEC; + configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), total_brate ); + if ( hCPE != NULL ) + { + st->hFdCngEnc->hFdCngCom->CngBitrate = hCPE->element_brate - 1; + } + } + + if ( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) + { + AdjustFirstSID( st ); + } + + /*----------------------------------------------------------------* + * LP analysis + *----------------------------------------------------------------*/ + + alw_pitch_lag_12k8[0] = st->old_pitch_la; + alw_pitch_lag_12k8[1] = st->old_pitch_la; + alw_voicing[0] = st->voicing[2]; + alw_voicing[1] = st->voicing[2]; + + i = 0; + if ( element_mode == IVAS_CPE_TD && st->idchan == 1 && hCPE->hStereoTD->tdm_low_rate_mode == 1 ) + { + i = 1; + } + + analy_lp( inp_12k8, L_FRAME, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, i ); + + lsp2lsf( lsp_new, lsf_new, M, INT_FS_12k8 ); + stab_fac = lsf_stab( lsf_new, st->lsf_old1, 0, L_FRAME ); + mvr2r( lsf_new, st->lsf_old1, M ); + + if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) + { + /*----------------------------------------------------------------* + * Comparison of the LP coefficents to determine if it is possible + * to reuse the primary channel LP coefficients in the secondary channel + *----------------------------------------------------------------*/ + + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison( hCPE->hStereoTD, hCPE->hStereoClassif, st, inp_12k8, tdm_A_PCh, A, M, tdm_lsp_new_PCh, lsp_new, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC ); + } + + /*----------------------------------------------------------------* + * Compute weighted input (for OL pitch analysis) + * OL pitch analysis + * stable high pitch detection + * 1/4 pitch precision improvement + *----------------------------------------------------------------*/ + + find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1_FLT, L_look ); + + if ( st->vad_flag == 0 ) + { + /* reset the OL pitch tracker memories during inactive frames */ + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); + } + + old_pitch1 = st->pitch[1]; + + pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, *relE, L_look, st->clas, st->input_bwidth, st->Opt_SC_VBR ); + + /* Updates for adaptive lag window memory */ + st->old_pitch_la = st->pitch[2]; + + /* Detection of very short stable pitch period */ + StableHighPitchDetect( &flag_spitch, st->pitch, st->voicing, st->Bin_E, wsp, st->localVAD, &st->voicing_sm, &st->voicing0_sm, &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); + + /* 1/4 pitch precision improvement */ + if ( element_brate <= IVAS_32k ) + { + pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[2], &voicing_fr[2], 2 * L_SUBFR, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[3], &voicing_fr[3], 3 * L_SUBFR, wsp, 7 ); + } + else + { + pitch_fr[0] = st->pitch[0]; + pitch_fr[1] = st->pitch[0]; + pitch_fr[2] = st->pitch[1]; + pitch_fr[3] = st->pitch[1]; + + voicing_fr[0] = st->voicing[0]; + voicing_fr[1] = st->voicing[0]; + voicing_fr[2] = st->voicing[1]; + voicing_fr[3] = st->voicing[1]; + } + + /*------------------------------------------------------------------* + * Update estimated noise energy and voicing cut-off frequency + *-----------------------------------------------------------------*/ + + noise_est( st, old_pitch1, tmpN, epsP, Etot, *relE, corr_shift, tmpE, fr_bands, cor_map_sum, &ncharX, &sp_div, + &non_staX, loc_harm, lf_E, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp, &dummy /*sp_floor*/, S_map, hStereoClassif, NULL, st->ini_frame ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + /* Run noise_est for Left and Right channel */ + *loc_harmLR = *loc_harm; + noise_est( st, old_pitch1, tmpN_LR[0], epsP, Etot_LR[0], Etot_LR[0] - hCPE->hFrontVad[0]->lp_speech, corr_shiftL, tmpE_LR[0], fr_bands_LR[0], &cor_map_sum_LR[0], &ncharX_LR, &sp_div_LR, + &non_staX_LR, loc_harmLR, lf_E_LR[0], &hCPE->hFrontVad[0]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[0], hCPE->hFrontVad[0]->ini_frame ); + + /* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */ + noise_est( st, old_pitch1, tmpN_LR[1], epsP, Etot_LR[1], Etot_LR[1] - hCPE->hFrontVad[1]->lp_speech, corr_shiftR, tmpE_LR[1], fr_bands_LR[1], &cor_map_sum_LR[1], &ncharX_LR, &sp_div_LR, + &non_staX_LR, loc_harmLR, lf_E_LR[1], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame ); + } + + /*------------------------------------------------------------------* + * Update parameters used in the VAD and DTX + *-----------------------------------------------------------------*/ + + vad_param_updt( st, corr_shift, corr_shift, A, old_pitch1, NULL, 1 ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + vad_param_updt( st, corr_shiftL, corr_shiftR, A, old_pitch1, &hCPE->hFrontVad[0], CPE_CHANNELS ); + } + + /*-----------------------------------------------------------------* + * Find spectral tilt + * UC and VC frame selection + *-----------------------------------------------------------------*/ + + find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, MODE1, &( st->bckr_tilt_lt_flt ), st->Opt_SC_VBR ); + + st->coder_type = find_uv( st, pitch_fr, voicing_fr, inp_12k8, ee, &dE1X, corr_shift, *relE, Etot, hp_E, &flag_spitch, last_core_orig, hStereoClassif ); + + /*-----------------------------------------------------------------* + * channel aware mode configuration * + *-----------------------------------------------------------------*/ + + st->rf_mode = 0; + st->rf_target_bits_write = 0; + + /*-----------------------------------------------------------------* + * Signal classification for FEC + * TC frame selection + *-----------------------------------------------------------------*/ + + st->clas = signal_clas( st, inp_12k8, ee, *relE, L_look, tdm_SM_last_clas ); + + select_TC( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); + + if ( st->Opt_SC_VBR ) + { + st->hSC_VBR->Local_VAD = st->localVAD; + } + + /*-----------------------------------------------------------------* + * Collect stereo classifier features + *-----------------------------------------------------------------*/ + + if ( hStereoClassif != NULL ) + { + stereo_classifier_features( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new, epsP, st->pitch, st->voicing, *cor_map_sum, non_staX, sp_div, st->clas ); + } + + /*----------------------------------------------------------------* + * 1st stage speech/music classification (GMM model) + *----------------------------------------------------------------*/ + + smc_dec = ivas_smc_gmm( st, hStereoClassif, localVAD_HE_SAD, Etot, lsp_new, *cor_map_sum, epsP, PS, non_staX, *relE, &high_lpn_flag, flag_spitch ); + + + /*----------------------------------------------------------------* + * VAD energy updates + * Update of old per-band energy spectrum + *----------------------------------------------------------------*/ + + long_enr( st, Etot, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); + + mvr2r( fr_bands + NB_BANDS, st->hNoiseEst->enrO, NB_BANDS ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + long_enr( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR ); + + mvr2r( fr_bands_LR[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO, NB_BANDS ); + mvr2r( fr_bands_LR[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO, NB_BANDS ); + } + + /*----------------------------------------------------------------* + * SNR-based speech/music classification + * AC frame selection + *----------------------------------------------------------------*/ + + st->GSC_IVAS_mode = 0; + if ( st->idchan == 1 && element_mode == IVAS_CPE_TD ) + { + /* No speech/music classification in the secondary channel of TD stereo */ + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + + st->GSC_noisy_speech = 0; + if ( st->hGSCEnc != NULL ) + { + st->hGSCEnc->noise_lev = NOISE_LEVEL_SP3; + } + } + else if ( element_mode != IVAS_CPE_MDCT ) + { + /* SNR-based speech/music classification */ + if ( ( element_mode >= IVAS_CPE_DFT && element_brate >= IVAS_24k4 ) || ( element_mode == IVAS_SCE && element_brate >= SCE_SMC_THR ) ) + { + if ( ivas_format == SBA_FORMAT && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA && st->sba_br_sw_while_no_data ) + { + SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); + st->sba_br_sw_while_no_data = 0; + } + else if ( ivas_format == SBA_FORMAT && st->core_brate == FRAME_NO_DATA && element_brate != last_element_brate ) + { + st->sba_br_sw_while_no_data = 1; + } + + if ( flag_16k_smc ) + { + /* Compute core-coder buffers at internal sampling rate */ + error = ivas_compute_core_buffers( st, NULL, old_inp_16k, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener, A, Aw, epsP, lsp_new, lsp_mid ); + if ( error != IVAS_ERR_OK ) + { + return error; + } + + smc_dec = ivas_acelp_tcx20_switching( st, st->speech_enc_flt, st->wspeech_enc_flt, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); + } + else + { + smc_dec = ivas_acelp_tcx20_switching( st, inp_12k8, wsp, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); + } + } + /* Switch to ACELP for non-harmonic transient signals */ + else if ( ( ( element_mode >= IVAS_CPE_DFT && element_brate <= IVAS_16k4 ) || ( element_mode == IVAS_SCE && element_brate < SCE_SMC_THR ) ) && ( loc_harm[0] != 1 ) && smc_dec == MUSIC ) + { + if ( element_mode == IVAS_SCE ) + { + if ( transient_analysis( st->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) + { + smc_dec = SPEECH; + } + } + else if ( element_mode == IVAS_CPE_DFT ) + { + for ( i = 0; i < CPE_CHANNELS; i++ ) + { + if ( smc_dec != SPEECH && transient_analysis( hCPE->hCoreCoder[i]->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) + { + smc_dec = SPEECH; /* overwrite initial music decision, initial SPEECH_MUSIC never changed */ + } + } + } + } + + /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ + ivas_smc_mode_selection( st, element_brate, smc_dec, *relE, Etot, attack_flag, inp_12k8, S_map, flag_spitch ); + } + + /*----------------------------------------------------------------* + * 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) + *----------------------------------------------------------------*/ + + if ( st->Opt_DTX_ON && element_mode != IVAS_CPE_DFT ) + { + st->vad_flag = *vad_flag_dtx; + } + + /*-----------------------------------------------------------------* + * Update old input signal buffer + *-----------------------------------------------------------------*/ + + mvr2r( &old_inp_12k8[L_FRAME], st->old_inp_12k8, L_INP_MEM ); + +#ifdef IVAS_FLOAT_FIXED + free( signal_in_fx - ( input_Fs / 50 ) ); + free( enerBuffer_fx ); + free( old_inp_12k8_fx ); + free( old_inp_16k_fx ); + free( mem_decim_dummy_fx ); + free( temp1F_icatdmResampBuf_fx ); +#endif + pop_wmops(); + return error; +} +#endif + #ifdef IVAS_FIXED_ENC /*-------------------------------------------------------------------* * calculate_energy_buffer_fx() diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 55f76e430..316d279da 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -43,6 +43,8 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #endif @@ -62,8 +64,8 @@ static void stereo_mode_combined_format_enc( const Encoder_Struct *st_ivas, CPE_ ivas_error ivas_cpe_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ - const float data_f_ch0[], /* i : input signal for channel 0 */ - const float data_f_ch1[], /* i : input signal for channel 1 */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ const int16_t input_frame, /* i : input frame length per channel */ const int16_t nb_bits_metadata /* i : number of metadata bits */ ) @@ -155,9 +157,15 @@ ivas_error ivas_cpe_enc( } mvr2r( data_f_ch0, sts[0]->input, input_frame ); +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arr16( data_f_ch0, sts[0]->input_fx, 0, input_frame ); +#endif if ( data_f_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ { mvr2r( data_f_ch1, sts[1]->input, input_frame ); +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arr16( data_f_ch1, sts[1]->input_fx, 0, input_frame ); +#endif } /*----------------------------------------------------------------* @@ -484,10 +492,17 @@ ivas_error ivas_cpe_enc( for ( n = 0; n < n_CoreChannels; n++ ) { +#ifdef IVAS_FLOAT_FIXED + error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], + &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], + realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], + fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); +#else error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index e983df322..cca282ff9 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -65,6 +65,9 @@ ivas_error ivas_enc( BSTR_ENC_HANDLE hMetaData; int16_t nb_bits_metadata[MAX_SCE + 1]; float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; +#ifdef IVAS_FLOAT_FIXED + Word16 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; +#endif int32_t ivas_total_brate; ivas_error error; error = IVAS_ERR_OK; @@ -113,7 +116,30 @@ ivas_error ivas_enc( set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); } } +#ifdef IVAS_FLOAT_FIXED + FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + data_fx[n] = st_ivas->p_data_fx[n]; + } + n = 0; + WHILE( n < nchan_inp ) + { + FOR( i = 0; i < n_samples_chan; i++ ) + { + data_fx[n][i] = (Word16) ( data[i * nchan_inp + n] ); + } + n++; + } + + IF( n_samples_chan < input_frame ) + { + FOR( n = 0; n < nchan_inp; n++ ) + { + set16_fx( data_fx[n] + n_samples_chan, 0, input_frame - n_samples_chan ); + } + } +#endif if ( ivas_format == SBA_FORMAT ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 4bdf08e1a..dc7c49756 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -2107,6 +2107,13 @@ void ivas_destroy_enc( free( st_ivas->p_data_f[n] ); st_ivas->p_data_f[n] = NULL; } +#ifdef IVAS_FLOAT_FIXED + if ( st_ivas->p_data_fx[n] != NULL ) + { + free( st_ivas->p_data_fx[n] ); + st_ivas->p_data_fx[n] = NULL; + } +#endif } /* main IVAS handle */ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 296323cf9..96b1f2460 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -167,11 +167,17 @@ ivas_error ivas_ism_enc( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], + &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], + realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], + fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 6c2d569af..27b8e492c 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -136,7 +136,7 @@ ivas_error ivas_masa_enc_open( for ( i = 0; i < hMasa->data.num_Cldfb_instances; i++ ) { - if ( ( error = openCldfb_ivas( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 075135e41..353be1fec 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -90,7 +90,7 @@ ivas_error ivas_omasa_enc_open( hOMasa->num_Cldfb_instances = numAnalysisChannels; for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) { - if ( ( error = openCldfb_ivas( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 3e40937fb..396df4b64 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -175,12 +175,19 @@ ivas_error ivas_sce_enc( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], + &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], + realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], + fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 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->ivas_total_brate ); +#else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 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->ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index aebe83ca1..6959f9e5e 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -367,6 +367,9 @@ static void stereo_dft_enc_open( hStereoDft->win_ana_energy = (float) hStereoDft->N - hStereoDft->dft_ovl; hStereoDft->win_ana_energy += 2 * sum_f( win, hStereoDft->dft_ovl ); hStereoDft->win_ana_energy = hStereoDft->win_ana_energy / hStereoDft->NFFT; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->win_ana_energy_fx = (Word16) ( hStereoDft->win_ana_energy * ( 1 << 15 ) ); +#endif set_f( hStereoDft->output_mem_dmx_32k, 0, STEREO_DFT_OVL_32k ); hStereoDft->dft_zp = (int16_t) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 03cf7bfe2..1e97552e3 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -403,7 +403,7 @@ ivas_error stereo_memory_enc( /* allocate CLDFB for primary channel */ if ( st->cldfbAnaEnc == NULL ) { - if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -419,7 +419,7 @@ ivas_error stereo_memory_enc( if ( st->cldfbSynTd == NULL ) { - if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -553,7 +553,7 @@ ivas_error stereo_memory_enc( for ( i = 0; i < CPE_CHANNELS; i++ ) { st = hCPE->hCoreCoder[i]; - if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 8a388ca92..1c899987e 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -311,7 +311,7 @@ ivas_error stereo_set_tdm( /* allocate CLDFB ana for secondary channel */ if ( st->cldfbAnaEnc == NULL ) { - if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -325,7 +325,7 @@ ivas_error stereo_set_tdm( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/lsf_enc.c b/lib_enc/lsf_enc.c index ea07e8a1e..a9671520e 100644 --- a/lib_enc/lsf_enc.c +++ b/lib_enc/lsf_enc.c @@ -43,6 +43,9 @@ #include "prot_fx2.h" #include "basop_proto_func.h" #include "ivas_prot.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif #include "ivas_rom_com.h" #include "wmc_auto.h" diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index 3926f4a2b..1009c2bcc 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -8,9 +8,10 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "ivas_prot_fx.h" /* Function prototypes */ /*-----------------------------------------------------------------* @@ -29,8 +30,12 @@ static void lsfq_CNG_fx( BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word32 p_offset_scale1[][MAX_NO_SCALES + 1], Word32 p_offset_scale2[][MAX_NO_SCALES + 1], Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ); +static Word32 vq_lvq_lsf_enc_ivas_fx( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word16 *resq, Word16 *lsfq ); + static void lsf_mid_enc_fx( BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); +static void lsf_mid_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word32 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); + /*===========================================================================*/ /* FUNCTION : lsf_enc_fx() */ /*---------------------------------------------------------------------------*/ @@ -336,7 +341,266 @@ void lsf_enc_fx( return; } +void lsf_enc_ivas_fx( + Encoder_State *st, /* i/o: state structure */ + Word16 *lsf_new, /* o : quantized LSF vector */ + Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 Q_new ) +{ + Word16 nBits = 0; + Word16 int_fs; + Word16 force_sf = 0; + Word16 fec_lsf[M], stab, i; + Word16 no_param_lpc; + + Word16 param_lpc[NPRM_LPC_NEW]; + Word32 L_tmp; + Word16 coder_type, ppp_mode, nelp_mode; + + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, SID_1k75 ) ) + { + coder_type = INACTIVE; + move16(); + } + ELSE + { + coder_type = st->coder_type; + move16(); + } + + test(); + if ( EQ_16( coder_type, AUDIO ) && GSC_IVAS_mode > 0 ) + { + coder_type = GENERIC; + move16(); + } + + no_param_lpc = 0; + move16(); + + IF( st->Opt_SC_VBR ) + { + ppp_mode = st->hSC_VBR->ppp_mode; + nelp_mode = st->hSC_VBR->nelp_mode; + move16(); + move16(); + } + ELSE + { + ppp_mode = 0; + nelp_mode = 0; + move16(); + move16(); + } + + /* initialize */ +#if 0 + int_fs = INT_FS_16k_FX; + move16(); + if (EQ_16(L_frame, L_FRAME)) + { + int_fs = INT_FS_FX; + move16(); + } +#else + assert( st->sr_core <= 32000 ); + int_fs = extract_l( st->sr_core ); + move32(); +#endif + /* convert LSPs to LSFs */ + lsp2lsf_fx( lsp_new, lsf_new, M, int_fs ); + + /* check resonance for pitch clipping algorithm */ + gp_clip_test_lsf_fx( st->element_mode, lsf_new, st->clip_var_fx, 0 ); + + /* Find the number of bits for LSF quantization */ + nBits = 0; + move16(); + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + nBits = LSF_BITS_CNG; + move16(); + } + ELSE + { + test(); + IF( ( nelp_mode == 0 ) && ( ppp_mode == 0 ) ) + { + nBits = st->acelp_cfg.lsf_bits; + move16(); + } + ELSE IF( EQ_16( nelp_mode, 1 ) ) + { + nBits = 30; + move16(); + + if ( EQ_16( st->bwidth, NB ) ) + { + nBits = 32; + move16(); + } + } + ELSE IF( EQ_16( ppp_mode, 1 ) ) + { + nBits = 26; + move16(); + } + } + force_sf = 0; + move16(); + /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ + test(); + if ( LT_16( st->Nb_ACELP_frames, 3 ) && NE_32( st->core_brate, SID_2k40 ) ) + { + force_sf = 1; + move16(); + } + + /* in case of unstable filter in decoder FEC, choose safety-net to help FEC */ + IF( EQ_16( st->next_force_safety_net_fx, 1 ) ) + { + force_sf = 1; + move16(); + st->next_force_safety_net_fx = 0; + move16(); + } + + /*-------------------------------------------------------------------------------------* + * Frame end LSF quantization + *-------------------------------------------------------------------------------------*/ + lsf_end_enc_ivas_fx( st, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, + force_sf, param_lpc, &no_param_lpc, NULL, st->coder_type_raw, tdm_lsfQ_PCh ); + + /* convert quantized LSFs back to LSPs */ + lsf2lsp_fx( lsf_new, lsp_new, M, st->sr_core ); + + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && EQ_16( st->core, ACELP_CORE ) ) + { + /* don't use old LSF values if this is the first ACELP frame after HQ frames */ + Copy( lsf_new, st->lsf_old_fx, M ); + } + /* set seed_acelp used in UC mode */ + + test(); + IF( EQ_16( coder_type, UNVOICED ) && GT_16( st->element_mode, EVS_MONO ) ) + { + st->seed_acelp = 0; + move16(); + FOR( i = no_param_lpc - 1; i >= 0; i-- ) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st->seed_acelp = add( i_mult( add( shr( st->seed_acelp, 1 ), param_lpc[i] ), 31821 ), 13849 ); + } + } + + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-------------------------------------------------------------------------------------* + * FEC - enforce safety-net in the next frame in case of unstable filter + *-------------------------------------------------------------------------------------*/ + + IF( NE_16( st->last_L_frame, st->L_frame ) ) + { + /* FEC - in case of core switching, use old LSFs */ + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); + } + + FEC_lsf_estim_enc_fx( st, fec_lsf ); + + /* in case of FEC in decoder - calculate LSF stability */ + stab = lsf_stab_ivas_fx( lsf_new, fec_lsf, 0, st->L_frame ); + + test(); + test(); + test(); + /* If decoder FEC frame may be unstable force safety-net usage */ + IF( ( EQ_16( st->L_frame, L_FRAME16k ) ) && ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( coder_type, GENERIC ) ) ) + { + st->next_force_safety_net_fx = 1; + move16(); + } + ELSE IF( ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( st->clas, VOICED_CLAS ) || ( LT_16( st->clas, VOICED_CLAS ) && EQ_16( coder_type, AUDIO ) ) ) ) + { + st->next_force_safety_net_fx = 1; + move16(); + } + + + /* FEC - update adaptive LSF mean vector */ + FOR( i = 0; i < M; i++ ) + { + L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ + st->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ + } + + /* FEC - update LSF memories */ + Copy( st->lsfoldbfi0_fx, st->lsfoldbfi1_fx, M ); + Copy( lsf_new, st->lsfoldbfi0_fx, M ); + + + /*-------------------------------------------------------------------------------------* + * Mid-frame LSF encoding + * LSP interpolation and conversion of LSPs to A(z) + *-------------------------------------------------------------------------------------*/ + IF( st->rate_switching_reset ) + { + /*extrapolation in case of unstable LSF convert*/ + Copy( lsp_new, st->lsp_old_fx, M ); + Copy( lsf_new, st->lsf_old_fx, M ); + } + /* Mid-frame LSF encoding */ + lsf_mid_enc_ivas_fx( st->hBstr, st->acelp_cfg.mid_lsf_bits, st->sr_core, st->lsp_old_fx, lsp_new, lsp_mid, coder_type, st->bwidth, st->Bin_E_old_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); + + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && EQ_16( st->core, ACELP_CORE ) ) + { + /* don't use old LSP/LSF values if this is the first ACELP frame after HQ frames */ + Copy( lsp_mid, st->lsp_old_fx, M ); + lsp2lsf_fx( lsp_mid, st->lsf_old_fx, M, int_fs ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + test(); + IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) + { + IF( EQ_16( st->active_cnt, 1 ) ) + { + Copy( lsp_mid, st->lsp_old_fx, M ); + lsp2lsf_fx( lsp_mid, st->lsf_old_fx, M, int_fs ); + Copy( lsp_new, lsp_mid, M ); + } + /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); + } + ELSE + { + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); + } + /*------------------------------------------------------------------* + * Check LSF stability (distance between old LSFs and current LSFs) + *------------------------------------------------------------------*/ + IF( NE_32( st->core_brate, SID_2k40 ) ) + { + st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st->lsf_old_fx, 0, st->L_frame ); + } + return; +} /*-------------------------------------------------------------------* * lsfq_CNG_fx() * @@ -441,47 +705,136 @@ static void lsfq_CNG_fx( return; } -/*-------------------------------------------------------------------* - * qlsf_Mode_Select_fx() - * - * Mode selection for LSF quantizer - *-------------------------------------------------------------------*/ - - -static Word16 qlsf_Mode_Select_fx( - const Word16 *w, /* i : weighting vector Q8 */ - const Word16 *pred1, /* i : prediction vector x2.56 */ - const Word16 streaklimit, /* i : predictive streak limit Q15 */ - const Word32 op_loop_thr /* i : Open-loop Threshold */ +static void lsfq_CNG_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *lsf, /*x2.56 unquantized LSF vector */ + const Word16 *wghts, /*Q10 LSF weights */ + Word16 *qlsf /*x2.56 quantized LSF vecotor */ ) { - Word16 pred_pow2[M]; - Word32 temp32, En = 0; - Word16 safety_net; - Word16 i, cs, cl; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif + Word16 i, j, idx_cv, idx_lvq[3]; + Word32 min_dist, dist; + Word16 dd[M], ddq[M]; + const Word16 *p_cb; + Word16 first_cb, last_cb; + Word16 idx_lead_cng[2], idx_scale_cng[2]; + Word16 tmp; - /* calculate the prediction residual */ - cl = 0; + idx_cv = 0; move16(); - FOR( i = 0; i < M; i++ ) + + /* quantize first stage with 4 bits + The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF + coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 + the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains + either NB or WB LSF data. */ + IF( GT_16( lsf[M - 1], WB_LIMIT_LSF_FX ) ) /* 16kHz sampled LSF vector*/ { - cl = s_max( cl, abs_s( pred1[i] ) ); + p_cb = &CNG_SN1_fx[0]; + move16(); + first_cb = 0; + move16(); + last_cb = 6; + move16(); } - cs = norm_s( cl ); - En = 0; - move16(); - FOR( i = 0; i < M; i++ ) + ELSE /* 12.8kHz sampled LSF vector*/ { - pred_pow2[i] = shl( pred1[i], cs ); + p_cb = &CNG_SN1_fx[6 * M]; move16(); -#ifdef BASOP_NOGLOB - En = L_mac_o( En, mult( pred_pow2[i], shl_o( w[i], 2, &Overflow ) ), pred_pow2[i], &Overflow ); /* 2.56*2.56 at Q-4 */ -#else /* BASOP_NOGLOB */ - En = L_mac( En, mult( pred_pow2[i], shl( w[i], 2 ) ), pred_pow2[i] ); /* 2.56*2.56 at Q-4 */ -#endif /* BASOP_NOGLOB */ + first_cb = 6; + move16(); + last_cb = M; + move16(); + } + + + min_dist = L_add( MAXINT32, 0 ); + FOR( i = first_cb; i < last_cb; i++ ) + { + tmp = sub( *p_cb, shl( lsf[0], 1 ) ); /*x2.56 */ + dist = Mult_32_16( L_mult0( wghts[0], *p_cb ), tmp ); /*Q8 + x2.56 -Q15 + x2.56 = Q-7 + x2.56+x.256 */ + p_cb++; + FOR( j = 1; j < M; j++ ) + { + tmp = sub( *p_cb, lsf[j] ); + tmp = sub( tmp, lsf[j] ); + + dist = L_add( dist, Mult_32_16( L_mult0( wghts[j], *p_cb ), tmp ) ); + p_cb++; + } + IF( LT_32( dist, min_dist ) ) + { + min_dist = dist; + move16(); /*Q-4 */ + idx_cv = i; + move16(); + } + } + + /* calculate difference */ + FOR( i = 0; i < M; i++ ) + { + dd[i] = sub( lsf[i], CNG_SN1_fx[idx_cv * M + i] ); /*x2.56 */ + move16(); + } + + /* quantize the difference with LVQ */ + /* MSVQ_ROM to be updated */ + mslvq_cng_ivas_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts ); + + index_lvq_ivas_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, 0 ); + Vr_add( qlsf, &CNG_SN1_fx[idx_cv * M], qlsf, M ); + + /* write the VQ index to the bitstream */ + push_indice_fx( hBstr, IND_ISF_0_0, idx_cv, 4 ); + + /* write the LVQ index to the bitstream */ + push_indice_fx( hBstr, IND_ISF_0_1, idx_lvq[0], LEN_INDICE ); + push_indice_fx( hBstr, IND_ISF_0_1, idx_lvq[1], LSF_BITS_CNG - 4 - LEN_INDICE ); + + return; +} +/*-------------------------------------------------------------------* + * qlsf_Mode_Select_fx() + * + * Mode selection for LSF quantizer + *-------------------------------------------------------------------*/ + + +static Word16 qlsf_Mode_Select_fx( + const Word16 *w, /* i : weighting vector Q8 */ + const Word16 *pred1, /* i : prediction vector x2.56 */ + const Word16 streaklimit, /* i : predictive streak limit Q15 */ + const Word32 op_loop_thr /* i : Open-loop Threshold */ +) +{ + Word16 pred_pow2[M]; + Word32 temp32, En = 0; + Word16 safety_net; + Word16 i, cs, cl; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /* calculate the prediction residual */ + cl = 0; + move16(); + FOR( i = 0; i < M; i++ ) + { + cl = s_max( cl, abs_s( pred1[i] ) ); + } + cs = norm_s( cl ); + En = 0; + move16(); + FOR( i = 0; i < M; i++ ) + { + pred_pow2[i] = shl( pred1[i], cs ); + move16(); +#ifdef BASOP_NOGLOB + En = L_mac_o( En, mult( pred_pow2[i], shl_o( w[i], 2, &Overflow ) ), pred_pow2[i], &Overflow ); /* 2.56*2.56 at Q-4 */ +#else /* BASOP_NOGLOB */ + En = L_mac( En, mult( pred_pow2[i], shl( w[i], 2 ) ), pred_pow2[i] ); /* 2.56*2.56 at Q-4 */ +#endif /* BASOP_NOGLOB */ } cs = shl( cs, 1 ); @@ -543,11 +896,630 @@ static Word16 qlsf_Mode_Select_fx( /* _ (Word16*) qlsf : quantized LSFs in the cosine domain x2.56 */ /*------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void lsf_end_enc_fx( +/*------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*========================================================================*/ +void lsf_end_enc_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ + Word16 *qlsf, /* o : quantized LSF */ + const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ + const Word16 coder_type_org, /* i : coding type */ + Word16 Q_ener, /* i : Q valuen for Bin_Ener */ + Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + Word16 *lpc_param, + Word16 *no_indices, + Word16 *bits_param_lpc, + Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif +) +{ + Word16 i; + Word16 Idx0[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for safety-net quantizer */ + Word16 Idx1[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for predictive quantizer */ + Word16 indice[MAX_VQ_STAGES + 3]; /* Temp. array of indice for vector de-quantizer */ + Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ + Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; + const Word16 *Bit_alloc1 = NULL; + Word32 Err[2]; /* Quantization error for safety-net(0) and predictive(1) quantizers */ + Word16 Tmp[M]; /* Temporary target vector (mean and prediction removed) */ + Word16 pred0[M]; /* Prediction for the safety-net quantizer (usually mean) */ + Word16 pred1[M]; /* Prediction for the predictive quantizer */ + Word16 pred2[M]; /* Prediction for the predictive quantizer */ + Word16 wghts[M]; /* Weighting used for quantizer (currently GSM based) */ + Word16 stages0; /* Amount of stages used by safety-net quantizer */ + Word16 stages1; /* Amount of stages used by predictive quantizer */ + Word16 levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer */ + Word16 levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer */ + Word16 predmode; /* 0: safety-net only, 1: predictive only, 2: best of the two */ + Word16 safety_net, cumleft, num_bits; + Word16 *Idx, stages, *bits; + Word16 Tmp2[M], Tmp1[M]; + Word32 abs_threshold; /* Absolute threshold depending on signal bandwidth, that indicates + very good perceptual LSF quantization performance */ + Word16 lsfq[M * 2], resq[M * 2]; + Word16 coder_type; /* coder type (from LSF quantizer point of view) */ + Word16 nBits; /* Number of bits */ + Word16 TCQIdx0[M + 2]; /* Optimal codebook indices for VQ-TCQ quantizer */ + Word16 *TCQIdx; + Word16 tmp; + Word16 flag_1bit_gran; + BSTR_ENC_HANDLE hBstr = st->hBstr; +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + Word16 pred3[M]; + Word16 dummy, dummy_v[5]; +#endif + + flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); + + nBits = nBits_in; + move16(); + /* Update LSF coder_type for LSF quantizer for some special cases */ + test(); + test(); + test(); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) && ( st->idchan == 0 ) ) /* this bit is used only for primary channel or mono */ +#else + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) ) +#endif + { + IF( EQ_16( coder_type_raw, VOICED ) ) + { + coder_type = VOICED; + move16(); /* Reflect Inactive mode */ + if ( EQ_16( flag_1bit_gran, 1 ) ) + { + nBits = sub( nBits, 1 ); /* This is for real Generic*/ + } + } + ELSE + { + nBits = sub( nBits, 1 ); /* This is for real Generic*/ + coder_type = coder_type_org; + move16(); + } + } + ELSE + { + coder_type = coder_type_org; + move16(); + } + + /*----------------------------------------------------------------------------------- -* + * Calculate the number of stages and levels for each stage based on allowed bit budget + * Set absolute threshold for codebook-type decision logic depending on signal bandwidth + *------------------------------------------------------------------------------------ -*/ + IF( EQ_16( st->bwidth, NB ) ) + { + abs_threshold = L_add( SFNETLOWLIMIT_NB, 0 ); + } + ELSE + { + abs_threshold = L_add( SFNETLOWLIMIT_WB, 0 ); + } + /* Calculate LSF weighting coefficients */ + Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], Q_ener, lsf, wghts, (Word16) EQ_16( st->bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), st->sr_core, M ); + + /*--------------------------------------------------------------------------------* + * LSF quantization of SID frames + *--------------------------------------------------------------------------------*/ + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + lsfq_CNG_fx( hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); + sort_fx( qlsf, 0, M - 1 ); + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); + + return; + } + /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ + find_pred_mode( &predmode, coder_type, st->bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); + + /*----------------------------------------------------------------* + * Calculate number of stages and levels for each stage based on the allowed bit allocation + * (subtract one bit for LSF predictor selection) + *----------------------------------------------------------------*/ + lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); + + + /*--------------------------------------------------------------------------------* + * LSF quantization of all other frames but SID frames + * Select safety-net or predictive mode + *--------------------------------------------------------------------------------*/ + + Err[0] = MAXINT32; + move32(); + Err[1] = MAXINT32; + move32(); + /* for mem_MA update */ + FOR( i = 0; i < M; i++ ) + { + pred1[i] = add( ModeMeans_fx[mode_lvq][i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); + move16(); + } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + { + /* if secondary channel predmode is set to be > 2 */ + predmode += 3; + + tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); + } +#endif + IF( predmode == 0 ) + { + /* Subtract only mean */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Vr_subt( lsf, pred0, Tmp, M ); + + /* LVQ quantization (safety-net only) */ + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, + st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + safety_net = 1; + move16(); + st->pstreaklen_fx = 0; + move16(); /* predictive LSF quantizer streak is ended with safety-net */ + } + ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ + { + Vr_subt( lsf, pred1, Tmp1, M ); + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); + + safety_net = 0; + move16(); + } + ELSE +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) + { + if ( predmode == 2 ) +#endif + { + /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + test(); + test(); + test(); + IF( ( ( GT_16( st->pstreaklen_fx, ( STREAKLEN + 3 ) ) ) && ( EQ_16( coder_type, VOICED ) ) ) || ( ( GT_16( st->pstreaklen_fx, ( STREAKLEN ) ) ) && ( NE_16( coder_type, VOICED ) ) ) ) + { + /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ + st->streaklimit_fx = mult( st->streaklimit_fx, STREAKMULT_FX ); + move16(); + } + + IF( st->pstreaklen_fx == 0 ) + { + /* reset the consecutive AR-predictor multiplier */ + st->streaklimit_fx = 32767; /*1.0 in Q15 */ + move16(); + } + + /* VOICED_WB@16kHz */ + test(); + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) + { + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + /* subtract only mean */ + Vr_subt( lsf, pred0, Tmp, M ); + + FOR( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ); + Tmp2[i] = sub( Tmp[i], pred2[i] ); + pred2[i] = add( pred2[i], pred0[i] ); + } + + /* select safety_net or predictive */ + safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, st->streaklimit_fx, OP_LOOP_THR_HVO ); + IF( EQ_16( force_sf, 1 ) ) + { + safety_net = 1; + move16(); + } + + IF( safety_net ) + { + /* Safety-net - BC-TCQ quantization : SN */ + Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); + st->pstreaklen_fx = 0; + move16(); + } + ELSE + { + /* predictive - BC-TCQ quantization : AR */ + Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); + st->pstreaklen_fx = add( st->pstreaklen_fx, 1 ); + } + } + /* all other frames (not VOICED@16kHz) */ + ELSE + { + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + /* subtract only mean */ + Vr_subt( lsf, pred0, Tmp, M ); + + FOR( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + Tmp2[i] = sub( lsf[i], pred2[i] ); + } + + /* safety-net */ + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + /* Predictive quantizer is calculated only if it can be selected */ + test(); + IF( !force_sf || GT_32( Err[0], abs_threshold ) ) + { + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); + } + test(); + test(); + /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: + if the non-predictive (safety-net) quantization error (Err[0]) is low enough (spectral distortion is low) it is selected + or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. + or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ + IF( force_sf || LT_32( Mult_32_16( Err[0], ( st->streaklimit_fx ) ), L_add( Err[1], Mult_32_16( Err[1], PREFERSFNET_FX ) ) ) || LT_32( Err[0], abs_threshold ) ) + { + safety_net = 1; + move16(); + st->pstreaklen_fx = 0; + move16(); /* Reset the consecutive predictive frame counter */ + } + ELSE + { + safety_net = 0; + move16(); /* Increase the consecutive predictive frame counter by one */ + st->pstreaklen_fx = add( st->pstreaklen_fx, 1 ); + } + } + } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) + else /* of "if (predmode==2)" */ + { + mvr2r( ModeMeans[mode_lvq], pred0, M ); + + if ( predmode == 4 ) + { + mode_lvq_p = 9; /* force to Generic WB with AR*/ + } + + for ( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = pred0[i] + Predictors[mode_lvq_p][i] * ( st->mem_AR[i] - pred0[i] ); + Tmp[i] = lsf[i] - pred2[i]; + Tmp2[i] = lsf[i] - pred3[i]; + } + + /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + if ( st->pstreaklen > ( STREAKLEN ) ) + { + /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ + st->streaklimit *= STREAKMULT; + } + + if ( st->pstreaklen == 0 ) + { + /* reset the adaptive scaling factor */ + st->streaklimit = 1.0f; + } + + /* intra pred */ + /* use G AR pred for the intra mode (as a safety mode, this is why the indexes 0/1 are interchanged)*/ + + lsf_allocate( nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); + + Err[0] = vq_lvq_lsf_enc( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); + + if ( force_sf ) + { + safety_net = 1; /* intra-frame prediction */ + st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + } + else + { /* try also the inter frame prediction */ + + /* AR inter-frame prediction */ + lsf_allocate( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); + + + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); + + if ( Err[0] * ( st->streaklimit ) < PREFERSFNET * Err[1] ) + { + safety_net = 1; + st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + } + else + { + safety_net = 0; + ( st->pstreaklen )++; /* Increase the consecutive predictive frame counter by one */ + } + } + } + } +#endif /*--------------------------------------------------------------------------* \ + * Write indices to array \ + *--------------------------------------------------------------------------*/ + + IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->core, ACELP_CORE ) ) + { + /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ + test(); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && ( st->idchan == 0 ) ) +#else + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) ) +#endif + { + /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ + push_indice_fx( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub( coder_type, 2 ), 1 ); + } + + /* write predictor selection bit */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( GE( predmode, 2 ) ) +#else + IF( EQ_16( predmode, 2 ) ) +#endif + { + push_indice_fx( st->hBstr, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); + } + + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) + { + /* BC-TCVQ (only for VOICED@16kHz) */ + TCQIdx = &TCQIdx0[1]; + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; + FOR( i = 0; i < ( M / 2 ) + 3; i++ ) + { + push_indice_fx( hBstr, IND_LSF, TCQIdx[i], Bit_alloc1[i] ); + } + } + ELSE + { + cumleft = nBits; + move16(); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( GE( predmode, 2 ) ) +#else + IF( EQ_16( predmode, 2 ) ) +#endif + { + /* subtract predictor selection bit */ + cumleft = sub( nBits, 1 ); + } + + IF( safety_net ) + { + stages = stages0; + move16(); + Idx = Idx0; + move16(); + bits = bits0; + move16(); + } + ELSE + { + stages = stages1; + move16(); + Idx = Idx1; + move16(); + bits = bits1; + move16(); + } + + tmp = sub( stages, 1 ); + FOR( i = 0; i < tmp; i++ ) + { + indice[i] = Idx[i]; + move16(); + num_bits = bits[i]; + move16(); + cumleft -= num_bits; + move16(); + push_indice_fx( hBstr, IND_LSF, indice[i], num_bits ); + } + + WHILE( cumleft > 0 ) + { + indice[i] = Idx[i]; + move16(); + + IF( GT_16( cumleft, LEN_INDICE ) ) + { + num_bits = LEN_INDICE; + move16(); + } + ELSE + { + num_bits = cumleft; + move16(); + } + + cumleft = sub( cumleft, num_bits ); + push_indice_fx( hBstr, IND_LSF, indice[i], num_bits ); + i = add( i, 1 ); + } + } + } + ELSE + { + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) ) + { + /* BC-TCVQ (only for VOICED@16kHz) */ + /* Number of quantization indices */ + *no_indices = 10; + move16(); + FOR( i = 0; i < *no_indices; i++ ) + { + lpc_param[i] = TCQIdx0[i]; + move16(); + bits_param_lpc[i] = BC_TCVQ_BIT_ALLOC_40B[i]; + move16(); + } + } + ELSE + { + /* Number of quantization indices */ + + /* there are 31 bits */ + IF( EQ_16( safety_net, 1 ) ) + { + Idx = Idx0; + move16(); + *no_indices = add( stages0, 1 ); + FOR( i = 0; i < stages0; i++ ) + { + lpc_param[i] = Idx[i]; + move16(); + indice[i] = Idx[i]; + move16(); + bits_param_lpc[i] = bits0[i]; + move16(); + } + lpc_param[stages0] = Idx[stages0]; + move16(); + indice[stages0] = Idx[stages0]; + move16(); + tmp = sub( stages0, 1 ); + bits_param_lpc[tmp] = LEN_INDICE; + move16(); + bits_param_lpc[stages0] = sub( bits0[tmp], LEN_INDICE ); + } + ELSE + { + *no_indices = add( stages1, 1 ); + Idx = Idx1; + move16(); + FOR( i = 0; i < stages1; i++ ) + { + lpc_param[i] = ( Idx[i] ); + move16(); + indice[i] = Idx[i]; + move16(); + bits_param_lpc[i] = bits1[i]; + move16(); + } + lpc_param[stages1] = ( Idx[stages1] ); + move16(); + indice[stages1] = Idx[stages1]; + move16(); + tmp = sub( stages1, 1 ); + bits_param_lpc[tmp] = LEN_INDICE; + move16(); + bits_param_lpc[stages1] = sub( bits1[tmp], LEN_INDICE ); + } + IF( EQ_16( predmode, 2 ) ) + { + FOR( i = *no_indices; i > 0; i-- ) + { + tmp = sub( i, 1 ); + lpc_param[i] = lpc_param[tmp]; + move16(); + bits_param_lpc[i] = bits_param_lpc[tmp]; + move16(); + } + lpc_param[0] = safety_net; + move16(); /* put the safety net info on the last param */ + bits_param_lpc[0] = 1; + move16(); + *no_indices = add( *no_indices, 1 ); + } + } + } + + + /*--------------------------------------------------------------------------* + * De-quantize encoded LSF vector + *--------------------------------------------------------------------------*/ + + IF( safety_net ) + { + /* Safety-net */ + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) + { + /* BC-TCQ */ + Copy( lsfq, st->mem_MA_fx, M ); + Vr_add( lsfq, pred0, qlsf, M ); + } + ELSE + { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + { + /* intra mode*/ + vq_dec_lvq( 0, qlsf, &indice[0], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); + v_add( qlsf, pred3, qlsf, M ); + v_sub( qlsf, pred1, st->mem_MA, M ); + } + else +#endif + { + vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + Vr_add( qlsf, pred0, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); + } + } + } + ELSE + { + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) + { + /* BC-TCVQ */ + Copy( lsfq, st->mem_MA_fx, M ); + Vr_add( lsfq, pred2, qlsf, M ); + } + ELSE + { + /* LVQ */ + vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], + &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + IF( EQ_16( predmode, 1 ) ) + { + Copy( qlsf, st->mem_MA_fx, M ); + Vr_add( qlsf, pred1, qlsf, M ); + } + ELSE + { + Vr_add( qlsf, pred2, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); + } + } + } + + /* Sort the quantized vector to ascending order */ + sort_fx( qlsf, 0, M - 1 ); + + /* Verify stability by adding minimum separation */ + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); + + /* Update AR-predictor memories */ + Copy( qlsf, st->mem_AR_fx, M ); + return; +} + +void lsf_end_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ Word16 *qlsf, /* o : quantized LSF */ @@ -559,10 +1531,8 @@ void lsf_end_enc_fx( Word16 *no_indices, Word16 *bits_param_lpc, Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ -#endif ) { Word16 i; @@ -596,10 +1566,8 @@ void lsf_end_enc_fx( Word16 tmp; Word16 flag_1bit_gran; BSTR_ENC_HANDLE hBstr = st->hBstr; -#ifdef LSF_RE_USE_SECONDARY_CHANNEL Word16 pred3[M]; Word16 dummy, dummy_v[5]; -#endif flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); @@ -609,11 +1577,8 @@ void lsf_end_enc_fx( test(); test(); test(); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) && ( st->idchan == 0 ) ) /* this bit is used only for primary channel or mono */ -#else - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) ) -#endif { IF( EQ_16( coder_type_raw, VOICED ) ) { @@ -657,7 +1622,7 @@ void lsf_end_enc_fx( *--------------------------------------------------------------------------------*/ IF( EQ_32( st->core_brate, SID_2k40 ) ) { - lsfq_CNG_fx( hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); + lsfq_CNG_ivas_fx( hBstr, lsf, wghts, qlsf ); sort_fx( qlsf, 0, M - 1 ); reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); @@ -688,16 +1653,16 @@ void lsf_end_enc_fx( pred1[i] = add( ModeMeans_fx[mode_lvq][i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); move16(); } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL + /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ - if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + IF( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { /* if secondary channel predmode is set to be > 2 */ predmode += 3; - tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); + tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 ); } -#endif + IF( predmode == 0 ) { /* Subtract only mean */ @@ -705,8 +1670,7 @@ void lsf_end_enc_fx( Vr_subt( lsf, pred0, Tmp, M ); /* LVQ quantization (safety-net only) */ - Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, - st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); safety_net = 1; move16(); st->pstreaklen_fx = 0; @@ -715,19 +1679,27 @@ void lsf_end_enc_fx( ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ { Vr_subt( lsf, pred1, Tmp1, M ); - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq ); safety_net = 0; move16(); } ELSE -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) { - if ( predmode == 2 ) -#endif + IF( EQ_16( predmode, 2 ) ) { + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + + /* subtract only mean */ + Vr_subt( lsf, pred0, Tmp, M ); + + FOR( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + Tmp2[i] = sub( lsf[i], pred2[i] ); + } /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ test(); @@ -751,19 +1723,6 @@ void lsf_end_enc_fx( test(); IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt( lsf, pred0, Tmp, M ); - - FOR( i = 0; i < M; i++ ) - { - /* subtract mean and AR prediction */ - pred2[i] = mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ); - Tmp2[i] = sub( Tmp[i], pred2[i] ); - pred2[i] = add( pred2[i], pred0[i] ); - } - /* select safety_net or predictive */ safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, st->streaklimit_fx, OP_LOOP_THR_HVO ); IF( EQ_16( force_sf, 1 ) ) @@ -789,26 +1748,14 @@ void lsf_end_enc_fx( /* all other frames (not VOICED@16kHz) */ ELSE { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt( lsf, pred0, Tmp, M ); - - FOR( i = 0; i < M; i++ ) - { - /* subtract mean and AR prediction */ - pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); - Tmp2[i] = sub( lsf[i], pred2[i] ); - } - /* safety-net */ - Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); /* Predictive quantizer is calculated only if it can be selected */ test(); IF( !force_sf || GT_32( Err[0], abs_threshold ) ) { - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M] ); } test(); test(); @@ -831,97 +1778,83 @@ void lsf_end_enc_fx( } } } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) - else /* of "if (predmode==2)" */ + ELSE /* of "if (predmode==2)" */ { - mvr2r( ModeMeans[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); - if ( predmode == 4 ) + IF( EQ_16( predmode, 4 ) ) { mode_lvq_p = 9; /* force to Generic WB with AR*/ } - for ( i = 0; i < M; i++ ) + FOR( i = 0; i < M; i++ ) { /* subtract mean and AR prediction */ - pred2[i] = pred0[i] + Predictors[mode_lvq_p][i] * ( st->mem_AR[i] - pred0[i] ); - Tmp[i] = lsf[i] - pred2[i]; - Tmp2[i] = lsf[i] - pred3[i]; + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + Tmp[i] = sub( lsf[i], pred2[i] ); + Tmp2[i] = sub( lsf[i], pred3[i] ); } /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in - case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ - if ( st->pstreaklen > ( STREAKLEN ) ) + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + IF( GT_16( st->pstreaklen_fx, ( STREAKLEN ) ) ) { /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ - st->streaklimit *= STREAKMULT; + st->streaklimit_fx = mult( st->streaklimit_fx, STREAKMULT_FX ); + move16(); } - if ( st->pstreaklen == 0 ) + IF( EQ_16( st->pstreaklen_fx, 0 ) ) { /* reset the adaptive scaling factor */ - st->streaklimit = 1.0f; + st->streaklimit_fx = 32767; } /* intra pred */ /* use G AR pred for the intra mode (as a safety mode, this is why the indexes 0/1 are interchanged)*/ - lsf_allocate( nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); - - Err[0] = vq_lvq_lsf_enc( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); - - if ( force_sf ) + lsf_allocate_fx( nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); + Err[0] = vq_lvq_lsf_enc_ivas_fx( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); + IF( force_sf ) { - safety_net = 1; /* intra-frame prediction */ - st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + safety_net = 1; /* intra-frame prediction */ + st->pstreaklen_fx = 0; /* Reset the consecutive predictive frame counter */ } - else + ELSE { /* try also the inter frame prediction */ /* AR inter-frame prediction */ - lsf_allocate( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); - - - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); - - if ( Err[0] * ( st->streaklimit ) < PREFERSFNET * Err[1] ) + lsf_allocate_fx( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); + IF( LT_32( Mult_32_16( Err[0], ( st->streaklimit_fx ) ), L_add( Err[1], Mult_32_16( Err[1], PREFERSFNET_FX ) ) ) ) { safety_net = 1; - st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + st->pstreaklen_fx = 0; /* Reset the consecutive predictive frame counter */ } - else + ELSE { safety_net = 0; - ( st->pstreaklen )++; /* Increase the consecutive predictive frame counter by one */ + ( st->pstreaklen_fx )++; /* Increase the consecutive predictive frame counter by one */ } } } } -#endif /*--------------------------------------------------------------------------* \ - * Write indices to array \ - *--------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------* + * Write indices to array + *--------------------------------------------------------------------------*/ IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->core, ACELP_CORE ) ) { /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ test(); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && ( st->idchan == 0 ) ) -#else - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) ) -#endif { /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ push_indice_fx( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub( coder_type, 2 ), 1 ); } /* write predictor selection bit */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF( GE( predmode, 2 ) ) -#else - IF( EQ_16( predmode, 2 ) ) -#endif + IF( GE_16( predmode, 2 ) ) { push_indice_fx( st->hBstr, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); } @@ -941,11 +1874,7 @@ void lsf_end_enc_fx( { cumleft = nBits; move16(); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF( GE( predmode, 2 ) ) -#else - IF( EQ_16( predmode, 2 ) ) -#endif + IF( GE_16( predmode, 2 ) ) { /* subtract predictor selection bit */ cumleft = sub( nBits, 1 ); @@ -1108,20 +2037,16 @@ void lsf_end_enc_fx( } ELSE { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + IF( EQ_16( st->tdm_LRTD_flag, 0 ) && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ - vq_dec_lvq( 0, qlsf, &indice[0], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); - v_add( qlsf, pred3, qlsf, M ); - v_sub( qlsf, pred1, st->mem_MA, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); + vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages0, M, 9, levels0[stages0 - 1] ); + Vr_add( qlsf, pred3, qlsf, M ); } - else -#endif + ELSE { - vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + vq_dec_lvq_ivas_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } @@ -1139,9 +2064,7 @@ void lsf_end_enc_fx( ELSE { /* LVQ */ - vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], - &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); IF( EQ_16( predmode, 1 ) ) { Copy( qlsf, st->mem_MA_fx, M ); @@ -1166,7 +2089,6 @@ void lsf_end_enc_fx( return; } - /*-------------------------------------------------------------------* * first_VQstages() * @@ -1358,30 +2280,151 @@ static void first_VQstages( cs = add( cs, stagesVQ ); } - m = maxC; + m = maxC; + move16(); + } + + Copy( indices[1], indices_VQstage, maxC * stagesVQ ); + + return; +} + +/*--------------------------------------------------------------------------- + * vq_enc_lsf_lvq() + * + * Multi-stage VQ encoder for LSF quantization. Trained codebooks are used in initial stages + * and lattice-VQ quantization is applied on residual vector in other stages. + * + * Note: + * Compared to normal multistage VQ resulting LSF vector is reordered to ascending order before + * weighted error calculation (spectral distortion) at the final stage. + * + * Returns: + * Weighted error + *--------------------------------------------------------------------------*/ + +static Word32 vq_lvq_lsf_enc( + Word16 pred_flag, + Word16 mode, + Word16 u[], + Word16 *levels, + Word16 stages, + Word16 w[], + Word16 Idx[], + const Word16 *lsf, + const Word16 *pred, + Word32 p_offset_scale1[][MAX_NO_SCALES + 1], + Word32 p_offset_scale2[][MAX_NO_SCALES + 1], + Word16 p_no_scales[][2], + Word16 *resq, + Word16 *lsfq ) +{ + Word16 i; + const Word16 *const *cb, *cb_stage; + Word16 cand[LSFMBEST][M]; + Word16 maxC = LSFMBEST, stagesVQ; + Word16 mode_glb, j, indices_firstVQ[LSFMBEST * MAX_VQ_STAGES], c2; + Word32 e[LSFMBEST], L_tmp, L_ftmp; + Word16 quant[LSFMBEST][M], diff[M], dd[M]; + Word16 lat_cv[LSFMBEST][M]; + Word16 idx_lead[LSFMBEST][2], idx_scale[LSFMBEST][2]; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + stagesVQ = sub( stages, 1 ); + /* Codebook selection */ + IF( pred_flag == 0 ) /* safety net*/ + { + cb = &Quantizers_fx[CB_lsf[mode]]; + move16(); + mode_glb = add( offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub( levels[stagesVQ], min_lat_bits_SN_fx[mode] )] ); + } + ELSE /* predictive */ + { + cb = &Quantizers_p_fx[CB_p_lsf[mode]]; + move16(); + mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub( levels[stagesVQ], min_lat_bits_pred_fx[mode] )] ); + } + IF( stagesVQ > 0 ) + { + /* first VQ stages */ + first_VQstages( cb, u, levels, stagesVQ, w, M, MSVQ_MAXCNT, indices_firstVQ ); + } + + + FOR( i = 0; i < maxC; i++ ) + { + Copy( pred, cand[i], M ); + FOR( j = 0; j < stagesVQ; j++ ) + { + Idx[j] = indices_firstVQ[i * stagesVQ + j]; + move16(); + } + + FOR( j = 0; j < stagesVQ; j++ ) + { + cb_stage = cb[j]; + move16(); + Vr_add( cand[i], cb_stage + Idx[j] * M, cand[i], M ); + } + + /* LVQ quantization */ + Vr_subt( lsf, cand[i], dd, M ); + mslvq_fx( dd, quant[i], lat_cv[i], idx_lead[i], idx_scale[i], w, mode, mode_glb, pred_flag, p_no_scales ); + Vr_add( cand[i], quant[i], cand[i], M ); + + /* arrange the LSF candidate vector prior to selection to an ascending order*/ + sort_fx( cand[i], 0, M - 1 ); + + /* calculate the spectral distortion using weighted MSE of sorted LSF vector*/ + Vr_subt( cand[i], lsf, diff, M ); + FOR( j = 0; j < M; j++ ) + { +#ifdef BASOP_NOGLOB + diff[j] = shl_o( diff[j], 4, &Overflow ); +#else /* BASOP_NOGLOB */ + diff[j] = shl( diff[j], 4 ); +#endif /* BASOP_NOGLOB */ + move16(); + } +#ifdef BASOP_NOGLOB + L_tmp = L_mult( mult( diff[0], shl_o( w[0], 1, &Overflow ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#else + L_tmp = L_mult( mult( diff[0], shl( w[0], 1 ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#endif + FOR( j = 1; j < M; j++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac( L_tmp, mult( diff[j], shl_o( w[j], 1, &Overflow ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#else + L_tmp = L_mac( L_tmp, mult( diff[j], shl( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#endif + } + e[i] = L_tmp; + move32(); + } + + /* find the optimal candidate */ + c2 = minimum_32_fx( e, maxC, &L_ftmp ); + set16_fx( resq, 0, M ); + FOR( j = 0; j < stagesVQ; j++ ) + { + Idx[j] = indices_firstVQ[c2 * stagesVQ + j]; + move16(); + cb_stage = cb[j]; move16(); + Vr_add( resq, cb_stage + Idx[j] * M, resq, M ); } + Vr_add( resq, quant[c2], resq, M ); /* quantized prediction residual */ + Copy( cand[c2], lsfq, M ); + index_lvq_fx( lat_cv[c2], idx_lead[c2], idx_scale[c2], mode_glb, &Idx[stagesVQ], + &p_offset_scale1[0][0], &p_offset_scale2[0][0], &p_no_scales[0][0] ); - Copy( indices[1], indices_VQstage, maxC * stagesVQ ); - - return; + return e[c2]; } -/*--------------------------------------------------------------------------- - * vq_enc_lsf_lvq() - * - * Multi-stage VQ encoder for LSF quantization. Trained codebooks are used in initial stages - * and lattice-VQ quantization is applied on residual vector in other stages. - * - * Note: - * Compared to normal multistage VQ resulting LSF vector is reordered to ascending order before - * weighted error calculation (spectral distortion) at the final stage. - * - * Returns: - * Weighted error - *--------------------------------------------------------------------------*/ - -static Word32 vq_lvq_lsf_enc( +static Word32 vq_lvq_lsf_enc_ivas_fx( Word16 pred_flag, Word16 mode, Word16 u[], @@ -1391,9 +2434,6 @@ static Word32 vq_lvq_lsf_enc( Word16 Idx[], const Word16 *lsf, const Word16 *pred, - Word32 p_offset_scale1[][MAX_NO_SCALES + 1], - Word32 p_offset_scale2[][MAX_NO_SCALES + 1], - Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ) { @@ -1415,15 +2455,32 @@ static Word32 vq_lvq_lsf_enc( IF( pred_flag == 0 ) /* safety net*/ { cb = &Quantizers_fx[CB_lsf[mode]]; - move16(); - mode_glb = add( offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub( levels[stagesVQ], min_lat_bits_SN_fx[mode] )] ); + IF( LT_16( mode, 6 ) ) + { + move16(); + mode_glb = add( offset_lvq_modes_SN[mode], offset_in_lvq_mode_SN[mode][sub( levels[stagesVQ], min_lat_bits_SN[mode] )] ); + } + ELSE + { + move16(); + mode_glb = add( offset_lvq_modes_SN[mode], levels[stagesVQ] - min_lat_bits_SN[mode] ); + } } ELSE /* predictive */ { cb = &Quantizers_p_fx[CB_p_lsf[mode]]; - move16(); - mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub( levels[stagesVQ], min_lat_bits_pred_fx[mode] )] ); + IF( LT_16( mode, 6 ) || EQ_16( mode, 12 ) ) + { + move16(); + mode_glb = add( offset_lvq_modes_pred[mode], offset_in_lvq_mode_pred[mode][sub( levels[stagesVQ], min_lat_bits_pred_fx[mode] )] ); + } + ELSE + { + move16(); + mode_glb = sub( add( offset_lvq_modes_pred[mode], levels[stagesVQ] ), min_lat_bits_pred_fx[mode] ); + } } + IF( stagesVQ > 0 ) { /* first VQ stages */ @@ -1449,7 +2506,7 @@ static Word32 vq_lvq_lsf_enc( /* LVQ quantization */ Vr_subt( lsf, cand[i], dd, M ); - mslvq_fx( dd, quant[i], lat_cv[i], idx_lead[i], idx_scale[i], w, mode, mode_glb, pred_flag, p_no_scales ); + mslvq_ivas_fx( dd, quant[i], lat_cv[i], idx_lead[i], idx_scale[i], w, mode, mode_glb, pred_flag ); Vr_add( cand[i], quant[i], cand[i], M ); /* arrange the LSF candidate vector prior to selection to an ascending order*/ @@ -1496,12 +2553,10 @@ static Word32 vq_lvq_lsf_enc( } Vr_add( resq, quant[c2], resq, M ); /* quantized prediction residual */ Copy( cand[c2], lsfq, M ); - index_lvq_fx( lat_cv[c2], idx_lead[c2], idx_scale[c2], mode_glb, &Idx[stagesVQ], - &p_offset_scale1[0][0], &p_offset_scale2[0][0], &p_no_scales[0][0] ); + index_lvq_ivas_fx( lat_cv[c2], idx_lead[c2], idx_scale[c2], mode_glb, &Idx[stagesVQ], pred_flag ); return e[c2]; } - static void BcTcvq_1st_fx( Word16 x_fx[][2], /*x2.56*/ const Word16 CB_fx[][128][2], /*x2.56*/ @@ -2604,3 +3659,198 @@ static void lsf_mid_enc_fx( return; } + +static void lsf_mid_enc_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 nb_bits, /* i : number of bits */ + const Word32 int_fs, /* i : internal (ACELP) sampling frequency*/ + const Word16 qlsp0[], /* i : quantized LSPs from frame beginning*/ + const Word16 qlsp1[], /* i : quantized LSPs from frame end */ + Word16 lsp[], /* i/o: mid-frame LSP */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + Word32 Bin_Ener[], /* i : per bin log energy spectrum */ + Word16 Q_ener, /* i : Q value of Bin_ener */ + Word16 ppp_mode, + Word16 nelp_mode ) +{ + Word16 lsf[M], qlsf[M], qlsf1[M], qlsf0[M], wghts[M]; + Word32 err, err_min; + Word16 j, k, idx, size = 0; +#if 0 + Word32 Bin_Ener_mid[L_FFT/2]; +#endif + Word32 L_tmp; + Word16 tmp, k1; + const Word16 *ratio = NULL; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /* convert LSPs to LSFs */ + lsp2lsf_fx( lsp, lsf, M, int_fs ); + lsp2lsf_fx( qlsp0, qlsf0, M, int_fs ); + lsp2lsf_fx( qlsp1, qlsf1, M, int_fs ); + + /* LSF weighting */ + Unified_weighting_fx( Bin_Ener, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); + move16(); + /* codebook selection, number of bits, size of the codebook */ + test(); + IF( ppp_mode == 0 && nelp_mode == 0 ) + { + /* codebook selection */ + IF( EQ_16( coder_type, VOICED ) ) + { + SWITCH( nb_bits ) + { + case 5: + { + ratio = tbl_mid_voi_wb_5b_fx; + move16(); + BREAK; + } + case 4: + { + ratio = tbl_mid_voi_wb_4b_fx; + move16(); + BREAK; + } + case 1: + { + ratio = tbl_mid_voi_wb_1b_fx; + move16(); + BREAK; + } + } + } + ELSE IF( EQ_16( coder_type, UNVOICED ) ) + { + ratio = tbl_mid_unv_wb_5b_fx; + } + ELSE + { + /* GENERIC, TRANSITION, AUDIO and INACTIVE */ + SWITCH( nb_bits ) + { + case 5: + { + ratio = tbl_mid_gen_wb_5b_fx; + move16(); + BREAK; + } + case 4: + { + ratio = tbl_mid_gen_wb_4b_fx; + move16(); + BREAK; + } + case 2: + { + ratio = tbl_mid_gen_wb_2b_fx; + move16(); + BREAK; + } + } + } + + size = (Word16) pow2[nb_bits]; + move16(); + } + ELSE IF( EQ_16( ppp_mode, 1 ) ) + { + ratio = tbl_mid_voi_wb_1b_fx; + move16(); + nb_bits = 1; + move16(); + size = 2; + move16(); + } + ELSE IF( EQ_16( nelp_mode, 1 ) ) + { + ratio = tbl_mid_unv_wb_4b_fx; + move16(); + nb_bits = 4; + move16(); + size = 16; + move16(); + } + + /* loop over codevectors */ + err_min = MAXINT32; + move16(); + idx = 0; + move16(); + k1 = 0; + move16(); + FOR( k = 0; k < size; k++ ) + { + err = L_deposit_l( 0 ); + + FOR( j = 0; j < M; j++ ) + { + /* qlsf[j] = (1.0f - ratio[k*M+j]) * qlsf0[j] + ratio[k*M+j] * qlsf1[j]; */ + L_tmp = L_mult( sub( 0x2000, ratio[k1 + j] ), qlsf0[j] ); + L_tmp = L_mac( L_tmp, ratio[k1 + j], qlsf1[j] ); + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); + + test(); + test(); + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) + { + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + move16(); + } + + tmp = sub( lsf[j], qlsf[j] ); + /* err += wghts[j] * ftemp * ftemp; */ + /* tmp is usually very small, we can have some extra precision with very rare saturation */ +#ifdef BASOP_NOGLOB + tmp = shl_o( tmp, 4, &Overflow ); + tmp = mult_ro( tmp, tmp, &Overflow ); + err = L_mac_o( err, tmp, shl_o( wghts[j], 2, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + tmp = shl( tmp, 4 ); + tmp = mult_r( tmp, tmp ); + err = L_mac( err, tmp, shl( wghts[j], 2 ) ); +#endif + } + /* err = L_shl(err,Wscale); */ + err = Mult_32_16( err, LSF_1_OVER_256SQ ); + /* err = Mult_32_16(err,Wmult); */ + + IF( LT_32( err, err_min ) ) + { + err_min = L_add( err, 0 ); + idx = k; + move16(); + } + k1 += M; + move16(); + } + + /* calculate the quantized LSF vector */ + FOR( j = 0; j < M; j++ ) + { + /* qlsf[j] = (1.0f - ratio[idx*M+j]) * qlsf0[j] + ratio[idx*M+j] * qlsf1[j]; */ + L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); + L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); + + test(); + test(); + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) + { + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + move16(); + } + } + + reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, int_fs ); + + /* convert LSFs back to LSPs */ + lsf2lsp_fx( qlsf, lsp, M, int_fs ); + push_indice_fx( hBstr, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); + + return; +} diff --git a/lib_enc/mslvq_enc_fx.c b/lib_enc/mslvq_enc_fx.c index b68315506..ea953ebd5 100644 --- a/lib_enc/mslvq_enc_fx.c +++ b/lib_enc/mslvq_enc_fx.c @@ -7,6 +7,8 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" +#include "prot.h" /* Function prototypes */ +#include "basop32.h" /* Function prototypes */ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -17,6 +19,7 @@ *-----------------------------------------------------------------*/ static Word32 quantize_data_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, Word16 no_scales, const Word16 *no_lead ); +static Word32 quantize_data_ivas_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, const Word16 *no_lead ); static Word32 q_data_fx( Word16 *pTmp1, const Word16 *w1, Word16 *quant, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *p_sigma, const Word16 *p_inv_sigma, const Word16 *p_scales, Word16 *p_no_scales, const Word16 *p_no_lead ); static void prepare_data_fx( Word16 *xsort, Word16 *sign, Word16 *data, Word32 *w, const Word16 *w_in, const Word16 *sigma, const Word16 *inv_sigma, Word16 *p_sig ); static Word32 calculate_min_dist_fx( Word16 cv_pot[LATTICE_DIM], Word16 no_scales, const Word16 *scale, const Word32 *w, Word16 *p_best_scale, Word16 *p_best_idx, const Word16 *no_leaders, Word16 sig, Word16 *indx ); @@ -86,6 +89,122 @@ Word32 mslvq_fx( return dist; } + +Word32 mslvq_ivas_fx( + Word16 *pTmp, /* i : M-dimensional input vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + Word16 *w, /* i : weights for LSF quantization Q10*/ + Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + Word16 mode_glb, /* i : LVQ coding mode */ + Word16 pred_flag /* i : prediction flag (0: safety net, 1,2 - predictive )*/ +) +{ + Word32 dist, L_tmp; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + Word16 p_no_lead[MAX_NO_SCALES * 2]; + Word16 tmp, tmp1, i; + + dist = L_deposit_l( 0 ); + move16(); + + IF( EQ_16( pred_flag, 0 ) ) + { + p_sigma = sigma_MSLVQ_fx[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; + p_scales = scales_ivas_fx[mode_glb]; + tmp = no_lead_idx[mode_glb][0]; + tmp1 = no_lead_idx[mode_glb][1]; + IF( LE_16( tmp, LIMIT_LEADER ) && ( LT_16( tmp, sub( tmp1, 2 ) ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = leaders_short[tmp][i]; + p_no_lead[i + MAX_NO_SCALES] = leaders_short[tmp1][i]; + } + } + ELSE + { + IF( GE_16( pred_flag, 5 ) ) + { + /* assert( pred_flag >= 12 && pred_flag <= 15 ); */ + /* pred_flag is here the number of bits for MSLVQ */ + + p_sigma = &sigma_BWE16_fx[mode_glb * LATTICE_DIM]; + + /* inverse sigma is precomputed to save complexity */ +#if 1 // Pointing to wrong table, due to warning + p_inv_sigma = &sigma_BWE16_fx[mode_glb * LATTICE_DIM]; +#endif + + IF( EQ_16( mode_glb, 0 ) ) + { + p_scales = &scales_BWE_fx[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = no_lead_BWE[add( i, i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 ) )]; + } + } + ELSE + { + p_scales = &scales_BWE_3b_fx[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = no_lead_BWE_3b[add( i, i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 ) )]; + } + } + } + ELSE + { + p_sigma = sigma_p_fx[mode]; + + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_p_fx[mode]; + p_scales = scales_p_ivas_fx[mode_glb]; + + tmp = no_lead_p_idx[mode_glb][0]; + tmp1 = no_lead_p_idx[mode_glb][1]; + + IF( LE_16( tmp, LIMIT_LEADER ) && ( LT_16( tmp, sub( tmp1, 2 ) ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + + IF( EQ_16( tmp, LIMIT_LEADER ) && EQ_16( tmp1, 0 ) ) + { + tmp = add( tmp, DELTA_LEADER ); + tmp1 = add( tmp1, DELTA_LEADER ); + } + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = leaders_short[tmp][i]; + p_no_lead[i + MAX_NO_SCALES] = leaders_short[tmp1][i]; + } + } + } + + /* first subvector */ + dist = quantize_data_ivas_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, + p_sigma, p_inv_sigma, p_scales, p_no_lead ); + IF( LT_16( pred_flag, 5 ) ) + { + /* second subvector */ + L_tmp = quantize_data_ivas_fx( pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, + cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, + p_no_lead + MAX_NO_SCALES ); + + dist = L_add( dist, L_tmp ); + } + + return dist; +} /*-----------------------------------------------------------------* * q_data() * @@ -121,6 +240,33 @@ static Word32 q_data_fx( return dist; } +static Word32 q_data_ivas_fx( + Word16 *pTmp1, /* i: M-dimensional input vector x2.56 */ + const Word16 *w1, /* i: M-dimensional weight vector Q8 */ + Word16 *quant, /* o: quantized vector x2.56 */ + Word16 *cv_out, /* o: non-scaled lattice codevector x2.56 */ + Word16 *idx_lead, /* o: leader indexes for each subvector */ + Word16 *idx_scale, /* o: scale indexes for each subvector */ + const Word16 *p_sigma, /* i: standard deviation x2.56 */ + const Word16 *p_inv_sigma, /* i: inverse standard deviation Q15 */ + const Word16 *p_scales, /* i: scale values Q11 */ + const Word16 *p_no_lead /* i: number of leaders for each truncation and each subvector */ +) +{ + Word32 dist, L_tmp; + /* first subvector */ + dist = quantize_data_ivas_fx( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, + p_sigma, p_inv_sigma, p_scales, p_no_lead ); + /* second subvector */ + L_tmp = quantize_data_ivas_fx( pTmp1 + LATTICE_DIM, w1 + LATTICE_DIM, + quant + LATTICE_DIM, cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, + p_no_lead + MAX_NO_SCALES ); + + dist = L_add( dist, L_tmp ); + + return dist; +} /*-----------------------------------------------------------------* * mslvq_cng() * @@ -192,6 +338,82 @@ Word32 mslvq_cng_fx( return dist; } +Word32 mslvq_cng_ivas_fx( + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional input vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w /* i : weights for LSF quantization Q10*/ +) +{ + Word32 dist; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + Word16 no_scales[2]; + Word16 mode_glb, mode, i; + Word16 pTmp1[M], w1[M]; + Word16 p_no_lead[MAX_NO_SCALES * 2]; + + dist = L_deposit_l( 0 ); + mode = add( LVQ_COD_MODES, idx_cv ); + move16(); + + /* for CNG there is only one bitrate but several lattice quantizer structures, + depending on the previous VQ stage */ + mode_glb = add( START_CNG, idx_cv ); + move16(); + + p_sigma = sigma_MSLVQ_fx[mode]; + move16(); + p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; + move16(); + p_scales = scales_fx[mode_glb]; + move16(); + + no_scales[0] = 0; + no_scales[1] = 0; + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) leaders_short[no_lead_idx[mode_glb][0]][i]; + p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[no_lead_idx[mode_glb][1]][i]; + + IF( p_scales[i] > 0 ) + { + no_scales[0] += 1; + } + IF( p_scales[i + MAX_NO_SCALES] > 0 ) + { + no_scales[1] += 1; + } + } + + /* check if LSF component permutation is needed or not */ + IF( cng_sort[idx_cv] ) + { + FOR( i = 0; i < M; i++ ) + { + pTmp1[i] = pTmp[i]; + move16(); + w1[i] = w[i]; + move16(); + } + /* sorting the quantizer input and the corresponding weights according to the specified permutations */ + permute_fx( pTmp1, perm_MSLVQ[idx_cv] ); + permute_fx( w1, perm_MSLVQ[idx_cv] ); + + dist = q_data_ivas_fx( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_lead ); + /* permute back */ + permute_fx( quant, perm_MSLVQ[idx_cv] ); + } + ELSE + { + dist = q_data_ivas_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_lead ); + } + + return dist; +} /*-----------------------------------------------------------------* * prepare_data_fx() * @@ -546,6 +768,107 @@ static Word32 quantize_data_fx( return min_dist; } +static Word32 quantize_data_ivas_fx( + Word16 *data, /* i : residual LSF data to quantize x2.56*/ + const Word16 *w_in, /* i : weights Q10*/ + Word16 *qin, /* o : quantized output (scaled) x2.56*/ + Word16 *cv_out, /* o : codevectors Q1*/ + Word16 *idx_lead, /* o : leader indexes for each subvector */ + Word16 *idx_scale, /* o : scale indexes for each subvector */ + const Word16 *sigma, /* i : standard deviation x2.56 */ + const Word16 *inv_sigma, /* i : inverse of standard deviation Q15 */ + const Word16 *scale, /* i : scales for each truncation Q11*/ + const Word16 *no_leaders /* i : number of leader vectors for each truncation of each subvector */ +) +{ + Word16 j; + Word32 w[LATTICE_DIM]; + Word32 min_dist = 0; + Word16 best_idx = 0, best_scale = -1; + Word16 s; + Word16 indx[LATTICE_DIM]; + Word16 sig, sign[LATTICE_DIM]; + Word16 cv_pot[LATTICE_DIM]; + Word16 id[8]; + Word16 smallest; + Word32 L_tmp; + + IF( scale[0] > 0 ) + { + prepare_data_fx( cv_pot, sign, data, w, w_in, sigma, inv_sigma, &sig ); + move16(); + /* sorting of the input vector based on its absolute values; indx: permutation corresponding to the sorting */ + sort_desc_ind_fx( cv_pot, LATTICE_DIM, indx ); + smallest = indx[LATTICE_DIM - 1]; + move16(); + + min_dist = calculate_min_dist_fx( cv_pot, MAX_NO_SCALES, scale, w, &best_scale, &best_idx, no_leaders, sig, indx ); + + IF( GT_16( best_scale, -1 ) ) + { + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + id[indx[j]] = j; + } + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + cv_out[j] = i_mult2( sign[j], pl_HQ_fx[best_idx * LATTICE_DIM + id[j]] ); + move16(); + } + IF( pl_par[best_idx] ) + { + IF( NE_16( sig, pl_par[best_idx] ) ) + { + cv_out[smallest] = negate( cv_out[smallest] ); + } + } + s = scale[best_scale]; + move16(); /*Q11 */ + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + /*qin[j] = s * cv_out[j] * sigma[j]; */ + L_tmp = L_mult( cv_out[j], s ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = Mult_32_16( L_tmp, shl( sigma[j], 2 ) ); /* Q13 + Q2 +x2.56 -Q15 */ + + qin[j] = extract_l( L_tmp ); /*x2.56 */ + } + *idx_lead = best_idx; + move16(); + *idx_scale = best_scale; + move16(); + } + ELSE + { + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + qin[j] = 0; + move16(); + } + + *idx_lead = best_idx; + move16(); + *idx_scale = best_scale; + move16(); + } + } + ELSE + { + *idx_lead = 0; + move16(); + *idx_scale = -1; + move16(); + + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + cv_out[j] = 0; + move16(); + qin[j] = 0; + move16(); + } + } + + return min_dist; +} /*-----------------------------------------------------------------* * sort_desc_ind() * @@ -655,7 +978,52 @@ void index_lvq_fx( return; } +void index_lvq_ivas_fx( + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i :scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + const Word16 prediction_flag ) +{ + Word32 index1, index2; + UWord32 offset_scale1[MAX_NO_SCALES + 1], offset_scale2[MAX_NO_SCALES + 1]; + Word64 idx64; + Word64 index2_64; + + index1 = 0; + move16(); + + create_offset( offset_scale1, offset_scale2, mode, prediction_flag ); + + /* for first subvector */ + IF( GT_16( idx_scale[0], -1 ) ) + { + index1 = L_add( encode_comb_fx( quant, idx_lead[0] ), L_add( table_no_cv_fx[idx_lead[0]], offset_scale1[idx_scale[0]] ) ); + } + + /* for second subvector */ + index2 = L_deposit_l( 0 ); + + IF( GT_16( idx_scale[1], -1 ) ) + { + index2 = L_add( encode_comb_fx( &quant[LATTICE_DIM], idx_lead[1] ), L_add( table_no_cv_fx[idx_lead[1]], offset_scale2[idx_scale[1]] ) ); + } + idx64 = W_mult0_32_32( index1, offset_scale2[MAX_NO_SCALES] ); + index2_64 = W_deposit32_l( index2 ); + idx64 = W_add_nosat( idx64, index2_64 ); + + /* convert to 3 short */ + index[0] = ( ( idx64 ) & ( 0x7fff ) ); + move16(); + index[1] = ( idx64 >> 15 ) & ( 0x7fff ); + move16(); + index[2] = ( idx64 >> 30 ) & ( 0x7fff ); + move16(); + + return; +} /*-----------------------------------------------------------------* * encode_comb() * diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index da9e0f0d3..855d25ce5 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -348,7 +348,7 @@ void noise_est_pre_fx( test(); test(); test(); - IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_16( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_16( sub( hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) + IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_16( sub_sat( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_16( sub_sat( hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) { /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ hNoiseEst->Etot_l_lp_fx = mac_r( L_mult( 983, hNoiseEst->Etot_l_fx ), 31785, hNoiseEst->Etot_l_lp_fx ); @@ -361,13 +361,116 @@ void noise_est_pre_fx( } } /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ - hNoiseEst->sign_dyn_lp_fx = round_fx( L_mac( L_mult( 3277, sub( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx ) ), 29491, hNoiseEst->sign_dyn_lp_fx ) ); + hNoiseEst->sign_dyn_lp_fx = round_fx( L_mac( L_mult( 3277, sub_sat( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx ) ), 29491, hNoiseEst->sign_dyn_lp_fx ) ); } return; } +void noise_est_pre_32fx( + const Word32 Etot, /* i : Energy of current frame */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const int16_t idchan, /* i : channel ID */ + const int16_t element_mode, /* i : element mode */ + const int16_t last_element_mode /* i : last element mode */ +) +{ + Word32 tmp; + + IF( LE_16( ini_frame_fx, 1 ) || ( EQ_16( idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) + { + hNoiseEst->Etot_h_32fx = Etot; + move16(); + hNoiseEst->Etot_l_32fx = Etot; + move16(); + hNoiseEst->Etot_l_lp_32fx = Etot; + move16(); + hNoiseEst->Etot_last_32fx = Etot; + move16(); + hNoiseEst->Etot_v_h2_32fx = 0; + move16(); + hNoiseEst->Etot_lp_32fx = Etot; + move16(); + hNoiseEst->sign_dyn_lp_32fx = 0; + move16(); + } + ELSE + { + /* *Etot_lp = 0.20f*Etot + 0.80f* *Etot_lp; */ + hNoiseEst->Etot_lp_32fx = L_add( Mpy_32_32( 429496730, Etot ), Mpy_32_32( 1717986918, hNoiseEst->Etot_lp_32fx ) ); + move16(); + + hNoiseEst->Etot_h_32fx = L_sub( hNoiseEst->Etot_h_32fx, 671089 ); + move16(); /* 10=0.04 in Q8 */ + hNoiseEst->Etot_h_32fx = L_max( hNoiseEst->Etot_h_32fx, Etot ); + move16(); + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, 1342177 ); + move16(); /* 20 = .08 in Q8 */ + + + /* Could even be higher but it also delays first entry to DTX */ + IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) ) + { + test(); + IF( ( LT_16( ini_frame_fx, s_min( HE_LT_CNT_INIT_FX, MAX_FRAME_COUNTER - 1 ) ) ) && ( LT_32( L_sub( hNoiseEst->Etot_h_32fx, hNoiseEst->Etot_lp_32fx ), (Word32) 3 * 16777216 ) ) /* 3.0 Q8 */ + ) + { + /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */ + tmp = Mpy_32_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 214748365 ); /* factor in Q15 3277 .1*32768 */ + tmp = L_min( 33554432, tmp ); /* 2.0 in Q8 is 512*/ + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, tmp ); + move16(); /* Q8 */ + } + /* Avoids large steps in short active segments */ + test(); + IF( ( GT_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) /* 30.0f*Q8 */ + && ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_SHORT_FX ) ) ) + { + /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */ + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, Mpy_32_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 42949673 ) ); + move16(); /* 0.02 = 655 Q8*/ + } + ELSE IF( GT_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 167772160 ) ) /* 10.0 in Q8*/ + { + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, 1342177 ); + move16(); /* 0.08 is 20 in Q8*/ + } + } + + hNoiseEst->Etot_l_32fx = L_min( hNoiseEst->Etot_l_32fx, Etot ); + + IF( LT_16( ini_frame_fx, 100 ) && LT_32( hNoiseEst->Etot_l_32fx, hNoiseEst->Etot_l_lp_32fx ) ) + { + /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */ + hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 214748364, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 1932735283, hNoiseEst->Etot_l_lp_32fx ) ); + move16(); + } + ELSE + { + test(); + test(); + test(); + test(); + IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_32( L_sub_sat( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_32( L_sub_sat( hNoiseEst->Etot_l_lp_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) ) + { + /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ + hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 64424509, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 2083059139, hNoiseEst->Etot_l_lp_32fx ) ); + move16(); + } + ELSE + { + /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */ + hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 42949673, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 2104533975, hNoiseEst->Etot_l_lp_32fx ) ); + } + } + /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ + hNoiseEst->sign_dyn_lp_32fx = L_add( Mpy_32_32( 214748365, L_sub_sat( hNoiseEst->Etot_h_32fx, hNoiseEst->Etot_l_32fx ) ), Mpy_32_32( 1932735283, hNoiseEst->sign_dyn_lp_32fx ) ); + } + + return; +} /*==================================================================================*/ /* FUNCTION : noise_est_down_fx() */ /*----------------------------------------------------------------------------------*/ diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index f76dd3e08..76a128110 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -211,8 +211,8 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ), &Q_new_inp, &mem_decim_size ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* @@ -1018,7 +1018,7 @@ void pre_proc_fx( } ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0 ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0, &Q_new_inp, &mem_decim_size ); } ELSE /* keep memories up-to-date in case of bitrate switching */ { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 9ad638274..b05dfcce2 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -306,6 +306,16 @@ void noise_est_pre_fx( ); +void noise_est_pre_32fx( + const Word32 Etot, /* i : Energy of current frame */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const Word16 idchan, /* i : channel ID */ + const Word16 element_mode, /* i : element mode */ + const Word16 last_element_mode /* i : last element mode */ + +); + void pitch_ol2_fx( const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ const Word16 pitch_ol, /* i : pitch to be improved */ @@ -558,6 +568,22 @@ Word16 wb_vad_fx( Word16 lp_noise /* i : long term noise energy */ ); +Word16 wb_vad_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Q_new+QSCALE*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + 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, + Word8 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech, /* i : long term active speech energy average */ + Word16 lp_noise /* i : long term noise energy */ +); + Word32 construct_snr_thresh_fx( Word16 sp_center[], /*(i) spectral center*/ Word32 snr_flux, /*(i) snr flux*/ Word32 lt_snr, /*(i) long time time domain snr*/ @@ -636,6 +662,21 @@ void lsf_end_enc_fx( #endif ); +void lsf_end_enc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ + Word16 *qlsf, /* o : quantized LSF */ + const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ + const Word16 coder_type_org, /* i : coding type */ + Word16 Q_ener, /* i : Q valuen for Bin_Ener */ + Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + Word16 *lpc_param, + Word16 *no_indices, + Word16 *bits_param_lpc, + Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +); void Mode2_abs_pit_enc_fx( Word16 T0, /* i : integer pitch lag */ Word16 T0_frac, /* i : pitch fraction */ @@ -1229,6 +1270,16 @@ void lsf_enc_fx( #endif const Word16 Q_new ); +void lsf_enc_ivas_fx( + Encoder_State *st, /* i/o: state structure */ + Word16 *lsf_new, /* o : quantized LSF vector */ + Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 Q_new ); void Es_pred_enc_fx( Word16 *Es_pred, /* o : predicited scaled innovation energy Q8 */ Word16 *indice, /* o : indice of quantization */ @@ -1315,6 +1366,15 @@ void perform_noise_estimation_enc_fx( Word16 enerBuffer_exp, HANDLE_FD_CNG_ENC st ); /* i/o: FD_CNG structure containing all buffers and variables */ +void perform_noise_estimation_enc_ivas_fx( Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word16 band_energies_exp, /* i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word32 *enerBuffer, + Word16 enerBuffer_exp, + HANDLE_FD_CNG_ENC st, /* i/o: FD_CNG structure containing all buffers and variables */ + const int32_t input_Fs, /* i : input sampling rate */ + CPE_ENC_HANDLE hCPE /* i : CPE encoder structure */ +); + /* Adjust the noise estimator at the beginning of each CNG phase (encoder-side) */ Word16 AdjustFirstSID_fx( Word16 npart, @@ -3029,6 +3089,16 @@ Word32 mslvq_cng_fx( const Word16 *w, /* i : weights for LSF quantization Q10*/ Word16 *no_scales ); +Word32 mslvq_cng_ivas_fx( + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional i vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w /* i : weights for LSF quantization Q10*/ +); + void Unified_weighting_fx( const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, @@ -3061,6 +3131,18 @@ Word32 mslvq_fx( Word16 pred_flag, /* i : prediction flag (0: safety net, 1 - predictive )*/ Word16 no_scales[][2] ); +Word32 mslvq_ivas_fx( + Word16 *pTmp, /* i : M-dimensional i vector */ + Word16 *quant, /* o : quantized vector */ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + Word16 *w, /* i : weights for LSF quantization */ + Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + Word16 mode_glb, /* i : LVQ coding mode */ + Word16 pred_flag /* i : prediction flag (0: safety net, 1 - predictive )*/ +); + Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ @@ -3216,6 +3298,14 @@ void index_lvq_fx( Word32 *p_offset_scale2, Word16 *p_no_scales ); +void index_lvq_ivas_fx( + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i : scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + const Word16 prediction_flag ); + ivas_error init_encoder_fx( Encoder_State *st_fx /* i/o: Encoder static variables structure */ ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 6ab6aae6c..9bc9d5393 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -775,6 +775,13 @@ typedef struct noise_estimation_structure Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ Word16 Etot_last_fx; /*Q8*/ Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ + + Word32 Etot_l_32fx; /* Q8 Noise estimator - Track energy from below */ + Word32 Etot_h_32fx; /* Q8 Noise estimator - Track energy from above */ + Word32 Etot_l_lp_32fx; /* Q8 Noise estimator - Smoothed low energy */ + Word32 Etot_last_32fx; /*Q8*/ + Word32 Etot_lp_32fx; /* Q8 Noise estimator - Filtered input energy */ + Word16 lt_tn_track_fx; /* Q15 */ Word16 lt_tn_dist_fx; /* Q8*/ Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ @@ -800,6 +807,10 @@ typedef struct noise_estimation_structure float Etot_sq_st_est; /* Noise estimation - short term estimate of E{ Etot^2 } */ Word16 Etot_v_h2_fx; Word16 sign_dyn_lp_fx; /*Q8*/ + + Word32 Etot_v_h2_32fx; + Word32 sign_dyn_lp_32fx; /*Q8*/ + Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ @@ -2267,10 +2278,10 @@ typedef struct enc_core_structure float mem_preemph16k_DFT; float inp_16k_mem_stereo_sw[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; - Word32 mem_preemph_DFT_fx; - Word32 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; - Word32 mem_preemph16k_DFT_fx; - Word32 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; + Word16 mem_preemph_DFT_fx; + Word16 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; + Word16 mem_preemph16k_DFT_fx; + Word16 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; /* MCT Channel mode indication: LFE, ignore channel? */ MCT_CHAN_MODE mct_chan_mode; diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 58c70edae..56756588c 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -1685,6 +1685,1242 @@ Word16 wb_vad_fx( } + 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 ); + } + + hVAD->vad_prim_reg = L_shl( L_and( hVAD->vad_prim_reg, (Word32) 0x3fffffffL ), 1 ); + + IF( st_fx->localVAD != 0 ) + { + hVAD->vad_prim_reg = L_or( hVAD->vad_prim_reg, 0x01L ); + hVAD->vad_prim_cnt_16 = add( hVAD->vad_prim_cnt_16, 1 ); + } + + return flag; +} + +Word16 wb_vad_ivas_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*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + 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, + Word8 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + 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 */ + Word16 lp_noise_fx /* i : long term noise energy */ +) +{ + Word16 i, flag = 0, hangover_short; + + Word16 snr_sum, thr1 = 0, thr1_nb_mod, thr2 = 0, nk = 0, nc = 0, th_clean = 0; + Word16 lp_snr; /* Q8 */ + const Word32 *pt1; + const Word32 *pt2; + const Word32 *pt3; + + Word16 min_snr, sign_thr; + + Word32 L_snr, L_snr_sum; + Word32 ftmp, ftmp1, ftmp2; + Word16 m_noise_local, e_noise, e_num, m_num, snr, snr_tmp, shift_snr; + + Word16 snr_sumt; + Word32 L_vad_thr; + Word16 hangover_hd; + Word16 snr_idx; + Word16 delta1, delta2, delta3, delta4; + + Word16 flag_he1; + Word16 stmp; + Word32 L_msnr, L_mssnr = 0, L_mssnr_hov; + Word16 j, tmp, tmp1, tmp2; + Word32 L_tmp, L_tmp1, L_tmp2; + + Word32 L_snr18, L_snr19; /* Q4 */ + Word32 L_msnr18, L_msnr19; /* Q13 */ + Word16 nb_sig_snr; /* Q0 */ + + Word16 nv; + Word16 nv_ofs; /* Q8 */ + Word32 L_snr_sum_HE_SAD; /* Q4 */ + 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 */ + + Word32 L_snr_outlier; + Word16 snr_outlier_index; + Word32 L_accum_ener_L; + Word32 L_accum_ener_H; + Word16 vad_bwidth_fx; + Word16 last_7k2_coder_type; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + if ( hNoiseEst == NULL ) + { + hNoiseEst = st_fx->hNoiseEst; + move16(); + } + + if ( hVAD == NULL ) + { + move16(); + hVAD = st_fx->hVAD; + } + if ( LT_16( lp_speech_fx, -100 * 256 ) ) + { + lp_speech_fx = st_fx->lp_speech_fx; + move16(); + } + + if ( LT_16( lp_noise_fx, -100 * 256 ) ) + { + lp_noise_fx = st_fx->lp_noise_fx; + move16(); + } + + vad_bwidth_fx = st_fx->input_bwidth; + move16(); + + L_snr_outlier = L_deposit_l( 0 ); + snr_outlier_index = 0; + move16(); + L_accum_ener_L = L_deposit_l( 0 ); + L_accum_ener_H = L_deposit_l( 0 ); + + L_snr18 = L_deposit_l( 0 ); /* Q4*/ + L_snr19 = L_deposit_l( 0 ); /* Q4 */ + L_msnr18 = L_deposit_l( 8192 ); /* 1.0 Q13*/ + L_msnr19 = L_deposit_l( 8192 ); /* 1.0 Q13 */ + + + IF( EQ_16( vad_bwidth_fx, NB ) ) + { + st_fx->min_band = 1; + move16(); + st_fx->max_band = 16; + move16(); + } + ELSE + { + st_fx->min_band = 0; + move16(); + st_fx->max_band = 19; + move16(); + } + + IF( st_fx->Opt_SC_VBR ) + { + last_7k2_coder_type = st_fx->hSC_VBR->last_7k2_coder_type; + move16(); + } + ELSE + { + 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 */ + { + nk = 3277; + move16(); /*0.1 Q15 */ + nc = 4122; + move16(); /*16.1 Q8 */ + nv = 525; + move16(); /* 2.05 Q8*/ + nv_ofs = 422; + move16(); /* 1.65 Q8*/ + th_clean = TH16_2_FX; + move16(); /* 35 Q8 */ + sign_thr = 21; + move16(); /*1.3 Q4 */ + tmp = sub( vad_bwidth_fx, WB ); + if ( tmp != 0 ) + { + sign_thr = 28; + move16(); /*1.75f; Q4 SWB */ + } + min_snr = 13; + move16(); /*0.8 Q4 WB */ + if ( tmp != 0 ) + { + min_snr = 4; + move16(); /*0.25f; Q4 SWB */ + } + + sign_thr_HE_SAD = 40; + move16(); /* 2.5f Q4 */ + ; + min_snr_HE_SAD = 3; + move16(); /* 0.2f Q4 */ + ; + } + ELSE /* NB input */ + { + move16(); + nk = 3277; + move16(); /* 0.1 Q15 */ + nc = 4096; + move16(); /* 16.0 Q8 */ + nv = 1024; + move16(); /* 4.0 Q8 */ + nv_ofs = 294; + move16(); /*1.15 Q8*/ + th_clean = TH8_1_FX; + move16(); /*20 Q8 */ + sign_thr = 28; + move16(); /* 1.75 * Q4 SIGN_THR */ + min_snr = 4; + 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 + *---------------------------------------------------------------------*/ + + lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8 */ + + snr_idx = 2; + move16(); + if ( GT_16( lp_snr, 4608 ) ) /*18.0 Q8*/ + { + snr_idx = 1; + move16(); + } + if ( GT_16( lp_snr, 6144 ) ) /*24.0 Q8*/ + { + snr_idx = 0; + move16(); + } + + + IF( snr_idx == 0 ) + { + stmp = 6; + move16(); + delta1 = 0; + move16(); /*0.0f in Q13 */ + delta2 = 0; + move16(); /*0.0f in Q13 */ + delta3 = 0; + move16(); /*0.0f in Q13 */ + delta4 = 0; + move16(); + + + /*vad_thr = 2.4f*lp_snr - 42.2f; + vad_thr = min(vad_thr, 80 ); */ + + L_vad_thr = -345702; + move32(); /* -42.2 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 77, lp_snr ); /* (2.4)Q5*(lp_snr)Q8 */ + L_vad_thr = L_min( L_vad_thr, 80 * ( 1 << 13 ) ); + } + ELSE IF( EQ_16( snr_idx, 1 ) ) + { + stmp = 6; + move16(); + delta1 = 819; + move16(); /*0.1f in Q13 */ + delta2 = 1638; + move16(); /*0.2f in Q13 */ + delta3 = 1638; + move16(); /*0.2f in Q13 */ + delta4 = 1638; + move16(); /*0.2f in Q13 */ + + /* vad_thr = 2.4f*lp_snr - 40.2f; + vad_thr = min(vad_thr, 80); + */ + L_vad_thr = -329318; + move32(); /* -40.2 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 77, lp_snr ); /* (2.4)Q5*(lp_snr)Q8 */ + L_vad_thr = L_min( L_vad_thr, 80 * ( 1 << 13 ) ); + } + ELSE + { + stmp = 9; + move16(); + delta1 = 1638; + move16(); /*0.2f in Q13 */ + delta2 = 3277; + move16(); /*0.4f in Q13 */ + delta3 = 2458; + move16(); /*0.3f in Q13 */ + delta4 = 3277; + move16(); /*0.4f in Q13 */ + /* vad_thr = 2.5f*lp_snr - 10.0f; + vad_thr = max(vad_thr, 1); + */ + L_vad_thr = -81920; + move32(); /* -10 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 80, lp_snr ); /* (2.5)Q5*(lp_snr)Q8 */ + L_vad_thr = L_max( L_vad_thr, 1 * ( 1 << 13 ) ); + } + + nb_sig_snr = 20; + move16(); + + pt1 = fr_bands; + pt2 = fr_bands + NB_BANDS; + pt3 = hNoiseEst->bckr_fx; + + L_snr_sum = L_deposit_l( 0 ); + L_snr_sum_HE_SAD = L_deposit_l( 0 ); + snr_sumt = 0; + move16(); + L_mssnr_hov = L_deposit_l( 0 ); + *snr_sum_he = 0; + move16(); + snr_sum_HE_SAD = 0; + move16(); + + + FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) + { + ftmp = L_add( *pt1++, 0 ); + ftmp1 = L_add( *pt2++, 0 ); + ftmp2 = L_add( *pt3++, 0 ); + + /*fr_enr = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 );*/ + L_tmp = Mult_32_16( hNoiseEst->enrO_fx[i], 13107 ); /* L_tmp(high word) = Qenr0fx*Q16+1 -16 -> Qener0+1 */ + L_tmp1 = Madd_32_16( L_tmp, ftmp, 26214 ); /* 26214 = .4 in Q16 */ + L_tmp1 = Madd_32_16( L_tmp1, ftmp1, 26214 ); /* L_tmp1 re_used a bit later for final snr[i]*/ + + L_tmp2 = Madd_32_16( L_tmp, ftmp, 19661 ); /* 19661 = 0.3 in Q16 */ + L_tmp2 = Msub_32_16( L_tmp2, ftmp1, -32768 ); /* -32768= -0.5 in Q16 */ + + IF( GT_32( ftmp, ftmp1 ) ) + { + /*snr[i] = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ) / ftmp2 ;*/ + /*snr[i] = L_tmp1/(ftmp2) */ + IF( ftmp2 != 0 ) + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + e_noise = norm_l( ftmp2 ); + m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, m_noise_local ); +#ifdef BASOP_NOGLOB + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + /* if bckr[i] == 0; approx. L_snr */ + e_noise = add( 30 + 1, abs_s( Q_new ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /*L_snr in Q4*/ + } + } + ELSE + { + /*snr[i] = ( 0.2f * st->enrO[i] + 0.3f * ftmp + 0.5f * ftmp1 ) / ftmp2 ;*/ + /*snr[i] =L_tmp2/( ftmp2 ) */ + IF( ftmp2 != 0 ) + { + e_num = norm_l( L_tmp2 ); + m_num = extract_h( L_shl( L_tmp2, e_num ) ); + + e_noise = norm_l( ftmp2 ); + m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, m_noise_local ); +#ifdef BASOP_NOGLOB + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { + e_num = norm_l( L_tmp2 ); + m_num = extract_h( L_shl( L_tmp2, e_num ) ); + + /* if bckr[i] == 0; approx. L_snr */ + e_noise = add( 30 + 1, abs_s( Q_new ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /*L_snr in Q4*/ + } + } + + if ( LT_32( L_snr, 2 * ( 1 << 4 ) ) ) + { + nb_sig_snr = sub( nb_sig_snr, 1 ); /* nb_sig_snr--; */ + } + 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 */ + + +#ifdef BASOP_NOGLOB + tmp = shl_o( snr, 5, &Overflow ); /* Q8 -> Q13 */ +#else /* BASOP_NOGLOB */ + tmp = shl( snr, 5 ); /* Q8 -> Q13 */ +#endif /* BASOP_NOGLOB */ + IF( LT_16( i, 2 ) ) + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta1, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta1 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + ELSE IF( LT_16( i, 7 ) ) + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta2, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta2 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + ELSE IF( LT_16( i, 18 ) ) + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta3, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta3 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta4, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta4 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + + tmp1 = tmp; + move16(); /* ftmp1 = ftmp; */ + sub( 0, 0 ); + if ( i < 7 ) + { +#ifdef BASOP_NOGLOB + tmp1 = add_o( tmp, 3277, &Overflow ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#else /* BASOP_NOGLOB */ + tmp1 = add( tmp, 3277 ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#endif /* BASOP_NOGLOB */ + } + + tmp = s_min( tmp, 16384 ); /* Q13, ftmp = min(ftmp, 2.0f); */ + tmp1 = s_min( tmp1, 16384 ); /* Q13, ftmp1 = min(ftmp1, 2.0f); */ + + L_msnr = L_deposit_l( tmp ); /*msnr = 1*tmp;*/ + FOR( j = 1; j < stmp; j++ ) + { + /* Q13*Q13 +1 -16 +2 = Q13 */ + L_msnr = L_shl( Mult_32_16( L_msnr, tmp ), 2 ); /*Q13 , msnr *= ftmp;*/ + } + L_mssnr = L_add( L_mssnr, L_msnr ); /*Q13 mssnr += msnr;*/ + + if ( EQ_16( i, 18 ) ) + { + L_msnr18 = L_add( L_msnr, 0 ); /*Q13 msnr18 = msnr; */ + } + + if ( EQ_16( i, 19 ) ) + { + L_msnr19 = L_add( L_msnr, 0 ); /* Q13 , msnr19 = msnr; */ + } + + L_msnr = L_deposit_l( tmp1 ); /* Q13, msnr = 1*tmp1 ;*/ + + FOR( j = 1; j < stmp; j++ ) + { + L_msnr = L_shl( Mult_32_16( L_msnr, tmp1 ), 2 ); /*Q13 msnr *= ftmp1;*/ + } + L_mssnr_hov = L_add( L_mssnr_hov, L_msnr ); /*Q13 mssnr_hov += msnr; */ + + /* recompute after he1 modifications */ + /* snr[i] = fr_enr / st->bckr[i] = L_tmp1/st->bckr[i];*/ + IF( hNoiseEst->bckr_fx[i] != 0 ) + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + e_noise = norm_l( hNoiseEst->bckr_fx[i] ); + m_noise_local = extract_h( L_shl( hNoiseEst->bckr_fx[i], e_noise ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, m_noise_local ); +#ifdef BASOP_NOGLOB + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + /* if bckr[i] == 0; approx. L_snr */ + e_noise = add( 30 + 1, abs_s( Q_new ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /*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 ); + + L_snr = L_max( L_snr, 16 ); /*Q4, if( snr[i] < 1.0f ) { snr[i] = 1.0f;} */ + + /* float saves all snrs in an snr[] vector , + in fix we only save two bands */ + if ( EQ_16( i, 18 ) ) + { + L_snr18 = L_add( L_snr, 0 ); /*Q4 */ + } + if ( EQ_16( i, 19 ) ) + { + L_snr19 = L_add( L_snr, 0 ); /* Q4 */ + } + + /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ + IF( LT_16( i, 3 ) ) + { +#ifdef BASOP_NOGLOB + L_accum_ener_L = L_add_o( L_accum_ener_L, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#else + L_accum_ener_L = L_add( L_accum_ener_L, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ +#endif + } + ELSE + { +#ifdef BASOP_NOGLOB + L_accum_ener_H = L_add_o( L_accum_ener_H, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#else + L_accum_ener_H = L_add( L_accum_ener_H, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ +#endif + } + + /* Identify the outlier band */ + IF( GT_32( L_snr, L_snr_outlier ) ) + { + L_snr_outlier = L_add( L_snr, 0 ); /*Q4*/ + snr_outlier_index = i; + move16(); + } + } /* end of band loop */ + + test(); + test(); + test(); /* one additional test for ELSE IF */ + IF( ( EQ_16( st_fx->max_band, 19 ) ) && ( GT_32( L_snr18, 5 * ( 1 << 4 ) ) ) && ( GT_32( L_snr19, 5 * ( 1 << 4 ) ) ) ) + { + /* mssnr = (mssnr + 3*(msnr18 + msnr19)) * 0.77f; */ + /* mssnr = (mssnr*.77f + 2.31f*(msnr18 + msnr19)); */ + L_tmp1 = Mult_32_16( L_mssnr, 25231 ); /* Q13+Q15+1-16 --> Q13 */ + L_tmp = Mult_32_16( L_shl( L_add( L_msnr18, L_msnr19 ), 2 ), 18924 ); /* Q(13+2)+Q(15-2)+1-16 --> Q13 */ + L_tmp = L_add( L_tmp1, L_tmp ); + if ( GT_32( L_tmp, L_mssnr ) ) + { + L_mssnr = L_tmp; + } + } + ELSE IF( ( snr_idx != 0 ) && GT_16( nb_sig_snr, 13 ) ) + { + L_tmp = -126976; + move32(); /* -15.5 Q13 */ + L_tmp = L_mac0( L_tmp, 80, lp_snr ); /* 2.5f(Q5)*lp_snr(Q8) - 15.5f */ + if ( L_tmp > 0 ) /* 2.5f*lp_snr - 15.5f > 0 */ + { + L_mssnr = L_add( L_mssnr, L_tmp ); /* mssnr += 2.5f*lp_snr - 15.5f; */ + } + } + + + /* Separated SNR_SUM outlier modification */ + L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ + + test(); + test(); + test(); + IF( ( EQ_16( st_fx->max_band, 19 ) ) && LT_32( L_snr_outlier, MAX_SNR_OUTLIER_3_FX ) && GT_16( snr_outlier_index, 3 ) && LT_16( snr_outlier_index, MAX_SNR_OUTLIER_IND_FX ) ) + { + + test(); + 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 */ + } + ELSE IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_2_FX ) ) /* float:: (accum_ener_L *INV_OUTLIER_THR_2 > accum_ener_H ) !!! */ + || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) + { + /* L_snr_sum = SNR_OUTLIER_WGHT_2 * (snr_sum - snr_outlier); */ + + /* 1.01*x -> (1*x + 0.01*x) to not drop down to Q3 */ + L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); + L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.01(in Q21)= 20972 Q4*Q21+1-16 -> Q10 */ + L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 6 ) ); /* Q4 */ + } + ELSE + { + /* L_snr_sum = SNR_OUTLIER_WGHT_3 * (snr_sum - snr_outlier);*/ + /* 1.02*x -> (1*x + 0.02*x) to not drop down to Q3 */ + L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); + L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.02(in Q20)= 20972 Q4*Q20+1-16 -> Q9 */ + L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 5 ) ); /* Q4 */ + } + } + /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ +#ifdef BASOP_NOGLOB + hVAD->L_snr_sum_vad_fx = L_shr( L_add_o( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol, &Overflow ), 1 ); /*Q4*/ +#else /* BASOP_NOGLOB */ + hVAD->L_snr_sum_vad_fx = L_shr( L_add( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol ), 1 ); /*Q4*/ +#endif /* BASOP_NOGLOB */ + + /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ + snr_sum_ol = vad_snr_log_fx( L_snr_sum_ol, LG10 ); + snr_sum = snr_sum_ol; + move16(); /* note for NB no outlier modification */ + + /* snr_sum_HE_SAD = 10.0f * (float)log10( snr_sum_HE_SAD ); */ + snr_sum_HE_SAD = vad_snr_log_fx( L_snr_sum_HE_SAD, LG10 ); + + *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 ); + IF( LT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) + { + lp_snr = add( lp_snr, 1 << 8 ); /* lp_snr += 1; */ + + if ( GT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) + { + lp_snr = hNoiseEst->sign_dyn_lp_fx; + move16(); + } + } + + /*thr1 = nk * lp_snr + nc*1.0 + nv * ( st->Etot_v_h2 - nv_ofs); */ /* Linear function for noisy speech */ + + L_tmp = L_shl( L_mult( sub( hNoiseEst->Etot_v_h2_fx, nv_ofs ), nv ), 7 ); /* Q8+Q8+1 +7 --> Q24 */ + L_tmp = L_mac( L_tmp, nc, (Word16) 32767 ); /* Q8+Q15+1 = Q24 */ + thr1 = mac_r( L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ + + IF( st_fx->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100 ) + { + /* lower threshold during warmup time */ + thr1 = sub( thr1, 2560 ); + L_vad_thr = 0; + } + + IF( GT_16( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) /* if (lp_snr > 20.0f )*/ + { + IF( st_fx->element_mode == EVS_MONO || hNoiseEst->first_noise_updt_cnt >= 100 ) + { + /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ + thr1 = add( thr1, mult( 9830, sub( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) ); /* Q15*Q8+1 -16 --> Q8 */ + + test(); + test(); + test(); + if ( EQ_16( st_fx->max_band, 16 ) && GT_16( lp_snr, 40 * 256 ) && GT_16( thr1, 6600 ) && LT_16( lp_speech_fx, 11520 ) ) + { + thr1 = 6600; + } + } + } + + + /*---------------------------------------------------------------------* + * WB input + * SNR threshold computing + * Hangover control & final VAD decision + *---------------------------------------------------------------------*/ + + IF( NE_16( vad_bwidth_fx, NB ) ) + { + + /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of + modyfying thr1 and snr_sum */ + + thr1_ol = thr1; + move16(); + hangover_short = 3; + move16(); + + IF( LT_16( lp_snr, th_clean ) ) + { + hangover_short = 4; + move16(); + + /* In this section the modified nk, and nc are used */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float + ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ + test(); + IF( ( snr_outlier_index <= 4 && ( st_fx->last_coder_type > UNVOICED ) && !st_fx->Opt_SC_VBR ) || + ( snr_outlier_index <= 4 && ( last_7k2_coder_type > UNVOICED ) && st_fx->Opt_SC_VBR ) ) + + + { + thr1_ol = sub( thr1_ol, (Word16) ( 1 << 8 ) ); /*thr1_ol = thr1 - 1.0f ; */ + /*snr_sum_ol = 10.0f * (float)log10( hVAD->L_snr_sum_vad_fx );*/ + snr_sum_ol = vad_snr_log_fx( hVAD->L_snr_sum_vad_fx, LG10 ); /* snr in Q8 */ + } + ELSE IF( ( ( LE_16( st_fx->last_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR != 0 ) ) || + ( ( LE_16( last_7k2_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR == 0 ) ) ) + + { + /* thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); */ + L_tmp2 = Msub_32_16( (Word32) ( 1 << ( 24 - 16 ) ), L_snr_outlier, 20972 ); /* (1.0)Q24(Q8 in high 32bit word) - Q4*Q19+1 */ + tmp2 = round_fx( L_shl( L_tmp2, 16 ) ); /* high word is in Q8 */ + thr1_ol = add( thr1_ol, tmp2 ); /* (Q8 , Q8) */ + } + ELSE + { + /*thr1_ol = thr1 + max(0, (float)(0.6f - 0.01f * L_snr_outlier)); */ + thr1_ol = thr1; + move16(); + L_tmp2 = Msub_32_16( (Word32) 614, L_snr_outlier, 20972 ); /* .6*1024= */ /* 0.6 Q26(Q10 in high word) - Q4*Q21+1 */ +#ifdef BASOP_NOGLOB + tmp2 = round_fx( L_shl_o( L_tmp2, 14, &Overflow ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#else /* BASOP_NOGLOB */ + tmp2 = round_fx( L_shl( L_tmp2, 14 ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#endif + if ( L_tmp2 > 0 ) + { + thr1_ol = add( thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ + } + } + } + + /* apply outlier modification */ + snr_sum = snr_sum_ol; + move16(); /*NB s*/ + thr1 = thr1_ol; + move16(); + + /* DTX HANGOVER is in pre_proc_fx() */ + flag_he1 = 0; + move16(); + + IF( GT_32( L_mssnr, L_vad_thr ) ) + { + flag_he1 = 1; + move16(); /* he1 primary decision */ + hVAD->nb_active_frames_he1 = add( hVAD->nb_active_frames_he1, 1 ); /* Counter of consecutive active speech frames */ + + IF( GE_16( hVAD->nb_active_frames_he1, ACTIVE_FRAMES_FX ) ) + { + hVAD->nb_active_frames_he1 = ACTIVE_FRAMES_FX; + move16(); + hVAD->hangover_cnt_he1 = 0; + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + /* inside HO period */ + test(); + if ( sub( hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX ) < 0 && hVAD->hangover_cnt_he1 != 0 ) + { + hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + } + + if ( hVAD->soft_hangover > 0 ) + { + hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + } + } + ELSE + { + /* Reset the counter of speech frames necessary to start hangover algorithm */ + hVAD->nb_active_frames_he1 = 0; + move16(); + } + + + IF( GT_16( hVAD->voiced_burst, 3 ) ) + { + IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */ + { + hVAD->soft_hangover = hangover_sf_tbl[add( snr_idx, 3 )]; + move16(); + } + ELSE + { + hVAD->soft_hangover = hangover_sf_tbl[snr_idx]; + move16(); + } + } + + + 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 */ + test(); + IF( flag_he1 == 0 && hVAD->soft_hangover > 0 ) + { + IF( GT_32( L_mssnr_hov, L_vad_thr ) ) + { + flag_he1 = 1; + move16(); + hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + } + ELSE + { + hVAD->soft_hangover = 0; + move16(); + } + + if ( hVAD->soft_hangover < 0 ) + { + hVAD->soft_hangover = 0; + move16(); + } + } + + test(); + test(); + IF( ( flag_he1 == 0 ) && ( LT_16( hVAD->hangover_cnt_he1, hangover_hd ) ) && ( hVAD->soft_hangover == 0 ) ) + { + flag_he1 = 1; + move16(); + hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + } + + + /* Calculate background stationarity */ + test(); + IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) + { + IF( GT_16( snr_sumt, hVAD->bcg_flux_fx ) ) + { + IF( hVAD->bcg_flux_init-- > 0 ) + { + IF( GT_16( snr_sumt, add( hVAD->bcg_flux_fx, 800 ) ) ) + { + /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), add( hVAD->bcg_flux_fx, 800 ), 3277 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), snr_sumt, 3277 ); /*Q4 */ + } + } + ELSE + { + IF( GT_16( snr_sumt, add( hVAD->bcg_flux_fx, 160 ) ) ) + { + /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), add( hVAD->bcg_flux_fx, 160 ), 328 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt;*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), snr_sumt, 328 ); /*Q4 */ + } + } + } + ELSE + { + IF( hVAD->bcg_flux_init-- > 0 ) + { + IF( LT_16( snr_sumt, sub( hVAD->bcg_flux_fx, 480 ) ) ) + { + /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31131 ), sub( hVAD->bcg_flux_fx, 480 ), 1638 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt;*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31131 ), snr_sumt, 1638 ); /*Q4 */ + } + } + ELSE + { + IF( LT_16( snr_sumt, sub( hVAD->bcg_flux_fx, 160 ) ) ) + { + /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), sub( hVAD->bcg_flux_fx, 160 ), 26 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt;*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), snr_sumt, 26 ); /*Q4 */ + } + } + } + + hVAD->bcg_flux_init = s_max( hVAD->bcg_flux_init, 0 ); + } + + flag = 0; + move16(); + st_fx->localVAD = 0; + move16(); + /* if ( snr_sum > thr1 && flag_he1 == 1 ) */ /* Speech present */ + test(); + + IF( ( GT_16( snr_sum, thr1 ) ) && ( EQ_16( flag_he1, 1 ) ) ) /* Speech present */ + { + flag = 1; + move16(); + st_fx->localVAD = 1; + move16(); + + hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + + IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) + { + hVAD->nb_active_frames = ACTIVE_FRAMES_FX; + move16(); + hVAD->hangover_cnt = 0; + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + /* inside HO period */ + test(); + if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) && hVAD->hangover_cnt != 0 ) + { + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + } + } + ELSE + { + /* Reset the counter of speech frames necessary to start hangover algorithm */ + hVAD->nb_active_frames = 0; + move16(); + + if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) ) /* inside HO period */ + { + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + } + + + IF( LE_16( hVAD->hangover_cnt, hangover_short ) ) /* "hard" hangover */ + { + test(); + test(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( LT_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + { + *noisy_speech_HO = 1; + move16(); + } + test(); + test(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( GE_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + { + *clean_speech_HO = 1; + move16(); + } + flag = 1; + move16(); /*HO*/ + } + } + + + /* localVAD and vad_flag for HE-SAD - in parallel with normal localVAD and vad_flag */ + + *localVAD_HE_SAD = 0; + move16(); + + test(); + IF( ( GT_16( snr_sum_HE_SAD, thr1 ) ) && ( EQ_16( flag_he1, 1 ) ) ) /* Speech present */ + { + + *localVAD_HE_SAD = 1; + move16(); + } + } /* end of WB SWB */ + + /*---------------------------------------------------------------------* + * NB input + * SNR threshold computing + * Hangover control & final VAD decision + *---------------------------------------------------------------------*/ + + ELSE /* NB input */ + { + /* Add localVAD_HE_SAD also for NB operation for use with speech music classifier */ + *localVAD_HE_SAD = 0; + move16(); + if ( GT_16( snr_sum_HE_SAD, thr1 ) ) + { + *localVAD_HE_SAD = 1; + move16(); + } + + st_fx->localVAD = 0; + move16(); /* safety inits for fx */ + IF( GT_16( snr_sum, thr1 ) ) /* Speech present, possibly in hangover */ + { + hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) + { + hVAD->nb_active_frames = ACTIVE_FRAMES_FX; + move16(); + hVAD->hangover_cnt = 0; + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + st_fx->localVAD = 1; + move16(); + } + ELSE + { + hVAD->nb_active_frames = 0; + move16(); /* Reset the counter of speech frames necessary to start hangover algorithm */ + /* st_fx->localVAD = 0; move16(); */ /* set above */ + } + + thr1_nb_mod = thr1; + move16(); /* thr1 may be adjusted after this point */ + IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_NB_FX ) ) + { + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + + IF( LT_16( lp_snr, 4864 ) ) + /*19.0f Q8*/ /* very low SNR */ + { + thr1_nb_mod = sub( thr1_nb_mod, 1331 ); /*thr1 -= 5.2f;*/ + } + ELSE IF( LT_16( lp_snr, 8960 ) ) /*35 in Q8 */ /* low SNR */ + { + thr1_nb_mod = sub( thr1_nb_mod, 512 ); /*thr1 -= 2.0f;*/ + } + } + + + thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */ + + /* -dtx condition dependency in noisy speech */ + tmp = 333; + move16(); /* 1.3f; */ + if ( st_fx->Opt_DTX_ON == 0 ) + { + tmp = 282; + move16(); /* 1.10f; */ + } + if ( LT_16( lp_snr, th_clean ) ) + { + 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 */ + { + flag = 1; + move16(); + } + + + test(); + IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */ + { + flag = 1; + move16(); + st_fx->localVAD = 0; + move16(); + + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + *NB_speech_HO = 1; + } + move16(); + } + thr1 = thr1_nb_mod; + 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_ -> this initialisation is not done here in float */ + move16(); + IF( vad_bwidth_fx != NB ) + { + if ( LT_16( lp_snr, TH16_2_NFLAG_FX ) ) /*now 27, original threshold: 35dB*/ + { + *flag_noisy_speech_snr = 1; + move16(); + } + } + ELSE + { + if ( LT_16( lp_snr, TH8_1_NFLAG_FX ) ) /* now 20.0 */ + { + *flag_noisy_speech_snr = 1; + move16(); + } + } + + if ( st_fx->hSC_VBR != NULL ) + { + /* SC-VBR */ + st_fx->hSC_VBR->vadsnr_fx = snr_sum; + move16(); /* for ppp, voiced_enc */ + st_fx->hSC_VBR->vadnoise_fx = thr1; + move16(); /* used in nb for find_uv */ + } + + /* Updates */ + hVAD->prim_act_quick_fx = mult_r( 26214, hVAD->prim_act_quick_fx ); /*Q15 */ + + if ( st_fx->localVAD != 0 ) + { + hVAD->prim_act_quick_fx = add( 6554, hVAD->prim_act_quick_fx ); /*Q15 */ + } + + hVAD->prim_act_slow_fx = mult_r( 32440, hVAD->prim_act_slow_fx ); /*Q15 */ + + if ( st_fx->localVAD != 0 ) + { + hVAD->prim_act_slow_fx = add( 328, hVAD->prim_act_slow_fx ); /*Q15 */ + } + + tmp = hVAD->prim_act_slow_fx; + move16(); + if ( LE_16( hVAD->prim_act_quick_fx, hVAD->prim_act_slow_fx ) ) + { + tmp = hVAD->prim_act_quick_fx; + move16(); + } + /*st->prim_act = 0.1f * tmp + (1.0f-0.1f)* st->prim_act;*/ + hVAD->prim_act_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_fx ); + + + hVAD->prim_act_quick_he_fx = mult_r( 26214, hVAD->prim_act_quick_he_fx ); /*Q15 */ + if ( *localVAD_HE_SAD != 0 ) + { + hVAD->prim_act_quick_he_fx = add( 6554, hVAD->prim_act_quick_he_fx ); /*Q15 */ + } + + hVAD->prim_act_slow_he_fx = mult_r( 32440, hVAD->prim_act_slow_he_fx ); /*Q15 */ + if ( *localVAD_HE_SAD != 0 ) + { + hVAD->prim_act_slow_he_fx = add( 328, hVAD->prim_act_slow_he_fx ); /*Q15 */ + } + + tmp = hVAD->prim_act_slow_he_fx; + move16(); + if ( LE_16( hVAD->prim_act_quick_he_fx, hVAD->prim_act_slow_he_fx ) ) + { + tmp = hVAD->prim_act_quick_he_fx; + move16(); + } + hVAD->prim_act_he_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_he_fx ); + + + if ( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ + { + hVAD->vad_flag_cnt_50 = sub( hVAD->vad_flag_cnt_50, 1 ); + } + + hVAD->vad_flag_reg_H = L_shl( L_and( hVAD->vad_flag_reg_H, (Word32) 0x3fffffffL ), 1 ); + + + if ( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) + { + hVAD->vad_flag_reg_H = L_or( hVAD->vad_flag_reg_H, 0x01L ); + } + + hVAD->vad_flag_reg_L = L_shl( L_and( hVAD->vad_flag_reg_L, (Word32) 0x3fffffffL ), 1 ); + + + IF( flag != 0 ) /* should not include the extra DTX hangover */ + { + hVAD->vad_flag_reg_L = L_or( hVAD->vad_flag_reg_L, 0x01L ); + hVAD->vad_flag_cnt_50 = add( hVAD->vad_flag_cnt_50, 1 ); + } + + 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 ); -- GitLab From 74c6c0620673582ad9aa94313f5173767ca07b4e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 10 Jul 2024 12:30:24 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/cldfb_evs.c | 2 +- lib_com/ivas_rom_com.c | 2 +- lib_com/prot_fx2.h | 22 +++++++++++----------- lib_enc/acelp_core_enc.c | 2 +- lib_enc/ivas_core_pre_proc_front.c | 6 +++--- lib_enc/stat_enc.h | 26 +++++++++++++------------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 9fa073106..1e7d5bd8f 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -1286,7 +1286,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) } } - IF( GE_16( numberBands, freqTable[1] ) && hTecEnc != NULL) + IF( GE_16( numberBands, freqTable[1] ) && hTecEnc != NULL ) { Word32 *tempEnergyValuesArry[CLDFB_NO_COL_MAX]; Word16 ScaleX2; diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index ace600eab..8733ad0bd 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -6835,4 +6835,4 @@ const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[9] = 0, /* offset */ { +0.000000e+000f, +5.937500e-002f, +1.375000e-001f, +2.343750e-001f, +3.500000e-001f, +4.843750e-001f, +6.375000e-001f, +8.093750e-001f, +1.000000e+000f } /* data */ } -}; \ No newline at end of file +}; diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 7975ff65f..e03108221 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -2289,17 +2289,17 @@ Word32 Interpol_lc_fx( /* o : interpolated value ); -//modif_fs_fx.c -Word16 modify_Fs_fx( /* o : length of output Q0 */ - const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ - const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ - Word16 *Q_new_inp, //TO be removed - Word16 *mem_decim_size //TO be removed +// modif_fs_fx.c +Word16 modify_Fs_fx( /* o : length of output Q0 */ + const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ + Word16 lg, /* i : length of input Q0 */ + const Word32 fin, /* i : frequency of input Q0 */ + Word16 sigOut_fx[], /* o : decimated signal Q0 */ + const Word32 fout, /* i : frequency of output Q0 */ + Word16 mem_fx[], /* i/o: filter memory Q0 */ + const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ + Word16 *Q_new_inp, // TO be removed + Word16 *mem_decim_size // TO be removed ); Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index c5359b781..d006fa1ea 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -2191,4 +2191,4 @@ ivas_error acelp_core_enc( return error; } -#endif \ No newline at end of file +#endif diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index b103282e9..48dff1e9c 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -917,7 +917,7 @@ ivas_error pre_proc_front_ivas_fx( float sp_div, PS[128]; /* speech/music clasif. parameters */ int16_t L_look; /* length of look-ahead */ #if 1 - float snr_sum_he; /* HE SAD parameters */ + float snr_sum_he; /* HE SAD parameters */ #endif float mem_decim_dummy[2 * L_FILT_MAX]; /* dummy decimation filter memory */ float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ @@ -959,8 +959,8 @@ ivas_error pre_proc_front_ivas_fx( Word16 *temp1F_icatdmResampBuf_fx; Word16 *old_inp_12k8_fx; Word16 *old_inp_16k_fx; - Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ - Word32 Etot_fx; /* total energy */ + Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word32 Etot_fx; /* total energy */ #if 0 Word32 fr_bands_fx[2 * NB_BANDS]; /* energy in frequency bands */ Word16 Q_new; diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 9bc9d5393..451ac33ee 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -770,17 +770,17 @@ typedef struct noise_estimation_structure float lt_tn_dist; float lt_Ellp_dist; float lt_haco_ev; - Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ - Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ - Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ - Word16 Etot_last_fx; /*Q8*/ - Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ - - Word32 Etot_l_32fx; /* Q8 Noise estimator - Track energy from below */ - Word32 Etot_h_32fx; /* Q8 Noise estimator - Track energy from above */ - Word32 Etot_l_lp_32fx; /* Q8 Noise estimator - Smoothed low energy */ - Word32 Etot_last_32fx; /*Q8*/ - Word32 Etot_lp_32fx; /* Q8 Noise estimator - Filtered input energy */ + Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ + Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ + Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ + Word16 Etot_last_fx; /*Q8*/ + Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ + + Word32 Etot_l_32fx; /* Q8 Noise estimator - Track energy from below */ + Word32 Etot_h_32fx; /* Q8 Noise estimator - Track energy from above */ + Word32 Etot_l_lp_32fx; /* Q8 Noise estimator - Smoothed low energy */ + Word32 Etot_last_32fx; /*Q8*/ + Word32 Etot_lp_32fx; /* Q8 Noise estimator - Filtered input energy */ Word16 lt_tn_track_fx; /* Q15 */ Word16 lt_tn_dist_fx; /* Q8*/ @@ -806,10 +806,10 @@ typedef struct noise_estimation_structure float Etot_st_est; /* Noise estimation - short term estimate of E{ Etot } */ float Etot_sq_st_est; /* Noise estimation - short term estimate of E{ Etot^2 } */ Word16 Etot_v_h2_fx; - Word16 sign_dyn_lp_fx; /*Q8*/ + Word16 sign_dyn_lp_fx; /*Q8*/ Word32 Etot_v_h2_32fx; - Word32 sign_dyn_lp_32fx; /*Q8*/ + Word32 sign_dyn_lp_32fx; /*Q8*/ Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ -- GitLab