diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 790d5c479b0d07e1a8d05d2866e0b0da82521fca..0fb526b416bbd40436673f52ff7700c207024964 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5856,7 +5856,11 @@ ivas_error ivas_mct_enc_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ); +#ifdef FIX_2344_ALIGN_PREPROC +void ivas_compute_core_buffers_fx( +#else ivas_error ivas_compute_core_buffers_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame */ Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz */ @@ -5870,7 +5874,7 @@ ivas_error ivas_compute_core_buffers_fx( Word32 epsP[M + 1], /* i/o: LP prediction errors */ Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ - Word16 Q_old_inp_16k, + const Word16 Q_old_inp_16k, Word16 Q_r[2], Word16 *Q_new ); @@ -5961,7 +5965,11 @@ void ivas_mct_enc_close_fx( MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ ); +#ifdef FIX_2344_ALIGN_PREPROC +void pre_proc_front_ivas_fx( +#else ivas_error pre_proc_front_ivas_fx( +#endif SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ @@ -6017,7 +6025,11 @@ ivas_error pre_proc_front_ivas_fx( Word16 *Q_new /* i/o : Q factor of speech buffers */ ); +#ifdef FIX_2344_ALIGN_PREPROC +void pre_proc_ivas_fx( +#else ivas_error pre_proc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 last_element_mode, /* i : last element mode Q0*/ const Word32 element_brate, /* i : element bitrate Q0*/ @@ -6046,7 +6058,7 @@ ivas_error pre_proc_ivas_fx( const Word16 e_enerBuffer, /* i : Q value of energy buffer */ Word16 fft_buff_fx[2 * L_FFT], /* i : FFT buffer Qx*/ const Word16 cor_map_sum_fx, /* i : speech/music clasif. parameter Q8*/ - Word16 *Q_new /* i/o : Q factor of speech buffers */ + Word16 *Q_new /* i/o: Q factor of speech buffers */ ); void ivas_initialize_handles_enc_fx( diff --git a/lib_com/options.h b/lib_com/options.h index 19a85a6200a33f2294b629b502f5e0d692264146..bdfe15ec6035c49c9a58aab0d1b3f7b417877dca 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -103,6 +103,7 @@ #define HARM_CORE_SW /* VA: basop issue 2314: Remove duplicated code in the core switching */ #define HARM_PREPROC /* VA: basop issue 2339: Remove duplicated code in the core-coder DTX */ #define HARM_NON_LINEARITY /* VA: basop issue 2345: Remove duplicated code in core-coder: non_linearity_fx() and LP CNG */ +#define FIX_2344_ALIGN_PREPROC /* VA: basop issue 2344: Align pre_proc_ivas() between FLP and BASOP */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 5810358c0db87a00677096df00fd2834b983fefd..206a3e25c23622cb34e84e559e6df7580d19032f 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -230,6 +230,20 @@ ivas_error ivas_core_enc_fx( #endif Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } + +#ifdef FIX_2344_ALIGN_PREPROC + Word32 last_element_brate_tmp = element_brate; + move32(); + IF( EQ_32( ivas_format, SBA_FORMAT ) ) + { + last_element_brate_tmp = last_element_brate; + move32(); + } + + pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate_tmp, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, + &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], + vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ); +#else IF( EQ_32( ivas_format, SBA_FORMAT ) ) { IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, @@ -250,6 +264,8 @@ ivas_error ivas_core_enc_fx( return error; } } +#endif + test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, IVAS_SCE ) ) { @@ -744,16 +760,22 @@ ivas_error ivas_core_enc_fx( Word16 Q_shb_spch_16 = Q_shb_spch; move16(); - shift = add( getScaleFactor16( shb_speech_fx, L_FRAME16k ), Q16 ); - Copy_Scale_sig_16_32_no_sat( shb_speech_fx, shb_speech_fx32, L_FRAME16k, shift ); // Q_shb_spch - Q_shb_spch = add( Q_shb_spch, shift ); - - IF( st->hBWE_FD ) +#ifdef FIX_2344_ALIGN_PREPROC + IF( st->tcxonly == 0 || hStereoICBWE != NULL || st->core == ACELP_CORE ) // temp. fix to keep BE until #1504 (FLP) is solved, then it will become: + // IF( st->tcxonly == 0 ) +#endif { - shift = getScaleFactor16( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k ); - st->Q_old_wtda = add( st->Q_old_wtda, shift ); - move16(); - Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, shift ); // st->Q_old_wtda + shift = add( getScaleFactor16( shb_speech_fx, L_FRAME16k ), Q16 ); + Copy_Scale_sig_16_32_no_sat( shb_speech_fx, shb_speech_fx32, L_FRAME16k, shift ); // Q_shb_spch + Q_shb_spch = add( Q_shb_spch, shift ); + + IF( st->hBWE_FD ) + { + shift = getScaleFactor16( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k ); + st->Q_old_wtda = add( st->Q_old_wtda, shift ); + move16(); + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, shift ); // st->Q_old_wtda + } } /* SWB TBE encoder */ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index dd9af7647ee2eb66ae1a9ba1804419680f966c1f..8090f9ede348e15a35784acfb5830f7c4548d9f8 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -76,7 +76,11 @@ static Word16 get_zero_flag( const Word32 arr[], const Word16 len ) * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) *--------------------------------------------------------------------*/ +#ifdef FIX_2344_ALIGN_PREPROC +void pre_proc_front_ivas_fx( +#else ivas_error pre_proc_front_ivas_fx( +#endif SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ @@ -157,7 +161,9 @@ ivas_error pre_proc_front_ivas_fx( STEREO_CLASSIF_HANDLE hStereoClassif; Word16 old_pitch1; /* previous frame OL pitch[1] @12.8 kHz */ Word16 LR_localVAD; +#ifndef FIX_2344_ALIGN_PREPROC ivas_error error; +#endif Word16 *signal_in_fx; Word32 *signal32_in_fx; Word16 *inp_12k8_fx, *new_inp_12k8_fx; /* pointers to current frame and new data */ @@ -167,7 +173,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 mem_decim_dummy_fx[2 * L_FILT_MAX]; /* dummy decimation filter memory */ #else Word16 *temp1F_icatdmResampBuf_fx; - Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ #endif Word32 tmpF_fx[STEREO_DFT_BAND_MAX]; Word32 *res_cod_SNR_M_fx; @@ -225,21 +231,30 @@ ivas_error pre_proc_front_ivas_fx( Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; Word16 Q_inp_const = -1; move16(); +#ifdef FIX_2344_ALIGN_PREPROC + Word16 headroom, preemp_len, inp_max; +#else Word16 headroom = 0, preemp_len = 0, inp_max = 0; move16(); move16(); move16(); +#endif Word16 *preemp_start_idx = NULL; +#ifdef FIX_2344_ALIGN_PREPROC + Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k /* = max( L_FRAME16k + STEREO_DFT_OVL_16k, L_FRAME16k + L_FILT16k + lMemRecalc_16k ) */], max_32; +#else Word32 sig_out[960], max_32; +#endif push_wmops( "pre_proc_front" ); /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ +#ifndef FIX_2344_ALIGN_PREPROC error = IVAS_ERR_OK; move32(); - +#endif cldfbScale.lb_scale = Q31; cldfbScale.hb_scale = Q31; move16(); @@ -544,12 +559,17 @@ ivas_error pre_proc_front_ivas_fx( * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ +#ifndef FIX_2344_ALIGN_PREPROC *Q_new = 0; move16(); set32_fx( sig_out, 0, 960 ); - +#endif headroom = 2; move16(); +#ifdef FIX_2344_ALIGN_PREPROC + preemp_len = 0; + move16(); +#endif st->mem_preemph_fx_q_inp = shl_sat( st->mem_preemph_fx_q_inp, sub( st->q_inp, st->mem_preemph_q ) ); /*st->q_inp*/ move16(); @@ -636,6 +656,7 @@ ivas_error pre_proc_front_ivas_fx( preemp_len = L_FRAME + L_FILT; move16(); } + st->mem_preemph_fx = shl_sat( st->mem_preemph_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1) saturation added as float value goes above 65536 for +10 dB test (ltv48_MC512.wav and ltv48_MC51.wav) */ move16(); st->mem_preemph_DFT_fx = shl_sat( st->mem_preemph_DFT_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1)*/ @@ -1329,12 +1350,11 @@ ivas_error pre_proc_front_ivas_fx( * 1st stage speech/music classification (GMM model) *----------------------------------------------------------------*/ - SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; shift = getScaleFactor32( PS_fx, 128 ); scale_sig32( PS_fx, 128, shift ); Qfact_PS = add( Qfact_PS, shift ); - smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, extract_h( Etot_fx ), lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, hSpMusClas->past_PS_Q ); /* Q0 */ + smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, extract_h( Etot_fx ), lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, st->hSpMusClas->past_PS_Q ); /* Q0 */ #ifdef DEBUGGING if ( st->idchan == 0 ) @@ -1476,11 +1496,15 @@ ivas_error pre_proc_front_ivas_fx( move16(); /* Compute core-coder buffers at internal sampling rate */ +#ifdef FIX_2344_ALIGN_PREPROC + 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, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); +#else 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, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } +#endif *epsP_fx_q = add( Q_r[0], 1 ); move16(); @@ -1571,7 +1595,11 @@ ivas_error pre_proc_front_ivas_fx( free( temp1F_icatdmResampBuf_fx ); #endif pop_wmops(); +#ifdef FIX_2344_ALIGN_PREPROC + return; +#else return error; +#endif } diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index a72585986d6ff608ce13b6ed03991da2fcfee7ce..a6e8966dfaf831234a15545dc2d098db9b1823ca 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -46,7 +46,11 @@ * Decision matrix, Preprocessing at other Fs, core switching decision, ...) *--------------------------------------------------------------------*/ +#ifdef FIX_2344_ALIGN_PREPROC +void pre_proc_ivas_fx( +#else ivas_error pre_proc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 last_element_mode, /* i : last element mode Q0*/ const Word32 element_brate, /* i : element bitrate Q0*/ @@ -75,20 +79,23 @@ ivas_error pre_proc_ivas_fx( const Word16 e_enerBuffer, /* i : Q value of energy buffer */ Word16 fft_buff_fx[2 * L_FFT], /* i : FFT buffer Qx*/ const Word16 cor_map_sum_fx, /* i : speech/music clasif. parameter Q8*/ - Word16 *Q_new /* i/o : Q factor of speech buffers */ + Word16 *Q_new /* i/o: Q factor of speech buffers */ ) { Word16 L_look, element_mode, lMemRecalc_12k8; Word16 *inp_16k_fx, *new_inp_12k8_fx, *inp_12k8_fx; /* pointers to current frame and new data */ Word16 *wsp_fx; /* weighted input signal buffer */ Word32 sr_core_tmp, total_brate_tmp; +#ifndef FIX_2344_ALIGN_PREPROC ivas_error error; +#endif push_wmops( "pre_proc" ); +#ifndef FIX_2344_ALIGN_PREPROC error = IVAS_ERR_OK; move32(); - +#endif /*----------------------------------------------------------------* * Initialization *----------------------------------------------------------------*/ @@ -166,6 +173,26 @@ ivas_error pre_proc_ivas_fx( move16(); } +#ifdef FIX_2344_ALIGN_PREPROC + IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + total_brate_tmp = ACELP_16k40; + move16(); + } + ELSE + { + total_brate_tmp = ACELP_9k60; + move16(); + } + + test(); + test(); + test(); + IF( st->hFdCngEnc != NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) && ( ( NE_16( st->hFdCngEnc->hFdCngCom->frameSize, st->L_frame ) ) || ( NE_16( st->hFdCngEnc->hFdCngCom->CngBandwidth, st->input_bwidth ) ) ) ) + { + configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate_tmp ); + } +#else test(); test(); test(); @@ -185,6 +212,7 @@ ivas_error pre_proc_ivas_fx( { configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), flag_1 ); } +#endif if ( st->ini_frame == 0 ) { @@ -227,6 +255,7 @@ ivas_error pre_proc_ivas_fx( * IC frames selection * enforce TC frames in case of switching *-----------------------------------------------------------------*/ + test(); test(); test(); @@ -287,7 +316,6 @@ ivas_error pre_proc_ivas_fx( move16(); } - /*---------------------------------------------------------------------* * Decision matrix (selection of technologies) *---------------------------------------------------------------------*/ @@ -308,6 +336,7 @@ ivas_error pre_proc_ivas_fx( /* core selection */ ivas_decision_matrix_enc_fx( st, element_brate, fft_buff_fx, enerBuffer_fx, e_enerBuffer, last_element_mode ); + test(); test(); if ( EQ_16( st->L_frame, L_FRAME16k ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, UNVOICED ) ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ @@ -399,14 +428,14 @@ ivas_error pre_proc_ivas_fx( } } - /*-----------------------------------------------------------------* * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) *-----------------------------------------------------------------*/ + test(); test(); test(); - IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << 8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) + IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << Q8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) { st->last_harm_flag_acelp = add( st->last_harm_flag_acelp, 1 ); /* Q0 */ move16(); @@ -474,6 +503,7 @@ ivas_error pre_proc_ivas_fx( } } +#ifndef FIX_2344_ALIGN_PREPROC /* channel-aware mode - due to lack of signaling bit, sharpFlag is 1 always in RF mode */ test(); test(); @@ -482,7 +512,7 @@ ivas_error pre_proc_ivas_fx( st->sharpFlag = 1; move16(); } - +#endif /* TD stereo, secondary channel - due to lack of signaling bits, sharpFlag is always 1 */ test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) @@ -517,6 +547,7 @@ ivas_error pre_proc_ivas_fx( /*-----------------------------------------------------------------* * Compute core-coder buffers at internal sampling rate *-----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) { sr_core_tmp = INT_FS_16k; @@ -570,16 +601,29 @@ ivas_error pre_proc_ivas_fx( move16(); st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k ); move16(); +#ifndef FIX_2344_ALIGN_PREPROC Word16 Q_inp_12k8 = *Q_new; move16(); Word16 Q_inp_16k = *Q_new; move16(); +#endif + IF( !flag_16k_smc ) { +#ifdef FIX_2344_ALIGN_PREPROC + Word16 Q_inp_12k8 = *Q_new; + move16(); + Word16 Q_inp_16k; + + 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, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, &Q_inp_16k ); +#else 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, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, &Q_inp_16k ); + +#endif + IF( GT_16( Q_inp_16k, Q_inp_12k8 ) ) { Scale_sig( old_inp_16k_fx, L_INP, sub( Q_inp_12k8, Q_inp_16k ) ); @@ -592,11 +636,12 @@ ivas_error pre_proc_ivas_fx( } move16(); +#ifndef FIX_2344_ALIGN_PREPROC IF( error != IVAS_ERR_OK ) { return error; } - +#endif test(); IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -604,6 +649,7 @@ ivas_error pre_proc_ivas_fx( move16(); } } + test(); IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) ) { @@ -681,15 +727,25 @@ ivas_error pre_proc_ivas_fx( } pop_wmops(); +#ifdef FIX_2344_ALIGN_PREPROC + return; +#else return error; +#endif } + /*-------------------------------------------------------------------* * ivas_compute_core_buffers() * * Compute core-coder buffers at internal sampling rate *--------------------------------------------------------------------*/ + +#ifdef FIX_2344_ALIGN_PREPROC +void ivas_compute_core_buffers_fx( +#else ivas_error ivas_compute_core_buffers_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame Q_new-1*/ Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz Q_new-1*/ @@ -703,7 +759,7 @@ ivas_error ivas_compute_core_buffers_fx( Word32 epsP_fx[M + 1], /* i/o: LP prediction errors Q_r*/ Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ - Word16 Q_old_inp_16k, + const Word16 Q_old_inp_16k, Word16 Q_r[2], Word16 *Q_new ) { @@ -719,19 +775,28 @@ ivas_error ivas_compute_core_buffers_fx( Word16 Q_tmp, mem_decim16k_size, size_modified; Word16 epsP_h[M + 1]; Word16 epsP_l[M + 1]; - +#ifdef FIX_2344_ALIGN_PREPROC + Word16 i, shift, Q_min; + Word16 preemp_len, inp_max; +#else Word16 headroom = 1, preemp_len = 0, inp_max = 0; move16(); move16(); move16(); +#endif Word16 *preemp_start_idx = NULL; +#ifdef FIX_2344_ALIGN_PREPROC + Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k /* = max( L_FRAME16k + STEREO_DFT_OVL_16k, L_FRAME16k + L_FILT16k + lMemRecalc_16k ) */], max_32; +#else Word32 sig_out[960], max_32; - /*Word16 Q_exp, Q_wsp_exp*/; +#endif + +#ifndef FIX_2344_ALIGN_PREPROC set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); set16_fx( epsP_h, 0, M + 1 ); set16_fx( epsP_l, 0, M + 1 ); set16_fx( input_buf_fx, 0, L_FRAME48k * 2 ); - +#endif Copy_Scale_sig( st->input_fx - input_frame, input_buf_fx, input_frame, sub( -1, st->q_old_inp ) ); Copy_Scale_sig( st->input_fx, input_buf_fx + input_frame, input_frame, sub( -1, st->q_inp ) ); @@ -757,9 +822,9 @@ ivas_error ivas_compute_core_buffers_fx( /*---------------------------------------------------------------* * Preprocessing at other sampling frequency rate (16/25.6/32kHz) *----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) { - L_frame_tmp = L_FRAME16k; move16(); } @@ -848,14 +913,23 @@ ivas_error ivas_compute_core_buffers_fx( Scale_sig( new_inp_16k_fx - lMemRecalc_16k - length_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } - size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ - Scale_sig( new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#ifdef FIX_2344_ALIGN_PREPROC + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - lMemRecalc_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx - lMemRecalc_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#else + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#endif Copy( st->mem_decim16k_fx, mem_decim16k_dummy_fx, 2 * L_FILT_MAX ); IF( lMemRecalc > 0 ) { +#ifdef FIX_2344_ALIGN_PREPROC + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - lMemRecalc_16k, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - lMemRecalc_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#else size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ - Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#endif } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); @@ -939,6 +1013,10 @@ ivas_error ivas_compute_core_buffers_fx( move16(); } +#ifdef FIX_2344_ALIGN_PREPROC + *Q_new = 0; + move16(); +#else test(); test(); @@ -951,10 +1029,22 @@ ivas_error ivas_compute_core_buffers_fx( { headroom = add( headroom, 1 ); } + +#endif + test(); +#ifdef FIX_2344_ALIGN_PREPROC + IF( EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) +#else test(); IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) +#endif { +#ifdef FIX_2344_ALIGN_PREPROC + preemp_len = 0; + move16(); +#endif + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching Q(-1) */ @@ -1040,8 +1130,12 @@ ivas_error ivas_compute_core_buffers_fx( maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); inp_max = s_max( extract_h( max_32 ), 1 ); +#ifdef FIX_2344_ALIGN_PREPROC + shift = sub( norm_s( inp_max ), 1 /* headroom */ ); +#else Word16 shift = sub( norm_s( inp_max ), headroom ); Word16 Q_min, i; +#endif shift = s_max( shift, 0 ); shift = s_min( shift, Q_MAX ); minimum_fx( st->Q_max_16k, L_Q_MEM, &Q_min ); @@ -1066,8 +1160,13 @@ ivas_error ivas_compute_core_buffers_fx( Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, add( *Q_new, 1 ) ); Scale_sig( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ), *Q_new ); } +#ifdef FIX_2344_ALIGN_PREPROC + ELSE /* keep memory up-to-date in case of bitrate switching */ +#else ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */ +#endif { +#ifndef FIX_2344_ALIGN_PREPROC IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; /* Q_new - 1 */ @@ -1078,7 +1177,9 @@ ivas_error ivas_compute_core_buffers_fx( st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; /* Q_new - 1 */ move16(); } - ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + ELSE +#endif + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { st->mem_preemph16k_fx = 0; move16(); @@ -1101,7 +1202,9 @@ ivas_error ivas_compute_core_buffers_fx( IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { /* update signal buffers */ +#ifndef FIX_2344_ALIGN_PREPROC Word16 shift; +#endif shift = negate( *Q_new ); move16(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) @@ -1137,6 +1240,14 @@ ivas_error ivas_compute_core_buffers_fx( analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, -1, Q_r ); } +#ifdef FIX_2344_ALIGN_PREPROC + FOR( i = 0; i < M + 1; i++ ) + { + epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); + move32(); + } + +#endif /*--------------------------------------------------------------* * Compute Weighted Input *---------------------------------------------------------------*/ @@ -1151,20 +1262,30 @@ ivas_error ivas_compute_core_buffers_fx( /* update old input signal @16kHz buffer */ test(); test(); +#ifndef FIX_2344_ALIGN_PREPROC test(); +#endif IF( ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); st->exp_old_inp_16k = 0; move16(); } +#ifdef FIX_2344_ALIGN_PREPROC + ELSE IF( EQ_32( sr_core, INT_FS_16k ) ) +#else ELSE IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) ) +#endif { Copy( &old_inp_16k_fx[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM ); st->exp_old_inp_16k = sub( Q16, *Q_new ); //(*Q_new - 1) move16(); } +#ifdef FIX_2344_ALIGN_PREPROC + ELSE +#else ELSE IF( GT_32( input_Fs, 8000 ) ) +#endif { lerp( st->old_inp_12k8_fx + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM * 4 / 5 ); Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) ); @@ -1181,6 +1302,8 @@ ivas_error ivas_compute_core_buffers_fx( { Copy( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k ); } + +#ifndef FIX_2344_ALIGN_PREPROC test(); IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -1190,6 +1313,8 @@ ivas_error ivas_compute_core_buffers_fx( move32(); } } - return IVAS_ERR_OK; +#else + return; +#endif } diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 718316e4abb172f6e4ed4bf00b900607678f1641..f81c6d7ad0740ab902851a72502b81977d16bdbb 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -947,16 +947,23 @@ ivas_error ivas_cpe_enc_fx( { front_vad_flag = 0; } + move16(); + +#ifndef FIX_2344_ALIGN_PREPROC + error = +#endif + pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_16k_16fx[n], + &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], + realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], + fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD, + band_energies_LR_fx, q_band_energies_LR, 0, front_vad_flag, 0, 0, ivas_format, st_ivas->hMCT != NULL, st_ivas->hEncoderConfig->last_ivas_total_brate, ivas_total_brate, &Q_new[n] ); - error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_16k_16fx[n], - &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], - realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], - fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD, - band_energies_LR_fx, q_band_energies_LR, 0, front_vad_flag, 0, 0, ivas_format, st_ivas->hMCT != NULL, st_ivas->hEncoderConfig->last_ivas_total_brate, ivas_total_brate, &Q_new[n] ); +#ifndef FIX_2344_ALIGN_PREPROC IF( error != IVAS_ERR_OK ) { return error; } +#endif e_old_wsp[n] = sub( Q15, q_old_wsp ); move16(); } diff --git a/lib_enc/ivas_ism_enc_fx.c b/lib_enc/ivas_ism_enc_fx.c index a157749c45f260fd68b285aa0f5c906e4b2d6ef4..eb8271bfd9d85a1136b0e10227c78c4a86757be2 100644 --- a/lib_enc/ivas_ism_enc_fx.c +++ b/lib_enc/ivas_ism_enc_fx.c @@ -244,19 +244,26 @@ ivas_error ivas_ism_enc_fx( Scale_sig( &A_fx[sce_id][0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[sce_id][0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } #endif + set16_fx( old_wsp_fx[sce_id][0], 0, L_WSP ); q_old_wsp = Q15; move16(); Word16 q_fr_bands[2]; - error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0], - &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], - realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], - fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0] ); +#ifndef FIX_2344_ALIGN_PREPROC + error = +#endif + pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0], + &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], + realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], + fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0] ); +#ifndef FIX_2344_ALIGN_PREPROC IF( error != IVAS_ERR_OK ) { return error; } +#endif + e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp ); move16(); diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index dd07017e59ebef377810b3651c41da872fd57580..091dce1481502274fd42996968cfe05364739ce6 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -251,6 +251,30 @@ ivas_error ivas_sce_enc_fx( move16(); Word16 q_fr_bands[2]; +#ifdef FIX_2344_ALIGN_PREPROC + Word16 front_vad_flag, force_front_vad, front_vad_dtx_flag; + IF( st_ivas->hSpar != NULL ) + { + front_vad_flag = st_ivas->hSpar->front_vad_flag; + force_front_vad = st_ivas->hSpar->force_front_vad; + front_vad_dtx_flag = st_ivas->hSpar->front_vad_dtx_flag; + } + ELSE + { + front_vad_flag = 0; + force_front_vad = 0; + front_vad_dtx_flag = 0; + } + move16(); + move16(); + move16(); + + pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_16k_fx[0], + &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], + realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], + fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc, + front_vad_flag, force_front_vad, front_vad_dtx_flag, ivas_format, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0] ); +#else error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_16k_fx[0], &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], @@ -260,6 +284,7 @@ ivas_error ivas_sce_enc_fx( { return error; } +#endif e_old_wsp[0] = sub( Q15, q_old_wsp ); move16();