diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index 2cd92db53b115961fabecaa5f4e1fb03a7e723e9..97fef62e561de5286b4cdce624a393e7d7c33d80 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -2791,6 +2791,7 @@ void DoRTFTn_fx_ivas( return; } +#ifndef HQ_ALIGN_DUPLICATED_CODE void fft3_fx_ivas( const Word32 X[], // Qx Word32 Y[], // Qx @@ -3287,7 +3288,7 @@ void ifft3_fx_ivas( return; } - +#endif static void rfft_post( const Word16 *sine_table, // Q15 diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index c93c6a20e7b0b50854347a7dfc8567579a0c5bb1..31ee54b8659416e61fb3a1b5b4ceb3a95c8faca9 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -2640,7 +2640,22 @@ void enforce_zero_for_min_envelope_fx( return; } +#ifdef HQ_ALIGN_DUPLICATED_CODE +/*--------------------------------------------------------------------------* + * apply_envelope() + * + * Apply spectral envelope without envelope adjustments and noisefill + *--------------------------------------------------------------------------*/ +void apply_envelope_enc_fx( + const Word16 *coeff, /* i : Normalized spectrum Q12 */ + const Word16 *norm, /* i : Envelope Q0 */ + const Word16 num_sfm, /* i : Total number of bands Q0 */ + const Word16 *sfm_start, /* i : Sub band start indices Q0 */ + const Word16 *sfm_end, /* i : Sub band end indices Q0 */ + Word32 *coeff_out /* o : scaled spectrum Q12 */ +) +#else /*--------------------------------------------------------------------------* * apply_envelope() * @@ -2655,6 +2670,7 @@ void apply_envelope_enc_ivas_fx( const Word16 *sfm_end, /* i : Sub band end indices Q0 */ Word32 *coeff_out /* o : coded/noisefilled spectrum Q12 */ ) +#endif { Word16 i; Word16 sfm; @@ -2680,11 +2696,19 @@ void apply_envelope_enc_ivas_fx( } +#ifdef HQ_ALIGN_DUPLICATED_CODE +/*--------------------------------------------------------------------------* + * apply_envelope_fx() + * + * Apply spectral envelope with envelope adjustments + *--------------------------------------------------------------------------*/ +#else /*--------------------------------------------------------------------------* * apply_envelope() * * Apply spectral envelope with envelope adjustments *--------------------------------------------------------------------------*/ +#endif void apply_envelope_fx( const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 68133ea6ecb379e73db3ea05fc477ffe1c9ac9cd..f0d4e8ec1f38bd02fe2987c132b0eb73a7e3627d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2722,14 +2722,15 @@ void ivas_param_mc_metadata_open_fx( HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ ); +#ifndef HQ_ALIGN_DUPLICATED_CODE Word16 mdct_classifier_ivas_fx( Encoder_State *st, /* i/o: Encoder state variable */ const Word16 *fft_buff, /* i : FFT spectrum from fft_rel */ const Word32 enerBuffer[], /* i : energy buffer */ - Word16 enerBuffer_exp, /* i: enenrgy buffer exponent */ + Word16 enerBuffer_exp, /* i : energy buffer exponent */ const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ); - +#endif /*----------------------------------------------------------------------------------* * Range Coder prototypes diff --git a/lib_com/options.h b/lib_com/options.h index a2f711f063268ed88eff4ce9e8e187ee4b541741..a84960578f2c49978155881263149f2ffdc7cbbd 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,6 +91,7 @@ #define HARM_2456_APPLY_SCALE /* FhG basop issue 2456: Harmonize apply_scale_ind(), apply_scale_ivas_fx() */ #define HARM_2454_TCX_RES_Q_SPEC /* FhG: harmonization of tcx_res_Q_spec_fx() and tcx_res_Q_spec_ivas_fx() */ #define FIX_FLOAT_1535_ARI_RES_Q_CLEANUP /* FhG: remove dead code from tcx_ari_res_Q_spec() */ +#define HQ_ALIGN_DUPLICATED_CODE /* Eri: Align duplicated code */ #define FIX_2467_RENAME_GSC_FUNCTION /* VA: basop issue 2467: Removal of unused function/table and renaming of _ivas_fx versions to default ones. */ #define HARMONIZE_FUNC /* VA: basop issue 2460: Remove duplicated code: various functions */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 7ec2fdc57498235475a7dbe41e40c7d2afd047fc..5a38408cf7934a84cfd0997662cdb5242b2ba94a 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -735,6 +735,16 @@ void enforce_zero_for_min_envelope_fx( const Word16 *sfm_end /* i : Sub band end indices Q0 */ ); +#ifdef HQ_ALIGN_DUPLICATED_CODE +void apply_envelope_enc_fx( + const Word16 *coeff, /* i : Normalized spectrum Q12 */ + const Word16 *norm, /* i : Envelope Q0 */ + const Word16 num_sfm, /* i : Total number of bands Q0 */ + const Word16 *sfm_start, /* i : Sub band start indices Q0 */ + const Word16 *sfm_end, /* i : Sub band end indices Q0 */ + Word32 *coeff_out /* o : scaled spectrum Q12 */ +); +#else void apply_envelope_enc_ivas_fx( const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ const Word16 *norm, /* i : Envelope Q0 */ @@ -743,6 +753,7 @@ void apply_envelope_enc_ivas_fx( const Word16 *sfm_end, /* i : Sub band end indices Q0 */ Word32 *coeff_out /* o : coded/noisefilled spectrum Q12 */ ); +#endif void apply_envelope_fx( const Word16 *coeff, /* i : Coded/noisefilled normalized spectrum Q12 */ @@ -4285,7 +4296,7 @@ void ifft3_fx( const Word16[], Word16[], const Word16 ); - +#ifndef HQ_ALIGN_DUPLICATED_CODE void fft3_fx_ivas( const Word32 X[], Word32 Y[], @@ -4294,6 +4305,7 @@ void ifft3_fx_ivas( const Word32 X[], Word32 Y[], const Word16 n ); +#endif void r_fft_fx_lc( const Word16 *phs_tbl, /* i : Table of phase */ @@ -7601,6 +7613,31 @@ void stat_noise_uv_dec_fx( const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ); +#ifdef HQ_ALIGN_DUPLICATED_CODE +void stat_noise_uv_mod_fx( + const Word16 element_mode, /* i : element mode */ + const Word16 coder_type, /* i : Coder type */ + Word16 noisiness, /* i : noisiness parameter Q=0 */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ + Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + const Word16 bfi, /* i : Bad frame indicator */ + Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP Q=15*/ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ + Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : i bandwidth */ + Word16 *Q_stat_noise, /* i/o: noise scaling */ + Word16 *Q_stat_noise_ge /* i/o: noise scaling */ +); +#else void stat_noise_uv_mod_fx( const Word16 coder_type, /* i : Coder type */ Word16 noisiness, /* i : noisiness parameter Q0 */ @@ -7646,6 +7683,7 @@ void stat_noise_uv_mod_ivas_fx( Word16 *Q_stat_noise, /* i/o: noise scaling */ Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ); +#endif Word16 FEC_SinOnset_fx( Word16 *exc, /* i/o : exc vector to modify */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 33c5545ce37b4036d4da03314b713530fd1d6377..7db32531abf88c12bb666a4b9eb9a22eaa16c9e4 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -28,13 +28,38 @@ Word32 L_Sqrt_Q0( const Word32 x ); * Modifies excitation signal in stationary noise segments *--------------------------------------------------------------------*/ +#ifdef HQ_ALIGN_DUPLICATED_CODE void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ + const Word16 element_mode, /* i : element mode */ + const Word16 coder_type, /* i : Coder type */ + Word16 noisiness, /* i : noisiness parameter Q=0 */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ + Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + const Word16 bfi, /* i : Bad frame indicator */ + Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP Q=15*/ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ + Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : i bandwidth */ + Word16 *Q_stat_noise, /* i/o: noise scaling */ + Word16 *Q_stat_noise_ge /* i/o: noise scaling */ +) +#else +void stat_noise_uv_mod_fx( + const Word16 coder_type, /* i : Coder type */ Word16 noisiness, /* i : noisiness parameter Q0 */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15 */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15*/ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15*/ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15*/ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12*/ Word16 *exc2, /* i/o: excitation buffer Q_exc */ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ @@ -50,6 +75,7 @@ void stat_noise_uv_mod_fx( Word16 *Q_stat_noise, /* i/o: noise scaling */ Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ) +#endif { Word16 exctilt; /* Q15 */ Word32 vare; /* Q31 */ @@ -63,6 +89,9 @@ void stat_noise_uv_mod_fx( Word16 newlsp_mix[M]; Word16 beta; /* Q15 */ Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ +#ifdef HQ_ALIGN_DUPLICATED_CODE + Word32 L_Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ +#endif /* noimix_fax * x <-> x + Noimix_fract * x */ Word16 i_subfr; Word16 i, k; @@ -74,6 +103,9 @@ void stat_noise_uv_mod_fx( Word16 En_shift, Tmp; Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ +#ifdef HQ_ALIGN_DUPLICATED_CODE + Word32 L_Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ +#endif /*---------------------------------------------------------* * Init local variables @@ -82,6 +114,10 @@ void stat_noise_uv_mod_fx( move16(); min_alpha = 16384; move16(); +#ifdef HQ_ALIGN_DUPLICATED_CODE + L_Noimix_fract = 0; + move32(); +#endif test(); test(); @@ -98,15 +134,23 @@ void stat_noise_uv_mod_fx( tmp_den = 31; move16(); tmp_shift = norm_s( tmp_den ); +#ifndef HQ_ALIGN_DUPLICATED_CODE move16(); +#endif L_tmp_res = L_deposit_h( noisiness ); L_tmp_res = L_shl( L_tmp_res, sub( tmp_shift, 1 ) ); tmp_den = shl( tmp_den, tmp_shift ); +#ifndef HQ_ALIGN_DUPLICATED_CODE move16(); +#endif tmp_res = div_l( L_tmp_res, tmp_den ); +#ifndef HQ_ALIGN_DUPLICATED_CODE move16(); +#endif min_alpha = add_sat( tmp_res, 16384 ); +#ifndef HQ_ALIGN_DUPLICATED_CODE move16(); +#endif /**st_min_alpha = sub(*st_min_alpha, 1638); move16();*/ min_alpha = s_max( min_alpha, sub( *st_min_alpha, 1638 ) ); @@ -128,9 +172,17 @@ void stat_noise_uv_mod_fx( Copy( exc2, Exc2_local, L_FRAME ); /* bound Q for internal use, optimization possible */ +#ifdef HQ_ALIGN_DUPLICATED_CODE + Q_local = s_min( 11, s_max( -1, *Q_exc ) ); +#else Q_local = s_min( 11, s_max( -1, Q_exc ) ); +#endif /* local excitation Q and incoming excitation Q*/ +#ifdef HQ_ALIGN_DUPLICATED_CODE + Qdiff = sub( Q_local, *Q_exc ); +#else Qdiff = sub( Q_local, Q_exc ); +#endif /* only shift if incoming Q is outside [11..-1] shift is done in energy calculations aswell */ Scale_sig( Exc2_local, L_FRAME, Qdiff ); /* current excitation Q and previous stat_noise states Q */ @@ -229,14 +281,30 @@ void stat_noise_uv_mod_fx( L_tmp_res = L_mac( 0, alpha, alpha ); L_tmp_res = L_mac( L_tmp_res, alpha_m1, alpha_m1 ); tmp_den = round_fx( L_Frac_sqrtQ31( L_tmp_res ) ); - +#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( element_mode, EVS_MONO ) ) + { + tmp_nom = sub( 32767, tmp_den ); + tmp_shift = norm_s( tmp_den ); + tmp_den = shl( tmp_den, tmp_shift ); + tmp_res = div_s( tmp_nom, tmp_den ); + Noimix_fract = shr( tmp_res, tmp_shift ); /* float value is in range 0.0 to 0.42 */ + } + ELSE + { + Word16 exp_sqr = 0; + move16(); + tmp_res = BASOP_Util_Divide1616_Scale( 32767, tmp_den, &exp_sqr ); // 15-exp_sqr + Noimix_fract = tmp_res; // 15-exp_sqr + move16(); + } +#else tmp_nom = sub( 32767, tmp_den ); tmp_shift = norm_s( tmp_den ); tmp_den = shl( tmp_den, tmp_shift ); tmp_res = div_s( tmp_nom, tmp_den ); - Noimix_fract = shr( tmp_res, tmp_shift ); /* float value is in range 0.0 to 0.42 */ - +#endif /* L_Ge might be 0 in unvoiced WB */ L_Ge = L_max( L_Ge, 1 ); tmp_shift = norm_l( L_Ge ); @@ -245,8 +313,20 @@ void stat_noise_uv_mod_fx( L_tmp_res = Mult_32_16( *ge_sm, tmp_res ); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ L_tmp_res = Mult_32_16( L_tmp_res, sub( 32767, beta ) ); /*30-Q_local-tmp_shift+15-15 */ L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ - tmp_res = extract_h( L_shl_sat( L_tmp_res, 15 ) ); /* 15+15-16=14 */ - Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ +#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( element_mode, EVS_MONO ) ) + { + tmp_res = extract_h( L_shl_sat( L_tmp_res, 15 ) ); /* 15+15-16=14 */ + Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ + } + ELSE + { + L_Noimix_fract = Mult_32_16( L_tmp_res, Noimix_fract ); /*15+15-exp_sqr-15 =15-exp_sqr */ + } +#else + tmp_res = extract_h( L_shl_sat( L_tmp_res, 15 ) ); /* 15+15-16=14 */ + Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ +#endif FOR( i = 0; i < L_FRAME; i++ ) { @@ -258,23 +338,70 @@ void stat_noise_uv_mod_fx( *--------------------------------------------------------------------*/ /* (1-alpha)*(float)sqrt(12.0f) * ((float)own_random(&(st->noimix_seed))/65536.0f) */ - randval = Random( noimix_seed ); /* +/-32767 */ - randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ + randval = Random( noimix_seed ); /* +/-32767 */ + randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ +#ifdef HQ_ALIGN_DUPLICATED_CODE + randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), sub( 1, *Q_stat_noise_ge ) ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ +#else randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), 1 - *Q_stat_noise_ge ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ +#endif + L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ + L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ - L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ - L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ +#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( element_mode, EVS_MONO ) ) + { + L_tmp3 = Mult_32_16( L_tmp, Noimix_fract ); /* Q_local+16+15-15 */ + L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ + Exc2_local[i] = extract_h( L_tmp ); /*Q_local */ + move16(); + } + ELSE + { + L_tmp3 = Mult_32_32( L_tmp, L_Noimix_fract ); /* Q_local+16+15-exp_sqr-15 =Q_local +1 */ + L_Exc2_local[i] = L_add( L_shr( L_tmp3, 1 ), Mpy_32_32( L_tmp, L_tmp_res ) ); // Q_local + 16 +15 -31 = Q_local + move32(); + } +#else L_tmp3 = Mult_32_16( L_tmp, Noimix_fract ); /* Q_local+16+15-15 */ L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ Exc2_local[i] = extract_h( L_tmp ); /*Q_local */ move16(); +#endif + } +#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( element_mode, EVS_MONO ) ) + { + *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ + move16(); + Qdiff = sub( *Q_exc, Q_local ); /* local excitation and incoming excitation */ + Scale_sig( Exc2_local, L_FRAME, Qdiff ); + Copy( Exc2_local, exc2, L_FRAME ); + } + ELSE + { + Word32 max_val; + maximum_abs_32_fx( L_Exc2_local, L_FRAME, &max_val ); + Word16 shift = 0; + move16(); + IF( GT_32( max_val, ONE_IN_Q15 ) ) + { + shift = norm_l( max_val ); + shift = sub( Q31 - Q15, shift ); + *Q_exc = sub( Q_local, shift ); // Q_exc = Q_local -shift + move16(); + } + *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ + move16(); + Copy_Scale_sig_32_16( L_Exc2_local, exc2, L_FRAME, negate( shift ) ); // Q_exc } +#else *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ move16(); Qdiff = sub( Q_exc, Q_local ); /* local excitation and incoming excitation */ Scale_sig( Exc2_local, L_FRAME, Qdiff ); Copy( Exc2_local, exc2, L_FRAME ); - +#endif /*--------------------------------------------------------------------* * Generate low-pass filtered version of ISP coefficients *--------------------------------------------------------------------*/ @@ -324,6 +451,8 @@ void stat_noise_uv_mod_fx( } } } + +#ifndef HQ_ALIGN_DUPLICATED_CODE /*--------------------------------------------------------------------* * stat_noise_uv_mod() * @@ -629,6 +758,7 @@ void stat_noise_uv_mod_ivas_fx( } } } +#endif /*---------------------------------------------------------------------------* * calc_tilt() diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 40b8be983c5482258884b36f2904bbf86f6a1acc..8c9beae1080bdf0b95c7bf26cbff891516c89cc0 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1443,9 +1443,15 @@ ivas_error acelp_core_dec_fx( IF( NE_16( st->nelp_mode_dec, 1 ) ) { /* modify the excitation signal of stationary unvoiced frames */ +#ifdef HQ_ALIGN_DUPLICATED_CODE + stat_noise_uv_mod_fx( st->element_mode, st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, &st->Q_exc, 1, &st->ge_sm_fx, + &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, + &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); +#else stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); +#endif } } diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index 6972e4dd3bb8d90aedc26354a21d5b55d59e5e8c..ff8d8d1c1e9a327c4dae4888083b770fe9a6b7c0 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -76,6 +76,13 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { +#ifdef HQ_ALIGN_DUPLICATED_CODE + stat_noise_uv_mod_fx( st_fx->element_mode, coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, + &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + +#else IF( st_fx->element_mode > EVS_MONO ) { stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, @@ -90,6 +97,7 @@ void stat_noise_uv_dec_fx( &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); } +#endif } diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 7a7b4ef59d11c970274a9eaa1baf8b1cbfddec07..2df22bdc8b97a6e1bc2d4f2e6bececc80e06423e 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -833,7 +833,12 @@ ivas_error acelp_core_enc_fx( IF( NE_16( nelp_mode, 1 ) ) { Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new +#ifdef HQ_ALIGN_DUPLICATED_CODE + Word16 q_exc2 = Q_new; + stat_noise_uv_enc_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); +#else stat_noise_uv_enc_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new ); +#endif } } ELSE @@ -847,7 +852,11 @@ ivas_error acelp_core_enc_fx( Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new Word16 q_exc2 = Q_new; move16(); +#ifdef HQ_ALIGN_DUPLICATED_CODE + stat_noise_uv_enc_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); +#else stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); +#endif } } diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 5c290fe7c9fb27dfda1bcd5e4398381d57437608..b2d7b417531fb78bdf1c456abc5f0e451a666be7 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -530,7 +530,11 @@ void hq_hr_enc_ivas_fx( { IF( NE_16( hqswb_clas, HQ_HVQ ) ) { +#ifdef HQ_ALIGN_DUPLICATED_CODE + apply_envelope_enc_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); +#else apply_envelope_enc_ivas_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); +#endif scale_sig32( t_audio_q_fx, length, sub( Q12, Q_audio ) ); // Q12 } diff --git a/lib_enc/ivas_decision_matrix_enc_fx.c b/lib_enc/ivas_decision_matrix_enc_fx.c index 79448bd19be0fd79461feb378067270014c7b822..adb69a98889a2b36c231f1620c799985f3aec45f 100644 --- a/lib_enc/ivas_decision_matrix_enc_fx.c +++ b/lib_enc/ivas_decision_matrix_enc_fx.c @@ -36,7 +36,9 @@ #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" /* Function prototypes */ - +#ifdef HQ_ALIGN_DUPLICATED_CODE +#include "prot_fx_enc.h" +#endif /*-----------------------------------------------------------------* * ivas_decision_matrix_enc() @@ -189,7 +191,11 @@ void ivas_decision_matrix_enc_fx( ELSE { /* select TCX core or HQ core using bits_frame_nominal to match the TCX configuration bitrate */ +#ifdef HQ_ALIGN_DUPLICATED_CODE + st->core = mdct_classifier_fx( st, fft_buff, enerBuffer, enerBuffer_exp, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */ +#else st->core = mdct_classifier_ivas_fx( st, fft_buff, enerBuffer, enerBuffer_exp, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */ +#endif move16(); } } diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index 11c4fcb4bda653572572e5c0cb85c1aa4793e7f4..8c1f697bf7e6f6fdec18abd4896652459dd843dd 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -9,7 +9,6 @@ #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ #include "ivas_prot_fx.h" /* Function prototypes */ /*--------------------------------------------------------------------------* @@ -81,7 +80,7 @@ static void dft_mag_square_fx( return; } - +#ifndef HQ_ALIGN_DUPLICATED_CODE /*-------------------------------------------------------------------* * mdct_classifier() * @@ -504,13 +503,17 @@ Word16 mdct_classifier_fx( return clas_final; /* Q0 */ } - +#endif +#ifdef HQ_ALIGN_DUPLICATED_CODE +Word16 mdct_classifier_fx( +#else Word16 mdct_classifier_ivas_fx( +#endif Encoder_State *st, /* i/o: Encoder state variable */ const Word16 *fft_buff, /* i : FFT spectrum from fft_rel */ - const Word32 enerBuffer[], /* i : energy buffer enerBuffer_exp*/ - Word16 enerBuffer_exp, - const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ + const Word32 enerBuffer[], /* i : energy buffer */ + Word16 enerBuffer_exp, /* i : energy buffer exponent */ + const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ) { Word16 c; @@ -545,7 +548,11 @@ Word16 mdct_classifier_ivas_fx( move16(); test(); +#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) || EQ_16( st->element_mode, EVS_MONO ) ) +#else IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) +#endif { gain2_start = GAIN2_START_SWB; gain3_start = GAIN3_START_SWB; @@ -759,6 +766,40 @@ Word16 mdct_classifier_ivas_fx( } } +#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + peak_H1 = L_add( enerBuffer[H1_start], 0 ); + Mpy_32_16_ss( enerBuffer[H1_start], 6554 /*0.4.Q15*/, &avrg_H1, &lsb16 ); + FOR( k = 1; k < 5; k++ ) + { + IF( GT_32( enerBuffer[H1_start + k], peak_H1 ) ) + { + peak_H1 = L_add( enerBuffer[H1_start + k], 0 ); + } + avrg_H1 = L_add( avrg_H1, Mult_32_16( enerBuffer[H1_start + k], 6554 /*0.4.Q15*/ ) ); + } + } + ELSE + { + // Todo (EN): This is introduced for IVAS, but looks strange + peak_H1 = enerBuffer[H1_start]; // enerBuffer_exp + move32(); + + avrg_H1 = enerBuffer[H1_start]; // enerBuffer_exp + move32(); + + FOR( i = 1; i < H_length; i++ ) + { + IF( GT_32( enerBuffer[H1_start + i], peak_H1 ) ) + { + peak_H1 = enerBuffer[H1_start + i]; // enerBuffer_exp + move32(); + } + avrg_H1 = L_add( avrg_H1, enerBuffer[H1_start + i] ); // enerBuffer_exp + } + } +#else peak_H1 = enerBuffer[H1_start]; // enerBuffer_exp move32(); @@ -774,7 +815,42 @@ Word16 mdct_classifier_ivas_fx( } avrg_H1 = L_add( avrg_H1, enerBuffer[H1_start + i] ); // enerBuffer_exp } +#endif + +#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + peak_H2 = L_add( enerBuffer[H2_start], 0 ); + Mpy_32_16_ss( enerBuffer[H2_start], 6554 /*0.4.Q15*/, &avrg_H2, &lsb16 ); + FOR( i = 1; i < H_length; i++ ) + { + IF( GT_32( enerBuffer[H2_start + i], peak_H2 ) ) + { + peak_H2 = L_add( enerBuffer[H2_start + i], 0 ); + } + avrg_H2 = L_add( avrg_H2, Mult_32_16( enerBuffer[H2_start + i], 6554 /*0.4.Q15*/ ) ); + } + } + ELSE + { + // Todo (EN): This is introduced for IVAS, but looks strange + peak_H2 = enerBuffer[H2_start]; + move32(); + avrg_H2 = enerBuffer[H2_start]; + move32(); + + FOR( i = 1; i < H_length; i++ ) + { + IF( GT_32( enerBuffer[H2_start + i], peak_H2 ) ) + { + peak_H2 = enerBuffer[H2_start + i]; + move32(); + } + avrg_H2 = L_add( avrg_H2, enerBuffer[H2_start + i] ); + } + } +#else peak_H2 = enerBuffer[H2_start]; move32(); @@ -790,7 +866,7 @@ Word16 mdct_classifier_ivas_fx( } avrg_H2 = L_add( avrg_H2, enerBuffer[H2_start + i] ); } - +#endif peak_l = L_deposit_l( 0 ); avrg_l = L_deposit_l( 0 ); peak_h = L_deposit_l( 0 ); @@ -1011,7 +1087,12 @@ Word16 mdct_classifier_ivas_fx( test(); test(); test(); +#ifdef HQ_ALIGN_DUPLICATED_CODE + test(); + if ( ( EQ_16( st->mdct_sw_enable, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) && ( EQ_16( st->flag_noisy_speech_snr, 1 ) || st->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) +#else if ( EQ_16( st->mdct_sw_enable, MODE2 || st->element_mode > EVS_MONO ) && ( EQ_16( st->flag_noisy_speech_snr, 1 ) || st->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) +#endif { clas_final = TCX_20_CORE; move16(); diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 671fb4615bb24e71d4c6c7284c7b1e4f5ddabb1d..1ffbd25612cb467a29b4ee789a45cf3a76004d43 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -785,7 +785,11 @@ void pre_proc_fx( IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && EQ_32( st->total_brate, ACELP_32k ) ) { /* Select MDCT Core */ +#ifdef HQ_ALIGN_DUPLICATED_CODE + st->core = mdct_classifier_fx( st, fft_buff, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); +#else st->core = mdct_classifier_fx( fft_buff, st, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); +#endif } test(); IF( ( EQ_32( st->total_brate, ACELP_13k20 ) ) && ( NE_16( st->bwidth, FB ) ) ) @@ -1226,7 +1230,11 @@ void pre_proc_fx( test(); IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && EQ_32( st->total_brate, ACELP_24k40 ) ) { +#ifdef HQ_ALIGN_DUPLICATED_CODE + st->core = mdct_classifier_fx( st, fft_buff, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); +#else st->core = mdct_classifier_fx( fft_buff, st, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); +#endif } test(); IF( ( EQ_32( st->total_brate, ACELP_16k40 ) ) && ( NE_16( st->bwidth, FB ) ) ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d4b0dfbb1ee119d90cceb2bcb3e62b144f005e28..8fde3603485e02e617074e4a4b253a67232b5493 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -244,14 +244,24 @@ void ivas_long_enr_fx( const Word16 Etot_LR[] /* i : total channel energy LR channels Q=8*/ ); +#ifdef HQ_ALIGN_DUPLICATED_CODE +Word16 mdct_classifier_fx( + Encoder_State *st, /* i/o: Encoder state variable */ + const Word16 *fft_buff, /* i : FFT spectrum from fft_rel */ + const Word32 enerBuffer[], /* i : energy buffer */ + Word16 enerBuffer_exp, /* i : energy buffer exponent */ + const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ +); +#else /* o: MDCT A/B decision */ Word16 mdct_classifier_fx( const Word16 *Y, /* i : re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Encoder_State *st_fx, /* i/o: Encoder state variable */ + Encoder_State *st_fx, /* i/o: Encoder state variable */ Word32 *cldfbBuf_Ener, Word16 enerBuffer_exp, - const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ + const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ); +#endif void noise_est_down_fx( const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) */ @@ -1820,6 +1830,17 @@ void encod_audio_fx( const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ ); +#ifdef HQ_ALIGN_DUPLICATED_CODE +void stat_noise_uv_enc_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word32 *LepsP, /* i : LP prediction errors */ + const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ + const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ + Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ + Word16 *exc2, /* i/o: excitation buffer */ + const Word16 uc_two_stage_flag, /* o : flag indicating two-stage UC */ + Word16 *Q_new ); +#else void stat_noise_uv_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors */ @@ -1829,7 +1850,8 @@ void stat_noise_uv_enc_fx( Word16 *exc2, /* i/o: excitation buffer */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ Word16 Q_new ); - +#endif +#ifndef HQ_ALIGN_DUPLICATED_CODE void stat_noise_uv_enc_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors Q=Qx*/ @@ -1839,6 +1861,7 @@ void stat_noise_uv_enc_ivas_fx( Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ Word16 *Q_new ); +#endif void analy_sp_fx( const Word16 element_mode, /* i : element mode */ diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index 126e5cf8e2a63c6b37f53f29b04bc9ffb2d358e2..07d124ece983201bf7f95747f1a140499034bcdd 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -36,6 +36,17 @@ /* _ None */ /*=======================================================================*/ +#ifdef HQ_ALIGN_DUPLICATED_CODE +void stat_noise_uv_enc_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word32 *LepsP, /* i : LP prediction errors */ + const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ + const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ + Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ + Word16 *exc2, /* i/o: excitation buffer */ + const Word16 uc_two_stage_flag, /* o : flag indicating two-stage UC */ + Word16 *Q_new ) +#else void stat_noise_uv_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors */ @@ -45,6 +56,7 @@ void stat_noise_uv_enc_fx( Word16 *exc2, /* i/o: excitation buffer */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ Word16 Q_new ) +#endif { Word16 noisiness = 0; move16(); @@ -97,15 +109,21 @@ void stat_noise_uv_enc_fx( * Modify the stationary noise excitation signal *-----------------------------------------------------------------*/ +#ifdef HQ_ALIGN_DUPLICATED_CODE + stat_noise_uv_mod_fx( st_fx->element_mode, st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, + st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); +#else stat_noise_uv_mod_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); +#endif return; } - +#ifndef HQ_ALIGN_DUPLICATED_CODE void stat_noise_uv_enc_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors Q=Qx*/ @@ -167,10 +185,17 @@ void stat_noise_uv_enc_ivas_fx( * Modify the stationary noise excitation signal *-----------------------------------------------------------------*/ +#ifdef HQ_ALIGN_DUPLICATED_CODE + stat_noise_uv_mod_fx( st_fx->element_mode, st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, + st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); +#else stat_noise_uv_mod_ivas_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); +#endif return; } +#endif