From 6d3e7f826aaed57141f32f520f50c854040fa6a2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 11 Mar 2024 12:40:06 +0530 Subject: [PATCH] Add conversion changes for core_switching_pre_dec, ism-funcs [x] Add conversion changes for core_switching_pre_dec [x] BASOP updates for ism-funcs --- lib_com/cldfb.c | 79 +++ lib_com/cnst.h | 5 + lib_com/float_to_fix_ops.c | 43 +- lib_com/frame_ener.c | 2 +- lib_com/ivas_ism_com.c | 38 ++ lib_com/ivas_mc_com.c | 40 ++ lib_com/ivas_prot.h | 6 + lib_com/ivas_prot_fx.h | 5 + lib_com/ivas_stat_com.h | 2 + lib_com/prot.h | 20 + lib_com/prot_fx2.h | 2 + lib_com/stat_com.h | 4 + lib_dec/amr_wb_dec.c | 7 + lib_dec/core_switching_dec.c | 867 +++++++++++++++++++++++++++++++ lib_dec/core_switching_dec_fx.c | 6 +- lib_dec/dec_prm.c | 4 + lib_dec/evs_dec.c | 7 + lib_dec/hf_synth_fx.c | 8 +- lib_dec/hq_core_dec_fx.c | 8 +- lib_dec/init_dec_fx.c | 4 +- lib_dec/ivas_core_dec.c | 11 +- lib_dec/ivas_ism_param_dec.c | 7 + lib_dec/ivas_mct_dec.c | 33 ++ lib_dec/ivas_stereo_dft_dec.c | 186 +++++++ lib_dec/ivas_stereo_dft_dec_fx.c | 4 + lib_dec/ivas_tcx_core_dec.c | 4 +- lib_dec/stat_dec.h | 24 +- lib_rend/ivas_dirac_decorr_dec.c | 30 ++ lib_rend/ivas_reverb.c | 7 +- lib_rend/ivas_rom_rend.c | 13 + lib_rend/ivas_rom_rend.h | 1 + 31 files changed, 1447 insertions(+), 30 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 1ba4be6b6..5d66ffed2 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -2295,6 +2295,45 @@ static void cldfb_init_proto_and_twiddles( * * Save the memory of filter; to be restored with cldfb_restore_memory_ivas() *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error cldfb_save_memory_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +) +{ + UWord16 offset = sub(hs->p_filter_length , hs->no_channels); + + IF ( hs->memory_flt != NULL || NE_16(hs->memory_length , 0) ) + { + /* memory already stored; Free memory first */ + return IVAS_ERR_OK; + } + + IF ( EQ_16(hs->type , CLDFB_ANALYSIS) ) + { + hs->memory_length = offset; + move16(); + } + ELSE + { + hs->memory_length = hs->p_filter_length; + move16(); + } +#if 1/*Floating point memory allocation: To be removed later*/ + IF ( ( hs->memory_flt = (float *) malloc( hs->memory_length * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); + } +#endif + IF ( ( hs->memory32 = (Word32 *) malloc( hs->memory_length * sizeof(Word32) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); + } + /* save the memory */ + Copy32( hs->cldfb_state_fx, hs->memory32, hs->memory_length ); + + return IVAS_ERR_OK; +} +#endif // IVAS_FLOAT_FIXED ivas_error cldfb_save_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ @@ -2334,6 +2373,46 @@ ivas_error cldfb_save_memory_ivas( * * Restores the memory of filter; memory to be save by cldfb_save_memory_ivas() *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void cldfb_restore_memory_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +) +{ + UWord16 offset = sub(hs->p_filter_length , hs->no_channels); + UWord16 size; + IF ( hs->memory_flt == NULL || EQ_16(hs->memory_length , 0) ) + { + /* memory not allocated */ + return; + } + + IF ( EQ_16(hs->type , CLDFB_ANALYSIS) ) + { + size = offset; + move16(); + } + ELSE + { + size = hs->p_filter_length; + move16(); + } + + /* read the memory */ + Copy32( hs->memory32, hs->cldfb_state_fx, hs->memory_length ); + + /* adjust sample rate if it was changed in the meanwhile */ + IF ( NE_16(hs->memory_length , size) ) + { + L_lerp_fx_q11( hs->cldfb_state_fx, hs->cldfb_state_fx, size, hs->memory_length); + } + hs->cldfb_state_length = size; + hs->memory_length = 0; + free( hs->memory32 ); + hs->memory32 = NULL; + + return; +} +#endif // IVAS_FLOAT_FIXED void cldfb_restore_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ diff --git a/lib_com/cnst.h b/lib_com/cnst.h index c86b95e15..10a198e23 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -2081,6 +2081,11 @@ typedef enum _DCTTYPE #define ENV_STAB_EST1 2.93f /* env_stab estimation coefficient 1 */ #define ENV_STAB_EST2 (-2.20f) /* env_stab estimation coefficient 2 */ #define ENV_STAB_EST3 0.741f /* env_stab estimation coefficient 3 */ +#ifdef IVAS_FLOAT_FIXED +#define ENV_STAB_EST1_FX 12001 /* env_stab estimation coefficient 1 *//*Q-12*/ +#define ENV_STAB_EST2_FX (-9011) /* env_stab estimation coefficient 2 *//*Q-12*/ +#define ENV_STAB_EST3_FX 3035 /* env_stab estimation coefficient 3 *//*Q-12*/ +#endif // IVAS_FLOAT_FIXED #define STAB_FAC_EST1 1.093f /* stab_fac HQ estimation coefficient 1 */ #define STAB_FAC_EST2 (-5.84e-05f) /* stab_fac HQ estimation coefficient 2, including Q12 scaling */ #define STAB_FAC_EST3 0.125f /* stab_fac HQ estimation coefficient 3 */ diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 2eb615707..227672dd4 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -3,6 +3,7 @@ #include #include "options.h" #include "prot.h" +#include "prot_fx2.h" Word32 floatToFixed(float f, Word16 Q) { if (f == 1.0f && Q == Q15) @@ -12,7 +13,15 @@ Word32 floatToFixed(float f, Word16 Q) if (Q < 0) return (Word32)((float)(f) / (float)(((unsigned)1) << (-Q)) + (f >= 0 ? 0.5 : -0.5)); else - return (Word32)(f * (float)((unsigned int)1 << Q) + (f >= 0 ? 0.5 : -0.5)); + { + Word64 result_32; + result_32=(Word64)(f * (float)((unsigned int)1 << Q) + (f >= 0 ? 0.5 : -0.5)); + if (result_32 > MAX_32) + return MAX_32; + if (result_32 < MIN_32) + return MIN_32; + return (Word32)result_32; + } } float fixedToFloat(Word32 i, Word16 Q) @@ -42,6 +51,30 @@ void floatToFixed_arrL(float *f, Word32 *i, Word16 Q, Word16 l) #endif } } +void floatToFixed_arr16( float *f, Word16 *i, Word16 Q, Word16 l ) +{ + if ( Q <= 0 ) + { + floatToFixed_arr( f, i, Q, l ); + return; + } + for ( int j = 0; j < l; j++ ) + { + i[j] = float_to_fix16( f[j], Q ); + } +} +void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l ) +{ + if ( Q <= 0 ) + { + floatToFixed_arrL( f, i, Q, l ); + return; + } + for ( int j = 0; j < l; j++ ) + { + i[j] = float_to_fix( f[j], Q ); + } +} void floatToFixed_arr(float *f, Word16 *i, Word16 Q, Word16 l) { for (int j = 0; j < l; j++) @@ -80,14 +113,14 @@ Word16 Q_factor(float x) { Word16 Q = 15; if ( x >= 1 || x <= -1 ) - Q = norm_s((Word16)x); + Q = norm_s((Word16)abs(x)); return Q; } Word16 Q_factor_L(float x) { Word16 Q = 31; if ( x >= 1 || x <= -1 ) - Q = norm_l((Word32)x); + Q = norm_l((Word32)abs(x)); return Q; } Word16 Q_factor_arr(float *x, Word16 l) @@ -96,7 +129,7 @@ Word16 Q_factor_arr(float *x, Word16 l) for (int i = 0; i < l; i++) { if (x[i] >= 1 || x[i] <= -1) - Q = s_min(Q, norm_s((Word16)x[i])); + Q = s_min(Q, norm_s((Word16)abs(x[i]))); } return Q; } @@ -106,7 +139,7 @@ Word16 Q_factor_arrL(float *x, Word16 l) for (int i = 0; i < l; i++) { if (x[i] >= 1 || x[i] <= -1) - Q = s_min(Q, norm_l((Word32)x[i])); + Q = s_min(Q, norm_l((Word32)abs(x[i]))); } return Q; } diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c index a73fdd212..b4c2d4a3a 100644 --- a/lib_com/frame_ener.c +++ b/lib_com/frame_ener.c @@ -134,7 +134,7 @@ void fer_energy_fx( *enr = W_extract_h( W_tmp ); // Q = q_synth * 2 + shift - 32 enr_tmp = BASOP_Util_Divide3216_Scale( *enr, shr( L_frame, 1 ) /*Q0*/, &exp ); - *enr = L_shl( L_deposit_l( enr_tmp ), 5 ); + *enr = L_shr( L_deposit_l( enr_tmp ), (shift-32-exp-1)); } return; } diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 1e6d7e85c..be778b440 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -41,6 +41,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#include "prot_fx1.h" /*-----------------------------------------------------------------------* @@ -934,6 +935,43 @@ void ivas_param_ism_config( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_param_ism_config_fx( + PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ + const Word16 nchan_obj /* i : number of ISM channels */ +) +{ + Word16 i; + + hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; + move16(); + + FOR ( i = 0; i < hParamIsm->nbands; i++ ) + { + hParamIsm->nblocks[i] = MAX_PARAM_ISM_NBLOCKS; + move16(); + } + + /* for elevation zero compute the max azi quantization indices */ + FOR ( i = 0; i < nchan_obj; i++ ) + { + hParamIsm->last_az_diff[i] = 0; + move16(); + hParamIsm->last_az_sgn[i] = 1; + move16(); + hParamIsm->last_el_diff[i] = 0; + move16(); + hParamIsm->last_el_sgn[i] = 1; + move16(); + } + + hParamIsm->last_dmx_gain_fx = (Word16) 16384; + move16(); + set16_fx( hParamIsm->last_cardioid_left_fx, (Word16) 16384, MAX_NUM_OBJECTS ); + + return; +} +#endif /*--------------------------------------------------------------- * ivas_ism_mode_select() diff --git a/lib_com/ivas_mc_com.c b/lib_com/ivas_mc_com.c index 1d85cb665..611153373 100644 --- a/lib_com/ivas_mc_com.c +++ b/lib_com/ivas_mc_com.c @@ -136,6 +136,45 @@ MC_MODE ivas_mc_mode_select( * ---------------------------------------------------------------*/ /*! r : number of loudspeaker channels */ +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_mc_ls_setup_get_num_channels( + const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup */ +) +{ + Word16 nchan; + + nchan = 0; + move16(); + + SWITCH ( mc_ls_setup ) + { + case MC_LS_SETUP_5_1: + nchan = 6; + move16(); + BREAK; + case MC_LS_SETUP_7_1: + nchan = 8; + move16(); + break; + case MC_LS_SETUP_5_1_2: + nchan = 8; + move16(); + BREAK; + case MC_LS_SETUP_5_1_4: + nchan = 10; + move16(); + BREAK; + case MC_LS_SETUP_7_1_4: + nchan = 12; + move16(); + BREAK; + default: + assert( 0 && "LS Setup not supported or defined for MC mode!\n" ); + } + + return nchan; +} +#else int16_t ivas_mc_ls_setup_get_num_channels( const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup */ ) @@ -167,6 +206,7 @@ int16_t ivas_mc_ls_setup_get_num_channels( return nchan; } +#endif /*--------------------------------------------------------------- diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 775235c24..2190b6b1e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -716,9 +716,15 @@ MC_MODE ivas_mc_mode_select( ); /*! r: number of loudspeaker channels */ +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_mc_ls_setup_get_num_channels( + const MC_LS_SETUP mc_ls_setup /* i : loudspeaker setup (CICP) */ +); +#else int16_t ivas_mc_ls_setup_get_num_channels( const MC_LS_SETUP mc_ls_setup /* i : loudspeaker setup (CICP) */ ); +#endif /*! r: output configuration*/ AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 0a96208f4..f7e49d822 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1601,4 +1601,9 @@ Word16 ivas_wb_bwe_dec_fx( Word16 *voice_factors_fx, /* i : voicing factors */ const Word16 pitch_buf_fx[], /* i : pitch buffer */ Word16 *Qpost ); + +void ivas_param_ism_config_fx( + PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ + const Word16 nchan_obj /* i : number of ISM channels */ +); #endif diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index fe9c6ca9c..cbbe26c8a 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -853,6 +853,8 @@ typedef struct ivas_param_ism_data_structure float last_dmx_gain; float last_cardioid_left[MAX_NUM_OBJECTS]; + Word16 last_dmx_gain_fx; + Word16 last_cardioid_left_fx[MAX_NUM_OBJECTS]; } PARAM_ISM_CONFIG_DATA, *PARAM_ISM_CONFIG_HANDLE; diff --git a/lib_com/prot.h b/lib_com/prot.h index 7f92257c5..bc711de0c 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -5944,6 +5944,16 @@ ivas_error core_switching_post_dec( const int16_t nchan_out, /* i : number of output channels */ const int16_t last_element_mode /* i : element mode of previous frame */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error core_switching_pre_dec_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + 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 */ +); +#endif // IVAS_FLOAT_FIXED ivas_error core_switching_pre_dec( Decoder_State *st, /* i/o: decoder state structure */ @@ -9195,10 +9205,20 @@ void resampleCldfb_ivas( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ const int32_t newSamplerate /* i : new samplerate to operate */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error cldfb_save_memory_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +); +#endif // IVAS_FLOAT_FIXED ivas_error cldfb_save_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ); +#ifdef IVAS_FLOAT_FIXED +void cldfb_restore_memory_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +); +#endif // IVAS_FLOAT_FIXED void cldfb_restore_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 00e6cfe18..9dda9c2ae 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -85,6 +85,8 @@ Word16 Q_factor_arrL(float* x, Word16 l); Word32 floatToFixed( float f, Word16 Q); float fixedToFloat( Word32 i, Word16 Q); +void floatToFixed_arr16(float *f, Word16 *i, Word16 Q, Word16 l); +void floatToFixed_arr32(float *f, Word32 *i, Word16 Q, Word16 l); // Float to 32-bit Mantissa and Exponent using frexp void f2me(float n, Word32 *mantissa, Word16 *expo); // 32-bit Mantissa and Exponent to Float using ldexp diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index e3f1ea035..31399a4dd 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -757,6 +757,9 @@ typedef struct cldfb_filter_bank_struct /* memory helper states */ float *memory_flt; Word16 *memory; +#ifdef IVAS_FLOAT_FIXED + Word32 *memory32;/*because cldfb_state_fx is word32 which is used to assign values*/ +#endif // IVAS_FLOAT_FIXED #if 0 //Can be deleted #endif @@ -768,6 +771,7 @@ typedef struct cldfb_filter_bank_struct #ifdef IVAS_FLOAT_FIXED Word32 *cldfb_state_fx; Word16 cldfb_state_length; + Word16 Q_cldfb_state; #endif /* other parameters */ diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c index 0da15ad6e..7a6e72e5d 100644 --- a/lib_dec/amr_wb_dec.c +++ b/lib_dec/amr_wb_dec.c @@ -162,10 +162,17 @@ 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 ) + { + return error; + } +#else if ( ( error = core_switching_pre_dec( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED last_core_ori = st->last_core; diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index ee95b2ff8..1f518a821 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -45,6 +45,10 @@ #include "ivas_cnst.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif // IVAS_FLOAT_FIXED +#include "debug.h" /*---------------------------------------------------------------------* * Local prototypes *---------------------------------------------------------------------*/ @@ -62,6 +66,869 @@ static void smoothTransitionDtxToTcx_fx( Word32 synth[], const int16_t output_fr * * Preprocessing/preparation for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error core_switching_pre_dec_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + 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 */ +) +{ +#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; + Word16 exp = 25; + + error = IVAS_ERR_OK; + + /* Codec mode switching */ + IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) + { + Copy( st->mem_syn2_fx, st->mem_syn1_fx, M ); + set16_fx( st->agc_mem_fx, 0, 2 ); + st->mem_deemph_fx = st->syn[M]; + move16(); + st->bpf_off = 1; + move16(); + IF( st->hBPF != NULL ) + { + set32_fx( st->hBPF->pst_old_syn_32, 0, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err_32 = 0; + move32(); + } + st->psf_lp_noise_fx = (Word16) st->lp_noise; + move16(); + + /* reset old HB synthesis buffer */ + IF( EQ_16( st->last_L_frame, L_FRAME ) ) + { + st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + } + ELSE + { + st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + } + move16(); + set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + + IF( st->hBWE_TD != NULL && NE_16( st->last_core, ACELP_CORE ) ) + { + /* reset BWE memories */ + set32_fx( st->hBWE_TD->old_bwe_exc_fx_32, 0, PIT16k_MAX * 2 ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + } + + /* reset upd_cnt */ + st->upd_cnt = MAX_UPD_CNT; + move16(); + + st->igf = 0; + move16(); + + IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) + { + hf_synth_reset_fx( st->hBWE_zero ); + } + + IF( st->hBWE_FD != NULL ) + { + set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + } + + IF( st->hHQ_core != NULL ) + { + set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + + set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); + + st->hHQ_core->last_max_pos_pulse = 0; + + move16(); + IF( GT_32( st->output_Fs, 16000 ) ) + { + set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + } + + /* pre-echo */ + st->hHQ_core->pastpre = 0; + move16(); + } + + /* reset the GSC pre echo energy threshold in case of switching */ + IF( st->hGSCDec != NULL ) + { + st->hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); + } + + IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) + { + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + st->last_core = HQ_CORE; + move16(); + Copy( st->hTcxDec->FBTCXdelayBuf, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } + + IF( st->hHQ_core != NULL ) + { + set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); + st->hHQ_core->last_max_pos_pulse = 0; + move16(); + + set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->hHQ_core->prev_frm_hfe2 = 0; + st->hHQ_core->prev_stab_hfe2 = 0; + move16(); + move16(); + } + } + + IF( NE_16( st->prev_bfi, 0 ) ) + { + Word16 delay_comp; + + /*switch off Hq Voicing as it was not updated in MODE2*/ + IF( st->hHQ_core != NULL ) + { + st->hHQ_core->oldHqVoicing = 0; + st->hHQ_core->HqVoicing = 0; + move16(); + move16(); + } + + delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + + /*TODO To be tested:control not entering the block*/ + IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + { + /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ + assert( 0 ); +#ifdef IVAS_FLOAT_FIXED + Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH]; + Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + Word32 syn_Overl_fx[320]; + Word32 fer_samples_fx[960]; + Copy_Scale_sig_16_32( st->hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 ); + Copy_Scale_sig_16_32( st->hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 ); +#else + float *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; + float realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; +#endif // IVAS_FLOAT_FIXED + + + FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) + { +#ifdef IVAS_FLOAT_FIXED + set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); + realBuffer_fx[i] = realBufferTmp_fx[i]; + imagBuffer_fx[i] = imagBufferTmp_fx[i]; + move32(); + move32(); +#else + set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + realBuffer[i] = realBufferTmp[i]; + imagBuffer[i] = imagBufferTmp[i]; +#endif // IVAS_FLOAT_FIXED + } + + /* CLDFB analysis of the synthesis at internal sampling rate */ +#ifdef IVAS_FLOAT_FIXED + IF( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ) != IVAS_ERR_OK ) + { + return error; + } + + cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna ); + cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/ + + /* CLDFB synthesis of the combined signal */ + IF( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ) != IVAS_ERR_OK ) + { + return error; + } + + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, st->cldfbSyn ); + cldfb_restore_memory_ivas_fx( st->cldfbSyn ); + Copy_Scale_sig_32_16( syn_Overl_fx, st->hTcxDec->syn_Overl, 320, 15 ); + Copy_Scale_sig_32_16( fer_samples_fx, st->hHQ_core->fer_samples_fx, 960, 9 ); +#else + if ( ( error = cldfb_save_memory_ivas( st->cldfbAna ) ) != IVAS_ERR_OK ) + { + return error; + } + cldfbAnalysis_ivas( st->hTcxDec->syn_Overl_float, realBuffer, imagBuffer, delay_comp, st->cldfbAna ); + cldfb_restore_memory_ivas( st->cldfbAna ); + + /* CLDFB synthesis of the combined signal */ + if ( ( error = cldfb_save_memory_ivas( st->cldfbSyn ) ) != IVAS_ERR_OK ) + { + return error; + } + + cldfbSynthesis_ivas( realBuffer, imagBuffer, st->hHQ_core->fer_samples, delay_comp, st->cldfbSyn ); + cldfb_restore_memory_ivas( st->cldfbSyn ); +#endif // IVAS_FLOAT_FIXED + } + + IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + { + lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, output_frame / 2, st->last_L_frame / 2 ); + /*Set to zero the remaining part*/ + set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, ( output_frame / 2 ) - delay_comp ); + } + } + + st->use_acelp_preq = 0; + st->reset_mem_AR = 0; + move16(); + move16(); + } + + /*FEC*/ + IF( LE_16( st->L_frame, L_FRAME16k ) ) + { + IF( LE_16( st->last_L_frame, L_FRAME16k ) && NE_16( st->core, HQ_CORE ) ) + { + IF( NE_16( st->L_frame, st->last_L_frame ) ) + { + IF( GT_16( st->L_frame, st->last_L_frame ) ) + { + oldLenClasBuff = mult_r(L_SYN_MEM_CLAS_ESTIM , div_s(st->last_L_frame , st->L_frame)); + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + } + ELSE + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + newLenClasBuff = mult_r(L_SYN_MEM_CLAS_ESTIM , div_s(st->L_frame , st->last_L_frame)); + } + move16(); + move16(); + lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + } + } + ELSE + { + set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); + } + } + + /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores + within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ + IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || NE_16( st->last_codec_mode, MODE2 ) ) ) + { + st->last_ppp_mode_dec = 0; + st->last_nelp_mode_dec = 0; + move16(); + move16(); + } + + /* Handle state reset of stat_noise_uv_mod memory */ + IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) ) + { + st->act_count = 3; + st->uv_count = 0; + move16(); + move16(); + } + + IF( ( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) && + NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) ) + { + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + st->hPFstat->reset = 1; + move16(); + } + + IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + Copy( TRWB2_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */ + Copy( TRWB2_Ave_fx, st->lsfoldbfi1_fx, M ); + Copy( TRWB2_Ave_fx, st->lsfoldbfi0_fx, M ); + Copy( TRWB2_Ave_fx, st->lsf_adaptive_mean_fx, M ); + lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_16k ); + } + ELSE + { + Copy( TRWB_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */ + Copy( TRWB_Ave_fx, st->lsfoldbfi1_fx, M ); + Copy( TRWB_Ave_fx, st->lsfoldbfi0_fx, M ); + Copy( TRWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); + lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_12k8 ); + } + Copy_Scale_sig_16_32( st->lsf_old_fx, st->lsf_old32, 0, M ); + Copy_Scale_sig_16_32( st->lsfoldbfi1_fx, st->lsfoldbfi132, 0, M ); + Copy_Scale_sig_16_32( st->lsfoldbfi0_fx, st->lsfoldbfi032, 0, M ); + Copy_Scale_sig_16_32( st->lsf_adaptive_mean_fx, st->lsf_adaptive_mean32, 0, M ); + + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) + { + /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ + set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); + set16_fx( st->agc_mem_fx, 0, 2 ); + } + st->mem_deemph_fx = 0; + move16(); + IF( !st->last_con_tcx ) + { + set16_fx( st->mem_syn2_fx, 0, M ); + } + set16_fx( st->mem_syn1_fx, 0, M ); + IF( st->hBWE_TD != NULL ) + { + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + } + + /* Reset ACELP parameters */ + set32_fx( st->mem_MA32, 0, M ); + + IF( EQ_32(st->sr_core , INT_FS_16k) ) + { + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + } + ELSE + { + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + } + Copy_Scale_sig_16_32( st->mem_AR_fx, st->mem_AR32, M, 0 ); +#if 1 /*To be removed later: floating point initializations*/ + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + set_f( st->dispMem, 0, 8 ); +#endif + st->tilt_code_fx = 0; + st->gc_threshold_fx = 0; + st->dm_fx.prev_gain_code = 0; + st->dm_fx.prev_state = 0; + move16(); + move32(); + move32(); + move16(); + set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); + + st->last_coder_type = GENERIC; + move16(); + + fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ +#if 1 /*To be removed later: floating point initializations*/ + st->lp_gainp = 0.0f; +#endif + st->lp_gainp_fx = 0; + move16(); + st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ + st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ + +#if 1 /*To be removed later: floating point initializations*/ + st->last_voice_factor = 0; +#endif + st->last_voice_factor_fx = 0; + st->Last_GSC_noisy_speech_flag = 0; + move16(); + move16(); + + /* reset CLDFB memories */ + cldfb_reset_memory_fx( st->cldfbAna ); + cldfb_reset_memory_fx( st->cldfbBPF ); + cldfb_reset_memory_fx( st->cldfbSyn ); + + /* reset TBE memories */ + IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) + { + set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); + } + ELSE IF( LT_16(st->L_frame , L_FRAME16k) ) + { + /* resample from 16kHz to 12.8kHZ */ + synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); + } + + IF( st->hBWE_TD != NULL ) + { + set32_fx( st->hBWE_TD->old_bwe_exc_fx_32, 0, PIT16k_MAX * 2 ); + } + + IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) + { + hf_synth_reset_fx( st->hBWE_zero ); + } + + IF( st->hBWE_FD != NULL ) + { + set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + } + } + + 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( st->hBWE_TD != NULL ) + { + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + set32_fx( st->hBWE_TD->old_bwe_exc_fx_32, 0, PIT16k_MAX * 2 ); + } +#if 1 + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + set_f( st->dispMem, 0, 8 ); + +#endif + st->tilt_code_fx = 0; + st->gc_threshold_fx = 0; + st->dm_fx.prev_gain_code = 0; + st->dm_fx.prev_state = 0; + move16(); + move32(); + move32(); + move16(); + set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); + st->last_coder_type = GENERIC; + move16(); + fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ + +#if 1 /*To be removed later: Floating point initialization*/ + st->lp_gainp = 0.0f; +#endif + + st->lp_gainp_fx = 0; + move16(); + st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ + st->lp_gainc_fx = shr( st->lp_gainc_fx, 12 - exp ); /*Q3*/ + +#if 1 /*To be removed later: Floating point initialization*/ + st->last_voice_factor = 0; +#endif // + st->last_voice_factor_fx = 0; + st->Last_GSC_noisy_speech_flag = 0; + move16(); + move16(); + + IF( GT_32(st->output_Fs , 16000) && st->hBWE_zero != NULL ) + { + hf_synth_reset_fx( st->hBWE_zero ); + } + + IF( st->hBWE_FD != NULL ) + { + set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + } + + 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) ) + { + /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ + Word16 offset; + offset = sub(st->cldfbAna->p_filter_length , st->cldfbAna->no_channels); + Word32 *old_synthFB_fx; + IF( ( old_synthFB_fx = (Word32 *) malloc( st->hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) ); + } + Copy_Scale_sig_16_32( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, Q10 - Q_old_synthFB ); + Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); + IF( old_synthFB_fx ) + free( old_synthFB_fx ); + } + } + + IF( EQ_16(st->core , HQ_CORE) && ( EQ_16(st->last_core , ACELP_CORE) || EQ_16(st->last_core , AMR_WB_CORE) || ( ( NE_16(st->element_mode , EVS_MONO) ) && ( NE_16(st->last_core , HQ_CORE) ) ) ) ) + { + set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + + set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); + st->hHQ_core->last_max_pos_pulse = 0; + move16(); + + set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->hHQ_core->prev_frm_hfe2 = 0; + st->hHQ_core->prev_stab_hfe2 = 0; + move16(); + move16(); + IF( GT_32(st->output_Fs , 16000) ) + { + set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + } + + IF( NE_16(st->element_mode , EVS_MONO) ) + { + /* Estimate mem_env_delta to reinit env_stab */ + tmp_fx = L_max( 0, ENV_STAB_EST1_FX + Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ) + Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ); /*Q12*/ + + st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ + + IF( NE_16(st->last_core , TCX_20_CORE) && NE_16(st->last_core , TCX_10_CORE) ) + { +#if 1 /*Floating point initialization*/ + set_f( st->hHQ_core->old_out, 0, output_frame ); + set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); +#endif // 1 + set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); + set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k ); + } + + st->hHQ_core->no_att_hangover = 0; + move16(); +#if 1 /*To be removed later: Floating point initialization*/ + st->hHQ_core->energy_lt = 300.0f; + set_f( st->hHQ_core->prev_noise_level, 0.0f, 2 ); + st->hHQ_core->prev_ni_ratio = 0.5f; + set_f( st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); +#endif + st->hHQ_core->energy_lt_fx = 2457600;/*300.0f Q13*/ + move32(); + set16_fx( st->hHQ_core->old_is_transient, 0, 3 ); + set16_fx( st->hHQ_core->prev_noise_level_fx, 0, 2 ); + st->hHQ_core->prev_R = 0; + move16(); + set16_fx( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); + st->hHQ_core->prev_hqswb_clas = HQ_NORMAL; + st->hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + move16(); + move16(); + set16_fx( st->hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); + } + ELSE + { +#if 1 /*To be removed later: Floating point initialization*/ + set_f( st->hHQ_core->old_out, 0, output_frame ); + set_f( st->hHQ_core->old_outLB, 0, L_FRAME16k ); +#endif // + set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); + set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k ); + } + } + + /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ + IF( st->hHQ_core != NULL ) + { + st->hHQ_core->pastpre--; + IF( LE_16(st->hHQ_core->pastpre , 0) ) + { + reset_preecho_dec_fx( st->hHQ_core ); + } + } + + IF( EQ_32(st->core_brate , FRAME_NO_DATA) ) + { + st->VAD = 0; + st->m_frame_type = ZERO_FRAME; + } + ELSE IF( EQ_32(st->core_brate , SID_2k40) || EQ_32(st->core_brate , SID_1k75) ) + { + st->VAD = 0; + st->m_frame_type = SID_FRAME; + } + ELSE + { + st->VAD = 1; + st->m_frame_type = ACTIVE_FRAME; + } + + move16(); + move16(); + /*switch on CNA on active frames*/ + IF( EQ_16(st->element_mode , EVS_MONO) ) /* for IVAS modes, st->flag_cna is set earlier */ + { + IF( st->VAD && ( ( NE_16(st->core , AMR_WB_CORE) && LE_32(st->total_brate , CNA_MAX_BRATE) ) || ( EQ_16(st->core , AMR_WB_CORE) && LE_32(st->total_brate , ACELP_8k85) ) ) ) + { + st->flag_cna = 1; + move16(); + } + ELSE IF( st->VAD || ( EQ_16( st->cng_type , FD_CNG ) && EQ_16( st->L_frame , L_FRAME16k ) ) ) + { + st->flag_cna = 0; + move16(); + } + } + + IF( EQ_16(st->core , AMR_WB_CORE) ) + { + st->cng_type = LP_CNG; + move16(); + } + + /* Reconfigure CNG */ + IF( st->hFdCngDec && ( NE_16( st->last_L_frame , st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize , st->L_frame ) || EQ_16(st->ini_frame , 0) || NE_16(st->bwidth , st->last_bwidth) ) ) + { + /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ + IF( NE_16(st->core , AMR_WB_CORE) ) + { + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + } + ELSE + { + configureFdCngDec_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); + + IF( st->VAD ) + { + st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate; + move32(); + } + } + IF( NE_16(st->last_L_frame , st->L_frame) && LE_16(st->L_frame , L_FRAME16k) && LE_16(st->last_L_frame , L_FRAME16k) ) + { + IF( EQ_16(st->element_mode , IVAS_CPE_DFT) || EQ_16(st->element_mode , IVAS_CPE_TD) ) + { + 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 ); + + 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 ); + + IF( EQ_16(st->L_frame , L_FRAME) ) + { + FOR( i = 0; i < shl(st->L_frame,1); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) floatToFixed( 0.6250f, 15 ) ); + } + } + ELSE + { + FOR( i = 0; i < shl(st->L_frame ,1); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) floatToFixed( 1.6f, 14 ) ); + } + } + } + } + } + +#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 ivas_error core_switching_pre_dec( Decoder_State *st, /* i/o: decoder state structure */ diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 341b07e5f..6f62e8e20 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -565,7 +565,7 @@ ivas_error core_switching_pre_dec_fx( } /* pre-echo */ - hHQ_core->pastpre_fx = 0; + hHQ_core->pastpre = 0; move16(); } /* reset the GSC pre echo energy threshold in case of switching */ @@ -957,8 +957,8 @@ ivas_error core_switching_pre_dec_fx( /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ IF (hHQ_core != NULL) { - hHQ_core->pastpre_fx--; - IF(hHQ_core->pastpre_fx <= 0) + hHQ_core->pastpre--; + IF(hHQ_core->pastpre <= 0) { reset_preecho_dec_fx(hHQ_core); } diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index 22b831e0b..e1460b02d 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -700,7 +700,11 @@ void getTCXparam_ivas( { ConfigureContextHm_ivas( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } +#ifdef IVAS_FLOAT_FIXED + hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, flag_ctx_hm ? &hm_cfg : NULL ); +#else hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS( st0, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, flag_ctx_hm ? &hm_cfg : NULL ); +#endif } else { diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 48d35293e..0148b4d01 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -246,10 +246,17 @@ ivas_error evs_dec_flt( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = core_switching_pre_dec( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * ACELP core decoding diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index b00431599..3c0cd6fb7 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -47,7 +47,7 @@ void hf_synth_init_fx( ) { - hBWE_zero->seed2_fx = RANDOM_INITSEED; + hBWE_zero->seed2 = RANDOM_INITSEED; set16_fx(hBWE_zero->mem_hf_fx, 0, 2 * L_FILT16k); set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); set16_fx(hBWE_zero->mem_hp400_fx, 0, 4); @@ -64,7 +64,7 @@ void hf_synth_reset_fx( FOR(i = 0; i < L_FRAME16k; i++) { - Random(&hBWE_zero->seed2_fx); + Random(&hBWE_zero->seed2); } set16_fx(hBWE_zero->mem_hf_fx, 0, 2 * L_FILT16k); @@ -164,7 +164,7 @@ static void hf_synthesis_fx( * generate white noise vector *-----------------------------------------------------------------*/ - Random_Fill(&hBWE_zero->seed2_fx, L_SUBFR16k, HF_exc, 3); /* 3 = Shift Right by 3 */ + Random_Fill(&hBWE_zero->seed2, L_SUBFR16k, HF_exc, 3); /* 3 = Shift Right by 3 */ /* o: HF_exc in Q-3 */ @@ -453,7 +453,7 @@ void hf_synth_amr_wb_reset_fx( FOR(i = 0; i < L_FRAME16k; i++) { - Random(&hBWE_zero->seed2_fx); + Random(&hBWE_zero->seed2); } set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 9eaecbc20..8abec2c7c 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -444,7 +444,7 @@ void hq_core_dec_fx( IF ( (st_fx->bfi == 0 && st_fx->prev_bfi == 0) || !(GE_16(output_frame, L_FRAME16k))) { preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, - &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag_fx, &hHQ_core->pastpre_fx, st_fx->bwidth ); + &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); } } ELSE @@ -479,7 +479,7 @@ void hq_core_dec_fx( { preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth,*Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, - &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag_fx, &hHQ_core->pastpre_fx, st_fx->bwidth ); + &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); } } @@ -1063,7 +1063,7 @@ void ivas_hq_core_dec_fx( IF( ( EQ_16( st_fx->bfi, 0 ) && EQ_16( st_fx->prev_bfi, 0 ) ) || !( GE_16( output_frame, L_FRAME16k ) ) ) { preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, - &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag_fx, &hHQ_core->pastpre_fx, st_fx->bwidth ); + &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); } } ELSE @@ -1096,7 +1096,7 @@ void ivas_hq_core_dec_fx( { preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, - &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag_fx, &hHQ_core->pastpre_fx, st_fx->bwidth ); + &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); } } } diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index cfdf40c98..a6a7a1060 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -844,9 +844,9 @@ void reset_preecho_dec_fx( hHQ_core->mean_prev_nc_fx = L_deposit_l(0); hHQ_core->wmold_hb_fx = 32767; move16(); - hHQ_core->prevflag_fx = 0; + hHQ_core->prevflag = 0; move16(); - hHQ_core->pastpre_fx = 0; + hHQ_core->pastpre = 0; move16(); return; diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index f4f4d5d27..d43aad479 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -376,11 +376,18 @@ ivas_error ivas_core_dec( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#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 ) + { + return error; + } +#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 ) { return error; } +#endif flag_sec_CNA = -1; if ( hCPE != NULL ) { @@ -468,8 +475,6 @@ ivas_error ivas_core_dec( hHQ_core->mem_env_delta_fx = hHQ_core->mem_env_delta; hHQ_core->mem_env_delta_hqfec_fx = hHQ_core->mem_env_delta_hqfec; hHQ_core->no_att_hangover_fx = hHQ_core->no_att_hangover; - hHQ_core->pastpre_fx = hHQ_core->pastpre; - hHQ_core->prevflag_fx = hHQ_core->prevflag; hHQ_core->oldHqVoicing_fx = hHQ_core->oldHqVoicing; floatToFixed_arr( hHQ_core->env_stab_state_p, hHQ_core->env_stab_state_p_fx, Q15, NUM_ENV_STAB_PLC_STATES ); hHQ_core->envstabplc_hocnt_fx = hHQ_core->envstabplc_hocnt; @@ -537,8 +542,6 @@ ivas_error ivas_core_dec( hHQ_core->mem_env_delta = hHQ_core->mem_env_delta_fx; hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec_fx; hHQ_core->no_att_hangover = hHQ_core->no_att_hangover_fx; - hHQ_core->pastpre = hHQ_core->pastpre_fx; - hHQ_core->prevflag = hHQ_core->prevflag_fx; hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing_fx; fixedToFloat_arr( hHQ_core->env_stab_state_p_fx, hHQ_core->env_stab_state_p, Q15, NUM_ENV_STAB_PLC_STATES ); hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt_fx; diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index a57d0d829..d9f1a061d 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -514,7 +514,14 @@ ivas_error ivas_param_ism_dec_open( output_Fs = st_ivas->hDecoderConfig->output_Fs; output_config = st_ivas->hDecoderConfig->output_config; +#ifdef IVAS_FLOAT_FIXED + + ivas_param_ism_config_fx( hParamIsmDec->hParamIsm, st_ivas->nchan_ism ); // assuming Q14 for gains; + hParamIsmDec->hParamIsm->last_dmx_gain = 1.0f; + set_f(hParamIsmDec->hParamIsm->last_cardioid_left, 1.0f, MAX_NUM_OBJECTS ); +#else ivas_param_ism_config( hParamIsmDec->hParamIsm, st_ivas->nchan_ism ); +#endif /*-----------------------------------------------------------------* * set input parameters diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 7b6a8b6bd..231501857 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -827,6 +827,38 @@ ivas_error mct_dec_reconfigure( void ivas_mct_dec_close( MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ ) +#ifdef IVAS_FLOAT_FIXED +{ + Word16 n, maxBlocks; + + IF ( hMCT == NULL || *hMCT == NULL ) + { + return; + } + + maxBlocks = shr( ( *hMCT )->nchan_out_woLFE, 1 ); + + FOR ( n = 0; n < maxBlocks; n++ ) + { + IF ( ( *hMCT )->hBlockData[n] != NULL ) + { + IF ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + { + free( ( *hMCT )->hBlockData[n]->hStereoMdct ); + ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; + } + + free( ( *hMCT )->hBlockData[n] ); + ( *hMCT )->hBlockData[n] = NULL; + } + } + + free( *hMCT ); + *hMCT = NULL; + + return; +} +#else { Word16 n, maxBlocks; @@ -857,6 +889,7 @@ void ivas_mct_dec_close( return; } +#endif /*------------------------------------------------------------------------- diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index f102baacd..fb45472e2 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -252,6 +252,61 @@ void stereo_dft_dequantize_itd( *------------------------------------------------------------------------*/ ivas_error stereo_dft_dec_create( +#ifdef IVAS_FLOAT_FIXED + STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 nchan_transport /* i : number of transport channels */ +) +{ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft_loc; + Word16 tmpS; + + IF ( *hStereoDft != NULL ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: DFT Stereo memory already allocated\n" ); + } + + IF ( ( hStereoDft_loc = (STEREO_DFT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo\n" ) ); + } + + IF ( ( hStereoDft_loc->hConfig = (STEREO_DFT_CONFIG_DATA_HANDLE) malloc( sizeof( STEREO_DFT_CONFIG_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo Config\n" ) ); + } + + IF ( ( hStereoDft_loc->hBpf = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF handle\n" ) ); + } + + IF ( ( hStereoDft_loc->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); + } + + hStereoDft_loc->hConfig->force_mono_transmission = 0; + move16(); + + IF ( sba_dirac_stereo_flag ) + { + ivas_sba_dirac_stereo_config( hStereoDft_loc->hConfig ); + } + ELSE + { + stereo_dft_config( hStereoDft_loc->hConfig, element_brate, &tmpS, &tmpS ); + } + + stereo_dft_dec_open( hStereoDft_loc, output_Fs, nchan_transport ); + + *hStereoDft = hStereoDft_loc; + + return IVAS_ERR_OK; +} +#else STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ const int32_t element_brate, /* i : element bitrate */ const int32_t output_Fs, /* i : output sampling rate */ @@ -308,6 +363,7 @@ ivas_error stereo_dft_dec_create( return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------- @@ -316,6 +372,135 @@ ivas_error stereo_dft_dec_create( * Open DFT decoder stereo handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void stereo_dft_dec_open( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 nchan_transport /* i : number of transport channels */ +) +{ + /*Sizes*/ + hStereoDft->N = (Word32) ( STEREO_DFT_HOP_MAX * output_Fs / 48000 ); + + /*Init. DFT sizes*/ + hStereoDft->NFFT = (Word32) ( STEREO_DFT32MS_N_MAX * output_Fs / 48000 ); + + hStereoDft->dft_trigo_8k = dft_trigo_32k; + hStereoDft->dft_trigo_12k8 = dft_trigo_12k8; + hStereoDft->dft_trigo_16k = dft_trigo_32k; + SWITCH (output_Fs) + { + case 48000: + hStereoDft->ONE_NFFT = (Word32) ( 0x00222222 ); + BREAK; + case 32000: + hStereoDft->ONE_NFFT = (Word32) ( 0x00333333 ); + BREAK; + case 16000: + hStereoDft->ONE_NFFT = (Word32) ( 0x00666666 ); + BREAK; + case 8000: + hStereoDft->ONE_NFFT = (Word32) ( 0x00CCCCCC ); + BREAK; + default: + assert(0); + } + hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; + hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; + + /* TODO: remove floating point dependency */ + hStereoDft->win232ms_8k = dft_win232ms_8k; + hStereoDft->win232ms_12k8 = dft_win232ms_12k8; + hStereoDft->win232ms_16k = dft_win232ms_16k; + + hStereoDft->dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * output_Fs ) / 48000 ); + hStereoDft->win232ms_8k_fx = dft_win232ms_8k_fx; + hStereoDft->win232ms_12k8_fx = dft_win232ms_12k8_fx; + hStereoDft->win232ms_16k_fx = dft_win232ms_16k_fx; + + /* TODO: remove floating point dependency */ + hStereoDft->win32ms_8k = dft_win232ms_8k + 1; + hStereoDft->win32ms_12k8 = dft_win232ms_12k8 + 1; + hStereoDft->win32ms_16k = dft_win232ms_16k + 1; + + hStereoDft->dft32ms_ovl2 = (Word16) ( ( STEREO_DFT32MS_OVL2_MAX * output_Fs ) / 48000 ); + hStereoDft->win32ms_8k_fx = dft_win232ms_8k_fx + 1; + hStereoDft->win32ms_12k8_fx = dft_win232ms_12k8_fx + 1; + hStereoDft->win32ms_16k_fx = dft_win232ms_16k_fx + 1; + + + IF ( EQ_32( output_Fs, 16000 ) ) + { + /* TODO: remove floating point dependency */ + hStereoDft->dft_trigo = dft_trigo_32k; + hStereoDft->win232ms = dft_win232ms_16k; + hStereoDft->win32ms = dft_win232ms_16k + 1; + + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hStereoDft->win232ms_fx = dft_win232ms_16k_fx; + hStereoDft->win32ms_fx = dft_win232ms_16k_fx + 1; + } + ELSE IF ( EQ_32( output_Fs, 32000 ) ) + { + /* TODO: remove floating point dependency */ + hStereoDft->dft_trigo = dft_trigo_32k; + hStereoDft->win232ms = dft_win232ms_32k; + hStereoDft->win32ms = dft_win232ms_32k + 1; + + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hStereoDft->win232ms_fx = dft_win232ms_32k_fx; + hStereoDft->win32ms_fx = dft_win232ms_32k_fx + 1; + } + ELSE + { + assert( EQ_32( output_Fs, 48000 ) ); + /* TODO: remove floating point dependency */ + hStereoDft->dft_trigo = dft_trigo_48k; + hStereoDft->win232ms = dft_win232ms_48k; + hStereoDft->win32ms = dft_win232ms_48k + 1; + + hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hStereoDft->win232ms_fx = dft_win232ms_48k_fx; + hStereoDft->win32ms_fx = dft_win232ms_48k_fx + 1; + } + + hStereoDft->win_8k = dft_win_8k; + + /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ + set_s( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_DEC_DFT_NB ); + + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); + hStereoDft->hb_stefi_delay = NS2SA( output_Fs, STEREO_DFT_TD_STEFI_DELAY_NS ); + + IF ( GT_16( nchan_transport, 2 ) ) + { + hStereoDft->min_smooth_gains_fx = min_smooth_gains2_fx; + hStereoDft->max_smooth_gains_fx = max_smooth_gains2_fx; + + /* TODO: remove floating point dependency */ + hStereoDft->min_smooth_gains = min_smooth_gains2; + hStereoDft->max_smooth_gains = max_smooth_gains2; + } + ELSE + { + hStereoDft->min_smooth_gains_fx = min_smooth_gains1_fx; + hStereoDft->max_smooth_gains_fx = max_smooth_gains1_fx; + + /* TODO: remove floating point dependency */ + hStereoDft->min_smooth_gains = min_smooth_gains1; + hStereoDft->max_smooth_gains = max_smooth_gains1; + } + + /* reset DFT stereo memories */ + stereo_dft_dec_reset( hStereoDft ); + + return; +} +#else static void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ const int32_t output_Fs, /* i : output sampling rate */ @@ -459,6 +644,7 @@ static void stereo_dft_dec_open( return; } +#endif /*------------------------------------------------------------------------- diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index fdee91e7f..8258b053f 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -81,7 +81,11 @@ * Local function prototypes *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const Word32 output_Fs, const Word16 nchan_transport ); +#else static void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const int32_t output_Fs, const int16_t nchan_transport ); +#endif static void stereo_dft_compute_td_stefi_params_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const Word16 samp_ratio ); diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index af0dd4a2e..1f2d58158 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -682,7 +682,7 @@ void stereo_tcx_core_dec( /* Update FEC_scale_syn parameters */ #ifdef IVAS_FLOAT_FIXED Word32 synth_fx[L_FRAME48k], enr_old_fx; - Word16 q_synth = 11, old_fpitch_fx; + Word16 q_synth = 0, old_fpitch_fx; for ( int p = 0; p < st->L_frame; p++ ) { synth_fx[p] = (Word32) ( synth[p] * ( 1u << q_synth ) ); @@ -1661,7 +1661,7 @@ static void dec_prm_tcx_ivas_fx( } 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) ( st->last_concealed_gain_syn_deemph_float, 14 ); + 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 ); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 98164ee5f..ccaccb78d 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -813,6 +813,10 @@ typedef struct bass_postfilt_structure float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ +#ifdef IVAS_FLOAT_FIXED + Word32 pst_mem_deemp_err_32; + Word32 pst_old_syn_32[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ +#endif // IVAS_FLOAT_FIXED float pst_lp_ener; /* Bass post-filter - long-term energy */ Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ @@ -1197,10 +1201,8 @@ typedef struct hq_dec_structure Word16 wmold_hb_fx; /* Q15 */ int16_t prevflag; - Word16 prevflag_fx; /* Q0 */ int16_t pastpre; - Word16 pastpre_fx; /* Q0 */ int16_t prev_frm_hfe2; @@ -1296,7 +1298,6 @@ typedef struct hq_dec_structure typedef struct zero_bwe_dec_structure { int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ - Word16 seed2_fx; /* HF (6-7kHz) BWE - seed for random signal generator Q0*/ float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ @@ -1833,6 +1834,14 @@ typedef struct Decoder_State //note_ : produces failures if added below their float parts Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ +#ifdef IVAS_FLOAT_FIXED + Word32 lsf_old32[M]; /* old LSF vector at the end of the frame Q2.56*/ + Word32 lsfoldbfi132[M]; + Word32 lsfoldbfi032[M]; + Word32 lsf_adaptive_mean32[M]; + Word32 mem_AR32[M]; + Word32 mem_MA32[M]; +#endif // IVAS_FLOAT_FIXED Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ /*----------------------------------------------------------------------------------* @@ -1886,6 +1895,10 @@ typedef struct Decoder_State float stab_fac_smooth_lt; float log_energy_old; +#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*/ +#endif float log_energy_diff_lt; Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ @@ -2302,7 +2315,12 @@ typedef struct Decoder_State Word16 last_wb_bwe_ener_fx; Word16 prev_fb_ener_adjust_fx; +#ifdef IVAS_FLOAT_FIXED + Word16 prev_synth_buffer_fx[NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)];/*Updated IVAS size is 96*/ +#else Word16 prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)]; + /*Old EVS size is 51*/ +#endif Word16 GainShape_Delay[NUM_SHB_SUBFR / 2]; Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index ca0d615d7..3df8407b5 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -60,6 +60,10 @@ static void get_lattice_coeffs( const int16_t band_index, const int16_t channel_index, float *lattice_coeffs ); +#ifdef IVAS_FLOAT_FIXED +static void get_lattice_coeffs_fx( const Word16 band_index, const Word16 channel_index, Word16 *lattice_coeffs ); +#endif + static void lattice2allpass( const int16_t filter_length, const float *lattice_coeffs, float *filter_coeffs_num_real, float *filter_coeffs_den_real ); @@ -302,7 +306,16 @@ ivas_error ivas_dirac_dec_decorr_open( freq_domain_decorr_ap_params->phase_coeff_imag[l * freq_domain_decorr_ap_params->max_band_decorr + n] = -sinf( cur_lattice_delta_phi ); /* calculate phase offset */ +#ifdef IVAS_FLOAT_FIXED + Word16 lattice_coeffs_fx[2 * DIRAC_MAX_DECORR_FILTER_LEN]; + get_lattice_coeffs_fx(band_table_idx, l, lattice_coeffs_fx); + FOR (Word16 i = 0; i < ap_filter_length[band_table_idx]; i++) { + lattice_coeffs[i] = ( float ) lattice_coeffs_fx[i] / (1 << 15); + } +#else get_lattice_coeffs( band_table_idx, l, lattice_coeffs ); +#endif + /* calcualte transfer function coefficients from the lattice coefficients */ lattice2allpass( freq_domain_decorr_ap_params->filter_length[k], lattice_coeffs, &freq_domain_decorr_ap_params->filter_coeff_num_real[( k_in + m ) * ( freq_domain_decorr_ap_params->filter_length[0] * num_outputs_diff ) + l * freq_domain_decorr_ap_params->filter_length[0]], &freq_domain_decorr_ap_params->filter_coeff_den_real[( k_in + m ) * ( freq_domain_decorr_ap_params->filter_length[0] * num_outputs_diff ) + l * freq_domain_decorr_ap_params->filter_length[0]] ); @@ -751,6 +764,23 @@ static void get_lattice_coeffs( return; } +#ifdef IVAS_FLOAT_FIXED +static void get_lattice_coeffs_fx( + const Word16 band_index, + const Word16 channel_index, + Word16 *lattice_coeffs ) +{ + Word16 k; + + for ( k = 0; k < ap_filter_length[band_index]; k++ ) + { + Word16 cur_lattice_coeff = ap_lattice_coeffs_fx[band_index][channel_index * ap_filter_length[band_index] + k]; + lattice_coeffs[k] = cur_lattice_coeff; + } + + return; +} +#endif /* convert lattice filter coeffs to all pass transfer function coeffs */ static void lattice2allpass( diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 7c133b8b4..271872a89 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -188,21 +188,24 @@ static void ivas_binaural_reverb_setPreDelay( const Word16 delaySamples /* i : reverb pre-delay in CLDFB slots */ ) { - if ( delaySamples < 1 ) + IF ( LT_16( delaySamples, 1 ) ) { hReverb->preDelayBufferLength = 1; + move16(); return; } - if ( delaySamples > REVERB_PREDELAY_MAX ) + IF ( GT_16( delaySamples, REVERB_PREDELAY_MAX ) ) { hReverb->preDelayBufferLength = REVERB_PREDELAY_MAX; + move16(); return; } hReverb->preDelayBufferLength = delaySamples; + move16(); return; } diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index a5272c3aa..dbcefb7a4 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -177,6 +177,19 @@ const float * const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS] = &ap_lattice_coeffs_3[0], }; +#ifdef IVAS_FLOAT_FIXED +const Word16 ap_lattice_coeffs_1_fx[330] = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; +const Word16 ap_lattice_coeffs_2_fx[132] = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; +const Word16 ap_lattice_coeffs_3_fx[66] = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; + +const Word16 * const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS] = +{ + &ap_lattice_coeffs_1_fx[0], + &ap_lattice_coeffs_2_fx[0], + &ap_lattice_coeffs_3_fx[0], +}; +#endif + const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1] = { 0.0f, 0.125f, 0.375f, 1.0f diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 409ee7b12..7f26e6cf7 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -62,6 +62,7 @@ extern const float ap_lattice_coeffs_1[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM extern const float ap_lattice_coeffs_2[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; extern const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; extern const float *const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; extern const int16_t sba_map_tc[11]; -- GitLab