diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 696b58640cdfe1e7c7a3ad1297640d004b60ba46..bf7e2ac0e48a4c348d2c869edd5fb2e5eebdcf46 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -846,7 +846,8 @@ void cng_params_postupd_ivas_fx( #endif /* BASOP_NOGLOB */ L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ tmp = add( add( Q_exc, Q_exc ), 1 ); - sp[i] = L_shr( L_tmp, sub( tmp, 6 ) ); + // To do : Saturation to be re-validated. + sp[i] = L_shr_sat( L_tmp, sub( tmp, 6 ) ); move32(); /* Q6 */ ptR++; diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 87984f20599f2db0333840a060628213b65039de..bead42ab91920b9fd5507c22d0a5cc3880f66b62 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1733,9 +1733,10 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ - y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ + ( *Zp_fx ) = L_add_sat( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ + // TODO: overflow of Z_fx to be checked move32(); } Zp_fx++; diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index df9cddf225a89659686f83db7bea5a54881b80f8..392411e68bfb9c1543e896d4cfa7ec239a195c91 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -631,7 +631,7 @@ void ivas_analy_sp_fx_front( move16(); } - Scale_fac[i_subfr] = -1; + Scale_fac[i_subfr] = -2; move16(); Scale_sig( pt_fft, L_FFT, Scale_fac[i_subfr] ); @@ -705,7 +705,7 @@ void ivas_analy_sp_fx_front( { if ( EspecdB != NULL ) { - temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE - 2 - 1 ), Q25 ) ); + temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE - 2 ), Q25 ) ); EspecdB[i] = extract_l( L_shr( Mpy_32_32( temp32_log, 1860652798 ), Q22 - Q7 ) ); /*log(x) = log2(x)*logf(2)*/ /* 10.0*log((float)tmp) */ /* 10.0*logf(2) in Q28 = 1860652798 */ @@ -1118,7 +1118,7 @@ static void ivas_find_enr1( move32(); FOR( i = min_band; i <= max_band; i++ ) { - etot = L_add( etot, L_shr( band[i], Q1 ) ); // Q_new + QSCALE - 1 + etot = L_add_sat( etot, L_shr( band[i], Q1 ) ); // Q_new + QSCALE - 1 } *LEtot = etot; move32(); diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 20587deede865b50d864381046bd21b2dfce7bc1..c8d88dd589a93c756be2af2c73f908d8d5494e8a 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -36,6 +36,7 @@ #include #include "options.h" +#include "options_warnings.h" #include "cnst.h" #include "prot.h" #include "ivas_prot.h" @@ -57,8 +58,8 @@ static void init_tcx( Encoder_State *st, const int16_t L_frame_old, const int32_ 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_core_sig_ana( Encoder_State *st ); -#endif 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 ); #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 ); @@ -494,9 +495,10 @@ void init_coder_ace_plus( init_sig_buffers( st, L_frame_old, L_subfr, st->total_brate, last_total_brate ); /* Initialize ACELP */ - init_acelp( st, L_frame_old, st->total_brate, last_total_brate ); #ifdef IVAS_FLOAT_FIXED init_acelp_ivas_fx( st, L_frame_old, 0 ); +#else + init_acelp( st, L_frame_old, st->total_brate, last_total_brate ); #endif if ( st->ini_frame == 0 ) @@ -814,7 +816,7 @@ 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; @@ -823,7 +825,9 @@ static void init_sig_buffers( { 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 ); +#ifndef IVAS_FLOAT_FIXED set_zero( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); +#endif if ( hTcxEnc != NULL ) { // set_zero( hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); @@ -841,8 +845,9 @@ static void init_sig_buffers( #endif } +#ifndef IVAS_FLOAT_FIXED mvr2r( st->old_wsp, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM ); - +#endif /*Resamp buffers needed only for ACELP*/ if ( st->L_frame == L_FRAME && !st->tcxonly ) { @@ -850,15 +855,20 @@ static void init_sig_buffers( } 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 mvr2r( st->old_inp_16k, st->buf_speech_enc_pe_flt + st->L_frame - L_INP_MEM, L_INP_MEM ); } st->mem_preemph_enc_flt = st->buf_speech_enc_flt[st->L_frame - 1]; +#ifndef IVAS_FLOAT_FIXED st->mem_wsp_enc_flt = st->buf_wspeech_enc_flt[st->L_frame + L_SUBFR - 1]; +#endif } 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 ); /*Resamp buffers needed only for ACELP*/ @@ -866,10 +876,9 @@ static void init_sig_buffers( { 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 ); } -#ifndef IVAS_FLOAT_FIXED st->hLPDmem->mem_w0_flt = 0; -#endif st->mem_wsp_enc_flt = st->buf_wspeech_enc_flt[st->L_frame + L_SUBFR - 1]; +#endif } st->new_speech_enc_flt = st->buf_speech_enc_flt + st->encoderPastSamples_enc + st->encoderLookahead_enc; @@ -880,12 +889,6 @@ static void init_sig_buffers( // hTcxEnc->new_speech_ltp_flt = hTcxEnc->buf_speech_ltp_flt + st->encoderPastSamples_enc + st->encoderLookahead_enc; } - if ( st->hTcxEnc != NULL ) - { - st->hTcxEnc->new_speech_TCX_flt = 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_flt = st->hTcxEnc->new_speech_TCX_flt - st->encoderLookahead_FB; - } - st->speech_enc_flt = st->buf_speech_enc_flt + st->encoderPastSamples_enc; st->speech_enc_pe_flt = st->buf_speech_enc_pe_flt + st->encoderPastSamples_enc; @@ -894,6 +897,7 @@ static void init_sig_buffers( // hTcxEnc->speech_ltp_flt = hTcxEnc->buf_speech_ltp_flt + st->encoderPastSamples_enc; } +#ifndef IVAS_FLOAT_FIXED if ( st->element_mode > EVS_MONO ) { st->wspeech_enc_flt = st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR; @@ -902,7 +906,6 @@ static void init_sig_buffers( { st->wspeech_enc_flt = st->buf_wspeech_enc_flt + st->L_frame + L_subfr; } -#ifndef IVAS_FLOAT_FIXED 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 ); @@ -935,6 +938,8 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol set16_fx( hTcxEnc->buf_speech_ltp, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } 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; + move16(); } ELSE { @@ -979,7 +984,7 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol st->mem_preemph_enc = st->buf_speech_enc[st->encoderPastSamples_enc + st->encoderLookahead_enc - 1]; move16(); - st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1]; + 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(); } /*coming from TCXonly modes*/ @@ -996,7 +1001,7 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol } hLPDmem->mem_w0 = 0; move16(); - st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame + L_SUBFR - 1]; + 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(); } } @@ -1010,9 +1015,6 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol if ( st->hTcxEnc != NULL ) { - st->hTcxEnc->new_speech_TCX_flt = 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_flt = st->hTcxEnc->new_speech_TCX_flt - st->encoderLookahead_FB; - #ifdef IVAS_FLOAT_FIXED st->hTcxEnc->new_speech_TCX = st->input_buff_fx + Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ); st->hTcxEnc->speech_TCX = st->hTcxEnc->new_speech_TCX - st->encoderLookahead_FB; @@ -1151,17 +1153,16 @@ static void init_core_sig_ana_ivas_fx( Encoder_State *st ) * * *-----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void init_acelp( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate ) { -#ifndef IVAS_FLOAT_FIXED int16_t mem_syn_r_size_old; int16_t mem_syn_r_size_new; -#endif + LPD_state_HANDLE hLPDmem = st->hLPDmem; /* Init pitch lag */ @@ -1180,62 +1181,43 @@ static void init_acelp( { if ( hLPDmem != NULL ) { -#ifndef IVAS_FLOAT_FIXED - set_zero( hLPDmem->syn_flt, 1 + M ); - set_zero( hLPDmem->mem_syn_r_flt, L_SYN_MEM ); -#endif + set_zero( hLPDmem->syn, 1 + M ); + set_zero( hLPDmem->mem_syn_r, L_SYN_MEM ); } if ( st->hTcxEnc != NULL ) { -#ifdef IVAS_FLOAT_FIXED - set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); + set_zero( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64 ); st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 ); - st->hTcxEnc->q_Txnq = Q15; - move16(); -#endif } } else /*Rate switching*/ { -#ifndef IVAS_FLOAT_FIXED if ( st->hTcxEnc != NULL ) { if ( st->last_core == ACELP_CORE ) { - lerp_flt( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->L_frame / 2, L_frame_old / 2 ); + lerp( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq, st->L_frame / 2, L_frame_old / 2 ); } else { - lerp_flt( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old ); + lerp( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old ); } - st->hTcxEnc->acelp_zir_flt = st->hTcxEnc->Txnq_flt + ( st->L_frame / 2 ); - -#ifdef IVAS_FLOAT_FIXED st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 ); -#endif } -#endif + /* Rate switching */ if ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO ) { if ( hLPDmem != NULL ) { -#ifndef IVAS_FLOAT_FIXED - mvr2r( hLPDmem->mem_syn1_flt, hLPDmem->mem_syn2_flt, M ); - set_zero( hLPDmem->syn_flt, M ); -#endif + mvr2r( hLPDmem->mem_syn1, hLPDmem->mem_syn2, M ); + set_zero( hLPDmem->syn, M ); } if ( st->hTcxEnc != NULL ) { -#ifndef IVAS_FLOAT_FIXED - set_zero( st->hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); -#else - set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 ); - st->hTcxEnc->q_Txnq = Q15; - move16(); -#endif + set_zero( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64 ); } } @@ -1252,20 +1234,15 @@ static void init_acelp( st->rate_switching_reset = 1; if ( hLPDmem != NULL ) { -#ifndef IVAS_FLOAT_FIXED - hLPDmem->tilt_code_flt = TILT_CODE_FLT; - set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); - set_zero( hLPDmem->syn_flt, 1 + M ); - hLPDmem->mem_w0_flt = 0.0f; - set_zero( hLPDmem->mem_syn_flt, M ); - set_zero( hLPDmem->mem_syn2_flt, M ); -#else hLPDmem->tilt_code = TILT_CODE; -#endif + set_zero( hLPDmem->old_exc, L_EXC_MEM ); + set_zero( hLPDmem->syn, 1 + M ); + hLPDmem->mem_w0 = 0.0f; + set_zero( hLPDmem->mem_syn, M ); + set_zero( hLPDmem->mem_syn2, M ); } /* unquantized LPC*/ -#ifndef IVAS_FLOAT_FIXED if ( !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) && total_brate == last_total_brate && st->last_bwidth == st->bwidth ) ) { mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ @@ -1276,25 +1253,6 @@ static void init_acelp( } mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); -#else - IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) - { - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 ); - } - } - Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ - IF( st->tcxonly == 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); - } -#endif st->last_core = TCX_20_CORE; @@ -1308,32 +1266,12 @@ static void init_acelp( { if ( st->L_frame != L_frame_old && st->L_frame <= L_FRAME16k && L_frame_old <= L_FRAME16k ) /* Rate switching between 12.8 and 16 kHz*/ { -#ifndef IVAS_FLOAT_FIXED float tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1]; -#endif - float A[M + 1]; -#ifdef IVAS_FLOAT_FIXED - Word16 A_fx[M + 1]; -#endif /* convert quantized LSP vector */ -#ifndef IVAS_FLOAT_FIXED st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); -#else - st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); - move16(); - IF( st->tcxonly == 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); - } -#endif -#ifndef IVAS_FLOAT_FIXED if ( st->L_frame == L_FRAME16k ) { mvr2r( st->lsp_old, st->lspold_enc, M ); @@ -1342,38 +1280,19 @@ static void init_acelp( { mvr2r( st->lsp_old1, st->lspold_enc, M ); } -#else - IF( st->L_frame == L_FRAME16k ) - { - Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); - } - ELSE - { - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); - } -#endif /* Update wsyn */ if ( hLPDmem != NULL ) { -#ifndef IVAS_FLOAT_FIXED - synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC ); + synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); lsp2a_stab( st->lsp_old, A, M ); -#else - E_LPC_f_lsp_a_conversion( st->lsp_old_fx, A_fx, M ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), M + 1 ); -#endif -#endif -#ifndef IVAS_FLOAT_FIXED - weight_a( A, Ap, GAMMA1_FLT, M ); + weight_a( A, Ap, GAMMA1, M ); tmp = 0.f; tmp_buf[0] = 0.f; - mvr2r( hLPDmem->mem_syn2_flt, tmp_buf + 1, M ); - deemph( tmp_buf + 1, st->preemph_fac_flt, M, &tmp ); + mvr2r( hLPDmem->mem_syn2, tmp_buf + 1, M ); + deemph( tmp_buf + 1, st->preemph_fac, M, &tmp ); residu( Ap, M, tmp_buf + M, &tmp, 1 ); - hLPDmem->mem_w0_flt = st->wspeech_enc_flt[-1] - tmp; -#endif + hLPDmem->mem_w0 = st->wspeech_enc[-1] - tmp; } } else if ( st->L_frame != L_frame_old ) /* Rate switching involving TCX only modes */ @@ -1385,28 +1304,22 @@ static void init_acelp( /*reset partly some memories*/ if ( hLPDmem != NULL ) { -#ifndef IVAS_FLOAT_FIXED - hLPDmem->tilt_code_flt = TILT_CODE_FLT; - set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); -#else hLPDmem->tilt_code = TILT_CODE; -#endif -#ifndef IVAS_FLOAT_FIXED + set_zero( hLPDmem->old_exc, L_EXC_MEM ); + /*Resamp others memories*/ /*Size of LPC syn memory*/ mem_syn_r_size_old = (int16_t) ( 1.25 * L_frame_old / 20.f ); mem_syn_r_size_new = (int16_t) ( 1.25 * st->L_frame / 20.f ); - lerp_flt( hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - mvr2r( hLPDmem->mem_syn_r_flt + L_SYN_MEM - M, hLPDmem->mem_syn_flt, M ); - mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn2_flt, M ); + lerp( hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + mvr2r( hLPDmem->mem_syn_r + L_SYN_MEM - M, hLPDmem->mem_syn, M ); + mvr2r( hLPDmem->mem_syn, hLPDmem->mem_syn2, M ); - /*Untouched memories : LPDmem->syn & LPDmem->mem_w0_flt*/ - hLPDmem->mem_w0_flt = 0; -#endif + /*Untouched memories : LPDmem->syn & LPDmem->mem_w0*/ + hLPDmem->mem_w0 = 0; } /* unquantized LPC*/ -#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ if ( st->L_frame == L_FRAME16k ) { @@ -1414,22 +1327,6 @@ static void init_acelp( } mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); -#else - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 ); - } - Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ - IF( st->tcxonly == 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); - } -#endif } /* necessary in BASOP only, due to different representations of st->lsf_old */ /* else if ( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ @@ -1447,22 +1344,8 @@ static void init_acelp( /* Post-processing */ if ( hLPDmem != NULL ) { -#ifndef IVAS_FLOAT_FIXED - set_zero( hLPDmem->dispMem_flt, 8 ); - hLPDmem->gc_threshold_flt = 0.0f; -#else - hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); - - FOR( Word16 i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } - hLPDmem->gc_threshold = 0; -#endif + set_zero( hLPDmem->dispMem, 8 ); + hLPDmem->gc_threshold = 0.0f; } /* Pulse Search configuration */ @@ -1475,7 +1358,6 @@ static void init_acelp( } /*BPF parameters for adjusting gain in function of background noise*/ -#ifndef IVAS_FLOAT_FIXED if ( st->codec_mode == MODE2 ) { st->pst_lp_ener = 0.0f; @@ -1484,26 +1366,12 @@ static void init_acelp( st->pst_mem_deemp_err = 0.0f; } } -#else - IF( EQ_16( st->codec_mode, MODE2 ) ) - { - st->mem_bpf_fx.lp_error_ener = L_deposit_l( 0 ); - st->pst_lp_ener_fx = 0; - move16(); - if ( EQ_16( st->last_codec_mode, MODE1 ) ) - { - st->mem_bpf_fx.lp_error = L_deposit_l( 0 ); - st->pst_mem_deemp_err_fx = 0; - move16(); - } - } -#endif return; } -#ifdef IVAS_FLOAT_FIXED +#else static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift ) { Word16 mem_syn_r_size_old; @@ -1782,7 +1650,7 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ test(); test(); - if ( ( LE_32( st->total_brate, ACELP_9k60 ) || st->rf_mode != 0 ) && ( EQ_32( st->sr_core, 12800 ) ) ) + if ( ( LE_32( st->total_brate, ACELP_9k60 ) || EQ_16( st->rf_mode, 1 ) ) && ( EQ_32( st->sr_core, 12800 ) ) ) { st->acelp_autocorr = 0; move16(); diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index e107c064e9447cd837a711e0efdae587ef036c75..87659d9760491c7b7194ddf3e32f69bfdc769482 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -211,7 +211,6 @@ void core_coder_mode_switch_ivas_fx( f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); - f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); /* Adaptive BPF */ set_zero( st->mem_bpf, 2 * L_FILT16k ); diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 0407d443eec263c238bb8c3eebce3ec2bd4fd14f..42377800a43ee1d5c62091820577967ea4b94c40 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -142,7 +142,7 @@ void hq_core_enc_ivas_fx( WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, TRANSITION_OVERLAP, FULL_OVERLAP, &left_overlap, &right_overlap, st->hTcxEnc->speech_TCX, &L_spec, wtda_audio_fx16, 1, 1 ); - q = st->hTcxEnc->q_speech_TCX; + q = 0; move16(); Q_audio = sub( Q16, q ); TCX_MDCT( wtda_audio_fx16, t_audio_fx, &Q_audio, left_overlap, sub( L_spec, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode ); @@ -164,7 +164,10 @@ void hq_core_enc_ivas_fx( *--------------------------------------------------------------------------*/ Q_audio = 0; move16(); - floatToFixed_arr( st->old_input_signal, st->old_input_signal_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); + Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); + st->q_old_inp = 0; + move16(); st->q_inp = 0; move16(); Copy( st->old_input_signal_fx, two_frames_buffer, input_frame ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index af572fda1e7bd87181ea397198d40fced6d181f3..0ff68804dd102932d5c4576d51582726123af432 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -196,7 +196,9 @@ ivas_error init_encoder( st->last_harm_flag_acelp = 0; /* (Decimated) Weighted Speech Memory */ +#ifndef IVAS_FLOAT_FIXED st->mem_wsp_enc_flt = 0.0; +#endif st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); @@ -430,7 +432,9 @@ ivas_error init_encoder( st->buf_synth_flt = st->hSignalBuf->buf_synth_flt; #endif st->buf_speech_enc_flt = st->hSignalBuf->buf_speech_enc_flt; +#ifndef IVAS_FLOAT_FIXED st->buf_wspeech_enc_flt = st->hSignalBuf->buf_wspeech_enc_flt; +#endif #ifdef IVAS_FLOAT_FIXED st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; @@ -454,11 +458,14 @@ ivas_error init_encoder( 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 ) ); + st->q_inp32 = Q31; + move16(); + st->q_inp = Q15; + move16(); + st->q_old_inp = Q15; + move16(); set16_fx( st->hSignalBuf->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); #endif - st->input_buff = st->hSignalBuf->input_buff_flt; - set_zero( st->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st->old_input_signal = st->input_buff; // This part needs to be removed once fx fn is invoked// #ifdef IVAS_FLOAT_FIXED st->input_buff_fx = st->hSignalBuf->input_buff; @@ -470,16 +477,18 @@ ivas_error init_encoder( #ifdef IVAS_FLOAT_FIXED st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); -#endif // IVAS_FLOAT_FIXED +#else st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC + NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ); +#endif } else { #ifdef IVAS_FLOAT_FIXED st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC; st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC; -#endif // IVAS_FLOAT_FIXED +#else st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC; +#endif } } else @@ -501,8 +510,9 @@ ivas_error init_encoder( #ifdef IVAS_FLOAT_FIXED st->buf_speech_enc = NULL; #endif +#ifndef IVAS_FLOAT_FIXED st->buf_wspeech_enc_flt = NULL; - st->input_buff = NULL; +#endif } /*-----------------------------------------------------------------* @@ -1368,7 +1378,6 @@ ivas_error init_encoder_ivas_fx( st->mem_preemph16k = 0.0f; st->mem_preemph_enc_flt = 0.0; st->mem_preemp_preQ = 0.0f; - st->mem_wsp_enc_flt = 0.0; st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); st->mem_preemph_DFT = 0.0f; @@ -1575,6 +1584,8 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->hSignalBuf->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); set16_fx( st->hSignalBuf->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); + st->exp_buf_wspeech_enc = 0; + move16(); /* initializations */ set32_fx( st->Bin_E_old_fx, 0, shr( L_FFT, 2 ) ); st->q_Bin_E_old = Q31; @@ -1587,7 +1598,13 @@ ivas_error init_encoder_ivas_fx( st->input_buff_fx = st->hSignalBuf->input_buff; st->input_buff32_fx = st->hSignalBuf->input_buff32; set16_fx( st->input_buff_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); + st->q_inp = Q15; + move16(); + st->q_old_inp = Q15; + move16(); set32_fx( st->input_buff32_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); + st->q_inp32 = Q31; + move16(); st->old_input_signal_fx = st->input_buff_fx; /* st->input_Fs / FRAMES_PER_SEC */ Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); @@ -1612,24 +1629,17 @@ ivas_error init_encoder_ivas_fx( st->buf_synth_flt = st->hSignalBuf->buf_synth_flt; #endif st->buf_speech_enc_flt = st->hSignalBuf->buf_speech_enc_flt; +#ifndef IVAS_FLOAT_FIXED st->buf_wspeech_enc_flt = st->hSignalBuf->buf_wspeech_enc_flt; +#endif set_f( st->mem_decim, 0, 2 * L_FILT_MAX ); set_f( st->mem_decim16k, 0, 2 * L_FILT_MAX ); set_f( st->old_inp_12k8, 0, L_INP_MEM ); set_f( st->old_inp_16k, 0, L_INP_MEM ); - st->input_buff = st->hSignalBuf->input_buff_flt; - set_zero( st->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st->old_input_signal = st->input_buff; - if ( st->element_mode == EVS_MONO ) - { - st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC + NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - } - else - { - st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC; - } set_f( st->hSignalBuf->buf_speech_enc_flt, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); +#ifndef IVAS_FLOAT_FIXED set_f( st->hSignalBuf->buf_wspeech_enc_flt, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); +#endif #endif } ELSE @@ -1655,8 +1665,9 @@ ivas_error init_encoder_ivas_fx( st->buf_synth_flt = NULL; #endif st->buf_speech_enc_flt = NULL; +#ifndef IVAS_FLOAT_FIXED st->buf_wspeech_enc_flt = NULL; - st->input_buff = NULL; +#endif #endif } @@ -2292,7 +2303,6 @@ ivas_error init_encoder_ivas_fx( f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); - f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); /* Initialize ACELP */ /* Adaptive BPF */ diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index cb523675eaa64c2499bb9b19a0b7236917306565..f0854c989e0f14404191f0a632f37ad431851b4b 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -366,7 +366,6 @@ ivas_error ivas_core_enc( Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // floatToFixed_arr( st->hTcxEnc->old_out, st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); Word16 nSubframes; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) @@ -401,8 +400,6 @@ ivas_error ivas_core_enc( Scale_sig( st->hTcxEnc->old_out_fx, L_FRAME32k, -st->hTcxEnc->Q_old_out ); // scaling back to Q0 st->hTcxEnc->Q_old_out = 0; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // fixedToFloat_arr( st->hTcxEnc->old_out_fx, st->hTcxEnc->old_out, st->hTcxEnc->Q_old_out, L_FRAME32k ); - for ( int k = 0; k < nSubframes; k++ ) { #ifndef MSAN_FIX @@ -417,36 +414,12 @@ ivas_error ivas_core_enc( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core encoder */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q = 0; - Word16 left_overlap, right_overlap; - IF( st->element_mode > EVS_MONO && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) - { - left_overlap = st->hTcxCfg->tcx_mdct_window_lengthFB; - right_overlap = st->hTcxCfg->tcx_mdct_window_delayFB; - Word16 L_frame1 = 640; - - Word16 l1 = ( shr( left_overlap, 1 ) * 2 ) + sub( L_frame1, shr( add( left_overlap, right_overlap ), 1 ) ) + ( shr( right_overlap, 1 ) * 2 ) - shr( left_overlap, 1 ) + st->hTcxCfg->tcx_offsetFB; - q = Q_factor_arr( st->hTcxEnc->speech_TCX_flt, l1 ) - 1; - st->hTcxEnc->q_speech_TCX = q; - - Word16 offset, overlap1; - offset = negate( shr( st->hTcxCfg->tcx_mdct_window_trans_lengthFB, 1 ) ); - overlap1 = st->hTcxCfg->tcx_mdct_window_trans_lengthFB; - - floatToFixed_arr( st->hTcxEnc->speech_TCX_flt - overlap1 / 2 + offset, st->hTcxEnc->speech_TCX - overlap1 / 2 + offset, q, l1 ); - floatToFixed_arr( st->hTcxEnc->speech_TCX_flt - overlap1 / 2 + offset, st->hTcxEnc->speech_TCX - overlap1 / 2 + offset, q, 2 * L_FRAME48k + 960 ); - } - ELSE - { - // FOR( i = 0; i < L_FRAME32k; i++ ) - //{ - // st->hTcxEnc->old_out_fx[i] = float_to_fix16_thrld( st->hTcxEnc->old_out[i], 0 ); - // } - } - - floatToFixed_arr( st->input, st->input_fx, 0, 960 ); -#endif + Scale_sig( st->input_fx, input_frame, negate( st->q_inp ) ); + st->q_inp = 0; + move16(); + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); + st->q_old_inp = 0; + move16(); Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( 0, st->hTcxEnc->q_Txnq ) ); st->hTcxEnc->q_Txnq = 0; move16(); @@ -486,43 +459,26 @@ ivas_error ivas_core_enc( for ( i = 0; i < CPE_CHANNELS; i++ ) { Encoder_State *st1 = sts[i]; - TCX_ENC_HANDLE hTcxEncCh = st1->hTcxEnc; - Word16 nSubframes = ( st1->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for ( n = 0; n < nSubframes; n++ ) - { - Word16 nl = (Word16) ( (float) ( hTcxEncCh->L_frameTCX / nSubframes ) * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); - floatToFixed_arr( &hTcxEncCh->new_speech_TCX_flt[nl - ( hTcxEncCh->L_frameTCX / nSubframes )], - &hTcxEncCh->new_speech_TCX[nl - ( hTcxEncCh->L_frameTCX / nSubframes )], - 0, - 2 * hTcxEncCh->L_frameTCX / nSubframes ); - - IF( n == 0 ) - { - floatToFixed_arr( &hTcxEncCh->speech_TCX_flt[-( sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 0 )], - &hTcxEncCh->speech_TCX[-( sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 0 )], - 0, - sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB ); - } - } - floatToFixed_arr( old_inp_16k[i], old_inp_16k_fx[i], 0, L_INP ); q_fac[i] = Q_factor_arr( old_wsp[i], L_WSP ); floatToFixed_arr( old_wsp[i], old_wsp_fx[i], q_fac[i], L_WSP ); if ( st1->element_mode == IVAS_CPE_DFT ) { - q_fac1 = Q_factor_arr( st1->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - floatToFixed_arr( st1->buf_wspeech_enc_flt, st1->buf_wspeech_enc, q_fac1, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - st1->exp_buf_wspeech_enc = 15 - q_fac1; } else if ( st1->element_mode != IVAS_CPE_MDCT ) { q_fac1 = Q_factor_arr( st1->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); floatToFixed_arr( st1->buf_speech_enc_flt, st1->buf_speech_enc, q_fac1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); st1->exp_buf_speech_enc = 15 - q_fac1; - // floatToFixed_arr( st1->hTcxEnc->buf_speech_ltp_flt, st1->hTcxEnc->buf_speech_ltp, q_fac1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); st1->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac1; } - floatToFixed_arr( st1->input_buff, st1->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + + Scale_sig( st1->input_fx, input_frame, negate( st1->q_inp ) ); + Scale_sig( st1->old_input_signal_fx, input_frame, negate( st1->q_old_inp ) ); + st1->q_old_inp = 0; + move16(); + st1->q_inp = 0; + move16(); } #endif ivas_mdct_core_whitening_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx_new, hMCT->p_mdst_spectrum_long_fx[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long_fx[cpe_id], @@ -532,16 +488,6 @@ ivas_error ivas_core_enc( { Encoder_State *st1 = sts[i]; Word16 nSubframes = ( st1->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - if ( st1->element_mode == IVAS_CPE_DFT ) - { - fixedToFloat_arr( st1->buf_wspeech_enc, st1->buf_wspeech_enc_flt, q_fac1, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - } - else if ( st1->element_mode != IVAS_CPE_MDCT ) - { - // fixedToFloat_arr( st1->hTcxEnc->buf_speech_ltp, st1->hTcxEnc->buf_speech_ltp_flt, q_fac1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - } - fixedToFloat_arr( st1->input_buff_fx, st1->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - fixedToFloat_arrL( st1->hTcxEnc->spectrum_fx[0], st1->hTcxEnc->spectrum[0], 31 - st1->hTcxEnc->spectrum_e[0], st1->hTcxEnc->L_frameTCX / nSubframes ); fixedToFloat_arrL( hMCT->p_orig_spectrum_long_fx[cpe_id][i], hMCT->p_orig_spectrum_long[cpe_id][i], 31 - orig_spectrum_e[i][0], N_TCX10_MAX ); fixedToFloat_arrL( hMCT->p_mdst_spectrum_long_fx[cpe_id][i], hMCT->p_mdst_spectrum_long[cpe_id][i], 31 - mdst_spectrum_e[i][0], N_TCX10_MAX ); @@ -569,31 +515,9 @@ ivas_error ivas_core_enc( Word16 q_fac1 = Q15; for ( i = 0; i < CPE_CHANNELS; i++ ) { - Word16 nSubframes; Encoder_State *st1 = sts[i]; - TCX_ENC_HANDLE hTcxEncCh = st1->hTcxEnc; - nSubframes = ( st1->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for ( n = 0; n < nSubframes; n++ ) - { - Word16 nl = (Word16) ( (float) ( hTcxEncCh->L_frameTCX / nSubframes ) * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); - floatToFixed_arr( &hTcxEncCh->new_speech_TCX_flt[nl - ( hTcxEncCh->L_frameTCX / nSubframes )], - &hTcxEncCh->new_speech_TCX[nl - ( hTcxEncCh->L_frameTCX / nSubframes )], - 0, - 2 * hTcxEncCh->L_frameTCX / nSubframes ); - - IF( n == 0 ) - { - floatToFixed_arr( &hTcxEncCh->speech_TCX_flt[-( sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 0 )], - &hTcxEncCh->speech_TCX[-( sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 0 )], - 0, - sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB ); - } - } if ( st1->element_mode == IVAS_CPE_DFT ) { - q_fac1 = Q_factor_arr( st1->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - floatToFixed_arr( st1->buf_wspeech_enc_flt, st1->buf_wspeech_enc, q_fac1, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - st1->exp_buf_wspeech_enc = 15 - q_fac1; } else if ( st1->element_mode != IVAS_CPE_MDCT ) { @@ -602,7 +526,6 @@ ivas_error ivas_core_enc( st1->exp_buf_speech_enc = 15 - q_fac1; st1->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac1; } - floatToFixed_arr( st1->input_buff, st1->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); } #endif stereo_mdct_core_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx ); @@ -617,15 +540,6 @@ ivas_error ivas_core_enc( fixedToFloat_arrL32( sts[i]->hTcxEnc->spectrum_fx[k], sts[i]->hTcxEnc->spectrum[k], 31 - sts[i]->hTcxEnc->spectrum_e[k], length ); } } - for ( i = 0; i < CPE_CHANNELS; i++ ) - { - Encoder_State *st1 = sts[i]; - if ( st1->element_mode == IVAS_CPE_DFT ) - { - fixedToFloat_arr( st1->buf_wspeech_enc, st1->buf_wspeech_enc_flt, q_fac1, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - } - fixedToFloat_arr( st1->input_buff_fx, st1->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - } #endif } } @@ -659,28 +573,21 @@ ivas_error ivas_core_enc( for ( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; - floatToFixed_arr( st->old_input_signal, st->old_input_signal_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); + Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); + st->q_old_inp = st->q_inp = 0; + move16(); + move16(); + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ // prev_lsp_wb_temp_fx, prev_lsp_wb_fx and prev_lpc_wb_fx in Q15. No float counterparts - floatToFixed_arr( st->input_buff, st->input_buff_fx, 0 /*Q_input*/, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); f2me_buf_16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, &st->exp_buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - IF( st->hTcxEnc != NULL ) - { - st->hTcxEnc->exp_buf_speech_ltp = 31; // Q0 - f2me_buf_16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, &st->exp_buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); - // f2me_buf_16( st->hTcxEnc->buf_speech_ltp_flt, st->hTcxEnc->buf_speech_ltp, &st->hTcxEnc->exp_buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - } floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx[n], Q_new[n] - 1, L_INP_12k8 ); floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx[n], Q_new[n] - 1, L_INP ); - - - if ( st->hBWE_FD != NULL ) - { - Scale_sig( st->hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( Q_new[n] - 1, st->hBWE_FD->prev_Q_input_lp ) ); - st->hBWE_FD->prev_Q_input_lp = Q_new[n] - 1; - } } #endif /*---------------------------------------------------------------------* @@ -691,11 +598,19 @@ ivas_error ivas_core_enc( { st = sts[n]; + IF( st->hTcxEnc != NULL ) + { + st->hTcxEnc->exp_buf_speech_ltp = 31; // Q0 + move16(); + } IF( st->hBWE_FD != NULL ) { Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); st->Q_old_wtda = -1; // This reset is required for resolving crash issue. Needs to be looked into further move16(); + Scale_sig( st->hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( sub( Q_new[n], 1 ), st->hBWE_FD->prev_Q_input_lp ) ); + st->hBWE_FD->prev_Q_input_lp = sub( Q_new[n], 1 ); + move16(); } /*---------------------------------------------------------------------* @@ -879,6 +794,10 @@ ivas_error ivas_core_enc( st->hBWE_FD->prev_Q_input_lp = sub( Q_new[n], 1 ); move16(); } + IF( st->hTcxEnc != NULL ) + { + Scale_sig( st->hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( st->hTcxEnc->exp_buf_speech_ltp ) ); + } } /*------------------------------------------------------------------* @@ -895,20 +814,13 @@ ivas_error ivas_core_enc( diff_nBits = sub( diff_nBits, n ); } } + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; - fixedToFloat_arr( st->old_input_signal_fx, st->old_input_signal, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - fixedToFloat_arr( st->input_fx, st->input, 0 /* Q_input*/, L_FRAME48k ); me2f_buf_16( st->buf_speech_enc_pe, st->exp_buf_speech_enc_pe, st->buf_speech_enc_pe_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); me2f_buf_16( st->buf_speech_enc, st->exp_buf_speech_enc, st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - IF( st->hTcxEnc != NULL ) - { - me2f_buf_16( st->buf_wspeech_enc, st->exp_buf_wspeech_enc, st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); - // me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - Scale_sig( st->hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, -st->hTcxEnc->exp_buf_speech_ltp ); - } } #endif #ifdef DEBUG_MODE_INFO diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 684e7b722aac95a6f76b51e54f3eb6d951964c3e..076ce0f473726880f096d650b128341f15402db5 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -549,13 +549,11 @@ ivas_error pre_proc_ivas( Word16 old_inp_16k_fx[L_INP], Q_old_inp_16k = -1; Word16 Q_r[2] = { 0 }, exp_wsp; Word16 old_wsp_fx[L_WSP], wsp_fx[L_FRAME + L_LOOK_12k8]; - floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); - st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); floatToFixed_arr16( wsp, wsp_fx, Q_old_inp_16k, (Word16) ( L_FRAME + L_LOOK_12k8 ) ); @@ -565,8 +563,7 @@ ivas_error pre_proc_ivas( floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel // wspeech_enc if ( st->hBWE_FD != NULL ) @@ -575,6 +572,11 @@ ivas_error pre_proc_ivas( st->Q_old_wtda = -1; // This reset needs to be looked into } #endif + Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); + st->q_inp = -1; + Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); + st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k ); + move16(); IF( !flag_16k_smc ) { error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx, @@ -634,18 +636,15 @@ ivas_error pre_proc_ivas( st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); - st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, *Q_new - 1, L_INP ); - fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); fixedToFloat_arr( st->old_wsp_fx, st->old_wsp, 15 - st->exp_old_wsp, L_WSP_MEM ); fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, *Q_new - 1, L_INP_MEM ); fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, *Q_new - 1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, *Q_new - 1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel #endif /* set the pointer of the current frame for the ACELP core */ IF( EQ_16( st->L_frame, L_FRAME ) ) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 5354e41137e838d434d9e52dac853741d09db417..2d8b7a860a9b13d747339524f44cb76a55845889 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -931,19 +931,15 @@ ivas_error pre_proc_front_ivas_fx( { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Encoder_State *st; - Word16 old_inp_12k8_e; - if ( hSCE != NULL ) + IF( hSCE != NULL ) { st = hSCE->hCoreCoder[n]; - floatToFixed_arr( hSCE->hCoreCoder[n]->input - (Word16) ( st->input_Fs / 50 ), hSCE->hCoreCoder[n]->input_fx - (Word16) ( st->input_Fs / 50 ), -1, (Word16) ( st->input_Fs / 25 ) ); - floatToFixed_arrL( hSCE->hCoreCoder[n]->input - (Word16) ( st->input_Fs / 50 ), hSCE->hCoreCoder[n]->input32_fx - (Word16) ( st->input_Fs / 50 ), 11, (Word16) ( st->input_Fs / 25 ) ); } - else + ELSE { st = hCPE->hCoreCoder[n]; - floatToFixed_arr( hCPE->hCoreCoder[n]->input - (Word16) ( st->input_Fs / 50 ), hCPE->hCoreCoder[n]->input_fx - (Word16) ( st->input_Fs / 50 ), -1, (Word16) ( st->input_Fs / 25 ) ); - floatToFixed_arrL( hCPE->hCoreCoder[n]->input - (Word16) ( st->input_Fs / 50 ), hCPE->hCoreCoder[n]->input32_fx - (Word16) ( st->input_Fs / 50 ), 11, (Word16) ( st->input_Fs / 25 ) ); } + Word16 old_inp_12k8_e; Word16 mem_decim_e; f2me_buf_16( st->mem_decim, st->mem_decim_fx, &mem_decim_e, 2 * L_FILT_MAX ); f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); @@ -1057,6 +1053,30 @@ ivas_error pre_proc_front_ivas_fx( mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); set16_fx( fft_buff_fx, 0, 512 ); + IF( hSCE != NULL ) + { + Copy_Scale_sig_16_32( hSCE->hCoreCoder[n]->input_fx, hSCE->hCoreCoder[n]->input32_fx, input_frame, sub( Q11, hSCE->hCoreCoder[n]->q_inp ) ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[n]->input_fx - input_frame, hSCE->hCoreCoder[n]->input32_fx - input_frame, input_frame, sub( Q11, hSCE->hCoreCoder[n]->q_old_inp ) ); + hSCE->hCoreCoder[n]->q_inp32 = Q11; + move16(); + Scale_sig( hSCE->hCoreCoder[n]->input_fx, input_frame, sub( -1, hSCE->hCoreCoder[n]->q_inp ) ); + hSCE->hCoreCoder[n]->q_inp = -1; + Scale_sig( hSCE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hSCE->hCoreCoder[n]->q_old_inp ) ); + hSCE->hCoreCoder[n]->q_old_inp = -1; + move16(); + } + ELSE + { + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->input_fx, hCPE->hCoreCoder[n]->input32_fx, input_frame, sub( Q11, hCPE->hCoreCoder[n]->q_inp ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->input_fx - input_frame, hCPE->hCoreCoder[n]->input32_fx - input_frame, input_frame, sub( Q11, hCPE->hCoreCoder[n]->q_old_inp ) ); + hCPE->hCoreCoder[n]->q_inp32 = Q11; + move16(); + Scale_sig( hCPE->hCoreCoder[n]->input_fx, input_frame, sub( -1, hCPE->hCoreCoder[n]->q_inp ) ); + hCPE->hCoreCoder[n]->q_inp = -1; + Scale_sig( hCPE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hCPE->hCoreCoder[n]->q_old_inp ) ); + hCPE->hCoreCoder[n]->q_old_inp = -1; + move16(); + } #ifdef MSAN_FIX FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) { @@ -1328,12 +1348,17 @@ ivas_error pre_proc_front_ivas_fx( * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) *----------------------------------------------------------------*/ - // Word16 scale_factor = sub( getScaleFactor16( st->input_fx - (Word16) ( st->input_Fs / 50 ), (Word16) ( st->input_Fs / 25 ) ), 1 ); - Word16 scale_factor = sub( norm_arr( st->input_fx - (Word16) ( st->input_Fs / 50 ), (Word16) ( st->input_Fs / 25 ) ), 1 ); + // Word16 scale_factor = sub( getScaleFactor16( st->input_fx - input_frame, (Word16) ( st->input_Fs / 25 ) ), 1 ); + Word16 scale_factor = sub( norm_arr( st->input_fx - input_frame, (Word16) ( st->input_Fs / 25 ) ), 1 ); Word16 q_input = s_min( add( -1, scale_factor ), sub( 16, old_inp_12k8_e ) ); - Copy_Scale_sig32_16( st->input32_fx - (Word16) ( st->input_Fs / 50 ), st->input_fx - (Word16) ( st->input_Fs / 50 ), (Word16) ( st->input_Fs / 25 ), add( 16 - 11, q_input ) ); /*scaling down from q11 to q_input*/ - Scale_sig( st->mem_decim_fx, 90, sub( q_input, 15 - mem_decim_e ) ); /*scaling from q(15-mem_decim_e) to q_input*/ - Scale_sig( old_inp_12k8_fx, 496, sub( q_input, sub( 15, old_inp_12k8_e ) ) ); /*scaling from q(15-old_inp_12k8_e) to q_input*/ + Copy_Scale_sig32_16( st->input32_fx - input_frame, st->input_fx - input_frame, (Word16) ( st->input_Fs / 25 ), add( 16 - 11, q_input ) ); /*scaling down from q11 to q_input*/ + st->q_inp = q_input; + move16(); + st->q_old_inp = q_input; + move16(); + + Scale_sig( st->mem_decim_fx, 90, sub( q_input, 15 - mem_decim_e ) ); /*scaling from q(15-mem_decim_e) to q_input*/ + Scale_sig( old_inp_12k8_fx, 496, sub( q_input, sub( 15, old_inp_12k8_e ) ) ); /*scaling from q(15-old_inp_12k8_e) to q_input*/ test(); IF( EQ_16( element_mode, IVAS_SCE ) ) { @@ -1576,7 +1601,7 @@ ivas_error pre_proc_front_ivas_fx( st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 - 1 ); move16(); Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 - 1 ), st->q_Bin_E ) ); - st->q_Bin_E = add( Q_new, Q_SCALE - 2 - 1 ); + 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*/ ); @@ -2443,6 +2468,12 @@ ivas_error pre_proc_front_ivas_fx( st->sba_br_sw_while_no_data = 1; } + IF( flag_16k_smc ) + { + Scale_sig( st->input_fx, input_frame, sub( -1, st->q_inp ) ); + 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]; @@ -2455,20 +2486,16 @@ ivas_error pre_proc_front_ivas_fx( { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 Q_old_inp_16k = -1; - floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); - st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); - st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, 880 ); floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel // wspeech_enc if ( st->hBWE_FD != NULL ) @@ -2477,7 +2504,9 @@ ivas_error pre_proc_front_ivas_fx( st->Q_old_wtda = -1; // This reset needs to be looked into } #endif - + Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); + st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k ); + move16(); /* Compute core-coder buffers at internal sampling rate */ error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx, A_fx, Aw_fx, @@ -2493,16 +2522,13 @@ ivas_error pre_proc_front_ivas_fx( st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); - st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); - fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel #endif #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index e0bc2f18f01026f2c7fa0420435e7e27433ae01a..a632c517e2aa892886fa98e21b14d220bd0663b7 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -503,7 +503,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */ ) { - Word16 n, sce_id, cpe_id; + Word16 n, sce_id, cpe_id, k, shift; Word16 len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing; Word32 input_buff_fx[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; @@ -514,7 +514,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( BSTR_ENC_HANDLE hBstr; Word16 i, nb_bits; Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST]; - Word16 nb_bits_tot; + Word16 nb_bits_tot, input_frame; Word16 nchan_transport_real, nchan_transport_old_real; ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; @@ -527,7 +527,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( error = IVAS_ERR_OK; move32(); - len_inp_memory = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); + input_frame = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); + len_inp_memory = input_frame; + move16(); IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) { len_inp_memory = add( len_inp_memory, NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ) ); @@ -659,72 +661,84 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_com_sce = 0; - Word16 q_com_cpe = 0; - - Word16 gb = find_guarded_bits_fx( len_inp_memory ); + Word16 q_com_sce = Q15; + move16(); + Word16 q_com_cpe = Q15; + move16(); IF( nSCE_old > 0 ) { - float max_val = 0.0f; - for ( int k = 0; k < nSCE_old; k++ ) + FOR( k = 0; k < nSCE_old; k++ ) { - for ( i = 0; i < len_inp_memory; i++ ) - { - max_val = max( max_val, (float) fabs( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff[i] ) ); - } + shift = getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame ); + Scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, shift ); + 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 ); + 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 ); } - q_com_sce = L_get_q1( max_val ) - gb; } IF( nCPE_old > 0 ) { - float max_val = 0.0f; + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - for ( i = 0; i < len_inp_memory; i++ ) - { - max_val = max( max_val, (float) fabs( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff[i] ) ); - } + shift = getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame ); + Scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, shift ); + 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 ); + 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 ); } } - q_com_cpe = L_get_q1( max_val ) - gb; } - - Word16 q_com = min( q_com_sce, q_com_cpe ); + Word16 q_com = s_min( q_com_sce, q_com_cpe ); + q_com = 0; // Expeiment purpose IF( nSCE_old > 0 ) { - for ( int k = 0; k < nSCE_old; k++ ) - { - st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = q_com; - } - for ( int k = 0; k < nSCE_old; k++ ) + FOR( k = 0; k < nSCE_old; k++ ) { - floatToFixed_arrL( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32, len_inp_memory ); + 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 ) ); + 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 ) ); + st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( Q6, q_com ); + move16(); } } IF( nCPE_old > 0 ) { - FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = q_com; - } - } - FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - floatToFixed_arrL( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32, len_inp_memory ); + 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 ) ); + 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 ) ); + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( Q6, q_com ); + move16(); } } } -#endif + test(); test(); IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) @@ -994,20 +1008,47 @@ ivas_error ivas_corecoder_enc_reconfig_fx( test(); test(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( st_ivas->nSCE ) { - fixedToFloat_arrL( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, q_com, len_inp_memory ); + IF( NE_16( input_frame, len_inp_memory ) ) + { + Copy_Scale_sig32_16( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[0]->hCoreCoder[0]->input_buff_fx, len_inp_memory, sub( add( Q16, 0 ), st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32 ) ); // Q(q_data_fx) -> Q(q_input) + st_ivas->hSCE[0]->hCoreCoder[0]->q_old_inp = 0; + move16(); + Copy_Scale_sig32_16( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx + sub( len_inp_memory, input_frame ), st_ivas->hSCE[0]->hCoreCoder[0]->input_buff_fx + sub( len_inp_memory, input_frame ), sub( len_inp_memory, input_frame ), sub( add( Q16, 0 ), st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32 ) ); // Q(q_data_fx) -> Q(q_input) + st_ivas->hSCE[0]->hCoreCoder[0]->q_inp = 0; + move16(); + } + ELSE + { + Copy_Scale_sig32_16( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[0]->hCoreCoder[0]->input_buff_fx, len_inp_memory, sub( add( Q16, 0 ), st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32 ) ); // Q(q_data_fx) -> Q(q_input) + st_ivas->hSCE[0]->hCoreCoder[0]->q_old_inp = 0; + move16(); + } } IF( st_ivas->nCPE ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - fixedToFloat_arrL( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, q_com, len_inp_memory ); + IF( NE_16( input_frame, len_inp_memory ) ) + { + Copy_Scale_sig32_16( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[0]->hCoreCoder[n]->input_buff_fx, len_inp_memory, sub( add( Q16, 0 ), st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32 ) ); // Q(q_data_fx) -> Q(q_input) + st_ivas->hCPE[0]->hCoreCoder[n]->q_old_inp = 0; + move16(); + + Copy_Scale_sig32_16( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx + sub( len_inp_memory, input_frame ), st_ivas->hCPE[0]->hCoreCoder[n]->input_buff_fx + sub( len_inp_memory, input_frame ), sub( len_inp_memory, input_frame ), sub( add( Q16, 0 ), st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32 ) ); // Q(q_data_fx) -> Q(q_input) + st_ivas->hCPE[0]->hCoreCoder[n]->q_inp = 0; + move16(); + } + ELSE + { + Copy_Scale_sig32_16( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[0]->hCoreCoder[n]->input_buff_fx, len_inp_memory, sub( add( Q16, 0 ), st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32 ) ); // Q(q_data_fx) -> Q(q_input) + st_ivas->hCPE[0]->hCoreCoder[n]->q_old_inp = 0; + move16(); + } } } -#endif IF( GT_16( st_ivas->nCPE, 1 ) && LE_16( nCPE_old, 1 ) ) { diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 629c23870a318ed0b5e77ec48759a6dd45cc0a63..dc44161b61b50fa172fb669f5ea78aaa227673f0 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -129,7 +129,6 @@ ivas_error ivas_cpe_enc_fx( Word16 localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ Word32 band_energies_LR_fx[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN (Q_buffer + QSCALE - band_ener_guardbits) */ Word16 Q_buffer[2]; - float orig_input[CPE_CHANNELS][L_FRAME48k]; Word16 orig_input_fx[CPE_CHANNELS][L_FRAME48k]; Word16 Etot_last_fx[CPE_CHANNELS]; Word32 tmp, input_Fs; @@ -206,18 +205,14 @@ ivas_error ivas_cpe_enc_fx( Copy32( data_fx_ch0, sts[0]->input32_fx, input_frame ); // Q(q_data_fx) Copy_Scale_sig32_16( sts[0]->input32_fx, sts[0]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( sts[0]->input32_fx, sts[0]->input, q_data_fx, input_frame ); -#endif + sts[0]->q_inp = 0; + move16(); IF( data_fx_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ { Copy32( data_fx_ch1, sts[1]->input32_fx, input_frame ); // Q(q_data_fx) Copy_Scale_sig32_16( sts[1]->input32_fx, sts[1]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( sts[1]->input32_fx, sts[1]->input, q_data_fx, input_frame ); -#endif + sts[1]->q_inp = 0; + move16(); } FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) @@ -340,49 +335,71 @@ ivas_error ivas_cpe_enc_fx( /*----------------------------------------------------------------* * Set TD stereo parameters *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - Q_inp = min( Q_inp, Q_factor_arrL( sts[1]->input, input_frame ) ); - floatToFixed_arrL32( sts[1]->input, sts[1]->input32_fx, Q_inp, input_frame ); + + Copy_Scale_sig_16_32( sts[1]->input_fx, sts[1]->input32_fx, input_frame, sub( Q11, sts[1]->q_inp ) ); + Copy_Scale_sig_16_32( sts[0]->input_fx, sts[0]->input32_fx, input_frame, sub( Q11, sts[0]->q_inp ) ); + + Word16 shift = getScaleFactor32( sts[1]->input32_fx, input_frame ); + scale_sig32( sts[1]->input32_fx, input_frame, shift ); + sts[1]->q_inp32 = add( Q11, shift ); + move16(); + + shift = getScaleFactor32( sts[0]->input32_fx, input_frame ); + scale_sig32( sts[0]->input32_fx, input_frame, shift ); + sts[0]->q_inp32 = add( Q11, shift ); + move16(); + + Q_inp = s_min( Q_inp, s_min( sts[0]->q_inp32, sts[1]->q_inp32 ) ); + scale_sig32( sts[0]->input32_fx, input_frame, sub( Q_inp, sts[0]->q_inp32 ) ); + scale_sig32( sts[1]->input32_fx, input_frame, sub( Q_inp, sts[1]->q_inp32 ) ); + sts[1]->q_inp32 = sts[0]->q_inp32 = Q_inp; + move16(); + move16(); + if ( ( error = stereo_set_tdm_fx( hCPE, input_frame, Q_inp ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = stereo_set_tdm( hCPE, input_frame ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif + /*----------------------------------------------------------------* * Resets/updates in case of stereo switching *----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( sts[0]->old_input_signal, sts[0]->old_input_signal_fx, 0, input_frame ); - Word16 q_inp = Q15; - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - q_inp = min( q_inp, Q_factor_arr( sts[n]->input_buff, 1965 ) ); - } - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - floatToFixed_arr( sts[n]->input_buff, sts[n]->input_buff_fx, q_inp, 1965 ); - } + shift = getScaleFactor16( sts[1]->old_input_signal_fx, input_frame ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); + sts[1]->q_old_inp = add( sts[1]->q_old_inp, shift ); + move16(); + shift = getScaleFactor16( sts[1]->input_fx, input_frame ); + Scale_sig( sts[1]->input_fx, input_frame, shift ); + sts[1]->q_inp = add( sts[1]->q_inp, shift ); + move16(); + + shift = getScaleFactor16( sts[0]->old_input_signal_fx, input_frame ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); + sts[0]->q_old_inp = add( sts[0]->q_old_inp, shift ); + move16(); + shift = getScaleFactor16( sts[0]->input_fx, input_frame ); + Scale_sig( sts[0]->input_fx, input_frame, shift ); + sts[0]->q_inp = add( sts[0]->q_inp, shift ); + move16(); + + Word16 q_inp = s_min( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), s_min( sts[1]->q_inp, sts[1]->q_old_inp ) ); + + Scale_sig( sts[1]->input_fx, input_frame, sub( q_inp, sts[1]->q_inp ) ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( q_inp, sts[1]->q_old_inp ) ); + sts[1]->q_inp = q_inp; + sts[1]->q_old_inp = q_inp; + Scale_sig( sts[0]->input_fx, input_frame, sub( q_inp, sts[0]->q_inp ) ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( q_inp, sts[0]->q_old_inp ) ); + sts[0]->q_inp = q_inp; + move16(); + sts[0]->q_old_inp = q_inp; + move16(); floatToFixed_arr( sts[0]->buf_speech_enc_flt, sts[0]->buf_speech_enc, q_inp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); -#endif stereo_switching_enc_fx( hCPE, sts[0]->old_input_signal_fx, input_frame, q_inp ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( hCPE->element_mode == IVAS_CPE_DFT ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - fixedToFloat_arr( sts[n]->input_buff_fx, sts[n]->input_buff, q_inp, 1965 ); - } - } -#endif #else stereo_switching_enc( hCPE, sts[0]->old_input_signal, input_frame ); #endif @@ -390,21 +407,24 @@ ivas_error ivas_cpe_enc_fx( * Temporal inter-channel alignment, stereo adjustment *----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_com = L_get_q_buf1( sts[0]->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - q_com = min( q_com, L_get_q_buf1( sts[1]->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) - 10; - floatToFixed_arrL32( sts[0]->input_buff, sts[0]->input_buff32_fx, q_com, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - floatToFixed_arrL32( sts[1]->input_buff, sts[1]->input_buff32_fx, q_com, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - sts[0]->q_inp32 = sts[1]->q_inp32 = q_com; -#endif + Copy_Scale_sig_16_32( sts[0]->input_buff_fx, sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), Q6 ); + sts[0]->q_inp32 = add( Q6, sts[0]->q_inp ); + move16(); + Copy_Scale_sig_16_32( sts[1]->input_buff_fx, sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), Q6 ); + sts[1]->q_inp32 = add( Q6, sts[1]->q_inp ); + move16(); stereo_tca_enc_fx( hCPE, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( sts[0]->input_buff32_fx, sts[0]->input_buff, sts[0]->q_inp32, 1965 ); - fixedToFloat_arrL32( sts[1]->input_buff32_fx, sts[1]->input_buff, sts[1]->q_inp32, 1965 ); -#endif + Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, 0 ), sts[0]->q_inp32 ) ); + Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, 0 ), sts[1]->q_inp32 ) ); + + sts[0]->q_inp = sts[1]->q_inp = sts[0]->q_old_inp = sts[1]->q_old_inp = 0; + move16(); + move16(); + move16(); + move16(); #else stereo_tca_enc( hCPE, input_frame ); #endif @@ -412,18 +432,16 @@ ivas_error ivas_cpe_enc_fx( * Input signal buffering - needed in IC-BWE and TD ITD in MDCT stereo *----------------------------------------------------------------*/ - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( sts[n]->input, sts[n]->input_fx, -1, input_frame ); -#endif - mvr2r( sts[n]->input, orig_input[n], input_frame ); + Scale_sig( sts[n]->input_fx, input_frame, sub( -1, sts[n]->q_inp ) ); + sts[n]->q_inp = -1; Copy( sts[n]->input_fx, orig_input_fx[n], input_frame ); IF( hCPE->hStereoICBWE != NULL ) { hCPE->hStereoICBWE->dataChan_fx[n] = &orig_input_fx[n][0]; - hCPE->hStereoICBWE->q_dataChan_fx = -1; + hCPE->hStereoICBWE->q_dataChan_fx = sts[n]->q_inp; move16(); } } @@ -444,11 +462,7 @@ ivas_error ivas_cpe_enc_fx( test(); IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf_16( sts[n]->input, sts[n]->input_fx, &q_inp, input_frame ); - q_inp = 15 - q_inp; -#endif - RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet, q_inp ); // Note q of sts[n]->input_fx changes inside function + RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet, sts[n]->q_inp ); // Note q of sts[n]->input_fx changes inside function } currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) sts[n]->hTranDet, NSUBBLOCKS, 0 ); // Q7 @@ -574,19 +588,7 @@ ivas_error ivas_cpe_enc_fx( if ( hCPE->element_mode == IVAS_CPE_DFT ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 i; /* flt2fix: to be removed */ - FOR( i = 0; i < CPE_CHANNELS; i++ ) - { - sts[i]->q_inp = Q_factor_arr( sts[i]->old_input_signal, 1965 ); // check length -#ifndef MSAN_FIX - hCPE->hStereoDft->q_input_mem_itd[i] = Q_factor_arr( &hCPE->hStereoDft->input_mem_itd[i][0], STEREO_DFT_OVL_MAX ); -#endif // MSAN_FIX - floatToFixed_arr( sts[i]->old_input_signal, sts[i]->old_input_signal_fx, sts[i]->q_inp, 1965 ); -#ifndef MSAN_FIX - floatToFixed_arr( &hCPE->hStereoDft->input_mem_itd[i][0], &hCPE->hStereoDft->input_mem_itd_fx[i][0], hCPE->hStereoDft->q_input_mem_itd[i], STEREO_DFT_OVL_MAX ); -#endif // MSAN_FIX - } #ifndef MSAN_FIX hCPE->hStereoClassif->xtalk_score_fx = floatToFixed( hCPE->hStereoClassif->xtalk_score, 31 ); #endif // !MSAN_FIX @@ -606,6 +608,36 @@ ivas_error ivas_cpe_enc_fx( scale_sig32( hCPE->hStereoDft->Spd_R_smooth_fx, STEREO_DFT_N_32k_ENC / 2, temp ); hCPE->hStereoDft->Spd_R_smooth_fx_e = sub( hCPE->hStereoDft->Spd_R_smooth_fx_e, temp ); + shift = getScaleFactor16( sts[1]->old_input_signal_fx, input_frame ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); + sts[1]->q_old_inp = add( sts[1]->q_old_inp, shift ); + move16(); + shift = getScaleFactor16( sts[1]->input_fx, input_frame ); + Scale_sig( sts[1]->input_fx, input_frame, shift ); + sts[1]->q_inp = add( sts[1]->q_inp, shift ); + move16(); + Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[1]->q_inp, sts[1]->q_old_inp ), sts[1]->q_inp ) ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( s_min( sts[1]->q_old_inp, sts[1]->q_old_inp ), sts[1]->q_old_inp ) ); + sts[1]->q_inp = s_min( sts[1]->q_inp, sts[1]->q_old_inp ); + move16(); + sts[1]->q_old_inp = sts[1]->q_inp; + move16(); + + shift = getScaleFactor16( sts[0]->old_input_signal_fx, input_frame ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); + sts[0]->q_old_inp = add( sts[0]->q_old_inp, shift ); + move16(); + shift = getScaleFactor16( sts[0]->input_fx, input_frame ); + Scale_sig( sts[0]->input_fx, input_frame, shift ); + sts[0]->q_inp = add( sts[0]->q_inp, shift ); + move16(); + Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), sts[0]->q_inp ) ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( s_min( sts[0]->q_old_inp, sts[0]->q_old_inp ), sts[0]->q_old_inp ) ); + sts[0]->q_inp = s_min( sts[0]->q_inp, sts[0]->q_old_inp ); + move16(); + sts[0]->q_old_inp = sts[0]->q_inp; + move16(); + stereo_dft_hybrid_ITD_flag_fx( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max ); /* Time Domain ITD compensation using extrapolation */ @@ -632,31 +664,20 @@ ivas_error ivas_cpe_enc_fx( } else if ( hCPE->element_mode == IVAS_CPE_TD ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); - floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); + Scale_sig( sts[0]->input_fx, input_frame, negate( sts[0]->q_inp ) ); + sts[0]->q_inp = 0; + move16(); + Scale_sig( sts[1]->input_fx, input_frame, negate( sts[1]->q_inp ) ); + sts[1]->q_inp = 0; + move16(); - IF( hCPE->hStereoTD->tdm_last_SM_flag ) - { - floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); - floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); - } -#endif /* Determine the energy ratio between the 2 channels */ tdm_ratio_idx = stereo_tdm_ener_analysis_fx( ivas_format, hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Compute the downmix signal based on the ratio index */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 input_fx[2][L_FRAME48k]; - // Word16 tmpppp;// to be checked:dynamic q leading to crash - // tmpppp = s_min( Q_factor_arr( sts[1]->input, input_frame ), Q_factor_arr( sts[0]->input, input_frame ) ); - floatToFixed_arr16( sts[1]->input, input_fx[1], 0, input_frame ); - floatToFixed_arr16( sts[0]->input, input_fx[0], 0, input_frame ); -#endif Word16 tdm_SM_flag; IF( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) { @@ -668,15 +689,7 @@ ivas_error ivas_cpe_enc_fx( tdm_SM_flag = 0; move16(); } - stereo_tdm_downmix_ivas_fx( hCPE->hStereoTD, input_fx[0], input_fx[1], input_frame, tdm_ratio_idx, tdm_SM_flag, tdm_ratio_idx_SM ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( input_fx[0], sts[0]->input, 0, input_frame ); - fixedToFloat_arr( input_fx[1], sts[1]->input, 0, input_frame ); -#endif -#else - stereo_tdm_downmix( hCPE->hStereoTD, sts[0]->input, sts[1]->input, input_frame, tdm_ratio_idx, ( ( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) ? tdm_SM_or_LRTD_Pri : 0 ), tdm_ratio_idx_SM ); -#endif + stereo_tdm_downmix_ivas_fx( hCPE->hStereoTD, sts[0]->input_fx, sts[1]->input_fx, input_frame, tdm_ratio_idx, tdm_SM_flag, tdm_ratio_idx_SM ); /* signal the bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; @@ -702,27 +715,49 @@ ivas_error ivas_cpe_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { - FOR( int16_t i = 0; i < CPE_CHANNELS; i++ ) - { - sts[i]->q_inp = Q_factor_arr( sts[i]->old_input_signal, 1965 ); // check length - floatToFixed_arr( sts[i]->old_input_signal, sts[i]->old_input_signal_fx, sts[i]->q_inp, 1965 ); - } if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { floatToFixed_arr( sts[1]->old_inp_12k8, sts[1]->old_inp_12k8_fx, 0, L_INP_MEM ); } } #endif - stereo_td_itd_mdct_stereo_fx( hCPE, vad_flag_dtx, vad_hover_flag, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) + test(); + IF( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { - FOR( int16_t i = 0; i < CPE_CHANNELS; i++ ) - { - fixedToFloat_arr( sts[i]->old_input_signal_fx, sts[i]->old_input_signal, sts[i]->q_inp, 1965 ); - } + + shift = getScaleFactor16( sts[1]->old_input_signal_fx, input_frame ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); + sts[1]->q_old_inp = add( sts[1]->q_old_inp, shift ); + move16(); + shift = getScaleFactor16( sts[1]->input_fx, input_frame ); + Scale_sig( sts[1]->input_fx, input_frame, shift ); + sts[1]->q_inp = add( sts[1]->q_inp, shift ); + move16(); + Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[1]->q_inp, sts[1]->q_old_inp ), sts[1]->q_inp ) ); + Scale_sig( sts[1]->old_input_signal_fx, input_frame, sub( s_min( sts[1]->q_old_inp, sts[1]->q_old_inp ), sts[1]->q_old_inp ) ); + sts[1]->q_inp = s_min( sts[1]->q_inp, sts[1]->q_old_inp ); + move16(); + sts[1]->q_old_inp = sts[1]->q_inp; + move16(); + + shift = getScaleFactor16( sts[0]->old_input_signal_fx, input_frame ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, shift ); + sts[0]->q_old_inp = add( sts[0]->q_old_inp, shift ); + move16(); + shift = getScaleFactor16( sts[0]->input_fx, input_frame ); + Scale_sig( sts[0]->input_fx, input_frame, shift ); + sts[0]->q_inp = add( sts[0]->q_inp, shift ); + move16(); + move16(); + Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[0]->q_old_inp ), sts[0]->q_inp ) ); + Scale_sig( sts[0]->old_input_signal_fx, input_frame, sub( s_min( sts[0]->q_old_inp, sts[0]->q_old_inp ), sts[0]->q_old_inp ) ); + sts[0]->q_inp = s_min( sts[0]->q_inp, sts[0]->q_old_inp ); + move16(); + sts[0]->q_old_inp = sts[0]->q_inp; + move16(); } -#endif + + stereo_td_itd_mdct_stereo_fx( hCPE, vad_flag_dtx, vad_hover_flag, input_frame ); #else stereo_td_itd_mdct_stereo( hCPE, vad_flag_dtx, vad_hover_flag, input_frame ); #endif @@ -772,11 +807,11 @@ ivas_error ivas_cpe_enc_fx( /* update old input signal buffer */ Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_FRAME8k, sts[1]->old_inp_12k8_fx, L_INP_MEM, 0 - 16 ); } + 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 ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS /*local fix2flt*/ /*fix2flt: dft_synthesize*/ - fixedToFloat_arrL( sts[0]->input32_fx + out_start_ind, sts[0]->input + out_start_ind, 16, out_end_ind - out_start_ind ); 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 ); if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) @@ -813,7 +848,9 @@ ivas_error ivas_cpe_enc_fx( } #endif /* no iDFT at input sampling rate for Side channel -> reset the buffer */ - set_zero( sts[1]->input, input_frame ); + set16_fx( sts[1]->input_fx, 0, input_frame ); + sts[1]->q_inp = Q15; + move16(); } #ifdef DEBUG_MODE_INFO @@ -1173,19 +1210,22 @@ ivas_error ivas_cpe_enc_fx( /* update input samples buffer */ for ( n = 0; n < CPE_CHANNELS; n++ ) { - mvr2r( orig_input[n], sts[n]->old_input_signal, input_frame ); + Copy( orig_input_fx[n], sts[n]->old_input_signal_fx, input_frame ); + sts[n]->q_old_inp = sts[n]->q_inp; } } else if ( hCPE->element_mode == IVAS_CPE_DFT ) { - mvr2r( sts[0]->input, sts[0]->old_input_signal, input_frame ); + Copy( sts[0]->input_fx, sts[0]->old_input_signal_fx, input_frame ); + sts[0]->q_old_inp = sts[0]->q_inp; } else if ( st_ivas->hMCT == NULL ) /* note: in MCT, input buffers are updated later in ivas_mct_enc() */ { /* update input samples buffer */ for ( n = 0; n < CPE_CHANNELS; n++ ) { - mvr2r( sts[n]->input, sts[n]->old_input_signal, input_frame ); + Copy( sts[n]->input_fx, sts[n]->old_input_signal_fx, input_frame ); + sts[n]->q_old_inp = sts[n]->q_inp; } } diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 9d768825be33b0ced2211761f89eeae668b40d5c..2a4ec05e1e58278865c9a5ec0afe83ed14497c9e 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -798,7 +798,6 @@ ivas_error front_vad_spar_fx( /*------------------------------------------------------------------* * compensate for SPAR filterbank delay *-----------------------------------------------------------------*/ - st->input_fx = input_fx; Copy_Scale_sig32_16( omni_in, st->input_fx, input_frame, Q16 - Q11 ); @@ -826,11 +825,11 @@ ivas_error front_vad_spar_fx( IF( tmp != 0 ) { Scale_sig( st->input_fx, input_frame, s ); + st->q_inp = add( st->q_inp, s ); + move16(); } Q_inp = s; move16(); - - /*------------------------------------------------------------------* * Front-VAD *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index dbb7b32dbbebf3bd1c693826abe92bb95e2848ba..01ffc82b3c915cc9304f4f2bbba7cc339ed571c3 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -529,7 +529,8 @@ ivas_error ivas_ism_enc_fx( Copy32( data[sce_id], st->input32_fx, input_frame ); // Q(q_data) q_st_inp_16 = sub( L_norm_arr( st->input32_fx, input_frame ), 16 ); Copy_Scale_sig_32_16( st->input32_fx, st->input_fx, input_frame, q_st_inp_16 ); // q_data -> Q(q_inp + q_data) - q_st_inp_16 = add( q_st_inp_16, q_data ); + st->q_inp = add( q_st_inp_16, q_data ); + move16(); st->element_mode = IVAS_SCE; move16(); @@ -561,10 +562,8 @@ ivas_error ivas_ism_enc_fx( /*---------------------------------------------------------------* * Time Domain Transient Detector *---------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->input32_fx, st->input, q_data, input_frame ); -#endif - RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_st_inp_16 ); + + RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, st->q_inp ); currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q7 move16(); @@ -612,14 +611,17 @@ ivas_error ivas_ism_enc_fx( * DTX analysis *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS /* compute the dominant sce_id using long term energy */ - for ( int j = 0; j < st_ivas->nchan_transport; j++ ) + FOR( Word16 j = 0; j < st_ivas->nchan_transport; j++ ) { - if ( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) - floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ + test(); + IF( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] ) + { + Copy_Scale_sig_16_32( st_ivas->hSCE[j]->hCoreCoder[0]->input_fx, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, input_frame, sub( Q11, st_ivas->hSCE[j]->hCoreCoder[0]->q_inp ) ); + st_ivas->hSCE[j]->hCoreCoder[0]->q_inp32 = Q11; + move16(); + } } -#endif IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { @@ -787,7 +789,10 @@ ivas_error ivas_ism_enc_fx( *----------------------------------------------------------------*/ /* update input samples buffer */ - mvr2r( st->input, st->old_input_signal, input_frame ); + + Copy( st->input_fx, st->old_input_signal_fx, input_frame ); + st->q_old_inp = st->q_inp; + move16(); hSCE->last_element_brate = hSCE->element_brate; move32(); diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 5cabb53bf01a564e29dd25c473c588b14f4c635d..3cc3e02f1dd873d83c01eda12430b7a3b5495b51 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -653,8 +653,9 @@ ivas_error ivas_mct_enc_fx( /* update input samples buffer (as done in ivas_cpe_enc() for other than MCT coding) */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - mvr2r( hCPE->hCoreCoder[n]->input, hCPE->hCoreCoder[n]->old_input_signal, input_frame ); - + Copy( hCPE->hCoreCoder[n]->input_fx, hCPE->hCoreCoder[n]->old_input_signal_fx, input_frame ); + hCPE->hCoreCoder[n]->q_old_inp = hCPE->hCoreCoder[n]->q_inp; + move16(); /* common encoder updates */ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -664,8 +665,6 @@ ivas_error ivas_mct_enc_fx( IF( st->hTcxEnc != NULL ) { st->hTcxEnc->exp_buf_speech_ltp = 31; /*Q0*/ - f2me_buf_16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, &st->exp_buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); - // f2me_buf_16( st->hTcxEnc->buf_speech_ltp_flt, st->hTcxEnc->buf_speech_ltp, &st->hTcxEnc->exp_buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } #endif @@ -676,8 +675,6 @@ ivas_error ivas_mct_enc_fx( me2f_buf_16( st->buf_speech_enc, st->exp_buf_speech_enc, st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); IF( st->hTcxEnc != NULL ) { - me2f_buf_16( st->buf_wspeech_enc, st->exp_buf_wspeech_enc, st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); - // me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); Scale_sig( st->hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, st->hTcxEnc->exp_buf_speech_ltp ); } #endif diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 7acb55cdee17b4f5ac6bec9fb5a7680247ab5410..aa9b891e7de361548ae6117ecafa426fcd41e3d5 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -127,10 +127,8 @@ ivas_error ivas_sce_enc_fx( q_input = sub( add( L_norm_arr( st->input32_fx, input_frame ), q_data_fx ), 16 ); Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( add( Q16, q_input ), q_data_fx ) ); // Q(q_data_fx) -> Q(q_input) - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( st->input32_fx, st->input, q_data_fx, input_frame ); -#endif + st->q_inp = q_input; + move16(); st->element_mode = IVAS_SCE; move16(); @@ -353,8 +351,9 @@ ivas_error ivas_sce_enc_fx( *----------------------------------------------------------------*/ /* update input samples buffer */ - mvr2r( st->input, st->old_input_signal, input_frame ); - + Copy( st->input_fx, st->old_input_signal_fx, input_frame ); + st->q_old_inp = st->q_inp; + move16(); hSCE->last_element_brate = hSCE->element_brate; move32(); diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index a13a76083941c721bad9e6b1b04e4ef84654c1e2..e3ff9b07ba8a384485119e8a0145afffdaa56517 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -759,6 +759,8 @@ void stereo_td_itd_fx( Copy( shift_input, sts[ch]->input_fx, input_frame ); sts[ch]->q_inp = q_new_shift; move16(); + /*sts[ch]->q_old_inp = q_new_shift; + move16();*/ IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) { // here shift_mem has same as input_mem, no need to update q // diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index b54ef3d1b49bfb7723e538bb87a46df821f57794..eb68c8d5673f236c3cdddffd3a179a77eb27ffdb 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -656,6 +656,13 @@ void stereo_mdct_core_enc_fx( move16(); sts[ch]->hTcxEnc->tns_ms_flag[1] = 0; move16(); + + Scale_sig( sts[ch]->input_fx, (Word16) ( sts[ch]->input_Fs / 50 ) + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), negate( sts[ch]->q_inp ) ); + Scale_sig( sts[ch]->old_input_signal_fx, (Word16) ( sts[ch]->input_Fs / 50 ), negate( sts[ch]->q_old_inp ) ); + sts[ch]->q_old_inp = 0; + move16(); + sts[ch]->q_inp = 0; + move16(); } /*--------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index a0f69932362cd25c659fadae74178f2fcd965d2c..8fc32840675239c74b5040d6985ba89e22a6fd17 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -1356,9 +1356,9 @@ void stereo_switching_enc_fx( /* First frame after DFT frame AND the content is uncorrelated or xtalk -> the primary channel is forced to left */ IF( EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) ) { - set_zero( sts[1]->input - input_frame, input_frame ); set_zero_fx( sts[1]->input32_fx - input_frame, input_frame ); - + set16_zero_fx( sts[1]->input_fx - input_frame, input_frame ); + sts[1]->q_old_inp = Q15; hCPE->hStereoTD->tdm_last_ratio_fx = tdm_ratio_tabl_fx[LRTD_STEREO_LEFT_IS_PRIM]; move32(); diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index 9abe856a02c3290ea5490e47fbeb354f8ff1037b..a315cf72580835a1e3e9d0b1df197d2e9cb890a4 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -1395,31 +1395,33 @@ static Word16 Get_dt_lt_ener_fx( Word16 *q_corr_RM ) { Encoder_State **sts; -#if 0 Word16 *Left_in_fx, *Right_in_fx; -#else - Word16 Left_in_fx[L_FRAME48k], Right_in_fx[L_FRAME48k]; - Word16 q_Left_in, q_Right_in; -#endif Word32 es_em_fx; Word16 tmp_SM_flag, tdm_SM_flag_loc; Word32 L_tmp, L_tmp1; - Word16 exp_diff; + Word16 exp_diff, tmp; sts = hCPE->hCoreCoder; -#if 0 + Left_in_fx = sts[0]->input_fx; /* Left channel */ Right_in_fx = sts[1]->input_fx; /* Right channel */ -#else - /* This part has f2f conversions as sts[0]->input_fx and sts[1]->input_fx are in Q0. - Precision loss is observed in Get_corr_n_fx() function. */ - q_Left_in = Q_factor_arr( sts[0]->input, input_frame ); - q_Right_in = Q_factor_arr( sts[1]->input, input_frame ); - q_Left_in = s_min( q_Left_in, q_Right_in ); - q_Left_in = sub( q_Left_in, Q1 ); - floatToFixed_arr16( sts[0]->input, Left_in_fx, q_Left_in, input_frame ); - floatToFixed_arr16( sts[1]->input, Right_in_fx, q_Left_in, input_frame ); -#endif + + tmp = getScaleFactor16( sts[0]->input_fx, input_frame ); + Scale_sig( sts[0]->input_fx, input_frame, tmp ); + sts[0]->q_inp = add( tmp, sts[0]->q_inp ); + move16(); + + tmp = getScaleFactor16( sts[1]->input_fx, input_frame ); + Scale_sig( sts[1]->input_fx, input_frame, tmp ); + sts[1]->q_inp = add( tmp, sts[1]->q_inp ); + move16(); + + Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[1]->q_inp ), sts[0]->q_inp ) ); + Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[1]->q_inp ), sts[1]->q_inp ) ); + sts[1]->q_inp = s_min( sts[0]->q_inp, sts[1]->q_inp ); + move16(); + sts[0]->q_inp = sts[1]->q_inp; + move16(); tdm_SM_flag_loc = tdm_last_SM_flag; move16(); diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 6a03966c93b6c2b2ce62f6f891d4d95a0fe329a2..f2c1a8bbc0e8fdd7e010f4ad5cb8cc7b03775dc1 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -280,7 +280,7 @@ void stereo_tcx_core_enc( /*HM*/ Word16 indexBuffer[2 * ( ( N_MAX / 2 ) + 1 )]; - Word16 s; + Word16 s, input_frame; CONTEXT_HM_CONFIG hm_cfg[2]; @@ -448,16 +448,20 @@ void stereo_tcx_core_enc( /* TODO: integrate this. */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->input_buff, st->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); st->prev_Q_new = 0; st->Q_old = 0; #endif Q_new = 0; move16(); + input_frame = idiv1616U( extract_l( L_shr( st->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); + Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); + st->q_old_inp = 0; + move16(); + st->q_inp = 0; + move16(); + core_signal_analysis_high_bitrate_ivas_fx( p_new_samples, T_op, lsp_new_fx, lsp_mid_fx, st, tnsSize, tnsBits, param_core, <pBits, NULL, st->L_frame, hTcxEnc->L_frameTCX, last_element_mode, vad_hover_flag, NULL, NULL, &Q_new, NULL ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->input_buff_fx, st->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); -#endif bitsAvailable = sub( st->bits_frame_core, nbits_header ); IF( st->igf ) diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 1714bc0c4eb90ca1d95da8b5f4464b52c2d22f27..7403143c35a3224ac8f4cb188e5b82d2113145cd 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -112,10 +112,10 @@ typedef struct signal_buffers_enc_data_structure float old_inp_16k_flt[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ float buf_speech_enc_pe_flt[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; #ifndef IVAS_FLOAT_FIXED - float buf_synth_flt[OLD_SYNTH_SIZE_ENC + L_FRAME32k]; /* can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching */ + float buf_synth_flt[OLD_SYNTH_SIZE_ENC + L_FRAME32k]; /* can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching */ + float buf_wspeech_enc_flt[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; /* increased by 320 to avoid memory overlap in find_wsp() and also to accomodate for the wspeech_enc */ #endif float buf_speech_enc_flt[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; - float buf_wspeech_enc_flt[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; /* increased by 320 to avoid memory overlap in find_wsp() and also to accomodate for the wspeech_enc */ // Fixed Word16 input_buff[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; Word32 input_buff32[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; @@ -1809,12 +1809,13 @@ typedef struct tcx_enc_structure // int16_t memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word8 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ - +#ifndef IVAS_FLOAT_FIXED float *speech_TCX_flt; float *new_speech_TCX_flt; +#endif Word16 *speech_TCX; Word16 *new_speech_TCX; - Word16 q_speech_TCX; + // Word16 q_speech_TCX; int16_t tcxltp; int16_t tcxltp_pitch_int; @@ -2236,10 +2237,11 @@ typedef struct enc_core_structure * General signal buffers *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED float *input_buff; float *input; float *old_input_signal; - +#endif Word16 *input_buff_fx; Word32 *input_buff32_fx; Word16 *input_fx; @@ -2247,7 +2249,7 @@ typedef struct enc_core_structure Word16 q_inp32; Word16 q_inp; Word16 *old_input_signal_fx; - // Word16 q_old_inp; + Word16 q_old_inp; Word16 Q_old_wtda; SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; @@ -2261,9 +2263,9 @@ typedef struct enc_core_structure float *buf_speech_enc_pe_flt; #ifndef IVAS_FLOAT_FIXED float *buf_synth_flt; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ + float *buf_wspeech_enc_flt; #endif float *buf_speech_enc_flt; - float *buf_wspeech_enc_flt; Word32 *Bin_E_old_fx; /* per bin energy of old 2nd frames */ Word16 q_Bin_E_old; Word16 *mem_decim_fx; /* decimation filter memory */ @@ -2494,14 +2496,14 @@ typedef struct enc_core_structure int16_t tcx10Enabled; /* Flag indicating if TCX 10 can be used */ int16_t tcx20Enabled; /* Flag indicating if TCX 20 can be used */ - float mem_wsp_enc_flt; /* wsp vector memory */ - Word16 mem_wsp_enc; /* wsp vector memory */ + Word16 mem_wsp_enc; /* wsp vector memory */ int16_t nb_bits_header_ace; /* number of bits for the header */ int16_t nb_bits_header_tcx; /* number of bits for the header */ Word16 preemph_fac; /*Preemphasis factor Q15*/ #ifndef IVAS_FLOAT_FIXED + float mem_wsp_enc_flt; /* wsp vector memory */ float preemph_fac_flt; /* Preemphasis factor */ float gamma_flt; #else