diff --git a/lib_basop/basop32.c b/lib_basop/basop32.c index 27b4992767c28495e79d03bfd466c620fc6e5d57..4f601911bbe1536ca6a951e51875a5e3d7094473 100644 --- a/lib_basop/basop32.c +++ b/lib_basop/basop32.c @@ -345,7 +345,7 @@ Flag Carry = 0; do \ { \ (void) 0; \ - } while ( 0 ) /* no-op */ + } while ( 0 ) /* no-op */ #define B_HELPER_GET_GLOBAL( global_flag ) 0 /* Default to 0 */ #endif diff --git a/lib_basop/typedefs.h b/lib_basop/typedefs.h index ed38603911cecf6c9cfaefaad4d9132214a64ae7..001f3f1647c4ed00dd47fd28101a3f20a3c52c1b 100644 --- a/lib_basop/typedefs.h +++ b/lib_basop/typedefs.h @@ -183,7 +183,7 @@ typedef struct */ typedef int Bool; #define false 0 -#define true 1 +#define true 1 /* ********* Check current platform diff --git a/lib_com/options.h b/lib_com/options.h index 20cc81e20895950369ff4086a5dca38a4b0be438..7a488c673d01cc009cfa9866aed1ada548c4da83 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,6 +98,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define FIX_MDCT_STEREO_ENC_STACK /* VA: basop issue 2428: Move IGF temporary buffers out of the highest stack */ +#define HARMONIZE_TBE3 /* VA: basop issue 2399: Remove duplicated code: TBE, step 3 */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ba82aae4ba4c2b2bf13ab2ddd8fbd9347ee1f154..068770b1c6720fbe43942109b1e61da8a00486cf 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2669,11 +2669,19 @@ void flip_and_downmix_generic_fx( ); void Calc_rc0_h( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ + Word16 *rc0 /* o : 1st parcor */ ); void PostShortTerm_fx( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -2684,6 +2692,7 @@ void PostShortTerm_fx( const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); +#ifndef HARMONIZE_TBE3 void PostShortTerm_ivas_enc_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -2705,7 +2714,7 @@ void PostShortTerm_ivas_dec_fx( Word16 *mem_zero, /* i/o: null memory to compute h_st*/ const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); - +#endif void flip_spectrum_and_decimby4_fx( const Word16 i[], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ @@ -5516,6 +5525,21 @@ void wb_tbe_dec_fx( Word16 *synth, /* i/o: ACELP core synthesis/final synthesis */ Word16 *Q_synth ); +#ifdef HARMONIZE_TBE3 +void swb_tbe_dec_fx( + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word16 *Q_white_exc, /* o : Q-factor of White_exc16k_fx */ + Word16 *synth_fx16, /* o : SHB synthesis/final synthesis 16-bit : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ + Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ + Word16 *pitch_buf_fx /* i : Q6 */ +); +#else void swb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -5528,17 +5552,19 @@ void swb_tbe_dec_fx( Word16 *synth, /* o : SHB synthesis/final synthesis */ Word16 *Q_synth, Word16 *pitch_buf ); +#endif void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word32 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp, - Word16 *fb_synth_ref, - Word16 Q_fb_synth_ref, - Word16 output_frame ); + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ + const Word16 Q_fb_exc, /* i : Q-factor of fb_exc[] */ + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + const Word16 hb_synth_exp, /* i : Q-factor of hb_synth[] */ + Word16 *fb_synth_ref, /* o : Q_fb_synth_ref */ + Word16 Q_fb_synth_ref, /* i : Q-factor of fb_synth_ref[] */ + const Word16 output_frame /* i : output frame length */ +); void tbe_read_bitstream_fx( Decoder_State *st_fx /* i/o: encoder state structure */ @@ -5548,8 +5574,8 @@ void GenTransition_fx( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ Word16 *output_HB, /* o : synthesized HB transitions signal st_fx->prev_Q_bwe_syn2 */ const Word32 output_Fs, /* i : output sampling rate */ - Word16 rf_flag, /* i : RF flag */ - Word32 total_bitrate /* i : total bitrate */ + const Word16 rf_flag, /* i : RF flag */ + const Word32 total_bitrate /* i : total bitrate */ ); void GenTransition_fx32( @@ -9818,18 +9844,20 @@ void v_sub32_fx( const Word16 N /* i : Vector length */ ); +#ifndef HARMONIZE_TBE3 void swb_tbe_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ Word16 *pitch_buf_fx, /* i : Q6 */ - Word16 *Q_white_exc ); - + Word16 *Q_white_exc /* o : Q-factor of White_exc16k_fx */ +); +#endif Word16 swb_bwe_dec_fx32( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index a6f0bdb381677b51e2f3e0421c453aa057c678d7..7f39768d9064644c1b54835e7410387d15801158 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -26,7 +26,11 @@ static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[], Word16 element_mode ); static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); +#ifdef HARMONIZE_TBE3 +static void Calc_st_filt_tbe_fx( const Word16 element_mode, const Word16 enc_dec, Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); +#else static void Calc_st_filt_tbe_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); +#endif static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); static void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); @@ -431,7 +435,6 @@ void flip_and_downmix_generic_fx32( /* Hilber transform stage - 0 - single precision */ Hilbert_transform_fx( tmp, tmp, tmpi_R, tmpi_I, length, 0 ); - Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 ); Copy32( mem3_ext, tmpi2_I, HILBERT_ORDER2 ); @@ -605,10 +608,11 @@ static void Hilbert_transform_sp_fx( /*---------------------------------------------- * flip_spectrum_fx *----------------------------------------------*/ + void flip_spectrum_fx( - const Word16 input[], /* i : input spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length /* i : vector length */ + const Word16 input[], /* i : input spectrum */ + Word16 output[], /* o : output spectrum */ + const Word16 length /* i : vector length */ ) { Word16 i; @@ -630,37 +634,74 @@ void flip_spectrum_fx( * * computes 1st parcor from composed filter impulse response *---------------------------------------------------------------------------*/ + void Calc_rc0_h( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ + Word16 *rc0 /* o : 1st parcor */ ) { Word32 L_acc; Word16 *ptrs; Word16 acf0, acf1; +#ifdef HARMONIZE_TBE3 + Word16 tmp2; +#endif Word16 temp, sh_acf; Word16 i; /* computation of the autocorrelation function acf */ - L_acc = L_mult( h[0], h[0] ); - FOR( i = 1; i < LONG_H_ST; i++ ) +#ifdef HARMONIZE_TBE3 + IF( element_mode != EVS_MONO && enc_dec == ENC ) { - L_acc = L_mac( L_acc, h[i], h[i] ); - } - sh_acf = norm_l( L_acc ); - L_acc = L_shl( L_acc, sh_acf ); - acf0 = extract_h( L_acc ); + L_acc = L_mult( h[0], h[0] ); // TBV: shouldn't it be "shr( h[0], 2 )" ? + FOR( i = 1; i < LONG_H_ST; i++ ) + { + tmp2 = shr( h[i], 2 ); + L_acc = L_mac( L_acc, tmp2, tmp2 ); + } + sh_acf = norm_l( L_acc ); + L_acc = L_shl( L_acc, sh_acf ); + acf0 = extract_h( L_acc ); - ptrs = h; + ptrs = h; - temp = *ptrs++; - move16(); - L_acc = L_mult( temp, *ptrs ); - FOR( i = 1; i < LONG_H_ST - 1; i++ ) + temp = *ptrs++; + move16(); + L_acc = L_mult( temp, *ptrs ); + FOR( i = 1; i < LONG_H_ST - 1; i++ ) + { + temp = shr( *ptrs++, 2 ); + move16(); + L_acc = L_mac( L_acc, temp, shr( *ptrs, 2 ) ); + } + } + ELSE +#endif { + L_acc = L_mult( h[0], h[0] ); + FOR( i = 1; i < LONG_H_ST; i++ ) + { + L_acc = L_mac( L_acc, h[i], h[i] ); + } + sh_acf = norm_l( L_acc ); + L_acc = L_shl( L_acc, sh_acf ); + acf0 = extract_h( L_acc ); + + ptrs = h; + temp = *ptrs++; move16(); - L_acc = L_mac( L_acc, temp, *ptrs ); + L_acc = L_mult( temp, *ptrs ); + FOR( i = 1; i < LONG_H_ST - 1; i++ ) + { + temp = *ptrs++; + move16(); + L_acc = L_mac( L_acc, temp, *ptrs ); + } } L_acc = L_shl( L_acc, sh_acf ); acf1 = extract_h( L_acc ); @@ -690,6 +731,7 @@ void Calc_rc0_h( return; } +#ifndef HARMONIZE_TBE3 static void Calc_rc0_h_ivas_enc_fx( Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ @@ -748,8 +790,13 @@ static void Calc_rc0_h_ivas_enc_fx( move16(); } } +#endif static void Calc_st_filt_tbe_fx( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ @@ -764,10 +811,27 @@ static void Calc_st_filt_tbe_fx( Word16 g0, temp; Word16 i; temp = sub( 2, norm_s( apond2[0] ) ); - /* compute i.r. of composed filter apond2 / apond1 */ - Syn_filt_s( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + +#ifdef HARMONIZE_TBE3 + IF( element_mode != EVS_MONO && enc_dec == ENC ) + { + /* compute i.r. of composed filter apond2 / apond1 */ + syn_filt_fx( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + } + ELSE +#endif + { + /* compute i.r. of composed filter apond2 / apond1 */ + Syn_filt_s( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + } + /* compute 1st parcor */ +#ifdef HARMONIZE_TBE3 + Calc_rc0_h( element_mode, enc_dec, h, parcor0 ); +#else Calc_rc0_h( h, parcor0 ); +#endif + /* compute g0 */ L_g0 = L_mult0( 1, abs_s( h[0] ) ); @@ -791,6 +855,7 @@ static void Calc_st_filt_tbe_fx( return; } +#ifndef HARMONIZE_TBE3 static void Calc_st_filt_tbe_ivas_enc_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ @@ -832,6 +897,7 @@ static void Calc_st_filt_tbe_ivas_enc_fx( return; } +#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ @@ -874,9 +940,7 @@ static void filt_mu_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*(14 - exp) */ ga = shl_sat( tmp, exp ); /*Q14 */ - /* ga = (float) 1. / ((float) 1. - (float) fabs (mu)); */ - ptrs = sig_in; /* points on sig_in(-1) */ FOR( n = 0; n < SubFrameLength; n++ ) @@ -992,7 +1056,18 @@ static void scale_st_swb( return; } + +/*-------------------------------------------------------------------* + * PostShortTerm() + * + * Short term processing + *-------------------------------------------------------------------*/ + void PostShortTerm_fx( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *sig_in, /* i : input signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -1006,8 +1081,7 @@ void PostShortTerm_fx( Word16 apond1_fx[LPC_SHB_ORDER + 1]; /* denominator coeff.*/ Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ Word16 sig_ltp_fx[L_SUBFR16k + 1]; /* residual signal */ - /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */ - Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ + Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ Word16 tmp; parcor0_fx = 0; @@ -1023,28 +1097,37 @@ void PostShortTerm_fx( /* Compute weighted LPC coefficients */ weight_a_fx( lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER ); - weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); - /* o: apond1_fx, apond2_fx in Q12 */ + weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); /* apond1_fx, apond2_fx in Q12 */ /* Compute A(gamma2) residual */ - Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); - /* o: sig_ltp_fx in Q_bwe_exc */ + Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); /* sig_ltp_fx in Q_bwe_exc */ /* Save last output of 1/A(gamma1) */ sig_ltp_fx[0] = *ptr_mem_stp; move16(); /* Control short term pst filter gain and compute parcor0 */ +#ifdef HARMONIZE_TBE3 + Calc_st_filt_tbe_fx( element_mode, enc_dec, apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); /* parcor0 in Q15, sig_ltp_fx in Q_bwe_exc */ +#else Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); - /* o: parcor0 in Q15 */ - /* i/o: sig_ltp_fx in Q_bwe_exc */ + /* i: parcor0 in Q15, o: sig_ltp_fx in Q_bwe_exc */ +#endif /* 1/A(gamma1) filtering, mem_stp is updated */ - Syn_filt_s( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); +#ifdef HARMONIZE_TBE3 + IF( element_mode != EVS_MONO && enc_dec == ENC ) + { + syn_filt_fx( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); + } + ELSE +#endif + { + Syn_filt_s( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); + } /* (1 + mu z-1) tilt filtering */ - filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); - /* o: sig_out in Q_bwe_exc */ + filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); /* sig_out in Q_bwe_exc */ /* gain control */ scale_st_swb( sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); @@ -1052,6 +1135,7 @@ void PostShortTerm_fx( return; } +#ifndef HARMONIZE_TBE3 void PostShortTerm_ivas_enc_fx( Word16 *sig_in, /* i : input signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -1171,7 +1255,7 @@ void PostShortTerm_ivas_dec_fx( return; } - +#endif /*-------------------------------------------------------------------* * flip_spectrum_and_decimby4() @@ -1180,12 +1264,12 @@ void PostShortTerm_ivas_dec_fx( *-------------------------------------------------------------------*/ void flip_spectrum_and_decimby4_fx( - const Word16 input[], /* i : input spectrum Q_inp */ - Word16 output[], /* o : output spectrum Q_inp */ - const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory Q_inp */ - Word16 mem2[], /* i/o : memory Q_inp */ - const Word16 ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ + const Word16 input[], /* i : input spectrum Q_inp */ + Word16 output[], /* o : output spectrum Q_inp */ + const Word16 length, /* i : vector length */ + Word16 mem1[], /* i/o: memory Q_inp */ + Word16 mem2[], /* i/o: memory Q_inp */ + const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ ) { Word16 i; @@ -2180,333 +2264,328 @@ void GenShapedSHBExcitation_fx( *mem_csfilt = Mult_32_16( L_tmp, varEnvShape ); move32(); } + + /* Track the low band envelope */ + L_tmp = *mem_csfilt; + move32(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - /* Track the low band envelope */ - L_tmp = *mem_csfilt; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) + excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], excTmp2[i] ); + move16(); + /* excNoisyEnv : Q_bwe_exc, + *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ + L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_bwe_exc+16 */ + } + *mem_csfilt = L_tmp; + move32(); + + /* create a random excitation - Reuse exc16k memory */ + White_exc16k = exc16k; + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); + + L_tmp = L_deposit_l( 0 ); + tmp = add( *Q_bwe_exc, 1 ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + L_tmp4 = L_shl_sat( L_deposit_l( White_exc16k[k] ), tmp ); + if ( excNoisyEnv[k] != 0 ) { - excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], excTmp2[i] ); - move16(); - /* excNoisyEnv : Q_bwe_exc, - *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ - L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_bwe_exc+16 */ + L_tmp4 = L_mult( excNoisyEnv[k], White_exc16k[k] ); /* (Q_bwe_exc) +5 +1*/ } - *mem_csfilt = L_tmp; + White_exc16k_32[k] = L_tmp4; move32(); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } + Q_temp = norm_l( L_tmp ); + if ( L_tmp == 0 ) { - /* create a random excitation - Reuse exc16k memory */ - White_exc16k = exc16k; - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); - - L_tmp = L_deposit_l( 0 ); - tmp = add( *Q_bwe_exc, 1 ); - FOR( k = 0; k < L_FRAME16k; k++ ) - { - L_tmp4 = L_shl_sat( L_deposit_l( White_exc16k[k] ), tmp ); - if ( excNoisyEnv[k] != 0 ) - { - L_tmp4 = L_mult( excNoisyEnv[k], White_exc16k[k] ); /* (Q_bwe_exc) +5 +1*/ - } - White_exc16k_32[k] = L_tmp4; - move32(); - L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); - } - Q_temp = norm_l( L_tmp ); - if ( L_tmp == 0 ) - { - Q_temp = 31; - move16(); - } - /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ - /* White_exc16k in Q6 */ + Q_temp = 31; + move16(); + } + /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ + /* White_exc16k in Q6 */ - /* calculate pow22 */ - /* pow22=0.00001f */ - tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); - pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ - tmp = sub( NOISE_QFAC, 5 ); - FOR( k = 0; k < L_FRAME16k; k++ ) - { - /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); - move16(); - /* i: excNoisyEnv in (Q_bwe_exc) */ - /* i: White_exc16k in Q6 */ - /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ - /* pow22 += White_exc16k[k] * White_exc16k[k]; */ - pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ - } - /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ - Q_pow22 = shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ); + /* calculate pow22 */ + /* pow22=0.00001f */ + tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); + pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ + tmp = sub( NOISE_QFAC, 5 ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /* White_exc16k[k] *= excNoisyEnv[k]; */ + White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); + move16(); + /* i: excNoisyEnv in (Q_bwe_exc) */ + /* i: White_exc16k in Q6 */ + /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ + /* pow22 += White_exc16k[k] * White_exc16k[k]; */ + pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ } + /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ + Q_pow22 = shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ); IF( GE_32( bitrate, ACELP_24k40 ) ) { IF( EQ_16( *vf_ind, 20 ) ) /* encoder side */ { + Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, + ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); + tmp = voiceFacEst[0]; + move16(); + tmp2 = MAX_16; + move16(); + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, - ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); - tmp = voiceFacEst[0]; + tmp2 = 26214 /*0.8f Q15*/; move16(); - tmp2 = MAX_16; - move16(); - if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) - { - tmp2 = 26214 /*0.8f Q15*/; - move16(); - } } } ELSE /* decoder side */ + { + /* *vf_ind is an integer scale by 0.125f*/ + tmp = shl( *vf_ind, ( 15 - 3 ) ); + tmp2 = MAX_16; + move16(); + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - { /* *vf_ind is an integer scale by 0.125f*/ - tmp = shl( *vf_ind, ( 15 - 3 ) ); - tmp2 = MAX_16; - move16(); - if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) + tmp2 = 26214 /*0.8f Q15*/; + move16(); + } + } { - tmp2 = 26214 /*0.8f Q15*/; + voice_factors[0] = mult_r( voice_factors[0], tmp2 ); + move16(); + voice_factors[1] = mult_r( voice_factors[1], tmp2 ); + move16(); + voice_factors[2] = mult_r( voice_factors[2], tmp2 ); + move16(); + voice_factors[3] = mult_r( voice_factors[3], tmp2 ); + move16(); + voice_factors[4] = mult_r( voice_factors[4], tmp2 ); move16(); } } -} -{ - voice_factors[0] = mult_r( voice_factors[0], tmp2 ); - move16(); - voice_factors[1] = mult_r( voice_factors[1], tmp2 ); - move16(); - voice_factors[2] = mult_r( voice_factors[2], tmp2 ); - move16(); - voice_factors[3] = mult_r( voice_factors[3], tmp2 ); - move16(); - voice_factors[4] = mult_r( voice_factors[4], tmp2 ); - move16(); -} -} -tmp = sub( Q_temp, 3 ); -FOR( k = 0; k < L_FRAME16k; k++ ) -{ - White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ -} -prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; -move16(); -*Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); -move16(); -deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); // Q_bwe_exc-NOISE_QADJ -{ - IF( EQ_16( coder_type, UNVOICED ) ) + tmp = sub( Q_temp, 3 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { - 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 */ - FOR( k = 0; k < L_FRAME16k; k++ ) - { - /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ - L_tmp = L_mult( White_exc16k[k], scale ); - /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); - move16(); - /* exc16kWhtnd: Q_bwe_exc */ - } - preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc + White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ } - ELSE + prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; + move16(); + *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); + move16(); + deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); // Q_bwe_exc-NOISE_QADJ { - Word16 nbSubFr, lSubFr; - Word16 tempQ15; - Word32 tempQ31; - /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ - nbSubFr = NB_SUBFR16k; - lSubFr = ( L_FRAME16k / NB_SUBFR16k ); - IF( LT_32( bitrate, ACELP_24k40 ) ) + IF( EQ_16( coder_type, UNVOICED ) ) { - nbSubFr = NB_SUBFR; - move16(); - lSubFr = ( L_FRAME16k / NB_SUBFR ); - move16(); + 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 */ + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ + L_tmp = L_mult( White_exc16k[k], scale ); + /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ + exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); + move16(); + /* exc16kWhtnd: Q_bwe_exc */ + } + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc } - k = 0; - FOR( i = 0; i < nbSubFr; i++ ) + ELSE { - test(); - IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) + Word16 nbSubFr, lSubFr; + Word16 tempQ15; + Word32 tempQ31; + /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ + nbSubFr = NB_SUBFR16k; + lSubFr = ( L_FRAME16k / NB_SUBFR16k ); + IF( LT_32( bitrate, ACELP_24k40 ) ) { - exp = 0; + nbSubFr = NB_SUBFR; move16(); - tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ - temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - exp = 0; + lSubFr = ( L_FRAME16k / NB_SUBFR ); move16(); - tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ - temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ - temp = sub( MAX_16, temp ); - tempQ31 = Mult_32_16( pow1, temp ); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ } - ELSE + k = 0; + FOR( i = 0; i < nbSubFr; i++ ) { - /* Adjust noise mixing for formant sharpening filter */ - tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); - /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ - vf_tmp = sub( MAX_16, tempQ15 ); - vf_tmp = mult_r( voice_factors[i], vf_tmp ); + test(); + IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) + { + exp = 0; + move16(); + tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ + temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ + exp = 0; + move16(); + tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - exp = 0; - move16(); - tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ - temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ - temp = sub( MAX_16, vf_tmp ); - tempQ31 = Mult_32_16( pow1, temp ); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ - } + /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ + temp = sub( MAX_16, temp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ + } + ELSE + { + /* Adjust noise mixing for formant sharpening filter */ + tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); + /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ + vf_tmp = sub( MAX_16, tempQ15 ); + vf_tmp = mult_r( voice_factors[i], vf_tmp ); - 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-NOISE_QADJ)*/ - L_tmp = L_shl_sat( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); - move16(); - /* Q_bwe_exc */ - } - k = add( k, lSubFr ); + exp = 0; + move16(); + tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - /* estimate the pre-emph factor */ - tempQ15 = sub( MAX_16, voice_factors[i] ); - exp = 0; - move16(); - temp = Sqrt16( tempQ15, &exp ); - temp = shl( temp, exp - 1 ); + /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ + temp = sub( MAX_16, vf_tmp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ + } + + 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-NOISE_QADJ)*/ + L_tmp = L_shl_sat( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); + move16(); + /* Q_bwe_exc */ + } + k = add( k, lSubFr ); + + /* estimate the pre-emph factor */ + tempQ15 = sub( MAX_16, voice_factors[i] ); + exp = 0; + move16(); + temp = Sqrt16( tempQ15, &exp ); + temp = shl( temp, exp - 1 ); - temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ - temp = div_s( temp, temp2 ); /* Q15 */ - temp = mult_r( PREEMPH_FAC, temp ); + temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ + temp = div_s( temp, temp2 ); /* Q15 */ + temp = mult_r( PREEMPH_FAC, temp ); - preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_bwe_exc + preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_bwe_exc + } } } -} -IF( LT_32( bitrate, ACELP_24k40 ) ) -{ - Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: excSHB in Q_bwe_exc */ -} -ELSE -{ - set16_fx( zero_mem, 0, LPC_SHB_ORDER ); + IF( LT_32( bitrate, ACELP_24k40 ) ) + { + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: excSHB in Q_bwe_exc */ + } + ELSE + { + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); - Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: tempSHB in Q_bwe_exc */ - /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ - IF( LE_32( bitrate, ACELP_32k ) ) - { - L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: tempSHB in Q_bwe_exc */ + /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ + IF( LE_32( bitrate, ACELP_32k ) ) + { + L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); - /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ - tmp = shl( Q_shb, 1 ); - tmp2 = add( shl( *Q_bwe_exc, 1 ), 1 ); - L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ + /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ + tmp = shl( Q_shb, 1 ); + tmp2 = add( shl( *Q_bwe_exc, 1 ), 1 ); + L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ + + *Q_bwe_exc = sub( *Q_bwe_exc, exp ); + move16(); /* compensate for the exp shift */ + tmp2 = add( prev_Q_bwe_syn, n_mem2 ); + IF( GT_16( *Q_bwe_exc, tmp2 ) ) + { + L_tmp2 = L_shl( L_tmp2, sub( tmp2, *Q_bwe_exc ) ); + *Q_bwe_exc = tmp2; + move16(); + } + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ + exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + move16(); + } + } + /* i: L_tmp2 in (Q31-exp) */ + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ - *Q_bwe_exc = sub( *Q_bwe_exc, exp ); - move16(); /* compensate for the exp shift */ - tmp2 = add( prev_Q_bwe_syn, n_mem2 ); - IF( GT_16( *Q_bwe_exc, tmp2 ) ) + /* Rescale the past memories: LP synth and SHB look ahead buffers */ + tmp = sub( *Q_bwe_exc, prev_Q_bwe_syn ); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - L_tmp2 = L_shl( L_tmp2, sub( tmp2, *Q_bwe_exc ) ); - *Q_bwe_exc = tmp2; + state_lpc_syn[i] = shl( state_lpc_syn[i], tmp ); move16(); } - FOR( i = 0; i < L_FRAME16k; i++ ) + FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) { - L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ - exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + excSHB[i] = shl( excSHB[i], tmp ); move16(); } - } - /* i: L_tmp2 in (Q31-exp) */ - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ + /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - /* Rescale the past memories: LP synth and SHB look ahead buffers */ - tmp = sub( *Q_bwe_exc, prev_Q_bwe_syn ); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - state_lpc_syn[i] = shl( state_lpc_syn[i], tmp ); - move16(); - } - FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) - { - excSHB[i] = shl( excSHB[i], tmp ); - move16(); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); + /* i: exc16kWhtnd in (Q_bwe_exc) */ + /* o: excSHB in (Q_bwe_exc) */ } - /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); - /* i: exc16kWhtnd in (Q_bwe_exc) */ - /* o: excSHB in (Q_bwe_exc) */ -} - -IF( EQ_16( extl, FB_TBE ) ) -{ - tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); - Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); - Scale_sig( fb_tbe_demph, 1, tmp ); - Syn_filt_s( 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) */ - - FOR( i = 0; i < 10; i++ ) + IF( EQ_16( extl, FB_TBE ) ) { - FOR( j = 0; j < 32; ++j ) + tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); + Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); + Scale_sig( fb_tbe_demph, 1, tmp ); + Syn_filt_s( 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) */ + + FOR( i = 0; i < 10; i++ ) { - White_exc16k_FB_temp[i * 32 + j] = mult_r( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); - move16(); + FOR( j = 0; j < 32; ++j ) + { + White_exc16k_FB_temp[i * 32 + j] = mult_r( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); + move16(); + } } - } - *Q_bwe_exc_fb = add( *Q_bwe_exc_fb, 20 ); - move16(); /**Q_bwe_exc_fb +35 +1 -16*/ - flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); + *Q_bwe_exc_fb = add( *Q_bwe_exc_fb, 20 ); + move16(); /**Q_bwe_exc_fb +35 +1 -16*/ + flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); - deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); -} -ELSE -{ - set16_fx( White_exc16k_FB, 0, L_FRAME16k ); -} + deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); + } + ELSE + { + set16_fx( White_exc16k_FB, 0, L_FRAME16k ); + } -return; + return; } #ifdef HARMONIZE_TBE2 @@ -5425,7 +5504,7 @@ void ScaleShapedSHB_fx32( *-------------------------------------------------------------------*/ void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ + const Word16 length, /* i : SHB overlap length */ Word16 *synSHB, /* i/o: synthesized shb signal Q_bwe_exc/Qx*/ Word16 *overlap, /* i/o: buffer for overlap-add Q_bwe_exc/Qx*/ const Word16 *subgain, /* i : subframe gain Q15*/ @@ -6218,7 +6297,6 @@ void create_random_vector_fx( /* INPUT/OUTPUT ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------------*/ - /* _ None */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ @@ -6226,21 +6304,21 @@ void create_random_vector_fx( /*======================================================================================*/ void interp_code_5over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx */ + Word16 interp_code_fx[], /* o : output vector Qx */ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, kk, kkp1, i_len2; Word32 Ltemp; - Word16 factor_i_fx[5] = { 6554, 19661, 32767, 19661, 6554 }; + const Word16 factor_i_fx[5] = { 6554, 19661, 32767, 19661, 6554 }; move16(); move16(); move16(); move16(); move16(); move16(); - Word16 factor_j_fx[5] = { 26214, 13107, 0, 13107, 26214 }; + const Word16 factor_j_fx[5] = { 26214, 13107, 0, 13107, 26214 }; move16(); move16(); move16(); @@ -6323,7 +6401,6 @@ void interp_code_5over2_fx( /* INPUT/OUTPUT ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------------*/ - /* _ None */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ @@ -6331,9 +6408,9 @@ void interp_code_5over2_fx( /*======================================================================================*/ void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx */ + Word16 interp_code_fx[], /* o : output vector Qx */ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, j; @@ -6873,7 +6950,6 @@ static void Estimate_mix_factors_fx( /* temp_p1_p3 = (float)sqrt(pow1/pow3); */ temp_p1_p3 = root_a_over_b_fx( pow1, Q_pow1, pow3, ( 2 * Q_shb + 1 ), &exp2 ); /* temp_p1_p3 in (Q31+exp2) */ - sc1 = sub( Q_bwe_exc, sub( Q_frac, exp1 ) ); sc2 = sub( Q_bwe_exc, sub( Q_shb, exp2 ) ); FOR( i = 0; i < L_FRAME16k; i++ ) diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 442e0caf070b9015759f51d6f300120618ffba00..b76218055a3402e05e714037348c2129dbe49471 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -1309,7 +1309,11 @@ static void calc_st_filt_local_fx( E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M ); /* compute 1st parcor */ +#ifdef HARMONIZE_TBE3 + Calc_rc0_h( EVS_MONO, DEC, h, parcor0 ); +#else Calc_rc0_h( h, parcor0 ); +#endif /* compute g0 */ L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index ec330496f345b9a53a92758454345e392af0a769..0c134ce5b73c8df9a381fe639bec891ef3f43edc 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -416,8 +416,12 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || ( NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) && GT_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->core, ACELP_CORE ) && GE_32( st_fx->output_Fs, 32000 ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) ) { /* SWB TBE decoder */ +#ifdef HARMONIZE_TBE3 + swb_tbe_dec_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); +#else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); +#endif /* FB TBE decoder */ test(); @@ -853,8 +857,13 @@ ivas_error evs_dec_fx( ELSE IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) { /* SWB TBE decoder */ +#ifdef HARMONIZE_TBE3 + swb_tbe_dec_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); +#else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); +#endif + test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index c44b34c171ecf3fe70b579c10b099dc3ee01d0b8..791c8172c5c2db4859e51beb3d00a443c7607eb4 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1000,21 +1000,29 @@ ivas_error ivas_core_dec_fx( IF( flag_swb_tbe ) { /* SWB TBE decoder */ +#ifdef HARMONIZE_TBE3 + swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, &Q_white_exc, NULL, hb_synth_32_fx[n], NULL, pitch_buf_fx[n] ); +#else swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); +#endif Copy_Scale_sig_16_32_no_sat( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, hBWE_TD->prev_Q_bwe_syn2 ) ); // Q11 Copy_Scale_sig_32_16( hBWE_TD->old_tbe_synth_fx_32, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx +#ifndef HARMONIZE_TBE3 IF( GT_16( Q_white_exc, 31 ) ) { Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); // Q31 Q_white_exc = 31; move16(); } - +#endif /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { +#ifdef HARMONIZE_TBE3 + // TODO: check why 'Q_synth' is not used instead of 'Q_white_exc' as the second but last paremeter in the following function call +#endif fb_tbe_dec_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, NULL, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); } } @@ -1109,6 +1117,9 @@ ivas_error ivas_core_dec_fx( q = Q11; move16(); +#ifdef HARMONIZE_TBE3 + // TODO: check whether 'Q_synth' is not used instead of 'Q_white_exc' as the last paremeter in the following function call +#endif stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q, Q_white_exc ); test(); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 7a6ba9ac4015b33dfddc09127555461619797cd0..cb0a565d0e4eb812561eb43cde73ea697dcaa90a 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -1334,7 +1334,7 @@ void wb_tbe_dec_fx( return; } - +#ifndef HARMONIZE_TBE3 /*======================================================================================*/ /* FUNCTION : void swb_tbe_dec_fx () */ /*--------------------------------------------------------------------------------------*/ @@ -3022,6 +3022,14 @@ void swb_tbe_dec_fx( return; } +#endif + +/*-------------------------------------------------------------------* + * gradientGainShape() + * + * + *-------------------------------------------------------------------*/ + static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, @@ -3378,7 +3386,6 @@ static void dequantizeSHBparams_fx( hBWE_TD = st_fx->hBWE_TD; /* LSFs */ - IF( EQ_16( extl, WB_TBE ) ) { IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) @@ -3483,7 +3490,7 @@ static void dequantizeSHBparams_fx( idx_shb_fr_gain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_ENER_SF ); } temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ + /* temp_shb_ener_sf_fx in Q12 */ /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ @@ -3506,12 +3513,9 @@ static void dequantizeSHBparams_fx( idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } - Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ - ); + Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], 2048 /*0.125f Q14*/, 1024 /*0.125f Q13*/ ); move16(); - /* o: Q_shb_res_gshape in Q14 */ + /* Q_shb_res_gshape in Q14 */ } IF( EQ_16( st_fx->codec_mode, MODE2 ) ) @@ -3525,7 +3529,7 @@ static void dequantizeSHBparams_fx( } *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); move16(); - /* o: Q_mixFactors in Q15 */ + /* Q_mixFactors in Q15 */ } ELSE { @@ -3782,16 +3786,16 @@ static void dequantizeSHBparams_fx( *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ - Word16 Q_fb_exc, - Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word16 hb_synth_exp, - Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ - Word16 Q_fb_synth_ref, - Word16 output_frame ) - + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ + const Word16 Q_fb_exc, /* i : Q-factor of fb_exc[] */ + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + const Word16 hb_synth_exp, /* i : Q-factor of hb_synth[] */ + Word16 *fb_synth_ref, /* o : Q_fb_synth_ref */ + Word16 Q_fb_synth_ref, /* i : Q-factor of fb_synth_ref[] */ + const Word16 output_frame /* i : output frame length */ +) { Word16 i; Word16 ratio = 0; @@ -3839,8 +3843,7 @@ void fb_tbe_dec_fx( fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* FB TBE synthesis */ - synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp, - st->element_mode ); + synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp, st->element_mode ); test(); IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->idchan == 0 ) ) @@ -3974,6 +3977,8 @@ void tbe_read_bitstream_fx( hBWE_TD->idxGain = (Word16) get_next_indice_fx( st_fx, 4 ); move16(); } + + return; } @@ -3989,8 +3994,8 @@ void GenTransition_fx( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ Word16 *output_HB, /* o : synthesized HB transitions signal st_fx->prev_Q_bwe_syn2 */ const Word32 output_Fs, /* i : output sampling rate */ - Word16 rf_flag, /* i : RF flag */ - Word32 total_bitrate /* i : total bitrate */ + const Word16 rf_flag, /* i : RF flag */ + const Word32 total_bitrate /* i : total bitrate */ ) { Word16 i, length; @@ -4531,6 +4536,21 @@ static void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ +#ifdef HARMONIZE_TBE3 +void swb_tbe_dec_fx( + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word16 *Q_white_exc, /* o : Q-factor of White_exc16k_fx */ + Word16 *synth_fx16, /* o : SHB synthesis/final synthesis 16-bit : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ + Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ + Word16 *pitch_buf_fx /* i : Q6 */ +) +#else void swb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ @@ -4539,9 +4559,11 @@ void swb_tbe_dec_ivas_fx( const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ Word16 *pitch_buf_fx, /* i : Q6 */ - Word16 *Q_white_exc ) + Word16 *Q_white_exc /* o : Q-factor of White_exc16k_fx */ +) +#endif { Word16 i, j, cnt, n; Word16 stemp; @@ -4551,6 +4573,9 @@ void swb_tbe_dec_ivas_fx( Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; Word16 lsf_shb_fx[LPC_SHB_ORDER], lpc_shb_fx[LPC_SHB_ORDER + 1], GainShape_fx[NUM_SHB_SUBFR]; // Q12,Q12,Q15 Word32 GainFrame_fx; // Q18 +#ifdef HARMONIZE_TBE3 + Word16 error_fx16[L_FRAME32k]; +#endif Word32 error_fx[L_FRAME32k]; Word16 ener_fx; Word32 L_ener; @@ -4605,12 +4630,17 @@ void swb_tbe_dec_ivas_fx( Word16 expa, expb; Word16 fraca, fracb; Word16 exp_ener, inv_ener; +#ifdef HARMONIZE_TBE3 + Word16 Q_exc = st->Q_exc; + move16(); +#endif hBWE_TD = st->hBWE_TD; +#ifndef HARMONIZE_TBE3 Word32 old_syn_12k8_16k_fx[L_FRAME16k]; Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) - +#endif /* initializations */ GainFrame_fx = 0; move32(); @@ -4643,8 +4673,23 @@ void swb_tbe_dec_ivas_fx( } /* find tilt */ - calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); - tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k_fx16, st->Q_syn2, st->L_frame ); + tilt_swb_fec_fx = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); + } + ELSE +#endif + { +#ifdef HARMONIZE_TBE3 + Word32 old_syn_12k8_16k_fx[L_FRAME16k]; + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) +#endif + calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); + tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) ); + } + test(); if ( st->bfi && st->clas_dec != UNVOICED_CLAS ) { @@ -4865,12 +4910,13 @@ void swb_tbe_dec_ivas_fx( } } } - ELSE + ELSE /* FER concealment of TBE parameters */ { Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); test(); IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) ) { + /* Gradient based GS estimation */ gradientGainShape( st, GainShape_fx, &GainFrame_fx ); } ELSE @@ -4906,6 +4952,7 @@ void swb_tbe_dec_ivas_fx( } } + /* FER concealment for SWB_TBE_2k8 */ IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) ) { test(); @@ -4977,10 +5024,25 @@ void swb_tbe_dec_ivas_fx( /* get the gainshape delay */ Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) +#ifdef HARMONIZE_TBE3 + test(); + test(); + IF( st->element_mode == EVS_MONO && ( ( st->rf_flag != 0 ) || EQ_32( st->total_brate, ACELP_9k60 ) ) ) { - hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape_fx[i * 4]; /*Q15*/ - move16(); + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape_fx[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); + move16(); + } + } + ELSE +#endif + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape_fx[i * 4]; /*Q15*/ + move16(); + } } L_tmp = L_mult( voice_factors_fx[0], 8192 ); @@ -5008,12 +5070,14 @@ void swb_tbe_dec_ivas_fx( } } +#if 0 // TBV: this looks like a bug in EVS: the code is present in float but not in BASOP test(); IF( st->use_partial_copy && st->nelp_mode_dec ) { set16_fx( vf_modified_fx, 0, NB_SUBFR16k ); } +#endif /* SHB LSF from current frame; and convert to LSP for interpolation */ E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); @@ -5134,8 +5198,13 @@ void swb_tbe_dec_ivas_fx( Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); } - /* convert from lsp to lsf */ - lsp2lsf_fx( lsp_temp_fx, lsf_shb_fx, LPC_SHB_ORDER, 1 ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode != EVS_MONO ) +#endif + { + /* convert from lsp to lsf */ + lsp2lsf_fx( lsp_temp_fx, lsf_shb_fx, LPC_SHB_ORDER, 1 ); + } } Copy( lsf_diff_fx + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); @@ -5162,8 +5231,17 @@ void swb_tbe_dec_ivas_fx( ptr_lsp_interp_coef_fx += 2; tmp = i_mult( j, ( LPC_SHB_ORDER + 1 ) ); + /* convert LSPs to LP coefficients */ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); + +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + /* Bring the LPCs to Q12 */ + Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); + } +#endif } } @@ -5200,19 +5278,17 @@ void swb_tbe_dec_ivas_fx( { Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ + /* mixFactors_fx in Q15, vind in Q0 */ } ELSE { vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ + /* mixFactors_fx in Q15, vind in Q0 */ } /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ + formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); /* lpc_shb_fx Q12, formant_fac_fx Q15 */ + IF( GT_32( st->total_brate, ACELP_32k ) ) { FOR( j = 0; j < 4; j++ ) @@ -5225,9 +5301,23 @@ void swb_tbe_dec_ivas_fx( /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ +#ifdef HARMONIZE_TBE3 + Word16 sig_len = L_FRAME32k + NL_BUFF_OFFSET; + move16(); + IF( st->element_mode == EVS_MONO ) + { + sig_len = L_FRAME32k; + move16(); + } + + Lmax = 0; + move32(); + FOR( cnt = 0; cnt < sig_len; cnt++ ) // note: this differs from the encoder where the length is always L_FRAME32k +#else Lmax = 0; move32(); FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#endif { Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) ); } @@ -5238,6 +5328,8 @@ void swb_tbe_dec_ivas_fx( move16(); } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); + + /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ find_max_mem_dec( st, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ tmp = add( st->prev_Q_bwe_exc, n_mem ); @@ -5257,20 +5349,35 @@ void swb_tbe_dec_ivas_fx( /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) ); - move16(); - } + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) ); + } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + + /* state_syn_shbexc_fx is kept at (st->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + } + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) ); + move16(); + } + } /* save the previous Q factor (32-bit) of the buffer */ st->prev_Q_bwe_exc = Q_bwe_exc; move16(); Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - /* -------- end of rescaling memories -------- */ Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; @@ -5279,30 +5386,54 @@ void swb_tbe_dec_ivas_fx( Q_shb = 0; move16(); - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + IF( GT_32( st->total_brate, ACELP_32k ) ) + { + FOR( j = 0; j < 4; j++ ) + { + Copy( lpc_shb_fx, &lpc_shb_sf_fx[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); + } + } + + /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the low band ACELP core excitation */ + GenShapedSHBExcitation_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->coder_type, st->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, + shb_res_gshape_fx, shb_res_dummy_fx, &vind, 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, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi ); + } + ELSE +#endif + { + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); #ifdef HARMONIZE_TBE2 - GenShapedSHBExcitation_ivas_fx( DEC, 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->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, - shb_res_gshape_fx, shb_res_dummy_fx, &vind, 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, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, - st->element_mode, st->flag_ACELP16k, nlExc16k_fx, NULL, mixExc16k_fx, NULL, st->extl_brate, MSFlag, - NULL, 0, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); -#else - GenShapedSHBExcitation_ivas_dec_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, + GenShapedSHBExcitation_ivas_fx( DEC, 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->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, shb_res_gshape_fx, shb_res_dummy_fx, &vind, 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, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, - st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, - NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); + st->element_mode, st->flag_ACELP16k, nlExc16k_fx, NULL, mixExc16k_fx, NULL, st->extl_brate, MSFlag, + NULL, 0, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); +#else + GenShapedSHBExcitation_ivas_dec_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->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, + shb_res_gshape_fx, shb_res_dummy_fx, &vind, 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, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, + st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, + NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); #endif + } *Q_white_exc = Q_bwe_exc_fb; move16(); + IF( EQ_16( st->extl, FB_TBE ) ) { hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; @@ -5322,6 +5453,7 @@ void swb_tbe_dec_ivas_fx( hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } + /* fill-in missing SHB excitation */ test(); test(); @@ -5341,8 +5473,13 @@ void swb_tbe_dec_ivas_fx( FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { /* TD BWE post-processing */ +#ifdef HARMONIZE_TBE3 + PostShortTerm_fx( st->element_mode, DEC, &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); +#else PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); +#endif } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ @@ -5375,10 +5512,7 @@ void swb_tbe_dec_ivas_fx( exp = 0; move16(); } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) { FOR( ; i < L_SHB_LAHEAD + 10; i++ ) @@ -5421,6 +5555,13 @@ void swb_tbe_dec_ivas_fx( move16(); L_ener = EPSILON_FX_SMALL; move32(); +#ifdef HARMONIZE_TBE3 + if ( st->element_mode == EVS_MONO ) + { + L_ener = 0; + move32(); + } +#endif FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -5452,10 +5593,32 @@ void swb_tbe_dec_ivas_fx( L_ener = L_add_sat( L_ener, L_shr( ener_tmp_fx[i], 2 ) ); /* 2*Q_bwe_exc */ } } - ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ + } + ELSE +#endif + { + ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ + } + /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + ener_fx = mult( ener_fx, 11587 ); + if ( GT_16( st->tilt_swb_fx, 16384 ) ) + { + st->prev_fractive = 1; + move16(); + } + } + +#endif IF( is_fractive == 0 ) { IF( GT_16( st->tilt_wb_fx, 2048 ) ) /*assuming st->tilt_wb_fx in Q11*/ @@ -5499,10 +5662,22 @@ void swb_tbe_dec_ivas_fx( IF( ener_fx != 0 ) { - L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/ - exp_ener = norm_s( ener_fx ); - tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ - inv_ener = shr( div_s( 16384, tmp ), 1 ); /*Q(15+14-2-exp-1) = 26 - exp*/ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 14 ) ); /* 3+11 +st->Q_syn2 -14 = st->Q_syn2*/ + exp_ener = norm_s( ener_fx ); + tmp = shl( ener_fx, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ + } + ELSE +#endif + { + L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/ + exp_ener = norm_s( ener_fx ); + tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ + inv_ener = shr( div_s( 16384, tmp ), 1 ); /*Q(15+14-2-exp-1) = 26 - exp*/ + } test(); IF( GT_32( L_tmp, st->enerLH_fx ) ) /*st->Q_syn2*/ @@ -5517,8 +5692,17 @@ void swb_tbe_dec_ivas_fx( move16(); /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } - L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + } + ELSE +#endif + { + GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + } } ELSE { @@ -5578,13 +5762,34 @@ void swb_tbe_dec_ivas_fx( { ener_fx = s_max( 1, ener_fx ); exp_ener = norm_s( ener_fx ); - tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/ - prev_ener_ratio_fx = L_shr_sat( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + tmp = shl( ener_fx, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp)*/ + prev_ener_ratio_fx = L_shr_sat( L_mult0( st->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ + } + ELSE +#endif + { + tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/ + prev_ener_ratio_fx = L_shr_sat( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */ + } } IF( EQ_16( st->nbLostCmpt, 1 ) ) { +#ifdef HARMONIZE_TBE3 + Word16 thr_tilt_swb = 4096; + move16(); + if ( st->element_mode == EVS_MONO ) + { + thr_tilt_swb = 16384; + move16(); + } +#endif + test(); test(); test(); @@ -5621,8 +5826,13 @@ void swb_tbe_dec_ivas_fx( GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } } +#ifdef HARMONIZE_TBE3 + ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, thr_tilt_swb ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && + ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) ) +#else ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 4096 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) ) +#endif { GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); } @@ -5770,7 +5980,6 @@ void swb_tbe_dec_ivas_fx( hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); - /* Gain shape smoothing after quantization */ test(); IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) @@ -5824,7 +6033,17 @@ void swb_tbe_dec_ivas_fx( Word16 n_mem3_new = 0; move16(); - find_max_mem_dec_m3( st, &n_mem3_new ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + n_mem3_new = n_mem3; + move16(); + } + ELSE +#endif + { + find_max_mem_dec_m3( st, &n_mem3_new ); + } ScaleShapedSHB_fx( SHB_OVERLAP_LEN, shaped_shb_excitation_fx, /* i/o: Q_bwe_exc */ @@ -5847,10 +6066,23 @@ void swb_tbe_dec_ivas_fx( max_val = 0; move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + FOR( i = 0; i < L_FRAME16k; i++ ) + { + max_val = s_max( max_val, shaped_shb_excitation_fx[i] ); /* Q0 */ + } + } + ELSE +#endif { - max_val = s_max( max_val, abs_s( shaped_shb_excitation_fx[i] ) ); /* Q0 */ + FOR( i = 0; i < L_FRAME16k; i++ ) + { + max_val = s_max( max_val, abs_s( shaped_shb_excitation_fx[i] ) ); /* Q0 */ + } } + IF( max_val == 0 ) { curr_frame_pow_fx = 0; @@ -5905,10 +6137,23 @@ void swb_tbe_dec_ivas_fx( curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; move16(); } + test(); +#ifdef HARMONIZE_TBE3 + IF( !st->bfi && st->prev_bfi ) // note: this is likely a bug in EVS +#else test(); IF( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) ) +#endif { +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + L_tmp = L_shr( curr_frame_pow_fx, 4 ); + L_tmp = Mult_32_16( L_tmp, 17476 ); + } +#endif + test(); test(); IF( ( GT_32( L_shr( curr_frame_pow_fx, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && @@ -6114,16 +6359,57 @@ void swb_tbe_dec_ivas_fx( set16_fx( st->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ } - FOR( i = 0; i < L_FRAME16k; i++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], sub( Q11, Q_bwe_exc ) ); - move32(); + /* rescale the memories if Q_bwe_exc is different from previous frame */ + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn2 ); + IF( sc != 0 ) + { + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) + { + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); + move16(); + } + + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) + { + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); + move32(); + } + } + IF( EQ_32( st->output_Fs, 48000 ) ) + { + Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); + } + IF( EQ_32( st->output_Fs, 16000 ) ) + { + Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); + } + } + + GenSHBSynth_fx( shaped_shb_excitation_fx, error_fx16, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); + + Copy( error_fx16 + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); } + ELSE +#endif + { + FOR( i = 0; i < L_FRAME16k; i++ ) + { + shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], sub( Q11, Q_bwe_exc ) ); + move32(); + } - /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ - GenSHBSynth_fx32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) ); - Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH ); + /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ + GenSHBSynth_fx32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); + + Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) ); + Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH ); + } /* resample SHB synthesis (if needed) and scale down */ synth_scale_fx = 32767; @@ -6149,16 +6435,35 @@ void swb_tbe_dec_ivas_fx( tmp1 = 0; move16(); - Word32 idx32 = L_shr_r( 0x00333333, 10 ); /*NUM_SHB_SUBFR/L_FRAME16k*/ // Q16 - - FOR( i = 0; i < L_FRAME16k; i++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - Word16 idx; - idx = extract_h( imult3216( idx32, i ) ); /*Q0*/ - L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ - move16(); - tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + Word16 idx = 0; + IF( i != 0 ) + { + idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); + } + L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); + tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + } + } + ELSE +#endif + { + Word32 idx32 = L_shr_r( 0x00333333, 10 ); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + Word16 idx; + idx = extract_h( imult3216( idx32, i ) ); /*Q0*/ + L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); + tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + } } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ @@ -6177,45 +6482,114 @@ void swb_tbe_dec_ivas_fx( } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); move16(); + +#ifdef HARMONIZE_TBE3 + test(); + IF( st->element_mode != EVS_MONO && GT_16( *Q_white_exc, Q31 ) ) + { + Scale_sig( White_exc16k_fx, L_FRAME16k, sub( Q31, *Q_white_exc ) ); // Q31 + *Q_white_exc = Q31; + move16(); + } +#endif } - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - FOR( i = 0; i < L_FRAME32k; i++ ) + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { - error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); - move32(); + + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx16[i] = mult_r( error_fx16[i], synth_scale_fx ); + move16(); + } + } + + interpolate_3_over_2_allpass_fx( error_fx16, L_FRAME32k, synth_fx16, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); + } + ELSE +#endif + { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); + move32(); + } } + + interpolate_3_over_2_allpass_fx32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } - interpolate_3_over_2_allpass_fx32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } ELSE IF( EQ_32( st->output_Fs, 32000 ) ) { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - FOR( i = 0; i < L_FRAME32k; i++ ) + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + synth_fx16[i] = mult_r( synth_scale_fx, error_fx16[i] ); + move16(); /*Qx*/ + } + } + ELSE { - synth_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); - move32(); /*Qx*/ + Copy( error_fx16, synth_fx16, L_FRAME32k ); } } ELSE +#endif { - Copy32( error_fx, synth_fx, L_FRAME32k ); + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + synth_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); + move32(); /*Qx*/ + } + } + ELSE + { + Copy32( error_fx, synth_fx, L_FRAME32k ); + } } } ELSE IF( EQ_32( st->output_Fs, 16000 ) ) { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - FOR( i = 0; i < L_FRAME32k; i++ ) + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { - error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); - move32(); + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx16[i] = mult_r( error_fx16[i], synth_scale_fx ); + move16(); + } } + + Decimate_allpass_steep_fx( error_fx16, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth_fx16 ); } + ELSE +#endif + { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); + move32(); + } + } - Decimate_allpass_steep_fx32( error_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, synth_fx ); + Decimate_allpass_steep_fx32( error_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, synth_fx ); + } } /* Update previous frame parameters for FEC */ @@ -6255,5 +6629,13 @@ void swb_tbe_dec_ivas_fx( hBWE_TD->prev_Qx = Q_bwe_exc; move16(); +#ifdef HARMONIZE_TBE3 + if ( Q_synth != NULL ) + { + *Q_synth = Q_bwe_exc; + move16(); + } +#endif + return; } diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 8133da6e55207f654fe6f13695de850d71752a75..e6e934ec8d05b420d37914f4a2062af4af4707b8 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -476,7 +476,11 @@ ivas_error evs_enc_fx( test(); IF( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) { +#ifdef HARMONIZE_TBE3 + swb_tbe_enc_fx( st, NULL, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); +#else swb_tbe_enc_fx( st, st->coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); +#endif IF( EQ_16( st->extl, FB_TBE ) ) { diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 55956600df3ebf63cd1bf0c056022182efa9ec35..60dd1d1a361da888188ac75181f7782be64a7f9b 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -737,7 +737,11 @@ ivas_error ivas_core_enc_fx( Word16 Q_fb_exc; Word16 fb_exc_fx[L_FRAME16k]; +#ifdef HARMONIZE_TBE3 + swb_tbe_enc_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], 0, st->voicing_fx, pitch_buf_fx[n] ); +#else swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], 0, st->voicing_fx, pitch_buf_fx[n] ); +#endif IF( EQ_16( st->extl, FB_TBE ) ) { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 153c24b36f1ef36da4b2ae2f5fc80081308e8533..39748c73c49f8dd0e039da3ec0cc4ffe00112ad4 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -581,6 +581,7 @@ void InitSWBencBufferStates_fx( ); void swb_tbe_enc_fx( +#ifndef HARMONIZE_TBE3 Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ Word16 *new_speech_fx, /* i : original i signal */ @@ -595,17 +596,18 @@ void swb_tbe_enc_fx( ); void swb_tbe_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ - const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ - Word16 *Q_white_exc, - Word16 Q_new, - Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6 */ +#endif + Encoder_State *st_fx, /* i/o: encoder state structure */ + STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ + const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ + Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ + Word16 Q_new, /* i : Q_new */ + Word16 Q_shb, /* i : SHB target Q factor */ + Word16 *voicing, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : subframe pitch Q6 */ ); void tbe_write_bitstream_fx( diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 7e52cca5397ad2ea765de8082d200a3fbe65e789..2a1a5fad91d89d0f9852037e4f1e25e3cc9a10e6 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -299,7 +299,6 @@ static void find_max_mem_wb_enc( Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } - IF( Lmax == 0 ) { n_mem_32 = 31; @@ -1369,6 +1368,7 @@ void fb_tbe_reset_enc_fx( /*======================================================================================*/ void swb_tbe_enc_fx( +#ifndef HARMONIZE_TBE3 Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ @@ -2286,24 +2286,24 @@ void swb_tbe_enc_fx( /*======================================================================================*/ void swb_tbe_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ - const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ - Word16 *Q_white_exc, - Word16 Q_new, - Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6 */ +#endif + Encoder_State *st_fx, /* i/o: encoder state structure */ + STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ + const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ + Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ + Word16 Q_new, /* i : Q_new */ + Word16 Q_shb, /* i : SHB target Q factor */ + Word16 *voicing, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : subframe pitch Q6 */ + ) { Word16 i, j, k, delay; - Word16 shb_old_speech_fx[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; Word32 GainFrame_fx; /* Q18 */ Word16 GainShape_fx[NUM_SHB_SUBFR]; /* Q15 */ @@ -2344,7 +2344,6 @@ void swb_tbe_enc_ivas_fx( Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER]; Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )]; - /*Word32 shb_ener_sf_fx_32[4];*/ Word32 shb_ener_sf_Q31; Word16 shb_res_fx[L_FRAME16k]; Word16 shb_res_gshape_fx[NB_SUBFR16k]; @@ -2352,12 +2351,10 @@ void swb_tbe_enc_ivas_fx( Word16 vf_ind_fx; Word16 formant_fac_fx; - // int16_t stab_check = 1; Word16 MSFlag; Word16 *nlExc16k_fx, *nlExc16k_e, *mixExc16k_fx, *mixExc16k_e; Word16 shaped_shb_excitationTemp_fx[L_FRAME16k]; - Word16 acorr_v2a_fx; /* Q15 */ Word16 acorr_EnvSHBres[ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN], *p_acorr, shb_env_tilt_fx; @@ -2469,15 +2466,31 @@ void swb_tbe_enc_ivas_fx( 0, 1 ); - /* Spectral smoothing of autocorrelation coefficients */ +#ifdef HARMONIZE_TBE3 + const Word16 *p_wac_swb_h, *p_wac_swb_l; + IF( st_fx->element_mode == EVS_MONO ) + { + p_wac_swb_h = wac_swb_h; + p_wac_swb_l = wac_swb_l; + } + ELSE + { + p_wac_swb_h = wac_swb_ivas_h; + p_wac_swb_l = wac_swb_ivas_l; + } +#endif test(); test(); IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { +#ifdef HARMONIZE_TBE3 + L_tmp = Mpy_32( R_h[i], R_l[i], p_wac_swb_h[i - 1], p_wac_swb_l[i - 1] ); +#else L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_ivas_h[i - 1], wac_swb_ivas_l[i - 1] ); +#endif L_Extract( L_tmp, &R_h[i], &R_l[i] ); } } @@ -2499,19 +2512,23 @@ void swb_tbe_enc_ivas_fx( /* if the LP gain is greater than a threshold, avoid saturation */ Word16 flag_sat = 0; - Word16 lpc_shb_fx0_req_shift = sub( norm_s( lpc_shb_fx[0] ), 2 ); - IF( GT_16( lpc_shb_fx0_req_shift, 0 ) ) +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode != EVS_MONO ) +#endif { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) + Word16 lpc_shb_fx0_req_shift = sub( norm_s( lpc_shb_fx[0] ), 2 ); + IF( GT_16( lpc_shb_fx0_req_shift, 0 ) ) { - IF( LT_16( norm_s( lpc_shb_fx[i] ), lpc_shb_fx0_req_shift ) ) + FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { - flag_sat = 1; - break; + IF( LT_16( norm_s( lpc_shb_fx[i] ), lpc_shb_fx0_req_shift ) ) + { + flag_sat = 1; + break; + } } } } - IF( GT_16( enerG, 256 /* 32.0 in Q3 */ ) || flag_sat ) { set16_fx( lpc_shb_fx, 0, LPC_SHB_ORDER + 1 ); @@ -2520,7 +2537,16 @@ void swb_tbe_enc_ivas_fx( } /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ - scale_sig( lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); + } + ELSE +#endif + { + scale_sig( lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); + } /* Expand bandwidth of the LP coeffs */ test(); @@ -2534,8 +2560,6 @@ void swb_tbe_enc_ivas_fx( } } - /* stab_check = a2lsp( lsf_shb, lpc_shb, LPC_SHB_ORDER ); */ - /* LPC to LSP conversion */ /* LPC: Q12, LSP: Q15 */ E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); @@ -2546,7 +2570,12 @@ void swb_tbe_enc_ivas_fx( test(); test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) ) +#else IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) +#endif { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { @@ -2556,11 +2585,6 @@ void swb_tbe_enc_ivas_fx( } } - // if ( stab_check == 0 ) - //{ - // mvr2r( hBWE_TD->prev_lsp_shb, lsf_shb, LPC_SHB_ORDER ); - // } - Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); @@ -2572,7 +2596,16 @@ void swb_tbe_enc_ivas_fx( test(); IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { - lsp_weights_ivas_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); + } + ELSE +#endif + { + lsp_weights_ivas_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); + } /* to compensate for the 1.1* weighting done inside the function lsp_weights */ /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ @@ -2600,7 +2633,16 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ - Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + Quant_BWE_LSF_fx( hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); // this is likely a bug in EVS + } + ELSE +#endif + { + Quant_BWE_LSF_fx( hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); + } } /* space the lsfs to assert a minimum distance */ @@ -2616,9 +2658,9 @@ void swb_tbe_enc_ivas_fx( L_tmp = L_mac( L_tmp, tmp, tmp ); } sd_uq_q_fx = round_fx( L_tmp ); /* sd_uq_q_fx in Q15 */ + /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ /* mean(voice_factors_fx[i], 4); */ - L_tmp = L_mult( voice_factors_fx[0], 8192 ); L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); @@ -2658,11 +2700,11 @@ void swb_tbe_enc_ivas_fx( Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - lsf_diff_fx[0] = lsf_diff_fx[sub( LPC_SHB_ORDER, 1 )] = 16384; /*Q15*/ + lsf_diff_fx[0] = lsf_diff_fx[LPC_SHB_ORDER - 1] = 16384; /*Q15*/ move16(); FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[sub( i, 1 )] ); + lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] ); move16(); } a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl_fx, M ); @@ -2765,12 +2807,9 @@ void swb_tbe_enc_ivas_fx( } /* -------- Calculate the SHB Energy -------- */ - /*shb_ener_sf[0] = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, 320 );*/ FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++ ) { - /* shbEner = shbEner + in[i] * in[i] */ - shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); - /* o: shb_ener_sf_Q31 in (2*Q_shb) */ + shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); /* shb_ener_sf_Q31 in (2*Q_shb) */ } shb_ener_sf_Q31 = Mult_32_16( shb_ener_sf_Q31, 102 /*0.003125f Q15*/ ); shb_ener_sf_Q31 = L_add( 1l /*1 Q0*/, shb_ener_sf_Q31 ); @@ -2782,16 +2821,14 @@ void swb_tbe_enc_ivas_fx( Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); - /* i: shb_frame_fx in Q_shb */ - /* o: shb_res_fx in Q_shb */ + /* shb_frame_fx in Q_shb, shb_res_fx in Q_shb */ set32_fx( shb_res_gshape_fx_32, 0, NB_SUBFR16k ); FOR( i = 0; i < NB_SUBFR16k; i++ ) { - shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i_mult( i, 64 ), 64 ); + shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i_mult( i, 64 ), 64 ); /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ move32(); } - /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ maximum_32_fx( shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp ); @@ -2809,7 +2846,6 @@ void swb_tbe_enc_ivas_fx( exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); recip = div_s( 16384, tmp ); - // Q_recip = sub( 31, sub( exp, 14 ) ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ } @@ -2842,17 +2878,17 @@ void swb_tbe_enc_ivas_fx( Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); } + /* Save the SWB LSP values from current frame for interpolation */ Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ - /* for 13.2 and 16.4kbps */ + + /* convert from lsp to to lpc for SHB synthesis */ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ + formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ /* calculate SHB auto-correlation function and convert to SHB voicing factor */ - // acorr_v2a = 0.0f; L_tmp = 0; move32(); acorr_v2a_fx = 0; @@ -2883,10 +2919,8 @@ void swb_tbe_enc_ivas_fx( move16(); FOR( k = 0; k < 4; k++ ) { - // seg_mean[k] = max(1.0f, mean(&EnvSHBres_4k[k * seg_len], seg_len)); seg_mean[k] = s_max( 1, mean_no_sat_fx( &EnvSHBres_4k_fx[k * seg_len], seg_len ) ); /* Q_shb */ move16(); - // den_seg_mean[k] = 1.0f / seg_mean[k]; tmp = BASOP_Util_Divide1616_Scale( MAX16B, seg_mean[k], &tmp_e ); tmp_e = sub( tmp_e, sub( 15, Q_shb ) ); den_seg_mean[k] = shl_sat( tmp, tmp_e ); /* Q15 */ @@ -2902,7 +2936,6 @@ void swb_tbe_enc_ivas_fx( { env_mean_normf_fx[0] = hBWE_TD->old_mean_EnvSHBres_fx; /* Q15 */ move16(); - // step = (den_seg_mean[0] - hBWE_TD->old_mean_EnvSHBres) * den_seg_len_2; step = mult( sub( den_seg_mean[0], hBWE_TD->old_mean_EnvSHBres_fx ), den_seg_len_2 ); /* Q15 */ FOR( i = 1; i < seg_len_2; i++ ) { @@ -2915,7 +2948,6 @@ void swb_tbe_enc_ivas_fx( p_env = &env_mean_normf_fx[seg_len_2]; FOR( k = 1; k < 4; k++ ) { - // step = ( den_seg_mean[k] - den_seg_mean[k - 1] ) * den_seg_len; step = mult( sub( den_seg_mean[k], den_seg_mean[k - 1] ), den_seg_len ); FOR( i = 0; i < seg_len; i++ ) { @@ -2926,7 +2958,6 @@ void swb_tbe_enc_ivas_fx( } /* last half of the last segment */ - // set_f( p_env, den_seg_mean[3], seg_len_2 ); set16_fx( p_env, den_seg_mean[3], seg_len_2 ); hBWE_TD->old_mean_EnvSHBres_fx = den_seg_mean[3]; move16(); @@ -2964,10 +2995,8 @@ void swb_tbe_enc_ivas_fx( Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); // Q_shb /* calculate energy normalization factor for the auto-correlation function */ - // pow0 = sum2_f( &buf_EnvSHBres[L_FRAME4k], L_FRAME4k ) + 1.0f; pow_e = sub( 15, Q_shb ); pow0_fx = sum2_16_exp_fx( &buf_EnvSHBres_fx[L_FRAME4k], L_FRAME4k, &pow_e, 0 /* Give guard bits */ ) + 1; - // if (hBWE_TD->prev_enr_EnvSHBres == 1.0f) IF( BASOP_Util_Cmp_Mant32Exp( hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e, 1, 31 ) == 0 ) { // scale = 1.0f / pow0; @@ -2976,7 +3005,6 @@ void swb_tbe_enc_ivas_fx( } ELSE { - // scale = 1.0f / max( pow0, hBWE_TD->prev_enr_EnvSHBres ); L_tmp1 = pow0_fx; move32(); IF( BASOP_Util_Cmp_Mant32Exp( L_tmp1, pow_e, hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e ) < 0 ) @@ -3004,7 +3032,6 @@ void swb_tbe_enc_ivas_fx( Word64 W_tmp = 0; move64(); - // tmp = *p_buf; FOR( i = 0; i < L_FRAME4k; ++i ) { L_tmp = L_mult( buf_EnvSHBres_fx[L_FRAME4k + i], p_buf[i] ); // 2 * Q_shb + 1 @@ -3014,7 +3041,6 @@ void swb_tbe_enc_ivas_fx( tmp_e = W_norm( W_tmp ); L_tmp1 = W_extract_h( W_shl( W_tmp, tmp_e ) ); // 2 * Q_shb + tmp_e - 31 L_tmp = Mpy_32_16_1( L_tmp1, scale_fx ); /* 2 * Q_shb + tmp_e - 31 - scale_e */ - //*p_acorr++ = extract_h( L_shl( L_tmp, add( 16, Q_shb ) - ( 2 * Q_shb + tmp_e - 31 - scale_e ) ) ); *p_acorr++ = extract_h( L_shl( L_tmp, sub( add( 16, Q_shb ), sub( sub( add( shl( Q_shb, 1 ), tmp_e ), 31 ), scale_e ) ) ) ); move16(); } @@ -3026,11 +3052,9 @@ void swb_tbe_enc_ivas_fx( /* multiply with the maximum of the SHB autocorrelation function */ maximum_fx( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN, &temp ); - // acorr_v2a *= temp; L_tmp = Mpy_32_16_1( L_tmp, temp ); /* 31 - tmp_e + Q_shb - 15 */ - // alpha = 25.0f; - alpha_fx = -1677721600; // Q26 + alpha_fx = -1677721600; // -25.0 in Q26 move32(); // acorr_v2a = 2.0f / ( 1.0f + (float) expf( -alpha * acorr_v2a ) ) - 1.0f; @@ -3045,8 +3069,6 @@ void swb_tbe_enc_ivas_fx( tmp_e = sub( 31, sub( sub( add( sub( 31, tmp_e ), Q_shb ), 15 ), 5 ) ); - // L_tmp = BASOP_Util_fPow(exp_tmp, exp_e, 2, 31, &res_e); - L_tmp = BASOP_Util_fPow( exp_tmp, exp_e, L_tmp, tmp_e, &res_e ); L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q31, 0, L_tmp, res_e, &tmp_e ); acorr_v2a_fx = BASOP_Util_Divide3232_Scale( 2, L_tmp, &res_e ); @@ -3056,7 +3078,6 @@ void swb_tbe_enc_ivas_fx( res_e = BASOP_Util_Add_MantExp( acorr_v2a_fx, res_e, -1, 15, &acorr_v2a_fx ); /* limit in the range 0.0 - 1.0 */ - // acorr_v2a = min( 1.0f, max( 0.0f, acorr_v2a ) ); acorr_v2a_fx = shl_sat( acorr_v2a_fx, res_e ); if ( acorr_v2a_fx < 0 ) @@ -3071,12 +3092,9 @@ void swb_tbe_enc_ivas_fx( move16(); } - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ vf_ind_fx = 20; move16(); - /* Save the SWB LSP values from current frame for interpolation */ - /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ Lmax = L_deposit_l( 0 ); @@ -3109,12 +3127,30 @@ void swb_tbe_enc_ivas_fx( rescale_genSHB_mem_enc( st_fx, sc ); } - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); - move16(); + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); + + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + move16(); + } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } + ELSE +#endif + { + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); + + /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + move16(); + } } /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ @@ -3130,17 +3166,32 @@ void swb_tbe_enc_ivas_fx( Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; move16(); + /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedSHBExcitation_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, st_fx->element_mode, 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, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 ); + } + ELSE +#endif + { #ifdef HARMONIZE_TBE2 - GenShapedSHBExcitation_ivas_fx( ENC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, + GenShapedSHBExcitation_ivas_fx( ENC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, #else - GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, + GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, #endif - 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, hBWE_TD->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 ); + 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, hBWE_TD->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(); @@ -3197,59 +3248,82 @@ void swb_tbe_enc_ivas_fx( test(); IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { +#ifdef HARMONIZE_TBE3 + PostShortTerm_fx( st_fx->element_mode, ENC, &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); +#else PostShortTerm_ivas_enc_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - /* i: shaped_shb_excitation_fx in Q_bwe_exc */ - /* i: lpc_shb_fx in Q12 */ + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); /* shaped_shb_excitation_fx in Q_bwe_exc, lpc_shb_fx in Q12 */ +#endif } + Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - Word16 max_val; - maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); - IF( max_val == 0 ) - { - Lscale = ONE_IN_Q31; /* 1.0f in Q31 */ - move32(); - IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) - { - Lscale = ONE_IN_Q30; /* sqrtf(0.25) = 0.5 in Q31 */ - move32(); - } - exp = 0; - move16(); - } - ELSE +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - Word64 prev_pow_64fx, curr_pow_64fx; - Word16 w_shift; tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); - prev_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - prev_pow_64fx = W_mac0_16_16( prev_pow_64fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ - curr_pow_64fx = W_mac0_16_16( curr_pow_64fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ } - IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) { /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_64fx = W_shr( curr_pow_64fx, 2 ); /* scale by 0.25 */ + curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ } - w_shift = s_min( W_norm( prev_pow_64fx ), W_norm( curr_pow_64fx ) ); - prev_pow_fx = W_extract_h( W_shl( prev_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 - curr_pow_fx = W_extract_h( W_shl( curr_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 - w_shift = sub( add( shl( Q_bwe_exc, 1 ), w_shift ), 32 ); + Lscale = root_a_over_b_fx( curr_pow_fx, shl( Q_bwe_exc, 1 ), prev_pow_fx, shl( Q_bwe_exc, 1 ), &exp ); + } + ELSE +#endif + { + Word16 max_val; + maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); + IF( max_val == 0 ) + { + Lscale = ONE_IN_Q31; /* 1.0f in Q31 */ + move32(); + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + Lscale = ONE_IN_Q30; /* sqrtf(0.25) = 0.5 in Q31 */ + move32(); + } + exp = 0; + move16(); + } + ELSE + { + Word64 prev_pow_64fx, curr_pow_64fx; + Word16 w_shift; + tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); + prev_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) + { + prev_pow_64fx = W_mac0_16_16( prev_pow_64fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_64fx = W_mac0_16_16( curr_pow_64fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + } + + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ + curr_pow_64fx = W_shr( curr_pow_64fx, 2 ); /* scale by 0.25 */ + } + + w_shift = s_min( W_norm( prev_pow_64fx ), W_norm( curr_pow_64fx ) ); + prev_pow_fx = W_extract_h( W_shl( prev_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 + curr_pow_fx = W_extract_h( W_shl( curr_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 + w_shift = sub( add( shl( Q_bwe_exc, 1 ), w_shift ), 32 ); - Lscale = root_a_over_b_fx( curr_pow_fx, - w_shift, - prev_pow_fx, - w_shift, - &exp ); + Lscale = root_a_over_b_fx( curr_pow_fx, w_shift, prev_pow_fx, w_shift, &exp ); + } } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) @@ -3264,10 +3338,7 @@ void swb_tbe_enc_ivas_fx( exp = 0; move16(); } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { FOR( ; i < L_SHB_LAHEAD + 10; i++ ) @@ -3275,8 +3346,13 @@ void swb_tbe_enc_ivas_fx( tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ tmp = sub( 32767 /*1.0f Q15*/, tmp ); +#ifdef HARMONIZE_TBE3 + Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#else L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#endif shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } @@ -3288,6 +3364,11 @@ void swb_tbe_enc_ivas_fx( tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ tmp = sub( 32767 /*1.0f Q15*/, tmp ); +#ifdef HARMONIZE_TBE3 + // TODO: to be verified, at the decoder there is + // Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 ); + // L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#endif L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ @@ -3310,8 +3391,19 @@ void swb_tbe_enc_ivas_fx( /* Estimate the gain-shape parameter */ n_subfr_saturation = 0; move16(); - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); +#ifdef HARMONIZE_TBE3 + Word16 limit_min_gain = 0; + move16(); + IF( st_fx->element_mode == EVS_MONO ) + { + limit_min_gain = 1; + move16(); + } + + EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, limit_min_gain ); +#else + EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); +#endif test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) @@ -3322,7 +3414,6 @@ void swb_tbe_enc_ivas_fx( IF( GT_16( Env_error_part_fx[i], 100 ) ) { /* set gain shape to the average of the remaining gains */ - // GainShape[i] = ( sum_f( GainShape, NUM_SHB_SUBGAINS ) - GainShape[i] ) / ( NUM_SHB_SUBGAINS - 1 ); L_tmp = L_sub( sum16_32_fx( GainShape_fx, NUM_SHB_SUBGAINS ), GainShape_fx[i] ); tmp = BASOP_Util_Divide3232_Scale( L_tmp, NUM_SHB_SUBGAINS - 1, &exp ); GainShape_fx[i] = shl( tmp, sub( exp, 15 ) ); /* Q15 */ @@ -3340,8 +3431,6 @@ void swb_tbe_enc_ivas_fx( /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ - /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); move16(); } @@ -3365,43 +3454,69 @@ void swb_tbe_enc_ivas_fx( } /* Gain frame adjustment factor */ - /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ - IF( hBWE_TD->prev_swb_GainShape_fx == 0 ) - { - exp = 13 /* norm_s(3) */; - tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; - } - ELSE +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); - } - - L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ + test(); + IF( GainShape_fx[0] && hBWE_TD->prev_swb_GainShape_fx ) + { + exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); + L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ - exp1 = sub( exp, exp1 ); /*move16(); */ - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + } + ELSE + { + temp_swb_fac = 0; + move16(); + } - L_feedback = L_mult( temp_swb_fac, temp_swb_fac ); + L_feedback = L_mult0( temp_swb_fac, temp_swb_fac ); + FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) + { + test(); + IF( GainShape_fx[i] && GainShape_fx[i - 1] ) + { + exp = norm_s( GainShape_fx[i - 1] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ + + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + } + ELSE + { + temp_swb_fac = 0; + move16(); + } - FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) + L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); + } + } + ELSE +#endif { - test(); - IF( GainShape_fx[i - 1] == 0 ) + IF( hBWE_TD->prev_swb_GainShape_fx == 0 ) { exp = 13 /* norm_s(3) */; tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; } ELSE { - exp = norm_s( GainShape_fx[i - 1] ); - tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); } - L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ + + L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ exp1 = norm_l( L_tmp ); frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); @@ -3409,7 +3524,31 @@ void swb_tbe_enc_ivas_fx( L_tmp = Mpy_32_16( exp1, frac, 22713 ); temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); + L_feedback = L_mult( temp_swb_fac, temp_swb_fac ); + + FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) + { + test(); + IF( GainShape_fx[i - 1] == 0 ) + { + exp = 13 /* norm_s(3) */; + tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; + } + ELSE + { + exp = norm_s( GainShape_fx[i - 1] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + } + L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ + + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + + L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); + } } /* feedback = 0.4f / (1 + 0.5f * feedback) */ @@ -3429,14 +3568,23 @@ void swb_tbe_enc_ivas_fx( move16(); /*Q15 */ } - /* calculate tilt in all sub-frame gains */ - Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); - lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + GainShape_tilt_fx = 0; // just to avoid compilation warnings + move16(); + } + ELSE +#endif + { + /* calculate tilt in all sub-frame gains */ + Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); + lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); + } test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - // if (acorr_v2a < 0.4f && vf_ind >= 5 && fabs(GainShape_tilt) < 0.2f && shb_env_tilt < 500.0f && hBWE_TD->prev_shb_env_tilt < 500.0f) test(); test(); test(); @@ -3444,14 +3592,11 @@ void swb_tbe_enc_ivas_fx( IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_Q_shb ) ) ) { /* stronger smoothing in case of unvoiced SHB residual signal with gaussian excitation */ - // feedback = lin_interp(acorr_v2a, 0.4f, 0.0f, 0.0f, 0.95f, 0); feedback = lin_interp_ivas_fx( acorr_v2a_fx, 13107 /* 0.4f in Q15 */, 0, 0, 31130 /* 0.95f in Q15 */, 0 ); - // feedback = min( max( feedback, 0.0f ), 1.0f ); feedback = s_min( s_max( feedback, 0 ), MAX16B ); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - // GainShape[i] = ( 1 - feedback ) * GainShape[i] + feedback * GainShape_Interp[i]; GainShape_fx[i] = extract_h( L_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i] ), feedback, GainShape_Interp_fx[i] ) ); move16(); } @@ -3473,7 +3618,6 @@ void swb_tbe_enc_ivas_fx( L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ - test(); test(); IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 /* 2.4f in Q13 */ ) && GT_16( tmp1, 6554 /* 0.8f in Q13 */ ) ) ) @@ -3496,7 +3640,6 @@ void swb_tbe_enc_ivas_fx( IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { /* Re-normalize gain shape before quantization */ - // sum_gain = sum2_f(GainShape, NUM_SHB_SUBGAINS); tmp = 0; move16(); sum_gain_fx = sum2_16_exp_fx( GainShape_fx, NUM_SHB_SUBGAINS, &tmp, 2 ); @@ -3507,11 +3650,9 @@ void swb_tbe_enc_ivas_fx( } ELSE { - // normFact = (float) sqrt( 1.0f / sum_gain ); normFact_fx = ISqrt32( sum_gain_fx, &tmp ); } - // v_multc( GainShape, normFact, GainShape, NUM_SHB_SUBGAINS ); FOR( i = 0; i < NUM_SHB_SUBGAINS; ++i ) { GainShape_fx[i] = extract_h( L_shl( Mpy_32_16_1( normFact_fx, GainShape_fx[i] ), tmp ) ); /* Q15 */ @@ -3556,16 +3697,13 @@ void swb_tbe_enc_ivas_fx( lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); - // if ( vf_ind >= 6 && fabs( GainShape_tilt ) < 0.12f ) test(); IF( GE_16( vf_ind_fx, 6 ) && LT_16( abs_s( GainShape_tilt_fx ), 3932 /* 0.12f in Q15 */ ) ) { - // feedback = 0.3f; feedback = 9830; /* 0.3f in Q15 */ move16(); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - // GainShape[i] = ( 1 - feedback ) * GainShape[i * NUM_SHB_SUBGAINS] + feedback * GainShape_Interp[i]; GainShape_fx[i] = extract_h( L_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), feedback, GainShape_Interp_fx[i] ) ); // Q15 move16(); } @@ -3579,8 +3717,7 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ - EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, - GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -3595,7 +3732,6 @@ void swb_tbe_enc_ivas_fx( GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ } - // if ( st_fx->element_mode > EVS_MONO && st_fx->L_frame != st_fx->last_L_frame && hBWE_TD->prev_gainFr_SHB != 0 && ( st_fx->last_extl == SWB_TBE || st_fx->last_extl == FB_TBE ) && st_fx->coder_type == TRANSITION && st_fx->coder_type_raw != VOICED && st_fx->clas == VOICED_CLAS && st_fx->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st_fx->L_frame >> 6 ) - 1] ) ) test(); test(); test(); @@ -3607,13 +3743,10 @@ void swb_tbe_enc_ivas_fx( test(); IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->L_frame, st_fx->last_L_frame ) && hBWE_TD->prev_gainFr_SHB_fx != 0 && ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->coder_type, TRANSITION ) && NE_16( st_fx->coder_type_raw, VOICED ) && EQ_16( st_fx->clas, VOICED_CLAS ) && EQ_16( st_fx->last_clas, VOICED_CLAS ) && LT_16( mult( 24576 /* 3.0f in Q13 */, voice_factors_fx[0] ), shr( voice_factors_fx[( st_fx->L_frame >> 6 ) - 1], 2 ) ) ) { - // float fac = GainFrame / hBWE_TD->prev_gainFr_SHB; Word16 fac = BASOP_Util_Divide3232_Scale( GainFrame_fx, hBWE_TD->prev_gainFr_SHB_fx, &tmp_e ); - // if ( fac > 4.0f ) IF( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( fac ), tmp_e, 1073741824, 3 ) > 0 ) { - // GainFrame = 4.0f * GainFrame / fac; GainFrame_fx = BASOP_Util_Divide3216_Scale( GainFrame_fx, fac, &tmp1_e ); GainFrame_fx = L_shl( GainFrame_fx, add( tmp1_e, 2 ) ); /* Q18 */ } @@ -3622,33 +3755,25 @@ void swb_tbe_enc_ivas_fx( test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - // if ( acorr_v2a > 0.1f && Env_error > 5.0f ) test(); test(); IF( GT_16( acorr_v2a_fx, 3277 /* 0.1f in Q15 */ ) && GT_16( Env_error_fx, 5 ) ) { /* attenuate frame gain in case of voiced SHB residual signal with gaussian excitation */ - // fact_atten = lin_interp( Env_error, 5.0f, 1.0f, 25.0f, 0.2f, 1 ); fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 5, MAX16B, 25, 6554 /* 0.2f in Q15 */, 1 ); - // GainFrame *= fact_atten; GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); } /* Frame gain attenuation in case of big error in envelope modelling */ - // else if ( Env_error > 100.0f || hBWE_TD->prev_Env_error > 100.0f ) ELSE IF( GT_16( Env_error_fx, 100 ) || GT_16( hBWE_TD->prev_Env_error_fx, 100 ) ) { - // if ( Env_error > 100.0f ) IF( GT_16( Env_error_fx, 100 ) ) { - // fact_atten = lin_interp( Env_error, 100.0f, 1.0f, 300.0f, 0.1f, 1 ); fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 100, MAX16B, 300, 3277 /* 0.1f in Q15 */, 1 ); } ELSE { - // fact_atten = lin_interp( hBWE_TD->prev_Env_error, 100.0f, 1.0f, 300.0f, 0.5f, 1 ); fact_atten_fx = lin_interp_ivas_fx( hBWE_TD->prev_Env_error_fx, 100, MAX16B, 300, ONE_IN_Q14 /* 0.5f in Q15 */, 1 ); } - // GainFrame *= fact_atten; GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); } } @@ -3677,17 +3802,25 @@ void swb_tbe_enc_ivas_fx( ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) { /*GainFrame *= (0.8f + 0.5f*feedback); */ - tmp = add( 13107 /* 0.8 in Q14 */, shr( feedback, 2 ) ); - GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, tmp ), 1 ); /* Q18 */ +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + tmp = add( 26214, mult_r( feedback, 16384 ) ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ + } + ELSE +#endif + { + tmp = add( 13107 /* 0.8 in Q14 */, shr( feedback, 2 ) ); + GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, tmp ), 1 ); /* Q18 */ + } } hBWE_TD->prev_frGainAtten = frGainAttenuate; move16(); - hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; move16(); /* Q18 */ - // if ( GainFrame > 153.0f && st_fx->element_mode >= IVAS_CPE_DFT && hStereoICBWE != NULL ) test(); test(); if ( GT_32( GainFrame_fx, 40108032 /* 153.0f in Q18 */ ) && GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) @@ -3702,7 +3835,6 @@ void swb_tbe_enc_ivas_fx( test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - // sd_uq_q = 1 - 0.7f * ( sd_uq_q * sd_uq_q ); tmp1 = mult_r( 22938 /*0.7f Q15*/, tmp ); /* Q15, Q6 => Q6 */ L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ } @@ -3744,22 +3876,43 @@ void swb_tbe_enc_ivas_fx( } voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ - // if ( voicingBufAvg <= 0.0f && sd_uq_q * pitBufAvg != 0 ) - test(); - IF( voicingBufAvg_fx <= 0 && Mpy_32_16_1( L_tmp, pitBufAvg_fx ) != 0 ) +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - // voicingBufAvg = sd_uq_q * pitBufAvg / 1.001f; - tmp = BASOP_Util_Divide1616_Scale( pitBufAvg_fx, 16400, &tmp_e ); - tmp_e = sub( add( tmp_e, 5 ), 1 ); - L_tmp1 = Mpy_32_16_1( L_tmp, tmp ); - voicingBufAvg_fx = extract_h( L_tmp1 ); + /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ + /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ + + /* 1/voicingBufAvg_fx */ + tmp = 32767; + move16(); + IF( voicingBufAvg_fx > 0 ) + { + exp = norm_s( voicingBufAvg_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ + + /* sd_uq_q*pitBufAvg */ + L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ + tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ + } } - // else if ( voicingBufAvg <= 0.0f ) - ELSE IF( voicingBufAvg_fx <= 0 ) + ELSE +#endif { - // voicingBufAvg = 1.0f; - voicingBufAvg_fx = MAX16B; - move16(); + test(); + IF( voicingBufAvg_fx <= 0 && Mpy_32_16_1( L_tmp, pitBufAvg_fx ) != 0 ) + { + // voicingBufAvg = sd_uq_q * pitBufAvg / 1.001f; + tmp = BASOP_Util_Divide1616_Scale( pitBufAvg_fx, 16400, &tmp_e ); + tmp_e = sub( add( tmp_e, 5 ), 1 ); + L_tmp1 = Mpy_32_16_1( L_tmp, tmp ); + voicingBufAvg_fx = extract_h( L_tmp1 ); + } + ELSE IF( voicingBufAvg_fx <= 0 ) + { + voicingBufAvg_fx = MAX16B; + move16(); + } } } @@ -3769,7 +3922,6 @@ void swb_tbe_enc_ivas_fx( { IF( st_fx->bwidth_sw_cnt > 0 ) { - // GainFrame *= ( (float) ( st_fx->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD ); tmp = i_mult( st_fx->bwidth_sw_cnt, ONE_BY_BWS_TRAN_PERIOD_Q15 ); GainFrame_fx = Mpy_32_16_1( GainFrame_fx, tmp ); } @@ -3777,9 +3929,19 @@ void swb_tbe_enc_ivas_fx( /* Controlled gain evolution in SWB for stronger voiced segments */ test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode == EVS_MONO ) + { + tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); + tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ + } + ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { - // GainFrame *= sd_uq_q; GainFrame_fx = Mpy_32_16_1( GainFrame_fx, extract_l( L_shl( L_tmp, 2 ) ) ); } ELSE @@ -3810,8 +3972,7 @@ void swb_tbe_enc_ivas_fx( if ( EQ_16( st_fx->rf_mode, 1 ) ) { /* Compensate for energy increase mismatch due to memory-less synthesis */ - // GainFrame *= 0.85f; - GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 ); + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 /*0.85f Q15*/ ); } } ELSE @@ -3820,12 +3981,21 @@ void swb_tbe_enc_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) { /* Compensate for energy increase mismatch due to memory-less synthesis*/ - GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ } } /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); + } + ELSE +#endif + { + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); + } IF( hStereoICBWE != NULL ) { @@ -3859,14 +4029,9 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ - /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ move16(); - /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); - /*White_exc16k_fx[i] =32767;*/ - /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ move16(); @@ -4278,15 +4443,15 @@ static Word32 pow_off_pk_corrected_fx( /*--------------------------------------------------------------------------*/ static void EstimateSHBGainShape_fx( - const Word16 length, /* i : SHB overlap length */ - const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ - const Word16 Q_oriSHB, /* i : Q of target original SHB frame */ - const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ - const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ - Word16 *subgain, /* o : estimate of gain shape Q15 */ - const Word16 *subwin, /* i : SHB subframe window Q15 */ - Word16 *n_subfr_saturation, /* o : Number of subframes which saturated while calculating oriNrg */ - const Flag limit_min_gain /* i : gain shape limiting flag */ + const Word16 length, /* i : SHB overlap length */ + const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ + const Word16 Q_oriSHB, /* i : Q of target original SHB frame */ + const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ + const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ + Word16 *subgain, /* o : estimate of gain shape Q15 */ + const Word16 *subwin, /* i : SHB subframe window Q15 */ + Word16 *n_subfr_saturation, /* o : Number of subframes which saturated while calculating oriNrg */ + const Flag limit_min_gain /* i : gain shape limiting flag */ ) { const Word16 *skip; @@ -4542,11 +4707,11 @@ static void EstimateSHBGainShape_fx( /*--------------------------------------------------------------------------*/ static Word16 closest_centroid_fx( - const Word16 *data, /* i : input data Qx*/ - const Word16 *weights, /* i : weights */ - const Word16 *quantizer, /* i : quantizer table Qx*/ - const Word16 centroids, /* i : number of centroids */ - const Word16 length ) /* i : dimension of quantiser */ + const Word16 *data, /* i : input data Qx */ + const Word16 *weights, /* i : weights */ + const Word16 *quantizer, /* i : quantizer table Qx */ + const Word16 centroids, /* i : number of centroids */ + const Word16 length ) /* i : dimension of quantiser */ { Word16 i, j, index; Word16 tmp, tmpL; @@ -4651,9 +4816,9 @@ static Word16 closest_centroid_lc_fx( /*------------------------------------------------------------*/ static void QuantizeSHBsubgains_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 subgains[], /* i/o: super highband temporal gains Q15*/ - const Word16 extl /* i : extension layer */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 subgains[], /* i/o: super highband temporal gains Q15 */ + const Word16 extl /* i : extension layer */ ) { Word16 i, idxSubGain; @@ -5153,9 +5318,10 @@ return; /*------------------------------------------------------------*/ static void determine_gain_weights_fx( - const Word32 *gain, /* i : Gain parameter Q18 */ - Word16 *weights, /* o : gain weights Q12/Q6*/ - const Word16 dims /* i : number of gains */ ) + const Word32 *gain, /* i : Gain parameter Q18 */ + Word16 *weights, /* o : gain weights Q12/Q6*/ + const Word16 dims /* i : number of gains */ +) { Word16 j; Word16 exp, exp1, frac, tmp, exp2; @@ -5218,13 +5384,13 @@ static void determine_gain_weights_fx( /*------------------------------------------------------------------------------*/ static void singlevectortest_gain_fx( - const Word32 *inp, /* i : input gain vector Q18*/ - const Word16 dimen, /* i : dimension of the input vector */ - const Word16 cb_size, /* i : codebook size */ - Word16 *index, /* o : quanitzation index */ - Word32 *recon, /* o : Reconstruction Q18 */ - const Word32 *codebook - /* i : Codebook Q18*/ ) + const Word32 *inp, /* i : input gain vector Q18*/ + const Word16 dimen, /* i : dimension of the input vector */ + const Word16 cb_size, /* i : codebook size */ + Word16 *index, /* o : quanitzation index */ + Word32 *recon, /* o : Reconstruction Q18 */ + const Word32 *codebook /* i : Codebook Q18*/ +) { Word16 k, interNum, flag; Word32 meanU, meanQ; @@ -5366,9 +5532,9 @@ static void return_M_Least_fx_GainFrame( *-------------------------------------------------------------------*/ static void Quant_lower_LSF_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ - Word16 lsf_q[], /* o : Quantized LSFs Q15 */ - Word16 lsf_idx[] /* o : Quantized LSFs indices */ + const Word16 lsf[], /* i : Input LSFs Q15 */ + Word16 lsf_q[], /* o : Quantized LSFs Q15 */ + Word16 lsf_idx[] /* o : Quantized LSFs indices */ ) { Word16 i; @@ -5392,9 +5558,9 @@ static void Quant_lower_LSF_fx( *-------------------------------------------------------------------*/ static Word16 Quant_mirror_point_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ - const Word16 lsf_q[], /* i : Quantized LSFs Q15 */ - Word16 *m /* o : Mirror point Q15 */ + const Word16 lsf[], /* i : Input LSFs Q15 */ + const Word16 lsf_q[], /* i : Quantized LSFs Q15 */ + Word16 *m /* o : Mirror point Q15 */ ) { Word16 m_diff; @@ -5418,9 +5584,9 @@ static Word16 Quant_mirror_point_fx( *-------------------------------------------------------------------*/ static Word16 Find_LSF_grid_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ - Word16 lsf_q[], /* o : Quantized LSFs Q15 */ - const Word16 m /* i : Mirror point Q15 */ + const Word16 lsf[], /* i : Input LSFs Q15 */ + Word16 lsf_q[], /* o : Quantized LSFs Q15 */ + const Word16 m /* i : Mirror point Q15 */ ) { Word16 lsf_map[NUM_MAP_LSF]; @@ -5438,7 +5604,6 @@ static Word16 Find_LSF_grid_fx( Word16 tmp, exp, tmp1; Word32 L_tmp; - tmp = shl( m, 1 ); lsf_map[0] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 0] ); move16(); @@ -5451,7 +5616,6 @@ static Word16 Find_LSF_grid_fx( lsf_map[4] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 4] ); move16(); - IF( GT_16( m, MAX_LSF_FX_2 ) ) { offset = lsf_map[0]; @@ -5666,6 +5830,7 @@ static void gainFrSmooth_En_fx( return; } + #define MAXINT32 MAX_32 static void first_VQstages_fx( const Word16 *const *cb, @@ -6041,8 +6206,8 @@ static void Quant_BWE_LSF_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 codec_mode, /* i : codec mode */ - const Word16 lsf_shb_fx[], /* i : unquanitzed LSFs Q15 */ - Word16 Q_lsfs_fx[], /* o : quanitzed LSFs Q15 */ + const Word16 lsf_shb_fx[], /* i : unquanitzed LSFs Q15 */ + Word16 Q_lsfs_fx[], /* o : quanitzed LSFs Q15 */ const Word32 extl_brate /* i : extension layer bit rate */ ) { @@ -6114,6 +6279,7 @@ static void Quant_BWE_LSF_fx( return; } + /*-------------------------------------------------------------------* * fb_tbe_enc() * @@ -6364,14 +6530,13 @@ void fb_tbe_enc_fx( *---------------------------------------------------------------------*/ void tbe_write_bitstream_fx( - Encoder_State *st_fx /* i/o: encoder state structure */ + Encoder_State *st_fx /* i/o: encoder state structure */ ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - test(); test(); test();