From 832751e64a46f710d9c53d326d0b75994b6ce0e1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 26 Feb 2025 12:41:22 +0530 Subject: [PATCH 1/2] Modifications in acelp encode sub-function call stack, bug fixes and saturation removal in GenShapedSHBExcitation_enc --- lib_com/prot_fx.h | 45 +++--- lib_com/swb_tbe_com_fx.c | 213 ++++++++++++----------------- lib_enc/acelp_core_switch_enc_fx.c | 10 +- lib_enc/analy_sp_fx.c | 46 +++---- lib_enc/core_enc_init.c | 22 ++- lib_enc/core_enc_reconf.c | 7 +- lib_enc/core_enc_switch.c | 2 +- lib_enc/enc_gen_voic_fx.c | 16 +-- lib_enc/enc_pit_exc_fx.c | 14 +- lib_enc/enc_tran_fx.c | 5 +- lib_enc/enc_uv_fx.c | 10 +- lib_enc/find_tar_fx.c | 82 +++++------ lib_enc/ivas_td_low_rate_enc.c | 17 ++- lib_enc/multi_harm_fx.c | 2 +- lib_enc/pit_enc_fx.c | 176 ++++++++++++------------ lib_enc/prot_fx_enc.h | 135 +++++++++--------- lib_enc/swb_tbe_enc_fx.c | 14 +- 17 files changed, 385 insertions(+), 431 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index cf7072cf5..485ddb33d 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3035,7 +3035,7 @@ void GenShapedSHBExcitation_fx( void GenShapedSHBExcitation_ivas_enc_fx( Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc_fb */ Word32 *mem_csfilt, /* i/o: memory */ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ @@ -3051,33 +3051,30 @@ void GenShapedSHBExcitation_ivas_enc_fx( Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, - const Word16 prev_bfi -#if 1 // def ADD_IVAS_TBE_CODE - , /* i : previous frame was concealed */ - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16 *nlExc16k_e, /* i/o: exp of nlExc16k */ - Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ - Word16 *mixExc16k_e, /* i/o: exp of mixExc16k_fx */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + const Word16 prev_bfi, + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *nlExc16k_e, /* i/o: exp of nlExc16k */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + Word16 *mixExc16k_e, /* i/o: exp of mixExc16k_fx */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ Word16 Q_EnvSHBres_4k, - Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ - Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ - Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ - Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ -#endif + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ ); void GenShapedSHBExcitation_ivas_dec_fx( @@ -11113,7 +11110,7 @@ void init_coder_ace_plus_ivas_fx( ); void core_coder_reconfig_ivas_fx( - Encoder_State *st ); + Encoder_State *st, const int32_t last_total_brate ); void core_coder_mode_switch_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 92271c1f1..6cdf1185a 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -2879,7 +2879,7 @@ void GenShapedSHBExcitation_fx( void GenShapedSHBExcitation_ivas_enc_fx( Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc_fb */ Word32 *mem_csfilt, /* i/o: memory */ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ @@ -2901,24 +2901,24 @@ void GenShapedSHBExcitation_ivas_enc_fx( Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ - const Word32 bitrate, /* i : bitrate */ - const Word16 prev_bfi, /* i : previous frame was concealed */ - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16 *nlExc16k_e, /* i/o: exp of nlExc16k */ - Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ - Word16 *mixExc16k_e, /* i/o: exp of mixExc16k_fx */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + const Word32 bitrate, + const Word16 prev_bfi, + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *nlExc16k_e, /* i/o: exp of nlExc16k */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + Word16 *mixExc16k_e, /* i/o: exp of mixExc16k_fx */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ Word16 Q_EnvSHBres_4k, - Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ - Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ - Word16 *Env_error, /* o : error in SHB residual envelope modelling Q0 */ - Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling Q0 */ + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ ) { Word16 i, j, k; @@ -2963,13 +2963,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( Word32 White_exc16k_32[L_FRAME16k]; Word16 White_exc16k_tmp[L_FRAME16k]; Word16 prev_Q_bwe_exc_fb; - Word16 chk1, chk2; - chk1 = 0; - chk2 = 0; - move16(); - move16(); -#if 1 // def ADD_IVAS_TBE_CODE Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; Word16 cbsize; Word16 mix_factor, old_fact, new_fact, fact, old_scale, new_scale, step_scale; @@ -2984,7 +2978,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( mix_factor = 0; /* Q15 */ move16(); -#endif + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); FOR( i = 0; i < L_FRAME32k; i = i + 2 ) @@ -3016,11 +3010,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( /* i: exc16k in Q_bwe_exc */ /* o: exc16kWhtnd in Q_bwe_exc */ -#if 1 // def ADD_IVAS_TBE_CODE IF( GE_32( extl_brate, SWB_TBE_2k8 ) ) -#else - IF( GE_32( bitrate, ACELP_24k40 ) ) -#endif { temp2 = 0; move16(); @@ -3041,25 +3031,21 @@ void GenShapedSHBExcitation_ivas_enc_fx( /* Estimate pow1 associated with Low band nonlinear extended excitation */ /* pow1=0.00001f */ tmp = sub( shl( *Q_bwe_exc, 1 ), 31 ); - pow1 = L_shl_sat( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ + W_tmp = W_shl( 21475 /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ FOR( k = 0; k < L_FRAME16k; k++ ) { /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ excTmp2[k] = abs_s( exc16kWhtnd[k] ); move16(); - chk1 = s_or( chk1, exc16kWhtnd[k] ); /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ - pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ + W_tmp = W_mac_16_16( W_tmp, exc16kWhtnd[k], exc16kWhtnd[k] ); // 2*Q_bwe_exc+1 } - Q_pow1 = shl( *Q_bwe_exc, 1 ); + exp = W_norm( W_tmp ); + pow1 = W_extract_h( W_shl( W_tmp, exp ) ); // 2*Q_bwe_exc+1+exp-32 = // tmp+exp + Q_pow1 = add( tmp, exp ); - test(); -#if 1 // ADD_IVAS_TBE_CODE IF( flag_ACELP16k == 0 ) -#else - IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) ) -#endif { /* varEnvShape = mean_fx(voice_factors, 4); */ /* unroll the loop */ @@ -3105,12 +3091,8 @@ void GenShapedSHBExcitation_ivas_enc_fx( test(); test(); test(); -#if 1 // def ADD_IVAS_TBE_CODE test(); IF( EQ_16( element_mode, EVS_MONO ) && *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) -#else - IF( *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) -#endif { /* pre-init smoothing filter to avoid energy drop outs */ L_tmp = L_mult( excTmp2[0], 1638 ); @@ -3137,7 +3119,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( *mem_csfilt = Mult_32_16( L_tmp, varEnvShape ); move32(); } -#if 1 // def ADD_IVAS_TBE_CODE + IF( MSFlag > 0 ) { // varEnvShape = 0.995f; @@ -3196,7 +3178,6 @@ void GenShapedSHBExcitation_ivas_enc_fx( } } ELSE -#endif { /* Track the low band envelope */ L_tmp = L_shl( *mem_csfilt, sub( Q_excTmp2, *Q_bwe_exc ) ); @@ -3222,7 +3203,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( *mem_csfilt = L_shr( L_tmp, sub( Q_excTmp2, *Q_bwe_exc ) ); move32(); } -#if 1 // def ADD_IVAS_TBE_CODE + test(); IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) { @@ -3261,7 +3242,6 @@ void GenShapedSHBExcitation_ivas_enc_fx( } } ELSE -#endif { /* create a random excitation - Reuse exc16k memory */ create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); // Q5 @@ -3282,36 +3262,32 @@ void GenShapedSHBExcitation_ivas_enc_fx( /* calculate pow22 */ /* pow22=0.00001f */ tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); - Word64 sum = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ + W_tmp = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ Q_White_exc16k = getScaleFactor32( White_exc16k_32, L_FRAME16k ); FOR( k = 0; k < L_FRAME16k; k++ ) { /* White_exc16k[k] *= excNoisyEnv[k]; */ White_exc16k[k] = extract_h( L_shl( White_exc16k_32[k], Q_White_exc16k ) ); // Q_excTmp2 + 6 + Q_White_exc16k - 16 ==> Q_excTmp2 + Q_White_exc16k - 10 move16(); - chk2 = s_or( chk2, White_exc16k[k] ); /* i: excNoisyEnv in (Q_excTmp2) */ /* i: White_exc16k in Q6 */ /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ + /* pow22 += White_exc16k[k] * White_exc16k[k]; */ - sum = W_mac0_16_16( sum, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2 + Q_White_exc16k - 10)*/ + W_tmp = W_mac0_16_16( W_tmp, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2 + Q_White_exc16k - 10)*/ } - Q_pow22 = W_norm( sum ); - pow22 = W_extract_h( W_shl( sum, Q_pow22 ) ); // 2*(Q_excTmp2 + Q_White_exc16k - 10)+Q_pow22-32 + Q_pow22 = W_norm( W_tmp ); + pow22 = W_extract_h( W_shl( W_tmp, Q_pow22 ) ); // 2*(Q_excTmp2 + Q_White_exc16k - 10)+Q_pow22-32 Q_pow22 = sub( add( Q_pow22, shl( sub( add( Q_White_exc16k, Q_excTmp2 ), 10 ), 1 ) ), 32 ); Q_White_exc16k = add( Q_White_exc16k, sub( Q_excTmp2, 10 ) ); } -#if 1 // def ADD_IVAS_TBE_CODE flag_plosive = 0; move16(); test(); test(); test(); IF( GE_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) -#else - IF( GE_32( bitrate, ACELP_24k40 ) ) -#endif { IF( EQ_16( *vf_ind, 20 ) ) /* encoder side */ { @@ -3545,7 +3521,6 @@ void GenShapedSHBExcitation_ivas_enc_fx( ELSE /* decoder side */ { test(); -#if 1 // def ADD_IVAS_TBE_CODE IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) { IF( *vf_ind == 0 ) @@ -3563,7 +3538,6 @@ void GenShapedSHBExcitation_ivas_enc_fx( } } ELSE -#endif { /* *vf_ind is an integer scale by 0.125f*/ tmp = shl( *vf_ind, ( 15 - 3 ) ); @@ -3576,10 +3550,9 @@ void GenShapedSHBExcitation_ivas_enc_fx( } } } -#if 1 // def ADD_IVAS_TBE_CODE + test(); IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) -#endif { voice_factors[0] = mult_r( voice_factors[0], tmp2 ); move16(); @@ -3593,103 +3566,94 @@ void GenShapedSHBExcitation_ivas_enc_fx( move16(); } } -#if 1 // def ADD_IVAS_TBE_CODE - Scale_sig( White_exc16k, L_FRAME16k, sub( *Q_bwe_exc, Q_White_exc16k ) ); // Q_bwe_exc + test(); IF( GE_16( element_mode, IVAS_CPE_DFT ) && nlExc16k != NULL ) { /* save buffers for IC-BWE */ // mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); - Copy( exc16kWhtnd, nlExc16k, L_FRAME16k ); + Copy( exc16kWhtnd, nlExc16k, L_FRAME16k ); // Q_bwe_exc *nlExc16k_e = sub( 15, *Q_bwe_exc ); move16(); + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); - /*Word16 temp_fac = divide3232(L_shr(pow1, Q_pow1), pow22); - Word16 temp_fac_exp = 0; - temp_fac = Sqrt16(temp_fac, &temp_fac_exp);*/ L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); - Word16 temp_fac = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 - // v_multc_fixed_16_16(White_exc16k,shr(temp_fac, temp_fac_exp) , mixExc16k, L_FRAME16k); + Word16 temp_fac = round_fx_sat( L_tmp ); // Q15-exp + FOR( k = 0; k < L_FRAME16k; k++ ) { - mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); // Q_bwe_exc + mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); // Q_White_exc16k+15-exp-15 = Q_White_exc16k-exp move16(); } - *mixExc16k_e = sub( 15, *Q_bwe_exc ); + *mixExc16k_e = sub( 15, sub( Q_White_exc16k, exp ) ); move16(); } -#endif - FOR( k = 0; k < L_FRAME16k; k++ ) - { - White_exc16k_FB[k] = White_exc16k[k]; /* Q_bwe_exc */ - move16(); - } + Copy( White_exc16k, White_exc16k_FB, L_FRAME16k ); // Q_White_exc16k prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; + *Q_bwe_exc_fb = Q_White_exc16k; move16(); - *Q_bwe_exc_fb = *Q_bwe_exc; move16(); - deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); - /* i/o: White_exc16k (Q_bwe_exc) */ - /* i: tbe_demph (Q_bwe_exc) */ + Word16 tbe_demph_fx = shl_sat( *tbe_demph, sub( Q_White_exc16k, *Q_bwe_exc ) ); // Q_White_exc16k + + deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, &tbe_demph_fx ); + /* i/o: White_exc16k (Q_White_exc16k) */ + /* i: tbe_demph_fx (Q_White_exc16k) */ + *tbe_demph = shr_sat( tbe_demph_fx, sub( Q_White_exc16k, *Q_bwe_exc ) ); + move16(); -#if 1 // def ADD_IVAS_TBE_CODE test(); IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) { IF( !flag_plosive ) /* use only LB excitation in case of plosives */ { /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */ - // old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1); - // old_scale = divide3232(*prev_pow_exc16kWhtnd, pow1); // exp = Q15 - (Q_pow1) - // Word16 old_scale_exp = Q15 - (Q_pow1); - // old_scale = Sqrt16(old_scale, &old_scale_exp); - // old_scale = shl(old_scale, old_scale_exp); //Q15 - L_tmp = root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ); - IF( exp < 0 ) - { - L_tmp = L_shl( L_tmp, exp ); - exp = 0; - move16(); - } - old_scale = round_fx_sat( L_tmp ); // exp + /* old_scale = (float) sqrt( *prev_pow_exc16kWhtnd / pow1 ); */ + old_scale = round_fx_sat( root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ) ); // exp + old_scale = shl( old_scale, s_min( 0, exp ) ); // limit Q factor to 15 + exp = s_max( 0, exp ); + // new_scale = 1.0f; new_scale = shr( 32767, exp ); // exp + // step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); step_scale = mult_r( sub( new_scale, old_scale ), 205 ); // exp scale = old_scale; // exp move16(); + /* interpolate between the old and the new value of the mixing factor */ old_fact = *prev_mix_factor; // Q15 + new_fact = mix_factor; // Q15 move16(); - new_fact = mix_factor; // Q15 move16(); + // step = (new_fact - old_fact) / (L_FRAME16k / 2); step = mult_r( sub( new_fact, old_fact ), 205 ); // Q15 fact = old_fact; // Q15 move16(); + + shift = add( exp, sub( *Q_bwe_exc, Q_White_exc16k ) ); + /* mixing of LB and gaussian excitation in the first half of the frame */ FOR( k = 0; k < L_FRAME16k / 2; k++ ) { - // exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; - // exc16kWhtnd[k] = add(mult_r(fact, mult(shl(White_exc16k[k], *Q_bwe_exc), scale)), mult_r(sub(32767, fact), exc16kWhtnd[k])); - L_tmp = L_add_sat( L_shl_sat( L_mult( fact, mult_r( White_exc16k[k], scale ) ), exp ), // Q15 + Q_bwe_exc + (Q15-exp) - Q15 + exp + Q1 - L_mult( sub( 32767, fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc + Q16 - exc16kWhtnd[k] = round_fx_sat( L_tmp ); // Q_bwe_exc + /* exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; */ + L_tmp = L_shl_sat( L_mult( fact, mult_r( White_exc16k[k], scale ) ), shift ); // Q_bwe_exc+16 + exc16kWhtnd[k] = mac_r_sat( L_tmp, sub( 32767, fact ), exc16kWhtnd[k] ); // Q_bwe_exc move16(); + fact = add_sat( fact, step ); // Q15 scale = add_sat( scale, step_scale ); // exp } + shift = sub( *Q_bwe_exc, Q_White_exc16k ); /* mixing of LB and gaussian excitation in the second half of the frame */ FOR( ; k < L_FRAME16k; k++ ) { // exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; - // exc16kWhtnd[k] = add(mult_r(new_fact, shl(White_exc16k[k], *Q_bwe_exc)), mult_r(sub(32767, new_fact), exc16kWhtnd[k])); - L_tmp = L_add( L_mult( new_fact, White_exc16k[k] ), - mult_r( sub( 32767, new_fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc + Q15 + Q1 => Q_bwe_exc + Q16 - exc16kWhtnd[k] = round_fx( L_tmp ); // Q_bwe_exc + L_tmp = L_shl_sat( L_mult( new_fact, White_exc16k[k] ), shift ); // Q_bwe_exc+16 + exc16kWhtnd[k] = mac_r( L_tmp, sub( 32767, new_fact ), exc16kWhtnd[k] ); // Q_bwe_exc move16(); } } @@ -3697,32 +3661,28 @@ void GenShapedSHBExcitation_ivas_enc_fx( PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc } ELSE -#endif { -#if 1 // def ADD_IVAS_TBE_CODE test(); IF( EQ_16( coder_type, UNVOICED ) || EQ_16( MSFlag, 1 ) ) -#else - IF( EQ_16( coder_type, UNVOICED ) ) -#endif { - L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + scale = 0; + move16(); + test(); - if ( chk1 == 0 && chk2 == 0 ) + IF( pow1 != 0 && pow22 != 0 ) { - L_tmp = 0; - move32(); + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ } - scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ + FOR( k = 0; k < L_FRAME16k; k++ ) { - /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ - L_tmp = L_mult( White_exc16k[k], scale ); // Q_bwe_exc + Q15 + Q1 => Q_bwe_exc + Q16 - /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx_sat( L_tmp ); // Q_bwe_exc + exc16kWhtnd[k] = mult_r_sat( White_exc16k[k], scale ); // Q_White_exc16k move16(); - /* exc16kWhtnd: Q_bwe_exc */ } + + Scale_sig( exc16kWhtnd, L_FRAME16k, sub( *Q_bwe_exc, Q_White_exc16k ) ); // Q_bwe_exc + PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc /* i/o: exc16kWhtnd (Q_bwe_exc) */ /* i/o: tbe_premph (Q_bwe_exc) */ @@ -3785,13 +3745,13 @@ void GenShapedSHBExcitation_ivas_enc_fx( temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ } + shift = sub( *Q_bwe_exc, Q_White_exc16k ); FOR( j = 0; j < lSubFr; j++ ) { /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ - L_tmp = L_mult( temp2, White_exc16k[k + j] ); /* 16+(Q_bwe_exc)*/ + L_tmp = L_shl_sat( L_mult( temp2, White_exc16k[k + j] ), shift ); // 16+(Q_bwe_exc) exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); // Q_bwe_exc move16(); - /* Q_bwe_exc */ } k = add( k, lSubFr ); @@ -3813,11 +3773,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( } } -#if 1 // def ADD_IVAS_TBE_CODE IF( LT_32( extl_brate, SWB_TBE_2k8 ) ) -#else - IF( LT_32( bitrate, ACELP_24k40 ) ) -#endif { syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); /* i: exc16kWhtnd in Q_bwe_exc */ @@ -3928,8 +3884,8 @@ void GenShapedSHBExcitation_ivas_enc_fx( Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); Scale_sig( fb_tbe_demph, 1, tmp ); syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); - /* i: White_exc16k_FB in (14-n2) */ - /* o: White_exc16k_FB_temp in (14-n2) */ + /* i: White_exc16k_FB in (Q_bwe_exc_fb) */ + /* o: White_exc16k_FB_temp in (Q_bwe_exc_fb) */ FOR( i = 0; i < 10; i++ ) { @@ -3951,10 +3907,11 @@ void GenShapedSHBExcitation_ivas_enc_fx( set16_fx( White_exc16k_FB, 0, L_FRAME16k ); } -#if 1 // def ADD_IVAS_TBE_CODE *prev_pow_exc16kWhtnd = L_shr_sat( pow1, Q_pow1 ); // power goes above MAX_32 *prev_mix_factor = mix_factor; -#endif + move32(); + move16(); + return; } diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index 47c735a85..8268d48b1 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -570,6 +570,7 @@ static void encod_gen_voic_core_switch_ivas_fx( Word16 h2[L_SUBFR + ( M + 1 )]; Word16 dummyF[NB_SUBFR16k]; Word16 lp_select, lp_flag; + Word16 q_h1; LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ BSTR_ENC_HANDLE hBstr; @@ -634,9 +635,8 @@ static void encod_gen_voic_core_switch_ivas_fx( find_targets_ivas_fx( inp, hLPDmem->mem_syn, 0, &( hLPDmem->mem_w0 ), Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn, h1 ); } - /*Scale_sig(h1, L_SUBFR, shift); */ /*Q14-shift */ - Copy_Scale_sig( h1, h2, L_SUBFR, -2 ); - Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + q_h1 = sub( 14, norm_s( h1[0] ) ); + Copy_Scale_sig( h1, h2, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_SUBFR, shift ); /* Q_new */ @@ -646,8 +646,9 @@ static void encod_gen_voic_core_switch_ivas_fx( * Adaptive exc. construction *----------------------------------------------------------------*/ set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */ + pitch = pit_encode_ivas_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*/ ); /* Q6 */ + 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*/, Q_new ); /* Q6 */ /*-----------------------------------------------------------------* * Find adaptive exitation @@ -666,6 +667,7 @@ static void encod_gen_voic_core_switch_ivas_fx( * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */ + Scale_sig( h1, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14+shift*/ lp_select = lp_filt_exc_enc_ivas_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index c0d1a8bca..d5333ae13 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -445,29 +445,29 @@ static void find_enr_dft_ivas_fx( * Spectral analysis of 12.8kHz input *-------------------------------------------------------------------*/ void ivas_analy_sp_fx( - const Word16 element_mode, /* i : element mode Q0*/ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 input_Fs, /* i : input sampling rate Q0*/ - Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ - const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands q_fr_bands */ - Word16 *q_fr_bands, /* o : energy in critical frequency bands Q0 */ - Word32 *lf_E, /* o : per bin E for first... q_lf_E */ - Word16 *q_lf_E, /* o : per bin E for first... Q0 */ - Word16 *Etot, /* o : total input energy Q8 */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ - Word16 *q_Bin_E, /* o : per-bin energy spectrum Q7 */ - Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ - Word16 *q_Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ - Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE - 2 */ - Word16 *q_PS, /* o : per-bin energy spectrum Q_new + QSCALE - 2 */ - Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (q_band_energies)*/ - Word16 *q_band_energies, /* o : Q of energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ - Word16 *fft_buff, /* o : FFT coefficients (q_fft_buff) */ - Word16 *q_fft_buff /* o : Q of FFT coefficients Q0 */ + const Word16 element_mode, /* i : element mode Q0 */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 input_Fs, /* i : input sampling rate Q0 */ + Word16 *speech, /* i : speech buffer Q_new */ + const Word16 Q_new, /* i : current scaling exp Q0 */ + Word32 *fr_bands, /* o : energy in critical frequency bands q_fr_bands */ + Word16 *q_fr_bands, /* o : energy in critical frequency bands Q0 */ + Word32 *lf_E, /* o : per bin E for first... q_lf_E */ + Word16 *q_lf_E, /* o : per bin E for first... Q0 */ + Word16 *Etot, /* o : total input energy Q8 */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + Word32 *Bin_E, /* o : per-bin energy spectrum q_Bin_E */ + Word16 *q_Bin_E, /* o : per-bin energy spectrum Q0 */ + Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame q_Bin_E_old */ + Word16 *q_Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q0 */ + Word32 *PS, /* o : per-bin energy spectrum q_PS */ + Word16 *q_PS, /* o : per-bin energy spectrum Q0 */ + Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (q_band_energies) */ + Word16 *q_band_energies, /* o : Q of energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ + Word16 *fft_buff, /* o : FFT coefficients (q_fft_buff) */ + Word16 *q_fft_buff /* o : Q of FFT coefficients Q0 */ ) { Word16 *pt; diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index e98956efe..74f73bf52 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -53,8 +53,8 @@ static void init_tcx_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag ); static void init_core_sig_ana_ivas_fx( Encoder_State *st ); static void init_modes_ivas_fx( Encoder_State *st, const Word32 last_total_brate ); -static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr ); -static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift ); +static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate); +static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate); /*-----------------------------------------------------------------------* * init_coder_ace_plus() * @@ -223,11 +223,11 @@ void init_coder_ace_plus_ivas_fx( } /* Initialize Signal Buffers */ - init_sig_buffers_ivas_fx( st, L_frame_old, L_subfr ); + init_sig_buffers_ivas_fx( st, L_frame_old, L_subfr, last_total_brate); /* Initialize ACELP */ - init_acelp_ivas_fx( st, L_frame_old, 0 ); + init_acelp_ivas_fx( st, L_frame_old, 0, last_total_brate); if ( st->ini_frame == 0 ) { @@ -442,7 +442,7 @@ static void init_tcx_ivas_fx( * Initialization of signal buffers *-----------------------------------------------------------------------*/ /*copy of evs function since it was static */ -static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr ) +static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate) { LPD_state_HANDLE hLPDmem = st->hLPDmem; @@ -478,7 +478,7 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol test(); test(); test(); - IF( NE_16( st->L_frame, L_frame_old ) && !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, st->last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) + IF( NE_16( st->L_frame, L_frame_old ) && !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) { lerp( st->buf_speech_enc, st->buf_speech_enc, st->L_frame, L_frame_old ); test(); @@ -530,7 +530,7 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol move16(); } /*coming from TCXonly modes*/ - ELSE IF( !st->tcxonly && GE_32( st->last_total_brate, ACELP_32k ) ) + ELSE IF( !st->tcxonly && GE_32(last_total_brate, ACELP_32k ) ) { Copy( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM ); @@ -647,7 +647,7 @@ static void init_core_sig_ana_ivas_fx( Encoder_State *st ) * * *-----------------------------------------------------------------------*/ -static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift ) +static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate) { Word16 mem_syn_r_size_old; Word16 mem_syn_r_size_new; @@ -753,7 +753,7 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh test(); test(); test(); - IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, st->last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) + IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) { Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ IF( EQ_16( st->L_frame, L_FRAME16k ) ) @@ -959,8 +959,6 @@ static void init_modes_ivas_fx( Word8 n; Word32 tmp32; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - (void) last_total_brate; - /* Restrict ACE/TCX20/TCX10 mode */ move16(); @@ -1050,7 +1048,7 @@ static void init_modes_ivas_fx( } /* Reconfigure core */ - core_coder_reconfig_ivas_fx( st ); + core_coder_reconfig_ivas_fx( st, last_total_brate); return; diff --git a/lib_enc/core_enc_reconf.c b/lib_enc/core_enc_reconf.c index 24729c124..890194966 100644 --- a/lib_enc/core_enc_reconf.c +++ b/lib_enc/core_enc_reconf.c @@ -49,7 +49,8 @@ *-----------------------------------------------------------------*/ void core_coder_reconfig_ivas_fx( - Encoder_State *st ) + Encoder_State *st, + const int32_t last_total_brate ) { Word16 i, bwidth, index; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; @@ -324,7 +325,7 @@ void core_coder_reconfig_ivas_fx( test(); test(); test(); - IF( ( LT_32( st->total_brate, ACELP_24k40 ) ) && ( ( GT_32( st->total_brate, st->last_total_brate ) ) || ( EQ_16( st->last_codec_mode, MODE1 ) ) ) ) + IF( ( LT_32( st->total_brate, ACELP_24k40 ) ) && ( ( GT_32( st->total_brate, last_total_brate ) ) || ( EQ_16( st->last_codec_mode, MODE1 ) ) ) ) { /* low-freq memQuantZeros_fx must be reset partially if bitrate increased */ FOR( i = 0; i < hTcxEnc->nmStartLine; i++ ) @@ -333,7 +334,7 @@ void core_coder_reconfig_ivas_fx( move16(); } } - ELSE IF( ( GE_32( st->total_brate, ACELP_24k40 ) ) && ( LE_32( st->total_brate, ACELP_32k ) ) && ( GE_32( st->last_total_brate, ACELP_13k20 ) ) && ( LT_32( st->last_total_brate, ACELP_24k40 ) ) ) + ELSE IF( ( GE_32( st->total_brate, ACELP_24k40 ) ) && ( LE_32( st->total_brate, ACELP_32k ) ) && ( GE_32( last_total_brate, ACELP_13k20 ) ) && ( LT_32( last_total_brate, ACELP_24k40 ) ) ) { FOR( i = 0; i < st->L_frame; i++ ) /* memQuantZeros_fx won't be updated */ { diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index b6f723c2b..81b299057 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -206,7 +206,7 @@ void core_coder_mode_switch_ivas_fx( st->restrictedMode = getRestrictedMode( st->element_mode, st->total_brate, 0 ); move16(); - core_coder_reconfig_ivas_fx( st ); + core_coder_reconfig_ivas_fx( st, last_total_brate); } ELSE { diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index 96e7e274c..1053f8b00 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -465,13 +465,13 @@ void encod_gen_voic_ivas_fx( Word16 shift_wsp; Word16 harm_flag_acelp; Word16 lp_select, lp_flag, L_frame; + Word16 q_h1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; /*------------------------------------------------------------------* @@ -554,16 +554,16 @@ void encod_gen_voic_ivas_fx( find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); /*Q11*/ - Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q14+shift*/ + q_h1 = sub( 14, norm_s( h1_fx[0] ) ); + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); *pt_pitch_fx = pit_encode_ivas_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 ); /* 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, Q_new ); /* Q6 */ + move16(); - // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); 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 ); /*-----------------------------------------------------------------* @@ -588,7 +588,7 @@ void encod_gen_voic_ivas_fx( /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ - + Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ lp_select = lp_filt_exc_enc_ivas_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 ); @@ -597,10 +597,6 @@ void encod_gen_voic_ivas_fx( push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } - /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ - hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx, &Overflow ), &Overflow ); /* Q14 */ - move16(); - /*-----------------------------------------------------------------* * Transform domain contribution encoding - active frames *-----------------------------------------------------------------*/ diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index e0d4f5016..e03db0c47 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -580,7 +580,7 @@ void enc_pit_exc_ivas_fx( Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ Word16 h1_q15[PIT_EXC_L_SUBFR + ( M + 1 )]; - SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + Word16 q_h1; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -740,8 +740,8 @@ void enc_pit_exc_ivas_fx( find_targets_ivas_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq, res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */ - Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + q_h1 = sub( 14, norm_s( h1[0] ) ); + Copy_Scale_sig( h1, h2, L_subfr, sub( 11, q_h1 ) ); /*Q11*/ /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */ @@ -750,9 +750,12 @@ void enc_pit_exc_ivas_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ + *pt_pitch = pit_encode_ivas_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 ); /* Q6 */ + L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new ); /* Q6 */ move16(); + Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ + /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ @@ -779,9 +782,6 @@ void enc_pit_exc_ivas_fx( push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } - /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ - hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ - gpit_tmp = gain_pit; move16(); /*Q14*/ test(); diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index b4495d4ff..bf04daff5 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -467,6 +467,7 @@ Word16 encod_tran_ivas_fx( Word16 L_frame_fx; Word16 shift_wsp; Word32 L_tmp; + Word16 q_h1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -540,7 +541,9 @@ Word16 encod_tran_ivas_fx( find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 ); + q_h1 = sub( 14, norm_s( h1[0] ) ); + Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ + Scale_sig( h1, L_SUBFR, sub( 13, q_h1 ) ); /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_SUBFR, shift ); diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 32c397613..0be344d72 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -93,8 +93,8 @@ void encod_unvoiced_fx( i_subfr_idx = shr( i_subfr, 6 ); Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ @@ -279,6 +279,7 @@ void encod_unvoiced_ivas_fx( Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i; Word16 index, i_subfr_idx; Word16 unbits_PI; + Word16 q_h1; acelp_cfg = &( st_fx->acelp_cfg ); SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -319,8 +320,9 @@ void encod_unvoiced_ivas_fx( find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); - Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + q_h1 = sub( 14, norm_s( h1_fx[0] ) ); + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); + Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index c758db8f3..4e15bc828 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -171,16 +171,19 @@ void find_targets_ivas_fx( Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ Word16 *cn, /* o : target vector in residual domain Q_new*/ - Word16 *h1 /* o : impulse response of weighted synthesis filter Q14*/ + Word16 *h1 /* o : impulse response of weighted synthesis filter Q(14 - norm_s(h1[0]))*/ ) { Word16 i; Word16 temp[M + 6 * L_SUBFR]; /* error of quantization */ Word16 scale, scaleq, j, d, s, s2, tmp; Word16 Aqs[M + 1]; - Word32 Ltmp; + Word32 h1_32[6 * L_SUBFR]; + Word16 sf; + Word64 Ltmp64; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /*------------------------------------------------------------------------* * Find the target vector for excitation search: @@ -200,12 +203,14 @@ void find_targets_ivas_fx( temp[i] = sub_sat( speech[i + i_subfr - M], mem_syn[i] ); /* Q_new - 1 */ move16(); } - Syn_filt_s( 1, p_Aq, M, &res[i_subfr], temp + M, L_subfr, temp, 0 ); - Residu3_fx( Ap, temp + M, xn, L_subfr, 0 ); /* xn in Q_new -1*/ + syn_filt_fx( 0, p_Aq, M, &res[i_subfr], temp + M, L_subfr, temp, 0 ); - deemph_fx( xn, tilt_fac, L_subfr, mem_w0 ); /* xn in Q_new -1 */ + Residu3_fx( Ap, temp + M, xn, L_subfr, 0 ); /* xn in Q_new */ + + deemph_fx( xn, tilt_fac, L_subfr, mem_w0 ); /* xn in Q_new */ + *mem_w0 = shr( *mem_w0, 1 ); // Q_new - 1 /*-----------------------------------------------------------------* * Find target in residual domain (cn[]) for innovation search @@ -216,13 +221,13 @@ void find_targets_ivas_fx( temp[0] = 0; move16(); preemph_copy_fx( xn, cn, tilt_fac, shr( L_subfr, 1 ), temp ); - syn_filt_s_lc_fx( 1, Ap, cn, temp, shr( L_subfr, 1 ) ); /* Q-1 -> Q-2 */ - Residu3_lc_fx( p_Aq, M, temp, cn, shr( L_subfr, 1 ), 1 ); /* Q-2 -> Q-1 */ - Scale_sig( cn, shr( L_subfr, 1 ), 1 ); /* Q_new */ + syn_filt_s_lc_fx( 1, Ap, cn, temp, shr( L_subfr, 1 ) ); /* Q_new -> Q_new - 1 */ + Residu3_lc_fx( p_Aq, M, temp, cn, shr( L_subfr, 1 ), 1 ); /* Q_new - 1 -> Q_new */ /* second half: res[] --> cn[] (approximated and faster) */ Copy( &res[i_subfr + shr( L_subfr, 1 )], cn + shr( L_subfr, 1 ), shr( L_subfr, 1 ) ); /* Q_new */ } + scale_sig( xn, L_subfr, -1 ); // Q_new - 1 /*---------------------------------------------------------------* * Compute impulse response, h1[], of weighted synthesis filter * @@ -242,67 +247,48 @@ void find_targets_ivas_fx( Copy_Scale_sig( p_Aq, Aqs, M + 1, d ); /* Q12 */ s = add( scale, 1 ); s2 = 16384; + move16(); } - set16_fx( h1, 0, L_subfr ); + + set32_fx( h1_32, 0, L_subfr ); Overflow = 0; move16(); FOR( i = 0; i < M; i++ ) { - Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ + Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= i; j++ ) { - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ + Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_o( h1_32[i - j], s, &Overflow ) ) ); /* Q27 */ } - h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ + h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */ + move32(); } - Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ + + Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= M; j++ ) { - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ + Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_o( h1_32[i - j], s, &Overflow ) ) ); /* Q27 */ } - h1[M] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ + h1_32[M] = W_extract_l( Ltmp64 ); /* Q27 */ + move32(); - // PMT("should we used extended basop here for when the L_subfr > L_SUBFR, to prevent saturation/overflow and the subsequent loop\n") FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); /* Q27 */ + Ltmp64 = W_msu_16_16( 0, Aqs[1], extract_h( L_shl_o( h1_32[i - 1], s, &Overflow ) ) ); /* Q27 */ FOR( j = 2; j <= M; j++ ) { - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ - } - h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ - } - IF( Overflow ) - { - s2 = shr( s2, 1 ); - FOR( i = 0; i < M; i++ ) - { - Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ - FOR( j = 1; j <= i; j++ ) - { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ - } - h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); /* Q11 + s */ - } - Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ - FOR( j = 1; j <= M; j++ ) - { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ - } - h1[M] = round_fx( L_shl( Ltmp, s ) ); /* Q11 + s */ - FOR( i = M + 1; i < L_subfr; i++ ) - { - Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); /* Q27 */ - FOR( j = 2; j <= M; j++ ) - { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ - } - h1[i] = round_fx( L_shl( Ltmp, s ) ); /* Q11 + s */ + Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_o( h1_32[i - j], s, &Overflow ) ) ); /* Q27 */ } + h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */ + move32(); } + sf = sub( L_norm_arr( h1_32, L_subfr ), 1 ); + Copy_Scale_sig32_16( h1_32, h1, L_subfr, sf ); // Q11 + sf + tmp = 0; - Deemph2( h1, tilt_fac, L_subfr, &tmp ); + move16(); + Deemph2( h1, tilt_fac, L_subfr, &tmp ); // Q11 + sf - 1 return; } diff --git a/lib_enc/ivas_td_low_rate_enc.c b/lib_enc/ivas_td_low_rate_enc.c index d09134951..5fffadc77 100644 --- a/lib_enc/ivas_td_low_rate_enc.c +++ b/lib_enc/ivas_td_low_rate_enc.c @@ -219,6 +219,7 @@ void encod_gen_2sbfr( Word32 norm_gain_code; Word16 pitch_limit_flag; Word16 error; + Word16 q_h1; LPD_state_HANDLE hLPDmem = st->hLPDmem; @@ -269,26 +270,23 @@ void encod_gen_2sbfr( Copy( &res[i_subfr], &exc[i_subfr], 2 * L_SUBFR ); // Q_new - // Scaling mem_syn buffer to Q_new - 1 from e_mem_syn - // Scale_sig( &hLPDmem->mem_w0, M + 1, sub( add( *Q_new, hLPDmem->e_mem_syn ), Q16 ) ); // M + 1 to sync mem_syn exponent with mem_w0 exponent - // hLPDmem->e_mem_syn = sub( Q16, *Q_new ); - - #ifndef FIX_1320_LOWRATE_ACELP find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, 2 * L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 ); #else find_targets_ivas_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, 2 * L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 ); #endif - /*Scale_sig(h1, L_SUBFR, shift); */ /*Q14-shift */ - Copy_Scale_sig( h1, h2, 2 * L_SUBFR, -2 ); - Scale_sig( h1, 2 * L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + + q_h1 = sub( 14, norm_s( h1[0] ) ); + Copy_Scale_sig( h1, h2, 2 * L_SUBFR, sub( 11, q_h1 ) ); /*------------------------------------------------------------------------* * Close-loop pitch search on the 1st and 3rd subfr only and quantization * Adaptive exc. construction *------------------------------------------------------------------------*/ + *pt_pitch = pit_encode_ivas_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, Q_new ); + move16(); - *pt_pitch = pit_encode_ivas_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 ); + Scale_sig( h1, 2 * L_SUBFR, sub( 13, q_h1 ) ); // Q13 tbe_celp_exc_ivas( st->element_mode, st->idchan, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, st->tdm_LRTD_flag ); @@ -310,6 +308,7 @@ void encod_gen_2sbfr( /*-----------------------------------------------------------------* * 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 */ #ifndef FIX_1320_LOWRATE_ACELP 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 ); diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 86fe541bb..78ef81c60 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -652,7 +652,7 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni pt1++; pt2++; } - tmp2 = L_shr_sat( tmp2_32, 7 ); // q15-> q8 + tmp2 = extract_l( L_shr_sat( tmp2_32, 7 ) ); // q15-> q8 IF( EQ_16( bwidth, NB ) ) { diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index 3793ee00d..80e144743 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -487,26 +487,27 @@ Word16 pit_encode_fx( /* o : Fractional pitc return pitch_cl; } -Word16 pit_encode_ivas_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 */ +Word16 pit_encode_ivas_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 Q_new */ + 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 Q(14 - norm_s(h1[0]) */ + const Word16 *xn, /* i : target vector Q_new */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 Q_new /* i */ ) { Word16 pitch_cl; @@ -617,6 +618,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional { nBits = pitch_bits[i_subfr >> L_sufr_sft]; } + test(); IF( EQ_16( coder_type, AUDIO ) ) { /*-------------------------------------------------------* @@ -628,7 +630,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional move16(); test(); test(); - if ( EQ_16( L_subfr, L_frame / 2 ) && i_subfr != 0 && EQ_16( L_frame, L_FRAME ) ) + if ( EQ_16( L_subfr, shr( L_frame, 1 ) ) && i_subfr != 0 && EQ_16( L_frame, L_FRAME ) ) { pit_flag = L_SUBFR; move16(); @@ -656,7 +658,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional } /* 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 ); + *T0 = pitch_fr4_ivas_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr, Q_new ); move16(); pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } @@ -684,19 +686,17 @@ Word16 pit_encode_ivas_fx( /* o : Fractional 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 ); + *T0 = pitch_fr4_ivas_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, 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 ); + *T0 = pitch_fr4_ivas_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR, Q_new ); move16(); } pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } -#if 1 - //#ifdef ADD_LRTD ELSE IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) || EQ_16( nBits, 4 ) ) { /*-------------------------------------------------------* @@ -731,7 +731,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional 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 ); + *T0 = pitch_fr4_ivas_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, Q_new ); move16(); IF( EQ_16( delta, 8 ) ) { @@ -748,7 +748,6 @@ Word16 pit_encode_ivas_fx( /* o : Fractional move16(); } } -#endif ELSE { /*-------------------------------------------------------* @@ -778,12 +777,12 @@ Word16 pit_encode_ivas_fx( /* o : Fractional { 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 ); + *T0 = pitch_fr4_ivas_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, 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 ); + *T0 = pitch_fr4_ivas_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, Q_new ); move16(); } } @@ -791,18 +790,18 @@ Word16 pit_encode_ivas_fx( /* o : Fractional { 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 ); + *T0 = pitch_fr4_ivas_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, 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 ); + *T0 = pitch_fr4_ivas_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, Q_new ); move16(); } } ELSE IF( EQ_16( nBits, 10 ) ) { - *T0 = pitch_fr4_ivas_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); + *T0 = pitch_fr4_ivas_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR, Q_new ); } pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -812,12 +811,12 @@ Word16 pit_encode_ivas_fx( /* o : Fractional 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 ); + *T0 = pitch_fr4_ivas_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, 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 ); + *T0 = pitch_fr4_ivas_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, Q_new ); move16(); } @@ -858,7 +857,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional } /* 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 ); + *T0 = pitch_fr4_ivas_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, Q_new ); move16(); } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) @@ -881,7 +880,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional } /* 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 ); + *T0 = pitch_fr4_ivas_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, Q_new ); move16(); } ELSE @@ -908,7 +907,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional } /* 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 ); + *T0 = pitch_fr4_ivas_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, Q_new ); move16(); } @@ -1156,19 +1155,20 @@ Word16 delta_pit_enc_fx( /* o : pitch index * * Find the closed loop pitch period with 1/4 subsample resolution. *-------------------------------------------------------------------*/ -Word16 pitch_fr4_ivas_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 */ +Word16 pitch_fr4_ivas_fx( /* o : chosen integer pitch lag */ + const Word16 exc[], /* i : excitation buffer Q_new */ + const Word16 xn[], /* i : target signal Q_new-1 */ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14 - norm_s[h[0]) */ + 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 */ + Word16 Q_new /* i */ ) { Word16 i; @@ -1225,7 +1225,7 @@ Word16 pitch_fr4_ivas_fx( /* o : chosen integer pitch move16(); move16(); /* corr[t_min..t_max] */ - norm_corr_ivas_fx( exc, xn, h, t_min, t_max, corr, L_subfr ); + norm_corr_ivas_fx( exc, xn, h, t_min, t_max, corr, L_subfr, Q_new ); /*-----------------------------------------------------------------* * Find integer pitch @@ -1238,7 +1238,7 @@ Word16 pitch_fr4_ivas_fx( /* o : chosen integer pitch FOR( i = add( t0_min, 1 ); i <= t0_max; i++ ) { - if ( corr[i] >= max_val ) + if ( GE_16( corr[i], max_val ) ) { t0 = i; move16(); @@ -1346,6 +1346,7 @@ Word16 pitch_fr4_ivas_fx( /* o : chosen integer pitch return ( t0 ); } + 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*/ @@ -1545,43 +1546,35 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag * excitation) *---------------------------------------------------------------------*/ void norm_corr_ivas_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 t_min, /* i : minimum value of searched range */ - const Word16 t_max, /* i : maximum value of searched range */ - Word16 ncorr[], /* o : normalized correlation Q15 */ - const Word16 L_subfr /* i : subframe size */ + const Word16 exc[], /* i : excitation buffer Q_new */ + const Word16 xn[], /* i : target signal Q_new-1 */ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14 - norm_s(h[0])) */ + const Word16 t_min, /* i : minimum value of searched range */ + const Word16 t_max, /* i : maximum value of searched range */ + Word16 ncorr[], /* o : normalized correlation */ + const Word16 L_subfr, /* i : subframe size */ + Word16 Q_new /* i */ ) { Word16 i, k, t; - Word16 corr, exp_corr, norm, exp_norm, exp, scale; + Word16 corr, exp_corr, norm, exp_norm, exp; Word16 excf[L_FRAME16k]; + Word16 ncorr_e[15 + 2 * L_INTERPOL1 + 1]; + Word16 h_e, e_max; Word32 L_tmp; Word64 W_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif 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 *-----------------------------------------------------------------*/ - conv_fx( &exc[k], h, excf, L_subfr ); - - /* Compute rounded down 1/sqrt(energy of xn[]) */ - L_tmp = L_mac_o( 1, xn[0], xn[0], &Overflow ); - FOR( i = 1; i < L_subfr; i++ ) - { - L_tmp = L_mac_o( L_tmp, xn[i], xn[i], &Overflow ); - } - exp = norm_l( L_tmp ); - exp = sub( 30, exp ); - - exp = add( exp, 2 ); /* energy of xn[] x 2 + rounded up */ - scale = negate( shr( exp, 1 ) ); /* (1< 0; i-- ) { /* saturation can occur in add() */ - /*excf[i] = add(mult(exc[k], h[i]), excf[i - 1]); move16(); */ excf[i] = round_fx_sat( L_mac_sat( L_mult( excf[i - 1], 32767 ), exc[k], h[i] ) ); + move16(); } excf[0] = mult_r( exc[k], h[0] ); move16(); } } + // Aligning the values of ncorr to a common exponent + maximum_fx( ncorr_e, t_max + 1 - t_min, &e_max ); + FOR( t = t_min; t <= t_max; t++ ) + { + ncorr[t] = shr( ncorr[t], sub( e_max, ncorr_e[t - t_min] ) ); + move16(); + } return; } + void norm_corr_fx( const Word16 exc[], /* i : excitation buffer Q_new*/ const Word16 xn[], /* i : target signal Q_new-1+shift*/ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 711d7069a..a3a7bd910 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -954,15 +954,18 @@ void norm_corr_fx( Word16 ncorr[], /* o : normalized correlation Q15 */ const Word16 L_subfr /* i : subframe size */ ); + void norm_corr_ivas_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 t_min, /* i : minimum value of searched range */ - const Word16 t_max, /* i : maximum value of searched range */ - Word16 ncorr[], /* o : normalized correlation Q15 */ - const Word16 L_subfr /* i : subframe size */ + const Word16 exc[], /* i : excitation buffer Q_new */ + const Word16 xn[], /* i : target signal Q_new-1 */ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14 - norm_s(h[0])) */ + const Word16 t_min, /* i : minimum value of searched range */ + const Word16 t_max, /* i : maximum value of searched range */ + Word16 ncorr[], /* o : normalized correlation */ + const Word16 L_subfr, /* i : subframe size */ + Word16 Q_new /* i */ ); + Word16 peak_avrg_ratio_fx( const Word32 total_brate, /* Q0 */ const Word32 *input_hi_fx, /* i : i signal Q_coeff*/ @@ -1024,20 +1027,23 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag const Word16 L_frame, /* i : length of the frame */ const Word16 L_subfr /* i : size of subframe */ ); -Word16 pitch_fr4_ivas_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 */ + +Word16 pitch_fr4_ivas_fx( /* o : chosen integer pitch lag */ + const Word16 exc[], /* i : excitation buffer Q_new */ + const Word16 xn[], /* i : target signal Q_new-1 */ + const Word16 h[], /* i : weighted synthesis filter impulse response Q(14 - norm_s[h[0]) */ + 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 */ + Word16 Q_new /* i */ ); + 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 */ @@ -2222,29 +2228,29 @@ void analy_sp_fx( ); void ivas_analy_sp_fx( - const Word16 element_mode, /* i : element mode */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 input_Fs, /* i : input sampling rate */ - Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ - const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands q_fr_bands */ - Word16 *q_fr_bands, /* o : Q of energy in critical frequency bands Q0 */ - Word32 *lf_E, /* o : per bin E for first... Q0 */ - Word16 *q_lf_E, /* o : Q of per bin E for first... q_lf_E */ - Word16 *Etot, /* o : total input energy Q8 */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - Word32 *Bin_E, /* o : per-bin energy spectrum q_Bin_E */ - Word16 *q_Bin_E, /* o : Q of per-bin energy spectrum Q0 */ - Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame q_Bin_E_old */ - Word16 *q_Bin_E_old, /* o : Q of per-bin energy spectrum of the previous frame Q0 */ - Word32 *PS, /* o : per-bin energy spectrum q_PS */ - Word16 *q_PS, /* o : Q of per-bin energy spectrum Q0 */ - Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (q_band_energies)*/ - Word16 *q_band_energies, /* o : Q of energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ - Word16 *fft_buff, /* o : FFT coefficients (q_fft_buff) */ - Word16 *q_fft_buff /* o : Q of FFT coefficients Q0 */ + const Word16 element_mode, /* i : element mode Q0 */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 input_Fs, /* i : input sampling rate Q0 */ + Word16 *speech, /* i : speech buffer Q_new */ + const Word16 Q_new, /* i : current scaling exp Q0 */ + Word32 *fr_bands, /* o : energy in critical frequency bands q_fr_bands */ + Word16 *q_fr_bands, /* o : energy in critical frequency bands Q0 */ + Word32 *lf_E, /* o : per bin E for first... q_lf_E */ + Word16 *q_lf_E, /* o : per bin E for first... Q0 */ + Word16 *Etot, /* o : total input energy Q8 */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + Word32 *Bin_E, /* o : per-bin energy spectrum q_Bin_E */ + Word16 *q_Bin_E, /* o : per-bin energy spectrum Q0 */ + Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame q_Bin_E_old */ + Word16 *q_Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q0 */ + Word32 *PS, /* o : per-bin energy spectrum q_PS */ + Word16 *q_PS, /* o : per-bin energy spectrum Q0 */ + Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (q_band_energies) */ + Word16 *q_band_energies, /* o : Q of energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ + Word16 *fft_buff, /* o : FFT coefficients (q_fft_buff) */ + Word16 *q_fft_buff /* o : Q of FFT coefficients Q0 */ ); void find_wsp_fx( const Word16 Az[], @@ -2337,7 +2343,7 @@ void find_targets_ivas_fx( Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ Word16 *cn, /* o : target vector in residual domain Q_new*/ - Word16 *h1 /* o : impulse response of weighted synthesis filter Q14*/ + Word16 *h1 /* o : impulse response of weighted synthesis filter Q(14 - norm_s(h1[0]))*/ ); void E_ACELP_adaptive_codebook( @@ -3424,26 +3430,27 @@ Word16 pit_encode_fx( /* o : Fractional pitc const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); -Word16 pit_encode_ivas_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 */ +Word16 pit_encode_ivas_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 Q_new */ + 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 Q(14 - norm_s(h1[0]) */ + const Word16 *xn, /* i : target vector Q_new */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 Q_new /* i */ ); Word16 lp_filt_exc_enc_fx( diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index f67d81c71..7422a5a15 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -3706,13 +3706,13 @@ void swb_tbe_enc_ivas_fx( Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; move16(); - GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, - hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, - shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, - EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); + GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, + vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, + shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, + &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, + nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, + &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); *Q_white_exc = Q_bwe_exc_fb; move16(); -- GitLab From 01b3c4b5c17bc6b6d165e52e7c638b15ccfd8c28 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 26 Feb 2025 12:46:11 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/prot_fx.h | 39 ++++++++++++++++++++------------------- lib_enc/core_enc_init.c | 20 ++++++++++---------- lib_enc/core_enc_switch.c | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 485ddb33d..412b5aa35 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3051,30 +3051,30 @@ void GenShapedSHBExcitation_ivas_enc_fx( Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi, - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16 *nlExc16k_e, /* i/o: exp of nlExc16k */ - Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ - Word16 *mixExc16k_e, /* i/o: exp of mixExc16k_fx */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *nlExc16k_e, /* i/o: exp of nlExc16k */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + Word16 *mixExc16k_e, /* i/o: exp of mixExc16k_fx */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ Word16 Q_EnvSHBres_4k, - Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ - Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ - Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ - Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ ); void GenShapedSHBExcitation_ivas_dec_fx( @@ -11110,7 +11110,8 @@ void init_coder_ace_plus_ivas_fx( ); void core_coder_reconfig_ivas_fx( - Encoder_State *st, const int32_t last_total_brate ); + Encoder_State *st, + const int32_t last_total_brate ); void core_coder_mode_switch_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 74f73bf52..657ef8d96 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -53,8 +53,8 @@ static void init_tcx_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag ); static void init_core_sig_ana_ivas_fx( Encoder_State *st ); static void init_modes_ivas_fx( Encoder_State *st, const Word32 last_total_brate ); -static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate); -static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate); +static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate ); +static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate ); /*-----------------------------------------------------------------------* * init_coder_ace_plus() * @@ -223,11 +223,11 @@ void init_coder_ace_plus_ivas_fx( } /* Initialize Signal Buffers */ - init_sig_buffers_ivas_fx( st, L_frame_old, L_subfr, last_total_brate); + init_sig_buffers_ivas_fx( st, L_frame_old, L_subfr, last_total_brate ); /* Initialize ACELP */ - init_acelp_ivas_fx( st, L_frame_old, 0, last_total_brate); + init_acelp_ivas_fx( st, L_frame_old, 0, last_total_brate ); if ( st->ini_frame == 0 ) { @@ -442,7 +442,7 @@ static void init_tcx_ivas_fx( * Initialization of signal buffers *-----------------------------------------------------------------------*/ /*copy of evs function since it was static */ -static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate) +static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const int32_t last_total_brate ) { LPD_state_HANDLE hLPDmem = st->hLPDmem; @@ -478,7 +478,7 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol test(); test(); test(); - IF( NE_16( st->L_frame, L_frame_old ) && !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) + IF( NE_16( st->L_frame, L_frame_old ) && !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) { lerp( st->buf_speech_enc, st->buf_speech_enc, st->L_frame, L_frame_old ); test(); @@ -530,7 +530,7 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol move16(); } /*coming from TCXonly modes*/ - ELSE IF( !st->tcxonly && GE_32(last_total_brate, ACELP_32k ) ) + ELSE IF( !st->tcxonly && GE_32( last_total_brate, ACELP_32k ) ) { Copy( st->old_wsp_fx, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, L_WSP_MEM ); @@ -647,7 +647,7 @@ static void init_core_sig_ana_ivas_fx( Encoder_State *st ) * * *-----------------------------------------------------------------------*/ -static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate) +static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const int32_t last_total_brate ) { Word16 mem_syn_r_size_old; Word16 mem_syn_r_size_new; @@ -753,7 +753,7 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh test(); test(); test(); - IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) + IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) { Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ IF( EQ_16( st->L_frame, L_FRAME16k ) ) @@ -1048,7 +1048,7 @@ static void init_modes_ivas_fx( } /* Reconfigure core */ - core_coder_reconfig_ivas_fx( st, last_total_brate); + core_coder_reconfig_ivas_fx( st, last_total_brate ); return; diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 81b299057..98e926a2b 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -206,7 +206,7 @@ void core_coder_mode_switch_ivas_fx( st->restrictedMode = getRestrictedMode( st->element_mode, st->total_brate, 0 ); move16(); - core_coder_reconfig_ivas_fx( st, last_total_brate); + core_coder_reconfig_ivas_fx( st, last_total_brate ); } ELSE { -- GitLab