From b63f009597d08561ae328d2e8ec75808d2e78187 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 16 Mar 2024 22:49:50 +0530 Subject: [PATCH] Integration of fixed point sub-functions - 1 [x] init_decoder_fx integrated [x] acelp sub-function: hf_synth block integration [x] cleanup changes for core_switching_pre_dec_ivas_fx [x] integration of sub - functions into stereo_tcx_core_dec. Intermediate conversions to be cleaned up. [x] acelp sub-function: non_linearity_fx integration [x] stereo_decoder_tcx_fx updates. --- lib_com/bits_alloc_fx.c | 67 + lib_com/cldfb.c | 33 +- lib_com/cng_exc_fx.c | 213 +- lib_com/cnst.h | 2 + lib_com/fd_cng_com_fx.c | 150 ++ lib_com/float_to_fix_ops.c | 687 +++++++ lib_com/ivas_prot_fx.h | 10 +- lib_com/lsf_tools_fx.c | 52 + lib_com/mslvq_com_fx.c | 254 +++ lib_com/prot.h | 25 +- lib_com/prot_fx1.h | 7 + lib_com/prot_fx2.h | 104 +- lib_com/rom_com.c | 429 ++++ lib_com/rom_com.h | 7 + lib_com/swb_tbe_com_fx.c | 381 ++++ lib_com/syn_filt_fx.c | 75 + lib_com/tools.c | 18 + lib_com/tools_fx.c | 77 + lib_dec/acelp_core_dec.c | 157 +- lib_dec/amr_wb_dec.c | 226 ++- lib_dec/cng_dec_fx.c | 99 + lib_dec/core_dec_init.c | 17 + lib_dec/core_dec_init_fx.c | 17 +- lib_dec/core_switching_dec.c | 229 +-- lib_dec/dec_LPD.c | 22 +- lib_dec/dec_tcx_fx.c | 72 +- lib_dec/er_util_fx.c | 14 +- lib_dec/evs_dec.c | 223 ++- lib_dec/fd_cng_dec_fx.c | 121 ++ lib_dec/gs_dec_fx.c | 29 + lib_dec/hf_synth.c | 6 +- lib_dec/hf_synth_fx.c | 291 ++- lib_dec/hq_core_dec_fx.c | 5 +- lib_dec/igf_dec.c | 9 - lib_dec/igf_dec_fx.c | 9 - lib_dec/init_dec.c | 8 + lib_dec/init_dec_fx.c | 1113 +++++++++++ lib_dec/ivas_core_dec.c | 224 ++- lib_dec/ivas_cpe_dec_fx.c | 2 +- lib_dec/ivas_sce_dec_fx.c | 2 +- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 45 + lib_dec/ivas_stereo_mdct_stereo_dec.c | 16 +- lib_dec/ivas_stereo_switching_dec.c | 10 + lib_dec/ivas_tcx_core_dec.c | 2515 +++++++++++++----------- lib_dec/lsf_dec_fx.c | 28 +- lib_dec/stat_dec.h | 41 +- lib_dec/swb_bwe_dec_hr_fx.c | 19 + 47 files changed, 6680 insertions(+), 1480 deletions(-) diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 703b67144..11868e523 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -1575,6 +1575,72 @@ static Word16 allocate_unused( *--------------------------------------------------------------------*/ /*! r: ACELP16k flag */ +#ifdef IVAS_FLOAT_FIXED +Word16 set_ACELP_flag( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate per channel */ + const Word16 idchan, /* i : Channel id */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 cng_type /* i : CNG type */ +) +{ + // PMT("Not floating point computation, but fixed point operator are still missing ") + test(); + test(); + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && EQ_16( idchan, 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) + { + return 1; + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) + { + test(); + test(); + test(); + IF( GE_32( element_brate, IVAS_24k4 ) && EQ_16( idchan, 0 ) && ( EQ_16( tdm_LRTD_flag, 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) + { + return 1; + } + ELSE + { + return 0; + } + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + IF( GE_32( element_brate, IVAS_24k4 ) ) + { + return 1; + } + ELSE + { + return 0; + } + } + ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) + { + IF( GE_32( element_brate, SCE_CORE_16k_LOW_LIMIT ) ) + { + return 1; + } + ELSE + { + return 0; + } + } + ELSE IF( GE_32( total_brate, ACELP_16k_LOW_LIMIT ) ) /* EVS_MONO */ + { + return 1; + } + ELSE + { + return 0; + } +} +#else Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ @@ -1633,4 +1699,5 @@ Word16 set_ACELP_flag( return 0; } } +#endif /*#endif IVAS_CODE*/ \ No newline at end of file diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 55b662e8d..1fad358a2 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1598,7 +1598,7 @@ void configureCldfb_ivas_fx( // h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); Word32 n_sampling_rate = sampling_rate * 2; - Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 ), 1 ); + Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 /* INV_CLDFB_BANDWIDTH in Q15 */), 1 ); val = L_shr( val, 1 ); h_cldfb->no_channels = extract_l( val ); @@ -1687,7 +1687,8 @@ ivas_error openCldfb_ivas_fx( hs->prototype = prototype; move16(); - configureCldfb_ivas( hs, sampling_rate ); + //configureCldfb_ivas( hs, sampling_rate ); + configureCldfb_ivas_fx( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; move16(); @@ -1986,6 +1987,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17036; hs->p_filter = CLDFB80_10_fx; + hs->q_scale = norm_s((Word16)CLDFB80_10_SCALE); + hs->scale = (Word16)(CLDFB80_10_SCALE*(1<q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2005,6 +2008,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_10_fx; + hs->q_scale = norm_s((Word16)LDQMF_10_SCALE); + hs->scale = (Word16)(LDQMF_10_SCALE*(1 << hs->q_scale)); #endif } break; @@ -2037,6 +2042,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_16_fx; + hs->q_scale = norm_s((Word16)CLDFB80_16_SCALE); + hs->scale = (Word16)(CLDFB80_16_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2056,6 +2063,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_16_fx; + hs->q_scale = norm_s((Word16)LDQMF_16_SCALE); + hs->scale = (Word16)(LDQMF_16_SCALE*(1 << hs->q_scale)); #endif } break; @@ -2088,6 +2097,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_20_fx; + hs->q_scale = norm_s((Word16)CLDFB80_20_SCALE); + hs->scale = (Word16)(CLDFB80_20_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2107,6 +2118,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15390; hs->p_filter = LDQMF_20_fx; + hs->q_scale = norm_s((Word16)LDQMF_20_SCALE); + hs->scale = (Word16)(LDQMF_20_SCALE*(1 << hs->q_scale)); #endif } break; @@ -2139,6 +2152,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_30_fx; + hs->q_scale = norm_s((Word16)CLDFB80_30_SCALE); + hs->scale = (Word16)(CLDFB80_30_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2158,6 +2173,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_30_fx; + hs->q_scale = norm_s((Word16)LDQMF_30_SCALE); + hs->scale = (Word16)(LDQMF_30_SCALE*(1 << hs->q_scale)); #endif } break; @@ -2190,6 +2207,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_32_fx; + hs->q_scale = norm_s((Word16)CLDFB80_32_SCALE); + hs->scale = (Word16)(CLDFB80_32_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2209,6 +2228,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15392; hs->p_filter = LDQMF_32_fx; + hs->q_scale = norm_s((Word16)LDQMF_32_SCALE); + hs->scale = (Word16)(LDQMF_32_SCALE*(1 << hs->q_scale)); #endif } break; @@ -2241,6 +2262,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_40_fx; + hs->q_scale = norm_s((Word16)CLDFB80_40_SCALE); + hs->scale = (Word16)(CLDFB80_40_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2260,6 +2283,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_40_fx; + hs->q_scale = norm_s((Word16)LDQMF_40_SCALE); + hs->scale = (Word16)(LDQMF_40_SCALE*(1 << hs->q_scale)); #endif } break; @@ -2292,6 +2317,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_60_fx; + hs->q_scale = norm_s((Word16)CLDFB80_60_SCALE); + hs->scale = (Word16)(CLDFB80_60_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2311,6 +2338,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_60_fx; + hs->q_scale = norm_s((Word16)LDQMF_60_SCALE); + hs->scale = (Word16)(LDQMF_60_SCALE*(1 << hs->q_scale)); #endif } break; diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index c5b8caaef..c6ff88ef0 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -14,7 +14,7 @@ #define A2 6554 #define OmA2 (32768-A2) #define GAIN_VAR 11811 /* in Q31 divided by 2 (Q30) */ - +const Word16 att_pow_tbl[SIZE_SCALE_TABLE_STEREO + 1] = { 9234, 10361, 13044, 16422, 22669, 31292, 32767, 26634, 28212, 20674, 16422, 27254, 30934, 32767 }; /*-------------------------------------------------------* * CNG_exc() * @@ -962,6 +962,217 @@ void cng_params_upd_fx( return; } +#ifdef IVAS_FLOAT_FIXED +void cng_params_upd_ivas_fx( + const Word16 lsp_new[], /* i : LSP aprameters Q15 */ + const Word16 exc2[], /* i : current enhanced excitation Q_exc */ + const Word16 L_frame, /* i : frame length Q0 */ + Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ + Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ + Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ + Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ + const Word16 Q_exc, /* i : Q value of excitation */ + const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ + Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ + Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ + Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ + Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ + const Word32 last_active_brate,/* i : Last active bit rate Q0 */ + const Word16 element_mode, /* i : Element mode */ + const Word16 bwidth /* i : Audio bandwidth */ +) +{ + Word32 L_ener, L_tmp; + Word16 i, j; + const Word16 *pt_exc2; + Word16 tmpv, maxv, scale; + Word16 fft_io[L_FRAME16k]; + Word32 sp[129]; + Word16 *ptR, *ptI; + Word32 env[NUM_ENV_CNG]; + Word16 exp1; + Word16 CNG_mode; + Word16 tmp; + Word16 temp_lo_fx, temp_hi_fx; + Word16 exp_pow; + Word32 att; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + + /* update the pointer to circular buffer of old LSP vectors */ + *ho_circ_ptr = add( *ho_circ_ptr, 1 ); + + if ( EQ_16( *ho_circ_ptr, HO_HIST_SIZE ) ) + { + *ho_circ_ptr = 0; + move16(); + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + Copy( lsp_new, &( ho_lsp_circ[( *ho_circ_ptr ) * M] ), M ); + + /* calculate the residual signal energy */ + /*enr = dotp( exc2, exc2, L_frame ) / L_frame; */ + + maxv = 0; + move16(); + FOR( i = 0; i < L_frame; i++ ) + { + maxv = s_max( maxv, abs_s( exc2[i] ) ); + } + scale = norm_s( maxv ); + + pt_exc2 = exc2; + move16(); + L_ener = L_deposit_l( 0 ); + IF( EQ_16( L_frame, L_FRAME ) ) + { + FOR( j = 0; j < 128; j++ ) + { + tmpv = shl( *pt_exc2, scale ); + L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ + pt_exc2++; + tmpv = shl( *pt_exc2, scale ); +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); +#else + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); +#endif + pt_exc2++; +#ifdef BASOP_NOGLOB + L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ +#else + L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ +#endif + } + } + ELSE /* L_FRAME16k */ + { + FOR( j = 0; j < 160; j++ ) + { + tmpv = shl( *pt_exc2, scale ); + L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ + pt_exc2++; + tmpv = shl( *pt_exc2, scale ); +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); +#else + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); +#endif + pt_exc2++; +#ifdef BASOP_NOGLOB + L_ener = L_add_o( L_ener, L_shr_o( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ +#else + L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ +#endif + } + } +#ifdef BASOP_NOGLOB + L_ener = L_shr_o( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ), &Overflow ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ +#else /* BASOP_NOGLOB */ + L_ener = L_shr( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ) ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ +#endif + + /* update the circular buffer of old energies */ + ho_ener_circ[*ho_circ_ptr] = L_ener; + move32(); + + IF( EQ_16( enc_dec_flag, ENC ) ) + { + /* Store residual signal for postponed FFT-processing*/ + *cng_buf_cnt = add( *cng_buf_cnt, 1 ); + if ( GT_16( *cng_buf_cnt, HO_HIST_SIZE ) ) + { + *cng_buf_cnt = HO_HIST_SIZE; + move16(); + } + Copy( exc2, &( cng_exc2_buf[( *ho_circ_ptr ) * L_FFT] ), L_FFT ); + cng_Qexc_buf[*ho_circ_ptr] = Q_exc; + move16(); + cng_brate_buf[*ho_circ_ptr] = last_active_brate; + move16(); + } + ELSE + { + /* calculate the spectrum of residual signal */ + Copy( exc2, fft_io, L_frame ); + + fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); + + ptR = &fft_io[1]; + ptI = &fft_io[L_FFT - 1]; + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* sp[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ +#ifdef BASOP_NOGLOB + L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ + L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ + L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ +#else + L_tmp = L_mult( *ptR, *ptR ); /* 2*Q_exc+1 */ + L_tmp = L_add( L_tmp, L_mult( *ptI, *ptI ) ); /* 2*Q_exc+1 */ + L_tmp = L_add( L_tmp, L_tmp ); /* 2*Q_exc+1 */ +#endif + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ + tmp = add( add( Q_exc, Q_exc ), 1 ); + sp[i] = L_shr( L_tmp, sub( tmp, 6 ) ); + move32(); /* Q6 */ + + ptR++; + ptI--; + } + + Copy32( sp, env, NUM_ENV_CNG ); + IF( element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT ) + { + Word16 index; + att = 0; + index = apply_scale_ind( &att, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); + // att = powf(10, att / 10.0f); + tmp = att_pow_tbl[index]; // Q15 + } + ELSE + { + CNG_mode = get_cng_mode( last_active_brate ); + /* att = 1/pow(2,ENR_ATT_fx[CNG_mode]); */ + L_tmp = L_shl( L_deposit_l( ENR_ATT_fx[CNG_mode] ), 8 ); /* 16 */ + temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); + + exp_pow = sub( 14, temp_hi_fx ); + L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ + L_tmp = L_shl( L_tmp, sub( 13, exp_pow ) ); /* Q13 */ + tmp = extract_l( L_tmp ); /* Q13 */ + + exp1 = norm_s( tmp ); + tmp = shl( tmp, exp1 ); /*Q(exp1+13) */ + tmp = div_s( 16384, tmp ); /*Q(15+14-exp1-13) */ + tmp = shr( tmp, sub( 1, exp1 ) ); /* Q15 */ + } + + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + env[i] = Mult_32_16( env[i], tmp ); + move32(); + } + + /* update the circular buffer of old residual envelope */ + /* Copy32( env, &(ho_env_circ[add(shl(*ho_circ_ptr,4),shl(*ho_circ_ptr,2))]), NUM_ENV_CNG ); */ + Copy32( env, &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); + } + *ho_circ_size = add( *ho_circ_size, 1 ); + if ( GT_16( *ho_circ_size, HO_HIST_SIZE ) ) + { + *ho_circ_size = HO_HIST_SIZE; + move16(); + } + + return; +} +#endif // IVAS_FLOAT_FIXED + /*---------------------------------------------------------------------* * get_cng_mode() * diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 10a198e23..c51c73ba0 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -2995,6 +2995,8 @@ extern const Word16 Idx2Freq_Tbl[]; #define FS_32K_IN_NS_Q31 68719 #define FS_16K_IN_NS_Q31 34360 +#define ONE_BY_THREE_Q15 10923 /* 1/3.f in Q15 */ + typedef enum { MCT_CHAN_MODE_REGULAR, diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 941e458fe..dc928860c 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -54,6 +54,121 @@ ivas_error createFdCngCom( * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) +{ + /* Calculate CLDFB scaling factor */ + /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ + /*hFdCngCom->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ + assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) ); + /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ + hFdCngCom->invScalingFactor = shl( mult( scale, scale ), 1 ); + /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ + hFdCngCom->scalingFactor = div_s( 0x4000, hFdCngCom->invScalingFactor ); + + /* Initialize the overlap-add */ + set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k ); + hFdCngCom->olapBufferAna = NULL; + set16_fx( hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); + + move16(); + set16_fx( hFdCngCom->olapBufferSynth, 0, FFTLEN ); + hFdCngCom->olapBufferSynth2 = NULL; + move16(); + + /* Initialize the comfort noise generation */ + set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN ); + set32_fx( hFdCngCom->cngNoiseLevel, 0, FFTCLDFBLEN ); + set16_fx( &hFdCngCom->cngNoiseLevelExp, 0, 1 ); + + /* Initialize quantizer */ + set32_fx( hFdCngCom->sidNoiseEst, 0, NPART ); + set16_fx( &hFdCngCom->sidNoiseEstExp, 0, 1 ); + set16_fx( hFdCngCom->A_cng, 0, M + 1 ); + hFdCngCom->A_cng[0] = 4096 /*1.f Q12*/; /* 3Q12 */ + move16(); + + /* Set some counters and flags */ + hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ + move16(); + hFdCngCom->active_frame_counter = 0; + move16(); + hFdCngCom->frame_type_previous = ACTIVE_FRAME; + move16(); + hFdCngCom->flag_noisy_speech = 0; + move16(); + hFdCngCom->likelihood_noisy_speech = 0; + move16(); + hFdCngCom->numCoreBands = 0; + move16(); + hFdCngCom->stopBand = 0; + move16(); + hFdCngCom->startBand = 0; + move16(); + hFdCngCom->stopFFTbin = 0; + move16(); + hFdCngCom->frameSize = 0; + move16(); + hFdCngCom->fftlen = 0; + move16(); + hFdCngCom->seed = 0; + move16(); + hFdCngCom->seed2 = 1; + move16(); + hFdCngCom->seed3 = 2; + move16(); + hFdCngCom->CngBitrate = -1; + move16(); + + /* Initialize noise estimation algorithm */ + set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN ); + mhvals( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win ) ); + mhvals( MSSUBFRLEN, &( hFdCngCom->msM_subwin ) ); + set32_fx( hFdCngCom->msPeriodogSum, 0, 2 ); + hFdCngCom->msPeriodogSum_exp[0] = 0; + move16(); + hFdCngCom->msPeriodogSum_exp[1] = 0; + move16(); + set32_fx( hFdCngCom->msPsdSum, 0, 2 ); + set16_fx( hFdCngCom->msSlope, 0, 2 ); + set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); + hFdCngCom->msQeqInvAv_exp[0] = 0; + move16(); + hFdCngCom->msQeqInvAv_exp[1] = 0; + move16(); + hFdCngCom->msFrCnt_init_counter = 0; + move16(); + hFdCngCom->msFrCnt_init_thresh = 1; + move16(); + hFdCngCom->init_old = 0; + move16(); + hFdCngCom->offsetflag = 0; + move16(); + hFdCngCom->msFrCnt = MSSUBFRLEN; + move16(); + hFdCngCom->msMinBufferPtr = 0; + move16(); + hFdCngCom->msAlphaCor[0] = 644245120l /*0.3f Q31*/; + move16(); + hFdCngCom->msAlphaCor[1] = 644245120l /*0.3f Q31*/; + move16(); + set16_fx( hFdCngCom->psize, 0, NPART ); + /* Initialize exponents */ + hFdCngCom->exp_cldfb_periodog = 0; + move16(); + + hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */ + move16(); + + set32_fx( hFdCngCom->olapBufferSynth_fx, 0, FFTLEN ); + set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); + set32_fx( hFdCngCom->exc_cng_32fx, 0, L_FRAME16k ); + hFdCngCom->likelihood_noisy_speech_32fx = 0; + move32(); + + return; +} +#endif void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) { /* Calculate CLDFB scaling factor */ @@ -1699,6 +1814,41 @@ void apply_scale( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------- + * apply_scale_ind() + * + * Apply bitrate-dependent scale + * returns index of scaleTable + *-------------------------------------------------------------------*/ +Word16 apply_scale_ind( + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ +) +{ + Word16 i; + // PMT("Verifiy if the basop ued are ok for stereo too") + FOR( i = 0; i < scaleTableSize; i++ ) + { + cast16(); + IF( s_and( (Word16) EQ_16( bwmode, (Word16) scaleTable[i].bwmode ), + s_and( L_sub( bitrate, scaleTable[i].bitrateFrom ) >= 0, + L_sub( bitrate, scaleTable[i].bitrateTo ) < 0 ) ) ) + { + BREAK; + } + } + + { + *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); + } + return i; +} +#endif // IVAS_FLOAT_FIXED + /*------------------------------------------------------------------- * bandcombinepow() * diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 227672dd4..dfa7879c0 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -143,3 +143,690 @@ Word16 Q_factor_arrL(float *x, Word16 l) } return Q; } +#ifdef IVAS_FLOAT_FIXED +void stereo_tcx_dec_mode_switch_reconf_To_fixed( + Decoder_State *st, + Word16 tofix, + Word16 last_element_mode ) +{ + bool reconf = ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || + ( st->bwidth != st->last_bwidth ) || + ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || + ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ); + if ( reconf ) + { + + H_IGF_GRID hGrid; + IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; + hPrivateData = &st->hIGFDec->igfData; + H_IGF_INFO hIGFInfo = &hPrivateData->igfInfo; + ACELP_config *pConfigAcelp = &( st->acelp_cfg ); + Word16 i = 0, + Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, Q_mem_syn_r = 0, Q_old_exc = 0, Q_fer_samples = 0, + Q_mem_syn2 = 0, Q_cldfbAna_cldfb_state = 0, Q_cldfbBPF_cldfb_state = 0, Q_cldfbSyn_cldfb_state = 0, Q_cldfbSynHB_cldfb_state = 0, + Q_state_lpc_syn = 0, Q_state_syn_shbexc = 0, Q_mem_stp_swb = 0, Q_mem_zero_swb = 0, Q_old_Aq_12_8 = 12, Q_pst_old_syn = 0, Q_mem_stp = 0, Q_mem_pf_in = 0, + Q_mem_res2 = 0, delay_comp = 0, Q_loBuffer = 0; + Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ) - 1; + Word16 Q_lsf_cng = Q_factor( 6400 ); + Word16 Q_old_enr_LP = Q_factor( st->old_enr_LP_float ); + Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0, Q_tcxltp_gain_post_prev = 0; + TD_BWE_DEC_HANDLE hBWE_TD = st->hBWE_TD; + Word16 Q_old_bwe_exc = 0, Q_bwe_non_lin_prev_scale = 0, Q_mem_genSHBexc_filt_down_wb2 = 0, Q_mem_genSHBexc_filt_down_wb3 = 0, Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_mem_genSHBexc_filt_down_shb = 0, Q_syn_overlap = 0, Q_mem_csfilt = 0, Q_tbe_demph = 0, Q_tbe_premph = 0, Q_gain_prec_swb = 0, Q_GainShape_Delay = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0, Q_prev_fb_ener_adjust = 0, Q_fb_state_lpc_syn = 0, Q_fbbwe_hpf_mem = 0, Q_prev_fbbwe_ratio = 0, Q_fb_tbe_demph = 0, + Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; + + if ( tofix ) + { + hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; + floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); + hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); + hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; + floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); + hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); + hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; + floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); + hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); + hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + st->sr_core = getCoreSamplerateMode2( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, 15 ); + Q_syn = Q_factor_arr( st->syn_float, 17 ); + Q_old_exc = Q_factor_arr( st->old_exc, L_EXC_MEM_DEC ) - 1; + Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ) - 1; + Q_mem_syn2 = Q_mem_syn_r; + floatToFixed_arr( st->old_exc, st->old_exc_fx, Q_old_exc, L_EXC_MEM_DEC ); + floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn_r, L_SYN_MEM ); + floatToFixed_arr( st->syn_float, st->syn, Q_syn, M + 1 ); + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, 15, M ); + floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, 15, M ); + floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn2, M ); + FOR( i = 0; i < M; i++ ) + { + st->mem_MA_fx[i] = (Word16) floatToFixed( (float) ( st->mem_MA[i] * 2.56 ), 0 ); + st->mem_AR_fx[i] = (Word16) floatToFixed( (float) ( st->mem_AR[i] * 2.56 ), 0 ); + st->lsf_old_fx[i] = (Word16) floatToFixed( (float) ( st->lsf_old[i] * 2.56 / st->scale), 0 ); + st->lsfold_uw[i] = (Word16) floatToFixed( (float) ( st->lsfold_uw_float[i] * 2.56 / st->scale), 0 ); + } + IF( st->hTcxCfg ) + { + st->hTcxCfg->preemph_fac = (Word16) floatToFixed( st->hTcxCfg->preemph_fac_flt, 15 ); + st->hTcxCfg->sq_rounding = (Word16) floatToFixed( st->hTcxCfg->sq_rounding_flt, 15 ); + st->hTcxCfg->bandwidth = (Word16) floatToFixed( st->hTcxCfg->bandwidth_flt, 15 ); + st->hTcxCfg->na_scale = (Word16) floatToFixed( st->hTcxCfg->na_scale_flt, 15 ); + + Word16 n = st->L_frame; + Word16 n0 = shr( imult1616( n, 9 ), 5 ); + Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[i], 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_trunc[n1 - n / 2 - 1 - i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[n / 2 + i], 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_flt[i], 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_flt[i], 15 ); + } + n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); + n0 = shr( imult1616( n, 9 ), 5 ); + n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i], 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); + } + } + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + { + st->old_pitch_buf_fx[i] = floatToFixed( st->old_pitch_buf[i], 16 ); + } + IF( st->hTcxDec ) + { + st->hTcxDec->Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 ) - 1; + st->hTcxDec->Q_syn_Overl_TDAC = Q_factor_arr( st->hTcxDec->syn_Overl_TDAC_float, L_FRAME32k / 2 ) - 1; + st->hTcxDec->Q_syn_Overl = Q_factor_arr( st->hTcxDec->syn_Overl_float, L_FRAME32k / 2 ) - 1; + st->hTcxDec->Q_syn_Overl_TDACFB = Q_factor_arr( st->hTcxDec->syn_Overl_TDACFB_float, L_FRAME32k / 2 ); + st->hTcxDec->Q_syn_OverlFB = Q_factor_arr( st->hTcxDec->syn_OverlFB_float, L_FRAME_MAX / 2 ); + Q_old_synth = Q_syn; + Q_synth_history = Q_factor_arr( st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX ); + floatToFixed_arr( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, st->hTcxDec->Q_old_syn_Overl, L_FRAME32k / 2 ); + floatToFixed_arr( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, st->hTcxDec->Q_syn_Overl_TDAC, L_FRAME32k / 2 ); + floatToFixed_arr( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, st->hTcxDec->Q_syn_Overl, L_FRAME32k / 2 ); + floatToFixed_arr( st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, st->hTcxDec->Q_syn_Overl_TDACFB, L_FRAME_MAX / 2 ); + floatToFixed_arr( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->hTcxDec->Q_syn_OverlFB, L_FRAME_MAX / 2 ); + floatToFixed_arr( st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); + floatToFixed_arr( st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, Q_synth_history, L_PROT48k + L_FRAME_MAX ); + Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); + st->hTcxDec->old_gaintcx_bfi = (Word16) floatToFixed( st->hTcxDec->old_gaintcx_bfi_float, Q_old_gaintcx_bfi ); + st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); + st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + st->output_frame_fx = st->hTcxDec->L_frameTCX; + st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, 15 ); + st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, 14 ); + st->hTcxDec->LastFrameLevel_bfi_fx = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 ); + FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) + { + st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16) floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); + } + st->hTcxDec->cummulative_damping_tcx = (Word16) floatToFixed( st->hTcxDec->cummulative_damping_tcx_float, 15 ); + } + IF( st->hHQ_core ) + { + st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; + st->hHQ_core->Q_old_out = Q_factor_arr( st->hHQ_core->old_out, L_FRAME48k ); + st->hHQ_core->Q_old_outLB = Q_factor_arr( st->hHQ_core->old_outLB, L_FRAME32k ); + floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); + floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->hHQ_core->Q_old_out, L_FRAME48k ); + floatToFixed_arr( st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->hHQ_core->Q_old_outLB, L_FRAME32k ); + } + IF( st->cldfbAna ) + { + Q_cldfbAna_cldfb_state = Q_factor_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q_cldfbAna_cldfb_state, st->cldfbAna->cldfb_state_length ); + } + IF( st->cldfbBPF ) + { + Q_cldfbBPF_cldfb_state = Q_factor_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q_cldfbBPF_cldfb_state, st->cldfbBPF->cldfb_state_length ); + } + IF( st->cldfbSyn ) + { + Q_cldfbSyn_cldfb_state = Q_factor_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q_cldfbSyn_cldfb_state, st->cldfbSyn->cldfb_state_length ); + } + IF( st->cldfbSynHB ) + { + Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); + } + floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q_old_Aq_12_8, M + 1 ); + st->tilt_code_fx = (Word16) floatToFixed( st->tilt_code, 15 ); + IF( st->hBPF ) + { + Q_pst_old_syn = Q_syn; + Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); + floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, Q_pst_old_syn, NBPSF_PIT_MAX ); + } + IF( st->hPFstat ) + { + Q_mem_stp = Q_factor_arr( st->hPFstat->mem_stp_flt, L_SUBFR ) - 1; + Q_mem_pf_in = Q_factor_arr( st->hPFstat->mem_pf_in_flt, L_SUBFR ) - 1; + Q_mem_res2 = Q_factor_arr( st->hPFstat->mem_res2_flt, DECMEM_RES2 ) - 1; + floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, Q_mem_stp, L_SUBFR ); + floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, Q_mem_pf_in, L_SUBFR ); + floatToFixed_arr( st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, Q_mem_res2, DECMEM_RES2 ); + st->hPFstat->gain_prec = (Word16) floatToFixed( st->hPFstat->gain_prec_flt, 14 ); // 1.f + } + + floatToFixed_arr( st->lsf_cng_float, st->lsf_cng, Q_lsf_cng, M ); + st->last_concealed_gain_syn_deemph = (Word16) floatToFixed( st->last_concealed_gain_syn_deemph_float, 14 ); + st->old_enr_LP = (Word16) floatToFixed( st->old_enr_LP_float, Q_old_enr_LP ); + st->enr_old_fx = (Word16) floatToFixed( st->enr_old, 0 ); + floatToFixed_arr( st->previoussynth, st->previoussynth_fx, 0, 960 ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_adaptive_mean_fx[i] = (Word16) floatToFixed( st->lsf_adaptive_mean[i] / 100, 8 ); + st->lsfoldbfi0_fx[i] = (Word16) floatToFixed( st->lsfoldbfi0[i] / 100, 8 ); + st->lsfoldbfi1_fx[i] = (Word16) floatToFixed( st->lsfoldbfi1[i] / 100, 8 ); + } + IF( st->hTcxLtpDec ) + { + Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); + Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); + Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); + st->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) floatToFixed( st->hTcxLtpDec->tcxltp_gain_post_prev_float, Q_tcxltp_gain_post_prev ); + floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_in_float, st->hTcxLtpDec->tcxltp_mem_in, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); + floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_out_float, st->hTcxLtpDec->tcxltp_mem_out, Q_tcxltp_mem_out, L_FRAME48k ); + } + + + floatToFixed_arr( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + // st->last_gain_syn_deemph = floatToFixed(st->last_gain_syn_deemph_float, 14); + st->last_gain_syn_deemph = 0; + IF( hBWE_TD ) + { + Q_old_bwe_exc = Q_factor_arr( hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); + floatToFixed_arr( hBWE_TD->old_bwe_exc, hBWE_TD->old_bwe_exc_fx, Q_old_bwe_exc, PIT16k_MAX * 2 ); + Q_bwe_non_lin_prev_scale = Q_factor_L( hBWE_TD->bwe_non_lin_prev_scale ); + hBWE_TD->bwe_non_lin_prev_scale_fx = floatToFixed( hBWE_TD->bwe_non_lin_prev_scale, Q_bwe_non_lin_prev_scale ); + Q_mem_genSHBexc_filt_down_wb2 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, 7 ); + floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, Q_mem_genSHBexc_filt_down_wb2, 7 ); + Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); + floatToFixed_arr( hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_shb_fx, Q_state_lsyn_filt_shb, 6 ); + Q_mem_genSHBexc_filt_down_wb3 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, 7 ); + floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, Q_mem_genSHBexc_filt_down_wb3, 7 ); + Q_state_lsyn_filt_dwn_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_dwn_shb, 6 ); + floatToFixed_arr( hBWE_TD->state_lsyn_filt_dwn_shb, hBWE_TD->state_lsyn_filt_dwn_shb_fx, Q_state_lsyn_filt_dwn_shb, 6 ); + Q_mem_resamp_HB = Q_factor_arr( hBWE_TD->mem_resamp_HB, 13 ); + floatToFixed_arr( hBWE_TD->mem_resamp_HB, hBWE_TD->mem_resamp_HB_fx, Q_mem_resamp_HB, 13 ); + hBWE_TD->prev_pow_exc16kWhtnd_fx = (Word16) floatToFixed( hBWE_TD->prev_pow_exc16kWhtnd, 15 ); + hBWE_TD->prev_mix_factor_fx = (Word16) floatToFixed( hBWE_TD->prev_mix_factor, 15 ); + Q_mem_genSHBexc_filt_down_shb = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, 7 ); + floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, Q_mem_genSHBexc_filt_down_shb, 7 ); + Q_state_lpc_syn = Q_factor_arr( hBWE_TD->state_lpc_syn, 10 ); + floatToFixed_arr( hBWE_TD->state_lpc_syn, hBWE_TD->state_lpc_syn_fx, Q_state_lpc_syn, 10 ); + Q_state_syn_shbexc = Q_factor_arr( hBWE_TD->state_syn_shbexc, 20 ); + floatToFixed_arr( hBWE_TD->state_syn_shbexc, hBWE_TD->state_syn_shbexc_fx, Q_state_syn_shbexc, 20 ); + Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); + floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, Q_syn_overlap, 20 ); + Q_mem_csfilt = Q_factor_arrL( hBWE_TD->mem_csfilt, 2 ); + floatToFixed_arrL( hBWE_TD->mem_csfilt, hBWE_TD->mem_csfilt_fx, Q_mem_csfilt, 2 ); + Q_tbe_demph = Q_factor( (Word16) hBWE_TD->tbe_demph ); + Q_tbe_premph = Q_factor( (Word16) hBWE_TD->tbe_premph ); + Q_gain_prec_swb = Q_factor( (Word16) hBWE_TD->gain_prec_swb ); + Q_mem_stp_swb = Q_factor_arr( hBWE_TD->mem_stp_swb, 10 ); + Q_GainShape_Delay = Q_factor_arr( hBWE_TD->GainShape_Delay, 8 ); + Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); + Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); + Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); + Q_fbbwe_hpf_mem = Q_factor_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], 16 ); + Q_prev_fbbwe_ratio = Q_factor( (Word16) hBWE_TD->prev_fbbwe_ratio ); + st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); + floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, Q_fb_state_lpc_syn, 10 ); + floatToFixed_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], &hBWE_TD->fbbwe_hpf_mem_fx[0][0], Q_fbbwe_hpf_mem, 16 ); + hBWE_TD->prev_fbbwe_ratio_fx = (Word16) floatToFixed( hBWE_TD->prev_fbbwe_ratio, Q_prev_fbbwe_ratio ); + Q_fb_tbe_demph = Q_factor( (Word16) hBWE_TD->fb_tbe_demph ); + hBWE_TD->fb_tbe_demph_fx = (Word16) floatToFixed( hBWE_TD->fb_tbe_demph, Q_fb_tbe_demph ); + hBWE_TD->tbe_demph_fx = (Word16) floatToFixed( hBWE_TD->tbe_demph, Q_tbe_demph ); + hBWE_TD->tbe_premph_fx = (Word16) floatToFixed( hBWE_TD->tbe_premph, Q_tbe_premph ); + hBWE_TD->gain_prec_swb_fx = (Word16) floatToFixed( hBWE_TD->gain_prec_swb, 14 ); + floatToFixed_arr( hBWE_TD->GainShape_Delay, st->GainShape_Delay, Q_GainShape_Delay, 8 ); + floatToFixed_arr( hBWE_TD->int_3_over_2_tbemem_dec, hBWE_TD->int_3_over_2_tbemem_dec_fx, Q_int_3_over_2_tbemem_dec, INTERP_3_2_MEM_LEN ); + floatToFixed_arr( hBWE_TD->mem_resamp_HB_32k, hBWE_TD->mem_resamp_HB_32k_fx, Q_mem_resamp_HB_32k, 7 ); + Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); + floatToFixed_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, Q_genSHBsynth_Hilbert_Mem, 21 ); + Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); + floatToFixed_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, Q_genSHBsynth_state_lsyn_filt_shb_local, 6 ); + floatToFixed_arr( hBWE_TD->mem_stp_swb, hBWE_TD->mem_stp_swb_fx, Q_mem_stp_swb, 10 ); + Q_mem_zero_swb = Q_factor_arr( hBWE_TD->mem_zero_swb, LPC_SHB_ORDER ); + floatToFixed_arr( hBWE_TD->mem_zero_swb, hBWE_TD->mem_zero_swb_fx, Q_mem_zero_swb, LPC_SHB_ORDER ); + } + IF( st->hTECDec ) + { + Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); + floatToFixed_arr( st->hTECDec->loBuffer_flt, st->hTECDec->loBuffer, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); + } + st->TcxBandwidth = (Word16) floatToFixed( st->TcxBandwidth_float, 15 ); + } + else + { + Q_old_exc = Q_factor_arr( st->old_exc, L_EXC_MEM_DEC ) - 1; + Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ) - 1; + Q_mem_syn2 = Q_mem_syn_r; + Q_syn = Q_factor_arr( st->syn_float, 17 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; + fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); + hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); + hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; + fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); + hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); + hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; + fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); + hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); + hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); + IF( st->hIGFDec ) + { + st->hIGFDec->virtualSpec_float = &st->hIGFDec->virtualSpecBuf[0]; + st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; + st->hIGFDec->igfData.igfInfo.nfSeed = &st->hIGFDec->igfData.igfInfo.nfSeedBuf[0]; + } + st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); + st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); + IF( EQ_32( st->sr_core, INT_FS_16k ) ) + { + st->gamma_float = GAMMA16k_FLT; + move16(); + } + ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + st->gamma_float = GAMMA16k_FLT; + move16(); + } + ELSE + { + st->gamma_float = GAMMA1_FLT; + move16(); + } + IF( st->hBWE_TD != NULL ) + { + Q_old_bwe_exc = Q_factor_arr( hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); + Q_bwe_non_lin_prev_scale = Q_factor_L( hBWE_TD->bwe_non_lin_prev_scale ); + Q_mem_genSHBexc_filt_down_wb2 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, 7 ); + Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); + Q_mem_genSHBexc_filt_down_wb3 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, 7 ); + Q_state_lsyn_filt_dwn_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_dwn_shb, 6 ); + Q_mem_resamp_HB = Q_factor_arr( hBWE_TD->mem_resamp_HB, 13 ); + Q_mem_genSHBexc_filt_down_shb = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, 7 ); + Q_state_lpc_syn = Q_factor_arr( hBWE_TD->state_lpc_syn, 10 ); + Q_state_syn_shbexc = Q_factor_arr( hBWE_TD->state_syn_shbexc, 20 ); + Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); + Q_mem_csfilt = Q_factor_arrL( hBWE_TD->mem_csfilt, 2 ); + Q_tbe_demph = Q_factor( (Word16) hBWE_TD->tbe_demph ); + Q_tbe_premph = Q_factor( (Word16) hBWE_TD->tbe_premph ); + Q_gain_prec_swb = Q_factor( (Word16) hBWE_TD->gain_prec_swb ); + Q_mem_stp_swb = Q_factor_arr( hBWE_TD->mem_stp_swb, 10 ); + Q_GainShape_Delay = Q_factor_arr( hBWE_TD->GainShape_Delay, 8 ); + Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); + Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); + Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); + Q_fbbwe_hpf_mem = Q_factor_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], 16 ); + Q_prev_fbbwe_ratio = Q_factor( (Word16) hBWE_TD->prev_fbbwe_ratio ); + Q_fb_tbe_demph = Q_factor( (Word16) hBWE_TD->fb_tbe_demph ); + Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); + Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); + Q_mem_zero_swb = Q_factor_arr( hBWE_TD->mem_zero_swb, LPC_SHB_ORDER ); + fixedToFloat_arr( st->hBWE_TD->prev_lsf_diff_fx, st->hBWE_TD->prev_lsf_diff, 15, LPC_SHB_ORDER - 2 ); + st->hBWE_TD->prev_tilt_para = 0.0f; + fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, 15, M + 1 ); + fixedToFloat_arr( hBWE_TD->old_bwe_exc_fx, hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( hBWE_TD->bwe_non_lin_prev_scale_fx, Q_bwe_non_lin_prev_scale ); + fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2, Q_mem_genSHBexc_filt_down_wb2, 7 ); + fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3, Q_mem_genSHBexc_filt_down_wb3, 7 ); + fixedToFloat_arr( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb, Q_state_lsyn_filt_shb, 6 ); + fixedToFloat_arr( hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb, Q_state_lsyn_filt_dwn_shb, 6 ); + fixedToFloat_arr( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB, Q_mem_resamp_HB, 13 ); + fixedToFloat_arr( hBWE_TD->state_syn_shbexc_fx, hBWE_TD->state_syn_shbexc, Q_state_syn_shbexc, 20 ); + fixedToFloat_arrL( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_csfilt, Q_mem_csfilt, 2 ); + fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_shb, Q_mem_genSHBexc_filt_down_shb, 7 ); + fixedToFloat_arr( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap, Q_syn_overlap, 20 ); + fixedToFloat_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, Q_genSHBsynth_state_lsyn_filt_shb_local, HILBERT_MEM_SIZE ); + fixedToFloat_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem, Q_genSHBsynth_Hilbert_Mem, HILBERT_MEM_SIZE ); + hBWE_TD->tbe_demph = fixedToFloat( hBWE_TD->tbe_demph_fx, Q_tbe_demph ); + hBWE_TD->tbe_premph = fixedToFloat( hBWE_TD->tbe_premph_fx, Q_tbe_premph ); + fixedToFloat_arr( st->GainShape_Delay, hBWE_TD->GainShape_Delay, Q_GainShape_Delay, 8 ); + fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); + fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); + bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); + if ( ( st->bwidth == SWB || st->bwidth == FB ) && st->igf && ( st->bwidth == SWB || st->bwidth == FB ) ) + { + hBWE_TD->prev_pow_exc16kWhtnd = (float) hBWE_TD->prev_pow_exc16kWhtnd_fx / 32767; + hBWE_TD->prev_mix_factor = (float) hBWE_TD->prev_mix_factor_fx / 32767; + } + st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); + hBWE_TD->fb_tbe_demph = fixedToFloat( hBWE_TD->fb_tbe_demph_fx, Q_fb_tbe_demph ); + fixedToFloat_arrL( &hBWE_TD->fbbwe_hpf_mem_fx[0][0], &hBWE_TD->fbbwe_hpf_mem[0][0], Q_fbbwe_hpf_mem, 16 ); + hBWE_TD->prev_fbbwe_ratio = fixedToFloat( hBWE_TD->prev_fbbwe_ratio_fx, Q_prev_fbbwe_ratio ); + fixedToFloat_arr( hBWE_TD->state_lpc_syn_fx, hBWE_TD->state_lpc_syn, Q_state_lpc_syn, LPC_SHB_ORDER ); + fixedToFloat_arr( hBWE_TD->state_syn_shbexc_fx, hBWE_TD->state_syn_shbexc, Q_state_syn_shbexc, L_SHB_LAHEAD ); + fixedToFloat_arr( hBWE_TD->mem_stp_swb_fx, hBWE_TD->mem_stp_swb, Q_mem_stp_swb, LPC_SHB_ORDER ); + fixedToFloat_arr( hBWE_TD->mem_zero_swb_fx, hBWE_TD->mem_zero_swb, Q_mem_zero_swb, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb = fixedToFloat( hBWE_TD->gain_prec_swb_fx, 14 ); + } + st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); + IF( st->hTECDec != NULL ) + { + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + st->hTECDec->pGainTemp[i] = 0; + } + Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); + fixedToFloat_arr( st->hTECDec->loBuffer, st->hTECDec->loBuffer_flt, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); + } + IF( st->hTcxCfg ) + { + st->hTcxCfg->preemph_fac_flt = fixedToFloat( st->hTcxCfg->preemph_fac, 15 ); + st->hTcxCfg->sq_rounding_flt = fixedToFloat( st->hTcxCfg->sq_rounding, 15 ); + st->hTcxCfg->bandwidth_flt = fixedToFloat( st->hTcxCfg->bandwidth, 15 ); + st->hTcxCfg->na_scale_flt = fixedToFloat( st->hTcxCfg->na_scale, 15 ); + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_flt[st->hTcxCfg->tcx_mdct_window_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_windowFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_windowFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_windowFB_flt[st->hTcxCfg->tcx_mdct_window_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_windowFB[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_trans_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_trans[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_trans_flt[st->hTcxCfg->tcx_mdct_window_trans_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_trans[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_transFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_transFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_transFB_flt[st->hTcxCfg->tcx_mdct_window_trans_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_transFB[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_half_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_half[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_half_flt[st->hTcxCfg->tcx_mdct_window_half_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_half[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_halfFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_halfFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_halfFB_flt[st->hTcxCfg->tcx_mdct_window_half_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_halfFB[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_minimum_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimum[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_minimum_flt[st->hTcxCfg->tcx_mdct_window_min_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimum[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_minimumFB_flt[st->hTcxCfg->tcx_mdct_window_min_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re, 15 ); + } + Word16 n = st->L_frame; + Word16 n0 = shr( imult1616( n, 9 ), 5 ); + Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_trunc[i - n0].v.im, 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_trunc[n1 - n / 2 - 1 - i].v.re, 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2[i].v.im, 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2[n2 - i - 1].v.re, 15 ); + } + n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); + n0 = shr( imult1616( n, 9 ), 5 ); + n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im, 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re, 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im, 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re, 15 ); + } + st->hTcxCfg->tcx_aldo_window_1_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_flt + NS2SA( st->sr_core, N_ZERO_MDCT_NS ); + st->hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ); + } + IF( st->hTcxDec ) + { + Q_old_synth = Q_syn; + Q_synth_history = Q_factor_arr( st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX ); + st->hTcxDec->Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 ) - 1; + fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, st->hTcxDec->Q_old_syn_Overl, L_FRAME32k / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl_TDAC, st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->Q_syn_Overl_TDAC, 320 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->hTcxDec->Q_syn_Overl, 320 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl_TDACFB, st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->Q_syn_Overl_TDACFB, 480 ); + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->hTcxDec->Q_syn_OverlFB, 480 ); + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); + fixedToFloat_arr( st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, Q_synth_history, L_PROT48k + L_FRAME_MAX ); + fixedToFloat_arr( st->hTcxDec->ltpGainMemory_fx, st->hTcxDec->ltpGainMemory, 15, N_LTP_GAIN_MEMS ); + st->hTcxDec->tcxltp_second_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_second_last_pitch, 16 ); + st->hTcxDec->tcxltp_third_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_third_last_pitch, 16 ); + Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); + st->hTcxDec->old_gaintcx_bfi_float = fixedToFloat( st->hTcxDec->old_gaintcx_bfi, Q_old_gaintcx_bfi ); + st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, 14 ); + st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, 15 ); + st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->LastFrameLevel_bfi_fx, 15 ); + FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) + { + st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); + } + st->hTcxDec->cummulative_damping_tcx_float = fixedToFloat( st->hTcxDec->cummulative_damping_tcx, 15 ); + } + fixedToFloat_arr( st->syn, st->syn_float, Q_syn, M + 1 ); + fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, L_EXC_MEM_DEC ); + fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn_r, L_SYN_MEM ); + fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, 15, M ); + fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn2, M ); + fixedToFloat_arr( st->lspold_uw, st->lspold_uw_float, 15, M ); + FOR( i = 0; i < M; i++ ) + { + st->mem_AR[i] = fixedToFloat( L_mult( st->mem_AR_fx[i], 100 ), 9 ); + st->mem_MA[i] = fixedToFloat( L_mult( st->mem_MA_fx[i], 100 ), 9 ); + st->lsfold_uw_float[i] = (float) st->lsfold_uw[i] / ( 2.56f / st->scale ); + st->lsf_old[i] = (float) st->lsf_old_fx[i] / ( 2.56f / st->scale ); + } + IF( st->hHQ_core ) + { + fixedToFloat_arr( st->hHQ_core->old_out_fx, st->hHQ_core->old_out, st->hHQ_core->Q_old_out, L_FRAME48k ); + fixedToFloat_arr( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_outLB, st->hHQ_core->Q_old_outLB, L_FRAME32k ); + } + IF( st->cldfbAna ) + { + Q_cldfbAna_cldfb_state = Q_factor_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q_cldfbAna_cldfb_state, st->cldfbAna->cldfb_state_length ); + } + IF( st->cldfbBPF ) + { + Q_cldfbBPF_cldfb_state = Q_factor_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q_cldfbBPF_cldfb_state, st->cldfbBPF->cldfb_state_length ); + } + IF( st->cldfbSyn ) + { + Q_cldfbSyn_cldfb_state = Q_factor_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q_cldfbSyn_cldfb_state, st->cldfbSyn->cldfb_state_length ); + } + IF( st->cldfbSynHB ) + { + Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); + } + Word16 scale_fac = norm_s( st->old_Aq_12_8_fx[0] ) - 2; + Scale_sig( st->old_Aq_12_8_fx, M + 1, scale_fac ); + fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q_old_Aq_12_8, M + 1 ); + st->tilt_code = fixedToFloat( st->tilt_code_fx, 15 ); + IF( st->hBPF ) + { + Q_pst_old_syn = Q_syn; + Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); + fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err = 0; + } + IF( st->hPFstat ) + { + Q_mem_stp = Q_factor_arr( st->hPFstat->mem_stp_flt, L_SUBFR ) - 1; + Q_mem_pf_in = Q_factor_arr( st->hPFstat->mem_pf_in_flt, L_SUBFR ) - 1; + Q_mem_res2 = Q_factor_arr( st->hPFstat->mem_res2_flt, DECMEM_RES2 ) - 1; + fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, Q_mem_stp, L_SUBFR ); + fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, Q_mem_pf_in, L_SUBFR ); + fixedToFloat_arr( st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, Q_mem_res2, DECMEM_RES2 ); + st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, 14 ); // 1.f + } + Q_lsf_cng = Q_factor( 6400 ); + fixedToFloat_arr( st->lsf_cng, st->lsf_cng_float, Q_lsf_cng, M ); + st->past_gpit_float = fixedToFloat( st->past_gpit, 0 ); + st->past_gcode_float = fixedToFloat( st->past_gcode, 0 ); + st->gc_threshold = fixedToFloat( st->gc_threshold_fx, 0 ); + fixedToFloat_arr( st->lspold_cng, st->lspold_cng_float, 15, M ); + fixedToFloat_arr( st->Aq_cng, st->Aq_cng_float, 2, M ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_q_cng_float[i] = fixedToFloat( L_mult( st->lsf_q_cng[i], 100 ), 9 ); + st->old_lsf_q_cng_float[i] = fixedToFloat( L_mult( st->old_lsf_q_cng[i], 100 ), 9 ); + } + fixedToFloat_arr( st->lsp_q_cng, st->lsp_q_cng_float, 15, M ); + fixedToFloat_arr( st->old_lsp_q_cng, st->old_lsp_q_cng_float, 15, M ); + fixedToFloat_arr( st->mem_syn_unv_back, st->mem_syn_unv_back_float, 0, M ); + fixedToFloat_arr( st->mem_Aq, st->mem_Aq_float, 0, NB_SUBFR16k * ( M + 1 ) ); + if ( st->last_gain_syn_deemph == 16384 ) + { + st->last_gain_syn_deemph_float = 1; + } + st->last_concealed_gain_syn_deemph_float = fixedToFloat( st->last_concealed_gain_syn_deemph, 14 ); + st->lp_ener_bfi = fixedToFloat( st->lp_ener_FER_fx, 8 ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_adaptive_mean[i] = fixedToFloat( L_mult( st->lsf_adaptive_mean_fx[i], 100 ), 9 ); + st->lsfoldbfi0[i] = fixedToFloat( L_mult( st->lsfoldbfi0_fx[i], 100 ), 9 ); + st->lsfoldbfi1[i] = fixedToFloat( L_mult( st->lsfoldbfi1_fx[i], 100 ), 9 ); + } + st->old_enr_LP_float = fixedToFloat( st->old_enr_LP, Q_old_enr_LP ); + st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); + st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 0 ); + st->lp_gainp = fixedToFloat( st->lp_gainp_fx, 0 ); + st->cummulative_damping_float = 1; + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + { + st->old_pitch_buf[i] = fixedToFloat( st->old_pitch_buf_fx[i], 16 ); + } + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + { + st->mem_pitch_gain_float[i] = 1; + } + st->old_fpitch_float = fixedToFloat( st->old_fpitch, 16 ); + FOR( i = 0; i < 8; i++ ) + { + st->dispMem[i] = 0; + } + st->voice_fac_float = st->voice_fac; /* purely unvoiced */ + IF( st->hTcxLtpDec != NULL ) + { + Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); + Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); + Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); + fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); + fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, Q_tcxltp_mem_out, L_FRAME48k ); + st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, Q_tcxltp_gain_post_prev ); + } + IF( st->hTonalMDCTConc ) + { + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_flt[i] = fixedToFloat( st->hTonalMDCTConc->scaleFactorsBackground[i], 15 ); + } + } + IF( st->hPlcInfo ) + { + FOR( i = 0; i < L_FRAME_MAX; i++ ) + { + st->hPlcInfo->data_reci2[i] = fixedToFloat( st->hPlcInfo->data_reci2_fx[i], 0 ); + } + } + st->old_fpitchFB_float = fixedToFloat( st->old_fpitchFB, 16 ); + + IF( pConfigAcelp != NULL ) + { + pConfigAcelp->formant_enh_num_flt = fixedToFloat( pConfigAcelp->formant_enh_num, 15 ); + pConfigAcelp->formant_enh_den_flt = fixedToFloat( pConfigAcelp->formant_enh_den, 15 ); + st->acelp_cfg_rf.formant_enh_num_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_num, 15 ); + st->acelp_cfg_rf.formant_enh_den_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_den, 15 ); + if ( st->mem_syn_clas_estim != NULL ) + { + fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + } + } + } + } +} +#endif // IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 9e27b3612..8bc1bef86 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1661,7 +1661,6 @@ void ivas_DetectTonalComponents_fx( Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ const PsychoacousticParameters* psychParamsCurrent ); -#endif ivas_error stereo_dft_dec_create_fx( STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ @@ -1685,3 +1684,12 @@ ivas_error stereo_memory_dec_fx( const MC_MODE mc_mode, /* i : MC mode */ const Word16 nchan_transport /* i : number of transport channels*/ ); + +void ivas_initFdCngDec_fx( + DEC_CORE_HANDLE st, /* i/o: decoder state structure */ + Word16 scale +); + +void ivas_initFdCngCom_fx(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale); + +#endif diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index e844a58ef..8a704846f 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -1774,6 +1774,58 @@ Word16 vq_dec_lvq_fx( return ber_flag; } +Word16 vq_dec_lvq_ivas_fx( + Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ + Word16 no_bits /* (i): no. bits for lattice */ +) +{ + Word16 x_lvq[M]; + Word16 i, stagesm1; + Word16 pt_fx; + Word16 ber_flag; + + /* clear vector */ + set16_fx( x, 0, N ); + + /*-----------------------------------------------* + * add contribution of each stage + *-----------------------------------------------*/ + stagesm1 = sub( stages, 1 ); + IF( EQ_16( sf_flag, 1 ) ) + { + FOR( i = 0; i < stagesm1; i++ ) + { + pt_fx = i_mult2( indices[i], N ); + Vr_add( x, &Quantizers_fx[CB_lsf[mode] + i][pt_fx], x, N ); + } + + ber_flag = + // deindex_lvq_fx(&indices[stagesm1], x_lvq, mode, sf_flag, no_bits, p_offset_scale1, p_offset_scale2, p_no_scales); + deindex_lvq_ivas_fx( &indices[stagesm1], x_lvq, mode, sf_flag, no_bits ); + } + ELSE + { + FOR( i = 0; i < stagesm1; i++ ) + { + pt_fx = i_mult2( indices[i], N ); + Vr_add( x, &Quantizers_p_fx[CB_p_lsf[mode] + i][pt_fx], x, N ); + } + + ber_flag = + // deindex_lvq_fx(&indices[stagesm1], x_lvq, mode, sf_flag, no_bits, p_offset_scale1_p, p_offset_scale2_p, p_no_scales_p); + deindex_lvq_ivas_fx( &indices[stagesm1], x_lvq, mode, sf_flag, no_bits ); + } + + Vr_add( x, x_lvq, x, N ); + + return ber_flag; +} + ivas_error lsf_allocate_fx( const Word16 nBits, /* i : Number of bits to use for quantization */ const Word16 framemode, /* i : ISF quantizer mode */ diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index 567281556..1e8f89d64 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -31,6 +31,7 @@ *******************************************************************************************************/ #include "options.h" +#include "prot.h" #include "prot_fx2.h" #include "ivas_cnst.h" #include "stl.h" @@ -56,6 +57,15 @@ decode_indexes_fx(Word16 * index, Word16 no_bits, const Word16 * p_scales, Word1 Word32 * p_offset_scale1, Word32 * p_offset_scale2, Word16 * x_lvq, Word16 mode_glb, Word16 *scales); static Word32 divide_32_32_fx(Word32 y, Word32 x, Word32 * rem); static Word16 divide_16_16_fx(Word16 y, Word16 x, Word16 *rem); +static int16_t decode_indexes_ivas_fx( + Word16 *index, + const Word16 no_bits, + const Word16 *p_scales, // Q11 + const Word16 prediction_flag, + Word16 *x_lvq, // Q0 + const Word16 mode_glb, + Word16 *scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector Q11*/ +); /* used in CNG-LP coding */ void permute_fx( @@ -351,6 +361,145 @@ decode_indexes_fx( return 0; } +static int16_t decode_indexes_ivas_fx( + Word16 *index, + const Word16 no_bits, + const Word16 *p_scales, // Q11 + const Word16 prediction_flag, + Word16 *x_lvq, // Q1 + const Word16 mode_glb, + Word16 *scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector Q11*/ +) +{ + // UWord32 index1 = 0, index2, idx_scale; + Word32 index1 = 0, index2, idx_scale; + // uint16_t i; + Word16 i; + // float scale; + // Word16 scale; + + Word16 len_scales = i_mult( MAX_NO_SCALES, 2 ); + UWord32 offset_scale1[MAX_NO_SCALES + 1], offset_scale2[MAX_NO_SCALES + 1]; + + if ( no_bits <= 2 * LEN_INDICE ) /* the third short is not used */ + { + index[2] = 0; + if ( no_bits <= LEN_INDICE ) + { + index[1] = 0; + } + } + + /* safety check in case of bit errors */ + for ( i = 0; i < 3; i++ ) + { + if ( index[i] < 0 ) + { + // set_f(x_lvq, 0.0f, 2 * LATTICE_DIM); + set_s( x_lvq, 0, 2 * LATTICE_DIM ); + index[i] = 0; + return 1; + } + } + + create_offset( offset_scale1, offset_scale2, mode_glb, prediction_flag ); + /* first subvector */ + if ( offset_scale2[MAX_NO_SCALES - 1] > 0 ) + { + // divide_64_32(index, offset_scale2[MAX_NO_SCALES], &index1, &index2); + divide_64_32_fx( index, offset_scale2[MAX_NO_SCALES], &index1, &index2 ); + } + else + { + index1 = (UWord32) ( index[0] ); /* this is for very low bitrates, so there is no loss in truncation */ + index2 = 0; + } + + if ( index1 == 0 ) + { + for ( i = 0; i < LATTICE_DIM; i++ ) + { + // x_lvq[i] = 0.0; + x_lvq[i] = 0; + } + } + else + { + if ( index1 >= (Word32) offset_scale1[MAX_NO_SCALES] ) + { + /* safety check in case of bit errors */ + // set_f(x_lvq, 0.0f, 2 * LATTICE_DIM); + set_s( x_lvq, 0, 2 * LATTICE_DIM ); + return 1; + } + + /* find idx_scale */ + i = 1; + while ( (int16_t) i <= MAX_NO_SCALES && index1 >= (Word32) offset_scale1[i] ) + { + i++; + } + + idx_scale = i - 1; + index1 -= offset_scale1[idx_scale]; + + /* find idx_leader */ + i = 1; + while ( index1 >= (Word32) table_no_cv[i] ) + { + i++; + } + // decode_comb((Word32)(index1 - table_no_cv[i - 1]), x_lvq, i - 1); + decode_comb_fx( (Word32) ( index1 - table_no_cv[i - 1] ), x_lvq, i - 1 ); + scales_mslvq[0] = p_scales[mode_glb * len_scales + idx_scale]; + // for (i = 0; i < LATTICE_DIM; i++) + //{ + // //x_lvq[i] *= scale; + // x_lvq[i] = mult_r(shl(x_lvq[i], Q3), scale); //Q0 + // } + } + + /* second subvector */ + if ( index2 == 0 ) + { + for ( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + // x_lvq[i] = 0.0; + x_lvq[i] = 0; + } + } + else + { + + /* find the index for the scale/truncation */ + i = 1; + while ( index2 >= (Word32) offset_scale2[i] ) + { + i++; + } + + idx_scale = i - 1; + index2 -= offset_scale2[idx_scale]; + /* find the index of the leader vector */ + i = 1; + while ( index2 >= (Word32) table_no_cv[i] ) + { + i++; + } + // decode_comb((Word32)(index2 - table_no_cv[i - 1]), &x_lvq[LATTICE_DIM], i - 1); + decode_comb_fx( (Word32) ( index2 - table_no_cv[i - 1] ), &x_lvq[LATTICE_DIM], i - 1 ); + + scales_mslvq[1] = p_scales[mode_glb * len_scales + MAX_NO_SCALES + idx_scale]; + // for (i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++) + //{ + // //x_lvq[i] *= scale; + // x_lvq[i] = mult_r(shl(x_lvq[i], Q3), scale); //Q0 + // } + } + + return 0; +} + Word16 deindex_lvq_fx( Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ @@ -439,6 +588,111 @@ Word16 deindex_lvq_fx( return ber_flag; } +Word16 deindex_lvq_ivas_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits /* i : number of bits for lattice */ +) +{ + Word16 i; + const Word16 *p_scales; + Word16 mode_glb; + Word32 L_tmp; + // note_ : renamed from scales + Word16 scales_mslvq[2]; + Word16 ber_flag; + + IF( EQ_16( sf_flag, 1 ) ) + { + // mode_glb = add(offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub(no_bits, min_lat_bits_SN_fx[mode])]); + if ( mode < 6 ) /* for NB */ + { + mode_glb = offset_lvq_modes_SN[mode] + offset_in_lvq_mode_SN[mode][no_bits - min_lat_bits_SN[mode]]; + } + else + { + mode_glb = offset_lvq_modes_SN[mode] + no_bits - min_lat_bits_SN[mode]; /* there is granularity of 1 bit */ + } + p_scales = &scales_ivas_fx[0][0]; // Q11 + move16(); + } + ELSE + { + // mode_glb = add(offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub(no_bits,min_lat_bits_pred_fx[mode])]); + if ( ( mode < 6 ) || ( mode == 12 ) ) /* for NB */ + { + mode_glb = offset_lvq_modes_pred[mode] + offset_in_lvq_mode_pred[mode][no_bits - min_lat_bits_pred[mode]]; + } + else + { + mode_glb = offset_lvq_modes_pred[mode] + no_bits - min_lat_bits_pred[mode]; + } + p_scales = &scales_p_ivas_fx[0][0]; // Q11 + move16(); + } + + UWord32 offset_scale1[MAX_NO_SCALES + 1], offset_scale2[MAX_NO_SCALES + 1]; + create_offset( offset_scale1, offset_scale2, mode_glb, 1 - sf_flag ); + + /* decode the lattice index into the lattice codevectors for the two subvectors */ + // ber_flag = + // decode_indexes_fx(index, no_bits, p_scales, p_no_scales, offset_scale1, + // offset_scale2, x_lvq, mode_glb, scales_mslvq); /* x_lvq is here Q1 */ + ber_flag = + decode_indexes_ivas_fx( index, no_bits, p_scales, 1 - sf_flag, x_lvq, mode_glb, scales_mslvq ); /* x_lvq is here Q1 */ + + + IF( EQ_16( sf_flag, 1 ) ) + { + /* safety-net case*/ + IF( scales_mslvq[0] ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + IF( scales_mslvq[1] ) + { + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + } + ELSE + { + /* predictive mode AR or MA */ + IF( scales_mslvq[0] ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + IF( scales_mslvq[1] ) + { + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + } + } + } + + return ber_flag; +} + /*----------------------------------------------------------------------------------------------------* * deindex_lvq_cng() * Note: diff --git a/lib_com/prot.h b/lib_com/prot.h index 6f30a3b8c..8f204a011 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -811,6 +811,25 @@ void hf_synth( float *synth16k /* i/o: 16kHz synthesis signal */ ); +#ifdef IVAS_FLOAT_FIXED +void hf_synth_ivas_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16 *Aq, /* i : quantized Az */ + const Word16 *exc, /* i : excitation at 12.8 kHz */ + Word16 *synth, /* i : 12.8kHz synthesis signal */ + Word16 *synth16k, /* o : 16kHz synthesis signal */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *memExp1, /* o : HF excitation exponent */ + Word16 *mem_hp_interp, /* i/o: interpol. memory */ + const Word16 extl, /* i : flag indicating BWE */ + const Word16 CNG_mode, /* i : CNG_mode */ + Word16 element_mode +); +#endif int16_t lsp_convert_poly( float w[], /* i/o: LSP or ISP parameters */ const int16_t L_frame, /* i : flag for up or down conversion */ @@ -5949,8 +5968,10 @@ ivas_error core_switching_pre_dec_ivas_fx( const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ - const Word32 last_element_brate /* i : last element bitrate */ -); + const Word32 last_element_brate, /* i : last element bitrate */ + Word16 Q_old_synthFB, + Word16 *Q_olapBufferSynth , + Word16 *Q_olapBufferSynth2 ); #endif // IVAS_FLOAT_FIXED ivas_error core_switching_pre_dec( diff --git a/lib_com/prot_fx1.h b/lib_com/prot_fx1.h index c9008c968..2b52ad8af 100644 --- a/lib_com/prot_fx1.h +++ b/lib_com/prot_fx1.h @@ -496,6 +496,13 @@ void hp400_12k8_fx( Word16 mem[] /* i/o: filter memory [6] */ ); +#ifdef IVAS_FLOAT_FIXED +void hp400_12k8_ivas_fx( + Word16 signal[], /* i/o: input signal / output is divided by 16 */ + const Word16 lg, /* i : lenght of signal */ + Word16 mem[] /* i/o: filter memory [6] */ +); +#endif Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len ); void E_UTIL_f_convolve( const Word16 x[], const Word16 h[], Word16 y[], const Word16 size ); diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 51e625fb7..b466a7679 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -62,6 +62,12 @@ /* conversion functions: */ +// needed to be removed +void stereo_tcx_dec_mode_switch_reconf_To_fixed( + Decoder_State *st, + Word16 tofix, + Word16 last_element_mode ); + // Float to Word32 Word32 float_to_fix( float number, Word32 Q ); // Word32 to Float @@ -2171,6 +2177,17 @@ void synth_mem_updt2( Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec /* i : flag for decoder indication */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_synth_mem_updt2_fx( + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target */ + const Word16 dec, /* i : flag for decoder indication */ + Word16 Q ); +#endif //lerp.c @@ -2721,6 +2738,17 @@ void non_linearity_fx( const Word16 L_frame /* i : ACELP frame length */ ); +void non_linearity_ivas_fx( + const Word16 i[], /* i : i signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : i length */ + Word32 *prev_scale, /* i/o: memory Q30 */ + Word16 Q_inp, + Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ +); + void interp_code_5over2_fx( const Word16 inp_code[], /* i : i vector */ Word16 interp_code[], /* o : output vector */ @@ -3540,6 +3568,26 @@ void cng_params_upd_fx( const Word32 last_active_brate /* i : Last active bit rate Q0 */ ); +void cng_params_upd_ivas_fx( + const Word16 lsp_new[], /* i : LSP aprameters Q15 */ + const Word16 exc2[], /* i : current enhanced excitation Q_exc */ + const Word16 L_frame, /* i : frame length Q0 */ + Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ + Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ + Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ + Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ + const Word16 Q_exc, /* i : Q value of excitation */ + const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ + Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ + Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ + Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ + Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ + const Word32 last_active_brate, /* i : Last active bit rate Q0 */ + const Word16 element_mode, /* i : Element mode */ + const Word16 bwidth /* i : Audio bandwidth */ +); + int16_t get_cng_mode( const int32_t last_active_brate /* i : last active bitrate */ ); @@ -4716,6 +4764,14 @@ void apply_scale( const Word16 scaleTableSize /* i : Size of scale table */ ); +Word16 apply_scale_ind( + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ +); + /* Compute the power for each partition */ void bandcombinepow( const Word32* bandpow, /* i : Power for each band */ @@ -5555,6 +5611,11 @@ void swb_CNG_dec_fx( const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ); +#ifdef IVAS_FLOAT_FIXED +void td_cng_dec_init_ivas_fx( + DEC_CORE_HANDLE st /* i/o: decoder state structure */ +); +#endif void td_cng_dec_init( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ); @@ -6146,6 +6207,13 @@ void init_tcx_cfg_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ); +#ifdef IVAS_FLOAT_FIXED +void GSC_dec_init_ivas_fx( + GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ +); +#endif // IVAS_FIXED + + //gain_dec_fx.c void Es_pred_dec_fx( @@ -6854,6 +6922,12 @@ void generate_comfort_noise_dec_hf_ivas_fx( const Word16 idchan /* i : channel ID */ ); + ivas_error init_decoder_ivas_fx( + Decoder_State *st_fx, /* o: Decoder static variables structure */ + const Word16 idchan, /* i : channel ID */ + const MC_MODE mc_mode /* i : MC mode */ + ); + void reset_preecho_dec_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ); @@ -8440,10 +8514,10 @@ void decoder_tcx( void decoder_tcx_fx( Decoder_State *st, Word16 prm[], - float A[], + Word16 A_fx[], Word16 Aind[], - float synth[], - float synthFB[], + Word16 synth_fx[], + Word16 synthFB_fx[], const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag @@ -8874,6 +8948,30 @@ void configureFdCngDec( const Word16 last_L_frame, const Word16 element_mode ); + +Word32 sum2_f_16_fx( + const Word16 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ +); + +Word16 vq_dec_lvq_ivas_fx( + Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ + Word16 no_bits /* (i): no. bits for lattice */ +); + +Word16 deindex_lvq_ivas_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits /* i : number of bits for lattice */ +); + #endif void deleteCldfb_ivas_fx( diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 43da3fc64..8f851e2fd 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -40565,6 +40565,22 @@ const Word16 lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = 13107, 14746 }; +#ifdef IVAS_FLOAT_FIXED +const Word16 ivas_lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = +{ + /* Q15 */ + 1489, + 2979, + 4468, + 5958, + 7447, + 8937, + 10426, + 11916, + 13405, + 14895 +}; +#endif /* These words are subtracted from high/low/value with a shift left by 1. */ /* The value 0x0CCC should never be referenced, low is less/equal high */ @@ -42542,3 +42558,416 @@ const Word16 cos_scale_tbl_800[800] = { /* Q15 */ 32762, 32763, 32764, 32765, 32765, 32766, 32766, 32766 }; #endif // IVAS_FLOAT_FIXED + +const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors */ +{ + {3129, 0, 0, 3137, 0, 0, }, + {3287, 0, 0, 3137, 0, 0, }, + {2611, 5033, 0, 3137, 0, 0, }, + {2611, 5033, 0, 3340, 0, 0, }, + {2164, 3674, 5931, 2363, 3809, 6281, }, + {1898, 2985, 4745, 2115, 3667, 7045, }, + {2629, 5480, 0, 2971, 0, 0, }, + {2801, 0, 0, 2869, 5072, 0, }, + {1763, 2545, 3723, 2514, 4558, 21108, }, + {2195, 3960, 7440, 2500, 6017, 21960, }, + {1841, 2902, 1386, 2115, 3762, 22308, }, + {1699, 2709, 1288, 1865, 3246, 20660, }, + {3221, 0, 0, 3391, 0, 0, }, + {2537, 4923, 0, 3186, 0, 0, }, + {2816, 4229, 6397, 3676, 0, 0, }, + {2816, 4229, 6397, 3893, 0, 0, }, + {2160, 3481, 9091, 3391, 0, 0, }, + {2560, 4923, 8462, 2775, 4835, 0, }, + {2551, 3803, 5619, 3072, 5537, 0, }, + {2545, 4206, 7450, 3229, 0, 0, }, + {2162, 3655, 9263, 2699, 5296, 0, }, + {2039, 3082, 6871, 2426, 3637, 5586, }, + {1902, 2840, 6875, 2211, 3483, 5908, }, + {1888, 3057, 6899, 2211, 3483, 5908, }, + {1888, 3057, 6899, 2183, 3469, 6420, }, + {1888, 3057, 6899, 1970, 3174, 8081, }, + {2633, 1855, 4960, 2301, 3477, 5083, }, + {1527, 2269, 5875, 1964, 3033, 8001, }, + {1576, 2445, 5781, 1857, 2871, 4333, }, + {1531, 2258, 5869, 2420, 1660, 6823, }, + {1566, 2318, 3776, 2543, 3876, 1888, }, + {1568, 2320, 3780, 2183, 3360, 1665, }, + {1386, 1972, 4356, 1486, 2215, 4513, }, + {3356, 0, 0, 2494, 4425, 0, }, + {2633, 5009, 0, 2887, 0, 0, }, + {2224, 3538, 7696, 2494, 4425, 0, }, + {2119, 3225, 9861, 2494, 4425, 0, }, + {1974, 3139, 10121, 2494, 4425, 0, }, + {1722, 2453, 4059, 2494, 4425, 0, }, + {1839, 2658, 4472, 2490, 5455, 0, }, + {1722, 2533, 4581, 2037, 3393, 5808, }, + {1427, 2009, 4184, 1914, 3082, 1349, }, + {1370, 1861, 2719, 2017, 1339, 3913, }, + {2482, 3885, 0, 0, 0, 0, }, + {2375, 3827, 6975, 0, 0, 0, }, + {3395, 0, 0, 3883, 0, 0, }, + {3563, 0, 0, 3883, 0, 0, }, + {3346, 0, 0, 3418, 0, 0, }, + {3563, 0, 0, 4128, 0, 0, }, + {2820, 5218, 0, 3883, 0, 0, }, + {2637, 4962, 0, 3418, 0, 0, }, + {2482, 3885, 0, 3418, 0, 0, }, + {2217, 3616, 6502, 3418, 0, 0, }, + {2123, 3295, 8658, 3418, 0, 0, }, + {2242, 3397, 5562, 2693, 5132, 0, }, + {2387, 4024, 7483, 3452, 0, 0, }, + {1927, 2838, 4548, 2693, 5132, 0, }, + {1859, 2674, 3893, 2703, 5371, 0, }, + {2201, 3618, 1617, 2703, 5371, 0, }, + {2093, 3135, 1554, 2273, 3594, 5312, }, + {2201, 3618, 1617, 2238, 3895, 6172, }, + {1828, 3014, 1382, 2258, 3624, 5820, }, + {1863, 3170, 1402, 2113, 3381, 5146, }, + {1691, 2572, 1294, 2009, 3158, 4540, }, + {2424, 3706, 5654, 0, 0, 0, }, + {3299, 0, 0, 3313, 0, 0, }, + {2424, 3706, 5654, 3174, 0, 0, }, + {2424, 3706, 5654, 3313, 0, 0, }, + {2177, 3557, 6113, 3313, 0, 0, }, + {2207, 3737, 6475, 3008, 4605, 0, }, + {2816, 1873, 4263, 3008, 4605, 0, }, + {1966, 2914, 1433, 2682, 4366, 0, }, + {2301, 1626, 3895, 2627, 4714, 0, }, + {2205, 3536, 1570, 2560, 3995, 6105, }, + {1910, 3012, 1402, 2560, 3995, 6105, }, + {1898, 3276, 1380, 2363, 3637, 5844, }, + {2144, 1478, 3655, 2162, 3362, 5531, }, + {1988, 1409, 3090, 2136, 3543, 6002, }, + {1882, 1355, 2799, 2164, 3702, 6285, }, + {3311, 0, 0, 3393, 0, 0, }, + {2611, 4706, 0, 3201, 0, 0, }, + {2820, 5218, 0, 4128, 0, 0, }, + {2660, 4134, 0, 4128, 0, 0, }, + {2678, 4820, 0, 2840, 0, 0, }, + {2643, 4952, 0, 2775, 5003, 0, }, + {2402, 3618, 5726, 3252, 6201, 0, }, + {2209, 3622, 6168, 2840, 0, 0, }, + {2209, 3622, 6168, 2713, 5232, 0, }, + {1992, 2850, 4124, 3262, 6518, 0, }, + {2353, 3835, 1736, 3262, 6518, 0, }, + {1837, 2744, 5332, 2191, 3459, 5175, }, + {2353, 3835, 1736, 2701, 4685, 7550, }, + {1837, 2744, 5332, 1923, 2977, 4265, }, + {1853, 2717, 5322, 2271, 1591, 3491, }, + {1560, 2254, 4831, 1923, 2977, 4265, }, + {1626, 2510, 6512, 2271, 1591, 3491, }, + {3336, 0, 0, 2439, 4528, 0, }, + {2615, 5236, 0, 2799, 0, 0, }, + {2215, 3606, 8046, 2439, 4528, 0, }, + {2084, 3143, 5750, 2439, 4528, 0, }, + {1933, 3024, 5658, 2439, 4528, 0, }, + {1863, 3571, 6793, 2439, 4528, 0, }, + {1884, 3375, 6283, 1984, 3446, 8095, }, + {1513, 2275, 5517, 1800, 2889, 4720, }, + {1452, 2113, 5564, 1658, 2549, 3735, }, + {1552, 2285, 4022, 4139, 1634, 2496, }, + {1431, 2117, 4050, 4139, 1634, 2496, }, + {1486, 2150, 3778, 2775, 1761, 4515, }, + {1386, 2041, 3418, 2775, 1761, 4515, }, + {3371, 0, 0, 2568, 5036, 0, }, + {3031, 6023, 0, 3733, 0, 0, }, + {2801, 4704, 0, 3733, 0, 0, }, + {2801, 4704, 0, 4065, 0, 0, }, + {2197, 3815, 6617, 3436, 0, 0, }, + {2197, 3815, 6617, 2568, 5036, 0, }, + {2162, 3229, 5052, 3698, 6123, 0, }, + {2314, 3723, 1712, 4065, 0, 0, }, + {1947, 3055, 5111, 2570, 6084, 0, }, + {2351, 3770, 1665, 2570, 6084, 0, }, + {2351, 1656, 3932, 3133, 5603, 0, }, + {2469, 1742, 4464, 3098, 6504, 0, }, + {1646, 2457, 4046, 3080, 6574, 0, }, + {2336, 1650, 3921, 4040, 2387, 7604, }, + {2289, 1593, 4149, 2537, 4380, 7731, }, + {1576, 2322, 3921, 2521, 4706, 7946, }, + {2099, 1452, 3545, 2521, 4706, 7946, }, + {1980, 1460, 3385, 3768, 2252, 5793, }, + {2025, 1429, 3278, 2224, 4022, 5902, }, + {1232, 1779, 2904, 2588, 1564, 4542, }, + {1746, 3622, 9062, 2048, 2048, 2048, }, + {2070, 3405, 9017, 3231, 0, 0, }, + {2070, 3405, 9017, 2461, 4964, 0, }, + {1804, 3313, 8470, 2461, 4964, 0, }, + {1734, 3667, 9146, 2461, 4964, 0, }, + {1372, 2277, 4892, 2461, 4964, 0, }, + {2316, 3717, 1630, 2590, 5722, 0, }, + {1167, 1646, 2451, 2379, 3991, 1490, }, + {2140, 3248, 7688, 3418, 0, 0, }, + {2252, 3284, 4700, 2732, 4962, 0, }, + {2234, 3588, 6479, 2881, 0, 0, }, + {2234, 3588, 6479, 2756, 5171, 0, }, + {2234, 3588, 6479, 2230, 3448, 5167, }, + {1925, 2762, 3897, 2455, 3665, 5251, }, + {1802, 2621, 5783, 2250, 3553, 0, }, + {1701, 2488, 5994, 2230, 3497, 5076, }, + {1781, 2717, 5951, 2183, 3520, 5480, }, + {1566, 6379, 3723, 2299, 4728, 9779, }, + {1581, 2297, 4814, 2961, 1933, 4243, }, + {1435, 2000, 3559, 1939, 2975, 4263, }, + {1472, 2091, 3483, 2291, 1626, 3473, }, + {1718, 1310, 3117, 2289, 3475, 1630, }, + {1718, 1310, 3117, 1968, 3008, 1447, }, + {1310, 1810, 3547, 1546, 2232, 3170, }, + {2494, 1630, 4675, 2641, 6809, 0, }, + {3256, 1710, 9084, 2246, 6287, 0, }, + {2035, 5359, 0, 2234, 4573, 7079, }, + {1816, 3221, 7256, 2228, 3741, 6281, }, + {1714, 2535, 3897, 2658, 5728, 0, }, + {2330, 5787, 0, 2265, 5726, 8992, }, + {1927, 3954, 9160, 1394, 2592, 4767, }, + {2768, 8871, 0, 1679, 3164, 8550, }, + {2750, 7387, 0, 1759, 2975, 5304, }, + {2473, 5611, 0, 1554, 2539, 4468, }, + {2299, 5603, 0, 1789, 3067, 5296, }, + {1882, 5060, 0, 1259, 2195, 4292, }, + {3170, 9232, 0, 1689, 4460, 8816, }, + {2492, 5935, 0, 1509, 2492, 3952, }, + {1998, 4485, 11706, 3084, 1314, 8624, }, + {2267, 5314, 0, 2666, 1236, 1802, } +}; +const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors 20 modes Q11 */ +{ + {2998, 4861, 0, 0, 0, 0, }, + { 2629, 4421, 0, 0, 0, 0, }, + { 2549, 5304, 0, 0, 0, 0, }, + { 2338, 3805, 5994, 0, 0, 0, }, + { 2125, 3762, 6162, 0, 0, 0, }, + { 3102, 0, 0, 3153, 0, 0, }, + { 3244, 0, 0, 3153, 0, 0, }, + { 3244, 0, 0, 3317, 0, 0, }, + { 2629, 4421, 0, 3317, 0, 0, }, + { 2549, 5304, 0, 3153, 0, 0, }, + { 2590, 5251, 0, 3354, 0, 0, }, + { 2338, 3805, 5994, 3317, 0, 0, }, + { 2125, 3762, 6162, 3317, 0, 0, }, + { 2023, 3401, 5199, 3317, 0, 0, }, + { 2177, 3487, 5744, 2650, 4818, 0, }, + { 2177, 3926, 6273, 2795, 0, 0, }, + { 1871, 2891, 4552, 2650, 4818, 0, }, + { 1843, 2887, 4616, 2658, 4941, 0, }, + { 1806, 2869, 4919, 2689, 4999, 0, }, + { 2777, 1775, 4868, 2191, 3452, 5214, }, + { 1732, 2760, 5214, 2203, 3567, 5443, }, + { 1730, 2824, 5255, 2086, 3229, 5003, }, + { 1548, 2435, 5732, 2220, 3694, 5648, }, + { 1546, 2494, 5777, 1933, 2934, 4040, }, + { 1525, 2451, 5935, 2543, 1726, 3997, }, + { 1482, 2529, 6025, 2570, 1736, 4096, }, + { 1406, 2279, 4788, 1746, 2719, 3981, }, + { 1327, 2107, 3760, 1748, 2777, 4016, }, + { 1243, 1912, 3106, 1603, 2484, 3141, }, + { 1226, 1853, 3131, 1497, 2275, 3072, }, + { 1327, 2107, 3760, 1406, 2166, 3891, }, + { 3303, 0, 0, 0, 0, 0, }, + { 2594, 5068, 0, 3315, 0, 0, }, + { 2076, 3338, 5046, 2631, 4405, 0, }, + { 1828, 2846, 4739, 3000, 4708, 0, }, + { 1904, 2869, 4403, 2621, 4616, 0, }, + { 1828, 2846, 4739, 2613, 4517, 6111, }, + { 1828, 2846, 4739, 2121, 3371, 5060, }, + { 1755, 2738, 5046, 2136, 3543, 5376, }, + { 1566, 2496, 3180, 2121, 3371, 5060, }, + { 1615, 2719, 3383, 2154, 3653, 5541, }, + { 1564, 2506, 3184, 1884, 2955, 4167, }, + { 1357, 2172, 2535, 2824, 1839, 3995, }, + { 1378, 2260, 2674, 2578, 1695, 4001, }, + { 1363, 2193, 2557, 1644, 2541, 3540, }, + { 1347, 2127, 2486, 1945, 1333, 2926, }, + { 3276, 0, 0, 3180, 0, 0, }, + { 2674, 4970, 0, 3235, 0, 0, }, + { 2674, 4970, 0, 3432, 0, 0, }, + { 2560, 5926, 0, 3235, 0, 0, }, + { 2322, 4067, 6748, 3180, 0, 0, }, + { 2340, 4202, 6850, 3432, 0, 0, }, + { 2138, 4159, 7141, 3432, 0, 0, }, + { 2021, 3661, 5445, 3373, 0, 0, }, + { 1841, 3280, 5281, 3373, 0, 0, }, + { 1632, 2650, 4382, 3373, 0, 0, }, + { 1632, 2650, 4382, 2734, 4556, 0, }, + { 1517, 2357, 3719, 2734, 4556, 0, }, + { 2007, 3485, 1445, 2697, 5382, 0, }, + { 1632, 2650, 4382, 2428, 3956, 0, }, + { 1517, 2357, 3719, 2383, 3733, 5670, }, + { 1449, 2306, 3999, 2203, 3543, 5687, }, + { 1351, 2148, 3217, 2203, 3543, 5687, }, + { 1355, 2101, 3182, 2199, 3917, 6189, }, + { 1351, 2148, 3217, 2947, 1896, 4364, }, + { 1290, 1978, 3117, 2686, 1804, 4519, }, + { 1263, 1886, 2963, 2113, 3172, 1548, }, + { 3266, 0, 0, 3076, 0, 0, }, + { 2299, 3985, 7643, 3076, 0, 0, }, + { 2115, 4249, 8886, 2906, 5009, 0, }, + { 2017, 3672, 12216, 2623, 4759, 0, }, + { 1804, 3289, 14325, 2906, 5009, 0, }, + { 1728, 3239, 14376, 2623, 4759, 0, }, + { 1615, 3112, 14751, 2623, 4759, 0, }, + { 1779, 3168, 14325, 2109, 3592, 6352, }, + { 1673, 3055, 14581, 2109, 3592, 6352, }, + { 1546, 2830, 14608, 2109, 3592, 6352, }, + { 1445, 2693, 14796, 2109, 3592, 6352, }, + { 1411, 2654, 14929, 2080, 3840, 6633, }, + { 1429, 2611, 14764, 1871, 3170, 4982, }, + { 1390, 2693, 14929, 2516, 3778, 1665, }, + { 1390, 2693, 14929, 2433, 1581, 4003, }, + { 2070, 3639, 5652, 3305, 0, 0, }, + { 1974, 3235, 8183, 3540, 0, 0, }, + { 1798, 2949, 4687, 3540, 0, 0, }, + { 1744, 3364, 4974, 3540, 0, 0, }, + { 1746, 2830, 4231, 2549, 5486, 0, }, + { 2471, 1593, 4521, 2549, 5486, 0, }, + { 1646, 2772, 5421, 2883, 5355, 0, }, + { 1601, 2568, 5732, 2822, 5545, 0, }, + { 2471, 1593, 4521, 2074, 3751, 6252, }, + { 2471, 1593, 4521, 2908, 1785, 4771, }, + { 1398, 2080, 3661, 2306, 3862, 5988, }, + { 1284, 1878, 2965, 2306, 3862, 5988, }, + { 1347, 2105, 3188, 3035, 1996, 4397, }, + { 1626, 1187, 2725, 3035, 1996, 4397, }, + { 1685, 1212, 2709, 2756, 1832, 4726, }, + { 2248, 1511, 1136, 1779, 2641, 3813, }, + { 1552, 2275, 1126, 1783, 2799, 3903, }, + { 1128, 1568, 2285, 1619, 2459, 3405, }, + { 1128, 1568, 2285, 1972, 1427, 2709, }, + { 1075, 1576, 2197, 1669, 2533, 1161, }, + { 2191, 3667, 7993, 3274, 0, 0, }, + { 1679, 2492, 4278, 2570, 4689, 0, }, + { 1597, 2394, 5109, 2570, 4689, 0, }, + { 2201, 1480, 4835, 2273, 4016, 7149, }, + { 1415, 2107, 4786, 2117, 3667, 8200, }, + { 1374, 2203, 5337, 1955, 3168, 5148, }, + { 2424, 1589, 4335, 2164, 3420, 1380, }, + { 1937, 2965, 5576, 2854, 5416, 9381, }, + { 1941, 2977, 5576, 4034, 2404, 7135, }, + { 1812, 2879, 5658, 4034, 2404, 7135, }, + { 2549, 1724, 4870, 4093, 2392, 7540, }, + { 1781, 2756, 5763, 3571, 2166, 5933, }, + { 1693, 2496, 4456, 3252, 5324, 2037, }, + { 1673, 2428, 4079, 3262, 1994, 5363, }, + { 1683, 2467, 4298, 2998, 1851, 4911, }, + { 1683, 2467, 4298, 4204, 1714, 2783, }, + { 1067, 1529, 2115, 1630, 2729, 1110, }, + { 3438, 0, 0, 2625, 5060, 0, }, + { 2228, 3786, 6543, 3454, 0, 0, }, + { 2228, 3786, 6543, 2625, 5060, 0, }, + { 2306, 3459, 1617, 2625, 5060, 0, }, + { 1904, 2830, 1396, 2625, 5060, 0, }, + { 2283, 1626, 3792, 2623, 6211, 0, }, + { 1720, 2818, 1275, 1638, 2899, 8724, }, + { 1640, 2351, 3690, 0, 0, 0, }, + { 2752, 5380, 0, 3223, 0, 0, }, + { 2580, 4188, 0, 3223, 0, 0, }, + { 2580, 4188, 0, 3430, 0, 0, }, + { 2230, 3710, 6496, 3434, 0, 0, }, + { 2230, 3899, 6596, 3115, 5396, 0, }, + { 1972, 2949, 4335, 3430, 0, 0, }, + { 1972, 2949, 4335, 2666, 4935, 0, }, + { 1730, 2482, 3960, 2689, 4954, 0, }, + { 1595, 2242, 3481, 2689, 4954, 0, }, + { 1480, 2078, 3407, 2689, 4954, 0, }, + { 2066, 3414, 1540, 2676, 6187, 0, }, + { 2058, 3373, 1533, 2179, 3831, 6856, }, + { 1832, 3051, 1396, 2179, 3831, 6856, }, + { 1611, 2605, 1245, 2179, 3831, 6856, }, + { 1763, 1327, 2988, 2179, 3831, 6856, }, + { 1697, 1292, 2738, 2168, 4161, 7020, }, + { 1763, 1327, 2988, 3155, 1884, 5142, }, + { 1736, 1296, 2781, 2883, 1800, 5552, }, + { 1828, 1335, 2945, 2203, 1474, 3674, }, + { 2783, 4722, 0, 3418, 0, 0, }, + { 2205, 3946, 7262, 3418, 0, 0, }, + { 2205, 4161, 7327, 2926, 5552, 0, }, + { 1705, 2566, 4311, 2627, 5234, 0, }, + { 1589, 2359, 3805, 2627, 5234, 0, }, + { 1472, 2183, 3547, 2627, 5234, 0, }, + { 1927, 1333, 3205, 1478, 2437, 3973, }, + { 2646, 5076, 0, 3155, 0, 0, }, + { 2461, 3897, 0, 3155, 0, 0, }, + { 2105, 3360, 5027, 3375, 0, 0, }, + { 2553, 1798, 4769, 3375, 0, 0, }, + { 1767, 2781, 5165, 3375, 0, 0, }, + { 1673, 2502, 4116, 2199, 3655, 5597, }, + { 1669, 1253, 2623, 2160, 3530, 6045, }, + { 3164, 0, 0, 3170, 0, 0, }, + { 3358, 0, 0, 3170, 0, 0, }, + { 2723, 0, 0, 3270, 0, 0, }, + { 2529, 4743, 0, 3270, 0, 0, }, + { 2635, 5629, 0, 3170, 0, 0, }, + { 2635, 5629, 0, 3387, 0, 0, }, + { 2437, 4149, 0, 3387, 0, 0, }, + { 1949, 3428, 5656, 3270, 0, 0, }, + { 1880, 3217, 6574, 3270, 0, 0, }, + { 2572, 1622, 4255, 3270, 0, 0, }, + { 1550, 2463, 3837, 3270, 0, 0, }, + { 1906, 2985, 5017, 2650, 5615, 0, }, + { 2287, 1507, 3840, 2562, 5257, 0, }, + { 1581, 2531, 3934, 2562, 5257, 0, }, + { 1796, 2859, 5605, 2213, 3719, 6881, }, + { 2316, 3350, 0, 2807, 0, 0, }, + { 1826, 3260, 7012, 2658, 6565, 0, }, + { 1792, 3168, 7084, 2631, 5937, 8499, }, + { 1732, 3379, 6772, 2611, 5009, 8202, }, + { 1654, 6285, 3514, 2611, 5009, 8202, }, + { 1566, 6406, 3733, 2611, 5009, 8202, }, + { 1912, 2615, 1490, 2369, 3475, 0, }, + { 1705, 2379, 1347, 2357, 3454, 0, }, + { 1538, 2113, 1224, 2357, 3454, 0, }, + { 1554, 6426, 3778, 1888, 3088, 6369, }, + { 1452, 2058, 1167, 2170, 3629, 5568, }, + { 1527, 2050, 1230, 2056, 3692, 5922, }, + { 1521, 2048, 1226, 1916, 3811, 5885, }, + { 1536, 6492, 3942, 1509, 2914, 5502, }, + { 1536, 6492, 3942, 1349, 2168, 4044, }, + { 1587, 1257, 2123, 1630, 2670, 3901, }, + { 1830, 2742, 5220, 2678, 5326, 0, }, + { 1703, 2568, 3966, 2676, 5353, 0, }, + { 1703, 2523, 3923, 2371, 4048, 0, }, + { 1689, 2580, 4081, 2095, 3561, 5726, }, + { 1536, 2281, 3201, 2140, 3690, 5490, }, + { 1417, 2048, 2930, 2095, 3561, 5726, }, + { 1474, 2072, 3272, 3096, 1896, 4376, }, + { 1394, 1992, 3377, 2828, 1794, 4360, }, + { 1400, 1974, 3358, 2392, 3637, 1611, }, + { 1368, 1914, 3176, 2080, 3108, 1458, }, + { 1349, 1865, 2918, 2738, 1820, 1314, }, + { 1349, 1865, 2918, 1718, 2635, 1243, }, + { 3344, 0, 0, 3454, 0, 0, }, + { 3463, 0, 0, 3428, 0, 0, }, + { 2719, 5251, 0, 3180, 0, 0, }, + { 2560, 4079, 0, 3180, 0, 0, }, + { 2560, 4079, 0, 3428, 0, 0, }, + { 2203, 3665, 6025, 3454, 0, 0, }, + { 2183, 3446, 8349, 3428, 0, 0, }, + { 2621, 1865, 5072, 3428, 0, 0, }, + { 1708, 2516, 3870, 3454, 0, 0, }, + { 1921, 2875, 4409, 2674, 5386, 0, }, + { 2744, 1814, 4751, 2674, 5386, 0, }, + { 1705, 2560, 3907, 2674, 5386, 0, }, + { 1705, 2484, 3835, 2304, 3766, 5773, }, + { 1748, 2594, 3743, 2138, 3604, 5902, }, + { 1566, 2379, 3461, 2097, 3559, 5812, }, + { 1484, 2150, 3667, 3031, 1888, 6356, }, + { 1458, 2072, 3172, 3059, 1849, 6889, }, + { 1349, 1898, 2779, 3059, 1849, 6889, }, + { 1683, 1257, 2637, 1863, 3090, 4618, }, + { 1722, 1277, 2617, 2377, 1560, 3702, }, + { 1716, 1273, 2592, 2211, 1456, 3502, }, + { 1703, 1267, 2611, 1921, 2928, 1318, }, + { 1810, 2762, 5263, 2691, 5343, 0, }, + { 2009, 3016, 5701, 3461, 6844, 0, }, + { 1976, 3100, 5500, 2885, 5089, 8081, }, + { 1998, 2983, 5453, 4405, 2603, 8552, }, + { 2029, 3080, 6320, 5091, 2693, 9277, }, + { 1937, 2965, 5576, 2854, 5416, 9381, }, + { 1456, 2084, 3307, 3035, 1886, 7026, }, + { 1390, 1994, 3397, 1941, 3172, 7061, }, + { 1701, 1265, 3033, 1910, 3100, 4730, }, + { 1671, 1249, 2871, 2920, 1796, 4638, }, + { 1611, 2574, 1220, 1759, 2963, 4978, }, + { 1611, 2574, 1220, 2265, 1505, 3397, } +}; diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 3bbdeb87e..01effce6c 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -2080,6 +2080,9 @@ extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; #endif extern const Word16 Mean_isf_wb[]; extern const Word16 lsp_shb_prev_tbl_fx[]; +#ifdef IVAS_FLOAT_FIXED +extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; +#endif extern const Word16 tab_ari_qnew[4][4]; //enhancer.c @@ -2145,4 +2148,8 @@ extern const Word16 cos_scale_tbl_1200[1200]; extern const Word16 sin_scale_tbl_1200[1200]; extern const Word16 cos_scale_tbl_800[800]; extern const Word16 sin_scale_tbl_800[800]; + +extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; +extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; + #endif diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 1d39003e5..d37f614a7 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3055,6 +3055,118 @@ static Word32 non_linearity_scaled_copy( return prev_scale; } + +/*-------------------------------------------------------------------* + * non_linearity() + * + * Apply a non linearity to the SHB excitation + * -------------------------------------------------------------------*/ + +static Word32 non_linearity_scaled_copy_ivas( + const Word16 input[], + Word16 j, + const Word16 length, + Word32 output[], + Word32 prev_scale, + const Word16 scale_step, + const Word16 en_abs +) +{ + Word16 i; + Word32 L_tmp; + + + IF (en_abs) + { + FOR ( i = 0; i < j; i++ ) + { + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ + + test(); test(); + IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + { + /* NOTE: this is done to avoid the product to become zero for small non-zero input */ + L_tmp = 1; + move16(); + } + + output[i] = L_tmp; + move32(); + + L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ + prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ + } + FOR ( ; i < length; i++ ) + { + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ + + test(); test(); + IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + { + /* NOTE: this is done to avoid the product to become zero for small non-zero input */ + L_tmp = 1; + move16(); + } + output[i] = L_tmp; + move32(); + } + } + ELSE + { + FOR ( i = 0; i < j; i++ ) + { + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ + L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ + + test(); test(); + IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + { + /* NOTE: this is done to avoid the product to become zero for small non-zero input */ + L_tmp = 1; + move16(); + } + + if ( input[i] < 0 ) + { + L_tmp = L_negate(L_tmp); + } + output[i] = L_tmp; + move32(); + + L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ + prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ + } + + FOR ( ; i < length; i++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mult_sat( input[i], input[i]); /* 2*Q_inp+1 */ +#else /* BASOP_NOGLOB */ + L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ +#endif /* BASOP_NOGLOB */ + L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ + test(); test(); + IF(input[i] != 0 && prev_scale != 0 && L_tmp == 0) + { + /* NOTE: this is done to avoid the product to become zero for small non-zero input */ + L_tmp = 1; + move16(); + } + + if ( input[i] < 0 ) + { + L_tmp = L_negate(L_tmp); + } + output[i] = L_tmp; + move32(); + } + } + return prev_scale; +} + + /*==========================================================================*/ /* FUNCTION : void non_linearity() */ /*--------------------------------------------------------------------------*/ @@ -3325,6 +3437,275 @@ void non_linearity_fx( } +/*==========================================================================*/ +/* FUNCTION : void non_linearity_ivas_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Apply a non linearity to the SHB excitation */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* Word16 input[] i : input signal Q_inp */ +/* Word16 length i : input length */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* Word32 output[] o : output signal 2*Q_inp */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* Word32 *prev_scale i/o: memory Q30 */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------*/ +/* CALLED FROM : */ +/*==========================================================================*/ + +void non_linearity_ivas_fx( + const Word16 input[], /* i : input signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : input length */ + Word32* pPrevScale, /* i/o: memory Q30 */ + Word16 Q_inp, + Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ + +) +{ + Word16 i, j; + Word16 max_val=0; + Word32 scale; + Word16 scale_step; + Word16 exp, tmp; + Word16 e_tmp, f_tmp; + Word16 frac; + Word32 L_tmp; + Word32 L_tmp1; + + Word16 en_abs = 0; + Word16 v_fac = 0; + Word16 ths; + Word16 nframes; + Word32 prev_scale; + Word16 length_half; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + + IF ( EQ_16(L_frame, L_FRAME16k )) + { + nframes = 5; + move16(); + ths = 17817; + move16(); /* 0.87*5 in Q12 */ + } + ELSE + { + nframes = 4; + move16(); + ths = 15400; + move16(); /* 0.94*4 in Q12 */ + } + + + FOR ( i = 0; i < nframes; i++ ) + { + v_fac = add( v_fac, shr( voice_factors[i], 3 ) ); /* Q12 */ + } + + test(); + if ( EQ_16( coder_type, VOICED )&>_16(v_fac,ths)) + { + en_abs = 1; + move16(); + } + + length_half = shr(length, 1); + prev_scale = *pPrevScale; + move32(); + + + + /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ + + FOR ( i = j = 0; i < length_half; i++ ) + { + tmp = abs_s(input[i]); + if(GT_16(tmp,max_val)) + { + j = i; + move16(); + } + max_val = s_max(max_val, tmp); + + } + + + IF ( GT_16(max_val, shl(1,Q_inp))) + { + exp = norm_s( max_val ); + tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ + scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp,14)) ); /* Q31 */ + } + ELSE + { + scale = 1438814044; + move32(); /* Q31; 0.67 in Q31 */ + } + + test(); + IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale )) + { + scale_step = 16384; + move16(); /* Q14 */ + prev_scale = L_shr( scale, 1 ); /* Q30 */ + } + ELSE + { + + /* Computing log2(scale) */ + IF ( j == 0 ) + { + scale_step = 32767; + move16(); + } + ELSE + { + e_tmp = norm_l( scale ); + f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); + e_tmp = sub(-1, e_tmp); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + + /* Computing log2(prev_scale) */ + e_tmp = norm_l( prev_scale ); + f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); + e_tmp = negate(e_tmp); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + + /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ + L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ + + /* Computing 1/j */ + exp = norm_s( j ); + tmp = div_s( shl(1, sub( 14, exp)), j ); /* Q(29-exp) */ + + /* (log2(scale / prev_scale))/length */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp, 14), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ +#else + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp, 14) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ +#endif + + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + + tmp = extract_l( Pow2( 14, frac ) ); +#ifdef BASOP_NOGLOB + scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */ +#else + scale_step = shl( tmp, exp ); /* Q14 */ +#endif + } + } + + prev_scale = non_linearity_scaled_copy_ivas( input, j, length_half, output, prev_scale, scale_step, en_abs ); + + max_val = 0; + move16(); + j = shr(length, 1); + FOR ( i = length_half; i < length; i++ ) + { + tmp = abs_s(input[i]); + if(GT_16(tmp,max_val)) + { + j = i; + move16(); + } + max_val = s_max(max_val, tmp); + } + + IF ( GT_16( max_val, shl( 1, Q_inp ) )) + { + exp = norm_s( max_val ); + tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ +#ifdef BASOP_NOGLOB + scale = L_shl_o( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)), &Overflow ); /* Q31 */ +#else + scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)) ); /* Q31 */ +#endif + } + ELSE + { + scale = 1438814044; + move32(); /* Q31; 0.67 in Q31 */ + } + + test(); + IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale )) + { + scale_step = 16384; + move16(); /*Q14 */ + prev_scale = L_shr( scale, 1 ); /*Q30 */ + } + ELSE + { + /*scale_step = (float) exp(1.0f / (float) (j - length/2) * (float) log(scale / prev_scale)); */ + /* Computing log2(scale) */ + IF ( EQ_16(j,length_half)) + { + scale_step = 32767; + move16();/*Q14 */ + } + ELSE + { + e_tmp = norm_l( scale ); + f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); + e_tmp = sub(-e_tmp, 1); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + + /* Computing log2(prev_scale) */ + e_tmp = norm_l( prev_scale ); + f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); + e_tmp = negate(e_tmp); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + + /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ + L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ + + /* Computing 1/(j - length/2) */ + + tmp = sub( j, length_half ); + exp = norm_s( tmp ); + + + tmp = div_s( shl(1, sub( 14, exp)), tmp ); /* Q(29-exp) */ + + /* (log2(scale / prev_scale))/length */ +#ifdef BASOP_NOGLOB + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp,14), &Overflow); /*Q(16+29-exp+1-16+exp-14)->Q16 */ +#else + L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp,14) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ +#endif + + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ + + tmp = extract_l( Pow2( 14, frac ) ); +#ifdef BASOP_NOGLOB + scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */ +#else + scale_step = shl( tmp, exp ); /*Q14 */ +#endif + } + } + + prev_scale = non_linearity_scaled_copy_ivas( input+length_half, sub(j, length_half), sub(length, length_half), output+length_half, prev_scale, scale_step, en_abs ); + + *pPrevScale = prev_scale; + move32(); + + /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ + + return; +} + /*-------------------------------------------------------------------* diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 3e9f97f44..216138f5f 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -412,6 +412,81 @@ void E_UTIL_synthesis_fx(const Word16 shift, const Word32 a[], const Word32 x[], * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_synth_mem_updt2_fx( + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target */ + const Word16 dec, /* i : flag for decoder indication */ + Word16 Q ) +{ + Word16 mem_syn_r_size_old, mem_syn_r_size_new; + Word32 en1, en2; + Word16 en1_e, en2_e, loc_rat, loc_rat_e, tmp, tmp_e, i; + Word32 tmp1, tmp2; + + /* Residual and update old_exc */ + IF( GE_16( dec, DEC ) ) + { + lerp( old_exc + L_EXC_MEM_DEC - ( last_L_frame + last_L_frame / 2 ), old_exc + L_EXC_MEM_DEC - ( L_frame + L_frame / 2 ), L_frame + L_frame / 2, last_L_frame + last_L_frame / 2 ); + } + ELSE + { + lerp( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame ); + } + IF( EQ_16( dec, DEC_IVAS ) ) + { + IF( EQ_16( L_frame, L_FRAME16k ) ) + { + /* find scaling factor */ + // en1 = 1.25f * sum2_f( mem_syn2, M ); + en1 = Mpy_32_32( 1342177280 /*1.25f in Q30*/, sum2_f_16_fx( mem_syn2, M ) ); /* 2 * Q - 1 */ + en2 = L_shr( sum2_f_16_fx( mem_syn_r + L_SYN_MEM - M, M ), 1 ); /* 2 * Q - 1 */ + + // loc_rat = sqrtf( en2 ) / ( sqrtf( en1 ) + 0.01f ); + IF( EQ_32(en1, 0 )) + { + loc_rat = 0; + move16(); + } + ELSE + { + en1_e = 30 - 2 * Q; + en2_e = 30 - 2 * Q; + tmp1 = Sqrt32( en1, &en1_e ); + tmp2 = Sqrt32( en2, &en2_e ); + tmp = BASOP_Util_Divide3232_Scale( tmp1, tmp2, &tmp_e ); + loc_rat_e = en1_e - en2_e + tmp_e; + loc_rat = shl_sat( tmp, loc_rat_e); // Q15 + } + + /* scale synthesis filter memory */ + FOR( i = 0; i < M; i++ ) + { + // mem_syn_r[L_SYN_MEM - M + i] *= loc_rat; + mem_syn_r[L_SYN_MEM - M + i] = mult_r( mem_syn_r[L_SYN_MEM - M + i], loc_rat ); + } + } + } + /*Resamp memory*/ + /*Size of LPC syn memory*/ + /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ + mem_syn_r_size_old = shr( last_L_frame, 4 ); + mem_syn_r_size_new = shr( L_frame, 4 ); + + lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + + Copy( mem_syn_r + L_SYN_MEM - M, mem_syn2, M ); + + IF( mem_syn != NULL ) + { + Copy( mem_syn2, mem_syn, M ); + } +} +#endif void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ diff --git a/lib_com/tools.c b/lib_com/tools.c index 815cc2a75..c49940f6e 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -178,6 +178,24 @@ float sum_f( *---------------------------------------------------------------------*/ /*! r: sum of all squared vector elements */ +#ifdef IVAS_FLOAT_FIXED +Word32 sum2_f_16_fx( + const Word16 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ +) +{ + int16_t i; + Word32 tmp; + + tmp = 0; + FOR( i = 0; i < lvec; i++ ) + { + tmp = L_add( tmp, L_mult0( vec[i], vec[i] ) ); + } + + return tmp; +} +#endif float sum2_f( const float *vec, /* i : input vector */ const int16_t lvec /* i : length of input vector */ diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index cfcfe43be..9eed201f8 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -56,6 +56,7 @@ #define INV_BANDS3 10923 /* 1/9 in Q15 */ const Word16 b_hp400_fx[3] = { 3660, -7320, 3660 }; /* Q12 (/4) */ const Word16 a_hp400_fx[3] = { 16384, 29280, -14160 }; +const Word16 a_hp400_ivas_fx[3] = { 4096, 7320, -3540 };/*Q12*/ // conversion functions: Word32 float_to_fix( float number, Word32 Q ) @@ -3397,6 +3398,82 @@ void hp400_12k8_fx( return; } +#ifdef IVAS_FLOAT_FIXED +void hp400_12k8_ivas_fx( + Word16 signal[], /* i/o: input signal / output is divided by 16 */ + const Word16 lg, /* i : lenght of signal */ + Word16 mem[] /* i/o: filter memory [6] */ +) +{ + Word16 i; + Word16 y1_hi, y1_lo; + Word32 L_tmp, L_tmp2, L_tmp3; + + y1_hi = mem[2]; + move16(); + y1_lo = mem[3]; + move16(); + + L_tmp3 = L_mac( 16384L, mem[1], a_hp400_ivas_fx[2] ); /* rounding to maximize precision */ + L_tmp3 = L_mac( L_tmp3, y1_lo, a_hp400_ivas_fx[1] ); + L_tmp3 = L_shr( L_tmp3, 15 ); + L_tmp2 = L_mac( L_tmp3, mem[0], a_hp400_ivas_fx[2] ); + L_tmp2 = L_mac( L_tmp2, mem[5], b_hp400_fx[2] ); + L_tmp2 = L_mac( L_tmp2, mem[4], b_hp400_fx[1] ); + L_tmp3 = L_mult( mem[4], b_hp400_fx[2] ); + + mem[5] = signal[lg - 2]; + + FOR( i = 1; i < lg; i++ ) + { + /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] */ + /* + a[1]*y[i-1] + a[2] * y[i-2] */ + + L_tmp = L_mac( L_tmp2, y1_hi, a_hp400_ivas_fx[1] ); + L_tmp = L_mac( L_tmp, *signal, b_hp400_fx[0] ); + + L_tmp = L_shl( L_tmp, 1 ); /* coeff Q12 --> Q13 */ + + L_tmp2 = L_mac( L_tmp3, y1_hi, a_hp400_ivas_fx[2] ); + L_tmp2 = L_mac( L_tmp2, *signal, b_hp400_fx[1] ); + L_tmp3 = L_mac( 16384L, y1_lo, a_hp400_ivas_fx[2] ); /* rounding to maximize precision */ + + y1_lo = L_Extract_lc( L_tmp, &y1_hi ); + + L_tmp3 = L_mac( L_tmp3, y1_lo, a_hp400_ivas_fx[1] ); + L_tmp3 = L_shr( L_tmp3, 15 ); + + L_tmp2 = L_add( L_tmp3, L_tmp2 ); + + L_tmp3 = L_mult( *signal, b_hp400_fx[2] ); + + /* signal is divided by 16 to avoid overflow in energy computation */ + *signal++ = round_fx( L_tmp ); + } + + /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] */ + /* + a[1]*y[i-1] + a[2] * y[i-2] */ + + L_tmp = L_mac( L_tmp2, y1_hi, a_hp400_ivas_fx[1] ); + + mem[4] = *signal; + move16(); + L_tmp = L_mac( L_tmp, mem[4], b_hp400_fx[0] ); + + L_tmp = L_shl( L_tmp, 1 ); /* coeff Q12 --> Q13 */ + + mem[0] = y1_hi; + move16(); + mem[1] = y1_lo; + move16(); + L_Extract( L_tmp, &mem[2], &mem[3] ); + + /* signal is divided by 16 to avoid overflow in energy computation */ + *signal++ = round_fx( L_tmp ); + + return; +} +#endif Word16 dot_prod_satcontr(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len) { diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 3009cf2e0..661041919 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -95,7 +95,11 @@ ivas_error acelp_core_dec( float FEC_pitch; /* FEC pitch */ float old_bwe_exc[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ float *bwe_exc; /* Excitation for SWB TBE */ - int16_t i, int_fs; +#ifdef IVAS_FLOAT_FIXED + Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ + Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ +#endif + int16_t i, j, int_fs; int16_t tc_subfr; int16_t allow_cn_step; float temp_buf[L_FRAME16k + L_SYN_MEM]; @@ -137,6 +141,7 @@ ivas_error acelp_core_dec( set_zero(temp_buf, L_FRAME16k + L_SYN_MEM); Word32 bpf_error_signal_fx[L_FRAME16k]; Word16 tmp; + set_zero(old_exc2, L_FRAME16k + L_EXC_MEM); #endif error = IVAS_ERR_OK; @@ -317,15 +322,22 @@ ivas_error acelp_core_dec( { set_f( old_exc2, 0, L_EXC_MEM ); } + exc2 = old_exc2 + L_EXC_MEM; if ( st->hBWE_TD != NULL ) { mvr2r( st->hBWE_TD->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 ); bwe_exc = old_bwe_exc + PIT16k_MAX * 2; +#ifdef IVAS_FLOAT_FIXED + bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; +#endif } else { bwe_exc = NULL; +#ifdef IVAS_FLOAT_FIXED + bwe_exc_fx = NULL; +#endif } last_pulse_pos = 0; @@ -1510,7 +1522,7 @@ ivas_error acelp_core_dec( st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); } -/*==========================================================*/ + //ApplyFdCng_fx( syn_fx + L_SUBFR, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); ApplyFdCng_fx(syn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); /*==========================================================*/ @@ -2127,7 +2139,6 @@ ivas_error acelp_core_dec( #ifdef IVAS_FLOAT_FIXED Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; Word16 q_bpf_error_signal; - Word16 j; Word32 cldfb_state_offset = sub(st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels); q_bpf_error_signal = Q6; @@ -2217,7 +2228,7 @@ ivas_error acelp_core_dec( /* Fixed to float */ FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) { - FOR( Word16 j = st->hFdCngDec->hFdCngCom->numCoreBands; j < st->hFdCngDec->hFdCngCom->regularStopBand; j++ ) + FOR( j = st->hFdCngDec->hFdCngCom->numCoreBands; j < st->hFdCngDec->hFdCngCom->regularStopBand; j++ ) { realBuffer[i][j] = me2f( realBuffer_fx[i][j], tmpBufferScale + 15 ); imagBuffer[i][j] = me2f( imagBuffer_fx[i][j], tmpBufferScale + 15 ); @@ -2240,28 +2251,7 @@ ivas_error acelp_core_dec( /*WB/SWB-FD_CNG*/ if ((st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40) && (st->cng_type == FD_CNG) && (st->hFdCngDec->hFdCngCom->numCoreBands < st->cldfbSyn->no_channels)) { -#ifdef IVAS_FLOAT_FIXED - /* Float to fixed */ - f2me_buf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, st->hFdCngDec->hFdCngCom->cngNoiseLevel, &st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN); - - // NOTE: this should be removed later. - //st->hFdCngDec->hFdCngCom->q_cngNoiseLevel = 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp; - - Word16 tmpBufferScale = 0; - generate_comfort_noise_dec_hf_ivas_fx(realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag); - - /* Fixed to float */ - FOR(i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++) - { - FOR(j = st->hFdCngDec->hFdCngCom->numCoreBands; j < st->hFdCngDec->hFdCngCom->regularStopBand; j++) - { - realBuffer[i][j] = me2f(realBuffer_fx[i][j], tmpBufferScale + 15); - imagBuffer[i][j] = me2f(imagBuffer_fx[i][j], tmpBufferScale + 15); - } - } -#else generate_comfort_noise_dec_hf_flt(realBuffer, imagBuffer, st->hFdCngDec->hFdCngCom, st->cng_ism_flag); -#endif if (st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels) { @@ -2286,7 +2276,7 @@ ivas_error acelp_core_dec( float max_real = 0.f, max_imag = 0.f; for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { max_real = (float) max( max_real, fabs( realBuffer[i][j] ) ); max_imag = (float) max( max_imag, fabs( imagBuffer[i][j] ) ); @@ -2304,7 +2294,7 @@ ivas_error acelp_core_dec( floatToFixed_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q_real - 1, st->cldfbSynHB->p_filter_length ); floatToFixed_arrL( save_hb_synth, save_hb_synth_fx, Q_real - 1, L_FRAME48k ); - FOR( int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { @@ -2324,7 +2314,7 @@ ivas_error acelp_core_dec( fixedToFloat_arrL( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_real - 1, st->cldfbSynHB->p_filter_length ); /* restore lowband */ - FOR( int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { @@ -2373,7 +2363,7 @@ ivas_error acelp_core_dec( float max_real = 0.f, max_imag = 0.f; for (i = 0; i < CLDFB_NO_COL_MAX; i++) { - for (int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) { + for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) { max_real = (float)max(max_real , fabs(realBuffer[i][j])); max_imag = (float)max(max_imag, fabs(imagBuffer[i][j])); } @@ -2434,10 +2424,8 @@ ivas_error acelp_core_dec( /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ #ifdef IVAS_FLOAT_FIXED - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; Word16 q_bpf_error_signal; - Word16 j; Word32 cldfb_state_offset = sub(st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels); // Get Q-factor @@ -2489,7 +2477,7 @@ ivas_error acelp_core_dec( float max_real = 0.f, max_imag = 0.f; for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { max_real = (float) max( max_real, fabs( realBuffer[i][j] ) ); max_imag = (float) max( max_imag, fabs( imagBuffer[i][j] ) ); @@ -2534,8 +2522,62 @@ ivas_error acelp_core_dec( /*-----------------------------------------------------------------* * Bandwidth extension 6kHz-7kHz *-----------------------------------------------------------------*/ - - if ( st->hBWE_zero != NULL ) +#ifdef IVAS_FLOAT_FIXED + IF( st->hBWE_zero != NULL ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && + ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type_fx, AUDIO ) ) ) ) ) + { + Word16 tmp_exp = 0; + floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); + Word16 exc_fx[L_FRAME + L_SUBFR], exp_exc = 0, Q_exc = 0; + f2me_buf_16( exc, exc_fx, &exp_exc, L_FRAME ); + Q_exc = 15 - exp_exc; + Word16 Q_syn2 = 0; + Word16 synth_fx[L_FRAME48k]; + floatToFixed_arr( syn, syn_fx, Q_syn2, L_FRAME + L_SUBFR ); + floatToFixed_arr( synth, synth_fx, Q_syn2, L_FRAME + L_SUBFR ); + + floatToFixed_arr( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_syn2, NS2SA( 16000, DELAY_CLDFB_NS ) - 15 ); + floatToFixed_arr( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); + floatToFixed_arr( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, 0, M ); + floatToFixed_arr( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, -2 - tmp_exp, L_FIR - 1 ); + floatToFixed_arr( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_syn2, 6 ); + Word16 output_subfr = output_frame / NB_SUBFR; + + hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, + syn_fx, synth_fx, Q_exc, Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, + st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); + + IF( st->hBWE_FD != NULL ) + { + st->hBWE_FD->memExp1 = tmp_exp; + } + + fixedToFloat_arr( synth_fx, synth, Q_syn2, output_subfr ); + fixedToFloat_arr( syn_fx, syn, Q_syn2 - 2, L_SUBFR ); + fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, 0, NS2SA( 16000, DELAY_CLDFB_NS ) - 15 ); + fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, 0, INTERP_3_1_MEM_LEN ); + fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, 0, M ); + fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, -2 - tmp_exp, L_FIR - 1 ); + fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_syn2, 6 ); + } + ELSE + { + hf_synth_reset_fx( st->hBWE_zero ); + /*to be cleaned up*/ + hf_synth_reset( st->hBWE_zero ); + } + } +#else + if (st->hBWE_zero != NULL ) { if ( ( st->L_frame == L_FRAME && st->bwidth != NB && output_frame >= L_FRAME16k && ( st->extl == -1 || st->extl == SWB_CNG || ( st->extl == WB_BWE && st->extl_brate == 0 && st->coder_type != AUDIO ) ) ) ) @@ -2547,6 +2589,7 @@ ivas_error acelp_core_dec( hf_synth_reset( st->hBWE_zero ); } } +#endif /*-----------------------------------------------------------------* * Populate parameters for SWB TBE @@ -2562,7 +2605,53 @@ ivas_error acelp_core_dec( if ( !st->ppp_mode_dec && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) { +#ifdef IVAS_FLOAT_FIXED + Word16 voice_factors_fx[5]; + Word32 tmp_bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; + Word32 tmp_old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; + Word16 e1, e2; + set32_fx( tmp_bwe_exc_extended_fx, 0, L_FRAME32k + NL_BUFF_OFFSET ); + + // Extract exponents. + f2me_buf_16( bwe_exc, bwe_exc_fx, &e1, L_FRAME32k ); + f2me_buf( st->hBWE_TD->old_bwe_exc_extended, tmp_old_bwe_exc_extended_fx, &e2, NL_BUFF_OFFSET ); + st->Q_exc = 15 - s_max( e1, e2 ); + st->Q_exc = s_min( st->Q_exc, 14 ); // non_linearity_fx function crashes if Q == 15 + // Float to fixed + for ( i = 0; i < ( st->L_frame == L_FRAME16k ? 5 : 4 ); i++ ) + { + voice_factors_fx[i] = float_to_fix16( voice_factors[i], Q15 ); + } + for ( i = 0; i < NL_BUFF_OFFSET; i++ ) + { + tmp_old_bwe_exc_extended_fx[i] = floatToFixed( st->hBWE_TD->old_bwe_exc_extended[i], 2 * st->Q_exc ); + } + for ( i = 0; i < L_FRAME32k; i++ ) + { + bwe_exc_fx[i] = (Word16)floatToFixed( bwe_exc[i], st->Q_exc ); + if (bwe_exc[i] != 0 && bwe_exc_fx[i] == 0) + { + // NOTE: This is done to avoid zero values when float values are too small. + // Else it will lead to a crash later in Interpolate_allpass_steep_32. + bwe_exc_fx[i] = 1; + } + } + + /* update buffer memory */ + Copy32( tmp_old_bwe_exc_extended_fx, tmp_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + + non_linearity_ivas_fx( bwe_exc_fx, tmp_bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); + + /* update buffer memory */ + Copy32( tmp_bwe_exc_extended_fx + L_FRAME32k, tmp_old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + + // Fixed to float + st->hBWE_TD->bwe_non_lin_prev_scale = fix_to_float( st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q30 ); + me2f_buf( tmp_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, bwe_exc_extended, L_FRAME32k + NL_BUFF_OFFSET ); + me2f_buf( tmp_old_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ); +#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 ); +#endif } if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c index 7a6e72e5d..bd448a036 100644 --- a/lib_dec/amr_wb_dec.c +++ b/lib_dec/amr_wb_dec.c @@ -42,6 +42,9 @@ #include "prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx2.h" +#endif /*------------------------------------------------------------------* * amr_wb_dec_flt() * @@ -163,10 +166,231 @@ ivas_error amr_wb_dec_flt( /* Updates in case of HQ -> AMR-WB IO switching */ #ifdef IVAS_FLOAT_FIXED - IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) +#if 1 /*Float to fix conversions*/ + Word16 nchan_out = -1; + Word16 last_element_brate = -1; + Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, + Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_old_exc, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, + Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ + Q_mem_syn2 = Q_factor_arr( st->mem_syn2, M ); + Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); + Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ); + Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); + Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); + Q_syn = Q_factor_arr( st->syn_float, M + 1 ); + Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) ) - 1; + Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); + floatToFixed_arr16( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn, M ); + floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); + floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); + floatToFixed_arr16( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); + st->mem_deemph_fx = (Word16) floatToFixed( st->mem_deemph, Q_mem_deemph ); + st->psf_lp_noise_fx = (Word16) floatToFixed( st->psf_lp_noise, Q7 ); /*Used floatToFixed because does not give error in case of garbage value*/ + st->lp_noise = float_to_fix16( st->lp_noise_float, Q7 ); + floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + IF( st->hBPF ) + { + Q_pst_old_syn = Q_factor_arrL( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); + Q_pst_mem_deemp_err = Q_factor_L( st->hBPF->pst_mem_deemp_err ); + floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); + } + IF( st->hBWE_TD ) + { + Q_old_bwe_exc = Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = float_to_fix( st->hBWE_TD->bwe_non_lin_prev_scale, 30 ); + floatToFixed_arr32( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx_32, Q_old_bwe_exc, PIT16k_MAX * 2 ); + } + IF( st->hBWE_zero ) + { + Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); + Q_mem_syn_hf = Q_factor_arr( st->hBWE_zero->mem_syn_hf, M ); + Q_mem_hp400 = Q_factor_arr( st->hBWE_zero->mem_hp400, 4 ); + Q_delay_syn_hf = Q_factor_arr( st->hBWE_zero->delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + Q_mem_hp_interp = Q_factor_arr( st->hBWE_zero->mem_hp_interp, INTERP_3_1_MEM_LEN ); + floatToFixed_arr16( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, Q_mem_hf, ( L_FIR - 1 ) ); + floatToFixed_arr16( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, Q_mem_syn_hf, M ); + floatToFixed_arr16( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_mem_hp400, 4 ); + floatToFixed_arr16( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + floatToFixed_arr16( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); + } + IF( st->hBWE_FD ) + { + Q_old_syn_12k8_16k = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, 36 ); + floatToFixed_arr16( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_old_syn_12k8_16k, 36 ); + } + IF( st->hHQ_core ) + { + Q_prev_env = Q_factor_arrL( st->hHQ_core->prev_env, SFM_N_WB ); + Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples, 960 ); + } + IF( st->hGSCDec ) + { + st->hGSCDec->Last_frame_ener_fx = floatToFixed( st->hGSCDec->Last_frame_ener, 0 ); /*Q-0*/ + } + IF( st->hTcxDec ) + { + Q_FBTCXdelayBuf = Q_factor_arr( st->hTcxDec->FBTCXdelayBuf_float, 111 ); + Q_prev_synth_buffer = s_min( Q_prev_synth_buffer, Q_FBTCXdelayBuf ); + Q_syn_Overl = Q_factor_arr( st->hTcxDec->syn_Overl_float, 320 ); + Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 ) - 1; + } + Q_syn_Overl = s_min( Q_fer_samples, Q_syn_Overl ) - 1; + IF( st->hHQ_core ) + { + floatToFixed_arr32( st->hHQ_core->prev_env, st->hHQ_core->prev_env_fx, Q_prev_env, SFM_N_WB ); + floatToFixed_arr32( st->hHQ_core->prev_normq, st->hHQ_core->prev_normq_fx, 14, SFM_N_WB ); /*Q-14*/ + floatToFixed_arr32( st->hHQ_core->last_ni_gain, st->hHQ_core->last_ni_gain_fx, 17, BANDS_MAX ); /*Q-17*/ + floatToFixed_arr16( st->hHQ_core->last_env, st->hHQ_core->last_env_fx, 1, BANDS_MAX ); /*Q-1*/ + floatToFixed_arr32( st->hHQ_core->prev_coeff_out, st->hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); /*Q-12*/ + floatToFixed_arr16( st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, Q_syn_Overl, 960 ); + st->hHQ_core->memfilt_lb_fx = float_to_fix16( st->hHQ_core->memfilt_lb, 0 ); + st->hHQ_core->mean_prev_hb_fx = float_to_fix( st->hHQ_core->mean_prev_hb, 0 ); + st->hHQ_core->smoothmem_fx = float_to_fix16( st->hHQ_core->smoothmem, 15 ); + st->hHQ_core->mean_prev_fx = floatToFixed( st->hHQ_core->mean_prev, 0 ); + st->hHQ_core->mean_prev_nc_fx = floatToFixed( st->hHQ_core->mean_prev_nc, 0 ); + st->hHQ_core->wmold_hb_fx = float_to_fix16( st->hHQ_core->wmold_hb, 15 ); + } + IF( st->hTcxDec ) + { + floatToFixed_arr16( st->hTcxDec->FBTCXdelayBuf_float, st->hTcxDec->FBTCXdelayBuf, Q_prev_synth_buffer, 111 ); + floatToFixed_arr16( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, Q_syn_Overl, 320 ); + floatToFixed_arr16( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, Q_old_syn_Overl, L_FRAME32k / 2 ); + } + floatToFixed_arr16( st->prev_synth_buffer, st->prev_synth_buffer_fx, Q_prev_synth_buffer, 96 ); + IF( st->cldfbAna ) + { + floatToFixed_arr32( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q10, st->cldfbAna->cldfb_state_length ); + } + IF( st->cldfbSyn ) + { + floatToFixed_arr32( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q11, st->cldfbSyn->cldfb_state_length ); + } + Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, 258 ) - 1; + floatToFixed_arr16( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 258 ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_old32[i] = float_to_fix( ( st->lsf_old[i] * 2.56f ), 0 ); + st->lsfoldbfi132[i] = float_to_fix( ( st->lsfoldbfi1[i] * 2.56f ), 0 ); + st->lsfoldbfi032[i] = float_to_fix( ( st->lsfoldbfi0[i] * 2.56f ), 0 ); + st->lsf_adaptive_mean32[i] = float_to_fix( ( st->lsf_adaptive_mean[i] * 2.56f ), 0 ); + st->lsp_old_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); + st->mem_AR32[i] = float_to_fix( ( st->mem_AR[i] * 2.56f ), 0 ); + st->mem_MA32[i] = (Word32) ( ( st->mem_MA[i] * 5.12f ) ); + } + IF( st->hFdCngDec ) + { + Q_olapBufferAna = Q_factor_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, FFTLEN ) - 1; + floatToFixed_arr16( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, st->hFdCngDec->hFdCngCom->olapBufferAna_fx, Q_olapBufferAna, L_FRAME32k ); + Q_olapBufferSynth = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, 640 ) - 2; + floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, Q_olapBufferSynth, 640 ); + Q_olapBufferSynth2 = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 640 ) - 1; + floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, Q_olapBufferSynth2, 640 ); + } + IF( st->cldfbBPF ) + floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); + Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; + floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); + floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); + st->enr_old_fx = (Word32) st->enr_old; + st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); + st->stab_fac_smooth_lt_fx = float_to_fix( st->stab_fac_smooth_lt, Q15 ); + st->lp_ener_fx = float_to_fix( st->lp_ener, Q6 ); + st->lp_gainc_fx = (Word16) L_min( 32767, float_to_fix( st->lp_gainc, 3 ) ); + floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); + IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) + { + IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) ) + { + Q_old_synthFB = Q_factor_arr( st->hTcxDec->old_synthFB, st->hTcxDec->old_synth_lenFB ) - 1; + floatToFixed_arr16( st->hTcxDec->old_synthFB, st->hTcxDec->old_synthFB_fx, Q_old_synthFB, st->hTcxDec->old_synth_lenFB ); + } + } +#endif + IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, -1, -1, EVS_MONO, -1 , Q_old_synthFB,&Q_olapBufferSynth, &Q_olapBufferSynth2) ) != IVAS_ERR_OK ) { return error; } +#if 1 /*Fixed to float function changes*/ + fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); + fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); + st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); + st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q7 ); /*psf_lp_noise_fx has Q7*/ + fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); + fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, 258 ); + st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); + st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); /*Q3*/ + FOR( i = 0; i < M; i++ ) + { + st->mem_MA[i] = (float) ( st->mem_MA32[i] / 5.12f ); + st->mem_AR[i] = (float) ( st->mem_AR32[i] / 2.56f ); + st->lsf_old[i] = (float) ( st->lsf_old32[i] / 2.56f ); + st->lsfoldbfi1[i] = (float) ( st->lsfoldbfi132[i] / 2.56f ); + st->lsfoldbfi0[i] = (float) ( st->lsfoldbfi032[i] / 2.56f ); + st->lsf_adaptive_mean[i] = (float) ( st->lsf_adaptive_mean32[i] / 2.56f ); + st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); + } + fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn, L_SYN_MEM ); + fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn, M ); + fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); + IF( st->hBPF ) + { + fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err = fixedToFloat( st->hBPF->pst_mem_deemp_err_32, Q_pst_mem_deemp_err ); + } + IF( st->hGSCDec ) + { + st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, 0 ); /*Q-0*/ + } + IF( st->hTcxDec ) + { + fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); + } + IF( st->hBWE_FD ) + fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + IF( st->hBWE_TD ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( st->hBWE_TD->bwe_non_lin_prev_scale_fx, 30 ); + fixedToFloat_arrL( st->hBWE_TD->old_bwe_exc_fx_32, st->hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); + } + IF( st->hBWE_zero ) + { + fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); + fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, Q_mem_syn_hf, M ); + fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_mem_hp400, 4 ); + fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); + } + IF( st->cldfbAna ) + fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q10, st->cldfbAna->cldfb_state_length ); + IF( st->cldfbSyn ) + fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q11, st->cldfbSyn->cldfb_state_length ); + IF( st->cldfbBPF ) + fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q11, st->cldfbBPF->cldfb_state_length ); + IF( st->hHQ_core ) + { + fixedToFloat_arrL( st->hHQ_core->prev_env_fx, st->hHQ_core->prev_env, Q_prev_env, SFM_N_WB ); + fixedToFloat_arrL( st->hHQ_core->prev_normq_fx, st->hHQ_core->prev_normq, 14, SFM_N_WB ); /*Q-14*/ + fixedToFloat_arrL( st->hHQ_core->last_ni_gain_fx, st->hHQ_core->last_ni_gain, 17, BANDS_MAX ); /*Q-17*/ + fixedToFloat_arr( st->hHQ_core->last_env_fx, st->hHQ_core->last_env, 1, BANDS_MAX ); /*Q-1*/ + fixedToFloat_arrL( st->hHQ_core->prev_coeff_out_fx, st->hHQ_core->prev_coeff_out, Q12, L_HQ_WB_BWE ); + st->hHQ_core->memfilt_lb = fixedToFloat( st->hHQ_core->memfilt_lb_fx, 0 ); + st->hHQ_core->mean_prev_hb = fixedToFloat( st->hHQ_core->mean_prev_hb_fx, 0 ); + st->hHQ_core->smoothmem = st->hHQ_core->smoothmem_fx / 32767.f; + st->hHQ_core->mean_prev = fixedToFloat( st->hHQ_core->mean_prev_fx, 0 ); + st->hHQ_core->mean_prev_nc = fixedToFloat( st->hHQ_core->mean_prev_nc_fx, 0 ); + st->hHQ_core->wmold_hb = st->hHQ_core->wmold_hb_fx / 32767.f; + fixedToFloat_arr( st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, Q_syn_Overl, 960 ); + } + IF( st->hFdCngDec ) + { + fixedToFloat_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, st->hFdCngDec->hFdCngCom->olapBufferAna_flt, Q_olapBufferAna, L_FRAME32k ); + fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, Q_olapBufferSynth2, L_FRAME32k ); + fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, Q_olapBufferSynth, L_FRAME32k ); + } +#endif #else if ( ( error = core_switching_pre_dec( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index e8844a1da..8c0e04881 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1002,6 +1002,105 @@ static void shb_CNG_decod_fx( * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void td_cng_dec_init_ivas_fx( + DEC_CORE_HANDLE st /* i/o: decoder state structure */ +) +{ + TD_CNG_DEC_HANDLE hTdCngDec; + Word16 i; + + hTdCngDec = st->hTdCngDec; + + hTdCngDec->cng_seed_fx = RANDOM_INITSEED; + move16(); + hTdCngDec->cng_ener_seed_fx = RANDOM_INITSEED; + move16(); + hTdCngDec->cng_ener_seed1_fx = RANDOM_INITSEED; + move16(); + hTdCngDec->old_enr_index_fx = -1; + move16(); + hTdCngDec->Enew_fx = L_deposit_l( 0 ); + hTdCngDec->last_allow_cn_step_fx = 0; + move16(); + Copy( st->lsp_old, st->lspCNG, M ); + st->shb_cng_ener_fx = -1541; + move16(); + IF( st->element_mode != EVS_MONO ) + { + set16_fx( hTdCngDec->shb_lpcCNG_fx, 0.0f, LPC_SHB_ORDER + 1 ); + hTdCngDec->shb_lpcCNG_fx[0] = 4096; + hTdCngDec->shb_cng_gain_fx = -20992; /* a dB value approximately corresponding to shb index 0(used as index -15) */ + } + st->wb_cng_ener_fx = -1541; + move16(); + st->last_wb_cng_ener_fx = -1541; + move16(); + st->last_shb_cng_ener_fx = -1541; + move16(); + st->swb_cng_seed_fx = RANDOM_INITSEED; + move16(); + hTdCngDec->ho_hist_ptr_fx = -1; + move16(); + hTdCngDec->ho_sid_bw_fx = L_deposit_l( 0 ); + set16_fx( hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); + hTdCngDec->ho_hist_size_fx = 0; + move16(); + hTdCngDec->act_cnt_fx = 0; + move16(); + hTdCngDec->ho_circ_ptr_fx = -1; + move16(); + set16_fx( hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); + set32_fx( hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE ); + set32_fx( hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); + hTdCngDec->ho_circ_size_fx = 0; + move16(); + + set16_fx( hTdCngDec->ho_16k_lsp_fx, 0, HO_HIST_SIZE ); + hTdCngDec->act_cnt2_fx = 0; + move16(); + hTdCngDec->num_ho_fx = 0; + move16(); + hTdCngDec->last_cng_type_fx = -1; + move16(); + set32_fx( hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG ); + set16_fx( hTdCngDec->exc_mem_fx, 0, 24 ); + set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 ); + set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG ); + st->CNG_mode = -1; + move16(); + + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + IF( st->element_mode != EVS_MONO ) + { + st->lsp_shb_prev_fx[i] = ivas_lsp_shb_prev_tbl_fx[i]; + move16(); + } + ELSE + { + st->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; + move16(); + } + st->lsp_shb_prev_prev_fx[i] = st->lsp_shb_prev_fx[i]; + move16(); + } + + st->shb_dtx_count_fx = 0; + move16(); + st->trans_cnt_fx = 0; + move16(); + st->last_shb_ener_fx = 0; + move16(); + set16_fx( st->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); + hTdCngDec->burst_cnt_fx = 0; + move16(); + + return; +} +#endif void td_cng_dec_init( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index 8fca8c892..fab458a20 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -704,6 +704,19 @@ void open_decoder_LPD_flt( #ifdef IVAS_FLOAT_FIXED st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = PLC_MIN_CNG_LEV; st->hTcxDec->CngLevelBackgroundTrace_bfi_exp = 16; + + hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; + move16(); + hTcxDec->conCurrLevelIndex = 0; + move16(); + hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + set16_fx(hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ + set16_fx(hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); + hTcxDec->conLastFrameLevel_e = 0; + hTcxDec->conCngLevelBackgroundTrace_e = 0; + + hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; #endif // IVAS_FLOAT_FIXED st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV_FLT; st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; @@ -975,9 +988,13 @@ void reset_tcx_overl_buf_fx( ) { set16_fx(hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_old_syn_Overl = 0; set16_fx(hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_syn_Overl_TDAC = 0; set16_fx(hTcxDec->syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_syn_Overl = 0; set16_fx(hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_syn_Overl_TDACFB = 0; return; } diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 2e444c7c9..6823346db 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1466,7 +1466,7 @@ void open_decoder_LPD_ivas_fx( *Q_old_Aq_12_8 = 14; IF( !st->last_con_tcx ) { - synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); + ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ,st->Q_syn); } /*mem of deemphasis stayed unchanged.*/ @@ -1686,11 +1686,26 @@ void open_decoder_LPD_ivas_fx( IF( is_init || MCT_flag || !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->element_mode, last_element_mode ) ) ) { st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = PLC_MIN_CNG_LEV; + st->hTcxDec->CngLevelBackgroundTrace_bfi_exp = 16; st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; st->hTcxDec->CurrLevelIndex_bfi = 0; st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV; set16_fx( st->hTcxDec->NoiseLevelMemory_bfi_fx, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); st->hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; + + + hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; + move16(); + hTcxDec->conCurrLevelIndex = 0; + move16(); + hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + set16_fx(hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ + set16_fx(hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); + hTcxDec->conLastFrameLevel_e = 0; + hTcxDec->conCngLevelBackgroundTrace_e = 0; + + hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; } } st->cummulative_damping = 32767 /*1.0f Q15*/; diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 1f518a821..ed78f5f09 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -73,149 +73,11 @@ ivas_error core_switching_pre_dec_ivas_fx( const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ - const Word32 last_element_brate /* i : last element bitrate */ -) + const Word32 last_element_brate, /* i : last element bitrate */ + Word16 Q_old_synthFB, + Word16 *Q_olapBufferSynth, + Word16 *Q_olapBufferSynth2 ) { -#if 1 /*Float to fix conversions*/ - Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, - Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_old_exc, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, - Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ - Q_mem_syn2 = Q_factor_arr( st->mem_syn2, M ); - Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); - Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ); - Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); - Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); - Q_syn = Q_factor_arr( st->syn_float, M + 1 ); - Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) )-1; - Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA(48000, DELAY_BWE_TOTAL_NS)); - Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); - floatToFixed_arr16( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); - floatToFixed_arr16( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); - st->mem_deemph_fx = (Word16)floatToFixed( st->mem_deemph, Q_mem_deemph ); - st->psf_lp_noise_fx = (Word16)floatToFixed( st->psf_lp_noise, Q7 );/*Used floatToFixed because does not give error in case of garbage value*/ - st->lp_noise = float_to_fix16( st->lp_noise_float, Q7 ); - floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); - IF( st->hBPF ) - { - Q_pst_old_syn = Q_factor_arrL( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); - Q_pst_mem_deemp_err = Q_factor_L( st->hBPF->pst_mem_deemp_err ); - floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); - } - IF( st->hBWE_TD ) - { - Q_old_bwe_exc = Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); - st->hBWE_TD->bwe_non_lin_prev_scale_fx = float_to_fix( st->hBWE_TD->bwe_non_lin_prev_scale, 30 ); - floatToFixed_arr32( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx_32, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } - IF( st->hBWE_zero ) - { - Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); - Q_mem_syn_hf = Q_factor_arr( st->hBWE_zero->mem_syn_hf, M ); - Q_mem_hp400 = Q_factor_arr( st->hBWE_zero->mem_hp400, 4 ); - Q_delay_syn_hf = Q_factor_arr( st->hBWE_zero->delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - Q_mem_hp_interp = Q_factor_arr( st->hBWE_zero->mem_hp_interp, INTERP_3_1_MEM_LEN ); - floatToFixed_arr16( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, Q_mem_hf, ( L_FIR - 1 ) ); - floatToFixed_arr16( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, Q_mem_syn_hf, M ); - floatToFixed_arr16( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_mem_hp400, 4 ); - floatToFixed_arr16( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - floatToFixed_arr16( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); - } - IF( st->hBWE_FD ) - { - Q_old_syn_12k8_16k = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, 36 ); - floatToFixed_arr16( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_old_syn_12k8_16k, 36 ); - } - IF( st->hHQ_core ) - { - Q_prev_env = Q_factor_arrL( st->hHQ_core->prev_env, SFM_N_WB ); - Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples, 960 ); - } - IF( st->hGSCDec ) - { - st->hGSCDec->Last_frame_ener_fx = floatToFixed( st->hGSCDec->Last_frame_ener, 0 ); /*Q-0*/ - } - IF( st->hTcxDec ) - { - Q_FBTCXdelayBuf = Q_factor_arr( st->hTcxDec->FBTCXdelayBuf_float, 111 ); - Q_prev_synth_buffer = s_min( Q_prev_synth_buffer, Q_FBTCXdelayBuf ); - Q_syn_Overl = Q_factor_arr( st->hTcxDec->syn_Overl_float, 320 ); - Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 )-1; - } - Q_syn_Overl = s_min( Q_fer_samples, Q_syn_Overl )-1; - IF( st->hHQ_core ) - { - floatToFixed_arr32( st->hHQ_core->prev_env, st->hHQ_core->prev_env_fx, Q_prev_env, SFM_N_WB ); - floatToFixed_arr32( st->hHQ_core->prev_normq, st->hHQ_core->prev_normq_fx, 14, SFM_N_WB ); /*Q-14*/ - floatToFixed_arr32( st->hHQ_core->last_ni_gain, st->hHQ_core->last_ni_gain_fx, 17, BANDS_MAX ); /*Q-17*/ - floatToFixed_arr16( st->hHQ_core->last_env, st->hHQ_core->last_env_fx, 1, BANDS_MAX ); /*Q-1*/ - floatToFixed_arr32( st->hHQ_core->prev_coeff_out, st->hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); /*Q-12*/ - floatToFixed_arr16( st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, Q_syn_Overl, 960 ); - st->hHQ_core->memfilt_lb_fx = float_to_fix16( st->hHQ_core->memfilt_lb, 0 ); - st->hHQ_core->mean_prev_hb_fx = float_to_fix( st->hHQ_core->mean_prev_hb, 0 ); - st->hHQ_core->smoothmem_fx = float_to_fix16( st->hHQ_core->smoothmem, 15 ); - st->hHQ_core->mean_prev_fx = floatToFixed( st->hHQ_core->mean_prev, 0 ); - st->hHQ_core->mean_prev_nc_fx = floatToFixed( st->hHQ_core->mean_prev_nc, 0 ); - st->hHQ_core->wmold_hb_fx = float_to_fix16( st->hHQ_core->wmold_hb, 15 ); - } - IF( st->hTcxDec ) - { - floatToFixed_arr16( st->hTcxDec->FBTCXdelayBuf_float, st->hTcxDec->FBTCXdelayBuf, Q_prev_synth_buffer, 111 ); - floatToFixed_arr16( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, Q_syn_Overl, 320 ); - floatToFixed_arr16( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, Q_old_syn_Overl, L_FRAME32k / 2 ); - } - floatToFixed_arr16( st->prev_synth_buffer, st->prev_synth_buffer_fx, Q_prev_synth_buffer, 96 ); - IF( st->cldfbAna ) - { - floatToFixed_arr32( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q10, st->cldfbAna->cldfb_state_length ); - } - IF( st->cldfbSyn ) - { - floatToFixed_arr32( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q11, st->cldfbSyn->cldfb_state_length ); - } - Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, 258 )-1; - floatToFixed_arr16( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 258 ); - FOR( Word16 i = 0; i < M; i++ ) - { - st->lsf_old32[i] = float_to_fix( (st->lsf_old[i] * 2.56f), 0 ); - st->lsfoldbfi132[i] = float_to_fix( (st->lsfoldbfi1[i] * 2.56f), 0 ); - st->lsfoldbfi032[i] = float_to_fix( (st->lsfoldbfi0[i] * 2.56f), 0 ); - st->lsf_adaptive_mean32[i] = float_to_fix( (st->lsf_adaptive_mean[i] * 2.56f), 0 ); - st->lsp_old_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); - st->mem_AR32[i] = float_to_fix( (st->mem_AR[i] * 2.56f), 0 ); - st->mem_MA32[i] = (Word32) ( (st->mem_MA[i] * 5.12f) ); - } - IF( st->hFdCngDec ) - { - Q_olapBufferAna = Q_factor_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, FFTLEN ) - 1; - floatToFixed_arr16( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, st->hFdCngDec->hFdCngCom->olapBufferAna_fx, Q_olapBufferAna, L_FRAME32k ); - Q_olapBufferSynth = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, 640 ) - 2; - floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, Q_olapBufferSynth, 640 ); - Q_olapBufferSynth2 = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 640 ) - 1; - floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, Q_olapBufferSynth2, 640 ); - } - IF( st->cldfbBPF ) - floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); - Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; - floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); - floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); - st->enr_old_fx = (Word32) st->enr_old; - st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); - st->stab_fac_smooth_lt_fx = float_to_fix( st->stab_fac_smooth_lt, Q15 ); - st->lp_ener_fx = float_to_fix( st->lp_ener, Q6 ); - st->lp_gainc_fx = (Word16)L_min(32767,float_to_fix( st->lp_gainc, 3 )); - floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); - IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) - { - IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) ) - { - Q_old_synthFB = Q_factor_arr( st->hTcxDec->old_synthFB, st->hTcxDec->old_synth_lenFB ) - 1; - floatToFixed_arr16( st->hTcxDec->old_synthFB, st->hTcxDec->old_synthFB_fx, Q_old_synthFB, st->hTcxDec->old_synth_lenFB ); - } - } -#endif Word32 tmp_fx; /*Q-12*/ Word16 i, oldLenClasBuff, newLenClasBuff; ivas_error error; @@ -823,11 +685,11 @@ ivas_error core_switching_pre_dec_ivas_fx( lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame ); } - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->L_frame * 2, st->last_L_frame * 2, &Q_olapBufferSynth2 ); + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->L_frame * 2, st->last_L_frame * 2, Q_olapBufferSynth2 ); IF( LE_32(st->total_brate , SID_2k40) && LE_32(st->last_total_brate , SID_2k40) ) { - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->L_frame * 2, st->last_L_frame * 2, &Q_olapBufferSynth ); + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->L_frame * 2, st->last_L_frame * 2, Q_olapBufferSynth ); IF( EQ_16(st->L_frame , L_FRAME) ) { @@ -847,85 +709,6 @@ ivas_error core_switching_pre_dec_ivas_fx( } } -#if 1 /*Fixed to float function changes*/ - fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); - fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); - st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); - st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q7 ); /*psf_lp_noise_fx has Q7*/ - fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); - fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); - fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, 258 ); - st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); - st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); /*Q3*/ - FOR( i = 0; i < M; i++ ) - { - st->mem_MA[i] = (float)(st->mem_MA32[i] / 5.12f); - st->mem_AR[i] = (float)(st->mem_AR32[i] / 2.56f); - st->lsf_old[i] = (float)(st->lsf_old32[i] / 2.56f); - st->lsfoldbfi1[i] = (float)(st->lsfoldbfi132[i] / 2.56f); - st->lsfoldbfi0[i] = (float)(st->lsfoldbfi032[i] / 2.56f); - st->lsf_adaptive_mean[i] = (float)(st->lsf_adaptive_mean32[i] / 2.56f); - st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); - } - fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn, L_SYN_MEM ); - fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn, M ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); - IF( st->hBPF ) - { - fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err = fixedToFloat( st->hBPF->pst_mem_deemp_err_32, Q_pst_mem_deemp_err ); - } - IF( st->hGSCDec ) - { - st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, 0 ); /*Q-0*/ - } - IF( st->hTcxDec ) - { - fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); - } - IF( st->hBWE_FD ) - fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - IF( st->hBWE_TD ) - { - st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( st->hBWE_TD->bwe_non_lin_prev_scale_fx, 30 ); - fixedToFloat_arrL( st->hBWE_TD->old_bwe_exc_fx_32, st->hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } - IF( st->hBWE_zero ) - { - fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); - fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, Q_mem_syn_hf, M ); - fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_mem_hp400, 4 ); - fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); - } - IF( st->cldfbAna ) - fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q10, st->cldfbAna->cldfb_state_length ); - IF( st->cldfbSyn ) - fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q11, st->cldfbSyn->cldfb_state_length ); - IF( st->cldfbBPF ) - fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q11, st->cldfbBPF->cldfb_state_length ); - IF( st->hHQ_core ) - { - fixedToFloat_arrL( st->hHQ_core->prev_env_fx, st->hHQ_core->prev_env, Q_prev_env, SFM_N_WB ); - fixedToFloat_arrL( st->hHQ_core->prev_normq_fx, st->hHQ_core->prev_normq, 14, SFM_N_WB ); /*Q-14*/ - fixedToFloat_arrL( st->hHQ_core->last_ni_gain_fx, st->hHQ_core->last_ni_gain, 17, BANDS_MAX ); /*Q-17*/ - fixedToFloat_arr( st->hHQ_core->last_env_fx, st->hHQ_core->last_env, 1, BANDS_MAX ); /*Q-1*/ - fixedToFloat_arrL( st->hHQ_core->prev_coeff_out_fx, st->hHQ_core->prev_coeff_out, Q12, L_HQ_WB_BWE ); - st->hHQ_core->memfilt_lb = fixedToFloat( st->hHQ_core->memfilt_lb_fx, 0 ); - st->hHQ_core->mean_prev_hb = fixedToFloat( st->hHQ_core->mean_prev_hb_fx, 0 ); - st->hHQ_core->smoothmem = st->hHQ_core->smoothmem_fx / 32767.f; - st->hHQ_core->mean_prev = fixedToFloat( st->hHQ_core->mean_prev_fx, 0 ); - st->hHQ_core->mean_prev_nc = fixedToFloat( st->hHQ_core->mean_prev_nc_fx, 0 ); - st->hHQ_core->wmold_hb = st->hHQ_core->wmold_hb_fx / 32767.f; - fixedToFloat_arr( st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, Q_syn_Overl, 960 ); - } - IF( st->hFdCngDec ) - { - fixedToFloat_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, st->hFdCngDec->hFdCngCom->olapBufferAna_flt, Q_olapBufferAna, L_FRAME32k ); - fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, Q_olapBufferSynth2, L_FRAME32k ); - fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, Q_olapBufferSynth, L_FRAME32k ); - } -#endif return error; } #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index 282d44259..49ec4a114 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -590,7 +590,16 @@ void decoder_LPD_flt( /* TCX decoder */ #ifdef IVAS_FLOAT_FIXED - decoder_tcx_fx( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, 0 ); + Word16 synth_fx[L_FRAME48k], synthFB_fx[L_FRAME48k], Aq_fx[(NB_SUBFR16k + 1) * (M + 1)]; + floatToFixed_arr(synth, synth_fx, 0, st->L_frame); + floatToFixed_arr(synthFB, synthFB_fx, 0, hTcxDec->L_frameTCX); + floatToFixed_arr(Aq, Aq_fx, Q12, M+1); + + //decoder_tcx_fx( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, 0 ); + decoder_tcx_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], bfi, 0, 0 ); + + fixedToFloat_arr(synth_fx, synth, 0, st->L_frame); + fixedToFloat_arr(synthFB_fx, synthFB, 0, hTcxDec->L_frameTCX); #else decoder_tcx_flt( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, 0 ); #endif @@ -620,7 +629,16 @@ void decoder_LPD_flt( /* TCX decoder */ #ifdef IVAS_FLOAT_FIXED - decoder_tcx_fx( st, prm, Aq, Aind, &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], bfi, k, 0 ); + Word16 synth_fx[L_FRAME48k], synthFB_fx[L_FRAME48k], Aq_fx[(NB_SUBFR16k + 1) * (M + 1)]; + floatToFixed_arr(synth, synth_fx, 0, st->L_frame + k * L_frame / 2); + floatToFixed_arr(synthFB, synthFB_fx, 0, hTcxDec->L_frameTCX + k * L_frameTCX / 2); + floatToFixed_arr(Aq, Aq_fx, Q12, M + 1); + + //decoder_tcx_fx( st, prm, Aq, Aind, &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], bfi, k, 0 ); + decoder_tcx_fx( st, prm, Aq_fx, Aind, &synth_fx[k * L_frame / 2], &synthFB_fx[k * L_frameTCX / 2], bfi, k, 0 ); + + fixedToFloat_arr(synth_fx, synth, 0, st->L_frame + k * L_frame / 2); + fixedToFloat_arr(synthFB_fx, synthFB, 0, hTcxDec->L_frameTCX + k * L_frameTCX / 2); #else decoder_tcx_flt( st, prm, Aq, Aind, &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], bfi, k, 0 ); #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index e9d2cb686..c06de0611 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3172,15 +3172,16 @@ void decoder_tcx_IGF_stereo_fx( void decoder_tcx_fx( Decoder_State *st, Word16 prm[], - float A[], + Word16 A_fx[], Word16 Aind[], - float synth[], - float synthFB[], + Word16 synth_fx[], + Word16 synthFB_fx[], const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ) { float x[N_MAX] = { 0 }; + //float A[M+1]; Word32 x_fx[N_MAX]; Word16 x_e; float gainlpc2[FDNS_NPTS]; @@ -3223,23 +3224,6 @@ void decoder_tcx_fx( init_tcx_info_fx( st, L_frame_glob, L_frameTCX_glob, frame_cnt, bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); #ifdef IVAS_FLOAT_FIXED - Word16 A_fx[M + 1], A_q; - - double max_val = 0; - FOR ( Word16 j = 0; j < M + 1; j++ ) - { - max_val = max( max_val, fabs( A[j] ) ); - } - IF ( fabs( max_val ) < 1.0 ) - A_q = Q15; - ELSE - A_q = norm_s( (Word16) max_val ); - - FOR ( Word16 j = 0; j < M + 1; j++ ) - { - A_fx[j] = float_to_fix16( A[j], A_q ); - } - /* TODO: Temporary inits. Remove float dependency */ st->gamma = float_to_fix16( st->gamma_float, Q15 ); st->preemph_fac = float_to_fix16( st->preemph_fac_float, Q15 ); @@ -3294,7 +3278,7 @@ void decoder_tcx_fx( dbgwrite_txt(&(st->lp_gainp), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_lpGainp.txt", NULL); #endif #else - decoder_tcx_invQ( st, prm, A, Aind, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &xn_buf[0], &fUseTns, &tnsData, &gain_tcx, &prm_sqQ, &nf_seed, bfi, frame_cnt ); + //decoder_tcx_invQ( st, prm, A, Aind, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &xn_buf[0], &fUseTns, &tnsData, &gain_tcx, &prm_sqQ, &nf_seed, bfi, frame_cnt ); #if 0 dbgwrite_txt(x, L_frameTCX, "logs\\dir\\Float_code_decoderTcxInvQ_x.txt", NULL); dbgwrite_txt(xn_buf, max(max(L_frame, L_spec), L_frameTCX), "logs\\dir\\Float_code_decoderTcxInvQ_xnBuf.txt", NULL); @@ -3330,7 +3314,7 @@ void decoder_tcx_fx( } me2f_buf( x_fx, x_e, x, N_MAX ); #else - decoder_tcx_noisefilling( st, NULL, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, 0, frame_cnt ); + //decoder_tcx_noisefilling( st, NULL, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, 0, frame_cnt ); #endif #ifdef IVAS_FLOAT_FIXED @@ -3387,7 +3371,7 @@ void decoder_tcx_fx( me2f_buf(x_fx, x_e, x, x_len); // Fixed to float ends here #else - decoder_tcx_noiseshaping_igf( st, L_spec, L_frame, L_frameTCX, left_rect, &x[0], &gainlpc2[0], &tmp_concealment_method, bfi ); + //decoder_tcx_noiseshaping_igf( st, L_spec, L_frame, L_frameTCX, left_rect, &x[0], &gainlpc2[0], &tmp_concealment_method, bfi ); #endif #ifdef IVAS_FLOAT_FIXED @@ -3400,12 +3384,10 @@ void decoder_tcx_fx( decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx_, fUseTns, &tnsData, bfi, frame_cnt, 0 ); FOR(Word16 ind = 0; ind < 1200; ind++) x[ind] = (float)(x_fx_[ind]) / (float)(1 << q); #else - decoder_tcx_tns( st, L_frame_glob, L_spec, L_frame, L_frameTCX, &x[0], fUseTns, &tnsData, bfi, frame_cnt, 0 ); + //decoder_tcx_tns( st, L_frame_glob, L_spec, L_frame, L_frameTCX, &x[0], fUseTns, &tnsData, bfi, frame_cnt, 0 ); #endif #ifdef IVAS_FLOAT_FIXED - // - Word16 synth_fx[2040], synthFB_fx[2040]; Word16 q_x = Q11, q_win = -2; FOR(Word16 i = 0; i < s_min(s_max(s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX, L_spec)), L_frame), 1200); i++) { @@ -3476,16 +3458,30 @@ void decoder_tcx_fx( FOR(Word16 ind = 0; ind < 960; ind++) { st->hHQ_core->old_out_fx[ind] = (Word16)(st->hHQ_core->old_out[ind] / (1<<(-q_win))); } - FOR(Word16 ind = 0; ind < L_frame_glob; ind++) { - synth_fx[ind] = (Word16)(synth[ind] / (1<<(-q_win))); +/*=======================================*/ + /*Scaling down the synth and synthFB buffers for decoder_tcx_imdct_fx */ + FOR( Word16 ind = 0; ind < L_frame_glob; ind++ ) + { + synth_fx[ind] = shr( synth_fx[ind], 2 ); } - FOR(Word16 ind = 0; ind < L_frameTCX_glob; ind++) { - synthFB_fx[ind] = (Word16)(synthFB[ind] / (1<<(-q_win))); + FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) + { + synthFB_fx[ind] = shr( synthFB_fx[ind], 2 ); } decoder_tcx_imdct_fx( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x_fx[0], q_x, xn_buf_fx, q_win, MDCT_IV, - fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); - + fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); + + /* Scaling up again */ + FOR( Word16 ind = 0; ind < L_frame_glob; ind++ ) + { + synth_fx[ind] = shl_sat( synth_fx[ind], 2 ); + } + FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) + { + synthFB_fx[ind] = shl_sat( synthFB_fx[ind], 2 ); + } + /*=======================================*/ IF(st->igf) me2f_buf(x_fx, x_e, x, s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX, L_spec) ) ); FOR(Word16 ind = 0; ind < 17; ind++) { @@ -3497,12 +3493,6 @@ void decoder_tcx_fx( FOR(Word16 ind = 0; ind < 960; ind++) { st->hHQ_core->old_out[ind] = (float)st->hHQ_core->old_out_fx[ind] * (1<<(-q_win)); } - FOR(Word16 ind = 0; ind < L_frame_glob; ind++) { - synth[ind] = (float)synth_fx[ind] * (1<<(-q_win)); - } - FOR(Word16 ind = 0; ind < L_frameTCX_glob; ind++) { - synthFB[ind] = (float)synthFB_fx[ind] * (1<<(-q_win)); - } IF ( EQ_16(st->hTcxCfg->last_aldo, 0) ) FOR(Word16 ind = 0; ind < L_FRAME32k / 2; ind++) { st->hTcxDec->syn_Overl_float[ind] = (float)st->hTcxDec->syn_Overl[ind] * (1<<(-q_win)); } @@ -3516,8 +3506,8 @@ void decoder_tcx_fx( // #else - decoder_tcx_imdct( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x[0], &xn_buf[0], MDCT_IV, - fUseTns, &synth[0], &synthFB[0], bfi, frame_cnt, sba_dirac_stereo_flag ); + //decoder_tcx_imdct( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x[0], &xn_buf[0], MDCT_IV, + // fUseTns, &synth[0], &synthFB[0], bfi, frame_cnt, sba_dirac_stereo_flag ); #endif } @@ -3931,7 +3921,7 @@ void decoder_tcx_invQ_fx( { tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gainCompensate_e ) /*Q15, gainCompensate_e*/; gainCompensate_e = add( gainCompensate_e, 10 /*scaling of h1[0] and E_UTIL:synthesis*/ ); - gainCompensate = round_fx( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; + gainCompensate = round_fx_sat( Sqrt32( tmp32, &gainCompensate_e ) ) /*Q15, gainCompensate_e*/; BASOP_Util_Divide_MantExp( st->last_gain_syn_deemph, st->last_gain_syn_deemph_e, gainCompensate, diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 85474cc90..43270dcde 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -588,11 +588,21 @@ Word16 GetPLCModeDecision( { pitch = L_add(st->old_fpitch, 0); } - TonalMDCTConceal_Detect(&st->tonalMDCTconceal, pitch, &numIndices + if (st->element_mode == EVS_MONO) + { + TonalMDCTConceal_Detect(&st->tonalMDCTconceal, pitch, &numIndices #ifdef ADD_IVAS_HTONALMDCTCONC , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) #endif - ); + ); + } + else { + TonalMDCTConceal_Detect(st->hTonalMDCTConc, pitch, &numIndices +#ifdef ADD_IVAS_HTONALMDCTCONC + , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) +#endif + ); + } test(); test(); diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 0148b4d01..90b425678 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -247,10 +247,231 @@ ivas_error evs_dec_flt( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) +#if 1 /*Float to fix conversions*/ + Word16 nchan_out = -1; + Word16 last_element_brate = -1; + Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, + Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_old_exc, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, + Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ + Q_mem_syn2 = Q_factor_arr( st->mem_syn2, M ); + Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); + Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ); + Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); + Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); + Q_syn = Q_factor_arr( st->syn_float, M + 1 ); + Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) ) - 1; + Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); + floatToFixed_arr16( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn, M ); + floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); + floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); + floatToFixed_arr16( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); + st->mem_deemph_fx = (Word16) floatToFixed( st->mem_deemph, Q_mem_deemph ); + st->psf_lp_noise_fx = (Word16) floatToFixed( st->psf_lp_noise, Q7 ); /*Used floatToFixed because does not give error in case of garbage value*/ + st->lp_noise = float_to_fix16( st->lp_noise_float, Q7 ); + floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + IF( st->hBPF ) + { + Q_pst_old_syn = Q_factor_arrL( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); + Q_pst_mem_deemp_err = Q_factor_L( st->hBPF->pst_mem_deemp_err ); + floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); + } + IF( st->hBWE_TD ) + { + Q_old_bwe_exc = Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = float_to_fix( st->hBWE_TD->bwe_non_lin_prev_scale, 30 ); + floatToFixed_arr32( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx_32, Q_old_bwe_exc, PIT16k_MAX * 2 ); + } + IF( st->hBWE_zero ) + { + Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); + Q_mem_syn_hf = Q_factor_arr( st->hBWE_zero->mem_syn_hf, M ); + Q_mem_hp400 = Q_factor_arr( st->hBWE_zero->mem_hp400, 4 ); + Q_delay_syn_hf = Q_factor_arr( st->hBWE_zero->delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + Q_mem_hp_interp = Q_factor_arr( st->hBWE_zero->mem_hp_interp, INTERP_3_1_MEM_LEN ); + floatToFixed_arr16( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, Q_mem_hf, ( L_FIR - 1 ) ); + floatToFixed_arr16( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, Q_mem_syn_hf, M ); + floatToFixed_arr16( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_mem_hp400, 4 ); + floatToFixed_arr16( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + floatToFixed_arr16( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); + } + IF( st->hBWE_FD ) + { + Q_old_syn_12k8_16k = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, 36 ); + floatToFixed_arr16( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_old_syn_12k8_16k, 36 ); + } + IF( st->hHQ_core ) + { + Q_prev_env = Q_factor_arrL( st->hHQ_core->prev_env, SFM_N_WB ); + Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples, 960 ); + } + IF( st->hGSCDec ) + { + st->hGSCDec->Last_frame_ener_fx = floatToFixed( st->hGSCDec->Last_frame_ener, 0 ); /*Q-0*/ + } + IF( st->hTcxDec ) + { + Q_FBTCXdelayBuf = Q_factor_arr( st->hTcxDec->FBTCXdelayBuf_float, 111 ); + Q_prev_synth_buffer = s_min( Q_prev_synth_buffer, Q_FBTCXdelayBuf ); + Q_syn_Overl = Q_factor_arr( st->hTcxDec->syn_Overl_float, 320 ); + Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 ) - 1; + } + Q_syn_Overl = s_min( Q_fer_samples, Q_syn_Overl ) - 1; + IF( st->hHQ_core ) + { + floatToFixed_arr32( st->hHQ_core->prev_env, st->hHQ_core->prev_env_fx, Q_prev_env, SFM_N_WB ); + floatToFixed_arr32( st->hHQ_core->prev_normq, st->hHQ_core->prev_normq_fx, 14, SFM_N_WB ); /*Q-14*/ + floatToFixed_arr32( st->hHQ_core->last_ni_gain, st->hHQ_core->last_ni_gain_fx, 17, BANDS_MAX ); /*Q-17*/ + floatToFixed_arr16( st->hHQ_core->last_env, st->hHQ_core->last_env_fx, 1, BANDS_MAX ); /*Q-1*/ + floatToFixed_arr32( st->hHQ_core->prev_coeff_out, st->hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); /*Q-12*/ + floatToFixed_arr16( st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, Q_syn_Overl, 960 ); + st->hHQ_core->memfilt_lb_fx = float_to_fix16( st->hHQ_core->memfilt_lb, 0 ); + st->hHQ_core->mean_prev_hb_fx = float_to_fix( st->hHQ_core->mean_prev_hb, 0 ); + st->hHQ_core->smoothmem_fx = float_to_fix16( st->hHQ_core->smoothmem, 15 ); + st->hHQ_core->mean_prev_fx = floatToFixed( st->hHQ_core->mean_prev, 0 ); + st->hHQ_core->mean_prev_nc_fx = floatToFixed( st->hHQ_core->mean_prev_nc, 0 ); + st->hHQ_core->wmold_hb_fx = float_to_fix16( st->hHQ_core->wmold_hb, 15 ); + } + IF( st->hTcxDec ) + { + floatToFixed_arr16( st->hTcxDec->FBTCXdelayBuf_float, st->hTcxDec->FBTCXdelayBuf, Q_prev_synth_buffer, 111 ); + floatToFixed_arr16( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, Q_syn_Overl, 320 ); + floatToFixed_arr16( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, Q_old_syn_Overl, L_FRAME32k / 2 ); + } + floatToFixed_arr16( st->prev_synth_buffer, st->prev_synth_buffer_fx, Q_prev_synth_buffer, 96 ); + IF( st->cldfbAna ) + { + floatToFixed_arr32( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q10, st->cldfbAna->cldfb_state_length ); + } + IF( st->cldfbSyn ) + { + floatToFixed_arr32( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q11, st->cldfbSyn->cldfb_state_length ); + } + Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, 258 ) - 1; + floatToFixed_arr16( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 258 ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_old32[i] = float_to_fix( ( st->lsf_old[i] * 2.56f ), 0 ); + st->lsfoldbfi132[i] = float_to_fix( ( st->lsfoldbfi1[i] * 2.56f ), 0 ); + st->lsfoldbfi032[i] = float_to_fix( ( st->lsfoldbfi0[i] * 2.56f ), 0 ); + st->lsf_adaptive_mean32[i] = float_to_fix( ( st->lsf_adaptive_mean[i] * 2.56f ), 0 ); + st->lsp_old_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); + st->mem_AR32[i] = float_to_fix( ( st->mem_AR[i] * 2.56f ), 0 ); + st->mem_MA32[i] = (Word32) ( ( st->mem_MA[i] * 5.12f ) ); + } + IF( st->hFdCngDec ) + { + Q_olapBufferAna = Q_factor_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, FFTLEN ) - 1; + floatToFixed_arr16( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, st->hFdCngDec->hFdCngCom->olapBufferAna_fx, Q_olapBufferAna, L_FRAME32k ); + Q_olapBufferSynth = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, 640 ) - 2; + floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, Q_olapBufferSynth, 640 ); + Q_olapBufferSynth2 = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 640 ) - 1; + floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, Q_olapBufferSynth2, 640 ); + } + IF( st->cldfbBPF ) + floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); + Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; + floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); + floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); + st->enr_old_fx = (Word32) st->enr_old; + st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); + st->stab_fac_smooth_lt_fx = float_to_fix( st->stab_fac_smooth_lt, Q15 ); + st->lp_ener_fx = float_to_fix( st->lp_ener, Q6 ); + st->lp_gainc_fx = (Word16) L_min( 32767, float_to_fix( st->lp_gainc, 3 ) ); + floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); + IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) + { + IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) ) + { + Q_old_synthFB = Q_factor_arr( st->hTcxDec->old_synthFB, st->hTcxDec->old_synth_lenFB ) - 1; + floatToFixed_arr16( st->hTcxDec->old_synthFB, st->hTcxDec->old_synthFB_fx, Q_old_synthFB, st->hTcxDec->old_synth_lenFB ); + } + } +#endif + IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, -1, -1, EVS_MONO, -1 ,Q_old_synthFB, &Q_olapBufferSynth,&Q_olapBufferSynth2) ) != IVAS_ERR_OK ) { return error; } +#if 1 /*Fixed to float function changes*/ + fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); + fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); + st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); + st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q7 ); /*psf_lp_noise_fx has Q7*/ + fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); + fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, 258 ); + st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); + st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); /*Q3*/ + FOR( i = 0; i < M; i++ ) + { + st->mem_MA[i] = (float) ( st->mem_MA32[i] / 5.12f ); + st->mem_AR[i] = (float) ( st->mem_AR32[i] / 2.56f ); + st->lsf_old[i] = (float) ( st->lsf_old32[i] / 2.56f ); + st->lsfoldbfi1[i] = (float) ( st->lsfoldbfi132[i] / 2.56f ); + st->lsfoldbfi0[i] = (float) ( st->lsfoldbfi032[i] / 2.56f ); + st->lsf_adaptive_mean[i] = (float) ( st->lsf_adaptive_mean32[i] / 2.56f ); + st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); + } + fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn, L_SYN_MEM ); + fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn, M ); + fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); + IF( st->hBPF ) + { + fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err = fixedToFloat( st->hBPF->pst_mem_deemp_err_32, Q_pst_mem_deemp_err ); + } + IF( st->hGSCDec ) + { + st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, 0 ); /*Q-0*/ + } + IF( st->hTcxDec ) + { + fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); + } + IF( st->hBWE_FD ) + fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + IF( st->hBWE_TD ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( st->hBWE_TD->bwe_non_lin_prev_scale_fx, 30 ); + fixedToFloat_arrL( st->hBWE_TD->old_bwe_exc_fx_32, st->hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); + } + IF( st->hBWE_zero ) + { + fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); + fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, Q_mem_syn_hf, M ); + fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_mem_hp400, 4 ); + fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); + } + IF( st->cldfbAna ) + fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q10, st->cldfbAna->cldfb_state_length ); + IF( st->cldfbSyn ) + fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q11, st->cldfbSyn->cldfb_state_length ); + IF( st->cldfbBPF ) + fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q11, st->cldfbBPF->cldfb_state_length ); + IF( st->hHQ_core ) + { + fixedToFloat_arrL( st->hHQ_core->prev_env_fx, st->hHQ_core->prev_env, Q_prev_env, SFM_N_WB ); + fixedToFloat_arrL( st->hHQ_core->prev_normq_fx, st->hHQ_core->prev_normq, 14, SFM_N_WB ); /*Q-14*/ + fixedToFloat_arrL( st->hHQ_core->last_ni_gain_fx, st->hHQ_core->last_ni_gain, 17, BANDS_MAX ); /*Q-17*/ + fixedToFloat_arr( st->hHQ_core->last_env_fx, st->hHQ_core->last_env, 1, BANDS_MAX ); /*Q-1*/ + fixedToFloat_arrL( st->hHQ_core->prev_coeff_out_fx, st->hHQ_core->prev_coeff_out, Q12, L_HQ_WB_BWE ); + st->hHQ_core->memfilt_lb = fixedToFloat( st->hHQ_core->memfilt_lb_fx, 0 ); + st->hHQ_core->mean_prev_hb = fixedToFloat( st->hHQ_core->mean_prev_hb_fx, 0 ); + st->hHQ_core->smoothmem = st->hHQ_core->smoothmem_fx / 32767.f; + st->hHQ_core->mean_prev = fixedToFloat( st->hHQ_core->mean_prev_fx, 0 ); + st->hHQ_core->mean_prev_nc = fixedToFloat( st->hHQ_core->mean_prev_nc_fx, 0 ); + st->hHQ_core->wmold_hb = st->hHQ_core->wmold_hb_fx / 32767.f; + fixedToFloat_arr( st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, Q_syn_Overl, 960 ); + } + IF( st->hFdCngDec ) + { + fixedToFloat_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, st->hFdCngDec->hFdCngCom->olapBufferAna_flt, Q_olapBufferAna, L_FRAME32k ); + fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, Q_olapBufferSynth2, L_FRAME32k ); + fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, Q_olapBufferSynth, L_FRAME32k ); + } +#endif #else if ( ( error = core_switching_pre_dec( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 4bf768279..eebd085cd 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -14,6 +14,10 @@ #include "ivas_prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_rom_dec.h" +#include "ivas_prot_fx.h" +#endif #define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ @@ -62,6 +66,123 @@ ivas_error createFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) return error; } +#ifdef IVAS_FLOAT_FIXED +void ivas_initFdCngDec_fx( + DEC_CORE_HANDLE st, /* i/o: decoder state structure */ + Word16 scale ) +{ + /* Initialize common */ + HANDLE_FD_CNG_DEC hFdCngDec; + + hFdCngDec = st->hFdCngDec; + + ivas_initFdCngCom_fx( hFdCngDec->hFdCngCom, scale ); + set16_fx( hFdCngDec->olapBufferAna, 0, 320 ); + hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; + move16(); + set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); + hFdCngDec->hFdCngCom->olapBufferSynth2 = hFdCngDec->olapBufferSynth2; + move16(); + + /* Set some counters and flags */ + + hFdCngDec->flag_dtx_mode = 0; + move16(); + hFdCngDec->lp_noise = -167772160l /*-20.f Q23*/; /* format: Q8.24 */ + move32(); + hFdCngDec->lp_speech = 209715200l /* 25.f Q23*/; /* format: Q8.24 */ + move32(); + + /* Initialization of the noise estimation algorithm */ + + set32_fx( hFdCngDec->bandNoiseShape, 0, FFTLEN2 ); + set16_fx( &hFdCngDec->bandNoiseShape_exp, 0, 1 ); + + set32_fx( hFdCngDec->partNoiseShape, 0, NPART ); + set16_fx( &hFdCngDec->partNoiseShape_exp, 0, 1 ); + + set32_fx( hFdCngDec->msPeriodog, 0, NPART_SHAPING ); + set16_fx( &hFdCngDec->msPeriodog_exp, 0, 1 ); + + set32_fx( hFdCngDec->msAlpha, 0, NPART_SHAPING ); + + set32_fx( hFdCngDec->msBminWin, 0, NPART_SHAPING ); + + set32_fx( hFdCngDec->msBminSubWin, 0, NPART_SHAPING ); + + set16_fx( hFdCngDec->msPsd, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); + + set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); + set16_fx( &hFdCngDec->msNoiseEst_exp, 0, 1 ); + + set32_fx( hFdCngDec->msMinBuf, 2147483647l /*1.0 Q31*/, MSNUMSUBFR * NPART_SHAPING ); + + set32_fx( hFdCngDec->msCurrentMin, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); + + set32_fx( hFdCngDec->msCurrentMinOut, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); + + set32_fx( hFdCngDec->msCurrentMinSubWindow, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); + + set16_fx( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); + + set16_fx( hFdCngDec->msPsdFirstMoment, 0, NPART_SHAPING ); + + set32_fx( hFdCngDec->msPsdSecondMoment, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msPeriodogBuf, 0, MSBUFLEN * NPART_SHAPING ); + + hFdCngDec->msPeriodogBufPtr = 0; + move16(); + + set16_fx( hFdCngDec->msLogPeriodog, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msLogNoiseEst, 0, NPART_SHAPING ); + + set16_fx( hFdCngDec->psize_shaping, 0, NPART_SHAPING ); + hFdCngDec->nFFTpart_shaping = 0; + move16(); + set32_fx( hFdCngDec->msPeriodog_ST_fx, 0, NPART_SHAPING ); + hFdCngDec->msPeriodog_ST_exp = 0; + move16(); + hFdCngDec->hFdCngCom->fftBuffer_exp = 0; + move16(); + hFdCngDec->hFdCngCom->periodog_exp = 0; + move16(); + set32_fx( hFdCngDec->smoothed_psd_fx, 0, L_FRAME16k ); + + set32_fx( hFdCngDec->hFdCngCom->sidNoiseEstLp, 0, NPART ); + + hFdCngDec->ms_last_inactive_bwidth = NB; + move16(); + hFdCngDec->ms_cnt_bw_up = 0; + move16(); + + hFdCngDec->cna_LR_LT_fx = 16384; /* 0.5 in Q15 */ + move16(); + hFdCngDec->cna_ILD_LT_fx = 0; + move16(); + hFdCngDec->first_cna_noise_updated = 0; + move16(); + hFdCngDec->first_cna_noise_update_cnt = 0; + move16(); + hFdCngDec->cna_nbands = CNA_INIT_NBANDS; + move16(); + Copy( cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1 ); + hFdCngDec->cna_act_fact_fx = 32767; /* 1.0f in Q15 */ + move16(); + hFdCngDec->cna_rescale_fact_fx = 0; + move16(); + hFdCngDec->cna_seed = 5687; + move16(); + set16_fx( hFdCngDec->cna_cm_fx, 0, STEREO_DFT_BAND_MAX ); + set16_fx( hFdCngDec->cna_g_state_fx, 0, STEREO_DFT_BAND_MAX ); + + st->CNG_mode = -1; + move16(); + Copy( st->lsp_old_fx, st->lspCNG_fx, M ); + return; +} +#endif void initFdCngDec( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ Word16 scale diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 5083a4087..460a3da49 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -1182,3 +1182,32 @@ void GSC_dec_init( move32(); return; } + +#ifdef IVAS_FLOAT_FIXED +void GSC_dec_init_ivas_fx( + GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ +) +{ + hGSCDec->seed_tcx_fx = 15687; + move16(); + hGSCDec->cor_strong_limit_fx = 1; + move16(); + set16_fx(hGSCDec->old_y_gain_fx, 0, MBANDS_GN); + hGSCDec->noise_lev_fx = NOISE_LEVEL_SP0; + move16(); + set16_fx(hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k); + hGSCDec->Last_GSC_pit_band_idx_fx = 0; + move16(); + + set16_fx(hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k); /*Q12*/ + set16_fx(hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k); + hGSCDec->last_ener_fx = 0; + move16(); + set16_fx(hGSCDec->last_bitallocation_band_fx, 0, 6); + + hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); + + return; +} +#endif diff --git a/lib_dec/hf_synth.c b/lib_dec/hf_synth.c index 1f0d2f6af..7af1f8291 100644 --- a/lib_dec/hf_synth.c +++ b/lib_dec/hf_synth.c @@ -41,6 +41,11 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx2.h" +#include "prot_fx1.h" +#include "basop32.h" +#endif /*---------------------------------------------------------------------* * Local function prototypes @@ -58,7 +63,6 @@ static void envelope( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const int32_t core_brate, c static void AdaptiveStartBand( int16_t *start_band, const int32_t core_brate, const float *lsf, const float voicing_fac, const int16_t clas, int16_t *voicing_flag, int16_t *start_band_old, float *OptCrit_old ); - /*-------------------------------------------------------------------* * hf_synth_init() * diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 3c0cd6fb7..011e0006e 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -25,6 +25,11 @@ static void filt_6k_7k_scale_fx(Word16 signal[], Word16 lg, Word16 mem[], Word16 static void hf_synthesis_fx(ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr,const Word16 Aq[], const Word16 exc[], const Word16 Q_exc,Word16 synth[],Word16 synth16k[] , const Word16 Q_syn, Word16* delay_syn_hf, Word16 *memExp1, Word16* mem_hp_interp, const Word16 extl, const Word16 CNG_mode ); +#ifdef IVAS_FLOAT_FIXED +static void hf_synthesis_ivas_fx(ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], + const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[] + , const Word16 Q_syn, Word16* delay_syn_hf, Word16 *memExp1, Word16* mem_hp_interp, const Word16 extl, const Word16 CNG_mode, Word16 element_mode); +#endif static void hf_synthesis_amr_wb_fx( const Word32 core_brate, const Word16 output_subfr, const Word16 Ap[], Word16 exc16k[], Word16 synth_out[], Word16 *mem_syn_hf, Word16 *delay_syn_hf, Word16 *mem_hp_interp, Word16 p_r, @@ -42,6 +47,21 @@ static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const * - initialization of 400 Hz high pass filter * - initialization of band pass 6kHz to 7kHz FIR filter *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void hf_synth_init_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ +) +{ + hBWE_zero->seed2 = RANDOM_INITSEED; + set16_fx( hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) ); + set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M ); + set16_fx( hBWE_zero->mem_hp400_fx, 0, 4 ); + set16_fx( hBWE_zero->delay_syn_hf_fx, 0, NS2SA( 16000, DELAY_CLDFB_NS ) ); + set16_fx( hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); + + return; +} +#else void hf_synth_init_fx( ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) @@ -56,6 +76,7 @@ void hf_synth_init_fx( return; } +#endif void hf_synth_reset_fx( ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) @@ -119,6 +140,45 @@ void hf_synth_fx( return; } + +#ifdef IVAS_FLOAT_FIXED +void hf_synth_ivas_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16 *Aq, /* i : quantized Az */ + const Word16 *exc, /* i : excitation at 12.8 kHz */ + Word16 *synth, /* i : 12.8kHz synthesis signal */ + Word16 *synth16k, /* o : 16kHz synthesis signal */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *memExp1, /* o : HF excitation exponent */ + Word16 *mem_hp_interp, /* i/o: interpol. memory */ + const Word16 extl, /* i : flag indicating BWE */ + const Word16 CNG_mode, /* i : CNG_mode */ + Word16 element_mode ) +{ + const Word16 *p_Aq; + Word16 i_subfr, output_subfr; + + output_subfr = output_frame / NB_SUBFR; + move16(); + + p_Aq = Aq; + move16(); + + FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) + { + hf_synthesis_ivas_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[i_subfr * output_subfr / L_SUBFR], + Q_syn2, delay_syn_hf, memExp1, mem_hp_interp, extl, CNG_mode, element_mode ); + p_Aq += ( M + 1 ); + move16(); + } + + return; +} +#endif /*-----------------------------------------------------------------------------------* * hf_synthesis() * @@ -203,8 +263,11 @@ static void hf_synthesis_fx( * calculate energy scaling factor to respect tilt of synth12k8 * (tilt: 1=voiced, -1=unvoiced) *-----------------------------------------------------------------*/ - +#ifdef EVS_MONO hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); +#else + hp400_12k8_ivas_fx(synth, L_SUBFR, hBWE_zero->mem_hp400_fx); +#endif /* i: mem_hp400 in Q_syn */ /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ @@ -344,6 +407,232 @@ static void hf_synthesis_fx( return; } +#ifdef IVAS_FLOAT_FIXED +static void hf_synthesis_ivas_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_subfr, /* i : output sub-frame length */ + const Word16 Aq[], /* i : quantized Az Q12 */ + const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc */ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn */ + Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn */ + const Word16 Q_syn, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn */ + Word16 *memExp1, /* o : HF excitation scaling exponent */ + Word16 *mem_hp_interp, /* i/o: interpol. memory */ + const Word16 extl, /* i : flag indicating BWE */ + const Word16 CNG_mode, /* i : CNG_mode */ + Word16 element_mode ) +{ + Word16 i; + Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_FRAME48k / NB_SUBFR]; + Word16 HF_exc[L_SUBFR16k]; + Word16 temp_buffer[NS2SA( 16000, DELAY_CLDFB_NS ) - L_FILT16k]; + Word16 tmp, ener, exp1, exp2, scale, delay; + Word32 L_tmp; + Word16 Ap[M16k + 1]; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + (void) extl; + (void) CNG_mode; + + /*-----------------------------------------------------------------* + * generate white noise vector + *-----------------------------------------------------------------*/ + + Random_Fill( &hBWE_zero->seed2, L_SUBFR16k, HF_exc, 3 ); /* 3 = Shift Right by 3 */ + + /* o: HF_exc in Q-3 */ + + /*-----------------------------------------------------------------* + * calculate energy scaling factor so that white noise would have the + * same energy as exc12k8 + *-----------------------------------------------------------------*/ + + /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + exp2 = sub( exp2, add( Q_exc, Q_exc ) ); + + /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ + L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); + tmp = round_fx( L_tmp ); + /* tmp = (float)(sqrt(ener/tmp)) */ + /* scale is -1 if tmp > ener */ + scale = shr( sub( ener, tmp ), 15 ); + tmp = shl( tmp, scale ); + exp1 = sub( exp1, scale ); + + tmp = div_s( tmp, ener ); + exp1 = sub( exp1, exp2 ); + + L_tmp = L_deposit_h( tmp ); + + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ + + exp2 = sub( *memExp1, exp1 ); + move16(); + *memExp1 = exp1; + move16(); + + /*-----------------------------------------------------------------* + * calculate energy scaling factor to respect tilt of synth12k8 + * (tilt: 1=voiced, -1=unvoiced) + *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + IF( element_mode == EVS_MONO ) + { + hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); + } + ELSE + { + hp400_12k8_ivas_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); + } +#else + hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); +#endif + /* i: mem_hp400 in Q_syn */ + /* i: synth in Q_syn */ + /* o: synth in Q_syn-3 */ + + L_tmp = L_mac( 1L, synth[0], synth[0] ); + FOR( i = 1; i < L_SUBFR; i++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); +#else + L_tmp = L_mac( L_tmp, synth[i], synth[i] ); +#endif + } + tmp = norm_l( L_tmp ); + ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ + /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ + + L_tmp = L_mac( 1L, synth[1], synth[0] ); + FOR( i = 2; i < L_SUBFR; i++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); +#else + L_tmp = L_mac( L_tmp, synth[i], synth[i - 1] ); +#endif + } + tmp = extract_h( L_shl( L_tmp, tmp ) ); /* tmp = r[1] */ + /*tmp in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0 */ + /*we use the same normalization factor for both ener and tmp, */ + /*if the headroom in "tmp" is less than "ener", tmp can saturate */ + /*but this is ok since below we apply some thresholds to tmp */ + + tmp = s_max( 0, tmp ); + if ( tmp > 0 ) + { + tmp = div_s( tmp, ener ); + } + + /*-----------------------------------------------------------------* + * modify energy of white noise according to synthesis tilt + *-----------------------------------------------------------------*/ + + /* tmp = 1.0 - fac */ +#ifdef BASOP_NOGLOB + tmp = add_o( 1, sub( 32767, tmp ), &Overflow ); +#else + tmp = add( 1, sub( 32767, tmp ) ); +#endif + test(); + if ( EQ_32( core_brate, FRAME_NO_DATA ) || EQ_32( core_brate, SID_2k40 ) ) + { + /* emphasize HF noise in CNG */ + /*fac *= 2.0f;*/ +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, tmp, &Overflow ); +#else + tmp = add( tmp, tmp ); +#endif + } + tmp = s_max( tmp, 3277 ); /* 0.1 in Q15 */ + + /*scale *= fac;*/ + tmp = mult_r( scale, tmp ); + /*-----------------------------------------------------------------* + * modify HF excitation according to both calculated scaling factors + * high pass filtering (0.94ms of delay) + *-----------------------------------------------------------------*/ + + filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx, tmp, exp2 ); + /* i: input HF_exc is scaled in float, here scaling is done inside this filter */ + /* i: mem_hf in Q-2 */ + /* o: HF_exc in Q0 */ + + /*-----------------------------------------------------------------* + * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz + *-----------------------------------------------------------------*/ + + /*weight_a( Aq, Ap, 0.6f, M );*/ + weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M ); + /* o: Ap in Q14 */ + + Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, hBWE_zero->mem_syn_hf_fx, 1 ); + /* i: Ap in Q14 */ + /* i: HF_exc in Q0 */ + /* o: HF_syn in Q0 */ + /* i/o: mem_syn_hf in Q0 */ + + Scale_sig( HF_syn, L_SUBFR16k, ( add( Q_syn, exp1 ) ) ); /* bring HF_syn to (Q_syn+exp1) */ + + /*-----------------------------------------------------------------* + * add filtered HF noise to speech synthesis + *-----------------------------------------------------------------*/ + + /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ + delay = NS2SA( 16000, DELAY_CLDFB_NS ) - 15; + Copy( HF_syn + L_SUBFR16k - delay, temp_buffer, delay ); + Copy( HF_syn, HF_syn + delay, L_SUBFR16k - delay ); + Copy( delay_syn_hf, HF_syn, delay ); + Copy( temp_buffer, delay_syn_hf, delay ); + + /* interpolate the HF synthesis */ + IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ + { + { + Word16 s; + s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), + sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), + 0 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); + Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); + Scale_sig( HF_syn, L_SUBFR16k, -s ); + } + Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); + } + ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ + { + { + Word16 s; + s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); + Scale_sig( HF_syn, L_SUBFR16k, -s ); + } + } + ELSE /* 16kHz sampled output */ + { + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + } + + Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); + + return; +} +#endif /*-------------------------------------------------------------------* * filt_6k_7k: diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 4dc07db54..d84ec8a14 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1217,6 +1217,8 @@ void HQ_core_dec_init( hHQ_core->Q_old_wtda = 15; hHQ_core->Q_old_postdec = 0; hHQ_core->Q_old_wtda_LB = 0; + hHQ_core->Q_old_out = 0; + hHQ_core->Q_old_outLB = 0; hHQ_core->last_hq_core_type_fx = -1; set16_fx(hHQ_core->old_is_transient_fx, 0, 3); @@ -1245,7 +1247,8 @@ void HQ_core_dec_init( set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); hHQ_core->last_max_pos_pulse_fx = 0; move16(); - + hHQ_core->Q_fer_samples = 0; + reset_preecho_dec_fx(hHQ_core); hHQ_core->prev_frm_hfe2_fx = 0; diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index 0e465c6cb..7428d2260 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -1596,22 +1596,13 @@ void init_igf_dec_flt( { set_c( (int8_t *) ( hIGFDec->infoTCXNoiseBuf ), 0, IGF_START_MX ); set_f( hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( hIGFDec->igfData.pSpecFlatBuf_fx, 0, IGF_START_MX ); -#endif hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733; hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733; hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; -#ifdef IVAS_FLOAT_FIXED - hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; -#endif hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; -#ifdef IVAS_FLOAT_FIXED - hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; -#endif return; } diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index cb50388bd..3bc13fae3 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -4262,20 +4262,11 @@ void init_igf_dec( hIGFDec->infoIGFStartLine = -1; move16(); - set_f( hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); -#ifdef IVAS_FLOAT_FIXED set32_fx( hIGFDec->igfData.pSpecFlatBuf_fx, 0, IGF_START_MX ); -#endif - hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; -#ifdef IVAS_FLOAT_FIXED hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; -#endif hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; - hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; -#ifdef IVAS_FLOAT_FIXED hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; -#endif return; } diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index c86292341..adabf549f 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -127,6 +127,10 @@ ivas_error init_decoder( st->mem_deemph = 0.0f; +#ifdef IVAS_FLOAT_FIXED + st->scale = 1.f; +#endif // IVAS_FLOAT_FIXED + set_f( st->mem_syn1, 0, M ); set_f( st->mem_syn2, 0, M ); st->stab_fac = 0.0f; @@ -570,6 +574,10 @@ ivas_error init_decoder( st->old_Es_pred = 0; set_f( st->old_Aq_12_8 + 1, 0, M ); st->old_Aq_12_8[0] = 1; +#ifdef IVAS_FLOAT_FIXED + set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); + st->old_Aq_12_8_fx[0] = ONE_IN_Q12; +#endif /*-----------------------------------------------------------------* * SC-VBR parameters diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index a6a7a1060..8a3634b17 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -10,6 +10,11 @@ #include "stl.h" /* required for wmc_tool */ #include "basop_util.h" #include "prot.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif + +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*----------------------------------------------------------------------* * init_decoder() @@ -826,6 +831,1114 @@ ivas_error init_decoder_fx( } +#ifdef IVAS_FLOAT_FIXED +ivas_error init_decoder_ivas_fx( + Decoder_State *st_fx, /* o: Decoder static variables structure */ + const Word16 idchan, /* i : channel ID */ + const MC_MODE mc_mode /* i : MC mode */ +) +{ + Word16 i; + ivas_error error; + + error = IVAS_ERR_OK; + + /*-----------------------------------------------------------------* + * General parameters + *-----------------------------------------------------------------*/ + + st_fx->codec_mode = MODE1; + move16(); + st_fx->last_codec_mode = MODE1; + move16(); + st_fx->core = ACELP_CORE; + move16(); + st_fx->L_frame = L_FRAME; + move16(); + st_fx->extl = -1; + move16(); + st_fx->extl_orig = -1; /* extension layer */ + move16(); + st_fx->extl_brate_orig = 0; /* extension layer bitrate */ + move16(); + st_fx->last_bits_frame_nominal = -1; + move16(); + st_fx->total_brate = ACELP_8k00; + move16(); + st_fx->last_total_brate = -1; + move16(); + st_fx->last_total_brate_ber = -1; + move32(); + st_fx->core_brate = ACELP_8k00; + move16(); + st_fx->ini_frame = 0; + move16(); + st_fx->bwidth = NB; + move16(); + st_fx->last_bwidth = NB; + move16(); + st_fx->extl_brate = 0; + move16(); + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + st_fx->coder_type = GENERIC; + st_fx->last_coder_type = GENERIC; +#endif + st_fx->coder_type_fx = GENERIC; /* low-rate mode flag */ + move16(); + st_fx->last_coder_type_fx = GENERIC; + move16(); + st_fx->inactive_coder_type_flag = 0; + move16(); + st_fx->last_L_frame = st_fx->L_frame; + move16(); + st_fx->last_core_brate = st_fx->core_brate; + move16(); + st_fx->last_core = -1; + move16(); + st_fx->last_extl = st_fx->extl; + move16(); + + st_fx->flag_ACELP16k = set_ACELP_flag(st_fx->element_mode, st_fx->total_brate, st_fx->total_brate, idchan, 0, -1, -1); + + /*-----------------------------------------------------------------* + * ACELP core parameters + *-----------------------------------------------------------------*/ + + /* LSF initilaizations */ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // Remove once fixed version is present. + mvr2r(GEWB_Ave, st_fx->mem_AR, M); + + set_f(st_fx->mem_MA, 0, M); + set_f(st_fx->dispMem, 0, 8); + st_fx->tilt_code = 0.0f; + st_fx->gc_threshold = 0.0f; +#endif + Copy(GEWB_Ave_fx, st_fx->mem_AR_fx, M); + + init_lvq_fx(st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx); + + set16_fx(st_fx->mem_MA_fx, 0, M); + + st_fx->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + st_fx->dm_fx.prev_gain_code = L_deposit_l(0); + FOR(i = 2; i < 8; i++) + { + st_fx->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } + st_fx->tilt_code_fx = 0; + move16(); + st_fx->gc_threshold_fx = 0; + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + st_fx->last_good = UNVOICED_CLAS; +#endif + st_fx->last_good_fx = UNVOICED_CLAS; + move16(); + st_fx->clas_dec = UNVOICED_CLAS; + move16(); + st_fx->low_rate_mode = 0; /* low-rate mode flag */ + st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // Remove once fixed version is present. + st_fx->lp_gainp = 0.0f; + st_fx->lp_gainc = 0.0f; + + set_f(st_fx->old_exc, 0, L_EXC_MEM_DEC); +#endif + + st_fx->lp_gainp_fx = 0; + move16(); + st_fx->lp_gainc_fx = 0; + move16(); + + set16_fx(st_fx->old_exc_fx, 0, L_EXC_MEM_DEC); + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // Remove once fixed version is present. + /* AVQ pre-quantizer memory */ + st_fx->mem_preemp_preQ = 0.0f; + st_fx->last_nq_preQ = 0; + st_fx->last_code_preq = 0; + st_fx->use_acelp_preq = 0; + + st_fx->mem_deemph = 0.0f; + +#ifdef IVAS_FLOAT_FIXED + st_fx->scale = 1.f; +#endif // IVAS_FLOAT_FIXED + + set_f(st_fx->mem_syn1, 0, M); + set_f(st_fx->mem_syn2, 0, M); + st_fx->stab_fac = 0.0f; + st_fx->stab_fac_smooth = 0.0f; + set_f(st_fx->agc_mem2, 0, 2); + set_f(st_fx->mem_syn3, 0, M); + st_fx->stab_fac_smooth_lt = 0.0f; + st_fx->log_energy_diff_lt = 0.0f; + st_fx->log_energy_old = 0.0f; + + mvr2r(GEWB_Ave, st_fx->lsf_old, M); + lsf2lsp(st_fx->lsf_old, st_fx->lsp_old, M, INT_FS_12k8); + + st_fx->mid_lsf_int = 0; + st_fx->safety_net = 0; +#endif + + /* AVQ pre-quantizer memory */ + st_fx->mem_preemp_preQ_fx = 0; + move16(); + st_fx->last_nq_preQ_fx = 0; + move16(); + st_fx->use_acelp_preq = 0; + move16(); + + st_fx->mem_deemph_fx = 0; + move16(); + + set16_fx(st_fx->mem_syn1_fx, 0, M); + move16(); + set16_fx(st_fx->mem_syn2_fx, 0, M); + st_fx->stab_fac_fx = 0; + move16(); + st_fx->stab_fac_smooth_fx = 0; + move16(); + set16_fx(st_fx->agc_mem_fx, 0, 2); + set16_fx(st_fx->mem_syn3_fx, 0, M); + + st_fx->stab_fac_smooth_lt_fx = 0; + st_fx->log_energy_diff_lt_fx = 0; + st_fx->log_energy_old_fx = 0; + + Copy(GEWB_Ave_fx, st_fx->lsf_old_fx, M); + lsf2lsp_fx(st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_12k8); + + st_fx->mid_lsf_int_fx = 0; + st_fx->safety_net_fx = 0; + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + /* FEC */ + st_fx->scaling_flag = 0; + st_fx->lp_ener_FEC_av_float = 5.0e5f; + st_fx->lp_ener_FEC_max_float = 5.0e5f; + st_fx->prev_bfi = 0; + st_fx->lp_ener_bfi = 60.0f; + st_fx->old_enr_LP_float = 0.0f; + st_fx->lp_ener = 0.0f; + st_fx->enr_old = 0.0f; + st_fx->bfi_pitch = (float)L_SUBFR; + st_fx->bfi_pitch_frame = L_FRAME; + set_f(st_fx->mem_syn_clas_estim, 0.0f, L_SYN_MEM_CLAS_ESTIM); + st_fx->last_con_tcx = 0; + + for (i = 0; i < 2 * NB_SUBFR16k; i++) + { + st_fx->old_pitch_buf[i] = (float)L_SUBFR; + } + + st_fx->upd_cnt = MAX_UPD_CNT; + + mvr2r(GEWB_Ave, st_fx->lsfoldbfi0, M); + mvr2r(GEWB_Ave, st_fx->lsfoldbfi1, M); + mvr2r(GEWB_Ave, st_fx->lsf_adaptive_mean, M); + + st_fx->seed_acelp = RANDOM_INITSEED; + st_fx->seed = RANDOM_INITSEED; + st_fx->nbLostCmpt = 0; + st_fx->decision_hyst = 0; +#endif + + /* FEC */ + st_fx->scaling_flag = 0; + move16(); + st_fx->lp_ener_FEC_av = 500000; + move32(); + st_fx->lp_ener_FEC_max = 500000; + move32(); + st_fx->prev_bfi = 0; + move16(); + st_fx->lp_ener_FER_fx = 15360; + move16(); /*60 in Q8*/ + st_fx->old_enr_LP = 0; + move16(); + st_fx->lp_ener_fx = L_deposit_l(0); + st_fx->enr_old_fx = L_deposit_l(0); + st_fx->bfi_pitch_fx = L_SUBFR_Q6; + move16(); + st_fx->bfi_pitch_frame = L_FRAME; + move16(); + set16_fx(st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM); + st_fx->classifier_Q_mem_syn = 0; + move16(); + st_fx->last_con_tcx = 0; + move16(); + + FOR(i = 0; i < 2 * NB_SUBFR16k; i++) + { + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; + move32(); /*15Q16*/ + } + + st_fx->upd_cnt = MAX_UPD_CNT; + move16(); + Copy(GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M); + Copy(GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M); + Copy(GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M); + + st_fx->seed_acelp = RANDOM_INITSEED; + move16(); + st_fx->seed = RANDOM_INITSEED; + move16(); + st_fx->nbLostCmpt = 0; + move16(); + st_fx->decision_hyst = 0; + move16(); + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + /* Stationary noise UV modification */ + st_fx->unv_cnt = 0; + st_fx->ge_sm = 10; + st_fx->uv_count = 0; + st_fx->act_count = 3; + mvr2r(st_fx->lsp_old, st_fx->lspold_s, M); + st_fx->noimix_seed = RANDOM_INITSEED; + st_fx->min_alpha = 1; + st_fx->exc_pe = 0; + + st_fx->prev_coder_type = GENERIC; + st_fx->tilt_wb = 0.0f; + + st_fx->last_voice_factor = 0.0f; + set_f(st_fx->prev_synth_buffer, 0, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); + + st_fx->old_bfi_cnt = 0; +#endif + + st_fx->unv_cnt_fx = 0; + move16(); + st_fx->ge_sm_fx = L_deposit_l(640); /*Q(GE_SHIFT)*/ + st_fx->uv_count_fx = 0; + move16(); + st_fx->act_count_fx = 3; + move16(); + Copy(st_fx->lsp_old_fx, st_fx->lspold_s_fx, M); + st_fx->noimix_seed_fx = RANDOM_INITSEED; + move16(); + st_fx->min_alpha_fx = 32767; + move16(); /*1; Q15*/ + st_fx->exc_pe_fx = 0; + move16(); + + st_fx->prev_coder_type_fx = GENERIC; + move16(); + + st_fx->tilt_wb_fx = 0; + move16(); + + st_fx->last_voice_factor_fx = 0; + move16(); + + set16_fx(st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); + st_fx->Qprev_synth_buffer_fx = 15; + move16(); + + st_fx->old_bfi_cnt_fx = 0; + move16(); + + /*-----------------------------------------------------------------* + * parameters for AC mode (GSC) + *-----------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->GSC_noisy_speech = 0; + st_fx->GSC_IVAS_mode = 0; + st_fx->Last_GSC_noisy_speech_flag = 0; +#endif + st_fx->GSC_noisy_speech_fx = 0; + st_fx->GSC_IVAS_mode = 0; + st_fx->Last_GSC_noisy_speech_flag_fx = 0; + + IF((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF((st_fx->hGSCDec = (GSC_DEC_HANDLE)count_malloc(sizeof(GSC_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); + } +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + GSC_dec_init_ivas(st_fx->hGSCDec); +#endif + GSC_dec_init_ivas_fx(st_fx->hGSCDec); + } + ELSE + { + st_fx->hGSCDec = NULL; + } + + /*-----------------------------------------------------------------* + * parameters for fast recovery (WI) + *-----------------------------------------------------------------*/ + + IF(EQ_32(st_fx->output_Fs, 16000) && EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF((st_fx->hWIDec = (WI_DEC_HANDLE)count_malloc(sizeof(WI_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n")); + } +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + set_f(st_fx->hWIDec->old_exc2, 0, L_EXC_MEM); + set_f(st_fx->hWIDec->old_syn2, 0, L_EXC_MEM); +#endif + set16_fx(st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM); + set16_fx(st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM); + } + ELSE + { + st_fx->hWIDec = NULL; + } + + /* NB post-filter */ + /*-----------------------------------------------------------------* + * NB/formant post-filter + *-----------------------------------------------------------------*/ + IF((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF((st_fx->hPFstat = (PFSTAT_HANDLE)count_malloc(sizeof(PFSTAT))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + Init_post_filter_ivas(st_fx->hPFstat); + st_fx->psf_lp_noise = 0.0f; +#endif + Init_post_filter(st_fx->hPFstat); + st_fx->psf_lp_noise_fx = 0; + } + ELSE + { + st_fx->hPFstat = NULL; + } + + /*-----------------------------------------------------------------* + * HF (6-7kHz) (zero) BWE parameters + *-----------------------------------------------------------------*/ + + IF((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF((st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE)malloc(sizeof(ZERO_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + hf_synth_init(st_fx->hBWE_zero); +#endif + hf_synth_init_fx(st_fx->hBWE_zero); + } + ELSE + { + st_fx->hBWE_zero = NULL; + } + + /*-----------------------------------------------------------------* + * LD music post-filter + *-----------------------------------------------------------------*/ + + IF((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF((st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE)count_malloc(sizeof(MUSIC_POSTFILT_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + music_postfilt_init_flt(st_fx->hMusicPF); +#endif + music_postfilt_init(st_fx->hMusicPF); + } + ELSE + { + st_fx->hMusicPF = NULL; + } + + /*-----------------------------------------------------------------* + * CNG and DTX + *-----------------------------------------------------------------*/ + + st_fx->first_CNG = 0; + move16(); + st_fx->cng_type = -1; + move16(); + st_fx->last_active_brate = ACELP_7k20; + move32(); + st_fx->last_CNG_L_frame = L_FRAME; + move16(); + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->last_vad = 0; +#endif + st_fx->last_vad_fx = 0; + move16(); + + st_fx->active_cnt = 20; + move16(); + + IF(idchan == 0 && (EQ_16(st_fx->element_mode, EVS_MONO) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD))) + { + if ((st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE)count_malloc(sizeof(TD_CNG_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + td_cng_dec_init_flt(st_fx); +#endif + td_cng_dec_init_ivas_fx(st_fx); + } + ELSE + { + st_fx->hTdCngDec = NULL; + } + + st_fx->masa_sid_format = 0; + move16(); + + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->prev_old_bfi = 0; + set_f(st_fx->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); + set_f(st_fx->previoussynth, 0, L_FRAME48k); +#endif + st_fx->prev_old_bfi_fx = 0; + + set16_fx(st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX* HQ_DELAY_COMP); + set16_fx(st_fx->previoussynth_fx, 0, L_FRAME48k); + + set32_fx(st_fx->delay_buf_out32_fx, 0, HQ_DELTA_MAX* HQ_DELAY_COMP); + set32_fx(st_fx->previoussynth_fx_32, 0, L_FRAME48k); + + IF(EQ_16(st_fx->element_mode, EVS_MONO)) + { + set16_fx(st_fx->old_synth_sw_fx, 0, NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)); + } + + IF((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, EVS_MONO))) + { + IF((st_fx->hHQ_core = (HQ_DEC_HANDLE)malloc(sizeof(HQ_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n")); + } + + /* HQ core initialization */ + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + HQ_core_dec_init_flt(st_fx->hHQ_core); +#endif + HQ_core_dec_init(st_fx->hHQ_core); + + IF(EQ_16(st_fx->element_mode, EVS_MONO)) + { + /* HQ NB FEC initialization */ + IF((st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE)malloc(sizeof(HQ_NBFEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n")); + } +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + HQ_nbfec_init_flt(st_fx->hHQ_nbfec); +#endif + HQ_nbfec_init(st_fx->hHQ_nbfec); + } + ELSE + { + st_fx->hHQ_nbfec = NULL; + move16(); + } + } + ELSE + { + st_fx->hHQ_core = NULL; + st_fx->hHQ_nbfec = NULL; + move16(); move16(); + } + + /*-----------------------------------------------------------------* + * TBE parameters + *-----------------------------------------------------------------*/ + + IF(idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + if ((st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE)malloc(sizeof(TD_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + td_bwe_dec_init(st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs); +#endif + td_bwe_dec_init_fx(st_fx, st_fx->hBWE_TD, +#ifdef ADD_IVAS_BWE + st_fx->extl, +#endif + st_fx->output_Fs); + + } + ELSE + { + st_fx->hBWE_TD = NULL; + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->old_bwe_delay = -1; + set_f(st_fx->hb_prev_synth_buffer, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS)); +#endif + st_fx->old_bwe_delay_fx = -1; /*Q0*/ move16(); + set16_fx(st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS)); + + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + + IF(idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF((st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE)malloc(sizeof(FD_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + fd_bwe_dec_init_flt(st_fx->hBWE_FD); +#endif + fd_bwe_dec_init(st_fx, st_fx->hBWE_FD); + } + ELSE + { + st_fx->hBWE_FD = NULL; + } + + /*-----------------------------------------------------------------* + * WB/SWB bandwidth switching parameters + *-----------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->tilt_swb = 0.0f; + st_fx->prev_ener_shb = 0.0f; + st_fx->prev_enerLH = 0.0f; + st_fx->enerLH = 0.0f; + st_fx->enerLL = 0.0f; + st_fx->prev_enerLL = 0.0f; + st_fx->prev_fractive = 0; + st_fx->prev_bws_cnt = 0; + st_fx->bws_cnt = N_WS2N_FRAMES; + st_fx->bws_cnt1 = N_NS2W_FRAMES; + st_fx->attenu1 = 0.1f; +#endif + st_fx->tilt_swb_fx = 0; + move16(); + + st_fx->prev_ener_shb_fx = 0; + move16(); + st_fx->prev_enerLH_fx = 0; + move16(); + st_fx->enerLH_fx = L_deposit_l(0); + st_fx->enerLL_fx = L_deposit_l(0); + st_fx->prev_enerLL_fx = 0; + move16(); + st_fx->prev_fractive_fx = 0; + move16(); + st_fx->prev_bws_cnt_fx = 0; + move16(); + st_fx->bws_cnt_fx = N_WS2N_FRAMES; + move16(); + st_fx->bws_cnt1_fx = N_NS2W_FRAMES; + move16(); + st_fx->attenu_fx = 3277; + move16(); + + st_fx->last_inner_frame = L_FRAME8k; + move16(); + + /*-----------------------------------------------------------------* + * HR SWB BWE parameters + *-----------------------------------------------------------------*/ + + IF(EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF((st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE)count_malloc(sizeof(HR_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n")); + } +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + hr_bwe_dec_init_flt(st_fx->hBWE_FD_HR); +#endif + hr_bwe_dec_init(st_fx->hBWE_FD_HR); + } + ELSE + { + st_fx->hBWE_FD_HR = NULL; + } + + /*----------------------------------------------------------------------------------* + * AMR-WB IO mode parameters + *----------------------------------------------------------------------------------*/ + + IF(st_fx->Opt_AMR_WB || EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF((st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE)count_malloc(sizeof(AMRWB_IO_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + /* AMR-WB IO init */ + amr_wb_dec_init_flt(st_fx->hAmrwb_IO); + + /* AMR-WB IO HF synth init */ + hf_synth_amr_wb_init(st_fx->hAmrwb_IO); +#endif + /* AMR-WB IO init */ + amr_wb_dec_init(st_fx->hAmrwb_IO); + + /* AMR-WB IO HF synth init */ + hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); + } + ELSE + { + st_fx->hAmrwb_IO = NULL; + } + + /*-----------------------------------------------------------------* + * channel-aware mode parameters + *-----------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + set_f(st_fx->tilt_code_dec, 0.0f, NB_SUBFR16k); +#endif + set16_fx(st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k); + + st_fx->use_partial_copy = 0; + move16(); + st_fx->prev_use_partial_copy = 0; + move16(); + st_fx->rf_flag = 0; + move16(); + st_fx->rf_flag_last = 0; + st_fx->prev_rf_frame_type = 0; + move16(); + st_fx->next_coder_type = 0; + move16(); + + st_fx->rf_target_bits = 0; + move16(); + + st_fx->rf_indx_nelp_fid = 0; + move16(); + st_fx->rf_indx_nelp_iG1 = 0; + move16(); + st_fx->rf_indx_nelp_iG2[0] = 0; + move16(); + st_fx->rf_indx_nelp_iG2[1] = 0; + move16(); + st_fx->rf_indx_tbeGainFr = 0; + move16(); + + + /*-----------------------------------------------------------------* + * Bass post-filter parameters + *-----------------------------------------------------------------*/ + + st_fx->bpf_off = 0; + + IF((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF((st_fx->hBPF = (BPF_DEC_HANDLE)malloc(sizeof(BPF_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n")); + } +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + bass_psfilter_init(st_fx->hBPF); +#endif + bass_psfilter_init_fx(st_fx->hBPF); + } + ELSE + { + st_fx->hBPF = NULL; + } + + /*-----------------------------------------------------------------* + * FD BPF & resampling tools parameters + *-----------------------------------------------------------------*/ + + IF ((idchan == 0 && NE_16(st_fx->element_mode , IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + /* open analysis for max. SR 48kHz */ + IF ((error = openCldfb_ivas_fx(&st_fx->cldfbAna_fx, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } + + /* open analysis BPF for max. SR 16kHz */ + IF ((error = openCldfb_ivas_fx(&st_fx->cldfbBPF_fx, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } + } + ELSE { + st_fx->cldfbAna_fx = NULL; + st_fx->cldfbBPF_fx = NULL; + } + + /* open synthesis for output SR */ + IF ((error = openCldfb_ivas_fx(&st_fx->cldfbSyn_fx, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + if ((idchan == 0 && st_fx->element_mode != IVAS_CPE_MDCT) || st_fx->element_mode == IVAS_CPE_TD) + { + /* open analysis for max. sampling rate 48kHz */ + if ((error = openCldfb_ivas(&st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } + + /* open analysis BPF for max. internal sampling rate 16kHz */ + if ((error = openCldfb_ivas(&st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } + } + else + { + st_fx->cldfbAna = NULL; + st_fx->cldfbBPF = NULL; + } + + /* open synthesis for output sampling rate */ + if ((error = openCldfb_ivas(&st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } +#endif + + st_fx->cldfbSynHB = NULL; + + st_fx->last_active_bandsToZero_bwdec = 0; + st_fx->perc_bwddec = 0; + st_fx->last_flag_filter_NB = 0; + st_fx->active_frame_cnt_bwddec = 0; + st_fx->total_frame_cnt_bwddec = 0; + set16_fx(st_fx->flag_buffer, 0, 20); + st_fx->avg_nrg_LT = 0; + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->perc_bwddec_float = 0.0f; + st_fx->avg_nrg_LT_float = 0.0f; +#endif + + /*-----------------------------------------------------------------* + * Noise gate parameters + *-----------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->ng_ener_ST = -51.0f; + + st_fx->old_Es_pred = 0; + set_f(st_fx->old_Aq_12_8 + 1, 0, M); + st_fx->old_Aq_12_8[0] = 1; +#endif +#ifdef IVAS_FLOAT_FIXED + set16_fx(st_fx->old_Aq_12_8_fx + 1, 0, M); + st_fx->old_Aq_12_8_fx[0] = ONE_IN_Q12; +#endif + st_fx->Ng_ener_ST_fx = -13056; + move16(); /*-51 IN Q8*/ + st_fx->old_Es_pred_fx = 0; + move16(); + set16_fx(st_fx->old_Aq_12_8_fx + 1, 0, M); + st_fx->old_Aq_12_8_fx[0] = 4096; + move16(); /*1 in Q12*/ + + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ + + IF(EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF((st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE)count_malloc(sizeof(SC_VBR_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); + } +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + sc_vbr_dec_init_flt(st_fx->hSC_VBR); +#endif + sc_vbr_dec_init(st_fx->hSC_VBR); + } + ELSE + { + st_fx->hSC_VBR = NULL; + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->last_ppp_mode_dec = 0; + st_fx->old_ppp_mode = 0; + st_fx->ppp_mode_dec = 0; + st_fx->last_nelp_mode_dec = 0; + st_fx->nelp_mode_dec = 0; + st_fx->prev_gain_pit_dec = 0.0f; + st_fx->prev_tilt_code_dec = 0.0f; + st_fx->vbr_hw_BWE_disable_dec = 0; + st_fx->last_vbr_hw_BWE_disable_dec = 0; +#endif + st_fx->last_ppp_mode_dec_fx = 0; + move16(); + st_fx->old_ppp_mode_fx = 0; + move16(); + st_fx->ppp_mode_dec_fx = 0; + move16(); + st_fx->last_nelp_mode_dec_fx = 0; + move16(); + st_fx->nelp_mode_dec_fx = 0; + move16(); + st_fx->prev_gain_pit_dec_fx = 0; + move16(); + st_fx->prev_tilt_code_dec_fx = 0; + move16(); + st_fx->vbr_hw_BWE_disable_dec_fx = 0; + move16(); + st_fx->last_vbr_hw_BWE_disable_dec_fx = 0; + move16(); + + /*-----------------------------------------------------------------* + * TCX core + *-----------------------------------------------------------------*/ + + /* TCX-LTP */ + IF((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + { + IF((st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE)count_malloc(sizeof(TCX_LTP_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n")); + } + } + ELSE + { + st_fx->hTcxLtpDec = NULL; + } + + /* TCX core */ + IF(idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF((st_fx->hTcxDec = (TCX_DEC_HANDLE)malloc(sizeof(TCX_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n")); + } + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + set_f(st_fx->hTcxDec->FBTCXdelayBuf_float, 0.0f, 111); + + st_fx->hTcxDec->old_synthFB = st_fx->hTcxDec->synth_history + NS2SA(st_fx->output_Fs, PH_ECU_MEM_NS); + st_fx->hTcxDec->prev_good_synth = st_fx->hTcxDec->old_synthFB + NS2SA(st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS); +#endif + set32_fx(st_fx->hTcxDec->FBTCXdelayBuf_32, 0, 111); + + st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA(st_fx->output_Fs, PH_ECU_MEM_NS); + st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA(st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS); + } + ELSE + { + st_fx->hTcxDec = NULL; + } + + /* TCX config. data structure */ + IF((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + { + IF((st_fx->hTcxCfg = (TCX_CONFIG_HANDLE)count_malloc(sizeof(TCX_config))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n")); + } + } + ELSE + { + st_fx->hTcxCfg = NULL; + } + + /* Tonal MDCT concealment data structure */ + IF((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + { + IF ((st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr)malloc(sizeof(TonalMDCTConceal_INSTANCE))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n")); + } + } + ELSE + { + st_fx->hTonalMDCTConc = NULL; + } + + + + /*-----------------------------------------------------------------* + * IGF + *-----------------------------------------------------------------*/ + + IF((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + { + IF((st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE)malloc(sizeof(IGFDEC_INSTANCE))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n")); + } + + st_fx->igf = 0; + move16(); + init_igf_dec(st_fx->hIGFDec); +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + init_igf_dec_flt(st_fx->hIGFDec); +#endif + } + ELSE + { + st_fx->hIGFDec = NULL; + } + + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ + IF(EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF ((st_fx->hPlcInfo = (T_PLCInfo_HANDLE)malloc(sizeof(T_PLCInfo))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n")); + } + } + ELSE + { + st_fx->hPlcInfo = NULL; + } + + IF(EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF ((st_fx->hTECDec = (TEC_DEC_HANDLE)malloc(sizeof(TEC_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); + } + } + ELSE + { + st_fx->hTECDec = NULL; + } + + + + /* Init Decoder */ + Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; + open_decoder_LPD_ivas_fx(st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8); + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + open_decoder_LPD_flt(st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1); +#endif + + /* PLC mode initialization */ + st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; + move16(); + + /* Init bandwidth / frame_type */ + st_fx->m_frame_type = ACTIVE_FRAME; + move16(); + st_fx->m_old_frame_type = ACTIVE_FRAME; + move16(); + + IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT))) + { + resampleCldfb_ivas_fx(st_fx->cldfbAna_fx, L_mult0( st_fx->L_frame, FRAMES_PER_SEC )); + resampleCldfb_ivas_fx(st_fx->cldfbBPF_fx, L_mult0( st_fx->L_frame, FRAMES_PER_SEC )); +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + resampleCldfb_ivas(st_fx->cldfbAna, st_fx->L_frame * FRAMES_PER_SEC); + resampleCldfb_ivas(st_fx->cldfbBPF, st_fx->L_frame * FRAMES_PER_SEC); +#endif + } + + /*-----------------------------------------------------------------* + * FD-CNG decoder + *-----------------------------------------------------------------*/ + + IF((EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || idchan == 0) && NE_16(mc_mode, MC_MODE_MCT) && NE_16(mc_mode, MC_MODE_PARAMUPMIX)) + { + /* Create FD_CNG instance */ + + IF ((error = createFdCngDec(&st_fx->hFdCngDec)) != IVAS_ERR_OK) + { + return error; + } + + /* Init FD-CNG */ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + initFdCngDec_flt(st_fx); +#endif + ivas_initFdCngDec_fx(st_fx, st_fx->cldfbSyn_fx->scale); + } + ELSE + { + st_fx->hFdCngDec = NULL; + } + + st_fx->cngTDLevel = 0; + move16(); + st_fx->cngTDLevel_e = 0; + move16(); + st_fx->lp_noise = -167772160l/*-20.f Q23*/; + st_fx->force_lpd_reset = 0; + move16(); + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. + st_fx->cngTDLevel_float = 0.f; + st_fx->lp_noise_float = -20.0f; +#endif + + /*-----------------------------------------------------------------* + * initialzie Q values + *-----------------------------------------------------------------*/ + + st_fx->Q_syn2 = 0; + move16(); + st_fx->Q_exc = 8; + st_fx->prev_Q_exc = 0; + move16(); + st_fx->Q_syn = 0; + move16(); + st_fx->prev_Q_syn = 0; + move16(); + + FOR(i = 0; i < L_Q_MEM; i++) + { + st_fx->Q_subfr[i] = 8; + move16(); + } + + st_fx->prev_Q_exc_fr = 0; + move16(); + st_fx->prev_Q_syn_fr = 0; + move16(); + + /*-----------------------------------------------------------------* + * IVAS parameters + *-----------------------------------------------------------------*/ + + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + st_fx->cng_ism_flag = 0; + + return error; + +} +#endif + + /*----------------------------------------------------------------------* * reset_preecho_dec() * diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index edc91154f..e412b00ae 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -377,10 +377,230 @@ ivas_error ivas_core_dec( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate ) ) != IVAS_ERR_OK ) +#if 1 /*Float to fix conversions*/ + Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, + Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_old_exc, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, + Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ + Q_mem_syn2 = Q_factor_arr( st->mem_syn2, M ); + Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); + Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ); + //Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); + Q_mem_syn = 0; + Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); + Q_syn = Q_factor_arr( st->syn_float, M + 1 ); + Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) ) - 1; + Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); + floatToFixed_arr16( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn, M ); + floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); + floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); + floatToFixed_arr16( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); + st->mem_deemph_fx = (Word16) floatToFixed( st->mem_deemph, Q_mem_deemph ); + st->psf_lp_noise_fx = (Word16) floatToFixed( st->psf_lp_noise, Q7 ); /*Used floatToFixed because does not give error in case of garbage value*/ + st->lp_noise = float_to_fix16( st->lp_noise_float, Q7 ); + floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + IF( st->hBPF ) + { + Q_pst_old_syn = Q_factor_arrL( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); + Q_pst_mem_deemp_err = Q_factor_L( st->hBPF->pst_mem_deemp_err ); + floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); + } + IF( st->hBWE_TD ) + { + Q_old_bwe_exc = Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = float_to_fix( st->hBWE_TD->bwe_non_lin_prev_scale, 30 ); + floatToFixed_arr32( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx_32, Q_old_bwe_exc, PIT16k_MAX * 2 ); + } + IF( st->hBWE_zero ) + { + Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); + Q_mem_syn_hf = Q_factor_arr( st->hBWE_zero->mem_syn_hf, M ); + Q_mem_hp400 = Q_factor_arr( st->hBWE_zero->mem_hp400, 4 ); + Q_delay_syn_hf = Q_factor_arr( st->hBWE_zero->delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + Q_mem_hp_interp = Q_factor_arr( st->hBWE_zero->mem_hp_interp, INTERP_3_1_MEM_LEN ); + floatToFixed_arr16( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, Q_mem_hf, ( L_FIR - 1 ) ); + floatToFixed_arr16( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, Q_mem_syn_hf, M ); + floatToFixed_arr16( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_mem_hp400, 4 ); + floatToFixed_arr16( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + floatToFixed_arr16( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); + } + IF( st->hBWE_FD ) + { + Q_old_syn_12k8_16k = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, 36 ); + floatToFixed_arr16( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_old_syn_12k8_16k, 36 ); + } + IF( st->hHQ_core ) + { + Q_prev_env = Q_factor_arrL( st->hHQ_core->prev_env, SFM_N_WB ); + Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples, 960 ); + } + IF( st->hGSCDec ) + { + st->hGSCDec->Last_frame_ener_fx = floatToFixed( st->hGSCDec->Last_frame_ener, 0 ); /*Q-0*/ + } + IF( st->hTcxDec ) + { + Q_FBTCXdelayBuf = Q_factor_arr( st->hTcxDec->FBTCXdelayBuf_float, 111 ); + Q_prev_synth_buffer = s_min( Q_prev_synth_buffer, Q_FBTCXdelayBuf ); + Q_syn_Overl = Q_factor_arr( st->hTcxDec->syn_Overl_float, 320 ); + Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 ) - 1; + } + Q_syn_Overl = s_min( Q_fer_samples, Q_syn_Overl ) - 1; + IF( st->hHQ_core ) + { + floatToFixed_arr32( st->hHQ_core->prev_env, st->hHQ_core->prev_env_fx, Q_prev_env, SFM_N_WB ); + floatToFixed_arr32( st->hHQ_core->prev_normq, st->hHQ_core->prev_normq_fx, 14, SFM_N_WB ); /*Q-14*/ + floatToFixed_arr32( st->hHQ_core->last_ni_gain, st->hHQ_core->last_ni_gain_fx, 17, BANDS_MAX ); /*Q-17*/ + floatToFixed_arr16( st->hHQ_core->last_env, st->hHQ_core->last_env_fx, 1, BANDS_MAX ); /*Q-1*/ + floatToFixed_arr32( st->hHQ_core->prev_coeff_out, st->hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); /*Q-12*/ + floatToFixed_arr16( st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, Q_syn_Overl, 960 ); + st->hHQ_core->memfilt_lb_fx = float_to_fix16( st->hHQ_core->memfilt_lb, 0 ); + st->hHQ_core->mean_prev_hb_fx = float_to_fix( st->hHQ_core->mean_prev_hb, 0 ); + st->hHQ_core->smoothmem_fx = float_to_fix16( st->hHQ_core->smoothmem, 15 ); + st->hHQ_core->mean_prev_fx = floatToFixed( st->hHQ_core->mean_prev, 0 ); + st->hHQ_core->mean_prev_nc_fx = floatToFixed( st->hHQ_core->mean_prev_nc, 0 ); + st->hHQ_core->wmold_hb_fx = float_to_fix16( st->hHQ_core->wmold_hb, 15 ); + } + IF( st->hTcxDec ) + { + floatToFixed_arr16( st->hTcxDec->FBTCXdelayBuf_float, st->hTcxDec->FBTCXdelayBuf, Q_prev_synth_buffer, 111 ); + floatToFixed_arr16( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, Q_syn_Overl, 320 ); + floatToFixed_arr16( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, Q_old_syn_Overl, L_FRAME32k / 2 ); + } + floatToFixed_arr16( st->prev_synth_buffer, st->prev_synth_buffer_fx, Q_prev_synth_buffer, 96 ); + IF( st->cldfbAna ) + { + floatToFixed_arr32( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q10, st->cldfbAna->cldfb_state_length ); + } + IF( st->cldfbSyn ) + { + floatToFixed_arr32( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q11, st->cldfbSyn->cldfb_state_length ); + } + Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, 258 ) - 1; + floatToFixed_arr16( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 258 ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_old32[i] = float_to_fix( ( st->lsf_old[i] * 2.56f ), 0 ); + st->lsfoldbfi132[i] = float_to_fix( ( st->lsfoldbfi1[i] * 2.56f ), 0 ); + st->lsfoldbfi032[i] = float_to_fix( ( st->lsfoldbfi0[i] * 2.56f ), 0 ); + st->lsf_adaptive_mean32[i] = float_to_fix( ( st->lsf_adaptive_mean[i] * 2.56f ), 0 ); + st->lsp_old_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); + st->mem_AR32[i] = float_to_fix( ( st->mem_AR[i] * 2.56f ), 0 ); + st->mem_MA32[i] = (Word32) ( ( st->mem_MA[i] * 5.12f ) ); + } + IF( st->hFdCngDec ) + { + Q_olapBufferAna = Q_factor_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, FFTLEN ) - 1; + floatToFixed_arr16( st->hFdCngDec->hFdCngCom->olapBufferAna_flt, st->hFdCngDec->hFdCngCom->olapBufferAna_fx, Q_olapBufferAna, L_FRAME32k ); + Q_olapBufferSynth = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, 640 ) - 2; + floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, Q_olapBufferSynth, 640 ); + Q_olapBufferSynth2 = Q_factor_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 640 ) - 1; + floatToFixed_arr32( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, Q_olapBufferSynth2, 640 ); + } + IF( st->cldfbBPF ) + floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); + Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; + floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); + floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); + st->enr_old_fx = (Word32) st->enr_old; + st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); + st->stab_fac_smooth_lt_fx = float_to_fix( st->stab_fac_smooth_lt, Q15 ); + st->lp_ener_fx = float_to_fix( st->lp_ener, Q6 ); + st->lp_gainc_fx = (Word16) L_min( 32767, float_to_fix( st->lp_gainc, 3 ) ); + floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); + IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) + { + IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) ) + { + Q_old_synthFB = Q_factor_arr( st->hTcxDec->old_synthFB, st->hTcxDec->old_synth_lenFB ) - 1; + floatToFixed_arr16( st->hTcxDec->old_synthFB, st->hTcxDec->old_synthFB_fx, Q_old_synthFB, st->hTcxDec->old_synth_lenFB ); + } + } +#endif + IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, Q_old_synthFB, &Q_olapBufferSynth, &Q_olapBufferSynth2) ) != IVAS_ERR_OK ) { return error; } +#if 1 /*Fixed to float function changes*/ + fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); + fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); + st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); + st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q7 ); /*psf_lp_noise_fx has Q7*/ + fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); + fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, 258 ); + st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); + st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); /*Q3*/ + FOR( i = 0; i < M; i++ ) + { + st->mem_MA[i] = (float) ( st->mem_MA32[i] / 5.12f ); + st->mem_AR[i] = (float) ( st->mem_AR32[i] / 2.56f ); + st->lsf_old[i] = (float) ( st->lsf_old32[i] / 2.56f ); + st->lsfoldbfi1[i] = (float) ( st->lsfoldbfi132[i] / 2.56f ); + st->lsfoldbfi0[i] = (float) ( st->lsfoldbfi032[i] / 2.56f ); + st->lsf_adaptive_mean[i] = (float) ( st->lsf_adaptive_mean32[i] / 2.56f ); + st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); + } + fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn, L_SYN_MEM ); + fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn, M ); + fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); + IF( st->hBPF ) + { + fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err = fixedToFloat( st->hBPF->pst_mem_deemp_err_32, Q_pst_mem_deemp_err ); + } + IF( st->hGSCDec ) + { + st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, 0 ); /*Q-0*/ + } + IF( st->hTcxDec ) + { + fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); + } + IF( st->hBWE_FD ) + fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + IF( st->hBWE_TD ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( st->hBWE_TD->bwe_non_lin_prev_scale_fx, 30 ); + fixedToFloat_arrL( st->hBWE_TD->old_bwe_exc_fx_32, st->hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); + } + IF( st->hBWE_zero ) + { + fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); + fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, Q_mem_syn_hf, M ); + fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_mem_hp400, 4 ); + fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); + fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); + } + IF( st->cldfbAna ) + fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q10, st->cldfbAna->cldfb_state_length ); + IF( st->cldfbSyn ) + fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q11, st->cldfbSyn->cldfb_state_length ); + IF( st->cldfbBPF ) + fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q11, st->cldfbBPF->cldfb_state_length ); + IF( st->hHQ_core ) + { + fixedToFloat_arrL( st->hHQ_core->prev_env_fx, st->hHQ_core->prev_env, Q_prev_env, SFM_N_WB ); + fixedToFloat_arrL( st->hHQ_core->prev_normq_fx, st->hHQ_core->prev_normq, 14, SFM_N_WB ); /*Q-14*/ + fixedToFloat_arrL( st->hHQ_core->last_ni_gain_fx, st->hHQ_core->last_ni_gain, 17, BANDS_MAX ); /*Q-17*/ + fixedToFloat_arr( st->hHQ_core->last_env_fx, st->hHQ_core->last_env, 1, BANDS_MAX ); /*Q-1*/ + fixedToFloat_arrL( st->hHQ_core->prev_coeff_out_fx, st->hHQ_core->prev_coeff_out, Q12, L_HQ_WB_BWE ); + st->hHQ_core->memfilt_lb = fixedToFloat( st->hHQ_core->memfilt_lb_fx, 0 ); + st->hHQ_core->mean_prev_hb = fixedToFloat( st->hHQ_core->mean_prev_hb_fx, 0 ); + st->hHQ_core->smoothmem = st->hHQ_core->smoothmem_fx / 32767.f; + st->hHQ_core->mean_prev = fixedToFloat( st->hHQ_core->mean_prev_fx, 0 ); + st->hHQ_core->mean_prev_nc = fixedToFloat( st->hHQ_core->mean_prev_nc_fx, 0 ); + st->hHQ_core->wmold_hb = st->hHQ_core->wmold_hb_fx / 32767.f; + fixedToFloat_arr( st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, Q_syn_Overl, 960 ); + } + IF( st->hFdCngDec ) + { + fixedToFloat_arr( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, st->hFdCngDec->hFdCngCom->olapBufferAna_flt, Q_olapBufferAna, L_FRAME32k ); + fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, Q_olapBufferSynth2, L_FRAME32k ); + fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, Q_olapBufferSynth, L_FRAME32k ); + } +#endif #else if ( ( error = core_switching_pre_dec( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate ) ) != IVAS_ERR_OK ) { @@ -411,6 +631,8 @@ ivas_error ivas_core_dec( if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) { + stereo_tcx_dec_mode_switch_reconf_To_fixed(st, 1, last_element_mode); + /* TCX decoder */ stereo_tcx_core_dec( st, frameMode[n], output[n], synth[n], pitch_buf[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hCPE == NULL ? NULL : hCPE->hStereoCng, nchan_out, st_ivas == NULL ? 0 : st_ivas->ivas_format ); } diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index b33b8453e..11ee97058 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -1374,7 +1374,7 @@ ivas_error create_cpe_dec( st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; st->is_ism_format = 0; - IF( ( error = init_decoder( st, n, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) + IF( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 62b6fbdad..2a369911f 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -372,7 +372,7 @@ ivas_error create_sce_dec( st->is_ism_format = 1; } #ifdef EVS_FLOAT - IF( ( error = init_decoder( st, 0, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) + IF( ( error = init_decoder_ivas_fx( st, 0, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) #else IF( ( error = init_decoder_fx( st, EVS_MONO ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 791c90996..8e14ab91c 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -154,7 +154,16 @@ void stereo_mdct_core_dec_fx( for ( ch = 0; ch < nChannels; ch++ ) { /* Initialization or re-configuration of Stereo TCX */ +#ifdef IVAS_FLOAT_FIXED + /* stereo_tcx_dec_mode_switch_reconf_To_fixed is for intermediatery conversions which is needed to be removed */ + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); + /*============*/ stereo_tcx_init_dec_fx( sts[ch], 0, hCPE->last_element_mode ); + /*============*/ + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); +#else + stereo_tcx_init_dec( sts[ch], 0, hCPE->last_element_mode ); +#endif sts[ch]->hTcxDec->tnsActive[0] = sts[ch]->hTcxDec->tnsActive[1] = 0; sts[ch]->enablePlcWaveadjust = 0; set_zero( signal_out_tmp[ch], L_FRAME_PLUS ); @@ -592,7 +601,43 @@ void stereo_mdct_core_dec_fx( if ( ( !bfi || !( sts[0]->core == ACELP_CORE && sts[1]->core == ACELP_CORE ) ) && !hCPE->hStereoMdct->isSBAStereoMode ) { +#ifdef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED + Word16 q_in_out = Q11; + Word16 q_x_1 = 11, q_x_0 = 11; + FOR( i = 0; i < CPE_CHANNELS; ++i ) + { + x_fx[i][0] = malloc( L_FRAME_PLUS * sizeof( Word32 ) ); + x_fx[i][1] = x_fx[i][0] + L_FRAME_PLUS / 2; + floatToFixed_arrL( x[i][0], x_fx[i][0], q_in_out, L_FRAME_PLUS / 2 ); + floatToFixed_arrL( x[i][1], x_fx[i][1], q_in_out, L_FRAME_PLUS / 2 ); + } + + FOR( i = 0; i < CPE_CHANNELS; ++i ) + { + x_0_fx[i][0] = malloc( N_MAX * sizeof( Word32 ) ); + x_0_fx[i][1] = x_0_fx[i][0] + L_FRAME48k / 2; + floatToFixed_arrL( x_0[i][0], x_0_fx[i][0], q_in_out, L_FRAME48k / 2 ); + floatToFixed_arrL( x_0[i][1], x_0_fx[i][1], q_in_out, L_FRAME48k / 2 ); + } +#endif + stereo_decoder_tcx_fx( hCPE->hStereoMdct, ms_mask, x_0_fx[1], x_fx[0], x_fx[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0, &q_x_1, &q_x_0 ); +#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED + FOR( k = 0; k < CPE_CHANNELS; ++k ) + { + fixedToFloat_arrL( x_fx[k][0], x[k][0], q_in_out, L_FRAME_PLUS / 2 ); + fixedToFloat_arrL( x_fx[k][1], x[k][1], q_in_out, L_FRAME_PLUS / 2 ); + + fixedToFloat_arrL( x_0_fx[k][0], x_0[k][0], q_in_out, L_FRAME48k / 2 ); + fixedToFloat_arrL( x_0_fx[k][1], x_0[k][1], q_in_out, L_FRAME48k / 2 ); + + free( x_fx[k][0] ); + free( x_0_fx[k][0] ); + } +#endif +#else stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 ); +#endif } { #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index f0069e9d9..5c98bad9b 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -661,7 +661,7 @@ void stereo_decoder_tcx_fx( { tmp = BASOP_Util_Divide3216_Scale( ( SMDCT_ILD_RANGE << 26 ), hStereoMdct->global_ild[k], &tmp_e ); tmp_32 = L_shr( (Word32) tmp, negate( add( 1, tmp_e ) ) ); /* nrgRatio = nrg[1]/nrg[0] */ // Q26 - nrgRatio = L_sub(tmp_32, 67108864); /* 1.0f in Q26 */ + nrgRatio = L_sub( tmp_32, 67108864 ); /* 1.0f in Q26 */ hStereoMdct->smooth_ratio_fx = L_add( Mpy_32_32( POINT_8_FIXED, hStereoMdct->smooth_ratio_fx ), Mpy_32_32( POINT_2_FIXED, nrgRatio ) ); // Q26 /* set flag to reverse dmx computation in case of right-side panning, only relevant for mono output */ @@ -680,19 +680,21 @@ void stereo_decoder_tcx_fx( test(); IF( ( GT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, ( ( EQ_16( core_r, TCX_10_CORE ) ) ? NB_DIV : 1 ) ) ) ) { - shift = norm_l(nrgRatio); - nrgRatio = L_shl(nrgRatio, shift); + shift = norm_l( nrgRatio ); + nrgRatio = L_shl( nrgRatio, shift ); v_multc_fixed( spec_r[k], nrgRatio, spec_r[k], L_frameTCX_r ); - *q_x_ch2 = *q_x_ch2 - 5 + shift; + Scale_sig32( spec_r[k], L_frameTCX_r, sub( 5, shift ) ); + *q_x_ch2 = *q_x_ch2; move16(); } ELSE IF( ( LT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, ( ( EQ_16( core_l, TCX_10_CORE ) ) ? NB_DIV : 1 ) ) ) ) { - tmp = BASOP_Util_Divide3232_Scale(ONE_IN_Q26, nrgRatio, &tmp_e); - inv_nrgRatio = L_deposit_h(tmp); + tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q26, nrgRatio, &tmp_e ); + inv_nrgRatio = L_deposit_h( tmp ); shift = 5 - tmp_e; v_multc_fixed( spec_l[k], inv_nrgRatio, spec_l[k], L_frameTCX_l ); - *q_x_ch1 = *q_x_ch1 - 5 + shift; + Scale_sig32( spec_l[k], L_frameTCX_l, sub( 5, shift ) ); + *q_x_ch1 = *q_x_ch1; move16(); } } diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index aa0fc5fb0..1906e7e90 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -205,6 +205,9 @@ static ivas_error allocate_CoreCoder_TCX_fx( st->igf = 0; move16(); init_igf_dec( st->hIGFDec ); +#if 1 // TODO: TO be removed later + init_igf_dec_flt( st->hIGFDec ); +#endif } IF ( st->hTonalMDCTConc == NULL ) @@ -246,6 +249,10 @@ static ivas_error allocate_CoreCoder( } GSC_dec_init_ivas( st->hGSCDec ); +#ifdef IVAS_FLOAT_FIXED + GSC_dec_init_ivas( st->hGSCDec ); +#endif // IVAS_FLOAT_FIXED + } if ( st->hPFstat == NULL ) @@ -256,6 +263,9 @@ static ivas_error allocate_CoreCoder( } Init_post_filter_ivas( st->hPFstat ); +#ifdef IVAS_FLOAT_FIXED + Init_post_filter(st->hPFstat); +#endif // IVAS_FLOAT_FIXED st->psf_lp_noise = 0.0f; } diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 1f2d58158..7ae1e5b82 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -35,7 +35,7 @@ #include "options.h" #include #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx1.h" #include "rom_com.h" #include "stat_dec.h" #include "wmc_auto.h" @@ -43,6 +43,7 @@ #include "stat_com.h" #include "ivas_prot.h" #include "prot_fx2.h" +#include "ivas_prot_fx.h" /*-------------------------------------------------------------* * Local prototypes @@ -137,8 +138,17 @@ void stereo_tcx_init_dec_fx( ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) ) { /*re-initialization*/ - // Need to replace this with fix call - stereo_tcx_dec_mode_switch_reconf( st, MCT_flag, last_element_mode ); + + Word16 Q_old_Aq_12_8 = 12; + stereo_tcx_dec_mode_switch_reconf_ivas_fx( st, MCT_flag, last_element_mode, + &st->hTcxDec->Q_syn_Overl_TDAC, + &st->hHQ_core->Q_fer_samples, + &st->hTcxDec->Q_syn_Overl, + &st->hTcxDec->Q_syn_Overl_TDACFB, + &st->hTcxDec->Q_syn_OverlFB, + &st->hHQ_core->Q_old_out, + &st->hHQ_core->Q_old_outLB, + &Q_old_Aq_12_8 ); } return; @@ -274,6 +284,26 @@ void stereo_tcx_core_dec( int16_t bfi; float psd[L_FRAME16k], psd_part[NPART_SHAPING]; +#ifdef IVAS_FLOAT_FIXED + Word32 L_tmp, mod; + + /*LPC*/ + Word16 lsf_fx[( NB_DIV + 1 ) * M], lsp_fx[( NB_DIV + 1 ) * M], lspmid_fx[M], lsfmid_fx[M]; + Word16 lspnew_uw_fx[NB_DIV * M], lsfnew_uw_fx[NB_DIV * M]; + Word16 Aq_fx[( NB_SUBFR16k + 1 ) * ( M + 1 )]; + Word16 q_Aq; + Word16 pit_gain_fx[NB_SUBFR16k]; + + /*Synth*/ + Word16 synth_buf_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; + Word16 *synth_fx; + Word16 synth_bufFB_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; + Word16 *synthFB_fx; + + Word32 psd_fx[L_FRAME16k]; + Word32 psd_part_fx[NPART_SHAPING]; + Word16 psd_part_e; +#endif // IVAS_FLOAT_FIXED TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -293,6 +323,7 @@ void stereo_tcx_core_dec( * Initialization or re-configuration of Stereo TCX *--------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED stereo_tcx_init_dec( st, 0, last_element_mode ); /*--------------------------------------------------------------------------------* @@ -314,23 +345,23 @@ void stereo_tcx_core_dec( st->m_decodeMode = DEC_CONCEALMENT_EXT; bfi = 1; } +#else + stereo_tcx_init_dec_fx(st, 0, last_element_mode); + + stereo_tcx_dec_mode_switch_reconf_To_fixed(st, 0, last_element_mode); + +#endif // IVAS_FLOAT_FIXED /* for bass postfilter */ if ( st->tcxonly ) { st->p_bpf_noise_buf_float = NULL; -#ifdef IVAS_FLOAT_FIXED - st->p_bpf_noise_buf_32 = NULL; -#endif } else { - st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; -#ifdef IVAS_FLOAT_FIXED - st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; -#endif - set_s( pitch, L_SUBFR, st->nb_subfr ); - set_zero( pit_gain, st->nb_subfr ); + st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; + set_s(pitch, L_SUBFR, st->nb_subfr); + set_zero(pit_gain, st->nb_subfr); } /* Initialize pointers */ @@ -341,21 +372,84 @@ void stereo_tcx_core_dec( set_zero( synth, L_FRAME_PLUS + M ); set_zero( synthFB, L_FRAME_PLUS + M ); +#ifdef IVAS_FLOAT_FIXED + + for ( int p = 0; p < hTcxDec->old_synth_len; p++ ) + { + hTcxDec->old_synth[p] = (Word16) ( hTcxDec->old_synth_float[p] ); + } + for ( int p = 0; p < hTcxDec->old_synth_lenFB; p++ ) + { + hTcxDec->old_synthFB_fx[p] = (Word16) ( hTcxDec->old_synthFB[p] + 0.5f ); + } + + /*=================================*/ + /*--------------------------------------------------------------------------------* + * Initializations + *--------------------------------------------------------------------------------*/ + + //total_nbbits = (Word16) ( st->total_brate / FRAMES_PER_SEC ); + iDiv_and_mod_32( st->total_brate, FRAMES_PER_SEC, &L_tmp, &mod, 0 ); + total_nbbits = (Word16) L_tmp; + bitsRead = 0; + LSF_Q_prediction = -1; /* to avoid compilation warnings */ + + IF ( frameMode == FRAMEMODE_NORMAL ) + { + st->m_decodeMode = DEC_NO_FRAM_LOSS; + bfi = 0; + } + + IF ( frameMode == FRAMEMODE_MISSING ) + { + st->m_decodeMode = DEC_CONCEALMENT_EXT; + bfi = 1; + } + /* for bass postfilter */ + IF(st->tcxonly) + { + st->p_bpf_noise_buf_32 = NULL; + } + ELSE + { + st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; + st->p_bpf_noise_buf = st->bpf_noise_buf; + set_s(pitch, L_SUBFR, st->nb_subfr); + set16_fx(pit_gain_fx, 0, st->nb_subfr); + } + + /* Initialize pointers */ + synth_fx = synth_buf_fx + hTcxDec->old_synth_len; + synthFB_fx = synth_bufFB_fx + hTcxDec->old_synth_lenFB; + Copy( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len ); + Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); + set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); + set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); /*--------------------------------------------------------------------------------* * BITSTREAM DECODING *--------------------------------------------------------------------------------*/ - if ( !bfi ) + IF ( !bfi ) { st->second_last_core = st->last_core; -#ifdef IVAS_FLOAT_FIXED - dec_prm_tcx_ivas_fx(st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead); + dec_prm_tcx_ivas_fx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); + + stereo_tcx_dec_mode_switch_reconf_To_fixed(st, 0, last_element_mode); + } #else + /*--------------------------------------------------------------------------------* + * BITSTREAM DECODING + *--------------------------------------------------------------------------------*/ + + if ( !bfi ) + { + st->second_last_core = st->last_core; + dec_prm_tcx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); -#endif // IVAS_FLOAT_FIXED } +#endif // IVAS_FLOAT_FIXED else { if ( st->nbLostCmpt > 1 ) @@ -365,109 +459,211 @@ void stereo_tcx_core_dec( /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ +#ifdef IVAS_FLOAT_FIXED_ + st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + st->hTcxDec->tcxltp_second_last_pitch = floatToFixed( st->hTcxDec->tcxltp_second_last_pitch_float, 16 ); + st->hTcxDec->tcxltp_third_last_pitch = floatToFixed( st->hTcxDec->tcxltp_third_last_pitch_float, 16 ); + st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); + floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); + floatToFixed_arr( st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2 ); + st->last_good_fx = st->last_good; + floatToFixed_arr( st->hTonalMDCTConc->pTCI_float->phaseDiff_float, st->hTonalMDCTConc->pTCI_fix->phaseDiff, Q12, MAX_NUMBER_OF_IDX ); + floatToFixed_arr( st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float, st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted, Q13, MAX_NUMBER_OF_IDX * GROUP_LENGTH ); + st->hTonalMDCTConc->pTCI_fix->numIndexes = st->hTonalMDCTConc->pTCI_float->numIndexes; + for ( int p = 0; p < MAX_NUMBER_OF_IDX; p++ ) + { + st->hTonalMDCTConc->pTCI_fix->indexOfTonalPeak[p] = st->hTonalMDCTConc->pTCI_float->indexOfTonalPeak[p]; + st->hTonalMDCTConc->pTCI_fix->lowerIndex[p] = st->hTonalMDCTConc->pTCI_float->lowerIndex[p]; + st->hTonalMDCTConc->pTCI_fix->upperIndex[p] = st->hTonalMDCTConc->pTCI_float->upperIndex[p]; + } + floatToFixed_arr(st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, Q2,st->hTonalMDCTConc->nSamples ); + /*=============================================*/ + st->core = GetPLCModeDecision( st ); + /*=============================================*/ + fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); + fixedToFloat_arr( st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2 ); + st->hTonalMDCTConc->pTCI_float->numIndexes = st->hTonalMDCTConc->pTCI_fix->numIndexes; + fixedToFloat_arr( st->hTonalMDCTConc->pTCI_fix->phaseDiff, st->hTonalMDCTConc->pTCI_float->phaseDiff_float, Q12, MAX_NUMBER_OF_IDX ); + fixedToFloat_arr( st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted, st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float, Q13, MAX_NUMBER_OF_IDX * GROUP_LENGTH ); + for ( int p = 0; p < MAX_NUMBER_OF_IDX; p++ ) + { + st->hTonalMDCTConc->pTCI_float->indexOfTonalPeak[p] = st->hTonalMDCTConc->pTCI_fix->indexOfTonalPeak[p]; + st->hTonalMDCTConc->pTCI_float->lowerIndex[p] = st->hTonalMDCTConc->pTCI_fix->lowerIndex[p]; + st->hTonalMDCTConc->pTCI_float->upperIndex[p] = st->hTonalMDCTConc->pTCI_fix->upperIndex[p]; + } +#else st->core = GetPLCModeDecision_flt( st ); +#endif // IVAS_FLOAT_FIXED + } + +#ifdef IVAS_FLOAT_FIXED + float scale = 1.f; + if ( st->lpcQuantization && st->prev_lpcQuantization ) + { + st->scale = 1.f; + scale = 1.f; + } + else if ( st->lpcQuantization && st->prev_lpcQuantization == 0 ) + { + scale = 1.f; + } + else if ( !st->lpcQuantization ) + { + st->scale = (float) st->sr_core / INT_FS_12k8; + scale = (float) st->sr_core / INT_FS_12k8; + } + for ( int p = 0; p < M; p++ ) + { + st->mem_MA_fx[p] = (Word16) ( st->mem_MA[p] * 2.56 ); + st->mem_AR_fx[p] = (Word16) ( st->mem_AR[p] * 2.56 ); + st->lsf_cng[p] = (Word16) ( st->lsf_cng_float[p] * 2.56 / st->scale ); + st->old_lsf_q_cng[p] = (Word16) ( st->old_lsf_q_cng_float[p] * 2.56 / st->scale ); + st->lsf_old_fx[p] = (Word16) ( st->lsf_old[p] * 2.56 / st->scale ); + st->lsp_old_fx[p] = (Word16) ( st->lsp_old[p] * MAX_16 ); + } + if ( st->gamma_float == GAMMA1_FLT ) + { + st->inv_gamma = GAMMA1_INV; + } + else if ( st->gamma_float == GAMMA16k_FLT ) + { + st->inv_gamma = GAMMA16k_INV; + } + + floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); + for ( int p = 0; p < M; p++ ) + { + st->lsfold_uw[p] = (Word16) ( st->lsfold_uw_float[p] * 2.56 / st->scale ); + } + for ( i = 0; i < M; i++ ) + { + st->lsf_adaptive_mean_fx[i] = (Word16) ( st->lsf_adaptive_mean[i] * ( 2.56f / st->scale ) ); } + st->stab_fac_fx = (Word16) floatToFixed( st->stab_fac, Q15 ); + /*=============================================*/ + for (int p = 0; p < 2 * NB_SUBFR16k + 2; p++) + { + st->old_pitch_buf_fx[p] = (Word32)(st->old_pitch_buf[p] * ONE_IN_Q16); + } + for (int p = 0; p < st->L_frame; p++) + { + st->hTcxDec->old_excFB_fx[p] = (Word16)(st->hTcxDec->old_excFB[p] * (1u << st->Q_exc)); + } + st->prev_Q_syn = st->Q_syn; + st->last_good_fx = st->last_good; + st->old_fpitchFB = (Word32)(st->old_fpitchFB_float * ONE_IN_Q16); + st->old_fpitch = (Word32)(st->old_fpitch_float * ONE_IN_Q16); + st->stab_fac_fx = (Word16)(st->stab_fac * MAX_16); + st->lp_gainp_fx = (Word16)floatToFixed(st->lp_gainp, Q14); + + floatToFixed_arr(lsp, lsp_fx, Q15, 2 * M); + floatToFixed_arr(st->old_lsp_q_cng_float, st->old_lsp_q_cng, Q15, M); + floatToFixed_arr(st->lsp_q_cng_float, st->lsp_q_cng, Q15, M); + floatToFixed_arr( synth, synth_fx, 0, st->L_frame ); + floatToFixed_arr( synthFB, synthFB_fx, 0, hTcxDec->L_frameTCX ); + /*====================================*/ /*--------------------------------------------------------------------------------* * LPC PARAMETERS *--------------------------------------------------------------------------------*/ st->acelp_cfg.midLpc = 0; - if ( !bfi ) + IF( !bfi ) { - if ( hTcxDec->enableTcxLpc ) + IF( hTcxDec->enableTcxLpc ) { - int16_t tcx_lpc_cdk; + Word16 tcx_lpc_cdk; - if ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) + IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - tcx_lpc_cdk = tcxlpc_get_cdk_float( GENERIC ); + tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); } - else + ELSE { - tcx_lpc_cdk = tcxlpc_get_cdk_float( st->coder_type ); + tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); } - mvr2r( st->lsf_old, &lsf[0], M ); - mvr2r( st->lsp_old, &lsp[0], M ); + Copy( st->lsf_old_fx, &lsf_fx[0], M ); + Copy( st->lsp_old_fx, &lsp_fx[0], M ); - D_lsf_tcxlpc_ivas( param_lpc, &lsf[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA ); + D_lsf_tcxlpc( param_lpc, &lsf_fx[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx ); - lsf2lsp( &lsf[M], &lsp[M], M, st->sr_core ); + lsf2lsp_fx( &lsf_fx[M], &lsp_fx[M], M, st->sr_core ); - lsf_update_memory_float( st->narrowBand, &lsf[M], st->mem_MA, st->mem_MA ); - mvr2r( &lsf[M], st->mem_AR, M ); + lsf_update_memory( st->narrowBand, &lsf_fx[M], st->mem_MA_fx, st->mem_MA_fx, M ); + Copy( &lsf_fx[M], st->mem_AR_fx, M ); hTcxDec->envWeighted = 1; - E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma_float); + E_LPC_lsp_unweight( &lsp_fx[M], lspnew_uw_fx, lsfnew_uw_fx, st->inv_gamma /*1.0f / st->gamma_float*/, M ); } - else + ELSE { - if ( hTcxDec->envWeighted ) + IF( hTcxDec->envWeighted ) { - mvr2r( st->lspold_uw_float, st->lsp_old, M ); - mvr2r( st->lsfold_uw_float, st->lsf_old, M ); + Copy( st->lspold_uw, st->lsp_old_fx, M ); + Copy( st->lsfold_uw, st->lsf_old_fx, M ); hTcxDec->envWeighted = 0; } - lpc_unquantize_flt( st, lsf, lsp, param_lpc, lspmid, lsfmid, AUDIO, &LSF_Q_prediction ); + lpc_unquantize( st, lsf_fx, lsp_fx, M, param_lpc, lspmid_fx, lsfmid_fx, AUDIO, &LSF_Q_prediction ); + // st->prev_lpcQuantization = st->lpcQuantization; - for ( k = 0; k < st->numlpc; ++k ) + FOR( k = 0; k < st->numlpc; ++k ) { - mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M ); - mvr2r( &lsf[( k + 1 ) * M], &lsfnew_uw[k * M], M ); + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); + Copy( &lsf_fx[( k + 1 ) * M], &lsfnew_uw_fx[k * M], M ); } } /* PLC: [LPD: LPC concealment] built the moving average for the LPC concealment */ - for ( k = 0; k < st->numlpc; k++ ) + FOR( k = 0; k < st->numlpc; k++ ) { - for ( i = 0; i < M; i++ ) + FOR( i = 0; i < M; i++ ) { - st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsfnew_uw[k * M + i] ) / 3; - st->lsfoldbfi1[i] = st->lsfoldbfi0[i]; - st->lsfoldbfi0[i] = lsfnew_uw[k * M + i]; + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[k * M + i], ONE_BY_THREE_Q15 ) ); + st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; + st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[k * M + i]; } } } - else + ELSE { /* PLC: [LPD: LPC concealment] Conceal the LPC from the lost frame */ - const float *lsfBase; /* base for differential lsf coding */ + const Word16 *lsfBase; /* base for differential lsf coding */ - if ( st->tcxonly == 0 || st->core < TCX_10_CORE ) + IF( st->tcxonly == 0 || st->core < TCX_10_CORE ) { st->numlpc = 1; } - else + ELSE { st->numlpc = 2; } - if ( st->nbLostCmpt == 1 ) + IF( st->nbLostCmpt == 1 ) { - mvr2r( st->lsf_old, st->old_lsf_q_cng_float, M ); - mvr2r( st->lsp_old, st->old_lsp_q_cng_float, M ); + Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); + Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); } - lsfBase = PlcGetlsfBase_flt( st->lpcQuantization, st->narrowBand, st->sr_core ); + lsfBase = PlcGetLsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); - dlpc_bfi_flt( st->L_frame, lsfnew_uw, st->lsfold_uw_float, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &( st->stab_fac ), st->lsf_adaptive_mean, st->numlpc, st->lsf_cng_float, st->plcBackgroundNoiseUpdated, st->lsf_q_cng_float, st->old_lsf_q_cng_float, lsfBase ); + dlpc_bfi( st->L_frame, lsfnew_uw_fx, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA_fx, st->mem_AR_fx, &( st->stab_fac_fx ), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase, (Word8) st->tcxonly ); hTcxDec->envWeighted = 0; - mvr2r( st->lspold_uw_float, lsp, M ); - mvr2r( st->lsfold_uw_float, lsf, M ); + Copy( st->lspold_uw, lsp_fx, M ); + Copy( st->lsfold_uw, lsf_fx, M ); - for ( k = 0; k < st->numlpc; k++ ) + FOR( k = 0; k < st->numlpc; k++ ) { - mvr2r( &lsfnew_uw[k * M], &lsf[( k + 1 ) * M], M ); + Copy( &lsfnew_uw_fx[k * M], &lsf_fx[( k + 1 ) * M], M ); - lsf2lsp( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core ); - lsf2lsp( st->lsf_q_cng_float, st->lsp_q_cng_float, M, st->sr_core ); + lsf2lsp_fx( &lsf_fx[( k + 1 ) * M], &lsp_fx[( k + 1 ) * M], M, st->sr_core ); + lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); - mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M ); + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); } } @@ -475,18 +671,18 @@ void stereo_tcx_core_dec( * Rate switching *---------------------------------------------------------------*/ - if ( st->rate_switching_reset ) + IF( st->rate_switching_reset ) { - mvr2r( &( lsf[M] ), &( lsf[0] ), M ); - mvr2r( &( lsp[M] ), &( lsp[0] ), M ); - mvr2r( &( lsf[M] ), st->lsf_old, M ); - mvr2r( &( lsp[M] ), st->lsp_old, M ); - mvr2r( &( lsf[M] ), lsfmid, M ); - mvr2r( &( lsp[M] ), lspmid, M ); - lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M ); + Copy( &( lsf_fx[M] ), &( lsf_fx[0] ), M ); + Copy( &( lsp_fx[M] ), &( lsp_fx[0] ), M ); + Copy( &( lsf_fx[M] ), st->lsf_old_fx, M ); + Copy( &( lsp_fx[M] ), st->lsp_old_fx, M ); + Copy( &( lsf_fx[M] ), lsfmid_fx, M ); + Copy( &( lsp_fx[M] ), lspmid_fx, M ); + E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); } - if ( st->enablePlcWaveadjust && bfi ) + IF( st->enablePlcWaveadjust && bfi ) { st->hPlcInfo->nbLostCmpt++; } @@ -495,34 +691,43 @@ void stereo_tcx_core_dec( * TD-TCX concealment *--------------------------------------------------------------------------------*/ - if ( st->core == ACELP_CORE ) + IF( EQ_16( st->core, ACELP_CORE ) ) { assert( bfi ); /*must only happen in BFI*/ - if ( !st->tcxonly ) + IF( !st->tcxonly ) { /*LPC interpolation*/ - int_lsp( st->L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 ); - int_lsp( st->L_frame, st->old_lsp_q_cng_float, st->lsp_q_cng_float, st->Aq_cng_float, M, interpol_frac_12k8, 0 ); + int_lsp_fx( st->L_frame, &lsp_fx[0], &lsp_fx[M], Aq_fx, M, interpol_frac_fx, 0 ); + int_lsp_fx( st->L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_fx, 0 ); } /* PLC: [TCX: TD PLC] */ - con_tcx_flt( st, &synthFB[0], -1.f, NULL, 0, NULL ); - lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); + con_tcx( st, &synthFB_fx[0] /*, -1.f, NULL, 0, NULL */ ); + IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) + { + Copy_Scale_sig( &synthFB_fx[-( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )], &synthFB_fx[-( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )], st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M, -( st->Q_exc - 1 ) ); + } + ELSE + { + Copy_Scale_sig( &synthFB_fx[-( st->hTcxDec->L_frameTCX )], &synthFB_fx[-( st->hTcxDec->L_frameTCX )], st->hTcxDec->L_frameTCX, -( st->Q_exc - 1 ) ); + } + + lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); st->con_tcx = 1; - set_f( &st->mem_pitch_gain_float[2], st->lp_gainp, st->nb_subfr ); + set16_fx( &st->mem_pitch_gain[2], st->lp_gainp_fx, st->nb_subfr ); /* LPC for ACELP/BWE */ - if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + IF( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) { - mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) ); + Copy( Aq_fx, st->mem_Aq, st->nb_subfr * ( M + 1 ) ); } /* PLC: [TCX: Tonal Concealment] */ /* Signal that this frame is not TCX */ - if ( st->hTonalMDCTConc != NULL ) + IF( st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_UpdateState_ivas( st->hTonalMDCTConc, 0, 0, 0, 0 ); + TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 ); } } @@ -532,209 +737,900 @@ void stereo_tcx_core_dec( /* Set pointer to parameters */ prm = param; - if ( st->core == TCX_20_CORE ) + IF( EQ_16( st->core, TCX_20_CORE ) ) { + /* Stability Factor */ - if ( !bfi ) + IF( !bfi ) { - st->stab_fac = lsf_stab( &lsf[M], &lsf[0], 0, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( &lsf_fx[M], &lsf_fx[0], 0, st->L_frame ); } + st->prev_lpcQuantization = st->lpcQuantization; - if ( hTcxDec->enableTcxLpc ) + IF( hTcxDec->enableTcxLpc ) { /* Convert quantized lsp to A */ - lsp2a_stab( &lsp[M], Aq, M ); + E_LPC_f_lsp_a_conversion( &lsp_fx[M], Aq_fx, M ); } - else + ELSE { - if ( !st->tcxonly ) + IF( !st->tcxonly ) { - if ( !bfi && st->prev_bfi && !( st->safety_net ) && st->rate_switching_reset ) + IF( !bfi && st->prev_bfi && !( st->safety_net ) && st->rate_switching_reset ) { /* diffuse LPC power on rate switching*/ - RecLpcSpecPowDiffuseLc_flt( &lsp[M], &lsp[0], &lsf[M], st, 0 ); - int_lsp( st->L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 ); - mvr2r( &lsf[M], lsfnew_uw, M ); + RecLpcSpecPowDiffuseLc( &lsp_fx[M], &lsp_fx[0], &lsf_fx[M], st, 0 ); + int_lsp_fx( st->L_frame, &lsp_fx[0], &lsp_fx[M], Aq_fx, M, interpol_frac_fx, 0 ); + Copy( &lsf_fx[M], lsfnew_uw_fx, M ); } - else + ELSE { /* LPC Interpolation for TCX */ - E_LPC_int_lpc_tcx_float( &lsp[0], &lsp[M], Aq ); + E_LPC_int_lpc_tcx( &lsp_fx[0], &lsp_fx[M], Aq_fx ); } } - else + ELSE { - lsp2a_stab( &lsp[M], Aq, M ); + E_LPC_f_lsp_a_conversion( &lsp_fx[M], Aq_fx, M ); } } - - if ( !bfi && hTcxDec->tcx_lpc_shaped_ari ) + IF( !bfi && hTcxDec->tcx_lpc_shaped_ari ) { basop_E_LPC_f_lsp_a_conversion( lspind, Aind, M ); } /* TCX decoder */ -#ifdef IVAS_FLOAT_FIXED - decoder_tcx_fx( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, sba_dirac_stereo_flag ); -#else - decoder_tcx_flt( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, sba_dirac_stereo_flag ); -#endif + /* TODO: move the internal conversions outside */ + decoder_tcx_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], bfi, 0, sba_dirac_stereo_flag ); } /*--------------------------------------------------------------------------------* * TCX10 *--------------------------------------------------------------------------------*/ - if ( st->core == TCX_10_CORE ) + IF( EQ_16( st->core, TCX_10_CORE ) ) { prm = NULL; /* just to avoid MSVC warnings */ - for ( k = 0; k < 2; k++ ) + FOR( k = 0; k < 2; k++ ) { /* Set pointer to parameters */ prm = param + ( k * DEC_NPRM_DIV ); /* Stability Factor */ - if ( !bfi ) + IF( !bfi ) { - st->stab_fac = lsf_stab( &lsf[( k + 1 ) * M], &lsf[k * M], 0, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( &lsf_fx[( k + 1 ) * M], &lsf_fx[k * M], 0, st->L_frame ); } - lsp2a_stab( &lsp[( k + 1 ) * M], Aq, M ); + E_LPC_f_lsp_a_conversion( &lsp_fx[( k + 1 ) * M], Aq_fx, M ); { - IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); + IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); /*float call to be removed*/ + IGFDecRestoreTCX10SubFrameData_fx( st->hIGFDec, k ); } /* TCX decoder */ -#ifdef IVAS_FLOAT_FIXED - decoder_tcx_fx( st, prm, Aq, Aind, &synth[k * st->L_frame / 2], &synthFB[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag ); -#else - decoder_tcx_flt( st, prm, Aq, Aind, &synth[k * st->L_frame / 2], &synthFB[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag ); -#endif + decoder_tcx_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag ); } } - /*--------------------------------------------------------------------------------* - * Post-processing - *--------------------------------------------------------------------------------*/ - - if ( st->core == TCX_10_CORE || st->core == TCX_20_CORE ) + /*============================================*/ + if( EQ_16( st->core, ACELP_CORE ) ) { - if ( st->enablePlcWaveadjust || /* bfi */ - ( st->last_total_brate >= HQ_48k && /* recovery */ - st->last_codec_mode == MODE2 ) ) + if ( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { - /* waveform adjustment */ - concealment_signal_tuning( st, bfi, synthFB, st->last_core_bfi ); - - if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL ) + for ( int p = 0; p < st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M; p++ ) { - lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); - - if ( !bfi && st->prev_bfi ) - { - st->hPlcInfo->Pitch = 0; - } + synthFB[p - ( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )] = (float) synthFB_fx[p - ( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )]; } } - - if ( !bfi && st->hTonalMDCTConc != NULL ) - { - TonalMDCTConceal_SaveTimeSignal_ivas( st->hTonalMDCTConc, synthFB, hTcxDec->L_frameTCX ); - } - - decoder_tcx_post_flt( st, synth, synthFB, Aq, bfi, 0 ); - - if ( st->core == TCX_20_CORE ) + else { - /* LPC Interpolation for BWE/post-processing */ - if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + for ( int p = 0; p < st->hTcxDec->L_frameTCX; p++ ) { - int_lsp( st->L_frame, st->lspold_uw_float, lspnew_uw, Aq, M, interpol_frac_12k8, 0 ); - mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) ); + synthFB[p - ( st->hTcxDec->L_frameTCX )] = (float) synthFB_fx[p - ( st->hTcxDec->L_frameTCX )]; } } - } - - /* PLC: [Common: Classification] */ - /* the classifier buffer is always updated if the sr is at - 16000 or below - the classification itself is just performed if(!st->tcxonly ) */ - if ( st->sr_core <= INT_FS_16k ) - { - if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || ( st->tcxonly && st->bfi ) ) + for ( int p = 0; p < M + 1; p++ ) { - float pitch_C[4]; - - /* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */ - set_f( pitch_C, floorf( st->old_fpitch_float + 0.5f ), 4 ); - - /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ - FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : st->core_ext_mode, MODE2, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified_float : -1.0f, st->narrowBand, CLASSIFIER_TCX, bfi, st->preemph_fac_float, st->tcxonly, st->last_core_brate, -1 ); + st->old_Aq_12_8[p] = (float) st->old_Aq_12_8_fx[p] / ( 1u << ( 15 - ( norm_s( st->old_Aq_12_8_fx[0] - 1 ) ) ) ); } - } - - /*--------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------*/ - - if ( bfi && st->last_core != ACELP_CORE ) - { - /* Update FEC_scale_syn parameters */ -#ifdef IVAS_FLOAT_FIXED - Word32 synth_fx[L_FRAME48k], enr_old_fx; - Word16 q_synth = 0, old_fpitch_fx; - for ( int p = 0; p < st->L_frame; p++ ) + for ( int p = 0; p < M; p++ ) { - synth_fx[p] = (Word32) ( synth[p] * ( 1u << q_synth ) ); + st->mem_syn2[p] = (float) st->mem_syn2_fx[p]; } - old_fpitch_fx = (Word16) ( st->old_fpitch_float + 0.5f ); - - IF ( hTcxLtpDec->tcxltp_gain_float == 0 ) + for ( int p = 0; p < M + 1; p++ ) { - fer_energy_fx( st->L_frame, UNVOICED, synth_fx, q_synth, shr( st->L_frame, 1 ), &enr_old_fx, st->L_frame ); + st->syn_float[p] = (float) st->syn[p] / pow( 2, st->Q_syn ); } - ELSE + for ( int p = 0; p < L_EXC_MEM_DEC; p++ ) + { + st->old_exc[p] = (float) st->old_exc_fx[p] / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) + { + st->old_pitch_buf[p] = (float) st->old_pitch_buf_fx[p] / ONE_IN_Q16; + } + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->syn_OverlFB_float[p] = (float) st->hTcxDec->syn_OverlFB[p] / pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_float[p] = (float) st->hTcxDec->syn_Overl[p] / pow( 2, st->Q_syn ); + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * pow( 2, st->Q_syn ); + } + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); + } + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < 60; p++ ) + { + st->mem_syn_r_float[p] = (float) ( st->mem_syn_r[p] ); + } + st->preemph_fac_float = (float) st->preemph_fac / MAX_16; + st->lp_gainc = (float) st->Mode2_lp_gainc / ONE_IN_Q16; + st->lp_gainp = (float) st->Mode2_lp_gainp / ONE_IN_Q29; + st->cummulative_damping_float = (float) st->cummulative_damping / MAX_16; + st->old_enr_LP_float = (float) st->old_enr_LP / ONE_IN_Q3; + st->bfi_pitch = (float) st->bfi_pitch_fx / ONE_IN_Q6; + + fixedToFloat_arr( synth_fx, synth, 0, hTcxDec->L_frameTCX ); + fixedToFloat_arr( &st->mem_pitch_gain[2], &st->mem_pitch_gain_float[2], Q14, st->nb_subfr ); + if ( !st->tcxonly ) + { + for ( int p = 0; p < shr( st->L_frame, 6 ); p++ ) + { + q_Aq = 15 - ( norm_s( Aq_fx[p * ( M + 1 )] - 1 ) ); + fixedToFloat_arr( Aq_fx + p * ( M + 1 ), Aq + p * ( M + 1 ), q_Aq, ( M + 1 ) ); + q_Aq = 15 - ( norm_s( st->Aq_cng[p * ( M + 1 )] - 1 ) ); + fixedToFloat_arr( st->Aq_cng + p * ( M + 1 ), st->Aq_cng_float + p * ( M + 1 ), q_Aq, ( M + 1 ) ); + } + } + IF( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + { + for ( int p = 0; p < st->nb_subfr; p++ ) + { + q_Aq = 15 - ( norm_s( st->mem_Aq[p * ( M + 1 )] - 1 ) ); + fixedToFloat_arr( st->mem_Aq + p * ( M + 1 ), st->mem_Aq_float + p * ( M + 1 ), q_Aq, ( M + 1 ) ); + } + } + } + /*======================================*/ + + if ( st->rate_switching_reset ) + { + q_Aq = 15 - ( norm_s( st->old_Aq_12_8_fx[0] - 1 ) ); + fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, q_Aq, M + 1 ); + st->scale = scale; + } + + for ( int p = 0; p < M; p++ ) + { + st->lsf_old[p] = (float) st->lsf_old_fx[p] / ( 2.56f / st->scale ); + st->lsp_old[p] = (float) st->lsp_old_fx[p] / ONE_IN_Q15; + } + + for ( int p = 0; p < M * ( 1 + st->numlpc ); p++ ) + { + lsf[p] = (float) lsf_fx[p] / ( 2.56f / scale ); + lsp[p] = (float) lsp_fx[p] / ONE_IN_Q15; + } + if ( st->lpcQuantization ) + { + st->safety_net = st->safety_net_fx; + st->mid_lsf_int = st->mid_lsf_int_fx; + } + if ( st->lpcQuantization && st->acelp_cfg.midLpc && st->core == ACELP_CORE && st->rate_switching_reset == 0 || st->rate_switching_reset ) + { + for ( int p = 0; p < M; p++ ) + { + lsfmid[p] = (float) lsfmid_fx[p] / 2.56f; + lspmid[p] = (float) lspmid_fx[p] / ONE_IN_Q15; + } + } + + for ( int p = 0; p < M; p++ ) + { + st->mem_MA[p] = (float) st->mem_MA_fx[p] / 2.56f; + st->mem_AR[p] = (float) st->mem_AR_fx[p] / 2.56f; + st->lsf_adaptive_mean[p] = (float) st->lsf_adaptive_mean_fx[p] / ( 2.56f / st->scale ); + st->lsfoldbfi1[p] = (float) st->lsfoldbfi1_fx[p] / ( 2.56f / st->scale ); + st->lsfoldbfi0[p] = (float) st->lsfoldbfi0_fx[p] / ( 2.56f / st->scale ); + st->lsf_q_cng_float[p] = (float) st->lsf_q_cng[p] / ( 2.56f / st->scale ); + st->old_lsf_q_cng_float[p] = (float) st->old_lsf_q_cng[p] / ( 2.56f / st->scale ); + } + + st->stab_fac = fixedToFloat( st->stab_fac_fx, Q15 ); + for ( int p = 0; p < M * st->numlpc; p++ ) + { + lsfnew_uw[p] = (float) lsfnew_uw_fx[p] / ( 2.56f / st->scale ); + } + fixedToFloat_arr( lspnew_uw_fx, lspnew_uw, Q15, st->numlpc * M ); + fixedToFloat_arr( st->lsp_q_cng, st->lsp_q_cng_float, Q15, M ); + + q_Aq = 15 - ( norm_s( Aq_fx[0] - 1 ) ); + fixedToFloat_arr( Aq_fx, Aq, q_Aq, M + 1 ); + fixedToFloat_arr( synth_fx, synth, 0, st->L_frame ); + fixedToFloat_arr( synthFB_fx, synthFB, 0, hTcxDec->L_frameTCX ); + +#else + /*--------------------------------------------------------------------------------* + * LPC PARAMETERS + *--------------------------------------------------------------------------------*/ + + st->acelp_cfg.midLpc = 0; + + if ( !bfi ) + { + if ( hTcxDec->enableTcxLpc ) + { + int16_t tcx_lpc_cdk; + if ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) + { + tcx_lpc_cdk = tcxlpc_get_cdk_float( GENERIC ); + } + else + { + tcx_lpc_cdk = tcxlpc_get_cdk_float( st->coder_type ); + } + + mvr2r( st->lsf_old, &lsf[0], M ); + mvr2r( st->lsp_old, &lsp[0], M ); + + D_lsf_tcxlpc_ivas( param_lpc, &lsf[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA ); + + lsf2lsp( &lsf[M], &lsp[M], M, st->sr_core ); + + lsf_update_memory_float( st->narrowBand, &lsf[M], st->mem_MA, st->mem_MA ); + mvr2r( &lsf[M], st->mem_AR, M ); + hTcxDec->envWeighted = 1; + + E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma_float ); + } + else + { + if ( hTcxDec->envWeighted ) + { + mvr2r( st->lspold_uw_float, st->lsp_old, M ); + mvr2r( st->lsfold_uw_float, st->lsf_old, M ); + hTcxDec->envWeighted = 0; + } + + lpc_unquantize_flt( st, lsf, lsp, param_lpc, lspmid, lsfmid, AUDIO, &LSF_Q_prediction ); + + for ( k = 0; k < st->numlpc; ++k ) + { + mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M ); + mvr2r( &lsf[( k + 1 ) * M], &lsfnew_uw[k * M], M ); + } + } + + /* PLC: [LPD: LPC concealment] built the moving average for the LPC concealment */ + for ( k = 0; k < st->numlpc; k++ ) + { + for ( i = 0; i < M; i++ ) + { + st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsfnew_uw[k * M + i] ) / 3; + st->lsfoldbfi1[i] = st->lsfoldbfi0[i]; + st->lsfoldbfi0[i] = lsfnew_uw[k * M + i]; + } + } + } + else + { + /* PLC: [LPD: LPC concealment] Conceal the LPC from the lost frame */ + const float *lsfBase; /* base for differential lsf coding */ + + if ( st->tcxonly == 0 || st->core < TCX_10_CORE ) + { + st->numlpc = 1; + } + else + { + st->numlpc = 2; + } + + if ( st->nbLostCmpt == 1 ) + { + mvr2r( st->lsf_old, st->old_lsf_q_cng_float, M ); + mvr2r( st->lsp_old, st->old_lsp_q_cng_float, M ); + } + + lsfBase = PlcGetlsfBase_flt( st->lpcQuantization, st->narrowBand, st->sr_core ); + + dlpc_bfi_flt( st->L_frame, lsfnew_uw, st->lsfold_uw_float, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &( st->stab_fac ), st->lsf_adaptive_mean, st->numlpc, st->lsf_cng_float, st->plcBackgroundNoiseUpdated, st->lsf_q_cng_float, st->old_lsf_q_cng_float, lsfBase ); + + hTcxDec->envWeighted = 0; + + mvr2r( st->lspold_uw_float, lsp, M ); + mvr2r( st->lsfold_uw_float, lsf, M ); + + for ( k = 0; k < st->numlpc; k++ ) + { + mvr2r( &lsfnew_uw[k * M], &lsf[( k + 1 ) * M], M ); + + lsf2lsp( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core ); + lsf2lsp( st->lsf_q_cng_float, st->lsp_q_cng_float, M, st->sr_core ); + + mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M ); + } + } + + /*---------------------------------------------------------------* + * Rate switching + *---------------------------------------------------------------*/ + + if ( st->rate_switching_reset ) + { + mvr2r( &( lsf[M] ), &( lsf[0] ), M ); + mvr2r( &( lsp[M] ), &( lsp[0] ), M ); + mvr2r( &( lsf[M] ), st->lsf_old, M ); + mvr2r( &( lsp[M] ), st->lsp_old, M ); + mvr2r( &( lsf[M] ), lsfmid, M ); + mvr2r( &( lsp[M] ), lspmid, M ); + lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M ); + } + + if ( st->enablePlcWaveadjust && bfi ) + { + st->hPlcInfo->nbLostCmpt++; + } + + /*--------------------------------------------------------------------------------* + * TD-TCX concealment + *--------------------------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE ) + { + assert( bfi ); /*must only happen in BFI*/ + if ( !st->tcxonly ) + { + /*LPC interpolation*/ + int_lsp( st->L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 ); + int_lsp( st->L_frame, st->old_lsp_q_cng_float, st->lsp_q_cng_float, st->Aq_cng_float, M, interpol_frac_12k8, 0 ); + } + + /* PLC: [TCX: TD PLC] */ + con_tcx_flt( st, &synthFB[0], -1.f, NULL, 0, NULL ); + lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); + st->con_tcx = 1; + set_f( &st->mem_pitch_gain_float[2], st->lp_gainp, st->nb_subfr ); + + /* LPC for ACELP/BWE */ + if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + { + mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) ); + } + + /* PLC: [TCX: Tonal Concealment] */ + /* Signal that this frame is not TCX */ + if ( st->hTonalMDCTConc != NULL ) + { + TonalMDCTConceal_UpdateState_ivas( st->hTonalMDCTConc, 0, 0, 0, 0 ); + } + } + + /*--------------------------------------------------------------------------------* + * TCX20 + *--------------------------------------------------------------------------------*/ + + /* Set pointer to parameters */ + prm = param; + if ( st->core == TCX_20_CORE ) + { + + /* Stability Factor */ + if ( !bfi ) + { + st->stab_fac = lsf_stab( &lsf[M], &lsf[0], 0, st->L_frame ); + } + + if ( hTcxDec->enableTcxLpc ) + { + /* Convert quantized lsp to A */ + lsp2a_stab( &lsp[M], Aq, M ); + } + else + { + if ( !st->tcxonly ) + { + if ( !bfi && st->prev_bfi && !( st->safety_net ) && st->rate_switching_reset ) + { + /* diffuse LPC power on rate switching*/ + RecLpcSpecPowDiffuseLc_flt( &lsp[M], &lsp[0], &lsf[M], st, 0 ); + int_lsp( st->L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 ); + mvr2r( &lsf[M], lsfnew_uw, M ); + } + else + { + /* LPC Interpolation for TCX */ + E_LPC_int_lpc_tcx_float( &lsp[0], &lsp[M], Aq ); + } + } + else + { + lsp2a_stab( &lsp[M], Aq, M ); + } + } + if ( !bfi && hTcxDec->tcx_lpc_shaped_ari ) + { + basop_E_LPC_f_lsp_a_conversion( lspind, Aind, M ); + } + + /* TCX decoder */ + decoder_tcx_flt( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, sba_dirac_stereo_flag ); + } + + /*--------------------------------------------------------------------------------* + * TCX10 + *--------------------------------------------------------------------------------*/ + + if ( st->core == TCX_10_CORE ) + { + prm = NULL; /* just to avoid MSVC warnings */ + + for ( k = 0; k < 2; k++ ) + { + /* Set pointer to parameters */ + prm = param + ( k * DEC_NPRM_DIV ); + + /* Stability Factor */ + if ( !bfi ) + { + st->stab_fac = lsf_stab( &lsf[( k + 1 ) * M], &lsf[k * M], 0, st->L_frame ); + } + + lsp2a_stab( &lsp[( k + 1 ) * M], Aq, M ); + { + IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); + } + + /* TCX decoder */ + decoder_tcx_flt( st, prm, Aq, Aind, &synth[k * st->L_frame / 2], &synthFB[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag ); + } + } +#endif + + /*--------------------------------------------------------------------------------* + * Post-processing + *--------------------------------------------------------------------------------*/ + + if ( st->core == TCX_10_CORE || st->core == TCX_20_CORE ) + { + if ( st->enablePlcWaveadjust || /* bfi */ + ( st->last_total_brate >= HQ_48k && /* recovery */ + st->last_codec_mode == MODE2 ) ) + { + /* waveform adjustment */ + concealment_signal_tuning( st, bfi, synthFB, st->last_core_bfi ); + + if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL ) + { + lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); + + if ( !bfi && st->prev_bfi ) + { + st->hPlcInfo->Pitch = 0; + } + } + } + +#ifdef IVAS_FLOAT_FIXED_ + floatToFixed_arr( st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, 0, st->hTonalMDCTConc->nSamples / 2 ); + floatToFixed_arr( st->hTonalMDCTConc->lastPcmOut_float, st->hTonalMDCTConc->lastPcmOut, 0, st->hTonalMDCTConc->nSamples ); + floatToFixed_arr( synthFB, synthFB_fx, 4, hTcxDec->L_frameTCX ); + + if ( !bfi && st->hTonalMDCTConc != NULL ) { - fer_energy_fx( st->L_frame, st->clas_dec, synth_fx, q_synth, old_fpitch_fx, &enr_old_fx, st->L_frame ); + TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, hTcxDec->L_frameTCX ); } - st->enr_old = (float) enr_old_fx; + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 4, st->hTonalMDCTConc->nSamples / 2 ); + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 4, st->hTonalMDCTConc->nSamples ); #else - if ( hTcxLtpDec->tcxltp_gain_float == 0 ) + if ( !bfi && st->hTonalMDCTConc != NULL ) { - fer_energy( st->L_frame, UNVOICED, synth, (float) ( st->L_frame / 2 ), &st->enr_old, st->L_frame ); + TonalMDCTConceal_SaveTimeSignal_ivas( st->hTonalMDCTConc, synthFB, hTcxDec->L_frameTCX ); } - else +#endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED + Word16 q_Aq_2; + float max = (float) fabs( Aq[0] ); + for ( int p = 1; p < M + 1; p++ ) + { + if ( max < fabs( Aq[p] ) ) + max = (float) ( fabs( Aq[p] ) ); + } + q_Aq = norm_s( (Word16) max ); + floatToFixed_arr( Aq, Aq_fx, q_Aq, M + 1 ); + + st->hTcxDec->gainHelper = (Word16) floatToFixed( st->hTcxDec->gainHelper_float, Q14 ); + st->hTcxDec->gainHelper_e = 1; + st->hTcxDec->stepCompensate = (Word16) floatToFixed( st->hTcxDec->stepCompensate_float, Q14 ); + st->hTcxDec->stepCompensate_e = 1; + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); + st->hTcxDec->damping = (Word16) floatToFixed( st->hTcxDec->damping_float, Q14 ); + st->bfi_pitch_fx = (Word16) floatToFixed( st->bfi_pitch, Q5 ); + st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); + if ( st->hPlcInfo ) + { + st->hPlcInfo->step_concealgain_fx = (Word16) floatToFixed( st->hPlcInfo->step_concealgain, Q15 ); + } + st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, Q14 ); + st->hTcxDec->conCngLevelBackgroundTrace = (Word16) floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, Q15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); + st->hTcxDec->conLastFrameLevel = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 - st->hTcxDec->conLastFrameLevel_e ); + if ( st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + floatToFixed_arr( st->mem_pitch_gain_float, st->mem_pitch_gain, Q15, 2 * NB_SUBFR16k + 2 ); + floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); + floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M ); + floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM ); + floatToFixed_arr( st->syn_float, st->syn, 0, M + 1 ); + floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); + floatToFixed_arr( synth, synth_fx, 0, st->L_frame ); + floatToFixed_arr( synthFB, synthFB_fx, 0, st->hTcxDec->L_frameTCX ); + + floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); + floatToFixed_arr( lspnew_uw, lspnew_uw_fx, Q15, M ); + + /*=========================================*/ + decoder_tcx_post( st, synth_fx, synthFB_fx, Aq_fx, bfi ); + + IF( EQ_16( st->core, TCX_20_CORE ) ) { - fer_energy( st->L_frame, st->clas_dec, synth, st->old_fpitch_float, &st->enr_old, st->L_frame ); + /* LPC Interpolation for BWE/post-processing */ + IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) + { + int_lsp_fx( st->L_frame, st->lspold_uw, lspnew_uw_fx, Aq_fx, M, interpol_frac_fx, 0 ); + Copy( Aq_fx, st->mem_Aq, st->nb_subfr * ( M + 1 ) ); + } + } + /*=================================*/ + for ( int p = 0; p < st->nb_subfr; p++ ) + { + q_Aq_2 = 15 - ( norm_s( Aq_fx[p * ( M + 1 )] - 1 ) ); + fixedToFloat_arr( Aq_fx + p * ( M + 1 ), Aq + p * ( M + 1 ), q_Aq_2, ( M + 1 ) ); + fixedToFloat_arr( st->mem_Aq + p * ( M + 1 ), st->mem_Aq_float + p * ( M + 1 ), q_Aq_2, ( M + 1 ) ); + } + fixedToFloat_arr( synth_fx, synth, 0, st->L_frame ); + fixedToFloat_arr( synthFB_fx, synthFB, 0, st->hTcxDec->L_frameTCX ); + fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, st->Q_syn, M ); + fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, st->Q_syn, L_SYN_MEM ); + fixedToFloat_arr( st->syn, st->syn_float, 0, M + 1 ); + fixedToFloat_arr( st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC ); + hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat( hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, Q14 ); + if ( st->hPlcInfo ) + { + st->hPlcInfo->recovery_gain_float = fixedToFloat( st->hPlcInfo->recovery_gain, Q14 ); + st->hPlcInfo->step_concealgain = fixedToFloat( st->hPlcInfo->step_concealgain_fx, Q15 ); + } + st->bfi_pitch = fixedToFloat( st->bfi_pitch_fx, Q6 ); + st->old_fpitch_float = fix_to_float( st->old_fpitch, Q16 ); + fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, q_Aq, M + 1 ); + fixedToFloat_arr( st->mem_pitch_gain, st->mem_pitch_gain_float, Q15, 2 * NB_SUBFR16k + 2 ); + fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); + st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); + st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->conLastFrameLevel, 15 - st->hTcxDec->conLastFrameLevel_e ); + for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) + { + st->hTcxDec->NoiseLevelMemory_bfi[p] = fixedToFloat( st->hTcxDec->conNoiseLevelMemory[p], 15 - st->hTcxDec->conNoiseLevelMemory_e[p] ); + } +#else + decoder_tcx_post_flt( st, synth, synthFB, Aq, bfi, 0 ); + + if ( st->core == TCX_20_CORE ) + { + /* LPC Interpolation for BWE/post-processing */ + if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + { + int_lsp( st->L_frame, st->lspold_uw_float, lspnew_uw, Aq, M, interpol_frac_12k8, 0 ); + mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) ); + } } #endif // IVAS_FLOAT_FIXED } - if ( !bfi && st->clas_dec >= VOICED_TRANSITION && st->clas_dec < INACTIVE_CLAS ) + /* PLC: [Common: Classification] */ + /* the classifier buffer is always updated if the sr is at + 16000 or below - the classification itself is just performed if(!st->tcxonly ) */ +#ifdef IVAS_FLOAT_FIXED + /*=============================================*/ + double max_val = 0; + for ( int j = 0; j <= M; j++ ) + { + max_val = max( max_val, fabs( Aq[j] ) ); + } + if ( fabs( max_val ) < 1.0f ) + q_Aq = Q15; + else + q_Aq = norm_s( (Word16) max_val ); + for ( int j = 0; j <= M; j++ ) + { + Aq_fx[j] = (Word16) ( Aq[j] * pow( 2, q_Aq ) ); + } + + st->lp_ener_bfi_fx = (Word16) floatToFixed( st->lp_ener_bfi, Q8 ); + st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); + if ( hTcxLtpDec->tcxltp ) + { + hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); + } + st->classifier_Q_mem_syn = Q5; + floatToFixed_arr( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM ); + st->Q_syn = 0; + floatToFixed_arr( synth, synth_fx, st->Q_syn, st->L_frame ); + + floatToFixed_arr( synth_buf + st->L_frame, synth_buf_fx + st->L_frame, 0, hTcxDec->old_synth_len ); + floatToFixed_arr( hTcxDec->old_synthFB + hTcxDec->L_frameTCX - NS2SA( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->old_synthFB_fx + hTcxDec->L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), 0, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); + floatToFixed_arr( synth_bufFB + hTcxDec->L_frameTCX, synth_bufFB_fx + hTcxDec->L_frameTCX, 0, hTcxDec->old_synth_lenFB ); + floatToFixed_arr( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), 0, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + floatToFixed_arr( lspnew_uw, lspnew_uw_fx, Q15, NB_DIV * M ); + floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); + floatToFixed_arr( &lsp[st->numlpc * M], &lsp_fx[st->numlpc * M], Q15, M ); + floatToFixed_arr( st->lsp_q_cng_float, st->lsp_q_cng, Q15, M ); + for ( int p = 0; p < M; p++ ) + { + lsfnew_uw_fx[( st->numlpc - 1 ) * M + p] = (Word16) ( lsfnew_uw[( st->numlpc - 1 ) * M + p] * 1.28f ); + lsf_fx[st->numlpc * M + p] = (Word16) ( lsf[st->numlpc * M + p] * 1.28f ); + st->lsfold_uw[p] = (Word16) ( st->lsfold_uw_float[p] * 1.28f ); + st->lsf_q_cng[p] = (Word16) ( st->lsf_q_cng_float[p] * 1.28f ); + } + floatToFixed_arr( synth + L_FRAME - L_LP - 1, synth_fx + L_FRAME - L_LP - 1, 0, L_LP + 1 ); + floatToFixed_arr( &lsp[M], &lsp_fx[M], Q15, M ); + st->Q_exc = 1; + floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); + IF( st->hTdCngDec != NULL ) + { + floatToFixed_arr( st->hTdCngDec->ho_lsp_circ, st->hTdCngDec->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); + floatToFixed_arrL( st->hTdCngDec->ho_env_circ, st->hTdCngDec->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); + floatToFixed_arrL( st->hTdCngDec->ho_ener_circ, st->hTdCngDec->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); + } + + Word16 signal_out_buf_fx[L_FRAME48k], signal_outFB_fx[L_FRAME48k]; + Word32 pitch_buf_fx[NB_SUBFR16k]; + Word16 *signal_out_fx = signal_out_buf_fx; + floatToFixed_arr( synth_buf, synth_buf_fx, 0, OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M ); + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); + floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1 ); + floatToFixed_arr( st->mem_Aq_float, st->mem_Aq, Q12, ( NB_SUBFR16k ) * ( M + 1 ) ); + if ( !st->tcxonly ) + { + floatToFixed_arr( st->p_bpf_noise_buf_float, st->p_bpf_noise_buf, 0, L_FRAME_16k ); + } + floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); + floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, 0, L_SUBFR ); + floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, 0, L_SUBFR ); + st->lp_noise = floatToFixed( st->lp_noise_float, Q16 ); + st->lp_error_ener = floatToFixed( st->hBPF->pst_lp_ener, Q16 ); + st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); + st->hPFstat->gain_prec = (Word16) floatToFixed( st->hPFstat->gain_prec_flt, Q14 ); + + /*=============================================*/ + IF( LE_32( st->sr_core, INT_FS_16k ) ) + { + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || ( st->tcxonly && st->bfi ) ) + { + Word16 pitch_C[4]; + + /* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */ + set16_fx( pitch_C, shl( round_fx( st->old_fpitch ), Q6 ), 4 ); + + /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ + Word16 prev_codec_mode = st->codec_mode; + st->codec_mode = MODE2; + FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->tcxonly ? GENERIC : st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_bfi_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 /*st->core_brate*/, st->Q_syn, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); + st->codec_mode = prev_codec_mode; + } + } + + + /*--------------------------------------------------------------------------------* + * Updates + *--------------------------------------------------------------------------------*/ + + IF( bfi && NE_16( st->last_core, ACELP_CORE ) ) + { + /* Update FEC_scale_syn parameters */ + IF( hTcxLtpDec->tcxltp_gain_float == 0 ) + { + frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr( st->L_frame, 1 ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); + } + ELSE + { + frame_ener_fx( st->L_frame, st->clas_dec, synth_fx, extract_l( L_shr( st->old_fpitch, 16 ) ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); + } + } + + IF( !bfi && GE_16( st->clas_dec, VOICED_TRANSITION ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) { /* use latest LPC set */ -#ifdef IVAS_FLOAT_FIXED - Word16 Aq_fx[L_SUBFR]; - Word16 q_fac; - double max_val = 0; - for (int j = 0; j <= M; j++) + st->old_enr_LP = Enr_1_Az_fx( Aq_fx, L_SUBFR ); // Q3 + } + + /* Update past buffers */ + Copy( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len ); + Copy( hTcxDec->old_synthFB_fx + hTcxDec->L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); + Copy( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + + Copy( &lspnew_uw_fx[( st->numlpc - 1 ) * M], st->lspold_uw, M ); + Copy( &lsfnew_uw_fx[( st->numlpc - 1 ) * M], st->lsfold_uw, M ); + + IF( EQ_16( bfi, 1 ) ) + { + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery */ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery */ + } + ELSE + { + Copy( &lsp_fx[st->numlpc * M], st->lsp_old_fx, M ); + Copy( &lsf_fx[st->numlpc * M], st->lsf_old_fx, M ); + } + Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); + Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); + + /* Update CNG parameters */ + IF( !st->tcxonly && st->hTdCngDec != NULL ) + { + /* update CNG parameters in active frames */ + IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + { + Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_h[M + 1], r_l[M + 1], tmp, lsptmp[M], q_r; + assert( st->L_frame == L_FRAME ); + + Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); + tmp = synth_fx[L_FRAME - L_LP - 1]; + E_UTIL_f_preemph2( 0, buf, st->preemph_fac, L_LP, &tmp ); + autocorr_fx( buf, M, r_h, r_l, &q_r, L_LP, Assym_window_W16fx, 0, 0 ); + lag_wind( r_h, r_l, M, INT_FS_12k8, LAGW_WEAK ); + E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); + E_LPC_a_lsp_conversion( A, lsptmp, &lspnew_uw_fx[0], M ); + Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 0 ); + + IF( st->hTdCngDec != NULL ) + { + cng_params_upd_ivas_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); + } + } + ELSE IF( st->hTdCngDec != NULL ) { - max_val = max(max_val, fabs(Aq[j])); + cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); } - if (fabs(max_val) < 1.0f) - q_fac = Q15; - else - q_fac = norm_s((Word16)max_val); - for (int j = 0; j <= M; j++) + /* Set 16k LSP flag for CNG buffer */ + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); + } + + st->last_is_cng = 0; + + /* Postfiltering */ + post_decoder( st, synth_buf_fx, pit_gain_fx, pitch, signal_out_fx, st->p_bpf_noise_buf ); + + IF( signal_outFB ) + { + Copy( synthFB_fx, signal_outFB_fx, hTcxDec->L_frameTCX ); + } + + IF( !bfi ) + { + IF( st->enablePlcWaveadjust ) + { + st->hPlcInfo->nbLostCmpt = 0; + } + + IF( NE_16( param[1 + NOISE_FILL_RANGES], 0 ) ) + { + Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ + tcxltp_pitch_tmp = L_shr( tcxltp_pitch_tmp, 10 ); // Q6 + set32_fx( pitch_buf_fx, tcxltp_pitch_tmp, NB_SUBFR16k ); + } + ELSE { - Aq_fx[j] = (Word16)(Aq[j] * pow(2, q_fac)); + set32_fx( pitch_buf_fx, L_shl( L_SUBFR, 6 ), NB_SUBFR16k ); } - Word16 old_enr_LP_fx = Enr_1_Az_fx(Aq_fx, L_SUBFR); - st->old_enr_LP_float = (float)(old_enr_LP_fx / pow(2, Q3)); + } + + IF( bfi ) + { + /*"LPD dec - All BFI"*/ + bitsRead = 0; /*to avoid empty counting */ + } + + /* updates */ + st->last_voice_factor_fx = 0; + st->last_coder_type = st->coder_type; + /*====================================*/ + + + fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM ); + st->lp_ener_bfi = fixedToFloat( st->lp_ener_bfi_fx, Q8 ); + + st->enr_old = (float) st->enr_old_fx; + + st->old_enr_LP_float = (float) ( st->old_enr_LP / pow( 2, Q3 ) ); + + fixedToFloat_arr( hTcxDec->old_synth, hTcxDec->old_synth_float, 0, hTcxDec->old_synth_len ); + fixedToFloat_arr( hTcxDec->synth_history_fx, hTcxDec->synth_history, 0, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + fixedToFloat_arr( hTcxDec->old_synthFB_fx, hTcxDec->old_synthFB, 0, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) + hTcxDec->old_synth_lenFB ); + fixedToFloat_arr( st->old_lsp_q_cng, st->old_lsp_q_cng_float, Q15, M ); + fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); + fixedToFloat_arr( st->lspold_uw, st->lspold_uw_float, Q15, M ); + for ( int p = 0; p < M; p++ ) + { + st->lsf_old[p] = (float) st->lsf_old_fx[p] / 1.28f; + st->lsfold_uw_float[p] = (float) st->lsfold_uw[p] / 1.28f; + st->old_lsf_q_cng_float[p] = (float) st->old_lsf_q_cng[p] / 1.28f; + } + + IF( !st->tcxonly && st->hTdCngDec != NULL ) + { + fixedToFloat_arr( st->hTdCngDec->ho_lsp_circ_fx, st->hTdCngDec->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); + fixedToFloat_arrL( st->hTdCngDec->ho_env_circ_fx, st->hTdCngDec->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); + fixedToFloat_arrL( st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, Q6, HO_HIST_SIZE ); + } + + st->last_voice_factor = st->last_voice_factor_fx; + fixedToFloat_arr( signal_out_fx, signal_out, 0, st->L_frame ); + fixedToFloat_arr( signal_outFB_fx, signal_outFB, 0, hTcxDec->L_frameTCX ); + fixedToFloat_arrL( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k ); + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); + fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, 0, L_SUBFR ); + fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, 0, L_SUBFR ); + st->hBPF->pst_lp_ener = fixedToFloat( st->lp_error_ener, Q16 ); + st->hBPF->pst_mem_deemp_err = fixedToFloat( st->mem_error, Q16 ); + st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); #else + if ( st->sr_core <= INT_FS_16k ) + { + if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || ( st->tcxonly && st->bfi ) ) + { + float pitch_C[4]; + + /* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */ + set_f( pitch_C, floorf( st->old_fpitch_float + 0.5f ), 4 ); + + /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ + FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : st->core_ext_mode, MODE2, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified_float : -1.0f, st->narrowBand, CLASSIFIER_TCX, bfi, st->preemph_fac_float, st->tcxonly, st->last_core_brate, -1 ); + } + } + + /*--------------------------------------------------------------------------------* + * Updates + *--------------------------------------------------------------------------------*/ + + if ( bfi && st->last_core != ACELP_CORE ) + { + /* Update FEC_scale_syn parameters */ + if ( hTcxLtpDec->tcxltp_gain_float == 0 ) + { + fer_energy( st->L_frame, UNVOICED, synth, (float) ( st->L_frame / 2 ), &st->enr_old, st->L_frame ); + } + else + { + fer_energy( st->L_frame, st->clas_dec, synth, st->old_fpitch_float, &st->enr_old, st->L_frame ); + } + } + + if ( !bfi && st->clas_dec >= VOICED_TRANSITION && st->clas_dec < INACTIVE_CLAS ) + { + /* use latest LPC set */ st->old_enr_LP_float = enr_1_Az( Aq, L_SUBFR ); -#endif } /* Update past buffers */ @@ -759,7 +1655,6 @@ void stereo_tcx_core_dec( mvr2r( st->lsp_q_cng_float, st->old_lsp_q_cng_float, M ); mvr2r( st->lsf_q_cng_float, st->old_lsf_q_cng_float, M ); - /* Update CNG parameters */ if ( !st->tcxonly && st->hTdCngDec != NULL ) { /* update CNG parameters in active frames */ @@ -786,10 +1681,10 @@ void stereo_tcx_core_dec( { cng_params_upd( &lsp[M], st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ, DEC, st->hTdCngDec->ho_env_circ, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); } - /* Set 16k LSP flag for CNG buffer */ st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); } + st->last_is_cng = 0; /* Postfiltering */ @@ -826,6 +1721,7 @@ void stereo_tcx_core_dec( /* updates */ st->last_voice_factor = 0.0f; st->last_coder_type = st->coder_type; +#endif // IVAS_FLOAT_FIXED /* -------------------------------------------------------------- * * In FFT domain: perform noise estimation during active frames @@ -833,194 +1729,208 @@ void stereo_tcx_core_dec( if ( st->hFdCngDec != NULL && ( st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= MAX_ACELP_BRATE ) { +#ifdef IVAS_FLOAT_FIXED + st->hFdCngDec->lp_noise = floatToFixed( st->hFdCngDec->lp_noise_float, Q23 ); + st->hFdCngDec->lp_speech = floatToFixed( st->hFdCngDec->lp_speech_float, Q23 ); + + noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, signal_out_fx, 0 ); + + st->hFdCngDec->lp_noise_float = fixedToFloat( st->hFdCngDec->lp_noise, Q23 ); + st->hFdCngDec->lp_speech_float = fixedToFloat( st->hFdCngDec->lp_speech, Q23 ); +#else noisy_speech_detection_flt( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, signal_out ); +#endif // IVAS_FLOAT_FIXED st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; #ifdef IVAS_FLOAT_FIXED st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01); + st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01 ); #endif st->lp_noise_float = st->hFdCngDec->lp_noise_float; - if ( st->element_mode != IVAS_CPE_TD ) - { + #ifdef IVAS_FLOAT_FIXED - Word16 signal_out_fx[L_FRAME48k], signal_outFB_fx[L_FRAME48k], q_buf = 1; + Word16 /*signal_out_fx[L_FRAME48k], signal_outFB_fx[L_FRAME48k],*/ q_buf = 1; - if ( ivas_format == ISM_FORMAT ) + if ( ivas_format == ISM_FORMAT ) + { + for ( int p = 0; p < L_FRAME48k; p++ ) { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - signal_outFB_fx[p] = (Word16) ( signal_outFB[p] * ( 1u << q_buf ) ); - } + signal_outFB_fx[p] = (Word16) ( signal_outFB[p] * ( 1u << q_buf ) ); } - else + } + else + { + for ( int p = 0; p < L_FRAME48k; p++ ) { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - signal_out_fx[p] = (Word16) ( signal_out[p] * ( 1u << q_buf ) ); - } + signal_out_fx[p] = (Word16) ( signal_out[p] * ( 1u << q_buf ) ); } - for ( int p = 0; p < st->L_frame; p++ ) + } + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + } + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) + { + st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + } + st->hFdCngDec->msNoiseEst_exp = 31 - Q4; + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + { + st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); + st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); + st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + } + for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) + { + if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) { - st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + st->hFdCngDec->msMinBuf[p] = MAX_32; } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) + else { - st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); } - st->hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + } + + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 + for ( int p = 0; p < FFTCLDFBLEN; p++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; + st->hFdCngDec->partNoiseShape_exp = 31 - Q4; + for ( int p = 0; p < NPART; p++ ) + { + st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); + } + for ( int p = 0; p < 24; p++ ) + { + st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); + } + /*=================================*/ + if ( st->element_mode != IVAS_CPE_TD ) + { + IF( EQ_32( ivas_format, ISM_FORMAT ) ) { - st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + Word16 buffer[L_FRAME16k]; + lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); + ApplyFdCng_fx( buffer, q_buf /* Q of buffer */, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) + ELSE { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } + ApplyFdCng_fx( signal_out_fx, q_buf, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); } - - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - for ( int p = 0; p < FFTCLDFBLEN; p++ ) + } + /*=================================*/ + if ( ( ( st->m_frame_type == ACTIVE_FRAME ) && ( ( st->bfi == 0 && + ( signal_out == NULL || + ( *signal_out( -FLT_MAX ) && + *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) < FLT_MAX && + *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && + ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && + !( st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode ) ) || + ( st->element_mode == IVAS_CPE_TD ) ) && + ( !st->BER_detect ) ) || + ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && ( st->hFdCngDec->hFdCngCom->active_frame_counter > 0 ) ) || ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) ) ) || + ( st->m_frame_type == ZERO_FRAME ) ) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); + st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); } - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; - st->hFdCngDec->partNoiseShape_exp = 31 - Q4; - for ( int p = 0; p < NPART; p++ ) + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) { - st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); + st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); } - for ( int p = 0; p < 24; p++ ) + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) { - st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); + st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); } -/*=================================*/ - IF( EQ_32( ivas_format, ISM_FORMAT ) ) + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) { - Word16 buffer[L_FRAME16k]; - lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); - ApplyFdCng_fx( buffer, q_buf /* Q of buffer */, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); } - ELSE + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) { - ApplyFdCng_fx( signal_out_fx, q_buf, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); + st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); + st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); + st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); } -/*=================================*/ - if ( ( ( st->m_frame_type == ACTIVE_FRAME ) && ( ( st->bfi == 0 && - ( signal_out == NULL || - ( *signal_out( -FLT_MAX ) && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && - ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && - !( st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode ) ) || - ( st->element_mode == IVAS_CPE_TD ) ) && - ( !st->BER_detect ) ) || - ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && ( st->hFdCngDec->hFdCngCom->active_frame_counter > 0 ) ) || ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) ) ) || - ( st->m_frame_type == ZERO_FRAME ) ) + if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) { - st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); - st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) - { - st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + for ( int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++ ) { - st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); - st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); - st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); } - if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) + } + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) + { + for ( int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++ ) { - for ( int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++ ) + if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) + { + st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; + } + else { - st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); + st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 } } - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) { - for ( int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++ ) + st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); + st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); + st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); + st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); + if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) + { + st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 + } + if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) + { + st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); + } + if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } + st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + else { - st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 - } - if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); - } - if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); - } + st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); } } - if ( sum_f( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) > 0.01f ) + } + if ( sum_f( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) > 0.01f ) + { + if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) { - if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) + int A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ); + for ( int p = 0; p < M; p++ ) { - int A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ); - for ( int p = 0; p < M; p++ ) - { - st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); - st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); - } + st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); + st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); } } } + } #else + if ( st->element_mode != IVAS_CPE_TD ) + { if ( ivas_format == ISM_FORMAT ) { float buffer[L_FRAME16k]; @@ -1031,9 +1941,10 @@ void stereo_tcx_core_dec( { ApplyFdCng_flt( signal_out, NULL, NULL, NULL, st, st->bfi, 0 ); } -#endif // IVAS_FLOAT_FIXED } +#endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /* Generate additional comfort noise to mask potential coding artefacts */ if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna && !st->cna_dirac_flag ) { @@ -1044,190 +1955,198 @@ void stereo_tcx_core_dec( /* Clear memory for secondary channel CNA */ set_f( hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2 ); } -#ifdef IVAS_FLOAT_FIXED - Word16 msPsd_fx[NPART_SHAPING]; - Word16 msPsd_e; - Word32 psd_part_fx[NPART_SHAPING]; - Word16 psd_part_e; - - f2me_buf_16(st->hFdCngDec->msPsd_float, msPsd_fx, &msPsd_e, st->hFdCngDec->nFFTpart_shaping); - - expand_range_var_exp(msPsd_fx, msPsd_e, psd_part_fx, &psd_part_e, st->hFdCngDec->nFFTpart_shaping); - - me2f_buf(psd_part_fx, psd_part_e, psd_part, st->hFdCngDec->nFFTpart_shaping); -#else expand_range_flt( st->hFdCngDec->msPsd_float, psd_part, st->hFdCngDec->nFFTpart_shaping ); -#endif scalebands_flt( psd_part, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand, psd, 1 ); -#ifndef IVAS_FLOAT_FIXED generate_stereo_masking_noise( signal_out, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); + } #else + /* Generate additional comfort noise to mask potential coding artefacts */ + if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna && !st->cna_dirac_flag ) + { + if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) + { + if ( st->element_mode != last_element_mode ) + { + /* Clear memory for secondary channel CNA */ + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2 ); + // to be removed + set_f( hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2 ); + } + expand_range( st->hFdCngDec->msPsd, psd_part_fx, &psd_part_e, st->hFdCngDec->nFFTpart_shaping ); + scalebands_fx( psd_part_fx, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand, psd_fx, 1 ); generate_stereo_masking_noise_fx( signal_out, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); -#endif } +#endif else if ( st->element_mode != IVAS_CPE_DFT ) { - generate_masking_noise_flt( signal_out, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + generate_masking_noise_flt( signal_out, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); } } - if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 ) - { + #ifdef IVAS_FLOAT_FIXED - Word16 signal_out_fx[L_FRAME48k], q_buf = 1; + q_buf = 1; - for ( int p = 0; p < L_FRAME48k; p++ ) + for ( int p = 0; p < L_FRAME48k; p++ ) + { + signal_out_fx[p] = (Word16) ( signal_out[p] * ( 1u << q_buf ) ); + } + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + } + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) + { + st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + } + st->hFdCngDec->msNoiseEst_exp = 31 - Q4; + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + { + st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); + st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); + st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + } + for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) + { + if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) { - signal_out_fx[p] = (Word16) ( signal_out[p] * ( 1u << q_buf ) ); + st->hFdCngDec->msMinBuf[p] = MAX_32; } - for ( int p = 0; p < st->L_frame; p++ ) + else { - st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); } + } + + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 + for ( int p = 0; p < FFTCLDFBLEN; p++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; + st->hFdCngDec->partNoiseShape_exp = 31 - Q4; + for ( int p = 0; p < 24; p++ ) + { + st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); + st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); + } + if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 ) + { + ApplyFdCng_fx( signal_out_fx, q_buf, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + } + if (st->element_mode == IVAS_CPE_TD && st->idchan == 0) + { + if ( ( ( st->m_frame_type == ACTIVE_FRAME ) && ( ( st->bfi == 0 && + ( signal_out == NULL || + ( *signal_out( -FLT_MAX ) && + *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) < FLT_MAX && + *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && + ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && + !( st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode ) ) || + ( st->element_mode == IVAS_CPE_TD ) ) && + ( !st->BER_detect ) ) || + ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && ( st->hFdCngDec->hFdCngCom->active_frame_counter > 0 ) ) || ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) ) ) || + ( st->m_frame_type == ZERO_FRAME ) ) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); + st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) { - st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); } - st->hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) { - st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } + st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); } - - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - for ( int p = 0; p < FFTCLDFBLEN; p++ ) + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); } - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; - st->hFdCngDec->partNoiseShape_exp = 31 - Q4; - for ( int p = 0; p < 24; p++ ) + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) { - st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); - st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); + st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); + st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); + st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); + st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); } - - ApplyFdCng_fx( signal_out_fx, q_buf, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); - - if ( ( ( st->m_frame_type == ACTIVE_FRAME ) && ( ( st->bfi == 0 && - ( signal_out == NULL || - ( *signal_out( -FLT_MAX ) && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && - ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && - !( st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode ) ) || - ( st->element_mode == IVAS_CPE_TD ) ) && - ( !st->BER_detect ) ) || - ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && ( st->hFdCngDec->hFdCngCom->active_frame_counter > 0 ) ) || ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) ) ) || - ( st->m_frame_type == ZERO_FRAME ) ) + if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) { - st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); - st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) + for ( int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++ ) { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) + } + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) + { + for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) { - st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) + { + st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 + } } for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) { - st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); - st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); - st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) - { - for ( int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++ ) + st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); + st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); + st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); + st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); + if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) { - st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); + st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; } - } - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) - { - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) + else { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } + st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) { - st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 - } - if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); - } - if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); - } + st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); + } + if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) + { + st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); } - } - for ( int p = 0; p < M; p++ ) - { - st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << Q14 ) ); - st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); } } + int A_cng_q = 14; + for ( int p = 0; p < M; p++ ) + { + st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q) ); + st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); + } + } + } #else + if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 ) + { ApplyFdCng_flt( signal_out, NULL, NULL, NULL, st, st->bfi, 0 ); -#endif // IVAS_FLOAT_FIXED } +#endif // IVAS_FLOAT_FIXED } - - +#ifdef IVAS_FLOAT_FIXED + st->scale = scale; +#endif // IVAS_FLOAT_FIXED pop_wmops(); return; } @@ -1442,312 +2361,6 @@ static void dec_prm_tcx_ivas_fx( Word16 *bitsRead /* o : number of read bits */ ) { -#if 1/*--------------Float to fixed changes----------------*/ - H_IGF_GRID hGrid; - IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - hPrivateData = &st->hIGFDec->igfData; - H_IGF_INFO hIGFInfo = &hPrivateData->igfInfo; - hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; - floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); - hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); - hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); - hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); - hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; - floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); - hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); - hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); - hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); - hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; - floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); - hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); - hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); - hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); - Word16 i = 0, - Q_old_syn_Overl=0, Q_syn_Overl_TDAC=0, Q_syn_Overl=0, Q_syn_Overl_TDACFB=0, Q_syn_OverlFB=0, - Q_old_synth=0, Q_syn=0, Q_synth_history=0, Q_mem_syn_r=0, Q_old_exc=0, Q_fer_samples=0, Q_old_out=0, - Q_old_outLB=0, Q_mem_syn2=0, Q_cldfbAna_cldfb_state=0, Q_cldfbBPF_cldfb_state=0, Q_cldfbSyn_cldfb_state=0, Q_cldfbSynHB_cldfb_state=0, - Q_state_lpc_syn=0, Q_state_syn_shbexc=0, Q_mem_stp_swb=0, Q_mem_zero_swb=0, Q_old_Aq_12_8 = 12, Q_pst_old_syn=0, Q_mem_stp=0, Q_mem_pf_in=0, - Q_mem_res2=0, delay_comp=0, Q_loBuffer=0; - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ - st->sr_core = getCoreSamplerateMode2( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); - st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, 15 ); - Q_syn = Q_factor_arr( st->syn_float, 17 ); - Q_old_exc = Q_factor_arr( st->old_exc, L_EXC_MEM_DEC ) - 1; - Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ) - 1; - Q_mem_syn2 = Q_mem_syn_r; - floatToFixed_arr( st->old_exc, st->old_exc_fx, Q_old_exc, L_EXC_MEM_DEC ); - floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn_r, L_SYN_MEM ); - floatToFixed_arr( st->syn_float, st->syn, Q_syn, M + 1 ); - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, 15, M ); - floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, 15, M ); - floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn2, M ); - FOR( i = 0; i < M; i++ ) - { - st->mem_MA_fx[i] = (Word16) floatToFixed( (float)(st->mem_MA[i] * 2.56), 0 ); - st->mem_AR_fx[i] = (Word16) floatToFixed((float)(st->mem_AR[i] * 2.56), 0 ); - st->lsf_old_fx[i] = (Word16) floatToFixed((float)(st->lsf_old[i] * 2.56), 0 ); - st->lsfold_uw[i] = (Word16) floatToFixed((float)(st->lsfold_uw_float[i] * 2.56), 0 ); - } - IF( st->hTcxCfg ) - { - st->hTcxCfg->preemph_fac = (Word16) floatToFixed( st->hTcxCfg->preemph_fac_flt, 15 ); - st->hTcxCfg->sq_rounding = (Word16) floatToFixed( st->hTcxCfg->sq_rounding_flt, 15 ); - st->hTcxCfg->bandwidth = (Word16) floatToFixed( st->hTcxCfg->bandwidth_flt, 15 ); - st->hTcxCfg->na_scale = (Word16) floatToFixed( st->hTcxCfg->na_scale_flt, 15 ); - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_window[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_flt[st->hTcxCfg->tcx_mdct_window_length - i - 1], 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_windowFB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_windowFB_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_windowFB[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_windowFB_flt[st->hTcxCfg->tcx_mdct_window_lengthFB - i - 1], 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_trans[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_trans_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_window_trans[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_trans_flt[st->hTcxCfg->tcx_mdct_window_trans_length - i - 1], 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_transFB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_transFB_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_window_transFB[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_transFB_flt[st->hTcxCfg->tcx_mdct_window_trans_lengthFB - i - 1], 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_half[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_half_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_window_half[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_half_flt[st->hTcxCfg->tcx_mdct_window_half_length - i - 1], 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_halfFB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_halfFB_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_window_halfFB[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_halfFB_flt[st->hTcxCfg->tcx_mdct_window_half_lengthFB - i - 1], 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_minimum[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_minimum_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_window_minimum[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_minimum_flt[st->hTcxCfg->tcx_mdct_window_min_length - i - 1], 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i], 15 ); - st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_mdct_window_minimumFB_flt[st->hTcxCfg->tcx_mdct_window_min_lengthFB - i - 1], 15 ); - } - Word16 n = st->L_frame; - Word16 n0 = shr( imult1616( n, 9 ), 5 ); - Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[i], 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_trunc[n1 - n / 2 - 1 - i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[n / 2 + i], 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_flt[i], 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_flt[i], 15 ); - } - n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); - n0 = shr( imult1616( n, 9 ), 5 ); - n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i], 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); - } - } - IF ( st->hTcxDec ) - { - Q_old_syn_Overl = Q_factor_arr( st->hTcxDec->old_syn_Overl_float, L_FRAME32k / 2 ) - 1; - Q_syn_Overl_TDAC = Q_factor_arr( st->hTcxDec->syn_Overl_TDAC_float, L_FRAME32k / 2 ) - 1; - Q_syn_Overl = Q_factor_arr( st->hTcxDec->syn_Overl_float, L_FRAME32k / 2 ) - 1; - Q_syn_Overl_TDACFB = Q_factor_arr( st->hTcxDec->syn_Overl_TDACFB_float, L_FRAME32k / 2 ); - Q_syn_OverlFB = Q_factor_arr( st->hTcxDec->syn_OverlFB_float, L_FRAME_MAX / 2 ); - Q_old_synth = Q_syn; - Q_synth_history = Q_factor_arr( st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX ); - floatToFixed_arr( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, Q_old_syn_Overl, L_FRAME32k / 2 ); - floatToFixed_arr( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, Q_syn_Overl_TDAC, L_FRAME32k / 2 ); - floatToFixed_arr( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, Q_syn_Overl, L_FRAME32k / 2 ); - floatToFixed_arr( st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, Q_syn_Overl_TDACFB, L_FRAME_MAX / 2 ); - floatToFixed_arr( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, Q_syn_OverlFB, L_FRAME_MAX / 2 ); - floatToFixed_arr( st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); - floatToFixed_arr( st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, Q_synth_history, L_PROT48k + L_FRAME_MAX ); - st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); - st->output_frame_fx = st->hTcxDec->L_frameTCX; - st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = (Word16) floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, 15 ); - st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, 14 ); - st->hTcxDec->LastFrameLevel_bfi_fx = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 ); - FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16)floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); - } - st->hTcxDec->cummulative_damping_tcx = (Word16)floatToFixed( st->hTcxDec->cummulative_damping_tcx_float, 15 ); - } - IF ( st->hHQ_core ) - { - Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; - Q_old_out = Q_factor_arr( st->hHQ_core->old_out, L_FRAME48k ); - Q_old_outLB = Q_factor_arrL( st->hHQ_core->old_outLB, L_FRAME32k ); - floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); - floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, Q_old_out, L_FRAME48k ); - floatToFixed_arrL( st->hHQ_core->old_outLB, st->hHQ_core->old_outLB_fx, Q_old_outLB, L_FRAME32k ); - } - IF ( st->cldfbAna ) - { - Q_cldfbAna_cldfb_state = Q_factor_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_length )-1; - floatToFixed_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q_cldfbAna_cldfb_state, st->cldfbAna->cldfb_state_length ); - } - IF ( st->cldfbBPF ) - { - Q_cldfbBPF_cldfb_state = Q_factor_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_length )-1; - floatToFixed_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q_cldfbBPF_cldfb_state, st->cldfbBPF->cldfb_state_length ); - } - IF ( st->cldfbSyn ) - { - Q_cldfbSyn_cldfb_state = Q_factor_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_length )-1; - floatToFixed_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q_cldfbSyn_cldfb_state, st->cldfbSyn->cldfb_state_length ); - } - IF ( st->cldfbSynHB ) - { - Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length )-1; - floatToFixed_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); - } - floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q_old_Aq_12_8, M + 1 ); - st->tilt_code_fx = (Word16) floatToFixed( st->tilt_code, 15 ); - IF ( st->hBPF ) - { - Q_pst_old_syn = Q_syn; - Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); - floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, Q_pst_old_syn, NBPSF_PIT_MAX ); - } - IF ( st->hPFstat ) - { - Q_mem_stp = Q_factor_arr( st->hPFstat->mem_stp_flt, L_SUBFR ) - 1; - Q_mem_pf_in = Q_factor_arr( st->hPFstat->mem_pf_in_flt, L_SUBFR ) - 1; - Q_mem_res2 = Q_factor_arr( st->hPFstat->mem_res2_flt, DECMEM_RES2 ) - 1; - floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, Q_mem_stp, L_SUBFR ); - floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, Q_mem_pf_in, L_SUBFR ); - floatToFixed_arr( st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, Q_mem_res2, DECMEM_RES2 ); - st->hPFstat->gain_prec = (Word16)floatToFixed( st->hPFstat->gain_prec_flt, 14 ); // 1.f - } - Word16 Q_lsf_cng = Q_factor( 6400 ); - floatToFixed_arr( st->lsf_cng_float, st->lsf_cng, Q_lsf_cng, M ); - st->last_concealed_gain_syn_deemph = (Word16) floatToFixed( st->last_concealed_gain_syn_deemph_float, 14 ); - Word16 Q_old_enr_LP = Q_factor( st->old_enr_LP_float ); - st->old_enr_LP = (Word16) floatToFixed( st->old_enr_LP_float, Q_old_enr_LP ); - st->enr_old_fx = (Word16) floatToFixed( st->enr_old, 0 ); - floatToFixed_arr( st->previoussynth, st->previoussynth_fx, 0, 960 ); - Word16 Q_tcxltp_mem_in=0, Q_tcxltp_mem_out=0, Q_tcxltp_gain_post_prev=0; - IF ( st->hTcxLtpDec ) - { - Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); - Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); - st->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) floatToFixed( st->hTcxLtpDec->tcxltp_gain_post_prev_float, Q_tcxltp_gain_post_prev ); - floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_in_float, st->hTcxLtpDec->tcxltp_mem_in, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); - floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_out_float, st->hTcxLtpDec->tcxltp_mem_out, Q_tcxltp_mem_out, L_FRAME48k ); - } - - Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ) - 1; - floatToFixed_arr( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); - TD_BWE_DEC_HANDLE hBWE_TD = st->hBWE_TD; - Word16 Q_old_bwe_exc = 0, Q_bwe_non_lin_prev_scale = 0, Q_mem_genSHBexc_filt_down_wb2 = 0, Q_mem_genSHBexc_filt_down_wb3 = 0, Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_mem_genSHBexc_filt_down_shb = 0, Q_syn_overlap = 0, Q_mem_csfilt = 0, Q_tbe_demph = 0, Q_tbe_premph = 0, Q_gain_prec_swb = 0, Q_GainShape_Delay = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0, Q_prev_fb_ener_adjust = 0, Q_fb_state_lpc_syn = 0, Q_fbbwe_hpf_mem = 0, Q_prev_fbbwe_ratio = 0, Q_fb_tbe_demph = 0, - Q_genSHBsynth_Hilbert_Mem=0, Q_genSHBsynth_state_lsyn_filt_shb_local=0; - IF ( hBWE_TD ) - { - Q_old_bwe_exc = Q_factor_arr( hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); - floatToFixed_arr( hBWE_TD->old_bwe_exc, hBWE_TD->old_bwe_exc_fx, Q_old_bwe_exc, PIT16k_MAX * 2 ); - Q_bwe_non_lin_prev_scale = Q_factor_L( hBWE_TD->bwe_non_lin_prev_scale ); - hBWE_TD->bwe_non_lin_prev_scale_fx = floatToFixed( hBWE_TD->bwe_non_lin_prev_scale, Q_bwe_non_lin_prev_scale ); - Q_mem_genSHBexc_filt_down_wb2 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, 7 ); - floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, Q_mem_genSHBexc_filt_down_wb2, 7 ); - Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); - floatToFixed_arr( hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_shb_fx, Q_state_lsyn_filt_shb, 6 ); - Q_mem_genSHBexc_filt_down_wb3 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, 7 ); - floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, Q_mem_genSHBexc_filt_down_wb3, 7 ); - Q_state_lsyn_filt_dwn_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_dwn_shb, 6 ); - floatToFixed_arr( hBWE_TD->state_lsyn_filt_dwn_shb, hBWE_TD->state_lsyn_filt_dwn_shb_fx, Q_state_lsyn_filt_dwn_shb, 6 ); - Q_mem_resamp_HB = Q_factor_arr( hBWE_TD->mem_resamp_HB, 13 ); - floatToFixed_arr( hBWE_TD->mem_resamp_HB, hBWE_TD->mem_resamp_HB_fx, Q_mem_resamp_HB, 13 ); - hBWE_TD->prev_pow_exc16kWhtnd_fx = (Word16) floatToFixed( hBWE_TD->prev_pow_exc16kWhtnd, 15 ); - hBWE_TD->prev_mix_factor_fx = (Word16) floatToFixed( hBWE_TD->prev_mix_factor, 15 ); - Q_mem_genSHBexc_filt_down_shb = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, 7 ); - floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, Q_mem_genSHBexc_filt_down_shb, 7 ); - Q_state_lpc_syn = Q_factor_arr( hBWE_TD->state_lpc_syn, 10 ); - floatToFixed_arr( hBWE_TD->state_lpc_syn, hBWE_TD->state_lpc_syn_fx, Q_state_lpc_syn, 10 ); - Q_state_syn_shbexc = Q_factor_arr( hBWE_TD->state_syn_shbexc, 20 ); - floatToFixed_arr( hBWE_TD->state_syn_shbexc, hBWE_TD->state_syn_shbexc_fx, Q_state_syn_shbexc, 20 ); - Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); - floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, Q_syn_overlap, 20 ); - Q_mem_csfilt = Q_factor_arrL( hBWE_TD->mem_csfilt, 2 ); - floatToFixed_arrL( hBWE_TD->mem_csfilt, hBWE_TD->mem_csfilt_fx, Q_mem_csfilt, 2 ); - Q_tbe_demph = Q_factor( (Word16) hBWE_TD->tbe_demph ); - Q_tbe_premph = Q_factor( (Word16) hBWE_TD->tbe_premph ); - Q_gain_prec_swb = Q_factor( (Word16) hBWE_TD->gain_prec_swb ); - Q_mem_stp_swb = Q_factor_arr( hBWE_TD->mem_stp_swb, 10 ); - Q_GainShape_Delay = Q_factor_arr( hBWE_TD->GainShape_Delay, 8 ); - Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); - Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); - Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); - Q_fbbwe_hpf_mem = Q_factor_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], 16 ); - Q_prev_fbbwe_ratio = Q_factor( (Word16) hBWE_TD->prev_fbbwe_ratio ); - st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); - floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, Q_fb_state_lpc_syn, 10 ); - floatToFixed_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], &hBWE_TD->fbbwe_hpf_mem_fx[0][0], Q_fbbwe_hpf_mem, 16 ); - hBWE_TD->prev_fbbwe_ratio_fx = (Word16) floatToFixed( hBWE_TD->prev_fbbwe_ratio, Q_prev_fbbwe_ratio ); - Q_fb_tbe_demph = Q_factor( (Word16) hBWE_TD->fb_tbe_demph ); - hBWE_TD->fb_tbe_demph_fx = (Word16) floatToFixed( hBWE_TD->fb_tbe_demph, Q_fb_tbe_demph ); - hBWE_TD->tbe_demph_fx = (Word16) floatToFixed( hBWE_TD->tbe_demph, Q_tbe_demph ); - hBWE_TD->tbe_premph_fx = (Word16) floatToFixed( hBWE_TD->tbe_premph, Q_tbe_premph ); - hBWE_TD->gain_prec_swb_fx = (Word16) floatToFixed( hBWE_TD->gain_prec_swb, 14 ); - floatToFixed_arr( hBWE_TD->GainShape_Delay, st->GainShape_Delay, Q_GainShape_Delay, 8 ); - floatToFixed_arr( hBWE_TD->int_3_over_2_tbemem_dec, hBWE_TD->int_3_over_2_tbemem_dec_fx, Q_int_3_over_2_tbemem_dec, INTERP_3_2_MEM_LEN ); - floatToFixed_arr( hBWE_TD->mem_resamp_HB_32k, hBWE_TD->mem_resamp_HB_32k_fx, Q_mem_resamp_HB_32k, 7 ); - Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); - floatToFixed_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, Q_genSHBsynth_Hilbert_Mem, 21 ); - Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); - floatToFixed_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, Q_genSHBsynth_state_lsyn_filt_shb_local, 6 ); - floatToFixed_arr( hBWE_TD->mem_stp_swb, hBWE_TD->mem_stp_swb_fx, Q_mem_stp_swb, 10 ); - Q_mem_zero_swb = Q_factor_arr( hBWE_TD->mem_zero_swb, LPC_SHB_ORDER ); - floatToFixed_arr( hBWE_TD->mem_zero_swb, hBWE_TD->mem_zero_swb_fx, Q_mem_zero_swb, LPC_SHB_ORDER ); - } - IF ( st->hTECDec ) - { - Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); - floatToFixed_arr( st->hTECDec->loBuffer_flt, st->hTECDec->loBuffer, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); - } - st->TcxBandwidth = (Word16)floatToFixed( st->TcxBandwidth_float, 15 ); -#endif // Float to fixed conversions end here Word16 start_bit_pos, bits_common; CONTEXT_HM_CONFIG hm_cfg; Word16 indexBuffer[N_MAX + 1]; @@ -1792,338 +2405,14 @@ static void dec_prm_tcx_ivas_fx( /* possible need for reconfiguration can only be decided correctly once last_core_from_bs has been decoded */ IF( NE_16( st->last_core, st->last_core_from_bs ) && ( NE_16( st->last_core_from_bs, TCX_20_CORE ) && NE_16( st->last_core_from_bs, TCX_10_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) ) { - stereo_tcx_dec_mode_switch_reconf_ivas_fx( st, 0, last_element_mode, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); -#if 1 /*Fixed to float changes */ - hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; - fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); - hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); - hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); - hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); - hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; - fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); - hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); - hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); - hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); - hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; - fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); - hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); - hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); - hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); - IF ( st->hIGFDec ) - { - st->hIGFDec->virtualSpec_float = &st->hIGFDec->virtualSpecBuf[0]; -#ifdef IVAS_FLOAT_FIXED - st->hIGFDec->virtualSpec_fx = &st->hIGFDec->virtualSpec[0]; -#endif - st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; - st->hIGFDec->igfData.igfInfo.nfSeed = &st->hIGFDec->igfData.igfInfo.nfSeedBuf[0]; - } - st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); - st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); - IF( EQ_32( st->sr_core, INT_FS_16k ) ) - { - st->gamma_float = GAMMA16k_FLT; - move16(); - } - ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - st->gamma_float = GAMMA16k_FLT; - move16(); - } - ELSE - { - st->gamma_float = GAMMA1_FLT; - move16(); - } - IF( st->hBWE_TD != NULL ) - { - fixedToFloat_arr( st->hBWE_TD->prev_lsf_diff_fx, st->hBWE_TD->prev_lsf_diff, 15, LPC_SHB_ORDER - 2 ); - st->hBWE_TD->prev_tilt_para = 0.0f; - fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, 15, M + 1 ); - fixedToFloat_arr( hBWE_TD->old_bwe_exc_fx, hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( hBWE_TD->bwe_non_lin_prev_scale_fx, Q_bwe_non_lin_prev_scale ); - fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2, Q_mem_genSHBexc_filt_down_wb2, 7 ); - fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3, Q_mem_genSHBexc_filt_down_wb3, 7 ); - fixedToFloat_arr( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb, Q_state_lsyn_filt_shb, 6 ); - fixedToFloat_arr( hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb, Q_state_lsyn_filt_dwn_shb, 6 ); - fixedToFloat_arr( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB, Q_mem_resamp_HB, 13 ); - fixedToFloat_arr( hBWE_TD->state_syn_shbexc_fx, hBWE_TD->state_syn_shbexc, Q_state_syn_shbexc, 20 ); - fixedToFloat_arrL( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_csfilt, Q_mem_csfilt, 2 ); - fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_shb, Q_mem_genSHBexc_filt_down_shb, 7 ); - fixedToFloat_arr( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap, Q_syn_overlap, 20 ); - fixedToFloat_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, Q_genSHBsynth_state_lsyn_filt_shb_local, HILBERT_MEM_SIZE ); - fixedToFloat_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem, Q_genSHBsynth_Hilbert_Mem, HILBERT_MEM_SIZE ); - hBWE_TD->tbe_demph = fixedToFloat( hBWE_TD->tbe_demph_fx, Q_tbe_demph ); - hBWE_TD->tbe_premph = fixedToFloat( hBWE_TD->tbe_premph_fx, Q_tbe_premph ); - fixedToFloat_arr( st->GainShape_Delay, hBWE_TD->GainShape_Delay, Q_GainShape_Delay, 8 ); - fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); - fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); - hBWE_TD->prev_pow_exc16kWhtnd = fixedToFloat( hBWE_TD->prev_pow_exc16kWhtnd_fx, 15 ); - hBWE_TD->prev_mix_factor = fixedToFloat( hBWE_TD->prev_mix_factor_fx, 15 ); - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); - hBWE_TD->fb_tbe_demph = fixedToFloat( hBWE_TD->fb_tbe_demph_fx, Q_fb_tbe_demph ); - fixedToFloat_arrL( &hBWE_TD->fbbwe_hpf_mem_fx[0][0], &hBWE_TD->fbbwe_hpf_mem[0][0], Q_fbbwe_hpf_mem, 16 ); - hBWE_TD->prev_fbbwe_ratio = fixedToFloat( hBWE_TD->prev_fbbwe_ratio_fx, Q_prev_fbbwe_ratio ); - fixedToFloat_arr( hBWE_TD->state_lpc_syn_fx, hBWE_TD->state_lpc_syn, Q_state_lpc_syn, LPC_SHB_ORDER ); - fixedToFloat_arr( hBWE_TD->state_syn_shbexc_fx, hBWE_TD->state_syn_shbexc, Q_state_syn_shbexc, L_SHB_LAHEAD ); - fixedToFloat_arr( hBWE_TD->mem_stp_swb_fx, hBWE_TD->mem_stp_swb, Q_mem_stp_swb, LPC_SHB_ORDER ); - fixedToFloat_arr( hBWE_TD->mem_zero_swb_fx, hBWE_TD->mem_zero_swb, Q_mem_zero_swb, LPC_SHB_ORDER ); - hBWE_TD->gain_prec_swb = fixedToFloat( hBWE_TD->gain_prec_swb_fx, 14 ); - } - - IF( st->hTECDec != NULL ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - st->hTECDec->pGainTemp[i] = 0; - } - fixedToFloat_arr( st->hTECDec->loBuffer, st->hTECDec->loBuffer_flt, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); - } - IF( st->hTcxCfg ) - { - st->hTcxCfg->preemph_fac_flt = fixedToFloat( st->hTcxCfg->preemph_fac, 15 ); - st->hTcxCfg->sq_rounding_flt = fixedToFloat( st->hTcxCfg->sq_rounding, 15 ); - st->hTcxCfg->bandwidth_flt = fixedToFloat( st->hTcxCfg->bandwidth, 15 ); - st->hTcxCfg->na_scale_flt = fixedToFloat( st->hTcxCfg->na_scale, 15 ); - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_flt[st->hTcxCfg->tcx_mdct_window_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window[i].v.re, 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_windowFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_windowFB[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_windowFB_flt[st->hTcxCfg->tcx_mdct_window_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_windowFB[i].v.re, 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_trans_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_trans[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_trans_flt[st->hTcxCfg->tcx_mdct_window_trans_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_trans[i].v.re, 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_transFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_transFB[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_transFB_flt[st->hTcxCfg->tcx_mdct_window_trans_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_transFB[i].v.re, 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_half_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_half[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_half_flt[st->hTcxCfg->tcx_mdct_window_half_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_half[i].v.re, 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_halfFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_halfFB[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_halfFB_flt[st->hTcxCfg->tcx_mdct_window_half_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_halfFB[i].v.re, 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_length / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_minimum_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimum[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_minimum_flt[st->hTcxCfg->tcx_mdct_window_min_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimum[i].v.re, 15 ); - } - FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_lengthFB / 2; i++ ) - { - st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.im, 15 ); - st->hTcxCfg->tcx_mdct_window_minimumFB_flt[st->hTcxCfg->tcx_mdct_window_min_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re, 15 ); - } - Word16 n = st->L_frame; - Word16 n0 = shr( imult1616( n, 9 ), 5 ); - Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_trunc[i - n0].v.im, 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_trunc[n1 - n / 2 - 1 - i].v.re, 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2[i].v.im, 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2[n2 - i - 1].v.re, 15 ); - } - n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); - n0 = shr( imult1616( n, 9 ), 5 ); - n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ - n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ - FOR( i = 0; i < n0; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB[i], 15 ); - } - FOR( i = n0; i < n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im, 15 ); - } - FOR( i = 0; i < n1 - n / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re, 15 ); - } - FOR( i = 0; i < n2 / 2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im, 15 ); - } - FOR( i = n2 / 2; i < n2; i++ ) - { - st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re, 15 ); - } - st->hTcxCfg->tcx_aldo_window_1_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_flt + NS2SA( st->sr_core, N_ZERO_MDCT_NS ); - st->hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ); - } - IF ( st->hTcxDec ) - { - fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); - fixedToFloat_arr( st->hTcxDec->syn_Overl_TDAC, st->hTcxDec->syn_Overl_TDAC_float, Q_syn_Overl_TDAC, 320 ); - fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, Q_syn_Overl, 320 ); - fixedToFloat_arr( st->hTcxDec->syn_Overl_TDACFB, st->hTcxDec->syn_Overl_TDACFB_float, Q_syn_Overl_TDACFB, 480 ); - fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, Q_syn_OverlFB, 480 ); - fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); - fixedToFloat_arr( st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, Q_synth_history, L_PROT48k + L_FRAME_MAX ); - fixedToFloat_arr( st->hTcxDec->ltpGainMemory_fx, st->hTcxDec->ltpGainMemory, 0, N_LTP_GAIN_MEMS ); - st->hTcxDec->tcxltp_second_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_second_last_pitch, 16 ); - st->hTcxDec->tcxltp_third_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_third_last_pitch, 16 ); - st->hTcxDec->old_gaintcx_bfi_float = 0; - st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, 14 ); - st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, 15 ); - st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->LastFrameLevel_bfi_fx, 15 ); - FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); - } - st->hTcxDec->cummulative_damping_tcx_float = fixedToFloat( st->hTcxDec->cummulative_damping_tcx, 15 ); - } - fixedToFloat_arr( st->syn, st->syn_float, Q_syn, M + 1 ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, L_EXC_MEM_DEC ); - fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn_r, L_SYN_MEM ); - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, 15, M ); - fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn2, M ); - fixedToFloat_arr( st->lspold_uw, st->lspold_uw_float, 15, M ); - FOR( i = 0; i < M; i++ ) - { - st->mem_AR[i] = fixedToFloat( L_mult( st->mem_AR_fx[i], 100 ), 9 ); - st->mem_MA[i] = fixedToFloat( L_mult( st->mem_MA_fx[i], 100 ), 9 ); - st->lsfold_uw_float[i] = fixedToFloat( L_mult( st->lsfold_uw[i], 100 ), 9 ); - st->lsf_old[i] = fixedToFloat( L_mult( st->lsf_old_fx[i], 100 ), 9 ); - } - IF ( st->hHQ_core ) - { - fixedToFloat_arr( st->hHQ_core->old_out_fx, st->hHQ_core->old_out, Q_old_out, L_FRAME48k ); - fixedToFloat_arr( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_outLB, Q_old_outLB, L_FRAME32k ); - } - IF ( st->cldfbAna ) - { - Q_cldfbAna_cldfb_state = Q_factor_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_length )-1; - fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q_cldfbAna_cldfb_state, st->cldfbAna->cldfb_state_length ); - } - IF ( st->cldfbBPF ) - { - Q_cldfbBPF_cldfb_state = Q_factor_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_length )-1; - fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q_cldfbBPF_cldfb_state, st->cldfbBPF->cldfb_state_length ); - } - IF ( st->cldfbSyn ) - { - Q_cldfbSyn_cldfb_state = Q_factor_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_length )-1; - fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q_cldfbSyn_cldfb_state, st->cldfbSyn->cldfb_state_length ); - } - IF ( st->cldfbSynHB ) - { - Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length )-1; - fixedToFloat_arrL( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); - } - fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q_old_Aq_12_8, M + 1 ); - st->tilt_code = fixedToFloat( st->tilt_code_fx, 15 ); - IF ( st->hBPF ) - { - fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); - st->hBPF->pst_mem_deemp_err = 0; - } - IF ( st->hPFstat ) - { - fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, Q_mem_stp, L_SUBFR ); - fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, Q_mem_pf_in, L_SUBFR ); - fixedToFloat_arr( st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, Q_mem_res2, DECMEM_RES2 ); - st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, 14 ); // 1.f - } - fixedToFloat_arr( st->lsf_cng, st->lsf_cng_float, Q_lsf_cng, M ); - st->past_gpit_float = fixedToFloat( st->past_gpit, 0 ); - st->past_gcode_float = fixedToFloat( st->past_gcode, 0 ); - st->gc_threshold = fixedToFloat( st->gc_threshold_fx, 0 ); - fixedToFloat_arr( st->lspold_cng, st->lspold_cng_float, 15, M ); - fixedToFloat_arr( st->Aq_cng, st->Aq_cng_float, 2, M ); - FOR( i = 0; i < M; i++ ) - { - st->lsf_q_cng_float[i] = fixedToFloat( L_mult( st->lsf_q_cng[i], 100 ), 9 ); - st->old_lsf_q_cng_float[i] = fixedToFloat( L_mult( st->old_lsf_q_cng[i], 100 ), 9 ); - } - fixedToFloat_arr( st->lsp_q_cng, st->lsp_q_cng_float, 15, M ); - fixedToFloat_arr( st->old_lsp_q_cng, st->old_lsp_q_cng_float, 15, M ); - fixedToFloat_arr( st->mem_syn_unv_back, st->mem_syn_unv_back_float, 0, M ); - fixedToFloat_arr( st->mem_Aq, st->mem_Aq_float, 0, NB_SUBFR16k * ( M + 1 ) ); - st->last_gain_syn_deemph_float = 1; - st->last_concealed_gain_syn_deemph_float = fixedToFloat( st->last_concealed_gain_syn_deemph, 14 ); - st->lp_ener_bfi = fixedToFloat( st->lp_ener_FER_fx, 8 ); - FOR( i = 0; i < M; i++ ) - { - st->lsf_adaptive_mean[i] = fixedToFloat( L_mult( st->lsf_adaptive_mean_fx[i], 100 ), 9 ); - st->lsfoldbfi0[i] = fixedToFloat( L_mult( st->lsfoldbfi0_fx[i], 100 ), 9 ); - st->lsfoldbfi1[i] = fixedToFloat( L_mult( st->lsfoldbfi1_fx[i], 100 ), 9 ); - } - st->old_enr_LP_float = fixedToFloat( st->old_enr_LP, Q_old_enr_LP ); - st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); - st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 0 ); - st->lp_gainp = fixedToFloat( st->lp_gainp_fx, 0 ); - st->cummulative_damping_float = 1; - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - st->old_pitch_buf[i] = fixedToFloat( st->old_pitch_buf_fx[i], 16 ); - } - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - st->mem_pitch_gain_float[i] = 1; - } - st->old_fpitch_float = fixedToFloat( st->old_fpitch, 16 ); - FOR( i = 0; i < 8; i++ ) - { - st->dispMem[i] = 0; - } - st->voice_fac_float = st->voice_fac; /* purely unvoiced */ - IF( st->hTcxLtpDec != NULL ) - { - fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); - fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, Q_tcxltp_mem_out, L_FRAME48k ); - st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, Q_tcxltp_gain_post_prev ); - } - IF ( st->hTonalMDCTConc ) - { - FOR( i = 0; i < FDNS_NPTS; i++ ) - { - st->hTonalMDCTConc->scaleFactorsBackground_flt[i] = fix16_to_float( st->hTonalMDCTConc->scaleFactorsBackground[i], 15 ); - } - } - IF ( st->hPlcInfo ) - { - FOR( i = 0; i < L_FRAME_MAX; i++ ) - { - st->hPlcInfo->data_reci2[i] = fixedToFloat( st->hPlcInfo->data_reci2_fx[i], 0 ); - } - } - st->old_fpitchFB_float = fixedToFloat( st->old_fpitchFB, 16 ); - ACELP_config *pConfigAcelp = &( st->acelp_cfg ); - IF( pConfigAcelp != NULL ) - { - pConfigAcelp->formant_enh_num_flt = fixedToFloat( pConfigAcelp->formant_enh_num, 15 ); - pConfigAcelp->formant_enh_den_flt = fixedToFloat( pConfigAcelp->formant_enh_den, 15 ); - st->acelp_cfg_rf.formant_enh_num_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_num, 15 ); - st->acelp_cfg_rf.formant_enh_den_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_den, 15 ); - fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); - } -#endif // Ends + Word16 Q_old_Aq_12_8 = Q12; + stereo_tcx_dec_mode_switch_reconf_ivas_fx( st, 0, last_element_mode, &st->hTcxDec->Q_syn_Overl_TDAC, + &st->hHQ_core->Q_fer_samples, + &st->hTcxDec->Q_syn_Overl, + &st->hTcxDec->Q_syn_Overl_TDACFB, + &st->hTcxDec->Q_syn_OverlFB, + &st->hHQ_core->Q_old_out, + &st->hHQ_core->Q_old_outLB, &Q_old_Aq_12_8 ); } st->last_core = st->last_core_from_bs; diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index afec6309d..0d3532e59 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -682,10 +682,16 @@ void lsf_end_dec_fx( else #endif { - ber_flag = vq_dec_lvq_fx(1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0]); - + if ( st->element_mode != EVS_MONO ) + { + ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); + } + else + { + ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + } st->BER_detect = s_or(st->BER_detect, ber_flag); Vr_add(qlsf, pred0, qlsf, M); Vr_subt(qlsf, pred1, st->mem_MA_fx, M); @@ -701,10 +707,16 @@ void lsf_end_dec_fx( move16(); move16(); } #endif - ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1-1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0]); - + if ( st->element_mode != EVS_MONO ) + { + ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + } + else + { + ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + } st->BER_detect = s_or(st->BER_detect, ber_flag); #ifdef LSF_RE_USE_SECONDARY_CHANNEL test(); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index b7867342a..d1c1acd7f 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -317,10 +317,10 @@ typedef struct typedef struct { - Word16 numIndexes; - Word16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; - Word16 lowerIndex[MAX_NUMBER_OF_IDX]; - Word16 upperIndex[MAX_NUMBER_OF_IDX]; + UWord16 numIndexes; + UWord16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; + UWord16 lowerIndex[MAX_NUMBER_OF_IDX]; + UWord16 upperIndex[MAX_NUMBER_OF_IDX]; Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ @@ -613,19 +613,19 @@ typedef struct tcx_dec_structure float old_syn_Overl_float[L_FRAME32k / 2]; Word16 old_syn_Overl[L_FRAME32k / 2]; Word32 old_syn_Overl_32[L_FRAME32k / 2]; - + Word16 Q_old_syn_Overl; float syn_Overl_TDAC_float[L_FRAME32k / 2]; Word16 syn_Overl_TDAC[L_FRAME32k / 2]; - + Word16 Q_syn_Overl_TDAC; float syn_Overl_TDACFB_float[L_FRAME_MAX / 2]; Word16 syn_Overl_TDACFB[L_FRAME_MAX / 2]; - + Word16 Q_syn_Overl_TDACFB; float syn_Overl_float[L_FRAME32k / 2]; Word16 syn_Overl[L_FRAME32k / 2]; - + Word16 Q_syn_Overl; float syn_OverlFB_float[L_FRAME_MAX / 2]; Word16 syn_OverlFB[L_FRAME_MAX / 2]; - + Word16 Q_syn_OverlFB; float FBTCXdelayBuf_float[111]; /* 2.3125ms at 48kHz -> 111 samples */ Word16 FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ Word32 FBTCXdelayBuf_32[111]; /* 2.3125ms at 48kHz -> 111 samples */ @@ -704,25 +704,25 @@ typedef struct gsc_dec_structure Word16 cor_strong_limit_fx; /* AC mode (GSC) - Indicator about high spectral correlation per band */ float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ - Word16 old_y_gain_fx[MBANDS_GN]; /* AC mode (GSC) - AR mem for low rate gain quantization */ + Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ int16_t noise_lev; /* AC mode (GSC) - noise level */ Word16 noise_lev_fx; /* AC mode (GSC) - noise level Q0*/ float lt_ener_per_band[MBANDS_GN16k]; - Word16 lt_ener_per_band_fx[MBANDS_GN]; /* Q12 */ + Word16 lt_ener_per_band_fx[MBANDS_GN16k]; /* Q12 */ float Last_frame_ener; /* AC mode (GSC) - last frame energy */ Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */ float Last_GSC_spectrum[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ - Word16 Last_GSC_spectrum_fx[L_FRAME]; /* AC mode (GSC) - Last good GSC spectrum */ + Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ Word16 Last_GSC_pit_band_idx_fx; /* AC mode (GSC) - Last pitch band index Q0*/ float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ - Word16 last_exc_dct_in_fx[L_FRAME]; /* AC mode (GSC) - previous excitation */ + Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ float last_ener; /* AC mode (GSC) - previous energy */ Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ @@ -929,8 +929,13 @@ typedef struct td_cng_dec_structure /* SWB DTX/CNG parameters */ float shb_cng_ener; + float shb_lpcCNG[LPC_SHB_ORDER + 1]; + Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; /* Assumed in Q12 */ + float shb_cng_gain; + Word16 shb_cng_gain_fx; /* Assumed in Q8 */ + float wb_cng_ener; float last_wb_cng_ener; float last_shb_cng_ener; @@ -1108,12 +1113,14 @@ typedef struct hq_dec_structure Word32 oldOut_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ #endif Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + Word16 Q_old_out; #ifdef IVAS_FLOAT_FIXED Word16 exp_old_out; #endif float old_outLB[L_FRAME32k]; Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ + Word16 Q_old_outLB; #ifdef IVAS_FLOAT_FIXED Word32 old_outLB_fx[L_FRAME32k]; #endif @@ -1164,7 +1171,7 @@ typedef struct hq_dec_structure float fer_samples[L_FRAME48k]; Word16 fer_samples_fx[L_FRAME48k]; - + Word16 Q_fer_samples; float prev_normq[SFM_N_WB]; /* previous norms */ Word32 prev_normq_fx[SFM_N_WB]; /* Q14 */ /* previous norms */ @@ -1899,6 +1906,7 @@ typedef struct Decoder_State #ifdef IVAS_FLOAT_FIXED Word32 log_energy_diff_lt_fx;/*In range of word16*//*Q-15*/ Word32 stab_fac_smooth_lt_fx;/*In range of word16*//*Q-15*/ + Word32 log_energy_old_fx; #endif float log_energy_diff_lt; @@ -1971,6 +1979,7 @@ typedef struct Decoder_State //Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ float lp_ener_bfi; /* FEC - long-term active-signal average energy */ + Word16 lp_ener_bfi_fx; /* FEC - long-term active-signal average energy */ int16_t last_good; /* FEC - clas of last good received */ @@ -2516,6 +2525,10 @@ typedef struct Decoder_State /* LPC quantization */ int16_t lpcQuantization; +#ifdef IVAS_FLOAT_FIXED + Word16 prev_lpcQuantization; /*temporary check if for last frame lpcQuantization was set or not, to be removed */ + float scale; /*temporary for lpc_unquantize fixed point implementation, to be removed */ +#endif // IVAS_FLOAT_FIXED int16_t numlpc; /* Bandwidth */ diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index eeb3c833b..e84c61779 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -1531,7 +1531,25 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ * * Initialize HR BWE state structure at the decoder *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void hr_bwe_dec_init( + HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ +) +{ + set16_fx( hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / FRAMES_PER_SEC - NUM_NONTRANS_START_FREQ_COEF ); + set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ + hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; + move16(); + hBWE_FD_HR->bwe_highrate_seed_fx = 12345; + move16(); + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); + hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; + move16(); /* set to a high exponent */ + + return; +} +#else void hr_bwe_dec_init( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ) @@ -1549,3 +1567,4 @@ void hr_bwe_dec_init( return; } +#endif -- GitLab