diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 753bc19cf8ccd5f516c52c0d68399edba62d703c..467ae9a8a74c2c91e8ee00ffbf25939883e2edab 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -548,6 +548,10 @@ void reset_indices_enc_fx( { Word16 i; +#ifdef MSAN_FIX + hBstr->nb_ind_tot = 0; + move16(); +#endif hBstr->nb_bits_tot = 0; move16(); hBstr->next_ind_fx = 0; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index eaa9cb209328360b90cc9cc18e339cf8fd489500..7f4b8dc8230982a09140413fb10e5df591abf123 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -234,8 +234,7 @@ ivas_error pre_proc_front_ivas_fx( const Word16 input_frame, /* i : frame length */ const Word16 n, /* i : channel number */ Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ - float old_inp_12k8[], /* o : buffer of old input signal */ - float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q-1 */ Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ Word16 *relE_fx, /* o : frame relative energy Q8 */ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ @@ -249,7 +248,8 @@ ivas_error pre_proc_front_ivas_fx( Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - float old_wsp[], /* o : weighted input signal buffer */ + Word16 old_wsp[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 *q_old_wsp, Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ Word16 *loc_harm, /* o : harmonicity flag */ diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index b07fc980fea3c2ed7a6003cbcf4a4525ab0e112b..7b177d99a067b14fa75e57f906fe7c541ac4cb7f 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -305,7 +305,7 @@ void amr_wb_enc_fx( *----------------------------------------------------------------*/ st->vad_flag = wb_vad_fx( st, fr_bands, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ); + &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ); if ( st->vad_flag == 0 ) { diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index ad78ce310ce94b5e94772eaaff9c9e58376e0af3..5b900c6d0c46da8d1f24b13be57ef31a5227eb0e 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -308,6 +308,7 @@ static void find_enr_dft_fx( ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q30 - gaurded_bits + ngmult_exp BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); + // To Be Checked BinE_fx[bin_cnt] = L_shl_sat( BinE_fx[bin_cnt], sub( *Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); // To Be Checked @@ -371,9 +372,11 @@ static void find_enr_dft_fx( ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); - BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( *Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); + // To Be Checked + BinE_fx[bin_cnt] = L_shl_sat( BinE_fx[bin_cnt], sub( *Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); - band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); + // To Be Checked + band_fx[i] = L_add_sat( BinE_fx[bin_cnt], band_fx[i] ); move32(); ptR_fx += 2; ptI_fx += 2; diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 262d8d42450121b684c6518631aad5ca1e5c35a7..e11f068b60025545274b06dee47173f94398c4de 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -316,7 +316,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * *----------------------------------------------------------*/ encode_acelp_gains_fx( code, acelp_cfg->gains_mode[j_subfr], Es_pred, clip_gain, &g_corr, &gain_pit, &gain_code, &prm, - &past_gcode, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr_fx ); + &past_gcode, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr ); gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index 106f6e83638bea5ba35c069fb80608bb4335c1fb..ca17c0f2506a20a33a41b2686efcafc2a7350615 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -161,7 +161,7 @@ void gauss_L2_ivas_fx( move16(); tmp16 = norm_l( tmp32_2 ); - g_corr->y1y2 = round_fx( L_shl( tmp32_2, tmp16 ) ); + g_corr->y1y2 = round_fx_sat( L_shl( tmp32_2, tmp16 ) ); g_corr->y1y2_e = sub( 31 - 18, tmp16 ); move16(); } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index c000fd95bd75a01918b83017c9b00248350f3091..1d3178aa58fd5f8b6628b048ae86788538aabae2 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -55,12 +55,12 @@ #ifndef IVAS_FLOAT_FIXED static void init_tcx( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate, const int16_t MCT_flag ); #endif -static void init_sig_buffers( Encoder_State *st, const int16_t L_frame_old, const int16_t L_subfr, const int32_t total_brate, const int32_t last_total_brate ); #ifndef IVAS_FLOAT_FIXED +static void init_sig_buffers( Encoder_State *st, const int16_t L_frame_old, const int16_t L_subfr, const int32_t total_brate, const int32_t last_total_brate ); static void init_core_sig_ana( Encoder_State *st ); static void init_acelp( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate ); -#endif static void init_modes( Encoder_State *st, const int32_t last_total_brate ); +#endif #ifdef IVAS_FLOAT_FIXED static void init_tcx_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag ); static void init_core_sig_ana_ivas_fx( Encoder_State *st ); @@ -234,9 +234,7 @@ void init_coder_ace_plus_ivas_fx( /* Initialize Signal Buffers */ init_sig_buffers_ivas_fx( st, L_frame_old, L_subfr ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_sig_buffers( st, L_frame_old, L_subfr, st->total_brate, last_total_brate ); -#endif + /* Initialize ACELP */ init_acelp_ivas_fx( st, L_frame_old, 0 ); @@ -460,7 +458,6 @@ void init_coder_ace_plus( if ( st->igf && st->hIGFEnc != NULL ) { - IGFEncSetMode( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); #ifdef IVAS_FLOAT_FIXED IGFEncSetMode_ivas_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); #endif @@ -489,10 +486,7 @@ void init_coder_ace_plus( } /* Initialize Signal Buffers */ -#ifdef IVAS_FLOAT_FIXED init_sig_buffers_ivas_fx( st, L_frame_old, L_subfr ); -#endif - init_sig_buffers( st, L_frame_old, L_subfr, st->total_brate, last_total_brate ); /* Initialize ACELP */ #ifdef IVAS_FLOAT_FIXED @@ -540,10 +534,8 @@ void init_coder_ace_plus( st->glr_reset = 0; /* Initialize ACELP/TCX Modes */ - init_modes( st, last_total_brate ); -#ifdef IVAS_FLOAT_FIXED init_modes_ivas_fx( st, last_total_brate ); -#endif + /* Adaptive BPF */ if ( st->total_brate >= HQ_48k ) { @@ -804,7 +796,7 @@ static void init_tcx( * * Initialization of signal buffers *-----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void init_sig_buffers( Encoder_State *st, const int16_t L_frame_old, @@ -813,120 +805,101 @@ static void init_sig_buffers( const int32_t last_total_brate ) { TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - UNUSED_PARAM( L_subfr ); + /* Encoder Past Samples at encoder-sampling-rate */ st->encoderPastSamples_enc = ( st->L_frame * 9 ) / 16; /* Initialize Signal Buffers and Pointers at encoder-sampling-rate */ if ( st->ini_frame == 0 ) { -#ifdef IVAS_FLOAT_FIXED - set16_fx( st->buf_speech_enc_pe, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - st->exp_buf_speech_enc_pe = 0; - set16_fx( st->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - st->exp_buf_speech_enc = 0; -#else - set_zero( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - set_zero( st->buf_speech_enc_pe_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - set_zero( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); -#endif + set_zero( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set_zero( st->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set_zero( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); if ( hTcxEnc != NULL ) { - // set_zero( hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set_zero( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } } else if ( st->L_frame != L_frame_old && !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) && ( total_brate == last_total_brate ) && ( st->last_bwidth == st->bwidth ) ) ) { -#ifndef IVAS_FLOAT_FIXED - lerp_flt( st->buf_speech_enc_flt, st->buf_speech_enc_flt, st->L_frame, L_frame_old ); + lerp( st->buf_speech_enc, st->buf_speech_enc, st->L_frame, L_frame_old ); + if ( ( st->last_core != TCX_20_CORE ) && ( st->last_core != TCX_10_CORE ) ) { - floatToFixed_arr( st->buf_speech_enc_flt, st->buf_speech_enc, 0, st->L_frame ); + mvr2r( st->buf_speech_enc, hTcxEnc->buf_speech_ltp, st->L_frame ); } - mvr2r( st->old_wsp, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM ); -#endif + mvr2r( st->old_wsp, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM ); + /*Resamp buffers needed only for ACELP*/ if ( st->L_frame == L_FRAME && !st->tcxonly ) { -#ifndef IVAS_FLOAT_FIXED // Need to remove after cleanup of old_inp_12k8 - mvr2r( st->old_inp_12k8, st->buf_speech_enc_pe_flt + st->L_frame - L_INP_MEM, L_INP_MEM ); -#else - - Word16 tmp = st->exp_old_inp_12k8; - move16(); - Copy( st->old_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM ); - /* SCaling to common exponent*/ - Scale_sig( st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM, sub( tmp, s_max( tmp, st->exp_buf_speech_enc_pe ) ) ); - Scale_sig( st->buf_speech_enc_pe, st->L_frame - L_INP_MEM, sub( st->exp_buf_speech_enc_pe, s_max( tmp, st->exp_buf_speech_enc_pe ) ) ); - Scale_sig( st->buf_speech_enc_pe + st->L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->L_frame ), sub( st->exp_buf_speech_enc_pe, s_max( tmp, st->exp_buf_speech_enc_pe ) ) ); - st->exp_buf_speech_enc_pe = s_max( tmp, st->exp_buf_speech_enc_pe ); -#endif + mvr2r( st->old_inp_12k8, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM ); } else if ( st->L_frame == L_FRAME16k && !st->tcxonly ) { -#ifndef IVAS_FLOAT_FIXED - lerp_flt( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); -#endif -#ifndef IVAS_FLOAT_FIXED // Need to remove after cleanup of old_inp_12k8 - mvr2r( st->old_inp_16k, st->buf_speech_enc_pe_flt + st->L_frame - L_INP_MEM, L_INP_MEM ); -#else - Word16 tmp = st->exp_old_inp_12k8; - move16(); - Copy( st->old_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM ); - /* SCaling to common exponent*/ - Scale_sig( st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM, sub( tmp, s_max( tmp, st->exp_buf_speech_enc_pe ) ) ); - Scale_sig( st->buf_speech_enc_pe, st->L_frame - L_INP_MEM, sub( st->exp_buf_speech_enc_pe, s_max( tmp, st->exp_buf_speech_enc_pe ) ) ); - Scale_sig( st->buf_speech_enc_pe + st->L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->L_frame ), sub( st->exp_buf_speech_enc_pe, s_max( tmp, st->exp_buf_speech_enc_pe ) ) ); - st->exp_buf_speech_enc_pe = s_max( tmp, st->exp_buf_speech_enc_pe ); -#endif + lerp( st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); + mvr2r( st->old_inp_16k, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM ); } -#ifndef IVAS_FLOAT_FIXED - st->mem_preemph_enc_flt = st->buf_speech_enc_flt[st->L_frame - 1]; - st->mem_wsp_enc_flt = st->buf_wspeech_enc_flt[st->L_frame + L_SUBFR - 1]; -#endif + st->mem_preemph_enc = st->buf_speech_enc[st->L_frame - 1]; + st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1]; } else if ( !st->tcxonly && last_total_brate > ACELP_32k ) /* coming from TCXonly modes */ { -#ifndef IVAS_FLOAT_FIXED - mvr2r( st->old_wsp, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM ); + mvr2r( st->old_wsp, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM ); /*Resamp buffers needed only for ACELP*/ if ( st->L_frame == L_FRAME16k ) { - lerp_flt( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); + lerp( st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); } - st->hLPDmem->mem_w0_flt = 0; - st->mem_wsp_enc_flt = st->buf_wspeech_enc_flt[st->L_frame + L_SUBFR - 1]; -#endif + st->hLPDmem->mem_w0 = 0; + st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1]; } -#ifndef IVAS_FLOAT_FIXED - st->new_speech_enc_flt = st->buf_speech_enc_flt + st->encoderPastSamples_enc + st->encoderLookahead_enc; + st->new_speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc + st->encoderLookahead_enc; + st->new_speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc + st->encoderLookahead_enc; - st->speech_enc_flt = st->buf_speech_enc_flt + st->encoderPastSamples_enc; + if ( hTcxEnc != NULL ) + { + hTcxEnc->new_speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc + st->encoderLookahead_enc; + } + + if ( st->hTcxEnc != NULL ) + { + st->hTcxEnc->new_speech_TCX = st->input_buff + st->input_Fs / FRAMES_PER_SEC; /* note: in EVS st->new_speech_TCX == st->input - 0.9375ms; in IVAS st->new_speech_TCX == st->input */ + st->hTcxEnc->speech_TCX = st->hTcxEnc->new_speech_TCX - st->encoderLookahead_FB; + } + + st->speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc; + st->speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc; + + if ( hTcxEnc != NULL ) + { + hTcxEnc->speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc; + } if ( st->element_mode > EVS_MONO ) { - st->wspeech_enc_flt = st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR; + st->wspeech_enc = st->buf_wspeech_enc + st->L_frame + L_SUBFR; } else { - st->wspeech_enc_flt = st->buf_wspeech_enc_flt + st->L_frame + L_subfr; + st->wspeech_enc = st->buf_wspeech_enc + st->L_frame + L_subfr; } + if ( st->ini_frame == 0 || st->L_frame != L_frame_old || st->last_codec_mode == MODE1 ) { - set_zero( st->buf_synth_flt, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); + set_zero( st->buf_synth, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); } - st->synth_flt = st->buf_synth_flt + st->L_frame + L_subfr; -#endif + st->synth = st->buf_synth + st->L_frame + L_subfr; return; } -#ifdef IVAS_FLOAT_FIXED +#else /*copy of evs function since it was static */ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr ) { @@ -950,6 +923,8 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol if ( hTcxEnc != NULL ) { set16_fx( hTcxEnc->buf_speech_ltp, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + hTcxEnc->exp_buf_speech_ltp = 0; + move16(); } set16_fx( st->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); /* increased by 320 to avoid memory overlap in ivas_find_wsp() and also to accomodate for the wspeech_enc */ st->exp_buf_wspeech_enc = 0; @@ -999,16 +974,17 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol lerp( st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM ); Copy( st->old_inp_16k_fx, st->buf_speech_enc_pe + st->L_frame - L_INP_MEM, L_INP_MEM ); /* SCaling to common exponent*/ - Scale_sig( st->buf_speech_enc_pe + sub( st->L_frame, L_INP_MEM ), L_INP_MEM, sub( st->exp_old_inp_12k8, s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ) ) ); - Scale_sig( st->buf_speech_enc_pe, sub( st->L_frame, L_INP_MEM ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ) ) ); - Scale_sig( st->buf_speech_enc_pe + st->L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->L_frame ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ) ) ); - st->exp_buf_speech_enc_pe = s_max( st->exp_old_inp_12k8, st->exp_buf_speech_enc_pe ); + Scale_sig( st->buf_speech_enc_pe + sub( st->L_frame, L_INP_MEM ), L_INP_MEM, sub( st->exp_old_inp_16k, s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe ) ) ); + Scale_sig( st->buf_speech_enc_pe, sub( st->L_frame, L_INP_MEM ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe ) ) ); + Scale_sig( st->buf_speech_enc_pe + st->L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->L_frame ), sub( st->exp_buf_speech_enc_pe, s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe ) ) ); + st->exp_buf_speech_enc_pe = s_max( st->exp_old_inp_16k, st->exp_buf_speech_enc_pe ); move16(); } st->mem_preemph_enc = st->buf_speech_enc[st->encoderPastSamples_enc + st->encoderLookahead_enc - 1]; move16(); st->exp_mem_preemph_enc = st->exp_buf_speech_enc; + move16(); st->mem_wsp_enc = shr( st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1], sub( Q16, st->exp_buf_wspeech_enc ) ); // Q-1 move16(); } @@ -1707,6 +1683,7 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh * *-----------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void init_modes( Encoder_State *st, const int32_t last_total_brate ) @@ -1768,8 +1745,7 @@ static void init_modes( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void init_modes_ivas_fx( Encoder_State *st, const Word32 last_total_brate ) diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index a3fa3e47b176125b7e00e5ad3a9a68bf37687000..3bde91b035642dc095efe0086f8ff602646c16d4 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -890,7 +890,6 @@ static void init_modes_fx( assert( st->fscale == 2 * st->L_frame ); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ tmp32 = L_shl( st->total_brate, 1 ); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ st->bits_frame_nominal = extract_l( L_shr( Mpy_32_16_1( tmp32, 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ - assert( st->bits_frame_nominal == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) ); IF( st->Opt_AMR_WB ) { diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index 9957ccdef4d3e7d169f40b5a4a3bf175ac09a424..e4782bb28dfc4ae86334e50d3eec546be4c0707b 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -1276,7 +1276,7 @@ void core_acelp_tcx20_switching_fx( move16(); } - IF( st->flag_noisy_speech_snr_fx ) + IF( st->flag_noisy_speech_snr ) { test(); IF( st->vad_flag || st->Opt_DTX_ON ) @@ -1295,7 +1295,7 @@ void core_acelp_tcx20_switching_fx( test(); test(); test(); - if ( EQ_32( st->sr_core, INT_FS_12k8 ) && ( LT_16( non_staX, 512 /*2.0f Q8*/ ) || ( st->flag_noisy_speech_snr_fx == 0 && EQ_16( st->vad_flag, 1 ) && ( offset_tcx == L_add( 0xFFD57AB5, 0 ) ) && GE_16( st->acelpFramesCount, 6 ) ) ) && + if ( EQ_32( st->sr_core, INT_FS_12k8 ) && ( LT_16( non_staX, 512 /*2.0f Q8*/ ) || ( st->flag_noisy_speech_snr == 0 && EQ_16( st->vad_flag, 1 ) && ( offset_tcx == L_add( 0xFFD57AB5, 0 ) ) && GE_16( st->acelpFramesCount, 6 ) ) ) && ( st->last_core == ACELP_CORE || st->last_core == TCX_20_CORE ) ) { st->core = st->last_core; diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index 268bd58ac41688fb95ff719de1bd70fa71522808..b3738eef9b47869bba55402da711c34d8187f4d8 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -85,7 +85,6 @@ void core_coder_mode_switch_fx( /* st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1( L_shl(st->bitrate,8), mult_r(div_s(st->fscale, shl(st->L_frame,4)), FL2WORD16(FSCALE_DENOM/12800.f))), 6)); */ tmp32 = L_shl( st->total_brate, 1 ); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ st->bits_frame_nominal = extract_l( L_shr( Mpy_32_16_1( tmp32, 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ - assert( st->bits_frame_nominal == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) ); st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index a4d506291546539e6790ade2018ec2cacb862d50..ae70dc6b33a5f4761cc65573c624c993b2f5394b 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -406,7 +406,7 @@ void coder_acelp_rf_fx( encode_acelp_gains_fx( code, acelp_cfg->gains_mode[j_subfr], Es_pred_rf, clip_gain, &g_corr, &gain_pit, &gain_code, &prm_rf, &past_gcode, - &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr_fx ); + &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr ); } diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 898a8b49a26a31b3319b088628a47873d27e728f..22e0b8b405f3ee0a4872daeddd726062532f534f 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -157,7 +157,7 @@ void encod_unvoiced_fx( *----------------------------------------------------------*/ index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, - st_fx->flag_noisy_speech_snr_fx, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); + st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); #ifdef DEBUGGING assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" ); @@ -413,7 +413,7 @@ void encod_unvoiced_ivas_fx( *----------------------------------------------------------*/ index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, - st_fx->flag_noisy_speech_snr_fx, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); + st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); #ifdef DEBUGGING assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" ); diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index fedb26afe4b303f4bb9cb427d6aee450ed88d410..d43510f99d5a02622e7f86de546fa5d2ebe15ddd 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -947,6 +947,9 @@ void core_signal_analysis_high_bitrate_ivas_fx( Copy_Scale_sig_16_32( tcx20Win, windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + ( left_overlap + right_overlap ) / 2, 0 ); *q_win = s_min( *q_win, sub( L_norm_arr( windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + ( left_overlap + right_overlap ) / 2 ), 1 ) ); move16(); +#ifdef MSAN_FIX + Scale_sig32( windowed_samples + frameno * L_FRAME_MAX + 2, win_len, *q_win ); +#endif } } @@ -1400,6 +1403,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( } } +#ifndef MSAN_FIX IF( windowed_samples != NULL ) { FOR( frameno = 0; frameno < nSubframes; frameno++ ) @@ -1410,6 +1414,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( } } } +#endif IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index fd7780c72ec6278624134830d90714231309d152..3ed8406485e0691572af2eda636609f9f5ee0834 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -66,6 +66,7 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) hsCom->numCoreBands = 16; move16(); hsCom->regularStopBand = idiv1616U( extract_l( L_shr( input_Fs, 5 ) ), 25 ); + move16(); if ( GT_16( hsCom->regularStopBand, 40 ) ) { hsCom->regularStopBand = 40; @@ -88,6 +89,7 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) hsCom->stopFFTbin = 256; move16(); hsCom->stopBand = add( sub( hsCom->regularStopBand, hsCom->numCoreBands ), hsCom->stopFFTbin ); + move16(); hsCom->nFFTpart = 20; move16(); } @@ -95,6 +97,7 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) initPartitions( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); + move16(); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); @@ -164,6 +167,7 @@ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variabl IF( EQ_16( hsCom->CngBandwidth, FB ) ) { hsCom->CngBandwidth = SWB; + move16(); } hsCom->CngBitrate = bitrate; move32(); @@ -268,6 +272,7 @@ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variabl BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr( hsCom->fftlen, 1 ) ); BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) ); hsCom->frameSize = shr( hsCom->fftlen, 1 ); + move16(); } void configureFdCngEnc_ivas_fx( diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 42377800a43ee1d5c62091820577967ea4b94c40..1f2afdd9b0a0e043f843e4112622d90877eb6c48 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -357,22 +357,11 @@ void hq_core_enc_ivas_fx( tcx_windowing_synthesis_past_frame( st->hTcxEnc->old_out_fx + nz, st->hTcxCfg->tcx_aldo_window_1_trunc, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, FULL_OVERLAP ); - FOR( i = 0; i < nz; i++ ) + FOR( i = 0; i < nz / 2; i++ ) { - Word16 reverse_index = sub( sub( nz, 1 ), i ); - - IF( LT_16( reverse_index, shr( nz, 1 ) ) ) - { - // Imaginary part: reverse index corresponds to imaginary part - st->hTcxEnc->old_out_fx[nz + overlap + i] = mult( wtda_audio_fx16[L_frame - 1 - i], st->hTcxCfg->tcx_aldo_window_1_trunc[-1 - i].v.im ); // Q0 + Q15 - Q15 -> Q0 - move16(); - } - ELSE - { - // Real part: reverse index - nz/2 corresponds to real part - st->hTcxEnc->old_out_fx[nz + overlap + i] = mult( wtda_audio_fx16[L_frame - 1 - i], st->hTcxCfg->tcx_aldo_window_1_trunc[-1 - ( i - shr( nz, 1 ) )].v.re ); // Q0 + Q15 - Q15 -> Q0 - move16(); - } + // This implementation is diffrent in float code need to revisit to check its correctness. + st->hTcxEnc->old_out_fx[nz + overlap + i] = mult( wtda_audio_fx16[L_frame - 1 - i], st->hTcxCfg->tcx_aldo_window_1_trunc[i].v.re ); // Q0 + Q15 - Q15 -> Q0; + st->hTcxEnc->old_out_fx[nz / 2 + ( nz + overlap + i )] = mult( wtda_audio_fx16[nz / 2 + ( L_frame - 1 - i )], st->hTcxCfg->tcx_aldo_window_1_trunc[nz / 2 - 1 - i].v.im ); // Q0 + Q15 - Q15 -> Q0; } Copy( wtda_audio_fx16 + sub( shr( overlap, 1 ), tcx_offset ), output_fx, st->L_frame ); diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 94876661894f9341db230a5d5e5bef392a8a79ca..32b3b195491f59984f0ad3b9c8ac9974c49a4dc6 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -348,9 +348,12 @@ void HQ_core_enc_init_fx( hHQ_core->hq_generic_speech_class = 0; move16(); hHQ_core->prev_Npeaks = 0; + move16(); set16_fx( hHQ_core->prev_peaks, 0, HVQ_MAX_PEAKS ); hHQ_core->hvq_hangover = 0; + move16(); hHQ_core->prev_hqswb_clas = HQ_NORMAL; + move16(); set16_fx( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); set16_fx( hHQ_core->prev_frm_index, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB ); @@ -369,7 +372,9 @@ void HQ_core_enc_init_fx( #ifdef MSAN_FIX hHQ_core->crest_lp_fx = HQ_CREST_THRESHOLD_FX; + move32(); hHQ_core->crest_mod_lp_fx = HQ_CREST_MOD_THRESHOLD_FX; + move32(); #endif return; diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 58148b43353499f7eb4ae518ffa6d38f79ce96f3..4b2e2d80b4c0129eee763528688ae56b6da19443 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -3770,7 +3770,7 @@ int16_t IGFEncWriteBitstream( * * sets the IGF mode according to given bitrate *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void IGFEncSetMode( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ const int32_t total_brate, /* i : encoder total bitrate */ @@ -3837,7 +3837,7 @@ void IGFEncSetMode( return; } -#ifdef IVAS_FLOAT_FIXED +#else void IGFEncSetMode_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ const Word32 total_brate, /* i : encoder total bitrate */ diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 81907c403b166ee9ceb9dd88d2f6ba90769d7ad1..0de32bdacd515ced7fe860618f586ed7e7ca7b02 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1533,16 +1533,10 @@ ivas_error IGF_Reconfig_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IGFEncSetMode( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#endif IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); } ELSE IF( igf && reset ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IGFEncSetMode( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#endif IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); } ELSE IF( !igf && *hIGFEnc != NULL ) diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 99491f144ecc8d90b29dca6b857b481092eefb3a..97e17265f2a00815b02d0e70514ab1e37d752284 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -485,7 +485,12 @@ ivas_error init_encoder( #ifdef IVAS_FLOAT_FIXED set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); +#ifdef MSAN_FIX + st->exp_old_inp_12k8 = 0; + move16(); +#endif st->exp_old_inp_16k = 0; + move16(); st->input_buff_fx = st->hSignalBuf->input_buff; st->input_buff32_fx = st->hSignalBuf->input_buff32; set32_fx( st->hSignalBuf->input_buff32, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); @@ -1612,6 +1617,8 @@ ivas_error init_encoder_ivas_fx( st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); + st->q_Bin_E_old = Q31; set16_fx( st->hSignalBuf->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); st->exp_buf_speech_enc = 0; move16(); @@ -2128,6 +2135,7 @@ ivas_error init_encoder_ivas_fx( st->rf_mode_last = st->rf_mode; move16(); + test(); IF( st->Opt_RF_ON || st->element_mode == EVS_MONO ) { IF( ( st->hRF = (RF_ENC_HANDLE) malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) @@ -2190,6 +2198,7 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); st->hTcxEnc->Q_old_out = 0; + move16(); /* MDCT selector */ MDCT_selector_reset_fx( st->hTcxEnc ); @@ -2363,7 +2372,21 @@ ivas_error init_encoder_ivas_fx( /* initialization for IVAS modes happens in first frame pre-processing */ IF( st->element_mode == EVS_MONO ) { - configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); + Word32 total_brate; + + test(); + IF( st->rf_mode && EQ_32( st->total_brate, ACELP_13k20 ) ) + { + total_brate = ACELP_9k60; + move32(); + } + ELSE + { + total_brate = st->total_brate; + move32(); + } + + configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, total_brate ); #if 1 configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); #endif diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index c8e6b0f12cfa7d0ca688ad3ab26ae44d67bfc0de..c0cc8e3643764fbad9cbee80d0ba469ec13e6029 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -125,7 +125,9 @@ ivas_error ivas_core_enc( FOR( i = 0; i < CPE_CHANNELS; i++ ) { set_zero_fx( bwe_exc_extended_fx[i], L_FRAME32k + NL_BUFF_OFFSET ); + set16_fx( old_syn_12k8_16k_fx[i], 0, L_FRAME16k ); } + set16_fx( shb_speech_fx, 0, L_FRAME16k ); #endif push_wmops( "ivas_core_enc" ); @@ -215,6 +217,19 @@ ivas_error ivas_core_enc( /*---------------------------------------------------------------------* * Pre-processing, incl. Decision matrix *---------------------------------------------------------------------*/ +#ifdef MSAN_FIX + IF( st->cldfbAnaEnc ) + { + Word16 tmp_shift = L_norm_arr( enerBuffer_fx[n], st->cldfbAnaEnc->no_channels ); + tmp_shift = sub( tmp_shift, 5 ); + IF( tmp_shift < 0 ) + { + scale_sig32( enerBuffer_fx[n], st->cldfbAnaEnc->no_channels, tmp_shift ); + enerBuffer_fx_exp[n] = sub( enerBuffer_fx_exp[n], tmp_shift ); + move16(); + } + } +#else Word16 tmp_shift = getScaleFactor32( enerBuffer_fx[n], CLDFB_NO_CHANNELS_MAX ); tmp_shift = sub( tmp_shift, 5 ); IF( tmp_shift < 0 ) @@ -223,6 +238,7 @@ ivas_error ivas_core_enc( enerBuffer_fx_exp[n] = sub( enerBuffer_fx_exp[n], tmp_shift ); move16(); } +#endif Scale_sig( fft_buff_fx[n], ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum // fft_buff_fx_exp = add(fft_buff_fx_exp,1); @@ -311,7 +327,8 @@ ivas_error ivas_core_enc( IF( st->core == ACELP_CORE ) { /* ACELP core encoder */ - Word16 Q_old_syn_12k8_16k; + Word16 Q_old_syn_12k8_16k = 0; + move16(); IF( ( error = acelp_core_enc( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ) != IVAS_ERR_OK ) { return error; @@ -425,7 +442,7 @@ ivas_error ivas_core_enc( FOR( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; - Scale_sig( old_inp_16k_fx[i], L_INP, sub( Q1, Q_new[i] ) ); // Q0 + Scale_sig( old_inp_16k_fx[n], L_INP, sub( Q1, Q_new[n] ) ); // Q0 IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->hTcxEnc->exp_buf_speech_ltp = st->exp_buf_speech_enc; diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index c64ddfc3f3a72726cafe59e94253cefdc41c571f..6735fc66a8954e00e65024f63327e1447134ac29 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -869,8 +869,7 @@ ivas_error pre_proc_front_ivas_fx( const Word16 input_frame, /* i : frame length */ const Word16 n, /* i : channel number */ Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ - float old_inp_12k8[], /* o : buffer of old input signal */ - float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q-1 */ Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ Word16 *relE_fx, /* o : frame relative energy Q8 */ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12 */ @@ -884,21 +883,22 @@ ivas_error pre_proc_front_ivas_fx( Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf) */ Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf) */ Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - float old_wsp[], /* o : weighted input signal buffer */ - Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ - Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ - Word16 *loc_harm, /* o : harmonicity flag */ - Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - Word16 *enerBuffer_fx_exp, /* o : energy buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ - Word16 *fft_buff_fx_q, /* o : FFT buffer */ - const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ - const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ - const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ - Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 *q_old_wsp, + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6 */ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15 */ + Word16 *loc_harm, /* o : harmonicity flag */ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8 */ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer */ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12 */ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */ + const Word16 currFlatness_fx, /* i : flatness parameter Q7 */ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) */ Word16 fr_bands_LR_fx_q, const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q) */ @@ -930,7 +930,9 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig( st->old_inp_12k8_fx, 240, shift ); st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); move16(); - f2me_buf_16( old_inp_12k8, old_inp_12k8_fx, &old_inp_12k8_e, 496 ); + shift = getScaleFactor16( old_inp_12k8_fx, 496 ); + Scale_sig( old_inp_12k8_fx, 496, shift ); + old_inp_12k8_e = sub( Q16, shift ); if ( old_inp_12k8_e > st->exp_old_inp_12k8 ) { Scale_sig( st->old_inp_12k8_fx, 240, st->exp_old_inp_12k8 - old_inp_12k8_e ); @@ -941,21 +943,12 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig( old_inp_12k8_fx, 496, old_inp_12k8_e - st->exp_old_inp_12k8 ); old_inp_12k8_e = st->exp_old_inp_12k8; } - float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ - float *wsp; /* weighted input signal buffer */ - float Etot; /* total energy */ - float lf_E[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - float tmpN[NB_BANDS]; /* Temporary noise update */ - float tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ - float tmpN_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ - float tmpE_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary averaged energy of 2 sf. */ - float PS[128]; /* speech/music clasif. parameters */ - float hp_E[2]; /* Energy in HF */ - float band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ - float *res_cod_SNR_M, tmpF[STEREO_DFT_BAND_MAX]; #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED - Word16 old_wsp_fx[L_WSP]; + Word16 q_tmpN_LR[CPE_CHANNELS]; + Word16 q_tmpE_LR[CPE_CHANNELS]; + Word16 q_tmpN; + Word16 q_tmpE; Word16 epsP_h[M + 1]; /* o : LP prediction errors */ Word16 epsP_l[M + 1]; /* o : LP prediction errors */ Word16 lr_vad_enabled; /* LR VAD indicator */ @@ -985,12 +978,9 @@ ivas_error pre_proc_front_ivas_fx( Word16 *inp_12k8_fx, *new_inp_12k8_fx; /* pointers to current frame and new data */ CLDFB_SCALE_FACTOR cldfbScale; Word16 *temp1F_icatdmResampBuf_fx; - Word16 *old_inp_16k_fx; Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ Word32 tmpF_fx[STEREO_DFT_BAND_MAX]; -#ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING Word32 *res_cod_SNR_M_fx; -#endif Word16 snr_sum_he_fx; /* HE SAD parameters */ Word16 new_inp_out_size; Word16 Q_new_inp; @@ -1029,8 +1019,9 @@ ivas_error pre_proc_front_ivas_fx( Word32 hp_E_fx[2]; /* Energy in HF */ Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; + Word16 band_energies_fx_exp, Qfact_PS, q_lf_E_fx; - old_inp_16k_fx = (Word16 *) malloc( 880 * sizeof( Word16 * ) ); mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); set16_fx( fft_buff_fx, 0, 512 ); @@ -1093,15 +1084,8 @@ ivas_error pre_proc_front_ivas_fx( move16(); tdm_SM_last_clas = &tmpS; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( tmpF, 0, STEREO_DFT_BAND_MAX ); - res_cod_SNR_M = tmpF; -#endif // IVAS_FLOAT - set32_fx( tmpF_fx, 0, STEREO_DFT_BAND_MAX ); -#ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING res_cod_SNR_M_fx = tmpF_fx; -#endif LR_localVAD = 0; move16(); @@ -1166,22 +1150,10 @@ ivas_error pre_proc_front_ivas_fx( IF( hCPE->hStereoDft != NULL ) { -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - res_cod_SNR_M = hCPE->hStereoDft->res_cod_SNR_M; -#endif -#ifndef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING res_cod_SNR_M_fx = hCPE->hStereoDft->res_cod_SNR_M_fx; -#endif } } -#if 0 - lgBin_E_fx = NULL; - if ( st != NULL ) - { - lgBin_E_fx = &st->lgBin_E_fx[0]; - } -#endif lMemRecalc_12k8 = 0; lMemRecalc = 0; move16(); @@ -1241,52 +1213,12 @@ ivas_error pre_proc_front_ivas_fx( L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ move16(); -#ifndef IVAS_FLOAT_FIXED - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ - inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ - - if ( NE_16( element_mode, IVAS_CPE_DFT ) ) - { - new_inp_12k8 -= L_FILT; - } - - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - STEREO_DFT_OVL_12k8 ); - } - else if ( element_mode == IVAS_CPE_TD ) - { - mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - lMemRecalc_12k8 - L_FILT ); - } - else - { - mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - L_FILT ); - } - wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ - - st->rf_mode = st->Opt_RF_ON; - - last_core_orig = st->last_core; -#else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Float to fix block start - /* - !!!! Scaling whole old_inp_12k8 to -1. Needs to be check later !!! - */ - floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); + Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( Q_to_be_looked_into, sub( Q15, old_inp_12k8_e ) ) ); + old_inp_12k8_e = sub( Q15, Q_to_be_looked_into ); Scale_sig( st->old_inp_12k8_fx, 240, sub( Q_to_be_looked_into, sub( Q15, st->exp_old_inp_12k8 ) ) ); st->exp_old_inp_12k8 = sub( Q15, Q_to_be_looked_into ); move16(); - - // Float to fix block end - - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ - inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ - - if ( NE_16( element_mode, IVAS_CPE_DFT ) ) - { - new_inp_12k8 -= L_FILT; - } #endif new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ inp_12k8_fx = new_inp_12k8_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ @@ -1309,11 +1241,9 @@ ivas_error pre_proc_front_ivas_fx( Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - L_FILT ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->old_wsp_fx, old_wsp, Q15 - st->exp_old_wsp, L_WSP_MEM ); - wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ -#endif Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); + *q_old_wsp = sub( Q15, st->exp_old_wsp ); + move16(); wsp_fx = old_wsp_fx + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ st->rf_mode = st->Opt_RF_ON; @@ -1321,10 +1251,6 @@ ivas_error pre_proc_front_ivas_fx( last_core_orig = st->last_core; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_to_be_looked_into, L_INP_12k8 ); -#endif -#endif /*--------------------------------------------------------------* * energy analysis @@ -1363,53 +1289,6 @@ ivas_error pre_proc_front_ivas_fx( * (if not available from downsampled DMX) *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - if ( element_mode == IVAS_SCE ) - { - modify_Fs( signal_in, input_frame, input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); - - mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); - set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); - modify_Fs( temp1F_icatdmResampBuf, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); - } - else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) - { - /* reconstruct past segment of the Secondary channel input signal when switching from DFT stereo */ - if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) - { - int16_t length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS ); - int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); - - modify_Fs( signal_in - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim, 0 ); - } - - modify_Fs( signal_in - lMemRecalc, input_frame, input_Fs, new_inp_12k8 - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); - mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); - - if ( lMemRecalc > 0 ) - { - modify_Fs( signal_in + input_frame - lMemRecalc, lMemRecalc, input_Fs, new_inp_12k8 + L_FRAME - lMemRecalc_12k8, INT_FS_12k8, mem_decim_dummy, ( st->max_bwidth == NB ) ); - } - set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); - modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); - } - else /* DFT stereo */ - { - /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ - mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); - } -#else -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Float to fix block start - /* - !!!! Scaling st->input_buff to -1. Needs to be check later. old_input_signal and input point to this common buffer !!! - */ - - // floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_to_be_looked_into, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - // input_fx and old_input_signal_fx already in Q(-1). All these point to input_buff - floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); -#endif test(); IF( EQ_16( element_mode, IVAS_SCE ) ) { @@ -1452,70 +1331,11 @@ ivas_error pre_proc_front_ivas_fx( /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ Copy( signal_in_fx + sub( input_frame, add( NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ), 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Float to fix block start - /* - !!!! Scaling st->input_buff to -1. Needs to be check later. old_input_signal and input point to this common buffer !!! - */ - - // fixedToFloat_arr( st->input_buff_fx, st->input_buff, Q_to_be_looked_into, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - // input_fx and old_input_signal_fx already in Q(-1). All these point to input_buff - fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_to_be_looked_into, L_INP_12k8 ); -#endif - old_inp_12k8_e = sub( 15, Q_to_be_looked_into ); -#ifndef IVAS_FLOAT_FIXED - /* save input resampled at 12.8kHz, non-preemhasised */ - if ( element_mode == IVAS_CPE_DFT ) - { -#ifndef IVAS_FLOAT_FIXED - mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8, st->buf_speech_enc_flt + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); -#else - Word16 tmp; - f2me_buf_16( new_inp_12k8 - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, &tmp, L_FRAME + STEREO_DFT_OVL_12k8 ); - /* SCaling to common exponent*/ - Scale_sig( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8, sub( tmp, s_max( tmp, st->exp_buf_speech_enc ) ) ); - Scale_sig( st->buf_speech_enc, L_FRAME32k - L_FRAME, sub( st->exp_buf_speech_enc, s_max( tmp, st->exp_buf_speech_enc ) ) ); - Scale_sig( st->buf_speech_enc + L_FRAME32k + L_FRAME, ( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ) - ( L_FRAME32k + L_FRAME ), sub( st->exp_buf_speech_enc, s_max( tmp, st->exp_buf_speech_enc ) ) ); - st->exp_buf_speech_enc = s_max( tmp, st->exp_buf_speech_enc ); -#endif - } - else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) - { -#ifndef IVAS_FLOAT_FIXED - mvr2r( new_inp_12k8 - lMemRecalc_12k8, st->buf_speech_enc_flt + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT ); -#else - Word16 tmp; - f2me_buf_16( new_inp_12k8 - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, &tmp, L_FRAME + lMemRecalc_12k8 + L_FILT ); - /* SCaling to common exponent*/ - Scale_sig( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT, sub( tmp, s_max( tmp, st->exp_buf_speech_enc ) ) ); - Scale_sig( st->buf_speech_enc, L_FRAME32k - L_FRAME, sub( st->exp_buf_speech_enc, s_max( tmp, st->exp_buf_speech_enc ) ) ); - Scale_sig( st->buf_speech_enc + L_FRAME32k + L_FRAME, ( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ) - ( L_FRAME32k + L_FRAME ), sub( st->exp_buf_speech_enc, s_max( tmp, st->exp_buf_speech_enc ) ) ); - st->exp_buf_speech_enc = s_max( tmp, st->exp_buf_speech_enc ); -#endif - } - else - { -#ifndef IVAS_FLOAT_FIXED - mvr2r( new_inp_12k8, st->buf_speech_enc_flt + L_FRAME32k, L_FRAME ); -#else - Word16 tmp; - f2me_buf_16( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, &tmp, L_FRAME ); - /* SCaling to common exponent*/ - Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, sub( tmp, s_max( tmp, st->exp_buf_speech_enc ) ) ); - Scale_sig( st->buf_speech_enc, L_FRAME32k, sub( st->exp_buf_speech_enc, s_max( tmp, st->exp_buf_speech_enc ) ) ); - Scale_sig( st->buf_speech_enc + L_FRAME32k + L_FRAME, ( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ) - ( L_FRAME32k + L_FRAME ), sub( st->exp_buf_speech_enc, s_max( tmp, st->exp_buf_speech_enc ) ) ); - - st->exp_buf_speech_enc = s_max( tmp, st->exp_buf_speech_enc ); -#endif - } -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); - // floatToFixed_arr( st->buf_speech_enc_flt, st->buf_speech_enc, Q_to_be_looked_into, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, -1 - ( 15 - st->exp_buf_speech_enc ) ); st->exp_buf_speech_enc = 16; -#endif + move16(); + /* save input resampled at 12.8kHz, non-preemhasised */ if ( element_mode == IVAS_CPE_DFT ) { @@ -1530,64 +1350,10 @@ ivas_error pre_proc_front_ivas_fx( Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_to_be_looked_into, L_INP_12k8 ); - // fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_to_be_looked_into, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); -#endif -#endif - /*------------------------------------------------------------------* * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ - - st->mem_preemph = st->mem_preemph_DFT; - st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; - - preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph ); - dummy = st->mem_preemph; - preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy ); - } - else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) - { - if ( st->idchan == 0 ) - { - if ( hCPE->last_element_mode == IVAS_CPE_DFT ) - { - st->mem_preemph = st->mem_preemph_DFT; - mvr2r( st->inp_12k8_mem_stereo_sw, new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); - preemph( new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph ); - } - - st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ - } - - /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ - if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) - { - int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); - preemph( new_inp_12k8 - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph ); - } - - preemph( new_inp_12k8 - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph ); - dummy = st->mem_preemph; - preemph( new_inp_12k8 - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy ); - } - else /* IVAS_SCE or IVAS_CPE_MDCT */ - { - preemph( new_inp_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph ); - dummy = st->mem_preemph; - preemph( new_inp_12k8 + L_FRAME, PREEMPH_FAC, L_FILT, &dummy ); - } -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); -#endif - Word16 Q_new = 1; IF( Q_new ) @@ -1718,19 +1484,6 @@ ivas_error pre_proc_front_ivas_fx( Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, Q_new ); - /* - Q_exp = sub(*Q_new, st->Q_old); - st->prev_Q_old = st->Q_old; - move16(); - st->Q_old = *Q_new; - move16(); - - // Scaling of memories - - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, Q_new, old_inp_12k8, &( st->mem_wsp_fx ), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, - hNoiseEst->ave_enr_fx, hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); - */ - Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), Q_new ); Q_new = add( Q_new, Q_to_be_looked_into ); @@ -1739,33 +1492,12 @@ ivas_error pre_proc_front_ivas_fx( { // See if needed } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_new, L_INP_12k8 ); - cldfbScale.hb_scale = cldfbScale.lb_scale; -#endif -#endif -#if 0 - /*------------------------------------------------------------------* - * Scaling of memories - *-----------------------------------------------------------------*/ - Q_new = 0; - floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); - floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); - floatToFixed_arrL( st->hNoiseEst->ave_enr2, st->hNoiseEst->ave_enr2_fx, Q_new + QSCALE, 20 ); - floatToFixed_arrL( st->hNoiseEst->fr_bands1, st->hNoiseEst->fr_bands1_fx, Q_new + QSCALE, 20 ); - floatToFixed_arrL( st->hNoiseEst->fr_bands2, st->hNoiseEst->fr_bands2_fx, Q_new + QSCALE, 20 ); - - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame, Q_exp, &Q_new, old_inp_12k8_fx, &( st->mem_wsp_fx ), st->hNoiseEst->enrO_fx, st->hNoiseEst->bckr_fx, - st->hNoiseEst->ave_enr_fx, st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->fr_bands1_fx, st->hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); -#endif /*-------------------------------------------------------------------------* * Spectral analysis *--------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - analy_sp( element_mode, hCPE, input_Fs, inp_12k8, st->Bin_E, st->Bin_E_old, fr_bands, lf_E, &Etot, st->min_band, st->max_band, band_energies, PS, fft_buff ); -#else + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 *lgBin_E_fx; Word32 PS_fx[128]; @@ -1778,49 +1510,35 @@ ivas_error pre_proc_front_ivas_fx( Word16 Scale_fac[2] = { 0 }; #endif - Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); - st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 ); - move16(); Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); move16(); Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ ); + st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 ); + move16(); fr_bands_fx_q = add( Q_new, QSCALE ); - + band_energies_fx_exp = sub( 31, add( Q_new, QSCALE ) ); + Qfact_PS = add( Q_new, QSCALE - 2 ); + q_lf_E_fx = add( Q_new, QSCALE - 2 ); IF( lgBin_E_fx != NULL ) { Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( band_energies_fx, band_energies, Q_new + QSCALE, 40 ); - fixedToFloat_arrL( lf_E_fx, lf_E, Q_new + QSCALE - 2, 148 ); - fixedToFloat_arrL( PS_fx, PS, Q_new + QSCALE - 2, 128 ); - Etot = fixedToFloat( Etot_fx, Q8 ); - // fixedToFloat_arr( fft_buff_fx, fft_buff, Q_new + QSCALE + Scale_fac[0] - 14 -1, 512 ); -#endif Word16 min_q = MAX_16, fft_q[2]; FOR( int i_sbfr = 0; i_sbfr < 2; i_sbfr++ ) { fft_q[i_sbfr] = add( Q_new, Scale_fac[i_sbfr] ); move16(); min_q = s_min( min_q, fft_q[i_sbfr] ); - // fixedToFloat_arr( fft_buff_fx + i_sbfr * L_FFT, fft_buff + i_sbfr * L_FFT, Q_new + Scale_fac[i_sbfr], L_FFT ); } FOR( int i_sbfr = 0; i_sbfr < 2; i_sbfr++ ) { Scale_sig( fft_buff_fx + i_sbfr * L_FFT, L_FFT, sub( min_q, fft_q[i_sbfr] ) ); } *fft_buff_fx_q = min_q; -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Etot_fx = (Word16) ( Etot * ( 1 << 8 ) ); - - /*float to fix conversions for wb_vad_ivas_fx*/ - st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED Word16 Q_bands0 = 0, Q_bands1 = 0; move16(); move16(); @@ -1863,7 +1581,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float + st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float move16(); move16(); move16(); @@ -1975,24 +1693,15 @@ ivas_error pre_proc_front_ivas_fx( corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx ); corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx ); + q_tmpN_LR[0] = q_tmpE_LR[0] = add( Q_bands0, QSCALE ); + move16(); + move16(); + q_tmpN_LR[1] = q_tmpE_LR[1] = add( Q_bands1, QSCALE ); + move16(); + move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->flag_noisy_speech_snr = (Word16) st->flag_noisy_speech_snr_fx; - - /*fixed to float for noise_est_down*/ - fixedToFloat_arrL( tmpN_fx, tmpN, Q_new + QSCALE, 20 ); - fixedToFloat_arrL( tmpE_fx, tmpE, Q_new + QSCALE, 20 ); - - /*fixed to float for noise_est_down_fx concerned with fr_bands_LR*/ - IF( lr_vad_enabled && st->idchan == 0 ) - { - fixedToFloat_arrL( tmpN_LR_fx[0], tmpN_LR[0], Q_bands0 + QSCALE, 20 ); - fixedToFloat_arrL( tmpE_LR_fx[0], tmpE_LR[0], Q_bands0 + QSCALE, 20 ); - fixedToFloat_arrL( tmpN_LR_fx[1], tmpN_LR[1], Q_bands1 + QSCALE, 20 ); - fixedToFloat_arrL( tmpE_LR_fx[1], tmpE_LR[1], Q_bands1 + QSCALE, 20 ); - } -#endif - + q_tmpN = q_tmpE = add( Q_new, QSCALE ); + move16(); *relE_fx = sub( Etot_fx, st->lp_speech_fx ); move16(); @@ -2044,16 +1753,13 @@ ivas_error pre_proc_front_ivas_fx( } else { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 band_energies_fx_exp; /* energy in critical bands without minimum noise floor E_MIN */ - - Word16 q_band_energies = Q_factor_arrL( band_energies, 2 * NB_BANDS ); - band_energies_fx_exp = 31 - q_band_energies; - floatToFixed_arrL( band_energies, band_energies_fx, ( 31 - band_energies_fx_exp ), 2 * NB_BANDS ); -#endif Word16 normmsPeriodog_fx = Q31, zero_flag = 0; move16(); move16(); + shift = getScaleFactor32( band_energies_fx, 2 * NB_BANDS ); + scale_sig32( band_energies_fx, 2 * NB_BANDS, shift ); + band_energies_fx_exp = sub( band_energies_fx_exp, shift ); + zero_flag = get_zero_flag( st->hFdCngEnc->msPeriodog_fx, NPART ); IF( zero_flag ) { @@ -2112,11 +1818,7 @@ ivas_error pre_proc_front_ivas_fx( st->cng_type = LP_CNG; move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_inp_12k8 = Q_factor_arr( inp_12k8, L_FRAME ); - floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, L_FRAME ); -#endif - dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_inp_12k8 ); + dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_new ); test(); test(); @@ -2201,35 +1903,12 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * LP analysis *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 *old_inp_12k8_loc_fx = (Word16 *) malloc( L_INP_12k8 * sizeof( Word16 ) ); - Word16 *inp_12k8_loc_fx, *new_inp_12k8_loc_fx; /* pointers to current frame and new data */ - new_inp_12k8_loc_fx = old_inp_12k8_loc_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ - inp_12k8_loc_fx = new_inp_12k8_loc_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ Word16 stab_fac_fx; Word16 Q_new_loc; - Word16 e_new_loc; - Word16 Q_r[2] = { 0 }; - Q_new_loc = ( Q_factor_arr( old_inp_12k8, L_INP_12k8 ) - 1 ); // 1 is the guard bit - // Q_new_loc = 0; /* Dynamic Q_new used above causes overflow issues */ - for ( int k = 0; k < L_INP_12k8; k++ ) - { - if ( fabs( old_inp_12k8[k] ) > 32768.0f ) - { - Q_new_loc = -1; - break; - } - } - if ( Q_new_loc < 0 ) - { - f2me_buf_16( old_inp_12k8, old_inp_12k8_loc_fx, &e_new_loc, L_INP_12k8 ); - Q_new_loc = 15 - e_new_loc; - } - else - { - floatToFixed_arr( old_inp_12k8, old_inp_12k8_loc_fx, Q_new_loc, L_INP_12k8 ); - } -#endif + Word16 Q_r[2]; + set16_fx( Q_r, 0, 2 ); + Q_new_loc = Q_new; + move16(); alw_pitch_lag_12k8[0] = st->old_pitch_la; move16(); @@ -2251,7 +1930,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - analy_lp_ivas_fx( inp_12k8_loc_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, + analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, i, Q_new_loc, Q_r ); FOR( int idx = 0; idx < M + 1; idx++ ) @@ -2267,9 +1946,6 @@ ivas_error pre_proc_front_ivas_fx( Copy( lsf_new_fx, st->lsf_old1_fx, M ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - free( old_inp_12k8_loc_fx ); -#endif if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) { /*----------------------------------------------------------------* @@ -2278,11 +1954,9 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 speech_buff[L_FRAME + M]; - Word16 Q_speech = Q_factor_arrL( inp_12k8 - M, L_FRAME + M ); - Word16 gb1 = find_guarded_bits_fx( M ); - floatToFixed_arr32( inp_12k8 - M, speech_buff, Q_speech - gb1, L_FRAME + M ); + Copy_Scale_sig_16_32( inp_12k8_fx - M, speech_buff, L_FRAME + M, Q12 ); #endif - hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), Q_speech ); + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( Q_new, 12 ) ); move16(); } @@ -2293,53 +1967,34 @@ ivas_error pre_proc_front_ivas_fx( * 1/4 pitch precision improvement *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 buf[15000] = { 0 }; - Word16 *inp_12k8_fx1 = &buf[M]; // this is done because find_wsp accesses inp from -16 index - Word16 wsp_fx1[L_FRAME + L_LOOK_12k8] = { 0 }; - - Word16 e1, q_inp_12k8; - f2me_buf_16( inp_12k8 - M, inp_12k8_fx1, &e1, 368 + M ); - q_inp_12k8 = s_min( sub( 15, e1 ), st->mem_wsp_q ); - for ( i = -M; i < 368; i++ ) - { /* starting index from -16 */ - inp_12k8_fx1[i] = (Word16) floatToFixed( inp_12k8[i], q_inp_12k8 ); - } - st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( q_inp_12k8, st->mem_wsp_q ) ); - st->mem_wsp_q = q_inp_12k8; + st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( Q_new, st->mem_wsp_q ) ); + st->mem_wsp_q = Q_new; move16(); move16(); -#endif - ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx1, TILT_FAC_FX, wsp_fx1, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); + ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); + Word16 Q_wsp = Q_new; + move16(); IF( EQ_16( st->vad_flag, 0 ) ) { /* reset the OL pitch tracker memories during inactive frames */ pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < L_FRAME + L_LOOK_12k8; i++ ) - { - wsp[i] = fixedToFloat( wsp_fx1[i], q_inp_12k8 ); - } -#endif - old_pitch1 = st->pitch[1]; move16(); -#ifdef IVAS_FLOAT_FIXED - Word16 exp_wsp = 0, Q_wsp = 0; + Word16 shift1 = getScaleFactor16( old_wsp_fx, L_WSP_MEM ); + Word16 shift2 = getScaleFactor16( wsp_fx, L_WSP - L_WSP_MEM ); + + shift = s_min( add( *q_old_wsp, shift1 ), add( Q_wsp, shift2 ) ); + Scale_sig( old_wsp_fx, L_WSP_MEM, sub( shift, add( *q_old_wsp, shift1 ) ) ); + Scale_sig( wsp_fx, L_WSP - L_WSP_MEM, sub( shift, add( Q_wsp, shift2 ) ) ); + *q_old_wsp = shift; + move16(); + Q_wsp = shift; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); - wsp_fx = old_wsp_fx + L_WSP_MEM; - f2me_buf_16( wsp, wsp_fx, &exp_wsp, L_WSP - L_WSP_MEM ); - Q_wsp = sub( 15, exp_wsp ); - floatToFixed_arr( wsp, wsp_fx, Q_wsp, L_WSP - L_WSP_MEM ); -#endif Scale_sig( st->mem_decim2_fx, 3, sub( Q_wsp, st->Q_old_wsp2 ) ); // Q( mem_decim ) = Q( old_wsp2 ) Scale_sig( st->old_wsp2_fx, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM, sub( Q_wsp, st->Q_old_wsp2 ) ); st->Q_old_wsp2 = Q_wsp; @@ -2347,61 +2002,96 @@ ivas_error pre_proc_front_ivas_fx( pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, *relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); - -#else - pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, *relE, L_look, st->clas, st->input_bwidth, st->Opt_SC_VBR ); -#endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + test(); + IF( lr_vad_enabled && st->idchan == 0 ) + { + FOR( i = 0; i < 2; i++ ) + { + shift = getScaleFactor32( tmpN_LR_fx[i], NB_BANDS ); + scale_sig32( tmpN_LR_fx[i], NB_BANDS, shift ); + q_tmpN_LR[i] = add( q_tmpN_LR[i], shift ); - Word16 q_wsp = Q_factor_arr( old_wsp, L_WSP ) - 3; - floatToFixed_arr16( old_wsp, old_wsp_fx, q_wsp, L_WSP ); + shift = getScaleFactor32( tmpE_LR_fx[i], NB_BANDS ); + scale_sig32( tmpE_LR_fx[i], NB_BANDS, shift ); + q_tmpE_LR[i] = add( q_tmpE_LR[i], shift ); + } + } + shift = getScaleFactor32( tmpN_fx, NB_BANDS ); + scale_sig32( tmpN_fx, NB_BANDS, shift ); + q_tmpN = add( q_tmpN, shift ); + shift = getScaleFactor32( tmpE_fx, NB_BANDS ); + scale_sig32( tmpE_fx, NB_BANDS, shift ); + q_tmpE = add( q_tmpE, shift ); + + shift = getScaleFactor32( lf_E_fx, 2 * VOIC_BINS ); + scale_sig32( lf_E_fx, 2 * VOIC_BINS, shift ); + q_lf_E_fx = add( q_lf_E_fx, shift ); + + shift = sub( getScaleFactor16( old_wsp_fx, L_WSP ), 3 ); + Scale_sig( old_wsp_fx, L_WSP, shift ); + *q_old_wsp = add( *q_old_wsp, shift ); + Q_wsp = *q_old_wsp; + move16(); Word16 q_fr_bands = Q30; - q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpN, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpE, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, fr_bands_fx_q - 4 /* needs 4 gaurd bits for summation */ ); - q_fr_bands = min( q_fr_bands, st->hNoiseEst->q_bckr ); - q_fr_bands = min( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ); - q_fr_bands = min( q_fr_bands, st->hNoiseEst->ave_enr_q ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( lf_E, 2 * VOIC_BINS ) + 2 ); + move16(); + q_fr_bands = s_min( q_fr_bands, q_tmpN ); + q_fr_bands = s_min( q_fr_bands, q_tmpE ); + q_fr_bands = s_min( q_fr_bands, sub( fr_bands_fx_q, 4 ) /* needs 4 gaurd bits for summation */ ); + q_fr_bands = s_min( q_fr_bands, st->hNoiseEst->q_bckr ); + q_fr_bands = s_min( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ); + q_fr_bands = s_min( q_fr_bands, st->hNoiseEst->ave_enr_q ); + q_fr_bands = s_min( q_fr_bands, add( q_lf_E_fx, 2 ) ); - if ( lr_vad_enabled && st->idchan == 0 ) + test(); + IF( lr_vad_enabled && st->idchan == 0 ) { - for ( int j = 0; j < 2; j++ ) + FOR( int j = 0; j < 2; j++ ) { - q_fr_bands = min( q_fr_bands, lf_E_LR_fx_q + 2 ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpN_LR[j], NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpE_LR[j], NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, fr_bands_LR_fx_q ); - q_fr_bands = min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ); - q_fr_bands = min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ); - q_fr_bands = min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ); + q_fr_bands = s_min( q_fr_bands, add( lf_E_LR_fx_q, 2 ) ); + q_fr_bands = s_min( q_fr_bands, q_tmpN_LR[j] ); + q_fr_bands = s_min( q_fr_bands, q_tmpE_LR[j] ); + q_fr_bands = s_min( q_fr_bands, fr_bands_LR_fx_q ); + q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ); + q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ); + q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ); } + } + Word16 q_inp_12k8 = Q_new; // inp_12k8_fx + move16(); - for ( int j = 0; j < 2; j++ ) + scale_sig32( lf_E_fx, 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), q_lf_E_fx ) ); + q_lf_E_fx = sub( q_fr_bands, 2 ); + scale_sig32( tmpN_fx, NB_BANDS, sub( q_fr_bands, q_tmpN ) ); + q_tmpN = q_fr_bands; + + scale_sig32( tmpE_fx, NB_BANDS, sub( q_fr_bands, q_tmpE ) ); + q_tmpE = q_fr_bands; + + test(); + IF( lr_vad_enabled && st->idchan == 0 ) + { + FOR( i = 0; i < 2; i++ ) { - floatToFixed_arr32( tmpN_LR[j], tmpN_LR_fx[j], q_fr_bands, NB_BANDS ); - floatToFixed_arr32( tmpE_LR[j], tmpE_LR_fx[j], q_fr_bands, NB_BANDS ); + scale_sig32( tmpN_LR_fx[i], NB_BANDS, sub( q_fr_bands, q_tmpN_LR[i] ) ); + q_tmpN_LR[i] = q_fr_bands; + move16(); + + scale_sig32( tmpE_LR_fx[i], NB_BANDS, sub( q_fr_bands, q_tmpE_LR[i] ) ); + q_tmpE_LR[i] = q_fr_bands; + move16(); } } - floatToFixed_arr32( tmpN, tmpN_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( tmpE, tmpE_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( lf_E, lf_E_fx, q_fr_bands - 2, 2 * VOIC_BINS ); - - q_inp_12k8 = Q_factor_arr( old_inp_12k8, L_INP_12k8 ); // inp_12k8_fx - floatToFixed_arr16( old_inp_12k8, old_inp_12k8_fx, q_inp_12k8, L_INP_12k8 ); - -#endif // IVAS_FLOAT_FIXED_CONVERSIONS scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( q_fr_bands, fr_bands_fx_q ) ); fr_bands_fx_q = q_fr_bands; move16(); Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); /* Detection of very short stable pitch period */ - StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, q_wsp, st->lgBin_E_fx ); + StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *q_old_wsp, st->lgBin_E_fx ); /* 1/4 pitch precision improvement */ IF( LE_32( element_brate, IVAS_32k ) ) @@ -2453,10 +2143,6 @@ ivas_error pre_proc_front_ivas_fx( { fr_bands_fx[k] = L_max( 1, fr_bands_fx[k] ); move32(); - /*st->hNoiseEst->fr_bands1_fx[k] = L_max(1, st->hNoiseEst->fr_bands1_fx[k]); - move32(); - st->hNoiseEst->fr_bands2_fx[k] = L_max(1, st->hNoiseEst->fr_bands2_fx[k]); - move32();*/ } noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div, @@ -2559,10 +2245,6 @@ ivas_error pre_proc_front_ivas_fx( Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); -#endif - /*-----------------------------------------------------------------* * channel aware mode configuration * *-----------------------------------------------------------------*/ @@ -2579,7 +2261,7 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 oi12k8_fx[L_INP_12k8]; - floatToFixed_arr( old_inp_12k8, oi12k8_fx, 0, L_INP_12k8 ); // Q_fac doesn't matter as it is only being used for sign + Copy_Scale_sig( old_inp_12k8_fx, oi12k8_fx, L_INP_12k8, negate( Q_new ) ); // Q0 Word16 *ni12k8_fx = oi12k8_fx + L_INP_MEM; inp_12k8_fx = ni12k8_fx - L_look; #endif @@ -2616,11 +2298,11 @@ ivas_error pre_proc_front_ivas_fx( * 1st stage speech/music classification (GMM model) *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; - Word16 Qfact_PS = Q_factor_arrL( PS, 128 ); - floatToFixed_arr32( PS, PS_fx, Qfact_PS, 128 ); -#endif + shift = getScaleFactor32( PS_fx, 128 ); + scale_sig32( PS_fx, 128, shift ); + Qfact_PS = add( Qfact_PS, shift ); + smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, Etot_fx, lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, hSpMusClas->past_PS_Q ); /*----------------------------------------------------------------* @@ -2678,16 +2360,10 @@ ivas_error pre_proc_front_ivas_fx( { if ( ivas_format == SBA_FORMAT && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA && st->sba_br_sw_while_no_data ) { -#ifdef IVAS_FLOAT_FIXED SetModeIndex_ivas_fx( st, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), element_mode, MCT_flag ); st->sba_br_sw_while_no_data = 0; move16(); -#else - SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); - - st->sba_br_sw_while_no_data = 0; -#endif // IVAS_FLOAT_FIXED } else if ( ivas_format == SBA_FORMAT && st->core_brate == FRAME_NO_DATA && element_brate != last_element_brate ) { @@ -2700,14 +2376,7 @@ ivas_error pre_proc_front_ivas_fx( st->q_inp = -1; move16(); } -/* these are for ivas_acelp_tcx20_switching_fx */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 res_cod_SNR_M_fx[STEREO_DFT_BAND_MAX]; - Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; - Word16 wsp_fx_temp[L_WSP]; - Word16 *wsp_fx_l; - // floatToFixed_arrL( st->hTcxEnc->spectrum_long, st->hTcxEnc->spectrum_long_fx, Q15, N_MAX ); -#endif + /* these are for ivas_acelp_tcx20_switching_fx */ Scale_sig32( st->hTcxEnc->spectrum_long_fx, N_MAX, sub( st->hTcxEnc->spectrum_long_e, 16 ) ); st->hTcxEnc->spectrum_long_e = 16; move16(); @@ -2720,7 +2389,6 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_old_inp_16k = -1; - floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, 880 ); Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, Q_old_inp_16k ) ) ); st->exp_old_inp_16k = sub( Q15, Q_old_inp_16k ); @@ -2752,54 +2420,21 @@ ivas_error pre_proc_front_ivas_fx( return error; } *epsP_fx_q = add( Q_r[0], 1 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // No need to do fixed to float for signal_in_fx - fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); -#endif -#ifdef IVAS_FLOAT_FIXED Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q15, st->exp_buf_speech_enc ) ); smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, 0, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < 7; i++ ) - { - res_cod_SNR_M[i] = me2f( res_cod_SNR_M_fx[i], res_cod_SNR_M_fx_e[i] ); - } -#endif -#else - smc_dec = ivas_acelp_tcx20_switching( st, st->speech_enc_flt, st->wspeech_enc_flt, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); -#endif } else { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS #define ATT_SEG_LEN ( L_FRAME / ATT_NSEG ) - // Q_new = s_min(Q_factor_arr( inp_12k8, ATT_NSEG * ATT_SEG_LEN ), Q_factor_arr( st->Bin_E, 256 )) - 1; - Q_new = 0; /* Dynamic Q_new used above causes overflow issues */ - for ( int k = 0; k < ATT_NSEG * ATT_SEG_LEN; k++ ) - { - if ( fabs( inp_12k8[k] ) > 32768.0f ) - { - Q_new = -1; - break; - } - } - floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_new, ATT_NSEG * ATT_SEG_LEN ); - floatToFixed_arr( wsp - L_WSP_MEM, wsp_fx_temp, Q_new, L_WSP_MEM ); - wsp_fx_l = wsp_fx_temp + L_WSP_MEM; - floatToFixed_arr( wsp, wsp_fx_l, Q_new, L_WSP - L_WSP_MEM ); -#endif - smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < 7; i++ ) - { - res_cod_SNR_M[i] = me2f( res_cod_SNR_M_fx[i], res_cod_SNR_M_fx_e[i] ); - } -#endif -#else - smc_dec = ivas_acelp_tcx20_switching( st, inp_12k8, wsp, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); #endif + Scale_sig( old_wsp_fx, L_WSP, sub( Q_new, *q_old_wsp ) ); + *q_old_wsp = Q_new; + move16(); + Q_wsp = Q_new; + move16(); + smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); } } /* Switch to ACELP for non-harmonic transient signals */ @@ -2826,30 +2461,12 @@ ivas_error pre_proc_front_ivas_fx( } } } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#define ATT_SEG_LEN ( L_FRAME / ATT_NSEG ) - Q_new = 0; /* Dynamic Q_new used above causes overflow issues */ - for ( int k = 0; k < ATT_NSEG * ATT_SEG_LEN; k++ ) - { - if ( fabs( inp_12k8[k] ) > 32768.0f ) - { - Q_new = -1; - break; - } - } - floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_new, ATT_NSEG * ATT_SEG_LEN ); -#endif // IVAS_FLOAT_FIXED_CONVERSIONS Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); move16(); /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); -#else - /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ - ivas_smc_mode_selection( st, element_brate, smc_dec, *relE, Etot, attack_flag, inp_12k8, S_map, flag_spitch ); -#endif // IVAS_FLOAT_FIXED } /*----------------------------------------------------------------* @@ -2865,11 +2482,13 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Update old input signal buffer *-----------------------------------------------------------------*/ + shift = getScaleFactor16( &old_inp_12k8_fx[L_FRAME], L_INP_MEM ); + Copy_Scale_sig( &old_inp_12k8_fx[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM, shift ); + st->exp_old_inp_12k8 = sub( Q15, add( Q_new, shift ) ); - f2me_buf_16( &old_inp_12k8[L_FRAME], st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); + Scale_sig( old_inp_12k8_fx, L_INP_12k8, negate( add( Q_new, 1 ) ) ); #ifdef IVAS_FLOAT_FIXED - free( old_inp_16k_fx ); free( mem_decim_dummy_fx ); free( temp1F_icatdmResampBuf_fx ); #endif diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index a632c517e2aa892886fa98e21b14d220bd0663b7..a121e2b61dd3bfbf9ab156658de6cb6c4173bf81 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -629,9 +629,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nb_bits = 0; move16(); + test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { - test(); IF( hBstr->ind_list[i].nb_bits > 0 ) { temp_ind_list[i].id = hBstr->ind_list[i].id; @@ -674,8 +674,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ); - shift = getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ) ); - Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, add( input_frame, NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ), shift ); + shift = getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame ); + Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, shift ); st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ); @@ -694,8 +694,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ); - shift = getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ) ); - Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, add( input_frame, NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ), shift ); + shift = getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame ); + Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, shift ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ); @@ -711,7 +711,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ) ); st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = q_com; move16(); - Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); + Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = q_com; move16(); Copy_Scale_sig_16_32( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, add( Q6, q_com ) ); @@ -729,7 +729,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = q_com; move16(); - Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); + Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = q_com; move16(); Copy_Scale_sig_16_32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, add( Q6, q_com ) ); @@ -803,6 +803,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */ + test(); IF( GT_16( st_ivas->nCPE, 1 ) && EQ_16( nCPE_old, 1 ) ) { free( st_ivas->hCPE[0]->hStereoMdct ); @@ -941,9 +942,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); IF( st_ivas->nSCE > 0 ) { + test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { - test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -965,9 +966,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } ELSE IF( st_ivas->nCPE > 0 ) { + test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { - test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -980,6 +981,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); i = add( i, 1 ); + test(); } st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i; move16(); @@ -1005,9 +1007,6 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } } - test(); - test(); - IF( st_ivas->nSCE ) { IF( NE_16( input_frame, len_inp_memory ) ) @@ -1050,6 +1049,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( } } + test(); + test(); IF( GT_16( st_ivas->nCPE, 1 ) && LE_16( nCPE_old, 1 ) ) { IF( EQ_16( nCPE_old, 1 ) ) @@ -1121,6 +1122,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) ) /* 1/50 in Q31*/; // ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + move16(); st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index e10443173fdf73f491957ba433d6eeed1f04bbe0..5bcf2df8cf2681f4b13b6fe36b8c8de2ec6d0da3 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -80,17 +80,11 @@ ivas_error ivas_cpe_enc_fx( CPE_ENC_HANDLE hCPE; Encoder_State **sts; Word16 n, n_CoreChannels; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float old_inp_12k8[CPE_CHANNELS][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ - float old_inp_16k[CPE_CHANNELS][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ -#else - float old_inp_12k8[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ - float old_inp_16k[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ -#endif #ifdef IVAS_FLOAT_FIXED - Word32 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ - Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ - Word32 old_inp_16k_fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ + Word32 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q16 */ + Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */ + Word32 old_inp_16k_fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q16 */ + Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q-1 */ Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ Word16 fft_buff_fx_q[CPE_CHANNELS]; /* FFT buffer */ Word16 fft_buff_fx_final_q = MAX_16; @@ -108,7 +102,6 @@ ivas_error ivas_cpe_enc_fx( Word32 realBuffer_fx[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ Word32 imagBuffer_fx[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ Word16 q_re_im_buf[CPE_CHANNELS]; - float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ Word16 pitch_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q6, fractional pitch values */ Word16 voicing_fr_fx[CPE_CHANNELS][NB_SUBFR]; /* Q15, fractional pitch gains */ Word16 loc_harm[CPE_CHANNELS]; /* harmonicity flag */ @@ -139,6 +132,8 @@ ivas_error ivas_cpe_enc_fx( Word32 cpe_brate; Word32 element_brate_ref; Word16 last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ + Word16 old_wsp_fx[CPE_CHANNELS][L_WSP]; + Word16 e_old_wsp[CPE_CHANNELS], q_old_wsp; error = IVAS_ERR_OK; move32(); @@ -183,6 +178,8 @@ ivas_error ivas_cpe_enc_fx( FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) { set16_zero_fx( fft_buff_fx[i], 2 * L_FFT ); + set16_zero_fx( old_inp_16k_16fx[i], L_INP ); + set_zero_fx( old_inp_16k_fx[i], L_INP ); } #endif /*------------------------------------------------------------------* @@ -250,7 +247,6 @@ ivas_error ivas_cpe_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( n = 0; n < CPE_CHANNELS; n++ ) { - sts[n]->flag_noisy_speech_snr_fx = (Word8) sts[n]->flag_noisy_speech_snr; Q_buffer[n] = 15; move16(); } @@ -769,7 +765,6 @@ ivas_error ivas_cpe_enc_fx( internal_Fs = getTcxonly_ivas_fx( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); /* iDFT at input sampling rate */ -#ifdef IVAS_FLOAT_FIXED Word16 out_start_ind, out_end_ind; Word16 out_12k8_start_ind[CPE_CHANNELS], out_12k8_end_ind[CPE_CHANNELS]; Word16 out_16k_start_ind = 0, out_16k_end_ind = 0; @@ -804,44 +799,18 @@ ivas_error ivas_cpe_enc_fx( } Copy_Scale_sig32_16( sts[0]->input32_fx + out_start_ind, sts[0]->input_fx + out_start_ind, sub( out_end_ind, out_start_ind ), sub( add( Q16, sts[0]->q_inp ), Q16 ) ); + Copy_Scale_sig32_16( old_inp_16k_fx[0], old_inp_16k_16fx[0], L_INP, -1 ); // Q16->Q-1 #ifdef IVAS_FLOAT_FIXED_CONVERSIONS /*local fix2flt*/ /*fix2flt: dft_synthesize*/ - fixedToFloat_arrL( old_inp_12k8_fx[0] + L_INP_MEM + out_12k8_start_ind[0], old_inp_12k8[0] + L_INP_MEM + out_12k8_start_ind[0], 16, out_12k8_end_ind[0] - out_12k8_start_ind[0] ); - fixedToFloat_arrL( old_inp_16k_fx[0] + L_INP_MEM + out_16k_start_ind, old_inp_16k[0] + L_INP_MEM + out_16k_start_ind, 16, out_16k_end_ind - out_16k_start_ind ); + Copy_Scale_sig_32_16( old_inp_12k8_fx[0] + L_INP_MEM + out_12k8_start_ind[0], old_inp_12k8_16fx[0] + L_INP_MEM + out_12k8_start_ind[0], out_12k8_end_ind[0] - out_12k8_start_ind[0], -Q17 ); if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { sts[1]->exp_old_inp_12k8 = Q15; move16(); - fixedToFloat_arrL( old_inp_12k8_fx[1] + L_INP_MEM + out_12k8_start_ind[1], old_inp_12k8[1] + L_INP_MEM + out_12k8_start_ind[1], 16, out_12k8_end_ind[1] - out_12k8_start_ind[1] ); + Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_INP_MEM + out_12k8_start_ind[1], old_inp_12k8_16fx[1] + L_INP_MEM + out_12k8_start_ind[1], out_12k8_end_ind[1] - out_12k8_start_ind[1], -Q17 ); // Q-1 } /*fix2flt end*/ -#endif -#else - stereo_dft_enc_synthesize( hCPE->hStereoDft, sts[0]->input, 0, input_Fs, input_Fs, 0 ); - - /* iDFT & resampling to 12.8kHz internal sampling rate */ - stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[0] + L_INP_MEM, 0, input_Fs, INT_FS_12k8, 0 ); - - /* iDFT & resampling to 16kHz internal sampling rate for M channel */ - if ( input_Fs == internal_Fs ) - { - mvr2r( sts[0]->input - STEREO_DFT_OVL_16k, old_inp_16k[0] + L_INP_MEM - STEREO_DFT_OVL_16k, input_frame + STEREO_DFT_OVL_16k ); - } - else - { - stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_16k[0] + L_INP_MEM, 0, input_Fs, internal_Fs, 0 ); - } - - /* DFT Stereo: iDFT of residual signal at 8kHz sampling rate */ - if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) - { - mvr2r( sts[1]->old_inp_12k8, old_inp_12k8[1], L_INP_MEM ); - stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM, 1, input_Fs, 8000, 0 ); - - /* update old input signal buffer */ - mvr2r( old_inp_12k8[1] + L_FRAME8k, sts[1]->old_inp_12k8, L_INP_MEM ); - } #endif /* no iDFT at input sampling rate for Side channel -> reset the buffer */ set16_fx( sts[1]->input_fx, 0, input_frame ); @@ -864,11 +833,16 @@ ivas_error ivas_cpe_enc_fx( { Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } - error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_12k8[n], old_inp_16k[n], + set16_fx( old_wsp_fx[n], 0, L_WSP ); + q_old_wsp = Q15; + move16(); + error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_16k_16fx[n], &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], - realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp[n], pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], + realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, add( Q_buffer[n], QSCALE ), Etot_LR_fx, lf_E_fx, add( Q_buffer[n], QSCALE - 2 ), localVAD_HE_SAD, band_energies_LR_fx, sub( add( Q_buffer[n], QSCALE ), band_ener_guardbits ), 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); + e_old_wsp[n] = sub( Q15, q_old_wsp ); + move16(); #else error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], @@ -1152,9 +1126,9 @@ ivas_error ivas_cpe_enc_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < CPE_CHANNELS; i++ ) + FOR( int i = 0; i < CPE_CHANNELS; i++ ) { - floatToFixed_arrL( old_inp_12k8[i], old_inp_12k8_fx[i], Q16, L_INP_12k8 ); + Copy_Scale_sig_16_32( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], Q16 + Q1, L_INP_12k8 ); } #endif stereo_dft_enc_res_fx( hCPE->hStereoDft, old_inp_12k8_fx[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, max_bits ); @@ -1185,18 +1159,12 @@ ivas_error ivas_cpe_enc_fx( * Core Encoder *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_wsp_fx[CPE_CHANNELS][L_WSP]; - Word16 e_old_wsp[CPE_CHANNELS]; - Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP]; - for ( n = 0; n < n_CoreChannels; n++ ) + FOR( n = 0; n < n_CoreChannels; n++ ) { - floatToFixed_arr( old_inp_16k[n], old_inp_16k_16fx[n], -1, L_INP ); - floatToFixed_arr( old_inp_12k8[n], old_inp_12k8_16fx[n], -1, L_INP_12k8 ); - floatToFixed_arr( old_wsp[n], old_wsp_fx[n], -1, L_WSP ); + Scale_sig( old_wsp_fx[n], L_WSP, sub( e_old_wsp[n], Q16 ) ); e_old_wsp[n] = 16; + move16(); } -#endif if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 71e394074df81ae3ac35235dddfbf4ade8c44396..5a9496d7706ce4bf5587aa7949cf22c2dfbc671d 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -276,7 +276,7 @@ ivas_error front_vad_fx( Word16 fft_buffLR_fx[2 * L_FFT]; /* fft buffer */ // Word16 front_create_flag = 0; Word16 n, n_chan, dummy; - Word8 dummy_short; + Word16 dummy_short; Word16 element_mode, last_element_mode; ivas_error error; Word16 Q_new = 0, band_ener_guardbits = 0; @@ -839,7 +839,6 @@ ivas_error front_vad_spar_fx( Scale_sig32( hFrontVad->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE + 2 ), hFrontVad->hNoiseEst->q_enrO ) ); hFrontVad->hNoiseEst->q_enrO = add( Q_new_old, QSCALE + 2 ); move16(); - st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; Word16 Q_buffer = hFrontVad->q_buffer_12k8; move16(); Scale_sig( hFrontVad->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp, hFrontVad->q_mem_decim ) ); diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index a0f76b78fa6ab306572175af911c50814a456846..07d3183be454c76371f9f559c4f6cb0263a8e1b0 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -91,6 +91,8 @@ ivas_error ivas_ism_dtx_open( { set32_fx( hISMDTX->long_term_energy_stereo_dmx_enc_fx[i], 0, PARAM_ISM_HYS_BUF_SIZE ); } + hISMDTX->long_term_energy_stereo_dmx_enc_e = 0; + move16(); set16_fx( hISMDTX->coh_fx, 0, MAX_NUM_OBJECTS ); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index d6dedf0b981df795807d7dd728d80989ca529796..219bab4a5a0158d339f92dec8c62f3b49ad1e102 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -431,16 +431,10 @@ ivas_error ivas_ism_enc_fx( SCE_ENC_HANDLE hSCE; Encoder_State *st; Word16 sce_id; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float old_inp_12k8[MAX_NUM_OBJECTS][1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ - float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ - Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ -#else - float old_inp_12k8[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ - float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 16kHz */ -#endif - Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */ - Word32 ener_fx[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin Q6 */ + Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */ + Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 12k8 Q-1 */ + Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */ + Word32 ener_fx[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin Q6 */ Word16 relE_fx[MAX_NUM_OBJECTS][1]; /* frame relative energy, Q8 */ Word16 A_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ @@ -454,7 +448,9 @@ ivas_error ivas_ism_enc_fx( Word32 realBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ Word32 imagBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ Word16 q_re_im_buf[MAX_NUM_OBJECTS]; - float old_wsp[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */ + Word16 old_wsp_fx[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */ + Word16 q_old_wsp; + Word16 e_old_wsp[MAX_NUM_OBJECTS][CPE_CHANNELS]; Word16 pitch_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values Q6 */ Word16 voicing_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains Q15 */ Word16 loc_harm[MAX_NUM_OBJECTS][1]; /* harmonicity flag */ @@ -513,6 +509,10 @@ ivas_error ivas_ism_enc_fx( nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism; move16(); } + FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) + { + set16_fx( old_inp_16k_fx[sce_id][0], 0, L_INP ); + } /*------------------------------------------------------------------* * Preprocesing @@ -585,11 +585,18 @@ ivas_error ivas_ism_enc_fx( { Scale_sig( &A_fx[sce_id][0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[sce_id][0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } - error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], + + set16_fx( old_wsp_fx[sce_id][0], 0, L_WSP ); + q_old_wsp = Q15; + move16(); + + + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0], &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], - realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp[sce_id][0], pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], + realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); - + e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp ); + move16(); IF( NE_32( error, IVAS_ERR_OK ) ) { return error; @@ -778,19 +785,9 @@ ivas_error ivas_ism_enc_fx( test(); IF( !dtx_flag || ( dtx_flag && EQ_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) ) { - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_wsp_fx[MAX_NUM_OBJECTS][CPE_CHANNELS][L_WSP]; - Word16 e_old_wsp[MAX_NUM_OBJECTS][CPE_CHANNELS]; - Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][CPE_CHANNELS][L_INP]; - for ( int n = 0; n < 1; n++ ) - { - floatToFixed_arr( old_inp_16k[sce_id][n], old_inp_16k_fx[sce_id][n], -1, L_INP ); - floatToFixed_arr( old_inp_12k8[sce_id][n], old_inp_12k8_fx[sce_id][n], -1, L_INP_12k8 ); - floatToFixed_arr( old_wsp[sce_id][n], old_wsp_fx[sce_id][n], -1, L_WSP ); - e_old_wsp[sce_id][n] = 16; - } -#endif + Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) ); + e_old_wsp[sce_id][0] = 16; + move16(); IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index e9c94b0326540762bb875a10a5b78923821b6ba2..f142b15321135f8ed71033d5da2ada407671ec67 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -397,8 +397,6 @@ ivas_error ivas_mct_enc_fx( Word16 n, cpe_id; MCT_ENC_HANDLE hMCT; CPE_ENC_HANDLE hCPE; - float mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; - float orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; Word32 mdst_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; Word32 orig_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; Word16 switch_bw; @@ -429,10 +427,6 @@ ivas_error ivas_mct_enc_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { hCPE = st_ivas->hCPE[cpe_id]; -#ifdef MSAN_FIX - set_zero( mdst_spectrum_long[cpe_id][n], L_FRAME48k ); - set_zero( orig_spectrum_long[cpe_id][n], L_FRAME48k ); -#endif set32_fx( orig_spectrum_long_fx[cpe_id][n], 0, L_FRAME48k ); set32_fx( mdst_spectrum_long_fx[cpe_id][n], 0, L_FRAME48k ); set16_fx( hMCT->q_mdst_spectrum_long_fx[cpe_id][n], Q31, CPE_CHANNELS ); diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 5d749e1a313f0343efd668996b11a35b48cb1eaa..1b7f19f7ff2eab272520788cf3ca04cb7afc355a 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -1783,6 +1783,11 @@ static void ivas_omasa_param_est_enc_fx( move16(); /* Need to initialize renormalization_factors, and variables to be normalized */ +#ifdef MSAN_FIX + set_zero_fx( &Foa_RealBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &Foa_ImagBuffer_fx[0][0], FOA_CHANNELS * CLDFB_NO_CHANNELS_MAX ); +#endif + set_zero_fx( renormalization_factor_diff_fx, hOMasa->nbands ); set_zero_fx( diffuseness_m_fx, hOMasa->nbands ); set16_fx( renormalization_factor_diff_e, 0, hOMasa->nbands ); @@ -2309,8 +2314,8 @@ static void ivas_omasa_energy_and_ratio_est_fx( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] = BASOP_Util_Divide3232_Scale( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j], L_add( hOmasaData->energy_ism_fx[block_m_idx][i], EPSILON_FX ), &temp_e ); temp_e = add( temp_e, sub( energy_ratio_ism_e[block_m_idx][i][j], hOmasaData->energy_ism_fx_e[block_m_idx][i] ) ); move32(); - - hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] = L_min( ONE_IN_Q30, L_shl( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j], add( 15, temp_e ) ) ); /* scaling to q30*/ + // TO be checked for saturation + hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] = L_min( ONE_IN_Q30, L_shl_sat( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j], add( 15, temp_e ) ) ); /* scaling to q30*/ move32(); ism_ratio_sum_fx = W_add( ism_ratio_sum_fx, hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] ); } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 9078624168a91b3f0450fc70452368d5e067c009..fb4c88fe1cc9a64c996cf30751ccb18652d48f42 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -68,11 +68,9 @@ ivas_error ivas_sce_enc_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversion - float old_inp_12k8[1][L_INP_12k8] = { 0 }; /* buffer of input signal @ 12k8 */ - float old_inp_16k[1][L_INP] = { 0 }; /* buffer of input signal @ 16kHz */ - float old_wsp[1][L_WSP]; /* old weighted input signal */ -#endif + Word16 old_wsp_fx[1][L_WSP]; + Word16 e_old_wsp[1]; + Word16 q_old_wsp; Word32 ener_fx[1]; /* residual energy from Levinson-Durbin Q6 */ Word32 enerBuffer_fx[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ Word16 enerBuffer_fx_exp[1]; /* energy buffer */ @@ -95,7 +93,8 @@ ivas_error ivas_sce_enc_fx( Word32 fr_bands_fx[1][2 * NB_BANDS]; /* energy in frequency bands */ Word32 lf_E_fx[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */ + Word16 old_inp_16k_fx[1][L_INP]; /* buffer of input signal @ 12k8 Q-1 */ Word16 vad_hover_flag[1]; /* VAD hangover flag */ Word16 attack_flag[1]; /* attack flag (GSC or TC) */ Word16 loc_harm[1]; /* harmonicity flag */ @@ -142,6 +141,8 @@ ivas_error ivas_sce_enc_fx( set_zero_fx( imagBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX ); } + set16_zero_fx( old_inp_16k_fx[0], L_INP ); + /*------------------------------------------------------------------* * SCE initialization - core coder *-----------------------------------------------------------------*/ @@ -241,12 +242,17 @@ ivas_error ivas_sce_enc_fx( { Scale_sig( &A_fx[0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } - error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_12k8[0], old_inp_16k[0], + set16_fx( old_wsp_fx[0], 0, L_WSP ); + q_old_wsp = Q15; + move16(); + + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_16k_fx[0], &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], - realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp[0], pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], + realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); - + e_old_wsp[0] = sub( Q15, q_old_wsp ); + move16(); #else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], @@ -341,18 +347,9 @@ ivas_error ivas_sce_enc_fx( * Encoder *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 old_wsp_fx[1][L_WSP]; - Word16 e_old_wsp[1]; - Word16 old_inp_16k_fx[1][L_INP]; - for ( int n = 0; n < 1; n++ ) - { - floatToFixed_arr( old_inp_16k[n], old_inp_16k_fx[n], -1, L_INP ); - floatToFixed_arr( old_inp_12k8[n], old_inp_12k8_fx[n], -1, L_INP_12k8 ); - floatToFixed_arr( old_wsp[n], old_wsp_fx[n], -1, L_WSP ); - e_old_wsp[n] = 16; - } -#endif + Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); + e_old_wsp[0] = 16; + move16(); IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index b4a7638bf5eca9af7557ba4c6fbcb40d6b5d6c35..43ef21e03bb1311195211778922cff40da10f5ec 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -339,8 +339,8 @@ typedef struct stereo_dft_enc_data_struct Word16 res_cod_mode[STEREO_DFT_ENC_DFT_NB]; /* mode from 0 (off) to 3 */ Word16 res_cod_band_max; /* Band max for coding of residual */ Word16 res_cod_line_max; /* Maximum number of MDCT lines to code for the residual coding */ - float res_cod_SNR_M[STEREO_DFT_BAND_MAX]; #ifndef IVAS_FLOAT_FIXED + float res_cod_SNR_M[STEREO_DFT_BAND_MAX]; float res_cod_NRG_M[STEREO_DFT_BAND_MAX]; float res_cod_NRG_S[STEREO_DFT_BAND_MAX]; float old_snr; diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index b42f60c147716014981022cdaa2cab68a698ff74..caa695d9e8a7db06a0443d7b57217d7aa956e8a9 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -862,7 +862,7 @@ static void utilCrossCorr_fx( } ELSE { - scale = Isqrt_lc( temp, &temp2_e ); // temp2_e + scale = ISqrt32( temp, &temp2_e ); // temp2_e } /* starting point of lag search range should be less than the ending point */ diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index 0d380f37ba086413349cd848eedee2c69745966d..64e3c4b82ffa26ebbc5b84fae7e970fd20d5c4ec 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -1644,8 +1644,10 @@ void stereo_icBWE_init_enc_fx( set16_fx( hStereoICBWE->nlExc16k_fx, 0, L_FRAME16k ); hStereoICBWE->nlExc16k_e = 0; + move16(); set16_fx( hStereoICBWE->mixExc16k_fx, 0, L_FRAME16k ); hStereoICBWE->mixExc16k_e = 0; + move16(); return; } diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index eb68c8d5673f236c3cdddffd3a179a77eb27ffdb..56520911b6de57aea2a83c74de4d744a5ad1f6de 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -568,6 +568,10 @@ void stereo_mdct_core_enc_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { +#ifdef MSAN_FIX + set32_fx( mdst_spectrum_long_fx[ch], 0, N_MAX ); + set32_fx( orig_spectrum_long_fx[ch], 0, N_MAX ); +#endif p_mdst_spectrum_long_fx[ch] = mdst_spectrum_long_fx[ch]; p_orig_spectrum_long_fx[ch] = orig_spectrum_long_fx[ch]; orig_spectrum_fx[ch][0] = orig_spectrum_long_fx[ch]; diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index b7725a527036f2018066bd075f8c464422f4e325..c427229b7a2509572532cc6fb12264a6745f4260 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -560,7 +560,7 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); /* Prevent the usage of MDCTA on noisy-speech or inactive */ - if ( EQ_16( st_fx->mdct_sw_enable, MODE2 ) && ( EQ_16( st_fx->flag_noisy_speech_snr_fx, 1 ) || st_fx->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) + if ( EQ_16( st_fx->mdct_sw_enable, MODE2 ) && ( EQ_16( st_fx->flag_noisy_speech_snr, 1 ) || st_fx->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) { clas_final = TCX_20_CORE; move16(); diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index bcca279fcf2cb5cecd04c26d62d4fce20fcf3cd7..52c30f7ef6be8666370f19d2f3d0cfeb545a2f25 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -351,7 +351,7 @@ void MDCT_selector_fx( test(); test(); /* Prevent the usage of HQ_CORE on noisy-speech or inactive */ - IF( EQ_16( st->mdct_sw_enable, MODE2 ) && EQ_16( st->core, HQ_CORE ) && ( EQ_16( st->flag_noisy_speech_snr_fx, 1 ) || st->vad_flag == 0 ) ) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) && EQ_16( st->core, HQ_CORE ) && ( EQ_16( st->flag_noisy_speech_snr, 1 ) || st->vad_flag == 0 ) ) { st->core = TCX_20_CORE; move16(); diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index e55f488df2546d3ab7014e6c0fa8a394808b8edb..12b09c9ebc1a4425ce6af05c4b2dafafae6786b1 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -268,7 +268,7 @@ void pre_proc_fx( noise_est_pre_fx( *Etot, st->ini_frame, hNoiseEst, 0, EVS_MONO, EVS_MONO ); st->vad_flag = wb_vad_fx( st, fr_bands, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), *Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ); + &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), *Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ); vad_flag_cldfb = vad_proc_fx( &( st->vad_st ), realBuffer, imagBuffer, cldfbScale->lb_scale, &cldfb_addition, enerBuffer, enerBuffer_exp, st->cldfbAnaEnc->no_channels, st->vad_flag ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 45850a1f7cbd201d542e78b88d5f04406465583f..83b1ca81e2c9f8bf37de5b9092a2303edc04f944 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -787,12 +787,12 @@ Word16 wb_vad_fx( Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ Word16 *localVAD_HE_SAD, - Word8 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech, /* i : long term active speech energy average */ - Word16 lp_noise /* i : long term noise energy */ + Word16 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech, /* i : long term active speech energy average */ + Word16 lp_noise /* i : long term noise energy */ ); Word16 wb_vad_ivas_fx( @@ -803,12 +803,12 @@ Word16 wb_vad_ivas_fx( Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ Word16 *localVAD_HE_SAD, - Word8 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech, /* i : long term active speech energy average */ - Word16 lp_noise /* i : long term noise energy */ + Word16 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech, /* i : long term active speech energy average */ + Word16 lp_noise /* i : long term noise energy */ ); Word32 construct_snr_thresh_fx( Word16 sp_center[], /*(i) spectral center*/ @@ -1680,18 +1680,18 @@ void tc_classif_enc_fx( ); Word16 gain_enc_uv_fx( - const Word16 *code, /*, -2,, -2 and 2*/ - Word16 mean_ener, /*, -2,, -2 and 2*/ + Word16 mean_ener, /* */ - const Word16 *code, /* i : algebraic excitation */ - const Word16 *code2, /* i : gaussian excitation */ - Word16 lcode, /* i : Subframe size in range: 40,64,80 */ - Word16 *gain_pit, /* o : quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word32 *gain_code2, /* o : quantized codebook gain */ - Word8 noisy_speech_flag, /* i : noisy speech flag */ - ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ - Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* o : Q12 innovation gain */ - const Word16 func_type /* i : algorithm: 2=gain_enc_uv_fx, 3=gain_enc_gacelp_uv */ +Word16 gain_enc_uv_fx( /* o : quantization pitch index */ + const Word16 *code, /* i : algebraic excitation */ + const Word16 *code2, /* i : gaussian excitation */ + Word16 lcode, /* i : Subframe size in range: 40,64,80 */ + Word16 *gain_pit, /* o : quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word32 *gain_code2, /* o : quantized codebook gain */ + Word16 noisy_speech_flag, /* i : noisy speech flag */ + ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ + Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ + Word32 *past_gcode, /* o : past gain of code */ + Word16 *gain_inov, /* o : Q12 innovation gain */ + const Word16 func_type /* i : algorithm: 2=gain_enc_uv_fx, 3=gain_enc_gacelp_uv */ ) { Word16 i, index, exp_L_tmp1, tmp; diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 894e476bd5c366bf9d8b6e77ce72d7ddb0d608c2..dcc876400d67cf2dd84f568f9b8e40030a2bdc3f 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -2234,11 +2234,10 @@ typedef struct enc_core_structure Word16 finalVAD; - int16_t flag_noisy_speech_snr; /* encoder detector for noisy speech */ - Word8 flag_noisy_speech_snr_fx; /*encoder detector for noisy speech*/ - int16_t Pos_relE_cnt; /* Number of frames between relE */ + Word16 flag_noisy_speech_snr; /* encoder detector for noisy speech */ + Word16 Pos_relE_cnt; /* Number of frames between relE */ - int16_t tdm_pc; /* pitch stability - used in TD stereo */ + Word16 tdm_pc; /* pitch stability - used in TD stereo */ /*----------------------------------------------------------------------------------* * General signal buffers diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 676b16ea29a581b1ff8f5fbb51cffd17e18cdaf9..c4f402234be0eac93273337223456c098c1fb239 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -415,6 +415,7 @@ void InitSWBencBuffer_fx( move16(); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); @@ -442,6 +443,7 @@ void InitSWBencBuffer_fx( hBWE_TD->cldfbHBLT = 8192 /*1.0f Q13*/; move16(); hBWE_TD->prev_gainFr_SHB_fx = 0; + move32(); set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); @@ -476,6 +478,7 @@ void InitSWBencBuffer_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + move16(); } set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); @@ -630,9 +633,12 @@ void ResetSHBbuffer_Enc_fx( /* overlap buffer used to Adjust SHB Frame Gain */ set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb_fx = 16384; /*Q14=1 */ + move16(); set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); hBWE_TD->tbe_demph_fx = 0; + move16(); hBWE_TD->tbe_premph_fx = 0; + move16(); return; diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 1326cc457f72ad5f38502d5872447453cd741867..ff846dc0c291621b20f229be89fa3d17aba9e987 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -650,12 +650,12 @@ Word16 wb_vad_fx( Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ Word16 *localVAD_HE_SAD, - Word8 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech_fx, /* i : long term active speech energy average */ - Word16 lp_noise_fx /* i : long term noise energy */ + Word16 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech_fx, /* i : long term active speech energy average */ + Word16 lp_noise_fx /* i : long term noise energy */ ) { Word16 i, flag = 0, hangover_short; @@ -1912,12 +1912,12 @@ Word16 wb_vad_ivas_fx( Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ Word16 *localVAD_HE_SAD, - Word8 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech_fx, /* i : long term active speech energy average */ - Word16 lp_noise_fx /* i : long term noise energy */ + Word16 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech_fx, /* i : long term active speech energy average */ + Word16 lp_noise_fx /* i : long term noise energy */ ) { Word16 i, flag = 0, hangover_short;