From b7312111062711972c30448f697113523043d808 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 12 Nov 2024 15:03:59 +0530 Subject: [PATCH] Encoder code float struct elements clean up and addition of Q-info for lib_com --- lib_com/cldfb.c | 399 ++++++++++++++++++++++++++-- lib_com/ivas_prot_fx.h | 70 +++++ lib_com/ivas_sba_config.c | 2 +- lib_com/prot.h | 4 + lib_com/prot_fx.h | 6 + lib_com/stat_com.h | 14 +- lib_com/swb_tbe_com.c | 4 + lib_dec/ivas_svd_dec.c | 46 ++-- lib_enc/acelp_core_enc.c | 21 +- lib_enc/core_enc_switch.c | 6 - lib_enc/core_switching_enc.c | 29 +- lib_enc/fd_cng_enc.c | 37 +-- lib_enc/fd_cng_enc_fx.c | 24 +- lib_enc/hq_core_enc.c | 7 + lib_enc/init_enc.c | 14 +- lib_enc/ivas_core_enc.c | 108 ++------ lib_enc/ivas_core_pre_proc_front.c | 152 +++++++---- lib_enc/ivas_cpe_enc.c | 198 +++++++------- lib_enc/ivas_enc.c | 261 +++++++----------- lib_enc/ivas_front_vad.c | 217 ++++++++------- lib_enc/ivas_init_enc.c | 38 +++ lib_enc/ivas_ism_enc.c | 35 +-- lib_enc/ivas_mct_enc.c | 67 +---- lib_enc/ivas_qmetadata_enc.c | 98 +++++++ lib_enc/ivas_sba_enc.c | 36 +++ lib_enc/ivas_sce_enc.c | 344 ++++++++++++++++++++++-- lib_enc/ivas_spar_encoder.c | 47 +--- lib_enc/ivas_stat_enc.h | 14 +- lib_enc/ivas_stereo_dft_enc.c | 26 +- lib_enc/ivas_stereo_dft_enc_itd.c | 5 + lib_enc/ivas_stereo_icbwe_enc.c | 16 +- lib_enc/ivas_stereo_switching_enc.c | 5 +- lib_enc/ivas_stereo_td_enc.c | 2 +- lib_enc/lib_enc.c | 2 +- lib_enc/stat_enc.h | 184 +++++-------- lib_enc/swb_bwe_enc_fx.c | 4 + lib_enc/swb_pre_proc.c | 2 +- lib_enc/swb_tbe_enc.c | 51 +++- lib_enc/swb_tbe_enc_fx.c | 152 ++++++++++- lib_rend/ivas_omasa_ana.c | 2 + 40 files changed, 1839 insertions(+), 910 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index d324afcc5..f9b618373 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -59,7 +59,11 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); +#ifdef IVAS_FLOAT_FIXED +static void cldfb_init_proto_and_twiddles_enc_fx( HANDLE_CLDFB_FILTER_BANK hs ); +#else static void cldfb_init_proto_and_twiddles_enc( HANDLE_CLDFB_FILTER_BANK hs ); +#endif #ifndef IVAS_FLOAT_FIXED static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead, float **realValues, float **imagValues, const int16_t numberBands, int16_t numberCols, TEC_ENC_HANDLE hTecEnc ); @@ -1648,9 +1652,11 @@ void configureCldfb_ivas( return; } -void configureCldfb_ivas_enc( + +#ifdef IVAS_FLOAT_FIXED +void configureCldfb_ivas_enc_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ - const int32_t sampling_rate /* i : sampling rate */ + const Word32 sampling_rate /* i : sampling rate */ ) { @@ -1658,18 +1664,34 @@ void configureCldfb_ivas_enc( 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->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); + h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); h_cldfb->zeros = 0; h_cldfb->anaScalefactor = 0; h_cldfb->synScalefactor = 0; h_cldfb->filterScale = 1; -#endif + cldfb_init_proto_and_twiddles_enc_fx( h_cldfb ); + + return; +} +#else +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; cldfb_init_proto_and_twiddles_enc( h_cldfb ); return; } +#endif #ifdef IVAS_FLOAT_FIXED void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ @@ -1822,9 +1844,11 @@ ivas_error openCldfb_ivas_enc( hs->type = type; hs->prototype = prototype; - configureCldfb_ivas_enc( hs, sampling_rate ); #ifndef IVAS_FLOAT_FIXED + configureCldfb_ivas_enc( hs, sampling_rate ); hs->memory_flt = NULL; +#else + configureCldfb_ivas_enc_fx( hs, sampling_rate ); #endif hs->memory_length = 0; @@ -2790,6 +2814,338 @@ static void cldfb_init_proto_and_twiddles( } #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +static void cldfb_init_proto_and_twiddles_enc_fx( + 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_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( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 10; + hs->da = 10; + 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) 17036; // Q14 + hs->scale = cldfb_scale_2_5ms[0]; + move16(); + move16(); + hs->p_filter = CLDFB80_10_fx; + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 40; + hs->da = -20; + 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) 15388; // Q14 + hs->p_filter = LDQMF_10_fx; + hs->scale = cldfb_scale_5_0ms[0]; + move16(); + move16(); + } + BREAK; + + case 16: + 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(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 20; + hs->da = 20; + 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; // Q14 + hs->p_filter = CLDFB80_16_fx; + hs->scale = cldfb_scale_2_5ms[1]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 80; + hs->da = -40; + 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) 15388; // Q14 + hs->p_filter = LDQMF_16_fx; + hs->scale = cldfb_scale_5_0ms[1]; + move16(); + move16(); + } + BREAK; + + case 20: + + 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( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 20; + hs->da = 20; + 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) 17050; // Q14 + hs->p_filter = CLDFB80_20_fx; + hs->scale = cldfb_scale_2_5ms[2]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 80; + hs->da = -40; + 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) 15390; // Q14 + hs->p_filter = LDQMF_20_fx; + hs->scale = cldfb_scale_5_0ms[2]; + move16(); + move16(); + } + BREAK; + + case 30: + 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( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[6], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[6], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 30; + hs->da = 30; + 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; // Q14 + hs->scale = cldfb_scale_2_5ms[6]; + hs->p_filter = CLDFB80_30_fx; + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 120; + hs->da = -60; + 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) 15388; // Q14 + hs->scale = cldfb_scale_5_0ms[6]; + hs->p_filter = LDQMF_30_fx; + move16(); + move16(); + } + BREAK; + + case 32: + 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(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 32; + hs->da = 32; + 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) 17050; // Q14 + hs->p_filter = CLDFB80_32_fx; + hs->scale = cldfb_scale_2_5ms[3]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 160; + hs->da = -80; + 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) 15392; // Q14 + hs->scale = cldfb_scale_5_0ms[3]; + hs->p_filter = LDQMF_32_fx; + move16(); + move16(); + } + BREAK; + + case 40: + 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( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 40; + hs->da = 40; + 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; // Q14 + hs->scale = cldfb_scale_2_5ms[4]; + hs->p_filter = CLDFB80_40_fx; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 160; + hs->da = -80; + 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; // Q14 + hs->p_filter = LDQMF_40_fx; + hs->scale = cldfb_scale_5_0ms[4]; + move16(); + move16(); + } + BREAK; + + case 60: + 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( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) + { + hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); + move16(); + } + IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) + { + hs->ds = 60; + hs->da = 60; + move16(); + move16(); + 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; // Q14 + hs->p_filter = CLDFB80_60_fx; + hs->scale = cldfb_scale_2_5ms[5]; + move16(); + move16(); + } + ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + hs->ds = 240; + hs->da = -120; + move16(); + move16(); + 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; // Q14 + hs->p_filter = LDQMF_60_fx; + hs->scale = cldfb_scale_5_0ms[5]; + move16(); + move16(); + } + break; + } + + return; +} +#else static void cldfb_init_proto_and_twiddles_enc( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) @@ -2825,8 +3181,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 10; hs->da = 10; - hs->scale_flt = CLDFB80_10_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_10_SCALE; hs->p_filter_flt = CLDFB80_10_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -2846,8 +3202,8 @@ static void cldfb_init_proto_and_twiddles_enc( { #ifndef IVAS_FLOAT_FIXED hs->p_filter_flt = LDQMF_10; -#endif hs->scale_flt = LDQMF_10_SCALE; +#endif hs->ds = 40; hs->da = -20; #ifndef IVAS_FLOAT_FIXED @@ -2889,8 +3245,8 @@ static void cldfb_init_proto_and_twiddles_enc( { #ifndef IVAS_FLOAT_FIXED hs->p_filter_flt = CLDFB80_16_flt; -#endif hs->scale_flt = CLDFB80_16_SCALE; +#endif hs->ds = 20; hs->da = 20; #ifndef IVAS_FLOAT_FIXED @@ -2912,8 +3268,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 80; hs->da = -40; - hs->scale_flt = LDQMF_16_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_16_SCALE; hs->p_filter_flt = LDQMF_16; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -2959,8 +3315,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 20; hs->da = 20; - hs->scale_flt = CLDFB80_20_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_20_SCALE; hs->p_filter_flt = CLDFB80_20_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -2980,8 +3336,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 80; hs->da = -40; - hs->scale_flt = LDQMF_20_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_20_SCALE; hs->p_filter_flt = LDQMF_20; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3027,8 +3383,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 30; hs->da = 30; - hs->scale_flt = CLDFB80_30_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_30_SCALE; hs->p_filter_flt = CLDFB80_30_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3048,8 +3404,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 120; hs->da = -60; - hs->scale_flt = LDQMF_30_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_30_SCALE; hs->p_filter_flt = LDQMF_30; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3089,8 +3445,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 32; hs->da = 32; - hs->scale_flt = CLDFB80_32_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_32_SCALE; hs->p_filter_flt = CLDFB80_32_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3110,8 +3466,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 160; hs->da = -80; - hs->scale_flt = LDQMF_32_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_32_SCALE; hs->p_filter_flt = LDQMF_32; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3157,8 +3513,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 40; hs->da = 40; - hs->scale_flt = CLDFB80_40_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_40_SCALE; hs->p_filter_flt = CLDFB80_40_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3178,8 +3534,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 160; hs->da = -80; - hs->scale_flt = LDQMF_40_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_40_SCALE; hs->p_filter_flt = LDQMF_40; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3225,8 +3581,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 60; hs->da = 60; - hs->scale_flt = CLDFB80_60_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = CLDFB80_60_SCALE; hs->p_filter_flt = CLDFB80_60_flt; hs->rot_vec_ana_delay_re = NULL; hs->rot_vec_ana_delay_im = NULL; @@ -3246,8 +3602,8 @@ static void cldfb_init_proto_and_twiddles_enc( { hs->ds = 240; hs->da = -120; - hs->scale_flt = LDQMF_60_SCALE; #ifndef IVAS_FLOAT_FIXED + hs->scale_flt = LDQMF_60_SCALE; hs->p_filter_flt = LDQMF_60; hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; @@ -3268,6 +3624,7 @@ static void cldfb_init_proto_and_twiddles_enc( return; } +#endif /*-------------------------------------------------------------------* * cldfb_save_memory_ivas() * diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 59be73bfb..dff4997f0 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5763,5 +5763,75 @@ void ivas_spar_get_cldfb_gains_fx( HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, const DECODER_CONFIG_HANDLE hDecoderConfig ); +void ivas_sba_getTCs_fx( + Word32 *sba_data[], /* i : SBA signals Q11 */ + Encoder_Struct *st_ivas, /* i/o: Encoder struct */ + const Word16 input_frame /* i : frame length */ +); + +ivas_error front_vad_spar_fx( + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const Word32 *omni_in, /* i : omnidirectional input signal Q11 */ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const Word16 input_frame /* i : input frame length */ +); + +ivas_error ivas_spar_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[], /* i/o: input/transport audio channel Q11 */ + const Word16 input_frame, /* i : input frame length */ + Word16 *nb_bits_metadata, /* i : number of MD bits written */ + BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */ +); + +ivas_error ivas_ism_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data[], /* i : input signal [channels][samples] Q(q_data) */ + Word16 q_data, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + Word16 *nb_bits_metadata, /* i : number of metadata bits */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +); + +ivas_error ivas_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 data_fx[], /* i : input signal for single channel Q(q_data_fx) */ + const Word16 q_data_fx, /* i : Q-factor of input signal for single channel */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); +ivas_error ivas_cpe_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + +ivas_error ivas_mct_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[MCT_MAX_CHANNELS], /* i : input signal buffers Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + +ivas_error ivas_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 *data, /* i : input signal Q0 */ + const Word16 n_samples /* i : number of input samples */ +); + +void reset_metadata_spatial_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + const Word32 element_brate, /* i : element bitrate */ + Word32 *total_brate, /* o : total bitrate */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 nb_bits_metadata /* i : number of meatdata bits */ +); #endif diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 424a95b5a..8aa12792c 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -583,7 +583,7 @@ void ivas_sba_zero_vert_comp_fx( /* Keep Z if not planar */ IF( !sba_planar && EQ_16( i, 1 ) ) { - continue; + CONTINUE; } FOR( j = ( i * i + 1 ); j < ( ( i + 1 ) * ( i + 1 ) - 1 ); j++ ) diff --git a/lib_com/prot.h b/lib_com/prot.h index dc328e5d4..6c5655f99 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -9000,11 +9000,13 @@ void configureFdCngEnc( const int16_t bwidth, const int32_t total_brate ); +#ifndef IVAS_FLOAT_FIXED void initFdCngEnc( HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: Contains the variables related to the FD-based CNG process */ const int32_t input_Fs, /* i : input signal sampling frequency in Hz */ const float scale /* i : scaling factor */ ); +#endif void resetFdCngEnc( Encoder_State *st /* i/o: encoder state structure */ @@ -9194,10 +9196,12 @@ void configureCldfb_ivas( const int32_t sampling_rate /* i : sampling rate */ ); +#ifndef IVAS_FLOAT_FIXED void configureCldfb_ivas_enc( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ const int32_t sampling_rate /* i : sampling rate */ ); +#endif void analysisCldfbEncoder_ivas( Encoder_State *st, /* i/o: encoder state structure */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1ac9d84c0..c95597fd7 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -11075,4 +11075,10 @@ ivas_error IGF_Reconfig_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word16 rf_mode /* i : flag to signal the RF mode */ ); + +void configureCldfb_ivas_enc_fx( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ + const Word32 sampling_rate /* i : sampling rate */ +); + #endif diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 6c19f481a..b6e68bd59 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -812,9 +812,11 @@ typedef struct cldfb_filter_bank_struct Word16 bandsToZero; /* bands not synthesized */ Word16 nab; /* number of active bands */ Word16 filtermode; - - float scale_flt; /* scaling of frequency domain */ +#ifndef IVAS_FLOAT_FIXED + float scale_flt; /* scaling of frequency domain */ +#else Word16 scale; /* scaling of frequency domain */ /* Q8 */ +#endif } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; @@ -901,10 +903,10 @@ typedef struct igf_grid_struct float fFactor_flt; float lFactor_flt; #else - Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ - Word16 gFactor; /* 1Q14 */ - Word16 fFactor; /* 1Q14 */ - Word16 lFactor; /* 1Q14 */ + Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ + Word16 gFactor; /* 1Q14 */ + Word16 fFactor; /* 1Q14 */ + Word16 lFactor; /* 1Q14 */ #endif } IGF_GRID, *H_IGF_GRID; diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index 139e15c44..ddb28532a 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -59,6 +59,7 @@ static void Hilbert_transform( float tmp_R[], float tmp_I[], float *tmpi_R, floa static void Estimate_mix_factors( const float *shb_res, const float *exc16kWhtnd, const float *White_exc16k, const float pow1, const float pow22, float *vf_modified, int16_t *vf_ind ); #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * swb_tbe_reset() * @@ -88,6 +89,7 @@ void swb_tbe_reset( return; } +#endif /*-------------------------------------------------------------------* @@ -1839,6 +1841,7 @@ void fb_tbe_reset_synth( return; } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * wb_tbe_extras_reset() * @@ -1854,6 +1857,7 @@ void wb_tbe_extras_reset( return; } +#endif /*-------------------------------------------------------------------* * wb_tbe_extras_reset_synth() diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 1cb20cc22..801bb9e2b 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -142,8 +142,8 @@ static void singularVectorsAccumulationLeft_fx( ); static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* singularVectors_e */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* singularVectors_e */ Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, @@ -166,9 +166,9 @@ static void flushToZeroMat_fx( #endif static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ Word16 *secDiag_fx_e, /* i/o: */ @@ -205,9 +205,9 @@ static Word32 GivensRotation_fx( Word16 *out_e ); static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], @@ -399,9 +399,9 @@ void svdMat2mat( Word16 svd_fx( Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ Word16 InputMatrix_e, - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) Q31*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) singularValues_fx_e*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ @@ -428,7 +428,7 @@ Word16 svd_fx( { FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { - singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; /* Q31 */ + singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; /* InputMatrix_e */ move32(); } } @@ -474,21 +474,21 @@ Word16 svd_fx( FOR( jCh = 0; jCh < nChannelsL; ++jCh ) { - temp_fx = singularVectors_Left_fx[jCh][iCh]; /* Q31 */ + temp_fx = singularVectors_Left_fx[jCh][iCh]; /* singularValues_fx_e */ move32(); - singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; /* Q31 */ + singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; /* singularValues_fx_e */ move32(); - singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ + singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; /* singularValues_fx_e */ move32(); } FOR( jCh = 0; jCh < nChannelsC; ++jCh ) { - temp_fx = singularVectors_Right_fx[jCh][iCh]; /* Q31 */ + temp_fx = singularVectors_Right_fx[jCh][iCh]; /* singularValues_fx_e */ move32(); - singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; /* Q31 */ + singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; /* singularValues_fx_e */ move32(); - singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; /* Q31 */ + singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; /* singularValues_fx_e */ move32(); } } @@ -591,9 +591,9 @@ int16_t svd( #ifdef IVAS_FLOAT_FIXED static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ Word16 *secDiag_fx_e, /* i/o: */ @@ -893,10 +893,10 @@ static int16_t BidagonalDiagonalisation( #ifdef IVAS_FLOAT_FIXED static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) Q31*/ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) Q31*/ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], const Word16 startIndex, /* i : Q0*/ @@ -1963,8 +1963,8 @@ static void singularVectorsAccumulationLeft( #ifdef IVAS_FLOAT_FIXED static void singularVectorsAccumulationRight_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* Q31 */ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* Q31 */ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */ Word32 secDiag[MAX_OUTPUT_CHANNELS], /* exp(secDiag_e) */ Word16 singularVectors_e, Word16 secDiag_e, diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 36861985c..47ccebb56 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -545,9 +545,6 @@ ivas_error acelp_core_enc( { if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, &st->hFdCngEnc->msNoiseEst_fx_exp, st->hFdCngEnc->npartDec ); -#endif FdCng_encodeSID_ivas_fx( st ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS me2f_buf( st->hFdCngEnc->hFdCngCom->sidNoiseEst, st->hFdCngEnc->hFdCngCom->sidNoiseEstExp, st->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, st->hFdCngEnc->npartDec ); @@ -575,10 +572,8 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->hFdCngEnc->hFdCngCom->A_cng_flt, st->hFdCngEnc->hFdCngCom->A_cng, Q12, ( M + 1 ) ); - // Word16 Q_exc_cng_l = Q_factor_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->L_frame ); floatToFixed_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->hFdCngEnc->hFdCngCom->exc_cng, Q_new, st->L_frame ); #endif - // 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 ); FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( Aq_fx, Aq, Q12, ( st->L_frame / L_SUBFR ) * ( M + 1 ) ); @@ -1307,10 +1302,11 @@ ivas_error acelp_core_enc( { #ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); #else st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); #endif - 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 ) ) ) @@ -1323,22 +1319,17 @@ ivas_error acelp_core_enc( floatToFixed_arr( voice_factors, voice_factors_fx, Q15, 5 ); // Saturation Conversion used as last values have garbage values even in float Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 q_bwe_exc = min( 14, Q_factor_arr( st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ) ); + Word16 q_bwe_exc = sub( st->prev_Q_bwe_exc, 16 ) / 2; q_bwe_exc = min( q_bwe_exc, Q_factor_arr( bwe_exc, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) - PIT16k_MAX * 2 ) ); floatToFixed_arr16( bwe_exc, bwe_exc_fx, q_bwe_exc, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) - PIT16k_MAX * 2 ); - floatToFixed_arr16( st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, q_bwe_exc, NL_BUFF_OFFSET ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS - - Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, 0 ); +#endif // IVAS_FLOAT_FIXED_CONVERSIONS + Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( q_bwe_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, q_bwe_exc, st->coder_type, voice_factors_fx, st->L_frame ); // Q bwe_exc_extended_fx = 2 * Q bwe_exc_fx = 2 * q_bwe_exc - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -q_bwe_exc ); - + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( q_bwe_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( bwe_exc_extended_fx, bwe_exc_extended, 2 * q_bwe_exc, L_FRAME32k + NL_BUFF_OFFSET ); - fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, q_bwe_exc, NL_BUFF_OFFSET ); - #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else 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 ); diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 3f79d365d..31d300f31 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -274,12 +274,6 @@ void core_coder_mode_switch_ivas_fx( } ELSE { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); - set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); - set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); - st->hBWE_TD->gain_prec_swb = 1.0f; -#endif set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); set16_fx( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 7bcd3a99c..c5f197eeb 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -917,10 +917,6 @@ void core_switching_post_enc( { #ifdef IVAS_FLOAT_FIXED wb_tbe_extras_reset_fx( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( st->hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#endif #else wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 ); #endif @@ -939,9 +935,15 @@ void core_switching_post_enc( } #endif +#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); set_f( st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); set_f( st->hBWE_TD->mem_csfilt, 0, 2 ); +#else + set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); + set16_fx( st->hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( st->hBWE_TD->mem_csfilt_fx, 0, 2 ); +#endif } if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && @@ -958,7 +960,6 @@ void core_switching_post_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS /* To be removed later when the function is converted to fixed*/ InitSWBencBufferStates( st->hBWE_TD, NULL ); - swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); #endif #else InitSWBencBufferStates( st->hBWE_TD, NULL ); @@ -974,15 +975,22 @@ void core_switching_post_enc( } else if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && ( ( st->element_mode == IVAS_CPE_TD && st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) || ( st->element_mode != IVAS_CPE_TD && st->last_total_brate != st->total_brate ) || ( st->last_bwidth != st->bwidth ) || ( st->last_codec_mode != MODE1 ) || ( st->rf_mode_last != st->rf_mode ) ) ) { +#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); - set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); +#else + set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); +#endif #ifndef IVAS_FLOAT_FIXED + set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb = 1.0f; #else + set16_fx( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); set16_fx( st->hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + st->hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; #endif - st->hBWE_TD->gain_prec_swb = 1.0f; } else if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) { @@ -1010,8 +1018,15 @@ void core_switching_post_enc( /* Fade towards init value for non HQ_CORE */ if ( st->hHQ_core != NULL ) { +#ifndef IVAS_FLOAT_FIXED st->hHQ_core->crest_lp = HQ_CREST_FAC_SM * ( st->hHQ_core->crest_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_THRESHOLD; st->hHQ_core->crest_mod_lp = HQ_CREST_FAC_SM * ( st->hHQ_core->crest_mod_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * HQ_CREST_MOD_THRESHOLD; +#else + st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_THRESHOLD_FX ) ); /*Q28*/ + st->hHQ_core->crest_lp_q = Q28; + st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_MOD_THRESHOLD_FX ) ); /*Q29*/ + st->hHQ_core->crest_mod_lp_q = Q29; +#endif } } diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 481d7fdf1..ab6c2efd1 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -90,7 +90,7 @@ ivas_error createFdCngEnc( * * Initialize FD_CNG *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void initFdCngEnc( HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: Contains the variables related to the FD-based CNG process */ const int32_t input_Fs, /* i : input signal sampling frequency in Hz */ @@ -136,43 +136,34 @@ void initFdCngEnc( } /* Initialize the Noise Estimator */ - +#ifndef IVAS_FLOAT_FIXED set_f( hFdCngEnc->msPeriodog, 0.0f, NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled - set_f( hFdCngEnc->msAlpha, 0.0f, NPART ); set_f( hFdCngEnc->msBminWin, 0.0f, NPART ); set_f( hFdCngEnc->msBminSubWin, 0.0f, NPART ); + set_f( hFdCngEnc->msAlpha, 0.0f, NPART ); set_f( hFdCngEnc->msPsd, 0.0f, NPART ); - set_f( hFdCngEnc->msNoiseFloor, 0.0f, NPART ); -#endif - set_f( hFdCngEnc->msNoiseEst, 0.0f, NPART ); - set_f( hFdCngEnc->energy_ho, 0.0f, NPART ); - set_f( hFdCngEnc->msNoiseEst_old, 0.0f, NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled set_f( hFdCngEnc->msMinBuf, FLT_MAX, MSNUMSUBFR * NPART ); set_f( hFdCngEnc->msCurrentMin, FLT_MAX, NPART ); set_f( hFdCngEnc->msCurrentMinOut, FLT_MAX, NPART ); set_f( hFdCngEnc->msCurrentMinSubWindow, FLT_MAX, NPART ); -#endif - set_s( hFdCngEnc->msLocalMinFlag, 0, NPART ); - set_s( hFdCngEnc->msNewMinFlag, 0, NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled set_f( hFdCngEnc->msPsdFirstMoment, 0.0f, NPART ); set_f( hFdCngEnc->msPsdSecondMoment, 0.0f, NPART ); -#endif - hFdCngEnc->msPeriodogBufPtr = 0; - + set_f( hFdCngEnc->msNoiseFloor, 0.0f, NPART ); + set_f( hFdCngEnc->energy_ho, 0.0f, NPART ); set_f( hFdCngEnc->msPeriodogBuf, 0.0f, MSBUFLEN * NPART ); -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled set_f( hFdCngEnc->msLogPeriodog, 0.0f, NPART ); set_f( hFdCngEnc->msLogNoiseEst, 0.0f, NPART ); -#endif - -#ifndef IVAS_FLOAT_FIXED set_f( hFdCngEnc->mem_coherence, EPSILON, 4 ); + set_f( hFdCngEnc->msNoiseEst_old, 0.0f, NPART ); + set_f( hFdCngEnc->msNoiseEst, 0.0f, NPART ); #endif + set_s( hFdCngEnc->msLocalMinFlag, 0, NPART ); + set_s( hFdCngEnc->msNewMinFlag, 0, NPART ); + hFdCngEnc->msPeriodogBufPtr = 0; + return; } +#endif /*-------------------------------------------------------------------* * configureFdCngEnc() @@ -1580,8 +1571,6 @@ void FdCngEncodeMDCTStereoSID_fx( Word32 tmp32, t1, t2; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); #endif @@ -2267,8 +2256,6 @@ void FdCngEncodeDiracMDCTStereoSID_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[0]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst, hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx, &hCPE->hCoreCoder[1]->hFdCngEnc->msNoiseEst_fx_exp, hCPE->hCoreCoder[1]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[1]->hFdCngEnc->npartDec ); f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN ); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 1c5a0a177..0821a3922 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -11,7 +11,7 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "rom_enc.h" -//#include "prot_fx.h" +#include "prot.h" #include "prot_fx.h" #include "prot_fx_enc.h" #include "basop_util.h" @@ -57,7 +57,9 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; /* Initialize common */ - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + initFdCngCom_flt( hsCom, scale ); +#endif initFdCngCom( hsCom, scale ); /* Configure the Noise Estimator */ @@ -93,7 +95,18 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); } - initPartitions( sidparts_encoder_noise_est, 24, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + initPartitions_flt( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); + + hsCom->nCLDFBpart = hsCom->npart - hsCom->nFFTpart; + for ( j = 0; j < hsCom->nCLDFBpart; j++ ) + { + hsCom->CLDFBpart[j] = hsCom->part[j + hsCom->nFFTpart] - ( 256 - hsCom->startBand ); + hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; + } +#endif + + initPartitions( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) @@ -108,6 +121,8 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); hsEnc->msPeriodog_fx_exp_cldfb = 0; move16(); + hsEnc->msPeriodog_fx_exp = 31; + move16(); set32_fx( hsEnc->msAlpha_fx, 0, NPART ); set32_fx( hsEnc->msBminWin_fx, 0, NPART ); set32_fx( hsEnc->msBminSubWin_fx, 0, NPART ); @@ -117,7 +132,8 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); set32_fx( hsEnc->energy_ho_fx, 0, NPART ); set32_fx( hsEnc->msNoiseEst_old_fx, 0, NPART ); - + hsEnc->msNoiseEst_old_fx_exp = 0; + move16(); set16_fx( hsEnc->msLogPeriodog_fx, 0, NPART ); set16_fx( hsEnc->msLogNoiseEst_fx, 0, NPART ); set16_fx( hsEnc->msPsd_fx, 0, NPART ); diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 6345a1c63..e1002faaa 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -699,8 +699,15 @@ void HQ_core_enc_init( #endif hHQ_core->last_max_pos_pulse = 0; +#ifndef IVAS_FLOAT_FIXED hHQ_core->crest_lp = HQ_CREST_THRESHOLD; hHQ_core->crest_mod_lp = HQ_CREST_MOD_THRESHOLD; +#else + hHQ_core->crest_lp_fx = HQ_CREST_THRESHOLD_FX; + hHQ_core->crest_lp_q = Q28; + hHQ_core->crest_mod_lp_fx = HQ_CREST_MOD_THRESHOLD_FX; + hHQ_core->crest_mod_lp_q = Q29; +#endif return; } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 0792fce03..355aab8d2 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -1105,9 +1105,10 @@ ivas_error init_encoder( return error; } - initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); #ifdef IVAS_FLOAT_FIXED initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); +#else + initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); #endif /* initialization for IVAS modes happens in first frame pre-processing */ if ( st->element_mode == EVS_MONO ) @@ -1192,6 +1193,7 @@ ivas_error init_encoder_ivas_fx( Word32 igf_brate; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * General parameters @@ -1463,6 +1465,7 @@ ivas_error init_encoder_ivas_fx( 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; + move16(); /* Stationary noise UV modification */ st->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ @@ -2312,17 +2315,8 @@ ivas_error init_encoder_ivas_fx( test(); IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { -#if 0 - IF ((error = createFdCngEnc_fx(&st->hFdCngEnc)) != IVAS_ERR_OK) - { - return error; - } -#endif createFdCngEnc_fx( &st->hFdCngEnc ); initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); -#if 1 - initFdCngEnc( 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 ) { diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index de065abb6..d5939811b 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -630,12 +630,12 @@ ivas_error ivas_core_enc( IF( NE_16( st->element_mode, EVS_MONO ) ) { - Word16 temp_e; + // Word16 temp_e; - f2me( st->hHQ_core->crest_lp, &st->hHQ_core->crest_lp_fx, &temp_e ); - st->hHQ_core->crest_lp_q = sub( Q31, temp_e ); - f2me( st->hHQ_core->crest_mod_lp, &st->hHQ_core->crest_mod_lp_fx, &temp_e ); - st->hHQ_core->crest_mod_lp_q = sub( Q31, temp_e ); + // f2me( st->hHQ_core->crest_lp, &st->hHQ_core->crest_lp_fx, &temp_e ); + // st->hHQ_core->crest_lp_q = sub( Q31, temp_e ); + // f2me( st->hHQ_core->crest_mod_lp, &st->hHQ_core->crest_mod_lp_fx, &temp_e ); + // st->hHQ_core->crest_mod_lp_q = sub( Q31, temp_e ); } floatToFixed_arr( st->input, st->input_fx, 0, 960 ); @@ -646,8 +646,8 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( NE_16( st->element_mode, EVS_MONO ) ) { - st->hHQ_core->crest_lp = fix_to_float( st->hHQ_core->crest_lp_fx, st->hHQ_core->crest_lp_q ); - st->hHQ_core->crest_mod_lp = fix_to_float( st->hHQ_core->crest_mod_lp_fx, st->hHQ_core->crest_mod_lp_q ); + // st->hHQ_core->crest_lp = fix_to_float( st->hHQ_core->crest_lp_fx, st->hHQ_core->crest_lp_q ); + // st->hHQ_core->crest_mod_lp = fix_to_float( st->hHQ_core->crest_mod_lp_fx, st->hHQ_core->crest_mod_lp_q ); } IF( st->element_mode > EVS_MONO ) { @@ -780,17 +780,6 @@ ivas_error ivas_core_enc( /* Temporarily calculating variable Q. Will get Q values from core processing */ Q_new[n] = Q_factor_arrL( bwe_exc_extended[n], L_FRAME32k + NL_BUFF_OFFSET ); Q_new[n] = Q_new[n] / 2; - if ( st->hBWE_TD != NULL ) - { - Word16 tmp_q_1 = Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_shb, 2 * ALLPASSSECTIONS_STEEP + 1 ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb3, 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_syn_shbexc, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_lpc_syn, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ) ); - Word16 tmp_q_2 = Q_factor_arrL( st->hBWE_TD->mem_csfilt, 2 ); - st->prev_Q_bwe_exc = min( tmp_q_2, tmp_q_1 + 16 ) - 2 /* Guard bits */; /* This reset need to be looked into once core processing is complete */ - } floatToFixed_arr16( new_inp_resamp16k[n], new_inp_resamp16k_fx[n], -1, L_FRAME16k ); floatToFixed_arr( voice_factors[n], voice_factors_fx[n], Q15, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float @@ -800,19 +789,6 @@ ivas_error ivas_core_enc( // prev_lsp_wb_temp_fx, prev_lsp_wb_fx and prev_lpc_wb_fx in Q15. No float counterparts floatToFixed_arr16( st->voicing, st->voicing_fx, Q15, 3 ); - if ( st->hBWE_TD != NULL ) - { - floatToFixed_arr16( st->hBWE_TD->old_speech_wb, st->hBWE_TD->old_speech_wb_fx, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); - floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_wb3, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr16( st->hBWE_TD->state_syn_shbexc, st->hBWE_TD->state_syn_shbexc_fx, ( st->prev_Q_bwe_exc - 16 ), L_SHB_LAHEAD ); - floatToFixed_arr16( st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - floatToFixed_arr16( st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, ( st->prev_Q_bwe_exc - 16 ), NL_BUFF_OFFSET ); - floatToFixed_arr16( st->hBWE_TD->syn_overlap, st->hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - floatToFixed_arr32( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_csfilt_fx, st->prev_Q_bwe_exc, 2 ); - } - if ( st->hBWE_FD != NULL ) { floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, -1, L_FRAME48k ); @@ -845,19 +821,6 @@ ivas_error ivas_core_enc( fixedToFloat_arr( pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); fixedToFloat_arrL( bwe_exc_extended_fx[n], bwe_exc_extended[n], 2 * Q_new[n], L_FRAME32k + NL_BUFF_OFFSET ); - if ( st->hBWE_TD != NULL ) - { - fixedToFloat_arr( st->hBWE_TD->old_speech_wb_fx, st->hBWE_TD->old_speech_wb, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); - fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb2, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - fixedToFloat_arr( st->hBWE_TD->state_syn_shbexc_fx, st->hBWE_TD->state_syn_shbexc, ( st->prev_Q_bwe_exc - 16 ), L_SHB_LAHEAD ); - fixedToFloat_arr( st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, ( st->prev_Q_bwe_exc - 16 ), NL_BUFF_OFFSET ); - fixedToFloat_arr( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); - fixedToFloat_arrL( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, st->prev_Q_bwe_exc, 2 ); - } - if ( st->hBWE_FD != NULL ) { fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, -1, L_FRAME48k ); @@ -949,7 +912,7 @@ ivas_error ivas_core_enc( if ( st->element_mode == IVAS_CPE_DFT ) { - hCPE->hStereoICBWE->icbweRefEner = me2f( hCPE->hStereoICBWE->icbweRefEner_fx, hCPE->hStereoICBWE->icbweRefEner_fx_e ); + // hCPE->hStereoICBWE->icbweRefEner = me2f( hCPE->hStereoICBWE->icbweRefEner_fx, hCPE->hStereoICBWE->icbweRefEner_fx_e ); fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); @@ -996,19 +959,6 @@ ivas_error ivas_core_enc( // Q_shb_spch = Q_factor_arr( shb_speech, L_FRAME16k ); - if ( st->hBWE_TD != NULL ) - { - Word16 tmp_q_1 = Q_factor_arr( st->hBWE_TD->mem_genSHBexc_filt_down_shb, 2 * ALLPASSSECTIONS_STEEP + 1 ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_syn_shbexc, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->state_lpc_syn, L_SHB_LAHEAD ) ); - tmp_q_1 = min( tmp_q_1, Q_factor_arr( st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ) ); - Word16 tmp_q_2 = Q_factor_arrL( st->hBWE_TD->mem_csfilt, 2 ); - st->prev_Q_bwe_exc = min( tmp_q_2, tmp_q_1 + 16 ) - 2 /* Guard bits */; /* This reset need to be looked into once core processing is complete */ - - tmp_q_1 = Q_factor_arr( st->hBWE_TD->mem_stp_swb, LPC_SHB_ORDER ); - st->prev_Q_bwe_syn = tmp_q_1; /* This reset need to be looked into once core processing is complete */ - } - floatToFixed_arr( voice_factors[n], voice_factors_fx[n], Q15, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float floatToFixed_arr( pitch_buf[n], pitch_buf_fx[n], Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float floatToFixed_arr32( bwe_exc_extended[n], bwe_exc_extended_fx[n], 2 * Q_new[n], L_FRAME32k + NL_BUFF_OFFSET ); @@ -1020,12 +970,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { floatToFixed_arr16( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); - floatToFixed_arr16( st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - floatToFixed_arr32( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_csfilt_fx, st->prev_Q_bwe_exc, 2 ); - st->hBWE_TD->gain_prec_swb_fx = float_to_fix16( st->hBWE_TD->gain_prec_swb, Q14 ); - floatToFixed_arr16( st->hBWE_TD->mem_stp_swb, st->hBWE_TD->mem_stp_swb_fx, st->prev_Q_bwe_syn, LPC_SHB_ORDER ); - floatToFixed_arr( &st->hBWE_TD->tbe_demph, &st->hBWE_TD->tbe_demph_fx, st->prev_Q_bwe_exc - 16 - NOISE_QADJ, 1 ); // Satruation conversion used as -ve Q not handled - floatToFixed_arr( &st->hBWE_TD->tbe_premph, &st->hBWE_TD->tbe_premph_fx, st->prev_Q_bwe_exc - 16, 1 ); // Satruation conversion used as -ve Q not handled } #endif swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], Q_shb_spch, st->voicing_fx, pitch_buf_fx[n] ); @@ -1033,12 +977,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); - fixedToFloat_arr( st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); - fixedToFloat_arrL( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, st->prev_Q_bwe_exc, 2 ); - st->hBWE_TD->gain_prec_swb = fixedToFloat( st->hBWE_TD->gain_prec_swb_fx, Q14 ); - fixedToFloat_arr( st->hBWE_TD->mem_stp_swb_fx, st->hBWE_TD->mem_stp_swb, st->prev_Q_bwe_syn, LPC_SHB_ORDER ); - st->hBWE_TD->tbe_demph = fixedToFloat( st->hBWE_TD->tbe_demph_fx, st->prev_Q_bwe_exc - 16 - NOISE_QADJ ); - st->hBWE_TD->tbe_premph = fixedToFloat( st->hBWE_TD->tbe_premph_fx, st->prev_Q_bwe_exc - 16 ); } #endif #else @@ -1195,7 +1133,7 @@ ivas_error ivas_core_enc( floatToFixed_arr16( hCPE->hStereoICBWE->icbwe_inp_mem[0], hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); floatToFixed_arr16( hCPE->hStereoICBWE->icbwe_inp_mem[1], hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); - floatToFixed_arr16( hCPE->hStereoICBWE->mem_decim_shb_ch0, hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, 0, 90 ); + // floatToFixed_arr16( hCPE->hStereoICBWE->mem_decim_shb_ch0, hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, 0, 90 ); stereo_icBWE_preproc_fx( hCPE, input_frame, new_swb_speech_buffer_fx16 /*tmp buffer*/, q_new_swb_speech_buffer ); @@ -1214,7 +1152,7 @@ ivas_error ivas_core_enc( fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], hCPE->hStereoICBWE->icbwe_inp_mem[0], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], hCPE->hStereoICBWE->icbwe_inp_mem[1], scale_factor, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); - fixedToFloat_arr( hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, hCPE->hStereoICBWE->mem_decim_shb_ch0, 0, 90 ); + // fixedToFloat_arr( hCPE->hStereoICBWE->mem_decim_shb_ch0_fx, hCPE->hStereoICBWE->mem_decim_shb_ch0, 0, 90 ); #else stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ ); @@ -1245,7 +1183,7 @@ ivas_error ivas_core_enc( f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_nonref, hCPE->hStereoICBWE->mem_shb_speech_nonref_fx, &hCPE->hStereoICBWE->mem_shb_speech_nonref_e, L_LOOK_16k ); // shb_speech_ref_e f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_ref, hCPE->hStereoICBWE->mem_shb_speech_ref_fx, &hCPE->hStereoICBWE->mem_shb_speech_ref_e, L_LOOK_16k ); // shb_speech_ref_e - f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); + // f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); scale_factor = s_min( scale_factor, Q_factor_arrL( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, LPC_SHB_ORDER ) ); floatToFixed_arr32( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref_fx, scale_factor, LPC_SHB_ORDER ); #ifdef MSAN_FIX @@ -1263,7 +1201,7 @@ ivas_error ivas_core_enc( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, 31 ); + // hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, 31 ); IF( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) { fixedToFloat_arrL( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref, 31 - hStereoICBWE->mem_lpc_shbsynth_nonref_e, LPC_SHB_ORDER ); @@ -1272,29 +1210,33 @@ ivas_error ivas_core_enc( { me2f_buf_16( hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, hStereoICBWE->shbSynthRef, L_FRAME16k ); } - + /* FOR( i = 0; i < 2; i++ ) { hStereoICBWE->memGsEnerMap[i] = me2f( hStereoICBWE->memGsEnerMap_fx[i], hStereoICBWE->memGsEnerMap_e ); } - - hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, 0 ); + */ + // hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, 0 ); IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) { - hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, Q31 ); + // hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, Q31 ); hStereoICBWE->memShbSpecMapping = fixedToFloat( hStereoICBWE->memShbSpecMapping_fx, 31 - hStereoICBWE->memShbSpecMapping_e ); } ELSE { hStereoICBWE->memShbSpecMapping = 0; +#ifndef IVAS_FLOAT_FIXED hStereoICBWE->prevSpecMapping = 0; +#else + hStereoICBWE->prevSpecMapping_fx = 0; +#endif } } ELSE { - hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, hStereoICBWE->prevgsMapping_e ); - hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); + // hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, hStereoICBWE->prevgsMapping_e ); + // hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); IF( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) { @@ -1304,13 +1246,13 @@ ivas_error ivas_core_enc( hStereoICBWE->memShbSpecMapping = me2f( hStereoICBWE->memShbSpecMapping_fx, hStereoICBWE->memShbSpecMapping_e ); } - hStereoICBWE->prevRefEner = fixedToFloat( hStereoICBWE->prevRefEner_fx, 31 - hStereoICBWE->prevRefEner_e ); - hStereoICBWE->prevNonRefEner = fixedToFloat( hStereoICBWE->prevNonRefEner_fx, 31 - hStereoICBWE->prevNonRefEner_e ); + // hStereoICBWE->prevRefEner = fixedToFloat( hStereoICBWE->prevRefEner_fx, 31 - hStereoICBWE->prevRefEner_e ); + // hStereoICBWE->prevNonRefEner = fixedToFloat( hStereoICBWE->prevNonRefEner_fx, 31 - hStereoICBWE->prevNonRefEner_e ); IF( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) { fixedToFloat_arrL( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref, 31 - hStereoICBWE->mem_lpc_shbsynth_nonref_e, LPC_SHB_ORDER ); } - hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); + // hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); } #endif #else diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 1dfe55f3b..4bd981654 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -73,6 +73,20 @@ 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) *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 get_zero_flag( Word32 arr[], Word16 len ) +{ + FOR( Word16 j = 0; j < len; j++ ) + { + IF( arr[j] != 0 ) + { + return 1; + BREAK; + } + } + return 0; +} +#endif #ifndef IVAS_FLOAT_FIXED ivas_error pre_proc_front_ivas( @@ -1615,9 +1629,6 @@ ivas_error pre_proc_front_ivas_fx( 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; - if ( st->cldfbAnaEnc ) - st->cldfbAnaEnc->scale = (Word16) ( st->cldfbAnaEnc->scale_flt * ( 1 << 8 ) ); - Word16 Q_bands0 = 0, Q_bands1 = 0; IF( lr_vad_enabled && st->idchan == 0 ) { @@ -1851,16 +1862,32 @@ ivas_error pre_proc_front_ivas_fx( #else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); #endif - Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); - st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_fft = 31 - normmsPeriodog; - floatToFixed_arrL( st->hFdCngEnc->msPeriodog, st->hFdCngEnc->msPeriodog_fx, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - - // not needed actuall its just output - Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); - st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); + Word16 normmsPeriodog_fx = Q31, zero_flag = 0; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); + IF( zero_flag ) + { + normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); + move16(); + } + st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); + move16(); + move16(); + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp = sub( st->hFdCngEnc->msPeriodog_fx_exp, normmsPeriodog_fx ); + Word16 msNoiseEst_Q = Q31; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_fx, NPART ); + IF( zero_flag ) + { + msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_fx, NPART ); + } + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); + st->hFdCngEnc->msNoiseEst_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); + move16(); #ifdef MSAN_FIX floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); #else @@ -1868,10 +1895,6 @@ ivas_error pre_proc_front_ivas_fx( #endif #endif perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_fx, st->hFdCngEnc->msNoiseEst, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); -#endif } else { @@ -1895,16 +1918,32 @@ ivas_error pre_proc_front_ivas_fx( #else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); #endif - Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); - st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; - st->hFdCngEnc->msPeriodog_fx_exp_fft = 31 - normmsPeriodog; - floatToFixed_arrL( st->hFdCngEnc->msPeriodog, st->hFdCngEnc->msPeriodog_fx, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - - // not needed actuall its just output - Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); - st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); + Word16 normmsPeriodog_fx = Q31, zero_flag = 0; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); + IF( zero_flag ) + { + normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); + move16(); + } + st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); + move16(); + move16(); + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, normmsPeriodog_fx ); + st->hFdCngEnc->msPeriodog_fx_exp = st->hFdCngEnc->msPeriodog_fx_exp - normmsPeriodog_fx; + move16(); + Word16 msNoiseEst_Q = Q31; + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_fx, NPART ); + IF( zero_flag ) + { + msNoiseEst_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_fx, NPART ); + } + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); + st->hFdCngEnc->msNoiseEst_fx_exp = st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q; + move16(); #ifdef MSAN_FIX floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); #else @@ -1912,20 +1951,11 @@ ivas_error pre_proc_front_ivas_fx( #endif Word16 normmsperiodog = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, PERIODOGLEN ); st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = 31 - normmsperiodog; - // floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, st->hFdCngEnc->hFdCngCom->periodog, 31 - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, PERIODOGLEN); - floatToFixed_arr( st->hFdCngEnc->msPeriodogBuf, st->hFdCngEnc->msPeriodogBuf_fx, 9, MSBUFLEN * NPART ); st->hFdCngEnc->hFdCngCom->init_old = (Word16) ( st->hFdCngEnc->hFdCngCom->init_old_flt * ( 1 << 9 ) ); st->hFdCngEnc->hFdCngCom->scalingFactor = (Word16) ( st->hFdCngEnc->hFdCngCom->scalingFactor * ( 1 << 30 ) ); #endif perform_noise_estimation_enc_ivas_fx( band_energies_fx, band_energies_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_fx, st->hFdCngEnc->msNoiseEst, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - fixedToFloat_arr( st->hFdCngEnc->msPeriodogBuf_fx, st->hFdCngEnc->msPeriodogBuf, 9, MSBUFLEN * NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - // fixedToFloat_arrL(st->hFdCngEnc->hFdCngCom->periodog, st->hFdCngEnc->hFdCngCom->periodog_flt, 31 - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, PERIODOGLEN); -#endif } } } @@ -1976,30 +2006,44 @@ ivas_error pre_proc_front_ivas_fx( } } - if ( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) + IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hFdCngEnc->msPeriodog_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); + Word16 zero_flag = 0, msPeriodog_fx_Q = Q31; + move16(); + move16(); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); + IF( zero_flag ) + { + msPeriodog_fx_Q = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); + } + msPeriodog_fx_Q = sub( sub( 31, msPeriodog_fx_Q ), st->hFdCngEnc->msPeriodog_fx_exp ); + Scale_sig32( st->hFdCngEnc->msPeriodog_fx, NPART, sub( sub( 31, msPeriodog_fx_Q ), st->hFdCngEnc->msPeriodog_fx_exp ) ); + st->hFdCngEnc->msPeriodog_fx_exp = sub( 31, msPeriodog_fx_Q ); + + Word16 energy_ho_fx_Q = Q31; + zero_flag = get_zero_flag( st->hFdCngEnc->energy_ho_fx, NPART ); + IF( zero_flag ) + { + energy_ho_fx_Q = getScaleFactor32( st->hFdCngEnc->energy_ho_fx, NPART ); + } + + Scale_sig32( st->hFdCngEnc->energy_ho_fx, NPART, energy_ho_fx_Q ); + st->hFdCngEnc->energy_ho_fx_exp = st->hFdCngEnc->energy_ho_fx_exp - energy_ho_fx_Q; + + Word16 msNoiseEst_old_Q = Q31; + zero_flag = get_zero_flag( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); + IF( zero_flag ) + { + energy_ho_fx_Q = getScaleFactor32( st->hFdCngEnc->msNoiseEst_old_fx, NPART ); + } + + Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, energy_ho_fx_Q ); + st->hFdCngEnc->msNoiseEst_old_fx_exp = st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_old_Q; st->hFdCngEnc->msPeriodog_fx_exp_fft = st->hFdCngEnc->msPeriodog_fx_exp_cldfb = st->hFdCngEnc->msPeriodog_fx_exp; - st->hFdCngEnc->energy_ho_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->energy_ho, NPART ); - st->hFdCngEnc->msNoiseEst_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); - st->hFdCngEnc->msNoiseEst_old_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msNoiseEst_old, NPART ); - floatToFixed_arrL( st->hFdCngEnc->msPeriodog, st->hFdCngEnc->msPeriodog_fx, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - floatToFixed_arrL( st->hFdCngEnc->energy_ho, st->hFdCngEnc->energy_ho_fx, 31 - st->hFdCngEnc->energy_ho_fx_exp, NPART ); - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - floatToFixed_arrL( st->hFdCngEnc->msNoiseEst_old, st->hFdCngEnc->msNoiseEst_old_fx, 31 - st->hFdCngEnc->msNoiseEst_old_fx_exp, NPART ); -#endif AdjustFirstSID_fx( st->hFdCngEnc->hFdCngCom->npart, st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog_fx_exp, st->hFdCngEnc->energy_ho_fx, &st->hFdCngEnc->energy_ho_fx_exp, st->hFdCngEnc->msNoiseEst_fx, &st->hFdCngEnc->msNoiseEst_fx_exp, st->hFdCngEnc->msNoiseEst_old_fx, &st->hFdCngEnc->msNoiseEst_old_fx_exp, &( st->hFdCngEnc->hFdCngCom->active_frame_counter ), st ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->energy_ho_fx, st->hFdCngEnc->energy_ho, 31 - st->hFdCngEnc->energy_ho_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_fx, st->hFdCngEnc->msNoiseEst, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); - fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_old_fx, st->hFdCngEnc->msNoiseEst_old, 31 - st->hFdCngEnc->msNoiseEst_old_fx_exp, NPART ); -#endif } /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 4796a9a7b..b31530d9f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -67,18 +67,19 @@ static void stereo_mode_combined_format_enc( const Encoder_Struct *st_ivas, CPE_ * Channel Pair Element (CPE) encoding routine *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_cpe_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - float data_f_ch0[], /* i : input signal for channel 0 */ - float data_f_ch1[], /* i : input signal for channel 1 */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ +ivas_error ivas_cpe_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { CPE_ENC_HANDLE hCPE; Encoder_State **sts; - int16_t n, n_CoreChannels; + Word16 n, n_CoreChannels; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion float old_inp_12k8[CPE_CHANNELS][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ float old_inp_16k[CPE_CHANNELS][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ @@ -105,8 +106,8 @@ ivas_error ivas_cpe_enc( float epsP[CPE_CHANNELS][M + 1]; /* LP prediction errors */ float lsp_new[CPE_CHANNELS][M]; /* LSPs at the end of the frame */ float lsp_mid[CPE_CHANNELS][M]; /* ISPs in the middle of the frame */ - int16_t vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ - int16_t attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ + Word16 vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ + Word16 attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ @@ -114,39 +115,38 @@ ivas_error ivas_cpe_enc( float voicing_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch gains */ Word16 pitch_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q6, fractional pitch values */ Word16 voicing_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q15, fractional pitch gains */ - int16_t loc_harm[CPE_CHANNELS]; /* harmonicity flag */ + Word16 loc_harm[CPE_CHANNELS]; /* harmonicity flag */ float cor_map_sum[CPE_CHANNELS]; /* speech/music clasif. parameter */ - int16_t vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ + Word16 vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ float currFlatness[CPE_CHANNELS] = { 0 }; /* flatness parameter */ #ifdef IVAS_FLOAT_FIXED Word16 currFlatness_fx[CPE_CHANNELS]; /* flatness parameter Q7 */ #endif float fft_buff[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ - int16_t tdm_ratio_idx, tdm_ratio_idx_SM; /* temp. TD stereo parameters */ - int16_t tdm_SM_or_LRTD_Pri; /* temp. TD stereo parameters */ -#ifndef IVAS_FLOAT_FIXED - float tdm_last_ratio; /* temp. TD stereo parameters */ -#endif - int16_t nb_bits; /* number of DFT stereo side bits */ + Word16 tdm_ratio_idx, tdm_ratio_idx_SM; /* temp. TD stereo parameters */ + Word16 tdm_SM_or_LRTD_Pri; /* temp. TD stereo parameters */ + + Word16 nb_bits; /* number of DFT stereo side bits */ float fr_bands[CPE_CHANNELS][2 * NB_BANDS]; /* energy in frequency bands */ float Etot_LR[CPE_CHANNELS]; /* total energy */ float lf_E[CPE_CHANNELS][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - int16_t localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ + Word16 localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ float band_energies_LR[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ float orig_input[CPE_CHANNELS][L_FRAME48k]; float Etot_last[CPE_CHANNELS]; Word16 Etot_last_fx[CPE_CHANNELS]; - int32_t tmp, input_Fs; - int16_t max_bwidth, ivas_format; + Word32 tmp, input_Fs; + Word16 max_bwidth, ivas_format; ENCODER_CONFIG_HANDLE hEncoderConfig; - int32_t ivas_total_brate; + Word32 ivas_total_brate; ivas_error error; - int32_t cpe_brate; - int32_t element_brate_ref; - int16_t last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ + Word32 cpe_brate; + Word32 element_brate_ref; + Word16 last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ error = IVAS_ERR_OK; + move32(); push_wmops( "ivas_cpe_enc" ); hCPE = st_ivas->hCPE[cpe_id]; @@ -158,6 +158,12 @@ ivas_error ivas_cpe_enc( ivas_total_brate = hEncoderConfig->ivas_total_brate; element_brate_ref = hCPE->element_brate; last_bits_frame_nominal = sts[0]->bits_frame_nominal; + move16(); + move16(); + move16(); + move32(); + move32(); + move32(); /*------------------------------------------------------------------* * Initialization - general @@ -167,6 +173,9 @@ ivas_error ivas_cpe_enc( tdm_ratio_idx = -1; tdm_ratio_idx_SM = -1; // tdm_last_ratio = 0; + move16(); + move16(); + move16(); set16_fx( pitch_fr_fx[0], 0, NB_SUBFR ); set16_fx( pitch_fr_fx[1], 0, NB_SUBFR ); @@ -183,13 +192,13 @@ ivas_error ivas_cpe_enc( * CPE initialization - core coder *-----------------------------------------------------------------*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { sts[n]->idchan = n; sts[n]->core = -1; sts[n]->core_brate = -1; /* updated in dtx() */ sts[n]->max_bwidth = max_bwidth; - if ( st_ivas->hMCT == NULL ) /*already updated before CPE call*/ + IF( st_ivas->hMCT == NULL ) /*already updated before CPE call*/ { sts[n]->input_bwidth = sts[n]->last_input_bwidth; /* updated in BWD */ sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD */ @@ -197,15 +206,19 @@ ivas_error ivas_cpe_enc( sts[n]->rate_switching_reset = 0; } - 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 ); + Copy32( data_fx_ch0, sts[0]->input32_fx, input_frame ); // Q(q_data_fx) + Copy_Scale_sig32_16( sts[0]->input32_fx, sts[0]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( sts[0]->input32_fx, sts[0]->input, q_data_fx, input_frame ); #endif - if ( data_f_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ + IF( data_fx_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 ); + Copy32( data_fx_ch1, sts[1]->input32_fx, input_frame ); // Q(q_data_fx) + Copy_Scale_sig32_16( sts[1]->input32_fx, sts[1]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( sts[1]->input32_fx, sts[1]->input, q_data_fx, input_frame ); #endif } @@ -213,20 +226,14 @@ ivas_error ivas_cpe_enc( * Stereo technology selection * Front-VAD on input L and R channels *----------------------------------------------------------------*/ - - if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) + test(); + IF( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { -#ifdef IVAS_FLOAT_FIXED - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); -#else hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); -#endif } -#ifdef IVAS_FLOAT_FIXED + stereo_mode_combined_format_enc_fx( st_ivas, hCPE ); -#else - stereo_mode_combined_format_enc( st_ivas, hCPE ); -#endif + #ifdef IVAS_FLOAT_FIXED Word16 Q_inp = 0; move16(); @@ -271,7 +278,7 @@ ivas_error ivas_cpe_enc( } #endif - if ( ( error = front_vad_fx( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands_fx, Etot_LR_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_LR_fx, NULL, NULL, Q_inp, Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) + IF( ( error = front_vad_fx( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands_fx, Etot_LR_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_LR_fx, NULL, NULL, Q_inp, Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -450,17 +457,17 @@ ivas_error ivas_cpe_enc( * Time Domain Transient Detector *---------------------------------------------------------------*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - if ( sts[n]->hTranDet == NULL ) + IF( sts[n]->hTranDet == NULL ) { currFlatness[n] = 0; - continue; + CONTINUE; } - if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) ) + test(); + IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr16( sts[n]->input, sts[n]->input_fx, -1, input_frame ); #endif @@ -469,23 +476,18 @@ ivas_error ivas_cpe_enc( sts[n]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); move16(); -#else - RunTransientDetection( sts[n]->input, input_frame, sts[n]->hTranDet ); -#endif } -#ifndef IVAS_FLOAT_FIXED - currFlatness[n] = GetTCXAvgTemporalFlatnessMeasure( sts[n]->hTranDet, NSUBBLOCKS, 0 ); -#else + currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS currFlatness[n] = fix16_to_float( currFlatness_fx[n], Q7 ); -#endif #endif } /* Synchonize detection for downmix-based stereo */ - if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -502,37 +504,16 @@ ivas_error ivas_cpe_enc( * Configuration of stereo encoder *----------------------------------------------------------------*/ - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { /* Force to MODE1 in IVAS */ sts[n]->codec_mode = MODE1; + move16(); sts[n]->element_mode = hCPE->element_mode; + move16(); } - -#ifndef IVAS_FLOAT_FIXED - if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || - ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) || sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ - { - if ( st_ivas->hQMetaData != NULL ) - { - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) - { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.70f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); - } - else - { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); - } - } - else - { - /* note; "bits_frame_nominal" needed in TD stereo as well */ - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); - } - } -#else test(); test(); test(); @@ -561,22 +542,17 @@ ivas_error ivas_cpe_enc( stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } -#endif - if ( hCPE->element_mode == IVAS_CPE_TD ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - if ( hCPE->hStereoTD->tdm_LRTD_flag ) + IF( hCPE->hStereoTD->tdm_LRTD_flag ) { sts[0]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); sts[1]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); } - else + ELSE { -#ifndef IVAS_FLOAT_FIXED - stereo_dft_config( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); -#else stereo_dft_config_fx( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); -#endif } } @@ -972,7 +948,7 @@ ivas_error ivas_cpe_enc( { if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) { - reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); + reset_metadata_spatial_fx( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); } } @@ -1007,9 +983,10 @@ ivas_error ivas_cpe_enc( #endif /* Reset metadata */ - if ( sts[0]->cng_sba_flag || ( ivas_format == SBA_FORMAT ) ) + test(); + IF( sts[0]->cng_sba_flag || EQ_32( ivas_format, SBA_FORMAT ) ) { - reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); + reset_metadata_spatial_fx( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); } } @@ -2469,6 +2446,7 @@ ivas_error create_cpe_enc_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; @@ -2476,6 +2454,10 @@ ivas_error create_cpe_enc_fx( element_mode_init = hEncoderConfig->element_mode_init; input_Fs = hEncoderConfig->input_Fs; max_bwidth = hEncoderConfig->max_bwidth; + move16(); + move16(); + move32(); + move16(); /*-----------------------------------------------------------------* * Allocate CPE handle @@ -2495,6 +2477,11 @@ ivas_error create_cpe_enc_fx( hCPE->last_element_brate = hCPE->element_brate; hCPE->element_mode = element_mode_init; hCPE->last_element_mode = element_mode_init; + move16(); + move32(); + move32(); + move16(); + move16(); hCPE->hStereoDft = NULL; hCPE->hStereoTD = NULL; @@ -2508,6 +2495,7 @@ ivas_error create_cpe_enc_fx( hCPE->hFrontVad[1] = NULL; hCPE->brate_surplus = 0; + move32(); /*-----------------------------------------------------------------* * Input memory buffer: allocate and initialize @@ -2515,6 +2503,10 @@ ivas_error create_cpe_enc_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { + test(); + test(); + test(); + test(); IF( EQ_16( ivas_format, STEREO_FORMAT ) || EQ_16( ivas_format, MASA_FORMAT ) || ( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { IF( ( hCPE->input_mem_fx[n] = (Word16 *) malloc( sizeof( Word16 ) * NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ) ) == NULL ) @@ -2531,7 +2523,7 @@ ivas_error create_cpe_enc_fx( } -#if 1 // TODO: To be removed later +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // TODO: To be removed later for ( n = 0; n < CPE_CHANNELS; n++ ) { if ( ivas_format == STEREO_FORMAT || ivas_format == MASA_FORMAT || ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ivas_format == MASA_ISM_FORMAT ) @@ -2559,11 +2551,7 @@ ivas_error create_cpe_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n" ) ); } -#ifndef IVAS_FLOAT_FIXED - stereo_classifier_init( hCPE->hStereoClassif ); -#else stereo_classifier_init_fx( hCPE->hStereoClassif ); -#endif /*-----------------------------------------------------------------* * Metadata: allocate and initialize @@ -2598,7 +2586,9 @@ ivas_error create_cpe_enc_fx( { st->total_brate = L_shr( hCPE->element_brate, CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } + move32(); st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); IF( ( error = init_encoder_ivas_fx( st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate ) ) != IVAS_ERR_OK ) { @@ -2608,6 +2598,7 @@ ivas_error create_cpe_enc_fx( IF( st->hFdCngEnc != NULL ) { st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); + move32(); } hCPE->hCoreCoder[n] = st; @@ -2619,6 +2610,7 @@ ivas_error create_cpe_enc_fx( IF( hEncoderConfig->Opt_DTX_ON ) { + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { IF( ( hCPE->hStereoCng = (STEREO_CNG_ENC_HANDLE) malloc( sizeof( STEREO_CNG_ENC ) ) ) == NULL ) @@ -2634,6 +2626,7 @@ ivas_error create_cpe_enc_fx( hCPE->hStereoCng = NULL; } + test(); IF( hEncoderConfig->Opt_DTX_ON && EQ_16( element_mode_init, IVAS_CPE_MDCT ) ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) @@ -2696,7 +2689,7 @@ ivas_error create_cpe_enc_fx( * TD stereo initialization *-----------------------------------------------------------------*/ - IF( hCPE->element_mode == IVAS_CPE_TD ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { IF( ( hCPE->hStereoTD = (STEREO_TD_ENC_DATA_HANDLE) malloc( sizeof( STEREO_TD_ENC_DATA ) ) ) == NULL ) { @@ -2709,7 +2702,7 @@ ivas_error create_cpe_enc_fx( /*-----------------------------------------------------------------* * MDCT stereo initialization *-----------------------------------------------------------------*/ - + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) { IF( ( hCPE->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) @@ -2718,8 +2711,13 @@ ivas_error create_cpe_enc_fx( } initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); + test(); + test(); hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + move16(); + test(); + test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { IF( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 17cc8661b..883fa1223 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -630,7 +630,7 @@ ivas_error ivas_enc( return error; } #else -ivas_error ivas_enc( +ivas_error ivas_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 *data, /* i : input signal Q0 */ const Word16 n_samples /* i : number of input samples */ @@ -642,9 +642,6 @@ ivas_error ivas_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; BSTR_ENC_HANDLE hMetaData; Word16 nb_bits_metadata[MAX_SCE + 1]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; -#endif Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; Word32 ivas_total_brate; ivas_error error; @@ -687,9 +684,6 @@ ivas_error ivas_enc( FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - data_f[n] = st_ivas->p_data_f[n]; // float initialization to be removed -#endif data_fx[n] = st_ivas->p_data_fx[n]; } @@ -701,22 +695,16 @@ ivas_error ivas_enc( { FOR( i = 0; i < n_samples_chan; i++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - data_f[n][i] = (float) data[i * nchan_inp + n]; // float initialization to be removed -#endif data_fx[n][i] = L_mult0( data[i * nchan_inp + n], shl( 1, st_ivas->q_data_fx ) ); move32(); } - n = add( n, 1 ); + n++; } IF( LT_16( n_samples_chan, input_frame ) ) { FOR( n = 0; n < nchan_inp; n++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); // float initialization to be removed -#endif set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) ); } } @@ -757,14 +745,6 @@ ivas_error ivas_enc( } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < n; i++ ) - { - fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); - } -#endif // 1 - - /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ @@ -777,7 +757,8 @@ ivas_error ivas_enc( IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { st_ivas->hCPE[0]->element_brate = ivas_total_brate; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) + move32(); + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) { return error; } @@ -785,54 +766,41 @@ ivas_error ivas_enc( ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { /* select ISM format mode; reconfigure the ISM format encoder */ - if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) - { - floatToFixed_arr32( data_f[i], data_fx[i], Q14, input_frame ); - } - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) + FOR( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { + scale_sig32( data_fx[i], input_frame, sub( Q14, st_ivas->q_data_fx ) ); // Q11 -> Q14 scale_sig32( st_ivas->hParamIsm->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hParamIsm->hFbMixer->fb_cfg->prior_input_length, sub( Q14, st_ivas->hParamIsm->hFbMixer->q_ppFilterbank_prior_input_fx[i] ) ); st_ivas->hParamIsm->hFbMixer->q_ppFilterbank_prior_input_fx[i] = Q14; + move16(); } -#endif ivas_param_ism_enc_fx( st_ivas, data_fx, input_frame, Q14 ); /* Stereo DMX generation */ ivas_param_ism_stereo_dmx_fx( st_ivas, data_fx, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) + FOR( i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { - fixedToFloat_arrL32( data_fx[i], data_f[i], Q14, input_frame ); + scale_sig32( data_fx[i], input_frame, sub( st_ivas->q_data_fx, Q14 ) ); // Q14 -> Q11 } -#endif -#else - ivas_param_ism_enc( st_ivas, data_f, input_frame ); - - /* Stereo DMX generation */ - ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); -#endif /* Core coding of Stereo DMX */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MODE_DISC ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) { /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -888,7 +856,7 @@ ivas_error ivas_enc( } ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - IF( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } @@ -896,27 +864,27 @@ ivas_error ivas_enc( IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - ivas_sba_getTCs( data_f, st_ivas, input_frame ); + ivas_sba_getTCs_fx( data_fx, st_ivas, input_frame ); } /* core-coding of transport channels */ IF( EQ_16( st_ivas->nSCE, 1 ) ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - IF( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -924,8 +892,8 @@ ivas_error ivas_enc( } ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - float *data_separated_object; Word32 *data_separated_object_fx; + Word16 q_data_separated_object; Word16 idx_separated_object; Word16 flag_omasa_ener_brate; @@ -939,13 +907,7 @@ ivas_error ivas_enc( v_multc_fixed( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame ); Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) - { - v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); - mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); - } -#endif + /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); @@ -958,8 +920,9 @@ ivas_error ivas_enc( idx_separated_object = 0; move16(); - data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; - data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; + data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; // Q(st_ivas->q_data_fx) + q_data_separated_object = st_ivas->q_data_fx; + move16(); /* put audio object data in SCE's */ IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) @@ -982,13 +945,9 @@ ivas_error ivas_enc( /* Estimate MASA parameters for the objects */ ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) - { - fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); - } - fixedToFloat_arrL( data_separated_object_fx, data_separated_object, st_ivas->q_data_fx, input_frame ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + + q_data_separated_object = st_ivas->q_data_fx; + move16(); } /* Encode ISMs transport channels */ @@ -996,14 +955,14 @@ ivas_error ivas_enc( move16(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_separated_object_fx, q_data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { return error; } } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - IF( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, &data_separated_object_fx, q_data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1013,7 +972,7 @@ ivas_error ivas_enc( flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); /* Analysis, decision about bitrates per channel & core coding */ - IF( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -1046,93 +1005,98 @@ ivas_error ivas_enc( ); /* Encode MASA transport channels */ - IF( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( ivas_cpe_enc_fx( st_ivas, 0, data_fx[n], data_fx[n + 1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - Word16 planar_sba_orig; + Word16 planar_sba_orig, nchan; planar_sba_orig = hEncoderConfig->sba_planar; -#ifdef IVAS_FLOAT_FIXED + move16(); + /* Analyze objects and determine needed audio signals */ ivas_osba_enc_fx( st_ivas->hOSba, st_ivas->hIsmMetaData, data_fx, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar, &st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 nchan; - if ( st_ivas->ism_mode == ISM_MODE_NONE ) - nchan = ( st_ivas->sba_analysis_order + 1 ) * ( st_ivas->sba_analysis_order + 1 ); - else + + IF( st_ivas->ism_mode == ISM_MODE_NONE ) + { + nchan = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); + } + ELSE + { nchan = hEncoderConfig->nchan_ism; - for ( n = 0; n < nchan; n++ ) + move16(); + } + FOR( n = 0; n < nchan; n++ ) { - fixedToFloat_arrL32( data_fx[n], data_f[n], st_ivas->q_data_fx, input_frame ); + scale_sig32( data_fx[n], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // Q(st_ivas->q_data_fx) -> Q11 } -#endif -#else - /* Analyze objects and determine needed audio signals */ - ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); + st_ivas->q_data_fx = Q11; + move16(); -#endif - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( st_ivas->ism_mode == ISM_MODE_NONE ) { /*once SBA and ISM are combined into SBA signal then disable planar flag*/ hEncoderConfig->sba_planar = 0; - if ( st_ivas->nchan_transport == 1 ) + move16(); + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; } - else + ELSE { hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; } /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } hEncoderConfig->sba_planar = planar_sba_orig; + move16(); } - else + ELSE { n = hEncoderConfig->nchan_ism; + move16(); hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_fx( st_ivas, &data_fx[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } /* get SBA TCs */ - ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); + ivas_sba_getTCs_fx( &data_fx[n], st_ivas, input_frame ); } /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -1146,14 +1110,14 @@ ivas_error ivas_enc( return error; } - // hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + /* hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; */ IF( st_ivas->nSCE > 0 ) { - hMetaData = st_ivas->hSCE[sub( st_ivas->nSCE, 1 )]->hMetaData; + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; } ELSE { - hMetaData = st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hMetaData; + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; } /* LFE low pass filter */ @@ -1173,13 +1137,10 @@ ivas_error ivas_enc( ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // To be removed - fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); -#endif IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1187,38 +1148,21 @@ ivas_error ivas_enc( ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { /* encode MC ParamUpmix parameters and write bitstream */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 4; i < 12; i++ ) - { - for ( int l = 0; l < input_frame; l++ ) - { - data_fx[i][l] = floatToFixed( data_f[i][l], st_ivas->q_data_fx ); - } - } -#endif ivas_mc_paramupmix_enc_fx( st_ivas, hMetaData, data_fx, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 4; i < 12; i++ ) + /* st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; */ + IF( st_ivas->nSCE > 0 ) { - for ( int l = 0; l < input_frame; l++ ) - { - data_f[i][l] = fixedToFloat( data_fx[i][l], st_ivas->q_data_fx ); - } + st_ivas->hLFE->hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; + } + ELSE + { + st_ivas->hLFE->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; } -#endif -#else - ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - -#endif - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); -#if 1 // To be removed - fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); -#endif - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1226,40 +1170,18 @@ ivas_error ivas_enc( ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* encode Parametric MC parameters and write bitstream */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ ) - { - for ( int l = 0; l < input_frame; l++ ) - { - data_fx[i][l] = floatToFixed( data_f[i][l], st_ivas->q_data_fx ); - } - } -#endif ivas_param_mc_enc_fx( st_ivas, hMetaData, data_fx, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ ) - { - for ( int l = 0; l < input_frame; l++ ) - { - data_f[i][l] = fixedToFloat( data_fx[i][l], st_ivas->q_data_fx ); - } - } -#endif -#else - ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); -#endif - if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1274,18 +1196,20 @@ ivas_error ivas_enc( FOR( i = 0; i < nchan_inp; i++ ) { - scale_sig32( data_fx[i], input_frame, Q8 - Q11 ); // Q11 -> Q8 + scale_sig32( data_fx[i], input_frame, sub( Q8, st_ivas->q_data_fx ) ); // st_ivas->q_data_fx -> Q8 } st_ivas->q_data_fx = Q8; move16(); ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_inp; i++ ) + + FOR( i = 0; i < nchan_inp; i++ ) { - fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); + scale_sig32( data_fx[i], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // st_ivas->q_data_fx -> Q11 } -#endif + st_ivas->q_data_fx = Q11; + move16(); + /* Scaling down the Q-factor of energy_ratio_fx from Q31 to Q30 */ FOR( i = 0; i < st_ivas->hMcMasa->nbands; i++ ) { @@ -1300,14 +1224,14 @@ ivas_error ivas_enc( IF( st_ivas->hMcMasa->separateChannelEnabled ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[2], st_ivas->q_data_fx, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1316,14 +1240,14 @@ ivas_error ivas_enc( { IF( EQ_16( st_ivas->nSCE, 1 ) ) { - IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } @@ -1337,6 +1261,7 @@ ivas_error ivas_enc( *----------------------------------------------------------------*/ hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); #ifdef DEBUG_MODE_INFO { diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index af515d836..7bf6300f9 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -560,6 +560,14 @@ ivas_error front_vad_create( } #ifdef IVAS_FLOAT_FIXED hFrontVad->delay_buf_fx = NULL; + IF( GT_16( hFrontVad->delay_samples, 0 ) ) + { + IF( ( hFrontVad->delay_buf_fx = (Word16 *) malloc( hFrontVad->delay_samples * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD delay buffer\n" ) ); + } + set16_fx( hFrontVad->delay_buf_fx, 0, hFrontVad->delay_samples ); + } #endif *hFrontVad_out = hFrontVad; @@ -700,35 +708,27 @@ void front_vad_destroy_fx( * Standalone front-VAD module for SPAR *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error front_vad_spar( - SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ - const float *omni_in, /* i : omnidirectional input signal */ - ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ - const int16_t input_frame /* i : input frame length */ +ivas_error front_vad_spar_fx( + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const Word32 *omni_in, /* i : omnidirectional input signal Q11 */ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const Word16 input_frame /* i : input frame length */ ) { FRONT_VAD_ENC_HANDLE hFrontVad; - float input[L_FRAME48k] = { 0 }; Word16 input_fx[L_FRAME48k]; - int16_t vad_flag_dtx[1]; - float fr_bands[1][2 * NB_BANDS]; + Word16 vad_flag_dtx[1]; Word32 fr_bands_fx[1][2 * NB_BANDS] = { { 0 } }; - float Etot[1]; Word16 Etot_fx[1]; - float lf_E[1][2 * VOIC_BINS]; - int16_t localVAD_HE_SAD[1]; - int16_t vad_hover_flag[1]; - float band_energies[2 * NB_BANDS]; + Word16 localVAD_HE_SAD[1]; + Word16 vad_hover_flag[1]; Word32 band_energies_fx[2 * NB_BANDS]; - int16_t high_lpn_flag; + Word16 high_lpn_flag; Encoder_State *st; - float tmpN[NB_BANDS], tmpE[NB_BANDS]; Word32 tmpN_fx[NB_BANDS] = { 0 }; Word32 tmpE_fx[NB_BANDS] = { 0 }; - float corr_shift; Word16 corr_shift_fx; -#if 1 Word32 res_energy_fx; Word16 A_fx[NB_SUBFR16k * ( M + 1 )], Aw_fx[NB_SUBFR16k * ( M + 1 )]; @@ -738,18 +738,9 @@ ivas_error front_vad_spar( Word16 alw_voicing_fx[2]; Word16 lsp_new_fx[M]; Word16 lsp_mid_fx[M]; -#endif - float A[NB_SUBFR16k * ( M + 1 )], Aw[NB_SUBFR16k * ( M + 1 )]; - float epsP[M + 1]; - float lsp_new[M]; - float lsp_mid[M]; - int16_t alw_pitch_lag_12k8[2]; - float alw_voicing[2]; - float cor_map_sum; - float non_staX; - int16_t loc_harm; - float S_map[L_FFT / 2]; -#if 1 + + Word16 alw_pitch_lag_12k8[2]; + Word16 loc_harm; Word16 epsP_h[M + 1]; Word16 epsP_l[M + 1]; Word32 lf_E_fx[1][2 * VOIC_BINS]; @@ -758,63 +749,71 @@ ivas_error front_vad_spar( Word16 Q_sp_div; Word16 non_staX_fx; Word16 sp_floor; -#else - float ncharX; - float sp_div, dummy; -#endif + Word16 cor_map_sum_fx; Word16 dummy_fx; Word16 S_map_fx[L_FFT / 2]; Word16 relE_fx; Word16 *wsp_fx; - float *inp_12k8; -#if 1 Word16 *inp_12k8_fx; -#endif - float old_wsp[L_WSP]; + Word16 old_wsp_fx[L_WSP]; - float *wsp; + Word16 flag_spitch; + Word32 PS_fx[L_FRAME / 2]; + Word16 s, Q_inp; + Word16 tmp; + Word16 old_pitch; + ivas_error error; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + float input[L_FRAME48k] = { 0 }; + float fr_bands[1][2 * NB_BANDS]; + float Etot[1]; + float lf_E[1][2 * VOIC_BINS]; + float band_energies[2 * NB_BANDS]; + float tmpN[NB_BANDS], tmpE[NB_BANDS]; + float corr_shift; + float A[NB_SUBFR16k * ( M + 1 )], Aw[NB_SUBFR16k * ( M + 1 )]; + float epsP[M + 1]; + float lsp_new[M]; + float lsp_mid[M]; + float alw_voicing[2]; + float cor_map_sum; + float non_staX; + float S_map[L_FFT / 2]; + float *inp_12k8; + float old_wsp[L_WSP]; + float *wsp; float relE; - - int16_t flag_spitch; float PS[L_FRAME / 2]; - Word32 PS_fx[L_FRAME / 2]; - int16_t old_pitch; - ivas_error error; -#ifdef DUMP_VAD_SPAR - FILE *fptmpN_fl = fopen( "tmpN_fl.txt", "ab+" ); - FILE *fptmpE_fl = fopen( "tmpE_fl.txt", "ab+" ); - FILE *fpbckr_fl = fopen( "bckr_fl.txt", "ab+" ); - - FILE *fptmpN_fx = fopen( "tmpN_fx.txt", "ab+" ); - FILE *fptmpE_fx = fopen( "tmpE_fx.txt", "ab+" ); - FILE *fpbckr_fx = fopen( "bckr_fx.txt", "ab+" ); #endif push_wmops( "front_vad_SPAR" ); error = IVAS_ERR_OK; + move32(); hFrontVad = hSpar->hFrontVad; st = hSpar->hCoreCoderVAD; - if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_total_brate <= SBA_DTX_BITRATE_THRESHOLD ) + test(); + IF( hEncoderConfig->Opt_DTX_ON && LE_32( hEncoderConfig->ivas_total_brate, SBA_DTX_BITRATE_THRESHOLD ) ) { /*------------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ inp_12k8 = hFrontVad->buffer_12k8; Word16 Q_bands = Q31; -#if 1 Word16 Q_inp_12k8 = Q9; -#endif -#if 1 + move16(); + move16(); + inp_12k8_fx = hFrontVad->buffer_12k8_fx; -#endif mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q9, L_WSP_MEM ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q9, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q9, 3 ); +#endif MVR2R_WORD16( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp = old_wsp + L_WSP_MEM; @@ -822,19 +821,40 @@ ivas_error front_vad_spar( st->core_brate = -1; /* updated in dtx() */ st->input_bwidth = st->last_input_bwidth; + move32(); + move16(); /*------------------------------------------------------------------* * compensate for SPAR filterbank delay *-----------------------------------------------------------------*/ Q_bands = Q9; + move16(); st->input = input; st->input_fx = input_fx; - mvr2r( omni_in, st->input, input_frame ); - delay_signal_float( st->input, input_frame, hFrontVad->delay_buf, hFrontVad->delay_samples ); - Word16 Q_inp; - Q_inp = Q_factor_arr( st->input, L_FRAME48k ); - floatToFixed_arr( st->input, st->input_fx, Q_inp, L_FRAME48k ); + Copy_Scale_sig32_16( omni_in, st->input_fx, input_frame, Q16 - Q11 ); + delay_signal( st->input_fx, input_frame, hFrontVad->delay_buf_fx, hFrontVad->delay_samples ); + + /* Scaling only if the omni_in buffer contains non-zero values */ + maximum_abs_16_fx( st->input_fx, input_frame, &tmp ); + IF( tmp != 0 ) + { + s = norm_s( tmp ); + } + ELSE + { + s = 15; + move16(); + } + IF( tmp != 0 ) + { + Scale_sig( st->input_fx, input_frame, s ); + } + Q_inp = s; + move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->input_fx, st->input, Q_inp, input_frame ); +#endif Word16 Q_add = 0; move16(); /*------------------------------------------------------------------* @@ -866,7 +886,7 @@ ivas_error front_vad_spar( floatToFixed_arrL( &band_energies[0], &band_energies_fx[0], Q_new_old + QSCALE + 2, 40 ); #endif #endif - if ( ( error = front_vad_fx( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands_fx, Etot_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_fx, &PS_fx[0], &st->lgBin_E_fx[0], Q_inp, &Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) + IF( ( error = front_vad_fx( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands_fx, Etot_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_fx, &PS_fx[0], &st->lgBin_E_fx[0], Q_inp, &Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -889,60 +909,45 @@ ivas_error front_vad_spar( Word32 e_min_scaled; e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands, QSCALE ) ) ), 1 ), 1 ); - // floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); - // Q_bands = Q_factor_arrL( fr_bands[0], 2 * NB_BANDS ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arrL( fr_bands[0], fr_bands_fx[0], Q_bands + QSCALE, 2 * NB_BANDS ); floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_bands + QSCALE, NB_BANDS ); #ifndef MSAN_FIX floatToFixed_arrL( tmpE, tmpE_fx, Q_bands + QSCALE, NB_BANDS ); #endif Etot_fx[0] = (Word16) ( Etot[0] * ONE_IN_Q8 ); - noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); -#ifdef DUMP_VAD_SPAR - for ( Word16 i = 0; i < 20; i++ ) - { - fprintf( fptmpN_fl, "%f\n", tmpN[i] ); - fprintf( fptmpE_fl, "%f\n", tmpE[i] ); - fprintf( fpbckr_fl, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); - } #endif - // fixedToFloat_arrL( fr_bands_fx[0], fr_bands[0], Q_bands, 2 * NB_BANDS ); + noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, e_min_scaled ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( hFrontVad->hNoiseEst->bckr_fx, hFrontVad->hNoiseEst->bckr, Q_bands + Q7, NB_BANDS ); fixedToFloat_arrL( tmpN_fx, tmpN, Q_bands + QSCALE, 20 ); fixedToFloat_arrL( tmpE_fx, tmpE, Q_bands + QSCALE, 20 ); -#ifdef DUMP_VAD_SPAR - for ( Word16 i = 0; i < 20; i++ ) - { - fprintf( fptmpN_fx, "%f\n", tmpN[i] ); - fprintf( fptmpE_fx, "%f\n", tmpE[i] ); - fprintf( fpbckr_fx, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); - } #endif - // corr_shift = correlation_shift( hFrontVad->hNoiseEst->totalNoise ); corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS corr_shift = fixedToFloat( corr_shift_fx, Q15 ); -#if 1 Q_inp_12k8 = Q_factor_arr( inp_12k8, 3 * L_FRAME / 2 ); floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); - dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); -#else - dtx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); #endif + dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); + /* linear prediction 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]; -#if 0 - analy_lp( inp_12k8, L_FRAME, L_LOOK_12k8, &res_energy, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */ ); -#else - // analy_lp( inp_12k8, L_FRAME, L_LOOK_12k8, &res_energy, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */ ); - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_r[2] = { 0 }; floatToFixed_arr( alw_voicing, alw_voicing_fx, Q15, 2 ); Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8 - 90, 3 * L_FRAME / 2 + 90 ); floatToFixed_arr( inp_12k8 - 90, inp_12k8_fx - 90, Q_inp_12k8, 3 * L_FRAME / 2 + 90 ); +#endif + analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( Word16 i = 0; i <= M; i++ ) { epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); @@ -955,10 +960,8 @@ ivas_error front_vad_spar( #endif relE = Etot[0] - st->lp_speech; -#if 0 - find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1_FLT, L_LOOK_12k8 ); -#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8-M, (3 * L_FRAME / 2)+M ); floatToFixed_arr( inp_12k8 - M, inp_12k8_fx - M, Q_inp_12k8, ( 3 * L_FRAME / 2 ) + M ); #ifdef MSAN_FIX @@ -966,26 +969,24 @@ ivas_error front_vad_spar( #else floatToFixed_arr( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); #endif // MSAN_FIX - st->mem_wsp_fx = (Word16) floatToFixed( st->mem_wsp, Q_inp_12k8 ); - // find_wsp_fx( A_fx, inp_12k8_fx, wsp_fx, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_LOOK_12k8, L_SUBFR, Aw_fx, GAMMA1, NB_SUBFR ); +#endif + ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( wsp_fx, wsp, Q_inp_12k8, 368 ); fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); #endif - if ( st->vad_flag == 0 ) + IF( st->vad_flag == 0 ) { /* reset the OL pitch tracker memories during inactive frames */ -#if 0 - pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); -#else pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); -#endif } old_pitch = st->pitch[1]; -#if 1 +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); floatToFixed_arr( wsp, wsp_fx, Q8, 368 ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q8, 115 ); @@ -996,16 +997,15 @@ ivas_error front_vad_spar( corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); relE_fx = (Word16) floatToFixed( relE, Q8 ); +#endif pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); // 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_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q8, 115 ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q8, 3 ); st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); -#else - 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_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; @@ -1125,15 +1125,6 @@ ivas_error front_vad_spar( hSpar->front_vad_dtx_flag = 0; hSpar->force_front_vad = 0; } -#ifdef DUMP_VAD_SPAR - fclose( fptmpN_fl ); - fclose( fptmpE_fl ); - fclose( fpbckr_fl ); - - fclose( fptmpN_fx ); - fclose( fptmpE_fx ); - fclose( fpbckr_fx ); -#endif pop_wmops(); return error; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 2378bd8d4..3c246c0ad 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -887,10 +887,17 @@ ivas_error ivas_init_encoder( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifndef IVAS_FLOAT_FIXED if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } +#else + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif if ( ivas_format == SBA_FORMAT && st_ivas->hEncoderConfig->Opt_DTX_ON ) { @@ -947,6 +954,7 @@ ivas_error ivas_init_encoder( } ism_total_brate = 0; +#ifndef IVAS_FLOAT_FIXED for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; @@ -955,6 +963,16 @@ ivas_error ivas_init_encoder( return error; } } +#else + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { @@ -1040,6 +1058,7 @@ ivas_error ivas_init_encoder( if ( st_ivas->ism_mode == ISM_MODE_NONE ) { /* allocate and initialize SBA core-coders */ +#ifndef IVAS_FLOAT_FIXED if ( st_ivas->nchan_transport == 1 ) { if ( ( error = create_sce_enc( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) @@ -1047,6 +1066,15 @@ ivas_error ivas_init_encoder( return error; } } +#else + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) + { + IF( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { @@ -1233,6 +1261,7 @@ ivas_error ivas_init_encoder( ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #endif +#ifndef IVAS_FLOAT_FIXED for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_enc( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) @@ -1240,6 +1269,15 @@ ivas_error ivas_init_encoder( return error; } } +#else + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 47423d868..e81b89e13 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -419,12 +419,13 @@ ivas_error ivas_ism_enc( return error; } #else -ivas_error ivas_ism_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - float *data[], /* i : input signal [channels][samples] */ - const Word16 input_frame, /* i : input frame length per channel */ - Word16 *nb_bits_metadata, /* i : number of metadata bits */ - const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +ivas_error ivas_ism_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data[], /* i : input signal [channels][samples] Q(q_data) */ + Word16 q_data, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + Word16 *nb_bits_metadata, /* i : number of metadata bits */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ) { SCE_ENC_HANDLE hSCE; @@ -526,8 +527,8 @@ ivas_error ivas_ism_enc( /*------------------------------------------------------------------* * Initialization - general *-----------------------------------------------------------------*/ - - mvr2r( data[sce_id], st->input, input_frame ); + Copy32( data[sce_id], st->input32_fx, input_frame ); // Q(q_data) + Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( Q16 - 1, q_data ) ); // Q(q_data) -> Q(-1) st->element_mode = IVAS_SCE; move16(); @@ -554,28 +555,20 @@ ivas_error ivas_ism_enc( /*---------------------------------------------------------------* * Time Domain Transient Detector *---------------------------------------------------------------*/ - -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr16( st->input, st->input_fx, -1, input_frame ); + fixedToFloat_arrL( st->input32_fx, st->input, q_data, input_frame ); #endif RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); move16(); -#else - RunTransientDetection( st->input, input_frame, st->hTranDet ); -#endif -#ifdef IVAS_FLOAT_FIXED currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS currFlatness[0] = me2f_16( currFlatness_fx[0], 15 - Q7 ); #endif -#else - currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); -#endif /*----------------------------------------------------------------* * Configuration of core encoder @@ -620,10 +613,10 @@ ivas_error ivas_ism_enc( /* compute the dominant sce_id using long term energy */ for ( int j = 0; j < st_ivas->nchan_transport; j++ ) { - IF( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) - floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ + if ( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) + floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ } - FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) { relE_fx[sce_id][0] = float_to_fix16( relE[sce_id][0], Q8 ); } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 4750162a7..49ae8f695 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -154,7 +154,7 @@ static void set_mct_enc_params( * cpe_id 1: L=data[4] R=data[5] * cpe_id 2: L=data[2] (mid) R=NULL *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void map_input_to_cpe_channels( const Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ float *pdata[MAX_INPUT_CHANNELS], /* o : mapped input pointers */ @@ -203,7 +203,7 @@ static void map_input_to_cpe_channels( return; } - +#endif static void map_input_to_cpe_channels_ivas_fx( const Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ Word32 *pdata[MAX_INPUT_CHANNELS], /* o : mapped input pointers */ @@ -386,11 +386,12 @@ ivas_error ivas_mct_enc( return error; } #else -ivas_error ivas_mct_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ +ivas_error ivas_mct_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[MCT_MAX_CHANNELS], /* i : input signal buffers Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { Word16 n, cpe_id; @@ -405,7 +406,7 @@ ivas_error ivas_mct_enc( Word16 max_bwidth; Word32 ivas_total_brate; ivas_error error; - float *pdata[MAX_INPUT_CHANNELS]; + Word32 *pdata_fx[MAX_INPUT_CHANNELS]; error = IVAS_ERR_OK; move32(); @@ -428,7 +429,7 @@ ivas_error ivas_mct_enc( FOR( n = 0; n < CPE_CHANNELS; n++ ) { hCPE = st_ivas->hCPE[cpe_id]; -#if 1 // float initialization to be removed +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS hMCT->p_mdst_spectrum_long[cpe_id][n] = mdst_spectrum_long[cpe_id][n]; hMCT->p_orig_spectrum_long[cpe_id][n] = orig_spectrum_long[cpe_id][n]; #ifdef MSAN_FIX @@ -493,50 +494,12 @@ ivas_error ivas_mct_enc( switch_bw = set_bw_mct_fx( st_ivas->hCPE, st_ivas->nCPE ); /*for MC and MCT remove pointer to LFE input that has been processed separately */ -#ifndef IVAS_FLOAT_FIXED - map_input_to_cpe_channels( st_ivas, pdata, data ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 *pdata_fx[MAX_INPUT_CHANNELS]; - Word32 data_fx_tmp[MCT_MAX_CHANNELS][960]; - Word32 *data_fx[MCT_MAX_CHANNELS]; - Word16 nchan_transport; - for ( int i = 0; i < MAX_INPUT_CHANNELS; i++ ) - { - pdata_fx[i] = NULL; - pdata[i] = NULL; - } - Word16 len = (Word16) ( st_ivas->hEncoderConfig->input_Fs / FRAMES_PER_SEC ); - nchan_transport = st_ivas->nchan_transport; - if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) - { - nchan_transport += st_ivas->hEncoderConfig->nchan_ism; - } - - for ( int i = 0; i < nchan_transport; i++ ) - { - data_fx[i] = data_fx_tmp[i]; - floatToFixed_arrL( data[i], data_fx[i], Q11, len ); - } - map_input_to_cpe_channels( st_ivas, pdata, data ); -#endif map_input_to_cpe_channels_ivas_fx( st_ivas, pdata_fx, data_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MCT_MAX_CHANNELS; i++ ) - { - if ( pdata_fx[i] == NULL ) - { - continue; - } - fixedToFloat_arrL( pdata_fx[i], pdata[i], Q11, len ); - } -#endif -#endif /* pre-processing */ FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = ivas_cpe_enc( st_ivas, cpe_id, pdata[cpe_id * CPE_CHANNELS], pdata[cpe_id * CPE_CHANNELS + 1], input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, cpe_id, pdata_fx[cpe_id * CPE_CHANNELS], pdata_fx[cpe_id * CPE_CHANNELS + 1], q_data_fx, input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) { return error; } @@ -583,10 +546,6 @@ ivas_error ivas_mct_enc( { for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { - // if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) - //{ - // continue; - // } length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) { @@ -635,10 +594,6 @@ ivas_error ivas_mct_enc( i++; } } - FOR( int b = 0; b < hMCT->nchan_out_woLFE; b++ ) - { - st = sts_tmp[b]; - } #endif #endif // 1 diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index f77bce2a8..8b5f9cd16 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -2126,7 +2126,104 @@ void ivas_qmetadata_enc_sid_encode( * * Reset metadata in spatial formats *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void reset_metadata_spatial_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + const Word32 element_brate, /* i : element bitrate */ + Word32 *total_brate, /* o : total bitrate */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 nb_bits_metadata /* i : number of meatdata bits */ +) +{ + Word16 i, next_ind_sid, last_ind_sid; + Word16 j; + Word16 metadata_sid_bits; + + test(); + IF( EQ_32( core_brate, SID_2k40 ) || core_brate == FRAME_NO_DATA ) + { + test(); + test(); + IF( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) && core_brate != FRAME_NO_DATA ) + { + IF( EQ_32( ivas_format, SBA_FORMAT ) ) + { + hMetaData->ind_list[0].value = 1; + move16(); + metadata_sid_bits = (Word16) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + move16(); + + WHILE( LT_16( hMetaData->nb_bits_tot, metadata_sid_bits ) ) + { + push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ + } + } + ELSE + { + /* Reset metadata and keep only SID metadata*/ + last_ind_sid = hMetaData->nb_ind_tot; + next_ind_sid = hMetaData->nb_ind_tot; + move16(); + move16(); + WHILE( GT_16( hMetaData->nb_bits_tot, nb_bits_metadata ) ) + { + next_ind_sid--; + hMetaData->nb_bits_tot = sub( hMetaData->nb_bits_tot, hMetaData->ind_list[next_ind_sid].nb_bits ); + move16(); + } + + hMetaData->nb_bits_tot = 0; + move16(); + + FOR( i = 0; i < next_ind_sid; i++ ) + { + hMetaData->ind_list[i].nb_bits = -1; + move16(); + } + + FOR( ( j = 0, i = next_ind_sid ); i < last_ind_sid; ( i++, j++ ) ) + { + hMetaData->ind_list[j].value = hMetaData->ind_list[i].value; + hMetaData->ind_list[j].nb_bits = hMetaData->ind_list[i].nb_bits; + hMetaData->nb_bits_tot = add( hMetaData->nb_bits_tot, hMetaData->ind_list[j].nb_bits ); + hMetaData->ind_list[i].nb_bits = -1; + move16(); + move16(); + move16(); + move16(); + } + hMetaData->nb_ind_tot = j; + move16(); + } + } + ELSE + { + /*Reset metadata*/ + reset_indices_enc( hMetaData, hMetaData->nb_ind_tot ); + } + + *total_brate = element_brate; + move32(); + } + ELSE IF( NE_32( ivas_format, SBA_FORMAT ) ) + { + /* Reset SID metadata bits*/ + WHILE( GT_16( hMetaData->nb_bits_tot, nb_bits_metadata ) ) + { + hMetaData->nb_ind_tot--; + hMetaData->nb_bits_tot = sub( hMetaData->nb_bits_tot, hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits ); + hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits = -1; + move16(); + move16(); + move16(); + } + } + + return; +} +#else void reset_metadata_spatial( const IVAS_FORMAT ivas_format, /* i : IVAS format */ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ @@ -2204,6 +2301,7 @@ void reset_metadata_spatial( return; } +#endif /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index f246cb49d..7f5ed5358 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -52,7 +52,42 @@ * * Get TCs from Ambisonics signal in ACN *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_sba_getTCs_fx( + Word32 *sba_data[], /* i : SBA signals Q11 */ + Encoder_Struct *st_ivas, /* i/o: Encoder struct */ + const Word16 input_frame /* i : frame length */ +) +{ + IF( st_ivas->hEncoderConfig->sba_planar ) + { + ivas_sba_zero_vert_comp_fx( sba_data, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar, input_frame ); + } + + st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); + move16(); + IF( GE_16( st_ivas->nchan_transport, 3 ) ) + { + /*convert WYZX downmix to WYXZ*/ + Word16 i = 0; + move16(); + Word32 temp; + FOR( i = 0; i < input_frame; i++ ) + { + temp = sba_data[2][i]; + sba_data[2][i] = sba_data[3][i]; + sba_data[3][i] = temp; + move32(); + move32(); + move32(); + } + } + + + return; +} +#else void ivas_sba_getTCs( float *sba_data[], /* i : SBA signals */ Encoder_Struct *st_ivas, /* i/o: Encoder struct */ @@ -82,6 +117,7 @@ void ivas_sba_getTCs( return; } +#endif /*-------------------------------------------------------------------* * ivas_sba_enc_reconfigure() diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 7c86f194a..43f9a9322 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -58,6 +58,305 @@ *-------------------------------------------------------------------*/ Indice ind_list[MAX_NUM_INDICES]; +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 data_fx[], /* i : input signal for single channel Q(q_data_fx) */ + const Word16 q_data_fx, /* i : Q-factor of input signal for single channel */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +) +{ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion + float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ + float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ + float ener[1]; /* residual energy from Levinson-Durbin */ + float relE[1]; /* frame relative energy */ + float A[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ + float Aw[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ + float epsP[1][M + 1]; /* LP prediction errors */ + float lsp_new[1][M]; /* LSPs at the end of the frame */ + float lsp_mid[1][M]; /* ISPs in the middle of the frame */ + float realBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + float old_wsp[1][L_WSP]; /* old weighted input signal */ + float pitch_fr[1][NB_SUBFR]; /* fractional pitch values */ + float voicing_fr[1][NB_SUBFR]; /* fractional pitch gains */ + float cor_map_sum[1]; /* speech/music clasif. parameter */ + float enerBuffer[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + float currFlatness[1]; /* flatness parameter */ + float fft_buff[1][2 * L_FFT]; /* FFT buffer */ + float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ + float Etot_LR[1]; /* total energy */ + float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ +#endif + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ + Word16 vad_hover_flag[1]; /* VAD hangover flag */ + Word16 attack_flag[1]; /* attack flag (GSC or TC) */ + Word16 loc_harm[1]; /* harmonicity flag */ + Word16 vad_flag_dtx[1]; /* HE-SAD flag with additional DTX HO */ + Word16 fft_buff_fx[1][2 * L_FFT]; /* FFT buffer */ + Word16 localVAD_HE_SAD[1]; /* local HE SAD */ + SCE_ENC_HANDLE hSCE; + Encoder_State *st; + IVAS_FORMAT ivas_format; + ivas_error error; + Word16 flag_16k_smc; + + push_wmops( "ivas_sce_enc" ); + + error = IVAS_ERR_OK; + move32(); + + hSCE = st_ivas->hSCE[sce_id]; + st = hSCE->hCoreCoder[0]; + ivas_format = st_ivas->hEncoderConfig->ivas_format; + move32(); + + /*------------------------------------------------------------------* + * Initialization - general + *-----------------------------------------------------------------*/ + Copy32( data_fx, st->input32_fx, input_frame ); // Q(q_data_fx) + Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( Q16 - 1, q_data_fx ) ); // Q(q_data_fx) -> Q(-1) + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( st->input32_fx, st->input, q_data_fx, input_frame ); +#endif + + st->element_mode = IVAS_SCE; + move16(); + + /*------------------------------------------------------------------* + * SCE initialization - core coder + *-----------------------------------------------------------------*/ + + st->idchan = 0; + st->core = -1; + st->core_brate = -1; /* updated in dtx() */ + st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ + st->bwidth = st->last_bwidth; /* updated in BWD */ + st->rate_switching_reset = 0; + move16(); + move16(); + move32(); + move16(); + move16(); + move16(); + move16(); + + /*---------------------------------------------------------------* + * Time Domain Transient Detector + *---------------------------------------------------------------*/ + test(); + IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + { + RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet ); + st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; + st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; + move16(); + move16(); + } + + Word16 tmp = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + currFlatness[0] = me2f_16( tmp, 15 - Q7 ); +#endif + + /*----------------------------------------------------------------* + * Configuration of core encoder + *----------------------------------------------------------------*/ + + /* Force to MODE1 in IVAS */ + st->codec_mode = MODE1; + move16(); + + /* set "bits_frame_nominal" */ + test(); + IF( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL ) + { + test(); + test(); + IF( ( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) && GE_32( st_ivas->hEncoderConfig->ivas_total_brate, MCMASA_SEPARATE_BRATE ) ) || GE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + st->bits_frame_nominal = extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); + } + ELSE + { + st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal; + move16(); + } + } + ELSE IF( st_ivas->hSpar != NULL ) + { + st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hSpar->core_nominal_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); + } + ELSE + { + st->bits_frame_nominal = sub( extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), ISM_NB_BITS_METADATA_NOMINAL ); + move16(); + } + + /* set "total_brate" */ + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + move32(); + + /* set flag for sampling rate of OL S/M classifier */ + flag_16k_smc = 0; + move16(); + test(); + test(); + test(); + if ( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_24k4 ) || EQ_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_32k ) ) && EQ_32( hSCE->element_brate, hSCE->last_element_brate ) ) + { + flag_16k_smc = 1; + move16(); + } + +#ifdef DEBUG_MODE_INFO + dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); +#endif + + + /*----------------------------------------------------------------* + * 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_fx[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], fft_buff_fx[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; + } + + /* sanity check -> DTX not supported for more than one SCEs/CPEs */ + IF( sub( add( st_ivas->nSCE, st_ivas->nCPE ), 1 ) > 0 ) + { + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) + { + st->core_brate = -1; + st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + move32(); + move32(); + } + } + + /*----------------------------------------------------------------* + * Reset metadata + *----------------------------------------------------------------*/ + + reset_metadata_spatial_fx( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata ); + + /*----------------------------------------------------------------* + * Combined format coding: get the ISM importance and the bit-rate + *----------------------------------------------------------------*/ + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = 0; + move16(); + ivas_set_ism_importance_interformat_fx( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx, &st_ivas->hIsmMetaData[0]->ism_imp ); + + st->total_brate = L_sub( ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ), L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + move32(); + } + + /*----------------------------------------------------------------* + * Write IVAS format signaling in SID frames + *----------------------------------------------------------------*/ + + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + ivas_write_format_sid_fx( ivas_format, IVAS_SCE, st->hBstr ); + } + + /*----------------------------------------------------------------* + * Core codec configuration + *----------------------------------------------------------------*/ + + /* IGF reconfiguration */ + test(); + IF( hSCE->last_element_brate != hSCE->element_brate || st->last_bwidth != st->bwidth ) + { + Word16 igf; + igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode ); + IF( NE_32( ( error = IGF_Reconfig_fx( &st->hIGFEnc, igf, 0, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->element_mode, st->rf_mode ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */ + test(); + test(); + IF( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + { + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 ); + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && st->low_rate_mode ) + { + st->flag_ACELP16k = 0; + } + ELSE + { + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); + } + move16(); + + /* modify the coder_type depending on the total_brate per channel */ + coder_type_modif( st, relE[0] ); + + /*----------------------------------------------------------------* + * Encoder + *----------------------------------------------------------------*/ + + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*----------------------------------------------------------------* + * Common updates + *----------------------------------------------------------------*/ + + /* update input samples buffer */ + mvr2r( st->input, st->old_input_signal, input_frame ); + + hSCE->last_element_brate = hSCE->element_brate; + move32(); + + /* Store previous attack detection flag */ + st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; + move16(); + +#ifdef DEBUG_MODE_INFO + { + float tmpF = hSCE->element_brate / 1000.0f; + dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, sce_id, ENC ) ); + } +#endif + + + pop_wmops(); + + return error; +} +#else ivas_error ivas_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t sce_id, /* i : SCE # identifier */ @@ -66,19 +365,19 @@ ivas_error ivas_sce_enc( const int16_t nb_bits_metadata /* i : number of metadata bits */ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ - float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ - Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion + float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ + float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ #else float old_inp_12k8[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ float old_inp_16k[1][L_INP]; /* buffer of input signal @ 16kHz */ #endif - float ener[1]; /* residual energy from Levinson-Durbin */ - float relE[1]; /* frame relative energy */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float A[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ - float Aw[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ + float ener[1]; /* residual energy from Levinson-Durbin */ + float relE[1]; /* frame relative energy */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion + float A[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ + float Aw[1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes */ #else float A[1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ float Aw[1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ @@ -365,14 +664,14 @@ ivas_error ivas_sce_enc( return error; } - +#endif /*------------------------------------------------------------------------- * create_sce_enc() * * Create, allocate and initialize IVAS encoder SCE handle *-------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error create_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t sce_id, /* i : SCE # identifier */ @@ -448,7 +747,7 @@ ivas_error create_sce_enc( return error; } -#ifdef IVAS_FLOAT_FIXED +#else ivas_error create_sce_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 sce_id, /* i : SCE # identifier */ @@ -461,6 +760,7 @@ ivas_error create_sce_enc_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * Allocate SCE handle @@ -478,11 +778,14 @@ ivas_error create_sce_enc_fx( hSCE->sce_id = sce_id; hSCE->element_brate = element_brate; hSCE->last_element_brate = hSCE->element_brate; + move16(); + move32(); + move32(); /*-----------------------------------------------------------------* * Metadata: allocate and initialize *-----------------------------------------------------------------*/ - + test(); IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { IF( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) @@ -506,13 +809,19 @@ ivas_error create_sce_enc_fx( copy_encoder_config_fx( st_ivas, st, 1 ); + test(); + test(); + test(); IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { st->element_mode = IVAS_SCE; + move16(); } st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); + move32(); IF( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ) != IVAS_ERR_OK ) { @@ -533,9 +842,9 @@ ivas_error create_sce_enc_fx( *-------------------------------------------------------------------------*/ ivas_error create_evs_sce_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t sce_id, /* i : SCE # identifier */ - const int32_t element_brate /* i : element bitrate */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 element_brate /* i : element bitrate */ ) { SCE_ENC_HANDLE hSCE = st_ivas->hSCE[sce_id]; @@ -680,7 +989,8 @@ void destroy_sce_enc( IF( st != NULL ) { - IF( EQ_16( st->element_mode, EVS_MONO ) && is_evs ) + test(); + IF( ( st->element_mode == EVS_MONO ) && is_evs ) { destroy_encoder_fx( hSCE->hCoreCoder[0] ); st = NULL; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6e506a125..2d83970c6 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -562,19 +562,21 @@ void ivas_spar_enc_close_fx( * Principal IVAS SPAR encoder routine *-------------------------------------------------------------------*/ -ivas_error ivas_spar_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - float *data_f[], /* i/o: input/transport audio channels */ - const int16_t input_frame, /* i : input frame length */ - int16_t *nb_bits_metadata, /* i : number of MD bits written */ - BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */ +ivas_error ivas_spar_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data_fx[], /* i/o: input/transport audio channel Q11 */ + const Word16 input_frame, /* i : input frame length */ + Word16 *nb_bits_metadata, /* i : number of MD bits written */ + BSTR_ENC_HANDLE hMetaData /* o : MetaData handle */ ) { ENCODER_CONFIG_HANDLE hEncoderConfig; Encoder_State *st0; /* used for bitstream handling */ ivas_error error; - + Word16 i, q_data = Q11; + move16(); error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; @@ -610,34 +612,21 @@ ivas_error ivas_spar_enc( push_indice( hMetaData, IND_ISM_NUM_OBJECTS, hEncoderConfig->nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); } /* front VAD */ - if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) + IF( ( error = front_vad_spar_fx( st_ivas->hSpar, data_fx[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { return error; } - if ( hEncoderConfig->sba_planar ) - { - ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); - } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 data_fx_arr[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; - Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word16 i, q_data = Q11; - Word16 num_ch = ivas_sba_get_nchan_fx( st_ivas->sba_analysis_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ - for ( i = 0; i < num_ch; i++ ) + IF( hEncoderConfig->sba_planar ) { - data_fx[i] = data_fx_arr[i]; - if ( data_f[i] != NULL ) - { - floatToFixed_arrL( data_f[i], data_fx[i], q_data, input_frame ); - } + ivas_sba_zero_vert_comp_fx( data_fx, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); } + FOR( i = 0; i < st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) { scale_sig32( st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input_fx[i], st_ivas->hSpar->hFbMixer->fb_cfg->prior_input_length, sub( q_data, st_ivas->hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i] ) ); st_ivas->hSpar->hFbMixer->q_ppFilterbank_prior_input_fx[i] = q_data; } -#endif /* SPAR encoder */ IF( NE_32( ( error = ivas_spar_enc_process_fx( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_fx, q_data ) ), IVAS_ERR_OK ) ) @@ -645,16 +634,6 @@ ivas_error ivas_spar_enc( return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < num_ch; i++ ) - { - if ( data_f[i] != NULL ) - { - fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); - } - } -#endif - *nb_bits_metadata = hMetaData->nb_bits_tot; /* Force IVAS front pre-proc decision for higher bitrates */ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index da7514f9d..ce900485d 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -668,7 +668,9 @@ typedef struct stereo_icbwe_enc_data_structure int16_t refChanIndx_bwe; /* SHB speech resampler memory */ float memHPF[8]; +#ifndef IVAS_FLOAT_FIXED float mem_decim_shb_ch0[2 * L_FILT_MAX]; +#endif /* SHB speech non-ref channel */ float mem_shb_speech_ref[L_LOOK_16k]; @@ -678,14 +680,16 @@ typedef struct stereo_icbwe_enc_data_structure float mem_lpc_shbsynth_nonref[LPC_SHB_ORDER]; /* inter-channel BWE spectral shape adj. */ +#ifndef IVAS_FLOAT_FIXED float prevSpecMapping; + float prevgsMapping; +#endif float memShbSpecMapping; float memShbSpecXcorr[6]; - float prevgsMapping; - +#ifndef IVAS_FLOAT_FIXED float prevRefEner; float prevNonRefEner; - +#endif float memGsEnerMap[2]; float dec_2over3_mem[L_FILT_2OVER3]; @@ -698,8 +702,8 @@ typedef struct stereo_icbwe_enc_data_structure float mem_nrg_R[CPE_CHANNELS]; float mem_nrg_DMX[CPE_CHANNELS]; #endif - float gDes_pastFrame; - float icbweRefEner; + // float gDes_pastFrame; + // float icbweRefEner; float shbSynthRef[L_FRAME16k]; float nlExc16k[L_FRAME16k]; diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index bf03b2825..52c669b13 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -626,6 +626,7 @@ ivas_error stereo_dft_enc_create_fx( } hStereoDft_loc->hConfig->force_mono_transmission = 0; + move16(); stereo_dft_config_fx( hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS ); @@ -856,18 +857,23 @@ static void stereo_dft_enc_open_fx( /*Sizes*/ hStereoDft->N = extract_l( Mpy_32_32( input_Fs, 42949673 /* STEREO_DFT_HOP_MAX_ENC / 48000 in Q31 */ ) ); // e = div_e + move16(); assert( ( ( input_Fs / FRAMES_PER_SEC ) / hStereoDft->N ) == 1 ); /*Init. DFT sizes*/ // hStereoDft->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, input_Fs_48k ); // e = div_e - hStereoDft->NFFT = extract_l( Mpy_32_32( input_Fs, 85899346 ) ); // e = div_e + hStereoDft->NFFT = extract_l( Mpy_32_32( input_Fs, 85899346 /* STEREO_DFT_N_MAX_ENC / 48000 in Q31 */ ) ); // e = div_e // hStereoDft->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, input_Fs ); // e = div_e - hStereoDft->dft_ovl = extract_l( Mpy_32_32( input_Fs, 18790482 ) ); // e = div_e + hStereoDft->dft_ovl = extract_l( Mpy_32_32( input_Fs, 18790482 /* STEREO_DFT_OVL_MAX / 48000 in Q31 */ ) ); // e = div_e + move16(); + move16(); mdct_window_sine_IVAS_updated( win_p, input_Fs, hStereoDft->dft_ovl, FULL_OVERLAP, IVAS_CPE_DFT ); // win_e = 15 - FOR( Word16 i = 0; i < shr( STEREO_DFT_OVL_MAX, 1 ); i++ ) + FOR( Word16 i = 0; i < ( STEREO_DFT_OVL_MAX / 2 ); i++ ) { win[STEREO_DFT_OVL_MAX - 1 - i] = win_p[i].v.re; win[i] = win_p[i].v.im; + move16(); + move16(); } hStereoDft->win_ana_energy_fx = sub( hStereoDft->N, hStereoDft->dft_ovl ); // e = div_e hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); // Q = 15 @@ -875,10 +881,16 @@ static void stereo_dft_enc_open_fx( hStereoDft->win_ana_energy_fx = add( hStereoDft->win_ana_energy_fx, shl( sum_s( win, hStereoDft->dft_ovl ), 1 ) ); // Q = 15 hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); hStereoDft->win_ana_energy_fx = div_s( hStereoDft->win_ana_energy_fx, hStereoDft->NFFT ); // Q = 15 + move16(); + move16(); + move16(); + move16(); + move16(); set32_fx( hStereoDft->output_mem_dmx_32k_fx, 0, STEREO_DFT_OVL_32k ); - hStereoDft->dft_zp = (int16_t) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); + hStereoDft->dft_zp = (Word16) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); + move16(); hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; @@ -899,6 +911,7 @@ static void stereo_dft_enc_open_fx( { hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + move16(); hStereoDft->win_ana_fx = win_ana_16k_fx; hStereoDft->win_fx = win_syn_16k_fx; } @@ -906,6 +919,7 @@ static void stereo_dft_enc_open_fx( { hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + move16(); hStereoDft->win_ana_fx = win_ana_32k_fx; hStereoDft->win_fx = win_syn_32k_fx; } @@ -914,6 +928,7 @@ static void stereo_dft_enc_open_fx( assert( EQ_32( input_Fs, 48000 ) ); hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + move16(); hStereoDft->win_ana_fx = win_ana_48k_fx; hStereoDft->win_fx = win_syn_48k_fx; } @@ -932,9 +947,12 @@ static void stereo_dft_enc_open_fx( NFFT_inner = imult1616( inner_frame_tbl[max_bwidth], STEREO_DFT_N_MAX_ENC / L_FRAME48k ); hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); hStereoDft->nbands_dmx = stereo_dft_band_config_fx( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); + move16(); + move16(); /*Set configuration*/ set16_fx( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_ENC_DFT_NB ); + test(); IF( hStereoDft->hConfig->ada_wb_res_cod_mode && EQ_16( hStereoDft->NFFT, STEREO_DFT_N_16k_ENC ) ) { /* residual coding is only applied for 16 kHz sampling rate */ diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index effd61ed8..d19c753c8 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -155,13 +155,18 @@ void stereo_dft_hybrid_ITD_flag( { IF( hConfig != NULL ) { + test(); + test(); + test(); IF( hConfig->res_cod_mode || ( hConfig->ada_wb_res_cod_mode && EQ_32( input_Fs, 16000 ) ) || EQ_16( hybrid_itd_max, 1 ) ) { hConfig->hybrid_itd_flag = 1; + move16(); } ELSE { hConfig->hybrid_itd_flag = 0; + move16(); } } ELSE diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index 63a5f0e11..ca51393e1 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -1571,7 +1571,7 @@ void stereo_icBWE_init_enc( ) { /* SHB speech resampler memory */ - set_f( hStereoICBWE->mem_decim_shb_ch0, 0, ( 2 * L_FILT_MAX ) ); + // set_f( hStereoICBWE->mem_decim_shb_ch0, 0, ( 2 * L_FILT_MAX ) ); /* SHB ref channel */ set_f( hStereoICBWE->mem_shb_speech_ref, 0, L_LOOK_16k ); @@ -1583,15 +1583,15 @@ void stereo_icBWE_init_enc( set_f( hStereoICBWE->mem_lpc_shbsynth_nonref, 0, LPC_SHB_ORDER ); /* inter-channel BWE spectral shape adj. */ - hStereoICBWE->prevSpecMapping = 0; - hStereoICBWE->prevgsMapping = 1.0f; + // hStereoICBWE->prevSpecMapping = 0; + // hStereoICBWE->prevgsMapping = 1.0f; set_f( &( hStereoICBWE->memShbSpecMapping ), 0, 1 ); set_f( hStereoICBWE->memShbSpecXcorr, 0, 6 ); - hStereoICBWE->prevNonRefEner = 1.0f; - hStereoICBWE->prevRefEner = 1.0f; + // hStereoICBWE->prevNonRefEner = 1.0f; + // hStereoICBWE->prevRefEner = 1.0f; - set_f( hStereoICBWE->memGsEnerMap, 1.0f, 2 ); + // set_f( hStereoICBWE->memGsEnerMap, 1.0f, 2 ); set_f( hStereoICBWE->dec_2over3_mem, 0, L_FILT_2OVER3 ); set_f( hStereoICBWE->dec_2over3_mem_lp, 0, L_FILT_2OVER3_LP ); @@ -1613,8 +1613,8 @@ void stereo_icBWE_init_enc( set_f( hStereoICBWE->mem_nrg_R, 0, 2 ); set_f( hStereoICBWE->mem_nrg_DMX, 0, 2 ); #endif - hStereoICBWE->gDes_pastFrame = 1.0f; - hStereoICBWE->icbweRefEner = 0.0f; + // hStereoICBWE->gDes_pastFrame = 1.0f; + // hStereoICBWE->icbweRefEner = 0.0f; hStereoICBWE->MSFlag = 0; return; diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index e6c8341a8..3a3c6c0bb 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -695,8 +695,11 @@ ivas_error stereo_memory_enc_fx( { return error; } - +#ifdef IVAS_FLOAT_FIXED + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); +#else initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); +#endif configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); } } diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 346c78d63..01737ac5b 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -1769,7 +1769,7 @@ void stereo_tdm_prep_dwnmx_fx( mener = Sqrt32( mener, &mener_e ); test(); test(); - IF( LT_32( mener, L_shl( 10, sub( 31, mener_e ) ) ) && ( sts[1]->vad_flag == 0 || EQ_16( sts[1]->coder_type_raw, UNVOICED ) ) ) + IF( ( BASOP_Util_Cmp_Mant32Exp( mener, mener_e, 10, Q31 ) < 0 ) && ( sts[1]->vad_flag == 0 || EQ_16( sts[1]->coder_type_raw, UNVOICED ) ) ) { hCPE->hStereoTD->flag_skip_DMX = 0; /* Can start using the TD downmix whenever the right channel is sufficiently low energy to limit switching artefacts */ move16(); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index a8130236d..7d7617431 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1875,7 +1875,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } ELSE /* IVAS */ { - IF( NE_32( ( error = ivas_enc( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_enc_fx( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 0f9646cac..c3573d64a 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -511,8 +511,8 @@ typedef struct td_cng_enc_structure typedef struct fd_cng_enc_structure { HANDLE_FD_CNG_COM hFdCngCom; +#ifndef IVAS_FLOAT_FIXED float msPeriodog[NPART]; /* Periodogram */ -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled float msBminWin[NPART]; float msBminSubWin[NPART]; float msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ @@ -521,6 +521,10 @@ typedef struct fd_cng_enc_structure float msCurrentMinOut[NPART]; float msCurrentMin[NPART]; float msCurrentMinSubWindow[NPART]; + float msPsdFirstMoment[NPART]; + float msPsdSecondMoment[NPART]; + float msNoiseFloor[NPART]; /* Estimated noise floor */ + float msNoiseEst[NPART]; /* Estimated noise level */ #endif Word32 msPeriodog_fx[NPART]; /* Periodogram */ Word16 msPeriodog_fx_exp; /* Common exponent for fft and cldfb energies */ @@ -535,40 +539,36 @@ typedef struct fd_cng_enc_structure Word32 msCurrentMin_fx[NPART]; Word32 msCurrentMinSubWindow_fx[NPART]; - int16_t msLocalMinFlag[NPART]; - int16_t msNewMinFlag[NPART]; -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled - float msPsdFirstMoment[NPART]; - float msPsdSecondMoment[NPART]; - float msNoiseFloor[NPART]; /* Estimated noise floor */ -#endif - float msNoiseEst[NPART]; /* Estimated noise level */ - float energy_ho[NPART]; + Word16 msLocalMinFlag[NPART]; + Word16 msNewMinFlag[NPART]; + Word16 msPsdFirstMoment_fx[NPART]; + Word32 msPsdSecondMoment_fx[NPART]; + Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ +#ifndef IVAS_FLOAT_FIXED float msNoiseEst_old[NPART]; -#if 1 // ndef IVAS_FLOAT_FIXED to be disabled + float energy_ho[NPART]; float msLogPeriodog[NPART]; /* Periodogram */ float msLogNoiseEst[NPART]; /* Estimated noise level */ #endif - Word16 msPsdFirstMoment_fx[NPART]; - Word32 msPsdSecondMoment_fx[NPART]; - Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ - Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ + Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ Word16 msNoiseEst_fx_exp; Word32 energy_ho_fx[NPART]; Word16 energy_ho_fx_exp; Word32 msNoiseEst_old_fx[NPART]; Word16 msNoiseEst_old_fx_exp; +#ifndef IVAS_FLOAT_FIXED float msPeriodogBuf[MSBUFLEN * NPART]; +#endif Word16 msPeriodogBuf_fx[MSBUFLEN * NPART]; - int16_t msPeriodogBufPtr; + Word16 msPeriodogBufPtr; - int16_t stopFFTbinDec; - int16_t startBandDec; - int16_t stopBandDec; - int16_t npartDec; - int16_t midbandDec[NPART]; - int16_t nFFTpartDec; - int16_t partDec[NPART]; + Word16 stopFFTbinDec; + Word16 startBandDec; + Word16 stopBandDec; + Word16 npartDec; + Word16 midbandDec[NPART]; + Word16 nFFTpartDec; + Word16 partDec[NPART]; Word16 msLogPeriodog_fx[NPART]; @@ -581,50 +581,7 @@ typedef struct fd_cng_enc_structure Word16 mem_coherence_exp[4]; } FD_CNG_ENC, *HANDLE_FD_CNG_ENC; -// typedef struct -//{ -// HANDLE_FD_CNG_COM hFdCngCom; -// -// Word32 msPeriodog[NPART]; /* Periodogram */ -// Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ -// Word16 msPeriodog_exp_fft; -// Word16 msPeriodog_exp_cldfb; -// Word32 msBminWin[NPART]; -// Word32 msBminSubWin[NPART]; -// Word16 msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ -// Word32 msAlpha[NPART]; /* Optimal smoothing parameter */ -// Word32 msMinBuf[MSNUMSUBFR*NPART]; /* Buffer of minima */ -// Word32 msCurrentMinOut[NPART]; -// Word32 msCurrentMin[NPART]; -// Word32 msCurrentMinSubWindow[NPART]; -// Word16 msLocalMinFlag[NPART]; -// Word16 msNewMinFlag[NPART]; -// Word16 msPsdFirstMoment[NPART]; -// Word32 msPsdSecondMoment[NPART]; -// Word16 msNoiseFloor[NPART]; /* Estimated noise floor */ -// Word32 msNoiseEst[NPART]; /* Estimated noise level */ -// Word16 msNoiseEst_exp; -// Word32 energy_ho[NPART]; -// Word16 energy_ho_exp; -// Word32 msNoiseEst_old[NPART]; -// Word16 msNoiseEst_old_exp; -// -// Word16 msPeriodogBuf[MSBUFLEN*NPART]; -// Word16 msPeriodogBufPtr; -// -// Word16 stopFFTbinDec; -// Word16 startBandDec; -// Word16 stopBandDec; -// Word16 npartDec; -// Word16 midbandDec[NPART]; -// Word16 nFFTpartDec; -// Word16 partDec[NPART]; -// -// Word16 msLogPeriodog[NPART]; -// Word16 msLogNoiseEst[NPART]; -// } -// FD_CNG_ENC_FX; -// typedef FD_CNG_ENC_FX *HANDLE_FD_CNG_ENC_FX; + /*------------------------------------------------------------------------------------------* * Structure for DTX-related variables used in both FD- and TD-CNG *------------------------------------------------------------------------------------------*/ @@ -1213,25 +1170,27 @@ typedef struct gsc_enc_structure typedef struct hq_enc_structure { - int16_t mode_count; /* HQ_HARMONIC mode count */ - int16_t mode_count1; /* HQ_NORMAL mode count */ - int16_t prev_Npeaks; /* number of peaks in previous frame */ - int16_t prev_peaks[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ - int16_t hvq_hangover; - int16_t prev_hqswb_clas; - int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; - - int16_t hq_generic_speech_class; + Word16 mode_count; /* HQ_HARMONIC mode count */ + Word16 mode_count1; /* HQ_NORMAL mode count */ + Word16 prev_Npeaks; /* number of peaks in previous frame */ + Word16 prev_peaks[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ + Word16 hvq_hangover; + Word16 prev_hqswb_clas; + Word16 prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + + Word16 hq_generic_speech_class; +#ifndef IVAS_FLOAT_FIXED float crest_lp; /* Low-pass filtered crest of high band */ float crest_mod_lp; /* Low-pass filtered noise band detection */ +#endif Word32 crest_lp_fx; Word16 crest_lp_q; Word32 crest_mod_lp_fx; Word16 crest_mod_lp_q; /* SWB BWE LR classification */ - int16_t prev_frm_index[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - int16_t prev_frm_hfe2; - int16_t prev_stab_hfe2; + Word16 prev_frm_index[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + Word16 prev_frm_hfe2; + Word16 prev_stab_hfe2; #ifndef IVAS_FLOAT_FIXED float prev_ni_ratio; float prev_En_sb[NB_SWB_SUBBANDS]; @@ -1240,7 +1199,7 @@ typedef struct hq_enc_structure Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ #endif - int16_t last_bitalloc_max_band[2]; + Word16 last_bitalloc_max_band[2]; #ifndef IVAS_FLOAT_FIXED float last_ni_gain[BANDS_MAX]; float last_env[BANDS_MAX]; @@ -1248,7 +1207,7 @@ typedef struct hq_enc_structure Word32 last_ni_gain_fx[BANDS_MAX]; /* Q17 */ Word16 last_env_fx[BANDS_MAX]; /* Q1 */ #endif - int16_t last_max_pos_pulse; + Word16 last_max_pos_pulse; } HQ_ENC_DATA, *HQ_ENC_HANDLE; @@ -1442,13 +1401,13 @@ typedef struct amrwb_io_enc_structure typedef struct td_bwe_enc_structure { #ifndef IVAS_FLOAT_FIXED - float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ + float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ + float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ #else Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories Q(Q_shb_spch) */ + Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories Q(-1) */ #endif - float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ float old_input_fhb[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; Word16 old_input_fhb_fx_Q; @@ -1462,8 +1421,11 @@ typedef struct td_bwe_enc_structure Word16 cldfbHBLT; /* Q13 */ #endif /* states for the filters used in generating SHB excitation from WB excitation*/ +#ifndef IVAS_FLOAT_FIXED float mem_csfilt[2]; - Word32 mem_csfilt_fx[2]; /* Q(prev_Q_bwe_exc) */ +#else + Word32 mem_csfilt_fx[2]; /* Q(prev_Q_bwe_exc) */ +#endif float mem_shb_res[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ Word16 mem_shb_res_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ Word32 mem_shb_res_32_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ @@ -1483,46 +1445,46 @@ typedef struct td_bwe_enc_structure #if 0 Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ #endif - Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ + Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ #endif #ifndef IVAS_FLOAT_FIXED float prev_mix_factor; /* mixing factor in the previous frame */ float prev_Env_error; /* error in SHB envelope modelling */ #else - Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ - Word16 prev_Env_error_fx; /* error in SHB envelope modelling Q0 */ + Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ + Word16 prev_Env_error_fx; /* error in SHB envelope modelling Q0 */ #endif /* states for the filters used in generating SHB signal from SHB excitation*/ +#ifndef IVAS_FLOAT_FIXED float state_syn_shbexc[L_SHB_LAHEAD]; float state_lpc_syn[LPC_SHB_ORDER]; - float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ - Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; /* Q(prev_Q_bwe_exc - 16) */ - Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; /* Q(prev_Q_bwe_exc - 16) */ - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ +#else + Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; /* Q(prev_Q_bwe_exc - 16) */ + Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; /* Q(prev_Q_bwe_exc - 16) */ +#endif + float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ + Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ int16_t bwe_seed[2]; #ifndef IVAS_FLOAT_FIXED float bwe_non_lin_prev_scale; -#else - Word32 bwe_non_lin_prev_scale_fx; /* Q30 */ -#endif float old_bwe_exc_extended[NL_BUFF_OFFSET]; - float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; /* Q(prev_Q_bwe_exc - 16) */ - Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* Q0 not sure */ -#ifndef IVAS_FLOAT_FIXED + float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain */ float decim_state1[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float decim_state2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; -#else - Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ - Word16 decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ -#endif float mem_genSHBexc_filt_down_wb2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_wb3[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_shb[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; +#else + Word32 bwe_non_lin_prev_scale_fx; /* Q30 */ + Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; /* Q(prev_Q_bwe_exc - 16) */ + Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain */ + Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ + Word16 decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ Word16 mem_genSHBexc_filt_down_wb2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_genSHBexc_filt_down_wb3_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_genSHBexc_filt_down_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ +#endif #ifndef IVAS_FLOAT_FIXED float elliptic_bpf_2_48k_mem[4][4]; @@ -1531,8 +1493,10 @@ typedef struct td_bwe_enc_structure float lsp_shb_slow_interpl[LPC_SHB_ORDER]; float lsp_shb_fast_interpl[LPC_SHB_ORDER]; float shb_inv_filt_mem[LPC_SHB_ORDER]; + float lsp_shb_spacing[3]; + float prev_swb_GainShape; #else - Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /* Q(elliptic_bpf_2_48k_mem_fx_Q[4]) */ + Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /* Q(elliptic_bpf_2_48k_mem_fx_Q[4]) */ Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; Word32 prev_fb_energy_fx; /* Q(prev_fb_energy_fx_Q) */ Word16 prev_fb_energy_fx_Q; @@ -1540,15 +1504,9 @@ typedef struct td_bwe_enc_structure Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; /* Q(Q_shb_spch) */ -#endif -#ifndef IVAS_FLOAT_FIXED - float lsp_shb_spacing[3]; - float prev_swb_GainShape; -#else Word16 lsp_shb_spacing_fx[3]; /* Q15 */ Word16 prev_swb_GainShape_fx; /* Q15 */ #endif - int16_t prev_frGainAtten; #ifndef IVAS_FLOAT_FIXED @@ -1602,19 +1560,19 @@ typedef struct td_bwe_enc_structure Word16 dec_2_over_3_mem_lp_fx[6]; #endif +#ifndef IVAS_FLOAT_FIXED float tbe_demph; float tbe_premph; float mem_stp_swb[LPC_SHB_ORDER]; float *ptr_mem_stp_swb; float gain_prec_swb; + float mem_zero_swb[LPC_SHB_ORDER]; +#else Word16 tbe_demph_fx; /* Q(prev_Q_bwe_exc - 16 - NOISE_QADJ) */ Word16 tbe_premph_fx; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; /* Q(st->prev_Q_bwe_syn) */ Word16 *ptr_mem_stp_swb_fx; Word16 gain_prec_swb_fx; /* Q14 */ -#ifndef IVAS_FLOAT_FIXED - float mem_zero_swb[LPC_SHB_ORDER]; -#else Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; #endif diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index ba1fe063f..f76a740b9 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -436,6 +436,10 @@ void swb_bwe_enc_ivas_fx( &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ inner_frame ); + /* Scaling has been added to avoid the yorig_32 buffer becoming zero inside direct_transform_fx */ + Scale_sig32( L_old_input_fx, inner_frame, Q5 ); + new_input_fx_exp = add( new_input_fx_exp, 5 ); + /* DCT of the ACELP core synthesis */ direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp, st_fx->element_mode ); diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 878c1aa9b..b30150ead 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -564,7 +564,7 @@ void swb_pre_proc_ivas_fx( { Word16 out_start_ind, out_end_ind; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, L_FRAME48k + STEREO_DFT_OVL_MAX, q_reImBuffer ); Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); } } diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 0d3f74364..18c519939 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -96,8 +96,8 @@ void InitSWBencBuffer( set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; hBWE_TD->bwe_seed[1] = 59; - set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); #ifndef IVAS_FLOAT_FIXED + set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale = 0; set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); @@ -108,6 +108,7 @@ void InitSWBencBuffer( set_f( hBWE_TD->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); hBWE_TD->prev_fb_energy = 0.0f; #else + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); @@ -125,10 +126,11 @@ void InitSWBencBuffer( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); + set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); #else set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); #endif - set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #ifdef IVAS_FLOAT_FIXED @@ -198,8 +200,8 @@ void InitSWBencBuffer( set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 ); /* TD BWE post-processing */ - hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; #ifndef IVAS_FLOAT_FIXED + hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); for ( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -207,6 +209,7 @@ void InitSWBencBuffer( hBWE_TD->swb_lsp_prev_interp[i] = (float) cos( (float) i * EVS_PI / (float) 10.0f ); } #else + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -287,12 +290,22 @@ void ResetSHBbuffer_Enc( ) { /* states for the filters used in generating SHB excitation from WB excitation*/ +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_csfilt, 0, 2 ); +#else + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); +#endif /* states for the filters used in generating SHB signal from SHB excitation*/ +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER ); +#else + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); +#endif set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; @@ -300,19 +313,29 @@ void ResetSHBbuffer_Enc( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); #else set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); #endif - set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); /* overlap buffer used to Adjust SHB Frame Gain */ +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb = 1.0f; set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); hBWE_TD->tbe_demph = 0.0f; hBWE_TD->tbe_premph = 0.0f; +#else + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + hBWE_TD->tbe_demph_fx = 0; + hBWE_TD->tbe_premph_fx = 0; +#endif return; } @@ -2980,13 +3003,26 @@ void TBEreset_enc( if ( bwidth == WB ) { +#ifndef IVAS_FLOAT_FIXED wb_tbe_extras_reset( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3 ); set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, 7 ); set_f( hBWE_TD->state_lpc_syn, 0, 10 ); set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); +#else + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, 10 ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); +#endif +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->mem_csfilt, 0, 2 ); +#else + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); +#endif } else if ( bwidth == SWB || bwidth == FB ) { @@ -2996,7 +3032,12 @@ void TBEreset_enc( set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); #endif +#ifdef IVAS_FLOAT_FIXED + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); +#else swb_tbe_reset( hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, hBWE_TD->syn_overlap, hBWE_TD->state_syn_shbexc, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), hBWE_TD->mem_stp_swb, &( hBWE_TD->gain_prec_swb ) ); +#endif + if ( bwidth == FB ) { diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 1304bdedb..9a219d065 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -110,6 +110,16 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *frGainAttenuate, Word16 *frGainSmoothEn ); +#ifdef IVAS_FLOAT_FIXED +static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, + Word16 *shb_frame_fx /* Q_in */, + const Word16 *lpc_shb_fx /* Q12 */, + const Word16 *lsp_shb_fx /* Q15 */, + Word16 *MA_lsp_shb_spacing /* Q15 */, + Word16 *frGainAttenuate /* Q0 */, + Word16 *frGainSmoothEn /* Q0 */ ); +#endif + /*-------------------------------------------------------------------* * find_max_mem_enc() @@ -2966,7 +2976,7 @@ void swb_tbe_enc_ivas_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ - gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); + gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); test(); test(); @@ -5372,19 +5382,19 @@ static void Quant_shb_ener_sf_ivas_fx( exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ + L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ - tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */ + tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ temp_shb_ener_sf_fx = 0; move16(); - idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 43 = 0.042f in Q10 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q11 */ /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q11+Q13+1 = Q25 */ + L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ @@ -6376,6 +6386,134 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, } } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * gainFrSmooth_En_ivas_fx() + * + * Gain frame smoothing and attenuation control + *-------------------------------------------------------------------*/ +static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, + Word16 *shb_frame_fx /* Q_in */, + const Word16 *lpc_shb_fx /* Q12 */, + const Word16 *lsp_shb_fx /* Q15 */, + Word16 *MA_lsp_shb_spacing /* Q15 */, + Word16 *frGainAttenuate /* Q0 */, + Word16 *frGainSmoothEn /* Q0 */ ) +{ + Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; + Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; + Word16 lsp_slow_evol_rate_e, lsp_fast_evol_rate_e; + Word16 lsp_spacing; + + Word32 tempQ31; + Word16 tempQ15_1, tempQ15_2; + Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + + /* inits */ + *frGainAttenuate = 0; + move16(); + *frGainSmoothEn = 0; + move16(); + *MA_lsp_shb_spacing = 16384; /* 0.5f in Q15 */ + move16(); + lsp_spacing = lsp_shb_fx[0]; + move16(); + + /* estimate the mean square error in lsps from current frame to past frames */ + tempQ15_1 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_slow_interpl_fx[0] ); + tempQ15_2 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_fast_interpl_fx[0] ); + lsp_slow_evol_rate = L_mult( tempQ15_1, tempQ15_1 ); + lsp_slow_evol_rate_e = 0; + move16(); + lsp_fast_evol_rate = L_mult( tempQ15_2, tempQ15_2 ); + lsp_fast_evol_rate_e = 0; + move16(); + + /* update the slow and fast lsp interp for next frame */ + tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 /* 0.7f in Q15 */ ); + hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 9830 /* 0.3f in Q15 */ ); + move16(); + tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 /* 0.3f in Q15 */ ); + hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 22937 /* 0.7f in Q15 */ ); + move16(); + + FOR( i = 1; i < LPC_SHB_ORDER; i++ ) + { + tempQ15_1 = sub( lsp_shb_fx[i], lsp_shb_fx[i - 1] ); + lsp_spacing = s_min( lsp_spacing, tempQ15_1 ); + + /* estimate the mean square error in lsps from current frame to past frames */ + tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); + tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); + lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); + lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); + + /* update the slow and fast interpolation lsps for next frame */ + tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 /* 0.7f in Q15 */ ); + hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 9830 /* 0.3f in Q15 */ ); + move16(); + tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 /* 0.3f in Q15 */ ); + hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 22937 /* 0.7f in Q15 */ ); + move16(); + } + + test(); + test(); + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && LT_16( lsp_spacing, 262 /* 0.008f in Q15 */ ) ) + { + hBWE_TD->lsp_shb_spacing_fx[0] = lsp_spacing; + move16(); + hBWE_TD->lsp_shb_spacing_fx[1] = lsp_spacing; + move16(); + hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; + move16(); + hBWE_TD->prev_frGainAtten = 1; + move16(); + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + } + + /* Estimate the moving average LSP spacing */ + tempQ31 = L_mult( hBWE_TD->lsp_shb_spacing_fx[0], 3277 ); /* 0.1f in Q15 */ + tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f in Q15 */ + tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f in Q15 */ + *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 ); /* 0.4f in Q15 */ + + hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; + move16(); + hBWE_TD->lsp_shb_spacing_fx[1] = hBWE_TD->lsp_shb_spacing_fx[2]; + move16(); + hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; + move16(); + + test(); + test(); + test(); + IF( ( LT_16( lsp_spacing, 262 /* 0.008f in Q15 */ ) && ( LT_16( *MA_lsp_shb_spacing, 164 /* 0.005f in Q15 */ ) || EQ_16( hBWE_TD->prev_frGainAtten, 1 ) ) ) || LE_16( lsp_spacing, 105 /* 0.0032f in Q15 */ ) ) + { + *frGainAttenuate = 1; + move16(); + + IF( NE_32( st_fx->total_brate, ACELP_24k40 ) ) + { + Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD ); + fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1, 3 ); + } + ELSE + { + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + } + + test(); + IF( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) + { + *frGainSmoothEn = 1; + move16(); + } + } +} +#endif + #define MAXINT32 MAX_32 static void first_VQstages_fx( const Word16 *const *cb, diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index 1d7e191b4..5fa4901b7 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -943,6 +943,8 @@ static void ivas_omasa_param_est_ana_fx( computeIntensityVector_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); intensity_q = sub( shl( add( foa_q, Q1 ), 1 ), 31 ); + direction_q = intensity_q; + move16(); computeDirectionVectors_fx( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], &direction_q ); -- GitLab