From 3d7a3171fedbb7649b2bb5c715d33b92ff56f57d Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 27 Aug 2025 11:33:40 +0200 Subject: [PATCH] remove REUSE_EVS_ACELP_PITCH_NORM_CORR --- lib_enc/acelp_core_switch_enc_fx.c | 23 +-- lib_enc/enc_amr_wb_fx.c | 17 +- lib_enc/enc_gen_voic_fx.c | 24 ++- lib_enc/enc_pit_exc_fx.c | 56 +++--- lib_enc/ivas_td_low_rate_enc_fx.c | 13 +- lib_enc/pit_enc_fx.c | 243 +++++++++++--------------- lib_enc/prot_fx_enc.h | 5 +- lib_enc/transition_enc_fx.c | 263 ++++++++++------------------- 8 files changed, 253 insertions(+), 391 deletions(-) diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index 7ab5492f7..98e56252c 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -400,14 +400,9 @@ static void encod_gen_voic_core_switch_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ - set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */ - pitch = pit_encode_fx( hBstr, - st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - st_fx->element_mode, Q_new -#endif - ); /* Q6 */ + + set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */ + pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/, st_fx->element_mode, Q_new ); /* Q6 */ /*-----------------------------------------------------------------* * Find adaptive exitation @@ -612,14 +607,10 @@ static void encod_gen_voic_core_switch_ivas_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ - set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */ - pitch = pit_encode_fx( hBstr, - st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - st_fx->element_mode, Q_new -#endif - ); /* Q6 */ + + set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */ + pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/, st_fx->element_mode, Q_new ); /* Q6 */ + /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index 395d95bdf..481bc51eb 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -129,6 +129,7 @@ void encod_amr_wb_fx( * target in residual domain "cn" * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ + Copy( &res[i_subfr], &exc[i_subfr], L_SUBFR ); /*Q_new*/ find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, @@ -146,12 +147,7 @@ void encod_amr_wb_fx( *----------------------------------------------------------------*/ *pt_pitch = pit_encode_fx( hBstr, st->acelp_cfg.pitch_bits, st->core_brate, 1, L_FRAME, -1, &pitch_limit_flag, i_subfr, exc, - L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, NULL /*hStereoTD->tdm_Pri_pitch_buf*/ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0, Q_new -#endif - ); + L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, NULL /*hStereoTD->tdm_Pri_pitch_buf*/, 0, Q_new ); /*-----------------------------------------------------------------* * Find adaptive exitation @@ -170,8 +166,7 @@ void encod_amr_wb_fx( * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ - lp_select = lp_filt_exc_enc_fx( MODE1, -1, i_subfr, exc, h1, - xn, y1, xn2, L_SUBFR, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); + lp_select = lp_filt_exc_enc_fx( MODE1, -1, i_subfr, exc, h1, xn, y1, xn2, L_SUBFR, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { @@ -181,13 +176,16 @@ void encod_amr_wb_fx( /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ + inov_encode_fx( st, st->core_brate, 1, L_FRAME, st->last_L_frame, -1, -1, 0, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, L_SUBFR, shift ); + /*-----------------------------------------------------------------* * Gain encoding * Pitch gain clipping test * Estimate spectrum tilt and voicing *-----------------------------------------------------------------*/ + gain_enc_amr_wb_fx( hBstr, xn, shift_wsp, y1, y2, code, st->core_brate, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, hAmrwb_IO->past_qua_en_fx ); @@ -216,9 +214,11 @@ void encod_amr_wb_fx( Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new+15 */ hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ move16(); + /*-----------------------------------------------------------------* * Find the total excitation *-----------------------------------------------------------------*/ + FOR( i = 0; i < L_SUBFR; i++ ) { L_tmp = L_mult( gcode16, code[i] ); /*Q10*/ @@ -233,6 +233,7 @@ void encod_amr_wb_fx( * Synthesize speech to update mem_syn[] * Update A(z) filters *-----------------------------------------------------------------*/ + Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); /*-----------------------------------------------------------------* diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index dba711330..b382ee46d 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -202,6 +202,7 @@ void encod_gen_voic_fx( /* set and write harmonicity flag */ harm_flag_acelp = 0; move16(); + test(); test(); IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) ) @@ -244,12 +245,8 @@ void encod_gen_voic_fx( *----------------------------------------------------------------*/ *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - st_fx->element_mode, Q_new -#endif - ); /* Q6 */ + L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ + tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); /*-----------------------------------------------------------------* @@ -395,6 +392,7 @@ void encod_gen_voic_fx( * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ + FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ @@ -535,7 +533,6 @@ void encod_gen_voic_ivas_fx( L_frame = st_fx->L_frame; move16(); - IF( EQ_16( L_frame, L_FRAME ) ) { T0_max_fx = PIT_MAX; @@ -568,9 +565,11 @@ void encod_gen_voic_ivas_fx( { shift_wsp = sub( shift_wsp, 1 ); } + /* set and write harmonicity flag */ harm_flag_acelp = 0; move16(); + test(); test(); IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) ) @@ -621,12 +620,7 @@ void encod_gen_voic_ivas_fx( *----------------------------------------------------------------*/ *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - st_fx->element_mode, Q_new -#endif - ); /* Q6 */ + L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ move16(); tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); @@ -653,6 +647,7 @@ void encod_gen_voic_ivas_fx( /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ + lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->coder_type, i_subfr_fx, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag ); @@ -683,6 +678,7 @@ void encod_gen_voic_ivas_fx( /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ + IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { gain_enc_lbr_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, @@ -731,7 +727,6 @@ void encod_gen_voic_ivas_fx( * Update memory of the weighting filter *-----------------------------------------------------------------*/ - /*At this point xn has to be in Qnew yn has to be in Qnew @@ -786,6 +781,7 @@ void encod_gen_voic_ivas_fx( * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ + FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index b44592307..da8db9147 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -1,6 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ + #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ @@ -45,6 +46,7 @@ /* RETURN ARGUMENTS : */ /* _ None */ /*=======================================================================*/ + void enc_pit_exc_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 *speech, /* i : Input speech Q_new-1*/ @@ -157,7 +159,6 @@ void enc_pit_exc_fx( } ELSE { - Local_BR = ACELP_7k20; move32(); Pitch_BR = st_fx->core_brate; /* Q0 */ @@ -228,6 +229,7 @@ void enc_pit_exc_fx( /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ + cn = NULL; if ( EQ_16( L_subfr, L_SUBFR ) ) { @@ -239,6 +241,7 @@ void enc_pit_exc_fx( p_Aq = Aq; pt_pitch = pitch_buf; /* pointer to the pitch buffer */ shift_wsp = add( Q_new, shift ); + FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) { @@ -248,6 +251,7 @@ void enc_pit_exc_fx( * target in residual domain "cn" * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ + Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */ /* condition on target (compared to float) has been put outside the loop */ find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, @@ -262,13 +266,10 @@ void enc_pit_exc_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ + *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, - L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - st_fx->element_mode, Q_new -#endif - ); /* Q6 */ + L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ + /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ @@ -286,8 +287,7 @@ void enc_pit_exc_fx( * (No LP filtering of the adaptive excitation) *-----------------------------------------------------------------*/ - lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, - xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ + lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { @@ -320,7 +320,7 @@ void enc_pit_exc_fx( push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 ); } } - else if ( use_fcb == 2 ) + ELSE IF( use_fcb == 2 ) { /*-----------------------------------------------------------------* * Innovation encoding @@ -344,9 +344,11 @@ void enc_pit_exc_fx( inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift ); + /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } @@ -364,9 +366,11 @@ void enc_pit_exc_fx( hLPDmem->tilt_code = 0; move16(); } + /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ + IF( use_fcb != 0 ) { Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ @@ -391,6 +395,7 @@ void enc_pit_exc_fx( * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ + IF( use_fcb != 0 ) { FOR( i = 0; i < L_subfr; i++ ) @@ -525,8 +530,11 @@ void enc_pit_exc_fx( cum_gpit = shl_sat( cum_gpit, 1 ); /*Q15*/ *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/ + + return; } + void enc_pit_exc_ivas_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 *speech, /* i : Input speech Q_new-1*/ @@ -710,11 +718,12 @@ void enc_pit_exc_ivas_fx( /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aw = Aw; + p_Aw = Aw; p_Aq = Aq; pt_pitch = pitch_buf; /* pointer to the pitch buffer */ shift_wsp = add( Q_new, shift ); + FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) { @@ -740,13 +749,10 @@ void enc_pit_exc_ivas_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ + *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, - L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - st_fx->element_mode, Q_new -#endif - ); /* Q6 */ + L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ + Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ /*-----------------------------------------------------------------* @@ -754,6 +760,7 @@ void enc_pit_exc_ivas_fx( *-----------------------------------------------------------------*/ pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder @@ -765,8 +772,9 @@ void enc_pit_exc_ivas_fx( * Codebook target computation * (No LP filtering of the adaptive excitation) *-----------------------------------------------------------------*/ - lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, - xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ + + lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ + IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); @@ -797,7 +805,7 @@ void enc_pit_exc_ivas_fx( push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 ); } } - else if ( use_fcb == 2 ) + ELSE IF( use_fcb == 2 ) { /*-----------------------------------------------------------------* * Innovation encoding @@ -821,12 +829,15 @@ void enc_pit_exc_ivas_fx( inov_encode_ivas_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); + /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, st_fx->L_frame, i_subfr, -1, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } + gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ @@ -841,9 +852,11 @@ void enc_pit_exc_ivas_fx( hLPDmem->tilt_code = 0; move16(); } + /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ + IF( use_fcb != 0 ) { Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); @@ -866,6 +879,7 @@ void enc_pit_exc_ivas_fx( * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ + IF( use_fcb != 0 ) { FOR( i = 0; i < L_subfr; i++ ) @@ -1001,4 +1015,6 @@ void enc_pit_exc_ivas_fx( cum_gpit = shl_sat( cum_gpit, 1 ); /*Q15*/ *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/ + + return; } diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 71b31130a..82bfcbd2f 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -163,6 +163,7 @@ void tdm_low_rate_enc( /*--------------------------------------------------------------------------------------* * Updates *--------------------------------------------------------------------------------------*/ + Copy( exc_wo_nf_fx, exc_fx, L_FRAME ); /* Q_new */ return; @@ -274,12 +275,8 @@ void encod_gen_2sbfr( * Close-loop pitch search on the 1st and 3rd subfr only and quantization * Adaptive exc. construction *------------------------------------------------------------------------*/ - *pt_pitch = pit_encode_fx( st->hBstr, st->acelp_cfg.pitch_bits, st->core_brate, 0, L_frame, coder_type, &pitch_limit_flag, i_subfr, exc, 2 * L_SUBFR, st->pitch, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - st->element_mode, Q_new -#endif - ); + + *pt_pitch = pit_encode_fx( st->hBstr, st->acelp_cfg.pitch_bits, st->core_brate, 0, L_frame, coder_type, &pitch_limit_flag, i_subfr, exc, 2 * L_SUBFR, st->pitch, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st->element_mode, Q_new ); move16(); Scale_sig( h1, 2 * L_SUBFR, sub( 13, q_h1 ) ); // Q13 @@ -297,12 +294,15 @@ void encod_gen_2sbfr( *-----------------------------------------------------------------*/ clip_gain = gp_clip_fx( st->element_mode, st->core_brate, st->voicing_fx, i_subfr, coder_type, xn, st->clip_var_fx, sub( Q_new, 1 ) ); // Q0 + /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ + Scale_sig( h1, 2 * L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ lp_filt_exc_enc_fx( MODE1, coder_type, i_subfr, exc, h1, xn, y1, xn2, 2 * L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &st->acelp_cfg.ltf_mode ); + /* update long-term pitch gain for speech/music classifier */ st->hSpMusClas->lowrate_pitchGain = add( mult( 29491, st->hSpMusClas->lowrate_pitchGain ), mult( 3277 /*Q15*/, gain_pit ) ); // Q14 move16(); @@ -319,6 +319,7 @@ void encod_gen_2sbfr( gain_enc_lbr_fx( st->hBstr, st->acelp_cfg.gains_mode, coder_type, i_subfr, xn, y1, add( sub( Q_new, 1 ), shift ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, st->element_mode ); + IF( st->Opt_SC_VBR ) { if ( EQ_16( st->hSC_VBR->last_ppp_mode, 1 ) ) diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index c62959799..d67ec74eb 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -1,6 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ + #include #include #include "options.h" /* Compilation switches */ @@ -8,7 +9,6 @@ #include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ #include "rom_basop_util.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -54,31 +54,29 @@ static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Wo /* _ None */ /*==============================================================================*/ -Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 pitch_bits[], /* i : pitch bits */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 *pitch, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - const Word16 element_mode, /* i : mode element */ - const Word16 Q_new /* i : scaling factor */ -#endif +/* o : Fractional pitch for each subframe */ +Word16 pit_encode_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 pitch_bits[], /* i : pitch bits */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *exc, /* i/o: pointer to excitation signal frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 *pitch, /* i : open loop pitch estimates in current frame */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ + const Word16 *h1, /* i : weighted filter input response */ + const Word16 *xn, /* i : target vector */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + const Word16 element_mode, /* i : mode element */ + const Word16 Q_new /* i : scaling factor */ ) { Word16 pitch_cl; @@ -115,6 +113,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc /*----------------------------------------------------------------* * Set pit_flag to 0 for every subframe with absolute pitch search *----------------------------------------------------------------*/ + pit_flag = i_subfr; move16(); if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) @@ -128,6 +127,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc * Fractional pitch search * Pitch quantization *-----------------------------------------------------------------*/ + mult_Top = 1; move16(); @@ -179,9 +179,11 @@ Word16 pit_encode_fx( /* o : Fractional pitc move16(); } } + /*-------------------------------------------------------* * Retrieve the number of Q bits *-------------------------------------------------------*/ + nBits = 0; move16(); IF( NE_16( coder_type, AUDIO ) ) @@ -228,13 +230,9 @@ Word16 pit_encode_fx( /* o : Fractional pitc } /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr, element_mode, Q_new ); move16(); + pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16( coder_type, VOICED ) ) @@ -262,23 +260,12 @@ Word16 pit_encode_fx( /* o : Fractional pitc test(); IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 5 ) ) { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_DOUBLEEXTEND_9b, PIT_FR1_DOUBLEEXTEND_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_DOUBLEEXTEND_9b, PIT_FR1_DOUBLEEXTEND_9b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } ELSE IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } @@ -315,21 +302,19 @@ Word16 pit_encode_fx( /* o : Fractional pitc /* pitch lag search limitation */ limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max ); + IF( nBits > 0 ) { /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); + IF( EQ_16( delta, 8 ) ) { *T0_frac = 0; move16(); } + pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE @@ -369,22 +354,12 @@ Word16 pit_encode_fx( /* o : Fractional pitc { IF( *limit_flag == 0 ) { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } ELSE { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN_EXTEND, PIT_FR1_EXTEND_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN_EXTEND, PIT_FR1_EXTEND_8b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } } @@ -392,33 +367,18 @@ Word16 pit_encode_fx( /* o : Fractional pitc { IF( *limit_flag == 0 ) { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } ELSE { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_EXTEND_9b, PIT_FR1_EXTEND_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_EXTEND_9b, PIT_FR1_EXTEND_9b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } } ELSE IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } @@ -429,22 +389,12 @@ Word16 pit_encode_fx( /* o : Fractional pitc test(); IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 6 ) ) { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_FRAME16k, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_FRAME16k, L_SUBFR, element_mode, Q_new ); move16(); } ELSE IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR, element_mode, Q_new ); move16(); } @@ -485,12 +435,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc } /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) @@ -513,12 +458,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc } /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } ELSE @@ -545,12 +485,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc } /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - element_mode, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, element_mode, Q_new ); move16(); } @@ -566,6 +501,8 @@ Word16 pit_encode_fx( /* o : Fractional pitc return pitch_cl; } + + /*-------------------------------------------------------------------* * abs_pit_enc() * @@ -575,11 +512,12 @@ Word16 pit_encode_fx( /* o : Fractional pitc * fr_step = 4: pitch range encoded with 8 bits *-------------------------------------------------------------------*/ -Word16 abs_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac /* i : pitch fraction */ +/* o : pitch index */ +Word16 abs_pit_enc_fx( + const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ + const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac /* i : pitch fraction */ ) { Word16 pitch_index = 0; @@ -764,11 +702,12 @@ Word16 abs_pit_enc_fx( /* o : pitch index * fr_step = 4: resolution 1/4 (frac = 0, 1, 2, or 3) *-------------------------------------------------------------------*/ -Word16 delta_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - const Word16 T0_min /* i : delta search min */ +/* o : pitch index */ +Word16 delta_pit_enc_fx( + const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ + const Word16 T0, /* i : integer pitch lag */ + const Word16 T0_frac, /* i : pitch fraction */ + const Word16 T0_min /* i : delta search min */ ) { Word16 pitch_index = 0; @@ -798,24 +737,22 @@ Word16 delta_pit_enc_fx( /* o : pitch index * Find the closed loop pitch period with 1/4 subsample resolution. *-------------------------------------------------------------------*/ -Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ - const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ - Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ - const Word16 i_subfr, /* i : flag to first subframe */ - const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ - const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ - const Word16 t0_fr1, /* i : minimum value for resolution 1 */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_subfr /* i : size of subframe */ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - const Word16 element_mode, /* i : mode element */ - const Word16 Q_new /* i : scaling factor */ -#endif +/* o : chosen integer pitch lag */ +Word16 pitch_fr4_fx( + const Word16 exc[], /* i : excitation buffer Q_new*/ + const Word16 xn[], /* i : target signal Q_new-1+shift*/ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ + const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ + const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ + Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ + const Word16 i_subfr, /* i : flag to first subframe */ + const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ + const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ + const Word16 t0_fr1, /* i : minimum value for resolution 1 */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_subfr, /* i : size of subframe */ + const Word16 element_mode, /* i : mode element */ + const Word16 Q_new /* i : scaling factor */ ) { Word16 i; @@ -870,16 +807,15 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag t_max = add( t0_max, L_INTERPOL1 ); corr = &corr_v[-t_min]; /* corr[t_min..t_max] */ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR if ( element_mode > EVS_MONO ) { norm_corr_ivas_fx( exc, xn, h, t_min, t_max, corr, L_subfr, Q_new ); } else -#endif { norm_corr_fx( exc, xn, h, t_min, t_max, corr, L_subfr ); } + /*-----------------------------------------------------------------* * Find integer pitch *-----------------------------------------------------------------*/ @@ -1000,6 +936,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag return ( t0 ); } + /*-------------------------------------------------------------------* * norm_corr() * @@ -1008,6 +945,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag * excitation divided by the square root of energy of filtered * excitation) *---------------------------------------------------------------------*/ + void norm_corr_ivas_fx( const Word16 exc[], /* i : excitation buffer Q_new */ const Word16 xn[], /* i : target signal Q_new-1 */ @@ -1033,6 +971,7 @@ void norm_corr_ivas_fx( k = negate( t_min ); h_e = add( 1, norm_s( h[0] ) ); // exponent of h + /*-----------------------------------------------------------------* * compute the filtered excitation for the first delay t_min *-----------------------------------------------------------------*/ @@ -1202,6 +1141,7 @@ void norm_corr_fx( return; } + /*-------------------------------------------------------------------* * pit_Q_enc() * @@ -1218,7 +1158,7 @@ void pit_Q_enc_fx( const Word16 T0, /* i : integer pitch lag */ const Word16 T0_frac, /* i : pitch fraction */ Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max_val */ + Word16 *T0_max /* o : delta search max_val */ ) { Word16 pitch_index; @@ -1300,6 +1240,8 @@ void pit_Q_enc_fx( return; } + + /*-------------------------------------------------------------------* * pit16k_Q_enc() * @@ -1307,13 +1249,13 @@ void pit_Q_enc_fx( *-------------------------------------------------------------------*/ void pit16k_Q_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 nBits, /* i : # of Q bits */ const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ const Word16 T0, /* i : integer pitch lag */ const Word16 T0_frac, /* i : pitch fraction */ Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max_val */ + Word16 *T0_max /* o : delta search max_val */ ) { Word16 pitch_index; @@ -1377,12 +1319,15 @@ void pit16k_Q_enc_fx( return; } + + /*------------------------------------------------------------------* * pit_encode: * * Close-loop pitch lag search and pitch lag quantization * Adaptive excitation construction *------------------------------------------------------------------*/ + void Mode2_pit_encode_fx( const Word16 coder_type, /* i : coding model */ const Word16 i_subfr, /* i : subframe index */ @@ -1423,6 +1368,7 @@ void Mode2_pit_encode_fx( * - Fractional pitch search * - Pitch quantization *-----------------------------------------------------------------*/ + IF( coder_type == 0 ) /*Unvoiced Coding do nothing*/ { *T0 = L_SUBFR; @@ -1592,6 +1538,7 @@ void Mode2_pit_encode_fx( return; } + static void limit_T0_voiced2( Word16 res, const Word16 *T_op, @@ -1706,8 +1653,11 @@ static void limit_T0_voiced2( *T0_min_frac = sub( temp1, i_mult2( temp2, res ) ); move16(); } + + return; } + /*-------------------------------------------------------------------* * abs_pit_enc: * @@ -1745,6 +1695,8 @@ void Mode2_abs_pit_enc_fx( } ( *pt_indice )++; + + return; } @@ -1764,8 +1716,9 @@ void Mode2_delta_pit_enc_fx( ) { /***pt_indice = (T0 - T0_min) * T0_res + T0_frac - T0_min_frac;*/ - **pt_indice = add( i_mult2( sub( T0, T0_min ), T0_res ), sub( T0_frac, T0_min_frac ) ); move16(); ( *pt_indice )++; + + return; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 5e2e14447..28389e9e0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -984,12 +984,11 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag const Word16 t0_fr1, /* i : minimum value for resolution 1 */ const Word16 L_frame, /* i : length of the frame */ const Word16 L_subfr /* i : size of subframe */ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR , const Word16 element_mode, /* i : mode element */ const Word16 Q_new /* i : scaling factor */ -#endif ); + void pit_Q_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ @@ -3372,11 +3371,9 @@ Word16 pit_encode_fx( /* o : Fractional pitc const Word16 *xn, /* i : target vector */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR , const Word16 element_mode, /* i : mode element */ const Word16 Q_new /* i : scaling factor */ -#endif ); Word16 lp_filt_exc_enc_fx( diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 8ed4b2fa8..1d2250526 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -120,6 +120,7 @@ void transition_enc_fx( lp_flag = st_fx->acelp_cfg.ltf_mode; move16(); + /*-----------------------------------------------------------------* * TC: subrame determination for glottal shape search * ------------------------------------------------------- @@ -152,9 +153,11 @@ void transition_enc_fx( limit_T0_fx( st_fx->L_frame, 8, 0, limit_flag, mult_Top * T_op[1], 0, T0_min, T0_max ); } + /*-----------------------------------------------------------------* * zero adaptive excitation signal construction *-----------------------------------------------------------------*/ + IF( GT_16( *tc_subfr, i_subfr ) ) { *gain_pit_fx = 0; @@ -232,6 +235,7 @@ void transition_enc_fx( * in the 1st subframe and the second one in 2nd subframe * and later *--------------------------------------------------------------*/ + ELSE IF( LT_16( *tc_subfr, i_subfr ) ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -265,6 +269,7 @@ void transition_enc_fx( * if tc_subfr==0, change tc_subfr corresponding to the * second glot. impulse position *----------------------------------------------------------*/ + test(); IF( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) { @@ -282,13 +287,7 @@ void transition_enc_fx( pit_limit = add( shl( pit_start, 1 ), *position ); /* Find the closed loop pitch period */ - - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -340,6 +339,7 @@ void transition_enc_fx( /*-----------------------------------------------------------------* * Find adaptive part of excitation, encode pitch period *-----------------------------------------------------------------*/ + test(); test(); test(); @@ -353,6 +353,7 @@ void transition_enc_fx( * second glottal impulse is in the 3rd or 4th subframe * - build exc[] in 2nd subframe *--------------------------------------------------------*/ + *T0 = 2 * L_SUBFR; move16(); *T0_frac = 0; @@ -369,6 +370,7 @@ void transition_enc_fx( * - build exc[] in 2nd subframe *--------------------------------------------------------*/ + IF( LT_16( add( *T0, *position ), L_SUBFR ) ) { /* impulse must be in the 2nd subframe (not in 1st) */ @@ -396,7 +398,6 @@ void transition_enc_fx( /* Find the adaptive codebook vector - ACELP long-term prediction */ pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) @@ -416,12 +417,7 @@ void transition_enc_fx( pit_flag = 0; move16(); - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); IF( LT_16( add( ( *T0 ), ( *position ) ), 2 * L_SUBFR ) ) @@ -480,16 +476,12 @@ void transition_enc_fx( * second glottal impulse is in the 4th subframe * - build exc[] in 4th subframe *--------------------------------------------------------*/ + /* always T0_frac = 0 */ pit_flag = 0; move16(); - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); IF( LT_16( add( *T0, *position ), 3 * L_SUBFR ) ) @@ -533,14 +525,10 @@ void transition_enc_fx( * second glottal impulse in the 3rd subframe * build exc[] in 4th subframe *--------------------------------------------------------*/ + pit_flag = L_SUBFR; move16(); - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); index = delta_pit_enc_fx( 2, *T0, *T0_frac, *T0_min ); push_indice( hBstr, IND_PITCH, index, nBits ); @@ -562,6 +550,7 @@ void transition_enc_fx( * first glottal impulse is NOT in the 1st subframe, * or two impulses are in the 1st subframe *------------------------------------------------------------*/ + ELSE { test(); @@ -571,23 +560,13 @@ void transition_enc_fx( test(); IF( !( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } } ELSE { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } pit_Q_enc_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -609,6 +588,7 @@ void transition_enc_fx( * - LP filtering of the adaptive excitation (if non-zero) * - codebook target computation *-----------------------------------------------------------------*/ + IF( *Jopt_flag == 0 ) { /* adaptive/TC excitation is zero */ @@ -640,9 +620,11 @@ void transition_enc_fx( **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); move16(); + /*---------------------------------------------------------------------* * fill the pitch buffer - needed for post-processing *---------------------------------------------------------------------*/ + test(); test(); test(); @@ -730,6 +712,7 @@ void transition_enc_fx( limit_flag = 1; move16(); } + IF( LE_16( i_subfr, 2 * L_SUBFR ) ) { IF( LT_16( i_subfr, 2 * L_SUBFR ) ) @@ -763,12 +746,7 @@ void transition_enc_fx( IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); pit16k_Q_enc_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } @@ -779,12 +757,8 @@ void transition_enc_fx( * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) *-----------------------------------------------------------------------------*/ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); IF( GT_16( *T0_max, 2 * L_SUBFR ) ) @@ -810,12 +784,7 @@ void transition_enc_fx( ELSE IF( EQ_16( nBits, 6 ) ) { /* delta search */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); @@ -831,6 +800,7 @@ void transition_enc_fx( * - LP filtering of the adaptive excitation * - codebook target computation *-----------------------------------------------------------------*/ + test(); IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *T0, 2 * L_SUBFR ) ) ) { @@ -897,6 +867,7 @@ void transition_enc_fx( /*---------------------------------------------------------------------* * fill the pitch buffer - needed for post-processing *---------------------------------------------------------------------*/ + test(); test(); IF( ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) || ( *tc_subfr == 0 && EQ_16( i_subfr, 2 * L_SUBFR ) ) ) @@ -943,7 +914,6 @@ void transition_enc_ivas_fx( Word16 *unbits_ACELP, /* i/o: unused bits */ Word16 Q_new, /* i : Current scaling */ Word16 shift /* i : downscaling needs for 12 bits convolutions */ - ) { Word16 pit_flag, pit_start, pit_limit, index, nBits; @@ -981,6 +951,7 @@ void transition_enc_ivas_fx( lp_flag = st_fx->acelp_cfg.ltf_mode; move16(); + /*-----------------------------------------------------------------* * TC: subrame determination for glottal shape search * ------------------------------------------------------- @@ -1013,9 +984,11 @@ void transition_enc_ivas_fx( limit_T0_fx( st_fx->L_frame, 8, 0, limit_flag, mult_Top * T_op[1], 0, T0_min, T0_max ); } + /*-----------------------------------------------------------------* * zero adaptive excitation signal construction *-----------------------------------------------------------------*/ + IF( GT_16( *tc_subfr, i_subfr ) ) { *gain_pit_fx = 0; @@ -1056,6 +1029,7 @@ void transition_enc_ivas_fx( /*-----------------------------------------------------------------* * glottal codebook contribution construction *-----------------------------------------------------------------*/ + ELSE IF( EQ_16( *tc_subfr, i_subfr ) ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -1093,6 +1067,7 @@ void transition_enc_ivas_fx( * in the 1st subframe and the second one in 2nd subframe * and later *--------------------------------------------------------------*/ + ELSE IF( LT_16( *tc_subfr, i_subfr ) ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -1126,6 +1101,7 @@ void transition_enc_ivas_fx( * if tc_subfr==0, change tc_subfr corresponding to the * second glot. impulse position *----------------------------------------------------------*/ + test(); IF( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) { @@ -1143,25 +1119,17 @@ void transition_enc_ivas_fx( pit_limit = add( shl( pit_start, 1 ), *position ); /* Find the closed loop pitch period */ - - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; move16(); } - test(); IF( GT_16( ( *T0 ), sub( 2 * L_SUBFR, ( *position ) ) ) ) { @@ -1201,6 +1169,7 @@ void transition_enc_ivas_fx( /*-----------------------------------------------------------------* * Find adaptive part of excitation, encode pitch period *-----------------------------------------------------------------*/ + test(); test(); test(); @@ -1214,6 +1183,7 @@ void transition_enc_ivas_fx( * second glottal impulse is in the 3rd or 4th subframe * - build exc[] in 2nd subframe *--------------------------------------------------------*/ + *T0 = 2 * L_SUBFR; move16(); *T0_frac = 0; @@ -1228,8 +1198,8 @@ void transition_enc_ivas_fx( /*--------------------------------------------------------* * second glottal impulse is in the 2nd subframe, * - build exc[] in 2nd subframe + *--------------------------------------------------------*/ - *--------------------------------------------------------*/ IF( LT_16( add( *T0, *position ), L_SUBFR ) ) { /* impulse must be in the 2nd subframe (not in 1st) */ @@ -1277,12 +1247,7 @@ void transition_enc_ivas_fx( pit_flag = 0; move16(); - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); IF( LT_16( add( ( *T0 ), ( *position ) ), 2 * L_SUBFR ) ) @@ -1326,6 +1291,7 @@ void transition_enc_ivas_fx( * second glottal impulse is in the 4th subframe * - build exc[] in 3rd subframe *--------------------------------------------------------*/ + *T0 = 4 * L_SUBFR; move16(); *T0_frac = 0; @@ -1341,16 +1307,12 @@ void transition_enc_ivas_fx( * second glottal impulse is in the 4th subframe * - build exc[] in 4th subframe *--------------------------------------------------------*/ + /* always T0_frac = 0 */ pit_flag = 0; move16(); - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); IF( LT_16( add( *T0, *position ), 3 * L_SUBFR ) ) @@ -1394,15 +1356,11 @@ void transition_enc_ivas_fx( * second glottal impulse in the 3rd subframe * build exc[] in 4th subframe *--------------------------------------------------------*/ + pit_flag = L_SUBFR; move16(); - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); index = delta_pit_enc_fx( 2, *T0, *T0_frac, *T0_min ); push_indice( hBstr, IND_PITCH, index, nBits ); @@ -1412,7 +1370,6 @@ void transition_enc_ivas_fx( offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; @@ -1424,6 +1381,7 @@ void transition_enc_ivas_fx( * first glottal impulse is NOT in the 1st subframe, * or two impulses are in the 1st subframe *------------------------------------------------------------*/ + ELSE { test(); @@ -1432,23 +1390,13 @@ void transition_enc_ivas_fx( test(); IF( !( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } } ELSE { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } pit_Q_enc_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -1469,6 +1417,7 @@ void transition_enc_ivas_fx( * - LP filtering of the adaptive excitation (if non-zero) * - codebook target computation *-----------------------------------------------------------------*/ + IF( *Jopt_flag == 0 ) { /* adaptive/TC excitation is zero */ @@ -1499,9 +1448,11 @@ void transition_enc_ivas_fx( **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); move16(); + /*---------------------------------------------------------------------* * fill the pitch buffer - needed for post-processing *---------------------------------------------------------------------*/ + test(); test(); test(); @@ -1622,12 +1573,7 @@ void transition_enc_ivas_fx( IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); pit16k_Q_enc_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } @@ -1638,12 +1584,8 @@ void transition_enc_ivas_fx( * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) *-----------------------------------------------------------------------------*/ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); IF( GT_16( *T0_max, 2 * L_SUBFR ) ) @@ -1669,17 +1611,13 @@ void transition_enc_ivas_fx( ELSE IF( EQ_16( nBits, 6 ) ) { /* delta search */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); push_indice( hBstr, IND_PITCH, index, nBits ); } + IF( EQ_16( nBits, 6 ) ) { limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -1781,6 +1719,7 @@ void transition_enc_ivas_fx( return; } + /*-------------------------------------------------------------------------------------------* * tc_enc() * @@ -1851,32 +1790,17 @@ static void tc_enc_fx( { IF( EQ_16( nBits, 9 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } ELSE { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } } @@ -1885,6 +1809,7 @@ static void tc_enc_fx( *T0 = L_SUBFR; move16(); } + test(); if ( EQ_16( *tc_subfr, L_SUBFR ) && LT_16( *T0, L_SUBFR ) ) { @@ -1896,23 +1821,13 @@ static void tc_enc_fx( { IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { /* T0_frac with 1/2 sample resolution */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); IF( *T0 > L_SUBFR ) { @@ -1924,7 +1839,6 @@ static void tc_enc_fx( } } - /* set tc_subfr to TC_0_0 */ test(); test(); @@ -1949,6 +1863,7 @@ static void tc_enc_fx( /* set past excitation buffer to zeros */ set16_fx( exc_fx - L_EXC_MEM, 0, L_EXC_MEM ); + /*--------------------------------------------------------------* * adapt. search of the second impulse in the same subframe * (when appears) @@ -1966,6 +1881,7 @@ static void tc_enc_fx( interp_code_4over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR ); } } + /*--------------------------------------------------------------* * compute glottal-shape codebook excitation *--------------------------------------------------------------*/ @@ -1976,9 +1892,11 @@ static void tc_enc_fx( /* gain_pit computation */ *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0, &Overflow ); move16(); + /*--------------------------------------------------------------* * Encode parameters and write indices *--------------------------------------------------------------*/ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { test(); @@ -2032,6 +1950,7 @@ static void tc_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); } } + push_indice( hBstr, IND_TC_IMP_SHAPE, imp_shape, 3 ); push_indice( hBstr, IND_TC_IMP_POS, imp_pos, 6 ); push_indice( hBstr, IND_TC_IMP_SIGN, pitch_sign_fx, 1 ); @@ -2039,9 +1958,11 @@ static void tc_enc_fx( *position = add( imp_pos, i_subfr ); move16(); + return; } + static void tc_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 i_subfr, /* i : subrame index */ @@ -2093,32 +2014,17 @@ static void tc_enc_ivas_fx( { IF( EQ_16( nBits, 9 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } ELSE { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } } @@ -2127,6 +2033,7 @@ static void tc_enc_ivas_fx( *T0 = L_SUBFR; move16(); } + test(); if ( EQ_16( *tc_subfr, L_SUBFR ) && LT_16( *T0, L_SUBFR ) ) { @@ -2138,23 +2045,15 @@ static void tc_enc_ivas_fx( { IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { /* T0_frac with 1/2 sample resolution */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR -#if !defined REUSE_EVS_ACELP_PITCH_NORM_CORR - , - 0 /*st_fx->element_mode*/, Q_new -#endif - ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); + move16(); + IF( *T0 > L_SUBFR ) { *T0 = L_SUBFR; @@ -2165,7 +2064,6 @@ static void tc_enc_ivas_fx( } } - /* set tc_subfr to TC_0_0 */ test(); test(); @@ -2190,12 +2088,14 @@ static void tc_enc_ivas_fx( /* set past excitation buffer to zeros */ set16_fx( exc_fx - L_EXC_MEM, 0, L_EXC_MEM ); + /*--------------------------------------------------------------* * adapt. search of the second impulse in the same subframe * (when appears) *--------------------------------------------------------------*/ pred_lt4_tc_fx( exc_fx, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); + IF( st_fx->hBWE_TD != NULL ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -2207,9 +2107,11 @@ static void tc_enc_ivas_fx( interp_code_4over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR ); } } + /*--------------------------------------------------------------* * compute glottal-shape codebook excitation *--------------------------------------------------------------*/ + Copy( h1, h1_fx, L_SUBFR + ( M + 1 ) ); /* create filtered glottal codebook contribution */ conv_fx( &exc_fx[i_subfr], h1_fx, yy1_fx, L_SUBFR ); @@ -2217,6 +2119,7 @@ static void tc_enc_ivas_fx( /* gain_pit computation */ *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0, &Overflow ); move16(); + /*--------------------------------------------------------------* * Encode parameters and write indices *--------------------------------------------------------------*/ @@ -2291,6 +2194,7 @@ static void tc_enc_ivas_fx( * - Uses scalar quantization prototypes tbl_gain_trans_tc[N_GAIN_TC]. * - Gains the glottal codebook contibution signal. *-----------------------------------------------------------------*/ + static void gain_trans_enc_fx( Word32 gain_trans32, /* i : gain for mode Tc Q7 */ Word16 exc[], /* i/o: glottal codebook contribution i:Q13 o:Q_new*gain_trans */ @@ -2351,6 +2255,8 @@ static void gain_trans_enc_fx( exc[i] = round_fx_o( L_shl_o( L_mult( exc[i], gain_trans ), tmp16, &Overflow ), &Overflow ); move16(); } + + return; } @@ -2359,6 +2265,7 @@ static void gain_trans_enc_fx( * * TC subframe determination *-----------------------------------------------------------------*/ + void tc_classif_enc_fx( const Word16 Q_new, /* i : scaling factor */ const Word16 L_frame, /* i : length of the frame */ -- GitLab