From 1dda7b9e5fc6cd12202f8a37194ac93fe69f2908 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:54:04 +0100 Subject: [PATCH 01/20] [cleanup] accept FIX_1904_HARM_GSC_ENC --- lib_com/gs_gains_fx.c | 53 --- lib_com/gs_inact_switching_fx.c | 12 - lib_com/gs_noisefill_fx.c | 394 ---------------- lib_com/gs_preech_fx.c | 116 ----- lib_com/options.h | 1 - lib_com/prot_fx.h | 83 ---- lib_dec/gs_dec_fx.c | 11 - lib_dec/ivas_td_low_rate_dec_fx.c | 4 - lib_enc/acelp_core_enc_fx.c | 4 - lib_enc/enc_pit_exc_fx.c | 520 --------------------- lib_enc/eval_pit_contr_fx.c | 369 --------------- lib_enc/gs_enc_fx.c | 737 ------------------------------ lib_enc/ivas_td_low_rate_enc_fx.c | 8 - lib_enc/prot_fx_enc.h | 52 --- 14 files changed, 2364 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 3f4edb7ff..c99b28bf7 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -343,12 +343,8 @@ void Ener_per_band_comp_fx( Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */ const Word16 Q_exc, /* i : frame length */ const Word16 Mband, /* i : Max band */ -#ifdef FIX_1904_HARM_GSC_ENC const Word16 Eflag, /* i : flag of highest band */ const Word16 L_frame /* i : frame length */ -#else - const Word16 Eflag /* i : flag of highest band */ -#endif ) { const Word16 *pt_fx; @@ -376,7 +372,6 @@ void Ener_per_band_comp_fx( pt_fx += 32; } -#ifdef FIX_1904_HARM_GSC_ENC IF( EQ_16( L_frame, L_FRAME16k ) ) { y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ @@ -384,57 +379,9 @@ void Ener_per_band_comp_fx( y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/ move16(); } -#endif return; } -#ifndef FIX_1904_HARM_GSC_ENC -void Ener_per_band_comp_ivas_fx( - const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ - Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */ - const Word16 Q_exc, /* i : frame length */ - const Word16 Mband, /* i : Max band */ - const Word16 Eflag, /* i : flag of highest band */ - const Word16 L_frame /* i : frame length */ -) -{ - const Word16 *pt_fx; - Word16 j; - - pt_fx = exc_diff_fx; - FOR( j = 0; j < 2; j++ ) - { - y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); /*Q12*/ - move16(); - pt_fx += 8; - } - - FOR( j = 1; j < Mband - 2; j++ ) - { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); /*Q12*/ - move16(); - pt_fx += 16; - } - - IF( EQ_16( Eflag, 1 ) ) - { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ - move16(); - pt_fx += 32; - } - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ - move16(); - y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/ - move16(); - pt_fx += 64; - } - - return; -} -#endif /*-------------------------------------------------------------------* diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index a8d2aa682..d00b8e3c0 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -77,11 +77,7 @@ void Inac_switch_ematch_fx( test(); IF( ( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) ) ) && bfi == 0 ) { -#ifdef FIX_1904_HARM_GSC_ENC Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); -#else - Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); -#endif /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) @@ -95,11 +91,7 @@ void Inac_switch_ematch_fx( /* Find spectrum and energy per band for GC and VC frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); -#ifdef FIX_1904_HARM_GSC_ENC Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); -#else - Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); -#endif /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) @@ -113,11 +105,7 @@ void Inac_switch_ematch_fx( /* Find spectrum and energy per band for inactive frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); -#ifdef FIX_1904_HARM_GSC_ENC Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); -#else - Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); -#endif /* More agressive smoothing in the first 50 frames */ pt_exc = dct_exc_tmp; diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 800a9c3be..0cc5b96c0 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -636,395 +636,9 @@ static void envelop_modify_fx( return; } -#ifndef FIX_1904_HARM_GSC_ENC -void highband_exc_dct_in_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *mfreq_bindiv, /* i : bin per bands tables */ - Word16 last_bin, /* i : last bin of bit allocation */ - Word16 Diff_len, /* i : number of bin before cut-off frequency */ - Word16 noise_lev, /* i : pulses dynamic */ - Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 *exc_diffQ, /* i : frequency coefficients of per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ - Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *exc_dct_in, /* o : dct of residual signal */ - Word16 last_coder_type, /* i : coding type of last frame */ - Word16 *bitallocation_band, /* i : bit allocation flag of each band */ - const Word16 *lsf_new, /* i : LSFs at the end of the frame */ - Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16 *last_ener, /* i : frequency energy of last frame */ - Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ - Word16 bfi, /* i : bad frame indicator */ - const Word16 coder_type, /* i : coder type */ - Word16 bwidth, - Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ - Word16 Qexc_diffQ, - Word16 Q_exc, - const Word16 GSC_noisy_speech, - Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -) -{ - Word16 i, j, k; - Word16 MAX_Bin = 0; - Word16 last_bin_tmp, ener = 0; - move16(); - Word16 noisepb[MBANDS_GN16k]; - Word16 Ener_per_bd_yQ[MBANDS_GN16k]; - Word16 *src, *dst; - Word32 L_tmp; - Word16 length_bin, bwe_flag = 0, tmp; - move16(); - Word16 frac, exp, tmp1; - Word16 tmp2; - Word16 *end, Q_hb_exc; - - FOR( j = 10; j < MBANDS_GN; j++ ) - { - /* ener += (float)pow(10, Ener_per_bd_iQ[j]); - ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */ - - L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q27 to Q16 */ - - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp = sub( exp, 14 ); - tmp1 = shl_sat( tmp, exp ); - move16(); - ener = add_sat( tmp1, ener ); /*Q0 */ - } - - test(); - IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) - { - if ( NE_16( last_coder_type, AUDIO ) ) - { - *last_ener = ener; - move16(); - } - test(); - test(); - IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) ) - { - MAX_Bin = 10; - move16(); - bwe_flag = 1; - move16(); - } - ELSE - { - MAX_Bin = 15; - move16(); - } - - last_bin_tmp = last_bin; - move16(); - last_bin = s_max( last_bin, MAX_Bin ); - last_bin = add( last_bin, 1 ); - } - ELSE - { - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - last_bin = MBANDS_GN16k; - move16(); - } - ELSE - { - last_bin = MBANDS_GN; - move16(); - } - last_bin_tmp = last_bin; - move16(); - } - - test(); - test(); - test(); - test(); - IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) ) - { - set16_fx( noisepb, 13107, last_bin ); /*0.4 in Q15 */ - } - ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) ) - { - set16_fx( noisepb, 13107 /*0.4f*/, last_bin ); - } - ELSE - { - EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame ); - } - - IF( exc_wo_nf != NULL ) - { - Copy( exc_diffQ, exc_wo_nf, L_frame ); - } - - test(); - test(); - test(); - IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) - { - set16_fx( noisepb, 3277, last_bin ); - } - test(); - IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) ) - { - FOR( i = 0; i < L_frame; i++ ) - { - IF( exc_diffQ[i] == 0 ) - { - /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/ - tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */ - tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */ - exc_diffQ[i] = add( exc_diffQ[i], tmp ); - move16(); /*Q */ - } - } - } - ELSE - { - Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ ); - } - /*--------------------------------------------------------------------------------------* - * Quantize average gain - * Subtract Q averaged gain - * VQ of remaining gain per band - *--------------------------------------------------------------------------------------*/ - test(); - IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) - { -#ifdef FIX_1904_HARM_GSC_ENC - Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); -#else - Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 ); -#endif - } - ELSE - { -#ifdef FIX_1904_HARM_GSC_ENC - Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); -#else - Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 ); -#endif - IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) - { - FOR( i = L_FRAME - 16; i < L_FRAME; i++ ) - { - /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */ - tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ - L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */ - exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */ - move16(); - } - } - } - /*--------------------------------------------------------------------------------------* - * Check potential energy excitation overshoot - *--------------------------------------------------------------------------------------*/ - IF( bfi ) - { - test(); - IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */ - { - FOR( i = 0; i < last_bin; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( sub( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - FOR( ; i < MBANDS_GN; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < last_bin; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - FOR( ; i < MBANDS_GN; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - } - } - /*--------------------------------------------------------------------------------------* - * Apply decoded gain onto the difference signal - *--------------------------------------------------------------------------------------*/ - - IF( GSC_noisy_speech ) - { - FOR( i = 0; i < L_frame; i++ ) - { - exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 ); - move16(); - } - } - - Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc ); - - IF( exc_wo_nf != NULL ) - { - Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, Q_exc ); - Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); - } - /*--------------------------------------------------------------------------------------* - * add the correction layer to the LF bins, - * and add the quantized pulses or the noise for the higher part of the spectrum - * (non valuable temporal content already zeroed) - * DC is Zeroed - *--------------------------------------------------------------------------------------*/ - - Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame ); - test(); - IF( core_brate == ACELP_8k00 && bwidth != NB ) - { - IF( EQ_16( bwe_flag, 1 ) ) - { - last_bin = sub( last_bin, 1 ); - tmp = i_mult( MAX_Bin, 16 ); - tmp1 = i_mult( last_bin, 16 ); - src = &exc_diffQ[L_FRAME - 1]; - move16(); - dst = &exc_dct_in[( tmp - 1 )]; - move16(); - end = &exc_diffQ[( tmp1 - 1 )]; - move16(); - - WHILE( src > end ) - { - *src-- = *dst--; - move16(); - } - test(); - test(); - if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) ) - { - exc_diffQ[160] = 0; - move16(); - } - - Q_hb_exc = 0; - move16(); - envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc ); - Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */ - } - IF( LT_16( nb_subfr, 4 ) ) - { - FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ ) - { - /*exc_dct_in[i] *= (0.067f*i-15.f); */ - tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ - tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ - L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ - exc_dct_in[i] = round_fx_sat( L_shl_sat( L_tmp, 6 ) ); /*Q_exc */ - } - } - - tmp1 = mult_r( ener, 16384 ); - tmp1 = sub( *last_ener, tmp1 ); - tmp = mult_r( *last_ener, 16384 ); - tmp = sub( ener, tmp ); - test(); - IF( tmp > 0 && tmp1 > 0 ) - { - length_bin = 6; - move16(); - IF( last_coder_type != AUDIO ) - { - set16_fx( last_bitallocation_band, 0, 6 ); - Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 ); - } - FOR( i = 4; i < ( 4 + length_bin ); i++ ) - { - test(); - IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) ) - { - k = shl( add( i, length_bin ), 4 ); - src = &exc_dct_in[k]; /*(i+length_bin)*16*/ - dst = &last_exc_dct_in[k]; - FOR( j = 0; j < 16; j++ ) - { - tmp = mult_r( 10923, abs_s( *src ) ); - tmp1 = mult_r( 10923, abs_s( *dst ) ); - - IF( GT_16( tmp, abs_s( *dst ) ) ) - { - tmp2 = *src; - *src = mult_r( 16384, sub_sat( *src, abs_s( *dst ) ) ); /*Q_exc */ - move16(); - tmp = mult_r( 16384, add_sat( tmp2, abs_s( *dst ) ) ); /*Q_exc */ - if ( tmp2 > 0 ) - { - *src = tmp; - move16(); - } - } - ELSE IF( GT_16( tmp1, abs_s( *src ) ) ) - { - tmp = mult_r( *src, 22938 ); - tmp1 = mult_r( 9830, abs_s( *dst ) ); - tmp2 = *src; - *src = sub( tmp, tmp1 ); /*Q_exc */ - move16(); - if ( tmp2 > 0 ) - { - *src = add( tmp, tmp1 ); /*Q_exc */ - move16(); - } - } - src++; - dst++; - } - } - } - } - IF( EQ_16( bwe_flag, 1 ) ) - { - Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 ); - } - ELSE - { - Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 ); - } - } - - Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 ); - Copy( &bitallocation_band[4], last_bitallocation_band, 6 ); - *last_ener = ener; - move16(); - - return; -} -#endif - - -#ifdef FIX_1904_HARM_GSC_ENC void highband_exc_dct_in_fx( -#else -void highband_exc_dct_in_ivas_fx( -#endif const Word32 core_brate, /* i : core bitrate */ const Word16 *mfreq_bindiv, /* i : bin per bands tables */ Word16 last_bin, /* i : last bin of bit allocation */ @@ -1194,19 +808,11 @@ void highband_exc_dct_in_ivas_fx( test(); IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) { -#ifdef FIX_1904_HARM_GSC_ENC Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); -#else - Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); -#endif } ELSE { -#ifdef FIX_1904_HARM_GSC_ENC Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); -#else - Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); -#endif test(); IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) diff --git a/lib_com/gs_preech_fx.c b/lib_com/gs_preech_fx.c index c496a3777..5f2ab3b3e 100644 --- a/lib_com/gs_preech_fx.c +++ b/lib_com/gs_preech_fx.c @@ -56,12 +56,8 @@ void pre_echo_att_fx( const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, const Word16 last_coder_type, /* i : Last coding mode Q0*/ -#ifdef FIX_1904_HARM_GSC_ENC const Word16 L_frame, /* i : Frame length Q0*/ const Word16 element_mode /* i : Current IVAS element mode*/ -#else - const Word16 L_frame /* i : Frame length Q0*/ -#endif ) { Word32 etmp_fx; @@ -73,9 +69,7 @@ void pre_echo_att_fx( Word16 tmp, n1, n2, exp, frac1, frac2; Word32 etmp1_fx; Word16 att_len; -#ifdef FIX_1904_HARM_GSC_ENC Word16 etmp_e, tmp_e; -#endif test(); IF( gsc_attack_flag_fx > 0 && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */ @@ -115,7 +109,6 @@ void pre_echo_att_fx( IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 ) { /* Find the average energy before the attack */ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( element_mode, EVS_MONO ) ) /* This could be harmonized with EVS, but won't be BE */ { etmp_fx = sum32_fx( finc_fx, attack_pos_fx ); @@ -133,7 +126,6 @@ void pre_echo_att_fx( ratio_fx = shr_sat( tmp, sub( 2, tmp_e ) ); /* Q13 */ } ELSE -#endif { L_tmp = sum32_fx( finc_fx, attack_pos_fx ); /*Q1 */ L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */ @@ -180,7 +172,6 @@ void pre_echo_att_fx( * In normal cases, just compute the energy of the frame *-------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( element_mode, EVS_MONO ) ) /* This could be harmonized with EVS, but won't be BE */ { Word16 exp_etmp = sub( 15, Q_new ); @@ -193,7 +184,6 @@ void pre_echo_att_fx( *Last_frame_ener_fx = L_shl( etmp_fx, sub( shl( Q_new, 1 ), sub( 30 /*31-1*/, exp_etmp ) ) ); /*2*Q_new+1*/ } ELSE -#endif { etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */ etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ @@ -204,109 +194,3 @@ void pre_echo_att_fx( return; } -#ifndef FIX_1904_HARM_GSC_ENC -void pre_echo_att_ivas_fx( - Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ - const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode Q0*/ - const Word16 L_frame /* i : Frame length Q0*/ -) -{ - Word32 etmp_fx; - Word32 finc_fx[ATT_LENGHT16k] = { 0 }; - move16(); - Word16 ratio_fx; - Word16 attack_pos_fx, i; - Word32 L_tmp; - Word16 tmp, tmp_e; - Word32 etmp1_fx; - Word16 etmp_e; - Word16 att_len; - - test(); - IF( gsc_attack_flag_fx > 0 && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */ - { - /*-------------------------------------------------------------------------* - * Find where the onset (attack) occurs by computing the energy per section - * The inverse weighting aims to favor the first maxima in case of - * gradual onset - *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; /* Q0 */ - move16(); - if ( EQ_16( L_frame, L_FRAME16k ) ) - { - att_len = ATT_LENGHT16k; /* Q0 */ - move16(); - } - FOR( i = 0; i < att_len; i++ ) - { - L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ - finc_fx[i] = L_tmp; - move32(); /*2*Q_new+1 */ - } - - attack_pos_fx = maximum_32_fx( finc_fx, att_len, &etmp_fx ); - - /* Scaled the maximum energy and allowed 6 dB increase*/ - etmp_fx = L_shr( etmp_fx, add( 2 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */ - etmp1_fx = etmp_fx; - move32(); - *Last_frame_ener_fx = L_shl_sat( *Last_frame_ener_fx, 2 ); - move32(); /*2*Q_new+1 */ - - /* If the maximum normalized energy > last frame energy + 6dB */ - test(); - IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 ) - { - /* Find the average energy before the attack */ - etmp_fx = sum32_fx( finc_fx, attack_pos_fx ); - etmp_e = sub( 31, add( shl( Q_new, 1 ), 1 ) ); - etmp_fx = L_add( etmp_fx, L_shr( 21474836 /*0.01 in Q31*/, etmp_e ) ); /* etmp = etmp + 0.01; (exp = etmp_e) */ - etmp_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( etmp_fx, L_mult0( attack_pos_fx, ATT_SEG_LEN ), &tmp_e ) ); - tmp_e = add( tmp_e, sub( etmp_e, 31 ) ); - etmp_e = tmp_e; - move16(); - - /* Find the correction factor and apply it before the attack */ - tmp = BASOP_Util_Divide3232_Scale( *Last_frame_ener_fx, etmp_fx, &tmp_e ); /* numerator Q = 2 * Q_new + 1; denominator Q = 31 - tmp_e */ - tmp_e = add( tmp_e, sub( sub( 31, etmp_e ), add( shl( Q_new, 1 ), 1 ) ) ); /* tmp_e = tmp_e + (31 - tmp_e) - (2 * Q_new + 1) */ - tmp = Sqrt16( tmp, &tmp_e ); - ratio_fx = shr_sat( tmp, sub( 2, tmp_e ) ); /* Q13 */ - - /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ - FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) - { - /*exc_fx[i] *= ratio_fx;*/ - exc_fx[i] = round_fx( L_shl( L_mac( -8192, exc_fx[i], ratio_fx ), 2 ) ); - move16(); - } - } - *Last_frame_ener_fx = etmp1_fx; /* 2 * Q_new + 1 */ - move32(); - } - ELSE - { - /*-------------------------------------------------------* - * In normal cases, just compute the energy of the frame - *-------------------------------------------------------*/ - Word16 exp_etmp = sub( 15, Q_new ); - etmp_fx = sum2_16_exp_fx( exc_fx, L_frame, &exp_etmp, 7 ); /* Q = 31-exp_etmp */ - - etmp_fx = L_shr( etmp_fx, 8 ); /*31-exp_etmp//INV_L_FRAME = 1/256*/ - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*31 - exp_etmp*/ - } - *Last_frame_ener_fx = L_shl( etmp_fx, sub( shl( Q_new, 1 ), sub( 30 /*31-1*/, exp_etmp ) ) ); /*2*Q_new+1*/ - move32(); /*2*Q_new+1*/ - } - - return; -} -#endif diff --git a/lib_com/options.h b/lib_com/options.h index 1b0440bbc..814cbf611 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_1904_HARM_GSC_ENC /* VA: #1904 Harmonization of EVS and IVAS GSC code */ #define FIX_2388_INITTNSCONFIGURATION /* FhG: issue 2388 : harmonizing InitTnsConfiguration() function */ #define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ #define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d3d45ab1d..3eb8d8f32 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1669,12 +1669,8 @@ void Ener_per_band_comp_fx( Word16 y_gain4[], /* o : Energy per band to quantize Q12 */ const Word16 Q_exc_diff, const Word16 Mband, /* i : Max band */ -#ifdef FIX_1904_HARM_GSC_ENC const Word16 Eflag, const Word16 L_frame /* i : frame length */ -#else - const Word16 Eflag -#endif ); void Ener_per_band_comp_ivas_fx( @@ -1718,23 +1714,9 @@ void pre_echo_att_fx( const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, const Word16 last_coder_type, /* i : Last coding mode Q0*/ -#ifdef FIX_1904_HARM_GSC_ENC const Word16 L_frame /* i : Frame length Q0*/, const Word16 element_mode /* i : Current IVAS element mode*/ -#else - const Word16 L_frame /* i : Frame length Q0*/ -#endif -); -#ifndef FIX_1904_HARM_GSC_ENC -void pre_echo_att_ivas_fx( - Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ - const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode Q0*/ - const Word16 L_frame /* i : Frame length Q0*/ ); -#endif void tcx_get_windows_mode1( const Word16 left_mode, /* i: overlap mode of left window half */ @@ -4797,70 +4779,6 @@ void freq_dnw_scaling_fx( const Word16 L_frame /* i : frame length */ ); -#ifndef FIX_1904_HARM_GSC_ENC -void highband_exc_dct_in_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *mfreq_bindiv, /* i : bin per bands tables */ - Word16 last_bin, /* i : last bin of bit allocation */ - Word16 Diff_len, /* i : number of bin before cut-off frequency */ - Word16 noise_lev, /* i : pulses dynamic */ - Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 *exc_diffQ, /* i : frequency coefficients of per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ - Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *exc_dct_in, /* o : dct of residual signal */ - Word16 last_coder_type, /* i : coding type of last frame */ - Word16 *bitallocation_band, /* i : bit allocation flag of each band */ - const Word16 *lsf_new, /* i : LSFs at the end of the frame */ - Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16 *last_ener, /* i : frequency energy of last frame */ - Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ - Word16 bfi, /* i : bad frame indicator */ - const Word16 coder_type, /* i : coder type */ - Word16 bwidth, - Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ - Word16 Qexc_diffQ, - Word16 Q_exc, - const Word16 GSC_noisy_speech, - Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -); -void highband_exc_dct_in_ivas_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *mfreq_bindiv, /* i : bin per bands tables */ - Word16 last_bin, /* i : last bin of bit allocation */ - Word16 Diff_len, /* i : number of bin before cut-off frequency */ - Word16 noise_lev, /* i : pulses dynamic */ - Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 *exc_diffQ, /* i : frequency coefficients of per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ - Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *exc_dct_in, /* o : dct of residual signal */ - Word16 last_coder_type, /* i : coding type of last frame */ - Word16 *bitallocation_band, /* i : bit allocation flag of each band */ - const Word16 *lsf_new, /* i : LSFs at the end of the frame */ - Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16 *last_ener, /* i : frequency energy of last frame */ - Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ - Word16 bfi, /* i : bad frame indicator */ - const Word16 coder_type, /* i : coder type */ - Word16 bwidth, - Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ - Word16 Qexc_diffQ, - Word16 *Q_exc, - const Word16 GSC_noisy_speech, - Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -); -#else void highband_exc_dct_in_fx( const Word32 core_brate, /* i : core bitrate */ const Word16 *mfreq_bindiv, /* i : bin per bands tables */ @@ -4892,7 +4810,6 @@ void highband_exc_dct_in_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); -#endif void lsf_dec_bfi( const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index a314bb232..0338c76b8 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -502,11 +502,7 @@ void decod_audio_fx( * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame, 0 ); -#else - pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame ); -#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -854,17 +850,10 @@ void gsc_dec_fx( * Estimate noise level *--------------------------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#else - highband_exc_dct_in_ivas_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, - &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, - st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#endif exc_dct_in[0] = 0; move16(); diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 6273cd186..916329e66 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -153,11 +153,7 @@ void tdm_low_rate_dec_fx( * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame, 0 ); -#else - pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame ); -#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 73a2e50c2..794aa6af9 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1474,14 +1474,10 @@ ivas_error acelp_core_enc_ivas_fx( ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ -#ifndef FIX_1904_HARM_GSC_ENC - encod_audio_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); -#else #ifdef HARMONIZE_ACELP_ENC encod_audio_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, shift ); #else encod_audio_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); -#endif #endif } ELSE diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 00095a89d..1ec7eac72 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -81,11 +81,7 @@ void enc_pit_exc_fx( Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ Word16 clip_gain, i; /* LSF clip gain and LP flag */ const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ -#ifdef FIX_1904_HARM_GSC_ENC Word16 cn[PIT_EXC_L_SUBFR]; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ -#else - Word16 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ -#endif Word16 *pt_pitch; /* pointer to floating pitch */ Word16 L_subfr; Word16 cum_gpit, gpit_tmp; @@ -107,10 +103,8 @@ void enc_pit_exc_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; -#ifdef FIX_1904_HARM_GSC_ENC Word16 q_h1 = 0; move16(); -#endif /*------------------------------------------------------------------* * Initialization @@ -233,27 +227,16 @@ void enc_pit_exc_fx( * ACELP subframe loop *------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC set16_fx( cn, 0, PIT_EXC_L_SUBFR ); -#else - cn = NULL; - if ( EQ_16( L_subfr, L_SUBFR ) ) - { - cn = cn1; - move16(); - } -#endif p_Aw = Aw; p_Aq = Aq; pt_pitch = pitch_buf; /* pointer to the pitch buffer */ shift_wsp = add( Q_new, shift ); -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { shift_wsp = sub( shift_wsp, 1 ); } -#endif FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) { @@ -267,7 +250,6 @@ void enc_pit_exc_fx( Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */ /* condition on target (compared to float) has been put outside the loop */ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { find_targets_ivas_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq, @@ -277,7 +259,6 @@ void enc_pit_exc_fx( Copy_Scale_sig( h1, h2, L_subfr, sub( 11, q_h1 ) ); /*Q11*/ } ELSE -#endif { find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); @@ -296,24 +277,20 @@ void enc_pit_exc_fx( *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ // TVTODO to be check if it would still be BE when moved above } -#endif /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } ELSE -#endif { pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } @@ -338,13 +315,11 @@ void enc_pit_exc_fx( } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { hSpMusClas->lowrate_pitchGain = mac_r_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 3277, gain_pit ); /* Q14*Q16(0.1) + Q15 -> Q15 Q14*Q15 + Q14 -> Q14 lowrate_pitchGain is compared to Q14 in sp_music_classif */ } ELSE -#endif { hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ } @@ -400,13 +375,8 @@ void enc_pit_exc_fx( * Gain encoding *-----------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, st_fx->L_frame, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); -#else - gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); -#endif } gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); @@ -416,13 +386,11 @@ void enc_pit_exc_fx( IF( use_fcb != 0 ) { -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { hLPDmem->tilt_code = est_tilt_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr ); /* Q15 */ } ELSE -#endif { hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ } @@ -440,13 +408,11 @@ void enc_pit_exc_fx( IF( use_fcb != 0 ) { -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ } ELSE -#endif { Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ } @@ -455,13 +421,11 @@ void enc_pit_exc_fx( Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 ); /* Q_new + Q15 + shift */ Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + Q15 + shift */ Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ } ELSE -#endif { hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ } @@ -472,13 +436,11 @@ void enc_pit_exc_fx( Ltmp = L_mult( xn[L_subfr - 1], 16384 ); /* Q_new + 14 -shift */ Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + 14 -shift */ Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ } ELSE -#endif { hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ } @@ -628,485 +590,3 @@ void enc_pit_exc_fx( return; } -#ifndef FIX_1904_HARM_GSC_ENC -void enc_pit_exc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *speech, /* i : Input speech Q_new-1*/ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res, /* i : residual signal Q_new*/ - Word16 *synth, /* i/o: core synthesis Q_new*/ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - Word16 *gpit, /* o : pitch mean gpit Q15*/ - Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 Q_new, - Word16 shift ) -{ - Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ - Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word16 cn[PIT_EXC_L_SUBFR]; - Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ - Word16 code[2 * L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2[2 * L_SUBFR]; /* Filtered algebraic excitation */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code; /* Gain of code */ - Word16 gain_inov; /* inovation gain */ - Word16 gain_pit; /* Pitch gain */ - Word16 pit_idx, i_subfr; /* tmp variables */ - Word16 T0_min, T0_max; /* pitch variables */ - Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ - Word16 clip_gain, i; /* LSF clip gain and LP flag */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 *pt_pitch; /* pointer to floating pitch */ - Word16 L_subfr; - Word16 cum_gpit, gpit_tmp; - Word32 Local_BR, Pitch_BR; - Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */ - Word32 norm_gain_code; - Word16 pitch_limit_flag; - Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word32 Ltmp; - Word32 Lgcode; - Word16 gcode16; - Word16 shift_wsp; - Word16 lp_select, lp_flag; - Word16 use_fcb; - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ - Word16 q_h1; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - pitch_limit_flag = 1; - move16(); /* always extended pitch Q range */ - use_fcb = 0; - unbits_PI = 0; - move16(); - move16(); - Pitch_CT = GENERIC; - move16(); - set16_fx( cn, 0, PIT_EXC_L_SUBFR ); - test(); - test(); - IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) - { - Local_BR = ACELP_8k00; - Pitch_BR = ACELP_8k00; - move32(); - move32(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_14k80; - move32(); - if ( st_fx->GSC_IVAS_mode > 0 ) - { - Local_BR = ACELP_9k60; - move32(); - } - Pitch_BR = st_fx->core_brate; - move32(); - } - } - ELSE IF( st_fx->GSC_noisy_speech ) - { - Local_BR = ACELP_7k20; - move32(); - Pitch_BR = ACELP_7k20; - move32(); - Pitch_CT = GENERIC; - move16(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Pitch_BR = st_fx->core_brate; - move32(); - } - } - ELSE - { - Local_BR = ACELP_7k20; - move32(); - Pitch_BR = st_fx->core_brate; - move32(); - Pitch_CT = AUDIO; - move16(); - - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_13k20; - move32(); - Pitch_CT = GENERIC; - move16(); - } - } - gain_code = 0; - move16(); - - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - T0_max = PIT16k_MAX; - T0_min = PIT16k_MIN; - } - ELSE - { - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - } - cum_gpit = 0; - move16(); - - L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */ - - lp_flag = st_fx->acelp_cfg.ltf_mode; - move16(); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && - ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || - ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && - EQ_16( L_subfr, L_SUBFR ) ) ) - { - use_fcb = 1; - move16(); - } - ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) - { - use_fcb = 2; - st_fx->acelp_cfg.fcb_mode = 1; - move16(); - move16(); - set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR ); - set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR ); - set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k ); - } - - *saved_bit_pos = st_fx->next_bit_pos_fx; /* Q0 */ - move16(); - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - p_Aw = Aw; - p_Aq = Aq; - pt_pitch = pitch_buf; /* pointer to the pitch buffer */ - shift_wsp = add( Q_new, shift ); - - FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) - { - - /*----------------------------------------------------------------* - * Bandwidth expansion of A(z) filter coefficients - * Find the the excitation search target "xn" and innovation - * target in residual domain "cn" - * Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - - Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */ - /* condition on target (compared to float) has been put outside the loop */ - - find_targets_ivas_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq, - res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - - q_h1 = sub( 14, norm_s( h1[0] ) ); - Copy_Scale_sig( h1, h2, L_subfr, sub( 11, q_h1 ) ); /*Q11*/ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */ - - /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - * Adaptive exc. construction - *----------------------------------------------------------------*/ - - *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, - L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ - - Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ - - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - - clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */ - - /*-----------------------------------------------------------------* - * Codebook target computation - * (No LP filtering of the adaptive excitation) - *-----------------------------------------------------------------*/ - - lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ - - - IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) - { - push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - st_fx->hSpMusClas->lowrate_pitchGain = mac_r( L_mult( 29491 /* 0.9 in Q15 */, st_fx->hSpMusClas->lowrate_pitchGain ), 3277 /* 0.1 in Q15 */, gain_pit ); /* Q14 */ - - gpit_tmp = gain_pit; - move16(); /*Q14*/ - test(); - IF( use_fcb > 0 ) - { - /* h2 in Q12 for codebook search */ - /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ - Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) ); - } - - IF( use_fcb == 0 ) - { - IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) ) - { - pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 ); - push_indice( hBstr, IND_PIT_IDX, pit_idx, 5 ); - } - ELSE - { - pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); - push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 ); - } - } - ELSE IF( use_fcb == 2 ) - { - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ - - inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift, Q_new ); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - - gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, sub( shift_wsp, 1 ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, - st_fx->element_mode ); - } - ELSE - { - /*-----------------------------------------------------------------* - * Innovation & gain encoding - *-----------------------------------------------------------------*/ - - inov_encode_ivas_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - - gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, st_fx->L_frame, i_subfr, -1, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - - gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); - - Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_sat( Lgcode ); - IF( use_fcb != 0 ) - { - hLPDmem->tilt_code = est_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr, 0 ); // Q15 - move16(); - } - ELSE - { - hLPDmem->tilt_code = 0; - move16(); - } - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - - IF( use_fcb != 0 ) - { - Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); - Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); // Q_new+14+shift - Ltmp = L_negate( Ltmp ); - Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift - Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 - hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ - } - ELSE - { - Ltmp = L_mult( xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift - Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 - hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ - } - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - - IF( use_fcb != 0 ) - { - FOR( i = 0; i < L_subfr; i++ ) - { - /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 + Q_new */ - Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ - exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ - move16(); - } - } - ELSE - { - FOR( i = 0; i < L_subfr; i++ ) - { - - Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ - exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ - move16(); - } - } - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 ); - - IF( EQ_16( L_subfr, 5 * L_SUBFR ) ) - { - cum_gpit = gpit_tmp; - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - - p_Aw += 5 * ( M + 1 ); - p_Aq += 5 * ( M + 1 ); - } - ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) ) - { - IF( i_subfr == 0 ) - { - cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */ - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - p_Aw += 2 * ( M + 1 ); - p_Aq += 2 * ( M + 1 ); - } - ELSE - { - cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */ - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - p_Aw += 3 * ( M + 1 ); - p_Aq += 3 * ( M + 1 ); - } - } - ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) - { - IF( i_subfr == 0 ) - { - cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */ - } - ELSE - { - cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */ - } - p_Aw += 2 * ( M + 1 ); - move16(); - p_Aq += 2 * ( M + 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - } - ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) ) - { - cum_gpit = gpit_tmp; - move16(); - - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - pt_pitch++; - p_Aw += 4 * ( M + 1 ); - p_Aq += 4 * ( M + 1 ); - } - ELSE - { - IF( i_subfr == 0 ) - { - - cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */ - } - ELSE - { - cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */ - } - - pt_pitch++; - p_Aw += ( M + 1 ); - p_Aq += ( M + 1 ); - } - } - - cum_gpit = shl_sat( cum_gpit, 1 ); /*Q15*/ - *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/ - - return; -} -#endif diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index dae547e35..c3505bfa1 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -89,13 +89,11 @@ Word16 Pit_exc_contribution_len_fx( move16(); } -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); // This should be the only version if #2253 is included in #1292 } ELSE -#endif { minimum_fx( pitch_buf, nb_subfr, &low_pit ); } @@ -391,11 +389,7 @@ Word16 Pit_exc_contribution_len_fx( set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k ); /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ -#ifdef FIX_1904_HARM_GSC_ENC FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) -#else - for ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) -#endif { delete_indice( hBstr, i ); } @@ -431,366 +425,3 @@ Word16 Pit_exc_contribution_len_fx( return last_pit_bin; } -#ifndef FIX_1904_HARM_GSC_ENC -Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */ - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual Q_new*/ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution Q_new*/ - Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ - Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ - Word16 Qnew ) -{ - - Word16 corr_dct_pit[MBANDS_LOC]; - Word32 corr_tmp, L_tmp; - Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res; - Word16 freq, i, j; - Word16 last_pit_band, pit_contr_idx, last_pit_bin; - Word32 ener_res; - Word32 ener_pit; - Word16 low_pit, F1st_harm, F8th_harm; - Word16 corr_dct_pit_tmp[MBANDS_LOC]; - Word16 time_flg = 0; - Word16 Len, max_len; - Word16 tmp_dec; - Word16 Mbands_loc = MBANDS_LOC - 2; - Word16 exp1, tmp, exp2; - Word32 L_tmp1, ener_init; - Word16 exp_norm; - Word16 norm; - Word16 val_thrs; - SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - move16(); - - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Mbands_loc = MBANDS_LOC; - move16(); - } - minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); - exp1 = norm_s( low_pit ); - tmp = shl( low_pit, exp1 ); - tmp_dec = 12800; - move16(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - tmp_dec = 16000; - move16(); - } - /*F1st_harm = (12800.0f|160000.f)/low_pit;*/ - tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/ - F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/ - - /*F8th_harm = 8.0f*F1st_harm;*/ - F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/ - - freq = 0; - move16(); - ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5) 2*Qnew*/ - FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */ - { - corr_tmp = L_deposit_l( 0 ); - ener_res = L_add( ener_init, 0 ); - ener_pit = L_add( ener_init, 0 ); - - FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */ - { - tmp_ex = mult_r( dct_pitex[j + freq], 8192 ); - tmp_res = mult_r( dct_res[j + freq], 8192 ); - corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/ - ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/ - ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/ - } - - L_tmp1 = Mult_32_32( ener_res, ener_pit ); - exp2 = norm_l( L_tmp1 ); - L_tmp1 = L_shl( L_tmp1, exp2 ); - exp_norm = sub( 30, exp2 ); - L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm ); - norm = extract_h( L_tmp1 ); /*15-exp_norm*/ - L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm ); - corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/ - - freq = add( freq, mfreq_bindiv_loc[i] ); - } - - val_thrs = 8192; - move16(); /* 0.5 in Q14*/ - /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/ - tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/ - tmp = s_max( tmp, val_thrs ); /*Qnew */ - - corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ - move16(); - - FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */ - { - L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q_new + 16 */ - L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q_new + 16 */ - - tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q_new */ - tmp = s_max( tmp, val_thrs ); /* Q_new */ - - corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ - move16(); - } - tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/ - tmp = s_max( tmp, val_thrs ); /* Q_new */ - corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ - move16(); - - Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); /* Q_new + 1 */ - - L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/ - FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */ - { - L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); /* Q_new + 16 */ - } - av_corr = round_fx( L_tmp1 ); /*Qnew*/ - - /* Find the cut-off freq similarly to HSX */ - last_pit_band = 0; - move16(); - av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/ - - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - /*av_corr *= 1.25f;*/ - av_corr = add( av_corr, shr( av_corr, 2 ) ); - } - test(); - if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/ - } - min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/ - - FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */ - { - ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/ - - IF( LT_16( ftmp, min_corr ) ) - { - last_pit_band = i; - move16(); - min_corr = ftmp; - move16(); - } - } - - IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) ) - { - DO - { - last_pit_band = add( last_pit_band, 1 ); - } - WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) ); - } - if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) - { - last_pit_band = s_max( last_pit_band, 7 ); - } - test(); - test(); - test(); - IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/ - { - last_pit_band = 7 + BAND1k2; - move16(); - } - ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) ) - { - last_pit_band = add( 10, BAND1k2 ); - } - - time_flg = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) ) - { - tmp_dec = 1; - move16(); - } - ELSE - { - tmp_dec = 0; - move16(); - } - - /* Different past and current decision */ - test(); - test(); - test(); - IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) ) - { - IF( *hangover == 0 ) - { - time_flg = tmp_dec; - move16(); - *hangover = HANGOVER_DELAY; - move16(); - } - ELSE - { - time_flg = 0; - move16(); - if ( hGSCEnc->mem_last_pit_band > 0 ) - { - time_flg = 1; - move16(); - } - - ( *hangover ) = sub( ( *hangover ), 1 ); /* Q0 */ - if ( *hangover < 0 ) - { - *hangover = 0; - move16(); - } - } - } - ELSE - { - time_flg = tmp_dec; - move16(); - *hangover = HANGOVER_DELAY; - move16(); - } - - /* Decicison on final length of time contribution */ - pit_contr_idx = 0; - move16(); - test(); - test(); - IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech ) - { - test(); - test(); - /*if(st_fx->core_brate core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 /* 64 in Q6 */ ) ) - { - last_pit_band = add( 9, BAND1k2 ); - if ( EQ_16( st_fx->bwidth, NB ) ) - { - last_pit_band = add( 7, BAND1k2 ); - } - } - ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 /* 128 in Q6 */ ) ) - { - last_pit_band = add( 5, BAND1k2 ); - } - ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - last_pit_band = add( 3, BAND1k2 ); - } - ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) ) - { - last_pit_band = add( BAND1k2, 1 ); - } - last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q15 */ - move16(); - - st_fx->bpf_off = 0; - move16(); - - max_len = sub( st_fx->L_frame, last_pit_bin ); - - if ( EQ_16( st_fx->bwidth, NB ) ) - { - max_len = sub( 160, last_pit_bin ); - } - - Len = 80; - move16(); - if ( LT_16( max_len, 80 ) ) - { - Len = max_len; - move16(); - } - test(); - IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) ) - { - move16(); /*ptr init*/ - FOR( i = 0; i < max_len; i++ ) - { - dct_pitex[i + last_pit_bin] = 0; - move16(); - } - } - ELSE - { - - FOR( i = 0; i < Len; i++ ) - { - dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */ - } - FOR( ; i < max_len; i++ ) - { - dct_pitex[i + last_pit_bin] = 0; - move16(); - } - } - hGSCEnc->mem_last_pit_band = last_pit_band; - move16(); - pit_contr_idx = sub( last_pit_band, BAND1k2 ); - } - ELSE - { - set16_fx( dct_pitex, 0, st_fx->L_frame ); - st_fx->bpf_off = 1; - move16(); - last_pit_bin = 0; - move16(); - last_pit_band = 0; - move16(); - pit_contr_idx = 0; - move16(); - hGSCEnc->mem_last_pit_band = 0; - move16(); - - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k ); - /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ - FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) - { - delete_indice( hBstr, i ); - } - delete_indice( hBstr, IND_ES_PRED ); - } - IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) - { - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - if ( pit_contr_idx > 0 ) - { - pit_contr_idx = 1; - move16(); - } - - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) - { - push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); - } - } - ELSE - { - push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); - } - } - ELSE - { - push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); - } - - return last_pit_bin; -} -#endif diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 4037aaa5e..0af00565e 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -61,9 +61,7 @@ void encod_audio_fx( GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; -#ifdef FIX_1904_HARM_GSC_ENC Word16 Q_exc; -#endif m_mean = 0; move16(); @@ -75,14 +73,12 @@ void encod_audio_fx( T0_frac_tmp = 0; move16(); -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { Copy_Scale_sig( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); Copy_Scale_sig( &hLPDmem->mem_w0, &hGSCEnc->mem_w0_tmp_fx, 1, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); } ELSE -#endif { Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); /* hLPDmem->q_mem_syn */ hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; @@ -98,13 +94,11 @@ void encod_audio_fx( * Encode GSC SWB speech flag *---------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC test(); IF( NE_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 ) { push_indice( hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2 ); } -#endif IF( attack_flag > 0 ) { @@ -369,14 +363,10 @@ void encod_audio_fx( tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); } -#ifdef FIX_1904_HARM_GSC_ENC Q_exc = Q_new; move16(); gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, &Q_exc ); -#else - gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, Q_new ); -#endif /*--------------------------------------------------------------------------------------* * iDCT transform @@ -385,23 +375,17 @@ void encod_audio_fx( edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { Scale_sig( exc, st_fx->L_frame, sub( Q_new, Q_exc ) ); /* TV This could probably be removed, but won't be BE */ Scale_sig( exc_wo_nf, st_fx->L_frame, sub( Q_new, Q_exc ) ); } -#endif /*--------------------------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type, st_fx->L_frame, st_fx->element_mode ); -#else - pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type, st_fx->L_frame ); -#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -436,13 +420,11 @@ void encod_audio_fx( * Updates *--------------------------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { Copy_Scale_sig( &hGSCEnc->mem_w0_tmp_fx, &hLPDmem->mem_w0, 1, sub( hLPDmem->q_mem_syn, sub( Q_new, 1 ) ) ); } ELSE -#endif { hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; move16(); @@ -454,394 +436,6 @@ void encod_audio_fx( } -#ifndef FIX_1904_HARM_GSC_ENC -void encod_audio_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12 */ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12 */ - const Word16 *res, /* i : residual signal Q_new */ - Word16 *synth, /* i/o: core synthesis Q-1 */ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ - const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC)*/ - Word16 *lsf_new, /* i : current frame ISF vector Qx2.56 */ - Word16 *tmp_noise, /* o : noise energy Q8*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ - Word16 Q_new, - Word16 shift ) -{ - const Word16 *p_Aq; - Word16 i, i_subfr, nb_subfr, last_pit_bin; - Word16 T0_tmp, T0_frac_tmp, nb_subfr_flag; - Word16 tmp_nb_bits_tot = 0; - Word16 Es_pred; - Word16 dct_res[L_FRAME16k], dct_epit[L_FRAME16k]; - Word16 m_mean = 0; - Word16 saved_bit_pos; - Word16 exc_wo_nf[L_FRAME16k]; - Word32 Lm_mean; - Word16 nb_bits; - Word16 indice; - SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - m_mean = 0; - move16(); - tmp_nb_bits_tot = 0; - move16(); - - T0_tmp = 64; - move16(); - T0_frac_tmp = 0; - move16(); - Copy_Scale_sig( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); - Copy_Scale_sig( &hLPDmem->mem_w0, &hGSCEnc->mem_w0_tmp_fx, 1, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); - move16(); - Es_pred = 0; - move16(); - - /*---------------------------------------------------------------* - * Encode GSC IVAS mode - * Encode GSC attack flag (used to reduce possible pre-echo) - * Encode GSC SWB speech flag - *---------------------------------------------------------------*/ - - test(); - if ( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 ) - { - push_indice( hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2 ); - } - - IF( attack_flag > 0 ) - { - push_indice( hBstr, IND_GSC_ATTACK, 1, 1 ); - } - ELSE - { - push_indice( hBstr, IND_GSC_ATTACK, 0, 1 ); - } - - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( NE_16( st_fx->coder_type, INACTIVE ) && ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) || - ( GT_16( st_fx->element_mode, EVS_MONO ) && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) - { - push_indice( hBstr, IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech, 1 ); - } - /*---------------------------------------------------------------* - * Find and encode the number of subframes - *---------------------------------------------------------------*/ - test(); - IF( GE_32( st_fx->core_brate, ACELP_9k60 ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) - { - FOR( i = 0; i < 5; i++ ) - { - test(); - if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) - { - hGSCEnc->cor_strong_limit = 0; - move16(); - } - } - } - test(); - test(); - test(); - test(); - IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( st_fx->GSC_noisy_speech && st_fx->GSC_IVAS_mode == 0 ) ) - { - nb_subfr = NB_SUBFR; - move16(); - test(); - test(); - if ( st_fx->GSC_IVAS_mode > 0 && LT_16( st_fx->GSC_IVAS_mode, 3 ) && LT_32( st_fx->core_brate, GSC_L_RATE_STG ) ) - { - nb_subfr = 2; - move16(); - } - hGSCEnc->cor_strong_limit = 0; - move16(); - nb_subfr_flag = 1; - move16(); - } - ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( LE_32( st_fx->core_brate, ACELP_13k20 ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) - { - hGSCEnc->cor_strong_limit = 0; - nb_subfr = SWNB_SUBFR; - nb_subfr_flag = 1; - move16(); - move16(); - move16(); - } - ELSE - { - test(); - test(); - IF( ( hGSCEnc->cor_strong_limit == 0 || EQ_16( st_fx->coder_type, INACTIVE ) ) && GE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - nb_subfr = 2; - move16(); - nb_subfr_flag = 0; - move16(); - hGSCEnc->cor_strong_limit = 0; - move16(); - } - ELSE - { - nb_subfr = SWNB_SUBFR; - move16(); - nb_subfr_flag = 1; - move16(); - } - - test(); - test(); - test(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) && NE_16( st_fx->coder_type, INACTIVE ) ) ) - { - nb_subfr = shl( nb_subfr, 1 ); - nb_subfr_flag |= 0x2; - logic16(); - } - - test(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) - { - push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 2 ); - } - ELSE IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - /* nb_subfr_flag can only have the value 0 or 1 */ - push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 1 ); - } - } - test(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) - { - nb_subfr = NB_SUBFR16k; - move16(); - } - - /*---------------------------------------------------------------* - * Compute adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( !( st_fx->GSC_IVAS_mode > 0 && EQ_16( st_fx->L_frame, i_mult( nb_subfr, 2 * L_SUBFR ) ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) && - ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) && - ( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) ) - { - IF( ( st_fx->element_mode > EVS_MONO ) ) - { - nb_bits = 5; - move16(); - } - ELSE - { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; - move16(); - } - Es_pred_enc_fx( &Es_pred, &indice, st_fx->L_frame, res, st_fx->voicing_fx, nb_bits, 0, Q_new ); - push_indice( hBstr, IND_ES_PRED, indice, nb_bits ); - } -#ifdef FIX_1904_HARM_GSC_ENC - enc_pit_exc_fx( st_fx, speech, Aw, Aq, Es_pred, res, synth, exc, &T0_tmp, - &T0_frac_tmp, pitch_buf, nb_subfr, &hGSCEnc->lt_gpitch_fx, &saved_bit_pos, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); -#else - enc_pit_exc_ivas_fx( st_fx, speech, Aw, Aq, Es_pred, res, synth, exc, &T0_tmp, - &T0_frac_tmp, pitch_buf, nb_subfr, &hGSCEnc->lt_gpitch_fx, &saved_bit_pos, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); -#endif - /*---------------------------------------------------------------* - * DCT transform - *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); - edct_16fx( res, dct_res, st_fx->L_frame, 7, st_fx->element_mode ); - /*---------------------------------------------------------------* - * Calculate energy dynamics - *---------------------------------------------------------------*/ - Lm_mean = L_deposit_l( 0 ); - FOR( i = 7; i < 15; i++ ) - { - /*m_mean = add(m_mean,edyn_fx( dct_res+i*16, 16, Q_new )); */ - Lm_mean = L_mac( Lm_mean, edyn_fx( dct_res + i * 16, 16, Q_new ), 4096 ); /*Q7*/ - } - m_mean = round_fx( Lm_mean ); /*Q7*/ - - IF( GT_16( m_mean, hGSCEnc->mid_dyn_fx ) ) - { - /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ - hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 26214, m_mean ), 6554, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ - move16(); - } - ELSE - { - /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ - hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 13107, m_mean ), 19661, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ - move16(); - } - IF( NE_16( st_fx->coder_type, INACTIVE ) ) - { - hGSCEnc->noise_lev = sub( ( NOISE_LEVEL_SP3 + 1 ), usquant_fx( hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr( GSF_NF_DELTA_FX, 1 ), GSC_NF_STEPS ) ); - move16(); - hGSCEnc->noise_lev = s_min( hGSCEnc->noise_lev, NOISE_LEVEL_SP3 ); - move16(); - } - - hGSCEnc->past_dyn_dec = hGSCEnc->noise_lev; - move16(); - IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP2; - move16(); - IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP0; - move16(); - } - ELSE IF( st_fx->GSC_noisy_speech == 0 ) - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP3; - move16(); - } - } - ELSE IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - hGSCEnc->noise_lev = s_max( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ); - push_indice( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ), 2 ); - } - ELSE IF( st_fx->GSC_noisy_speech ) - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP3; - move16(); - } - ELSE - { - push_indice( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP0 ), 3 ); - } - - /*---------------------------------------------------------------* - * Find and encode the last band where the adaptive (pitch) contribution is significant - *---------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC - last_pit_bin = Pit_exc_contribution_len_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &hGSCEnc->pit_exc_hangover, Q_new ); -#else - last_pit_bin = Pit_exc_contribution_len_ivas_fx( st_fx, dct_res, dct_epit, pitch_buf, &hGSCEnc->pit_exc_hangover, Q_new ); -#endif - - IF( last_pit_bin == 0 ) - { - hLPDmem->tilt_code = 0; - move16(); - } - ELSE - { - /*last_pit_bin++;*/ - last_pit_bin = add( last_pit_bin, 1 ); - } - - /*--------------------------------------------------------------------------------------* - * GSC encoder - *--------------------------------------------------------------------------------------*/ - - /* Find the current total number of bits used */ - tmp_nb_bits_tot = hBstr->nb_bits_tot; - move16(); - - - if ( st_fx->extl_brate > 0 ) - { - /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); - } - test(); - test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) - { - /* add 5 bits for noisiness */ - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); - } - - Word16 Q_exc = Q_new; - move16(); -#ifdef FIX_1904_HARM_GSC_ENC - gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, &Q_exc ); -#else - gsc_enc_ivas_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, &Q_exc ); -#endif - /*--------------------------------------------------------------------------------------* - * iDCT transform - *--------------------------------------------------------------------------------------*/ - - edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); - Scale_sig( exc, st_fx->L_frame, sub( Q_new, Q_exc ) ); - edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); - Scale_sig( exc_wo_nf, st_fx->L_frame, sub( Q_new, Q_exc ) ); - Q_exc = Q_new; - move16(); - /*--------------------------------------------------------------------------------------* - * Remove potential pre-echo in case an onset has been detected - *--------------------------------------------------------------------------------------*/ - - pre_echo_att_ivas_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_exc, st_fx->last_coder_type, st_fx->L_frame ); - - /*--------------------------------------------------------------------------------------* - * Update BWE excitation - *--------------------------------------------------------------------------------------*/ - IF( st_fx->hBWE_TD != NULL ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - set16_fx( voice_factors, 0, NB_SUBFR16k ); - interp_code_4over2_fx( exc, bwe_exc, L_FRAME16k ); - } - ELSE - { - set16_fx( voice_factors, 0, NB_SUBFR ); - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - } - } - /*--------------------------------------------------------------------------------------* - * Synthesis - *--------------------------------------------------------------------------------------*/ - - p_Aq = Aq; /* Q12 */ - FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_SUBFR ) - { - Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aq += ( M + 1 ); - } - - /*--------------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------------*/ - Copy_Scale_sig( &hGSCEnc->mem_w0_tmp_fx, &hLPDmem->mem_w0, 1, sub( hLPDmem->q_mem_syn, sub( Q_new, 1 ) ) ); - - move16(); - Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_new */ - - return; -} - -#endif /*================================================================================*/ /* FUNCTION : void gsc_enc_fx() */ /*--------------------------------------------------------------------------------*/ @@ -873,18 +467,10 @@ void gsc_enc_fx( const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, -#ifndef FIX_1904_HARM_GSC_ENC - Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ -#else const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ -#endif Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *tmp_noise, /* o : noise energy Q2*/ -#ifndef FIX_1904_HARM_GSC_ENC - Word16 Q_exc -#else Word16 *Q_exc -#endif ) { Word16 y2_filt[L_FRAME16k]; @@ -898,11 +484,7 @@ void gsc_enc_fx( Word16 concat_in[L_FRAME16k]; Word16 concat_out[L_FRAME16k]; Word16 max_ener_band[MBANDS_GN_BITALLOC16k], j; -#ifndef FIX_1904_HARM_GSC_ENC - Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; -#else Word16 Ener_per_bd_iQ[MBANDS_GN16k]; -#endif Word16 last_bin, mean_gain; Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; Word16 bitallocation_exc[2]; @@ -913,13 +495,11 @@ void gsc_enc_fx( Word16 seed_init; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; -#ifdef FIX_1904_HARM_GSC_ENC Word32 L_tmp; Word16 max_eq = 0; Word16 Q_concat = Q_PVQ_OUT; move16(); move16(); -#endif set16_fx( inpulses_fx, 0, NB_SFM ); set16_fx( imaxpulse_fx, 0, NB_SFM ); @@ -967,11 +547,7 @@ void gsc_enc_fx( move16(); } -#ifndef FIX_1904_HARM_GSC_ENC - Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1 /*, st_fx->L_frame IVAS_CODE*/ ); -#else Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, *Q_exc, MBANDS_GN, 1, st_fx->L_frame ); -#endif /*--------------------------------------------------------------------------------------* * Gain quantizaion @@ -1005,16 +581,9 @@ void gsc_enc_fx( * Frequency encoder *--------------------------------------------------------------------------------------*/ -#ifndef FIX_1904_HARM_GSC_ENC - bands_and_bit_alloc_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, st_fx->coder_type, st_fx->bwidth, - st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); - Q_tmp = Q_exc; -#else bands_and_bit_alloc_ivas_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, st_fx->coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); Q_tmp = *Q_exc; -#endif move16(); IF( bit == 0 ) @@ -1023,7 +592,6 @@ void gsc_enc_fx( } ELSE { -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could probably be harmonized */ { Q_concat = Q12; @@ -1031,7 +599,6 @@ void gsc_enc_fx( bit = sub( bit, pvq_core_enc_ivas_fx( hBstr, concat_in, concat_out, &Q_concat, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ) ); } ELSE -#endif { tmp = pvq_core_enc_fx( hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); @@ -1056,7 +623,6 @@ void gsc_enc_fx( move16(); set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k ); -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could be harmonized, but won't be mathematically BE */ { max_eq = 0; @@ -1080,7 +646,6 @@ void gsc_enc_fx( } } } -#endif FOR( j = 0; j < nb_subbands; j++ ) { @@ -1138,7 +703,6 @@ void gsc_enc_fx( * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC test(); test(); test(); @@ -1159,12 +723,10 @@ void gsc_enc_fx( } } ELSE -#endif { freq_dnw_scaling_fx( hGSCEnc->cor_strong_limit, st_fx->coder_type, hGSCEnc->noise_lev, st_fx->core_brate, exc_diffQ, Q_concat /*Q12 or Q10*/, st_fx->L_frame ); } -#ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could be harmonized, but won't be BE */ { Word16 Q_exc_new = s_min( *Q_exc, hGSCEnc->Q_last_exc_dct_in ); @@ -1181,22 +743,14 @@ void gsc_enc_fx( move16(); } } -#endif /*--------------------------------------------------------------------------------------* * Estimate noise level *--------------------------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ /* Q12 */, &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in /* Q_exc */, st_fx->last_coder_type, bitallocation_band, lsf_new /* x2.56 */, hGSCEnc->last_exc_dct_in_fx /* Q_exc */, &hGSCEnc->last_ener_fx /* Q0 */, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, st_fx->bwidth, exc_wo_nf, Q_concat, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#else - highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ, - &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCEnc->last_exc_dct_in_fx, &hGSCEnc->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, - st_fx->bwidth, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#endif exc_dct_in[0] = 0; move16(); @@ -1204,297 +758,6 @@ void gsc_enc_fx( return; } -#ifndef FIX_1904_HARM_GSC_ENC -void gsc_enc_ivas_fx( - Encoder_State *st, /* i/o: State structure */ - Word16 res_dct_in_fx[], - /* i : dct of residual signal */ // Q_exc - Word16 exc_dct_in_fx[], - /* i/o: dct of pitch-only excitation / total excitation */ // Q_exc - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 *lsf_new_fx, /* Qx2.56 */ - /* i : ISFs at the end of the frame */ // Q15 - Word16 *exc_wo_nf_fx, - /* o : excitation (in f domain) without noisefill */ // Q_exc - Word16 *tmp_noise_fx, /* o : long-term noise energy Q8*/ - Word16 *Q_exc ) -{ - Word16 i; - GSC_ENC_HANDLE hGSCEnc; - BSTR_ENC_HANDLE hBstr; - Word16 exc_diffQ_fx[L_FRAME16k]; - Word16 exc_diff_fx[L_FRAME16k]; - Word16 bit; - Word16 nb_subbands; - Word16 pvq_len; - Word16 bits_per_bands[MBANDS_GN_BITALLOC16k]; /*Q3*/ - Word16 tmp_band; - Word16 concat_in_fx[L_FRAME16k]; - Word16 concat_out_fx[L_FRAME16k]; - Word16 max_ener_band[MBANDS_GN_BITALLOC16k], j; - Word16 Ener_per_bd_iQ_fx[MBANDS_GN16k]; - Word16 last_bin; - Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; - Word16 bitallocation_exc[2]; - Word16 npulses[NB_SFM]; - Word16 maxpulse[NB_SFM]; - Word16 mean_gain_fx; - Word16 seed_init; - Word32 L_tmp; - Word16 max_eq; - - /*--------------------------------------------------------------------------------------* - * Initialization - *--------------------------------------------------------------------------------------*/ - - hGSCEnc = st->hGSCEnc; - hBstr = st->hBstr; - - bit = bits_used; - move16(); - - test(); - test(); - test(); - if ( st->coder_type == INACTIVE && ( EQ_16( st->tdm_LRTD_flag, 1 ) || EQ_16( st->element_mode, IVAS_SCE ) ) && LE_32( st->core_brate, GSC_LRES_GAINQ_LIMIT ) ) - { - bit = add( bit, GSC_LRES_NB_NITS ); - } - - set16_fx( exc_diffQ_fx, 0, st->L_frame ); - set16_fx( Ener_per_bd_iQ_fx, 0, MBANDS_GN16k ); - - /*--------------------------------------------------------------------------------------* - * Calculate the difference between the residual spectrum and the spectrum of adaptive excitation - * (non valuable temporal content present in exc_dct_in is already zeroed) - *--------------------------------------------------------------------------------------*/ - - v_sub_16( res_dct_in_fx, exc_dct_in_fx, exc_diff_fx, st->L_frame ); /* Q_exc */ - exc_diff_fx[0] = 0; - move16(); - - /*--------------------------------------------------------------------------------------* - * Multiply the difference spectrum with the normalized spectral shape of the residual signal - * This improves the stability of the differnece spectrum since the spectral shape of the - * residual signal is less suseptible to rapid changes than the difference spectrum - *--------------------------------------------------------------------------------------*/ - - IF( Diff_len == 0 ) - { - tmp_band = 0; - } - ELSE - { - tmp_band = hGSCEnc->mem_last_pit_band; - } - move16(); -#ifdef FIX_1904_HARM_GSC_ENC - Ener_per_band_comp_fx( exc_diff_fx, Ener_per_bd_iQ_fx, *Q_exc, MBANDS_GN, 1, st->L_frame ); -#else - Ener_per_band_comp_ivas_fx( exc_diff_fx, Ener_per_bd_iQ_fx, *Q_exc, MBANDS_GN, 1, st->L_frame ); -#endif - /*--------------------------------------------------------------------------------------* - * Gain quantizaion - *--------------------------------------------------------------------------------------*/ - - i = 0; - move16(); - - WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) - { - IF( LE_32( st->core_brate, brate_intermed_tbl[i] ) ) - { - BREAK; - } - i++; - } - - test(); - test(); - test(); - if ( st->element_mode > EVS_MONO && EQ_16( st->coder_type, AUDIO ) && - LE_32( st->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ - { - i--; - } - - mean_gain_fx = gsc_gainQ_ivas_fx( hBstr, st->element_mode, st->idchan, Ener_per_bd_iQ_fx, Ener_per_bd_iQ_fx, brate_intermed_tbl[i], st->coder_type, st->bwidth, st->L_frame, st->tdm_LRTD_flag, st->core_brate ); - - *tmp_noise_fx = mult( mean_gain_fx, 20480 ); // 20480 => 10 in Q11 - move16(); // Q8 - - /*--------------------------------------------------------------------------------------* - * PVQ encoder - *--------------------------------------------------------------------------------------*/ - - bands_and_bit_alloc_ivas_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ_fx, max_ener_band, bits_per_bands, &nb_subbands, exc_diff_fx, concat_in_fx, &pvq_len, st->coder_type, st->bwidth, st->GSC_noisy_speech, st->L_frame, st->element_mode, st->GSC_IVAS_mode ); - - set16_fx( npulses, 0, NB_SFM ); - - IF( bit == 0 ) - { - set16_fx( concat_out_fx, 0, L_FRAME16k ); - } - ELSE - { - Word16 Q_concat = Q12; - move16(); - bit = sub( bit, pvq_core_enc_ivas_fx( hBstr, concat_in_fx, concat_out_fx, &Q_concat, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, npulses, maxpulse, ACELP_CORE ) ); - } - - /* write unused bits */ - WHILE( bit > 0 ) - { - i = s_min( bit, 16 ); - push_indice( hBstr, IND_UNUSED, 0, i ); - bit = sub( bit, i ); - } - - /* Reorder Q bands */ - last_bin = 0; - move16(); - set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k ); - seed_init = 0; - move16(); - - max_eq = 0; - move16(); - - test(); - test(); - test(); - test(); - IF( ( ( ( LT_32( st->core_brate, ACELP_7k20 ) && EQ_16( st->GSC_noisy_speech, 1 ) ) || LT_32( st->core_brate, 6000 ) ) && LE_16( st->coder_type, UNVOICED ) ) || GE_16( st->GSC_IVAS_mode, 1 ) ) - { - j = emaximum_fx( Q12, concat_out_fx, shl( nb_subbands, 4 ), &L_tmp ); - IF( LE_16( add( abs_s( concat_out_fx[j] ), 41 /* 0.01f in Q12 */ ), ONE_IN_Q12 ) ) - { - max_eq = 32767; /* Q15 */ - move16(); - } - ELSE - { - max_eq = div_s( ONE_IN_Q12, add( abs_s( concat_out_fx[j] ), 41 /* 0.01f in Q12 */ ) ); /* Q15 */ - } - } - - FOR( j = 0; j < nb_subbands; j++ ) - { - Copy( concat_out_fx + i_mult( j, 16 ), exc_diffQ_fx + i_mult( max_ener_band[j], 16 ), 16 ); /* Q12 */ - - IF( GT_16( max_ener_band[j], last_bin ) ) - { - last_bin = max_ener_band[j]; - move16(); - } - - bitallocation_band[max_ener_band[j]] = 1; - move16(); - - seed_init = add( seed_init, npulses[j] ); - } - test(); - IF( NE_16( st->last_coder_type, AUDIO ) /* First audio frame */ - && NE_16( st->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_enc to UNVOICED */ - { - FOR( j = 0; j < nb_subbands * 16; j++ ) - { - IF( concat_out_fx[j] > 0 ) - { - seed_init = (Word16) L_mult0( seed_init, 8 ); - move16(); - } - IF( concat_out_fx[j] < 0 ) - { - seed_init = (Word16) L_add( seed_init, 3 ); - move16(); - } - } - - hGSCEnc->seed_tcx = seed_init; - move16(); - } - - test(); - IF( EQ_32( st->core_brate, ACELP_8k00 ) && st->bwidth != NB ) - { - bitallocation_exc[0] = 0; - move16(); - bitallocation_exc[1] = 0; - move16(); - - if ( exc_diffQ_fx[L_FRAME8k - 2] != 0 ) - { - bitallocation_exc[0] = 1; - move16(); - } - - if ( exc_diffQ_fx[L_FRAME8k - 1] != 0 ) - { - bitallocation_exc[1] = 1; - move16(); - } - } - - /*--------------------------------------------------------------------------------------* - * Skip adaptive (pitch) contribution frequency band (no noise added over the adaptive (pitch) contribution) - * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal - * Gain is based on the inter-correlation gain between the pulses found and residual signal - *--------------------------------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( st->GSC_IVAS_mode >= 1 && st->GSC_noisy_speech == 1 ) - { - FOR( i = 64; i < st->L_frame; i++ ) - { - exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); /* Q12 */ - move16(); - } - } - ELSE IF( st->core_brate < ACELP_7k20 && st->GSC_noisy_speech == 1 && st->coder_type <= UNVOICED ) - { - FOR( i = 0; i < L_FRAME; i++ ) - { - exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); /* Q12 */ - move16(); - } - } - ELSE - { - freq_dnw_scaling_fx( hGSCEnc->cor_strong_limit, st->coder_type, hGSCEnc->noise_lev, st->core_brate, exc_diffQ_fx, Q12, st->L_frame ); - } - - Word16 Q_exc_new = s_min( *Q_exc, hGSCEnc->Q_last_exc_dct_in ); - IF( NE_16( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ) - { - Scale_sig( hGSCEnc->last_exc_dct_in_fx, st->L_frame, sub( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ); /* Q_exc_new */ - hGSCEnc->Q_last_exc_dct_in = Q_exc_new; - move16(); - } - ELSE - { - Scale_sig( exc_dct_in_fx, st->L_frame, sub( Q_exc_new, *Q_exc ) ); /* Q_exc_new */ - *Q_exc = Q_exc_new; - move16(); - } - - /*--------------------------------------------------------------------------------------* - * Estimate noise level - *--------------------------------------------------------------------------------------*/ - highband_exc_dct_in_ivas_fx( st->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ_fx /* Q12 */, &hGSCEnc->seed_tcx, Ener_per_bd_iQ_fx, nb_subfr, exc_dct_in_fx /* Q_exc */, - st->last_coder_type, bitallocation_band, lsf_new_fx /* x2.56 */, hGSCEnc->last_exc_dct_in_fx /* Q_exc */, &hGSCEnc->last_ener_fx /* Q0 */, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st->coder_type, - st->bwidth, exc_wo_nf_fx, Q12, Q_exc, st->GSC_noisy_speech, NULL, st->L_frame, st->element_mode, st->GSC_IVAS_mode ); - - exc_dct_in_fx[0] = 0; - move16(); - - return; -} -#endif /*======================================================================*/ diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index b14a2d27d..8ca5a4a50 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -113,11 +113,7 @@ void tdm_low_rate_enc_fx( Word16 Q_exc = Q_new; move16(); -#ifdef FIX_1904_HARM_GSC_ENC gsc_enc_fx( st, dct_res_fx, dct_epit_fx, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf_fx, tmp_noise, &Q_exc ); -#else - gsc_enc_ivas_fx( st, dct_res_fx, dct_epit_fx, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf_fx, tmp_noise, &Q_exc ); -#endif /*--------------------------------------------------------------------------------------* * iDCT transform @@ -131,11 +127,7 @@ void tdm_low_rate_enc_fx( * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ -#ifdef FIX_1904_HARM_GSC_ENC pre_echo_att_fx( &st->hGSCEnc->Last_frame_ener_fx, exc_fx, attack_flag, Q_exc, st->last_coder_type, st->L_frame, st->element_mode ); -#else - pre_echo_att_ivas_fx( &st->hGSCEnc->Last_frame_ener_fx, exc_fx, attack_flag, Q_exc, st->last_coder_type, st->L_frame ); -#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d952988fd..840b2a516 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -833,33 +833,12 @@ void gsc_enc_fx( const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, -#ifndef FIX_1904_HARM_GSC_ENC - Word16 *lsf_new, /* i : ISFs at the end of the frame */ -#else const Word16 *lsf_new, /* i : ISFs at the end of the frame */ -#endif Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ Word16 *tmp_noise, /* o : noise energy */ -#ifndef FIX_1904_HARM_GSC_ENC - Word16 Q_exc -#else Word16 *Q_exc -#endif ); -#ifndef FIX_1904_HARM_GSC_ENC -void gsc_enc_ivas_fx( - Encoder_State *st, /* i/o: State structure */ - Word16 res_dct_in_fx[], /* i : dct of residual signal */ - Word16 exc_dct_in_fx[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 *lsf_new_fx, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf_fx, /* o : excitation (in f domain) without noisefill */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *Q_exc ); -#endif void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); @@ -3666,27 +3645,6 @@ void enc_pit_exc_fx( const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ const Word16 Q_new, const Word16 shift ); -#ifndef FIX_1904_HARM_GSC_ENC -void enc_pit_exc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *speech, /* i : Input speech Q_new-1*/ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res, /* i : residual signal Q_new*/ - Word16 *synth, /* i/o: core synthesis Q_new*/ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - Word16 *gpit, /* o : pitch mean gpit Q15*/ - Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 Q_new, - Word16 shift ); -#endif /* o : bin where pitch contribution is significant */ Word16 Pit_exc_contribution_len_fx( @@ -3697,16 +3655,6 @@ Word16 Pit_exc_contribution_len_fx( const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ); -#ifndef FIX_1904_HARM_GSC_ENC -/* o : bin where pitch contribution is significant */ -Word16 Pit_exc_contribution_len_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual Qnew*/ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution Qnew*/ - Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ - Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ - Word16 Qnew ); -#endif Word16 pvq_core_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ -- GitLab From cad786c1db94d52e898b5d0829d71a604ae699de Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:54:46 +0100 Subject: [PATCH 02/20] [cleanup] accept FIX_2388_INITTNSCONFIGURATION --- lib_com/core_com_config_fx.c | 8 -- lib_com/options.h | 1 - lib_com/prot_fx.h | 28 ------ lib_com/tcx_utils_fx.c | 31 ------- lib_com/tns_base.c | 154 --------------------------------- lib_dec/core_dec_init_fx.c | 4 - lib_dec/core_dec_switch_fx.c | 8 -- lib_enc/core_enc_init_fx.c | 4 - lib_enc/core_enc_switch_fx.c | 8 -- lib_enc/ivas_tcx_core_enc_fx.c | 4 - 10 files changed, 250 deletions(-) diff --git a/lib_com/core_com_config_fx.c b/lib_com/core_com_config_fx.c index cb9723487..fef5b6f39 100644 --- a/lib_com/core_com_config_fx.c +++ b/lib_com/core_com_config_fx.c @@ -997,11 +997,7 @@ void init_tcx_cfg_ivas_fx( IF( hTcxCfg->fIsTNSAllowed ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); -#else - InitTnsConfigs_ivas_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); -#endif SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) ); } @@ -1256,11 +1252,7 @@ void init_tcx_cfg_fx( IF( hTcxCfg->fIsTNSAllowed ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); -#else - InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); -#endif SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) ); } diff --git a/lib_com/options.h b/lib_com/options.h index 814cbf611..d86012fb8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2388_INITTNSCONFIGURATION /* FhG: issue 2388 : harmonizing InitTnsConfiguration() function */ #define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ #define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ #define FIX_2405_HARM_SMC_INIT /* VA, basop 2405, harmonisation of SMC init */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3eb8d8f32..c986f2ce7 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3436,22 +3436,8 @@ Word32 DTFS_getEngy_band_wb_fx( Word16 lband, Word16 hband ); -#ifndef FIX_2388_INITTNSCONFIGURATION -void InitTnsConfiguration( - const Word16 bwidth, - const Word16 frameLength, - STnsConfig *pTnsConfig, - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ); -#endif -#ifdef FIX_2388_INITTNSCONFIGURATION void InitTnsConfiguration_fx( -#else -void InitTnsConfiguration_ivas_fx( -#endif const Word16 bwidth, const Word16 frameLength, STnsConfig *pTnsConfig, @@ -4096,22 +4082,8 @@ void tcx_noise_filling_with_shift( const Word16 element_mode /* i : IVAS element mode */ ); -#ifndef FIX_2388_INITTNSCONFIGURATION -void InitTnsConfigs( - const Word16 bwidth, - const Word16 L_frame, - STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ); -#endif -#ifdef FIX_2388_INITTNSCONFIGURATION void InitTnsConfigs_fx -#else -void InitTnsConfigs_ivas_fx -#endif ( const Word16 bwidth, const Word16 L_frame, diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 44c034a20..69914bf66 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -1973,30 +1973,8 @@ void tcx_noise_filling_with_shift( *--------------------------------------------------------------*/ -#ifndef FIX_2388_INITTNSCONFIGURATION -void InitTnsConfigs( - const Word16 bwidth, /*Q0*/ - const Word16 L_frame, /*Q0*/ - STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, /*Q0*/ - const Word32 total_brate, /*Q0*/ - const Word16 element_mode, /*Q0*/ - const Word16 MCT_flag /*Q0*/ ) -{ - IF( GT_32( total_brate, ACELP_32k ) ) - { - InitTnsConfiguration( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); - } - InitTnsConfiguration( bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag ); - InitTnsConfiguration( bwidth, add( L_frame, shr( L_frame, 2 ) ), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag ); -} -#endif -#ifdef FIX_2388_INITTNSCONFIGURATION void InitTnsConfigs_fx -#else -void InitTnsConfigs_ivas_fx -#endif ( const Word16 bwidth, /*Q0*/ const Word16 L_frame, /*Q0*/ @@ -2008,19 +1986,10 @@ void InitTnsConfigs_ivas_fx { IF( GT_32( total_brate, ACELP_32k ) ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfiguration_fx( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); -#else - InitTnsConfiguration_ivas_fx( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); -#endif } -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfiguration_fx( bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag ); InitTnsConfiguration_fx( bwidth, add( L_frame, shr( L_frame, 2 ) ), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag ); -#else - InitTnsConfiguration_ivas_fx( bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag ); - InitTnsConfiguration_ivas_fx( bwidth, add( L_frame, shr( L_frame, 2 ) ), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag ); -#endif } void SetTnsConfig( diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 8c79d885f..1a491bfd8 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -72,138 +72,8 @@ static void ITF_GetFilterParameters_fx( Word32 rxx[], const Word16 maxOrder, Wor /* Interface functions */ /********************************/ -#ifndef FIX_2388_INITTNSCONFIGURATION -/** Init TNS configuration. - * Fills STnsConfig structure with sensible content. - * @param nSampleRate Sampling rate of the input. - * @param nFrameLength Frame length. - * @param pTnsConfig TNS configuration to be initialized. - * @return 0 on success, otherwise 1. - */ -void InitTnsConfiguration( - const Word16 bwidth, - const Word16 frameLength, - STnsConfig *pTnsConfig, - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ) -{ - Word16 iFilter = 0; - move16(); - Word16 *startLineFilter; - Word32 L_tmp; - Word32 nSampleRate; - Word16 s1; - Word16 s2; - (void) ( element_mode ); - (void) ( is_mct ); - nSampleRate = bwMode2fs[bwidth]; - move32(); - startLineFilter = &pTnsConfig->iFilterBorders[1]; - - /* Sanity checks */ - assert( ( nSampleRate > 0 ) && ( frameLength > 0 ) && ( pTnsConfig != NULL ) ); - test(); - test(); - IF( ( nSampleRate <= 0 ) || ( frameLength <= 0 ) || ( pTnsConfig == NULL ) ) - { - return /*TNS_FATAL_ERROR*/; - } - - - /* Initialize TNS filter flag and maximum order */ - move16(); - pTnsConfig->maxOrder = TNS_MAX_FILTER_ORDER; - - IF( LE_32( total_brate, ACELP_32k ) ) - { - move16(); - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParametersIGF32kHz_LowBR ) / sizeof( tnsParametersIGF32kHz_LowBR[0] ); - pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; - } - ELSE - { - test(); - IF( GT_32( nSampleRate, 32000 ) && EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) - { - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters48kHz_grouped ) / sizeof( tnsParameters48kHz_grouped[0] ); - move16(); - pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; - } - ELSE - IF( GT_32( nSampleRate, INT_FS_16k ) ) - { - { - - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters32kHz ) / sizeof( tnsParameters32kHz[0] ); - - move16(); - pTnsConfig->pTnsParameters = tnsParameters32kHz; - - if ( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ - { - move16(); - pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; - } - } - } - ELSE - { - IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ - { - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters16kHz_grouped ) / sizeof( tnsParameters16kHz_grouped[0] ); - pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; - } - ELSE - { - move16(); - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters16kHz ) / sizeof( tnsParameters16kHz[0] ); - pTnsConfig->pTnsParameters = tnsParameters16kHz; - } - } - } - - assert( pTnsConfig->nMaxFilters <= TNS_MAX_NUM_OF_FILTERS ); - - /* Set starting MDCT line for each filter based on the starting frequencies from the TNS table */ - - FOR( iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++ ) - { - assert( pTnsConfig->pTnsParameters[iFilter].startLineFrequency < nSampleRate / 2 ); - assert( nSampleRate <= 96000 ); - move16(); - startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); - } - - IF( igfStopFreq > 0 ) - { - L_tmp = L_mult( frameLength, igfStopFreq ); - s1 = sub( norm_l( L_tmp ), 1 ); - s2 = norm_l( nSampleRate ); - - move16(); - pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl( L_tmp, s1 ), extract_h( L_shl( nSampleRate, s2 ) ) ), sub( WORD16_BITS - 1, sub( s2, s1 ) ) ); - } - ELSE - { - move16(); - pTnsConfig->iFilterBorders[0] = frameLength; - } - return; /*TNS_NO_ERROR;*/ -} -#endif /* FIX_2388_INITTNSCONFIGURATION */ -#ifdef FIX_2388_INITTNSCONFIGURATION void InitTnsConfiguration_fx -#else -void InitTnsConfiguration_ivas_fx -#endif /* FIX_2388_INITTNSCONFIGURATION */ ( const Word16 bwidth, /*Q0*/ const Word16 frameLength, /*Q0*/ @@ -242,11 +112,7 @@ void InitTnsConfiguration_ivas_fx IF( LE_32( total_brate, ACELP_32k ) ) { move16(); -#ifdef FIX_2388_INITTNSCONFIGURATION pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParametersIGF32kHz_LowBR ) / sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ -#else - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ -#endif pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; } ELSE @@ -254,11 +120,7 @@ void InitTnsConfiguration_ivas_fx test(); IF( GT_32( nSampleRate, 32000 ) && EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) { -#ifdef FIX_2388_INITTNSCONFIGURATION pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters48kHz_grouped ) / sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ -#else - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters48kHz_grouped ), sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ -#endif move16(); pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } @@ -274,11 +136,7 @@ void InitTnsConfiguration_ivas_fx test(); IF( GT_16( element_mode, IVAS_SCE ) && GE_32( total_brate, L_tmp ) ) { -#ifdef FIX_2388_INITTNSCONFIGURATION pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters32kHz_Stereo ) / sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ -#else - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz_Stereo ), sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ -#endif move16(); IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { @@ -293,11 +151,7 @@ void InitTnsConfiguration_ivas_fx { move16(); -#ifdef FIX_2388_INITTNSCONFIGURATION pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters32kHz ) / sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ -#else - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ -#endif pTnsConfig->pTnsParameters = tnsParameters32kHz; @@ -312,21 +166,13 @@ void InitTnsConfiguration_ivas_fx IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { move16(); -#ifdef FIX_2388_INITTNSCONFIGURATION pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters16kHz_grouped ) / sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ -#else - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz_grouped ), sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ -#endif pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; } ELSE { move16(); -#ifdef FIX_2388_INITTNSCONFIGURATION pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters16kHz ) / sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ -#else - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ -#endif pTnsConfig->pTnsParameters = tnsParameters16kHz; } } diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 678d0b3d7..a75acb7e1 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -240,11 +240,7 @@ void open_decoder_LPD_fx( IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); -#else - InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); -#endif } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ if ( st->tcxonly == 0 ) diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 3a9148b76..5c824532e 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -133,11 +133,7 @@ void mode_switch_decoder_LPD_fx( IF( ( st->hTcxCfg->fIsTNSAllowed != 0 ) && st->hIGFDec != NULL ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0 /* 0 should be replaced with MCT_flag*/ ); -#else - InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0 /* 0 should be replaced with MCT_flag*/ ); -#endif } } } @@ -381,11 +377,7 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hTcxCfg->fIsTNSAllowed && st->hIGFDec != NULL && st->hTcxCfg != NULL ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); -#else - InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); -#endif SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, (Word8) EQ_16( st->element_mode, IVAS_CPE_MDCT ) ); } diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index c944bc5f4..23dcd45b1 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -361,11 +361,7 @@ static void init_tcx_fx( IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0 /*is_mct*/ ); -#else - InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0 /*is_mct*/ ); -#endif } /* TCX-LTP */ diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index 27c429ded..b94c1a0e3 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -109,11 +109,7 @@ void core_coder_mode_switch_fx( move16(); IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); -#else - InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); -#endif } st->narrowBand = 0; @@ -337,11 +333,7 @@ void core_coder_mode_switch_ivas_fx( IF( st->hTcxCfg->fIsTNSAllowed ) { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); -#else - InitTnsConfigs_ivas_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); -#endif SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT ); } diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index db24fbd35..20f030c6d 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -134,11 +134,7 @@ void stereo_tcx_init_enc_fx( test(); IF( !prev_IsTNSAllowed && st->hTcxCfg->fIsTNSAllowed && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) /* may happen in unified stereo when switching stereo technologies */ { -#ifdef FIX_2388_INITTNSCONFIGURATION InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, total_brate, st->element_mode, 0 ); -#else - InitTnsConfigs_ivas_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, total_brate, st->element_mode, 0 ); -#endif SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, 0 ); } -- GitLab From ea061b27c0d2d789261c469880143d1eecb8dcb4 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:55:34 +0100 Subject: [PATCH 03/20] [cleanup] accept FIX_2397_COPY_AQ_MDCT_CORE_BFI --- lib_com/options.h | 1 - lib_dec/ivas_mct_dec_fx.c | 4 ---- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 7 ------- 3 files changed, 12 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index d86012fb8..404bb620a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ #define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ #define FIX_2405_HARM_SMC_INIT /* VA, basop 2405, harmonisation of SMC init */ #define FIX_2280_REDUCTION_UNNECESSARY_SCALING /* VA: reduction of unnecessary scaling */ diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 73993d99a..2aca72cf1 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -222,12 +222,8 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { -#ifdef FIX_2397_COPY_AQ_MDCT_CORE_BFI test(); IF( !st_ivas->bfi && NE_16( hCPE->hCoreCoder[n]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) -#else - IF( NE_16( hCPE->hCoreCoder[n]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) -#endif { Word16 nSubframes; diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 8a8c7dc30..8df5a33fa 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -377,7 +377,6 @@ void stereo_mdct_core_dec_fx( } } -#ifdef FIX_2397_COPY_AQ_MDCT_CORE_BFI IF( !bfi ) { FOR( ch = 0; ch < nChannels; ch++ ) @@ -385,12 +384,6 @@ void stereo_mdct_core_dec_fx( Copy_Scale_sig_16_32_DEPREC( Aq_fx[ch], Aq_fx_32[ch], i_mult( nSubframes[ch], M ), sub( Q16, Q12 ) ); /* Q16 */ } } -#else - FOR( ch = 0; ch < nChannels; ch++ ) - { - Copy_Scale_sig_16_32_DEPREC( Aq_fx[ch], Aq_fx_32[ch], nSubframes[ch] * M, sub( Q16, Q12 ) ); /* Q16 */ - } -#endif /*--------------------------------------------------------------------------------* * Stereo processing -- GitLab From 2f6e379b0ab8571be234ca090264b8586ddb052d Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:56:17 +0100 Subject: [PATCH 04/20] [cleanup] accept HARMONIZE_TBE --- lib_com/ivas_prot_fx.h | 47 - lib_com/options.h | 1 - lib_com/prot_fx.h | 31 - lib_com/swb_tbe_com_fx.c | 51 - lib_dec/evs_dec_fx.c | 8 - lib_dec/ivas_core_dec_fx.c | 8 - lib_dec/swb_tbe_dec_fx.c | 4717 +++++++++--------------- lib_enc/evs_enc_fx.c | 8 - lib_enc/init_enc_fx.c | 8 - lib_enc/ivas_core_enc_fx.c | 8 - lib_enc/ivas_stereo_switching_enc_fx.c | 4 - lib_enc/ivas_stereo_td_enc_fx.c | 4 - lib_enc/prot_fx_enc.h | 28 - lib_enc/swb_tbe_enc_fx.c | 2309 ++---------- 14 files changed, 2052 insertions(+), 5180 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 6b75307f5..c32f62933 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1595,23 +1595,6 @@ void ivas_hq_core_dec_fx( #endif ); -#ifndef HARMONIZE_TBE -void ivas_HQ_FEC_Mem_update_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /*Q12*/ - Word32 *normq_fx, /*Q14*/ - Word16 *ynrm, - Word16 *Num_bands_p, - Word16 is_transient, - Word16 hqswb_clas, - Word16 c_switching_flag, - Word16 nb_sfm, - Word16 num_Sb, - Word16 *mean_en_high_fx, /*Q5*/ - Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ - Word16 output_frame -); -#endif /* o : Consumed bits Q0 */ Word16 ivas_hq_classifier_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -1861,36 +1844,6 @@ void stereoFdCngCoherence_fx( Word16 fft_exp ); -#ifndef HARMONIZE_TBE -void ivas_wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ - Word16 *Q_synth -); - -void GenShapedWBExcitation_ivas_fx( - Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ - Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ - Word32 *mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ - Word16 *mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ - Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ - const Word16 coder_type, /* i : coding type */ - const Word16 element_mode, /* i : element mode */ - const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor Q15*/ - const Word16 uv_flag, /* i : unvoiced flag */ - const Word16 igf_flag -); -#endif #ifndef HARM_FD_BWE /* o : Q_syn_hb*/ Word16 ivas_wb_bwe_dec_fx( diff --git a/lib_com/options.h b/lib_com/options.h index 404bb620a..e77f7f402 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ #define FIX_2405_HARM_SMC_INIT /* VA, basop 2405, harmonisation of SMC init */ #define FIX_2280_REDUCTION_UNNECESSARY_SCALING /* VA: reduction of unnecessary scaling */ #define FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE /* VA: reduction of unnecessary scaling, non-BE part */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c986f2ce7..db29ad2a3 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2717,12 +2717,6 @@ void Calc_rc0_h( Word16 *rc0 /* o : 1st parcor */ ); -#ifndef HARMONIZE_TBE -void Calc_rc0_h_ivas_enc_fx( - Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ -); -#endif void PostShortTerm_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -5584,36 +5578,11 @@ void swb_tbe_dec_fx( Word16 *Q_synth, Word16 *pitch_buf ); -#ifndef HARMONIZE_TBE -void ivas_dequantizeSHBparams_fx_9_1( - Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ - Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ - Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ - Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors, /* o : Q15 */ - Word16 *MSFlag ); -#endif void fb_tbe_dec_fx( -#ifndef HARMONIZE_TBE 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_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp ); - -void fb_tbe_dec_ivas_fx( -#endif - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, -#ifdef HARMONIZE_TBE Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ -#endif Word32 *hb_synth, /* o : high-band synthesis */ Word16 hb_synth_exp, Word16 *fb_synth_ref, diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 353b13c1b..3f962e16b 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -723,11 +723,7 @@ void Calc_rc0_h( return; } -#ifdef HARMONIZE_TBE static void Calc_rc0_h_ivas_enc_fx( -#else -void Calc_rc0_h_ivas_enc_fx( -#endif Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ) @@ -870,49 +866,6 @@ static void Calc_st_filt_tbe_ivas_enc_fx( return; } -#ifndef HARMONIZE_TBE -static void Calc_st_filt_tbe_ivas_dec_fx( - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 *mem_zero /* i : All zero memory */ -) -{ - Word32 L_g0; - - Word16 h[LONG_H_ST]; - - 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 ); - /* compute 1st parcor */ - Calc_rc0_h( h, parcor0 ); - - /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); - FOR( i = 1; i < LONG_H_ST; i++ ) - { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); - } - g0 = extract_h( L_shl( L_g0, 14 ) ); - - /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) - { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ - FOR( i = 0; i < L_SUBFR16k; i++ ) - { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); - move16(); - } - } - - return; -} -#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : output signal */ @@ -1235,11 +1188,7 @@ void PostShortTerm_ivas_dec_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ -#ifdef HARMONIZE_TBE Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); -#else - Calc_st_filt_tbe_ivas_dec_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); -#endif /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 9dd8f1873..0fa4c43f3 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -412,11 +412,7 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { -#ifdef HARMONIZE_TBE fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); -#else - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); -#endif } } ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) || @@ -851,11 +847,7 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { -#ifdef HARMONIZE_TBE fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); -#else - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); -#endif } } Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index be0b90043..2554c7c78 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1059,11 +1059,7 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ -#ifdef HARMONIZE_TBE wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); -#else - ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); -#endif } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) { @@ -1137,11 +1133,7 @@ ivas_error ivas_core_dec_fx( /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { -#ifdef HARMONIZE_TBE 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 ); -#else - fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); -#endif } } ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || flag_bwe_bws ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 3b842e704..3c92eaa12 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -13,11 +13,7 @@ * Local functions *-----------------------------------------------------------------*/ -#ifdef HARMONIZE_TBE static void dequantizeSHBparams_fx( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors, Word16 *MSFlag ); -#else -static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors ); -#endif static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2, Word16 *n_mem3 ); static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ); static void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ); @@ -258,21 +254,13 @@ static void rescale_genSHB_mem_dec( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { -#ifdef HARMONIZE_TBE hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf ); -#else - hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); -#endif move16(); } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { -#ifdef HARMONIZE_TBE hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf ); -#else - hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); -#endif move16(); } } @@ -614,11 +602,7 @@ void ResetSHBbuffer_Dec_fx( /* CALLED FROM : */ /*==========================================================================*/ -#ifdef HARMONIZE_TBE void wb_tbe_dec_fx( -#else -void ivas_wb_tbe_dec_fx( -#endif Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type Q0 */ Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc */ @@ -776,14 +760,8 @@ void ivas_wb_tbe_dec_fx( } ELSE { -#ifdef HARMONIZE_TBE /* de-quantization */ dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &j /*temp*/ ); -#else - /* de-quantization */ - Word16 ignore; - ivas_dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &ignore ); -#endif } } ELSE @@ -866,7 +844,6 @@ void ivas_wb_tbe_dec_fx( /* From low band excitation, generate highband excitation */ Lmax = 0; move32(); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) @@ -875,7 +852,6 @@ void ivas_wb_tbe_dec_fx( } } ELSE -#endif { FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { @@ -891,13 +867,11 @@ void ivas_wb_tbe_dec_fx( { Q_bwe_exc = norm_l( Lmax ); } -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Q_bwe_exc = sub( Q_bwe_exc, 1 ); } ELSE -#endif { Q_bwe_exc = sub( Q_bwe_exc, 3 ); } @@ -917,7 +891,6 @@ void ivas_wb_tbe_dec_fx( move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { prev_pow = 0; @@ -928,7 +901,6 @@ void ivas_wb_tbe_dec_fx( } } ELSE -#endif { W_tmp = 0; move64(); @@ -945,15 +917,12 @@ void ivas_wb_tbe_dec_fx( rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); } -#endif sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) @@ -964,7 +933,6 @@ void ivas_wb_tbe_dec_fx( } ELSE -#endif { FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { @@ -983,7 +951,6 @@ void ivas_wb_tbe_dec_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); #else -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, @@ -992,7 +959,6 @@ void ivas_wb_tbe_dec_fx( bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); } ELSE -#endif { GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, @@ -1018,13 +984,11 @@ void ivas_wb_tbe_dec_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); } ELSE -#endif { Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, exp, &exp ); } @@ -1051,7 +1015,6 @@ void ivas_wb_tbe_dec_fx( max = 0; move16(); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_FRAME16k / 4; i++ ) @@ -1060,7 +1023,6 @@ void ivas_wb_tbe_dec_fx( } } ELSE -#endif { FOR( i = 0; i < L_FRAME16k / 4; i++ ) { @@ -1107,12 +1069,7 @@ void ivas_wb_tbe_dec_fx( } test(); -#ifdef HARMONIZE_TBE IF( !st_fx->bfi && st_fx->prev_bfi ) -#else - test(); - IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) -#endif { IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) { @@ -1308,7 +1265,6 @@ void ivas_wb_tbe_dec_fx( } ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); @@ -1316,7 +1272,6 @@ void ivas_wb_tbe_dec_fx( Copy( upsampled_synth, synth, L_FRAME48k ); } ELSE -#endif { Copy_Scale_sig_16_32_no_sat( synth, tmp_synL, L_FRAME48k, sub( Q11, Qx ) ); interpolate_3_over_1_allpass_fx32( tmp_synL, L_FRAME16k, upsampled_synth_32fx, hBWE_TD->mem_resamp_HB_fx_32 ); @@ -1379,89 +1334,268 @@ void ivas_wb_tbe_dec_fx( return; } -#ifndef HARMONIZE_TBE -void wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ - Word16 *Q_synth ) + +/*======================================================================================*/ +/* FUNCTION : void swb_tbe_dec_fx () */ +/*--------------------------------------------------------------------------------------*/ +/* PURPOSE : SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module */ +/*--------------------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _(Word16) coder_type : coding type */ +/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ +/* _(Word16[]) voice_factors :voicing factors Q15 */ +/* _(Word16*) Q_white_exc :Q Format of White Exc */ +/* _(Word16*) Q_synth :Q Format of Synthesis */ +/*--------------------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _(Word16*)synth : SHB synthesis/final synthesis Q_white_exc */ +/* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ +/*--------------------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ Decoder_State *st_fx: : Decoder state structure */ +/*--------------------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------------------*/ +/* CALLED FROM : RX */ +/*======================================================================================*/ + +void swb_tbe_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word32 *bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ + Word16 Q_exc, + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ + Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ + Word16 *Q_white_exc, + Word16 *synth, /* o : SHB synthesis/final synthesis */ + Word16 *Q_synth, + Word16 *pitch_buf /* i : pitch buffer Q6 */ +) { Word16 i; - Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; - Word16 shaped_wb_excitation_frac[L_FRAME16k / 4]; - Word16 bwe_exc_extended_16[L_FRAME32k + 40]; - Word16 exc4kWhtnd[L_FRAME16k / 4]; - Word16 lsf_wb[LPC_SHB_ORDER_WB], lpc_wb[LPC_SHB_ORDER_WB + 1], GainShape[NUM_SHB_SUBFR]; + Word16 shaped_shb_excitation[L_FRAME16k + L_SHB_LAHEAD]; + Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; + Word16 lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR]; Word32 GainFrame; - Word16 error[L_FRAME16k]; - Word16 synth_frac[L_FRAME16k]; - Word16 upsampled_synth[L_FRAME48k]; - Word32 prev_pow, curr_pow, curr_frame_pow; + Word16 error[L_FRAME32k]; + Word32 L_ener; + Word16 ener; + Word16 is_fractive; + Word32 prev_pow, curr_pow, Lscale; + Word16 scale; + Word16 exp, tmp; + Word16 j, cnt; + Word16 n_mem, n_mem2, Qx, sc; + Word16 n_mem3; + Word32 Lmax, L_tmp; + Word16 frac; + + Word32 L_tmp1, L_tmp2; + Word16 expa, expb; + Word16 fraca, fracb; + Word16 GainShape_tmp[NUM_SHB_SUBGAINS]; + Word16 Q_bwe_exc; + Word16 Q_shb; + Word16 vf_modified[NB_SUBFR16k]; + Word16 stemp; + + Word16 tilt_swb_fec; + Word16 Q_bwe_exc_fb; + + Word16 lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; + Word16 lpc_shb_sf[4 * ( LPC_SHB_ORDER + 1 )]; + const Word16 *ptr_lsp_interp_coef; + Word32 shb_ener_sf_32; + Word16 shb_res_gshape[NB_SUBFR16k]; + Word16 mixFactors; + Word16 vind; + Word16 shb_res_dummy[L_FRAME16k]; + Word16 shaped_shb_excitationTemp[L_FRAME16k]; + Word32 ener_tmp[NUM_SHB_SUBGAINS]; + Word16 pitch_fx; + Word16 l_subframe_fx; + Word16 formant_fac; + Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; + Word16 refl[M]; + Word16 tilt_para; + Word16 tmp1, tmp2; + Word16 f_fx, inc_fx; + Word32 GainFrame_prevfrm_fx; + + Word16 synth_scale_fx; + Word16 mean_vf; + Word16 exp_ener, inv_ener; + Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */ + move32(); + Word16 max, n, temp, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD]; + Word32 curr_frame_pow; Word16 curr_frame_pow_exp; - Word16 temp, scale, n; - Word16 j; + Word32 L_prev_ener_shb; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; - Word16 Q_bwe_exc, Q_bwe_exc_ext, Qx; - Word16 n_mem, cnt; - Word16 max = 0; + /* initializations */ + GainFrame = L_deposit_l( 0 ); + mixFactors = 0; move16(); - Word32 L_tmp, Lacc, Lscale, Lmax = 0; - move32(); - Word16 tmp, exp, sc; - Word16 vf_modified[NB_SUBFR16k]; - Word16 uv_flag = 0; + shb_ener_sf_32 = L_deposit_l( 0 ); + set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); + st_fx->hTdCngDec->shb_dtx_count_fx = 0; move16(); - Word16 dummy = 0; + is_fractive = 0; move16(); - Word32 dummy2[HILBERT_MEM_SIZE]; - Word16 f, inc; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - set32_fx( &dummy2[0], 0, HILBERT_MEM_SIZE ); - IF( st_fx->bws_cnt == 0 ) + set16_fx( shb_res_gshape, 1638 /*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ + Q_shb = 0; /* high band target Q factor set to zero */ + move16(); + L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame ); + tilt_swb_fec = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); + /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ + /* o: tilt_swb_fec in Q11 */ + test(); + if ( st_fx->bfi && st_fx->clas_dec != UNVOICED_CLAS ) { - /* Initialization */ - set16_fx( GainShape, 11469 /*0.35f Q15*/, NUM_SHB_SUBFR ); - GainFrame = 1; - move32(); + tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; + move16(); + } - IF( !st_fx->bfi ) + /* WB/SWB bandwidth switching */ + test(); + test(); + IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && ( st_fx->clas_dec == UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( st_fx->prev_fractive == 0 ) && + ( LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) ) || + ( EQ_16( st_fx->prev_fractive, 1 ) && + GT_32( L_shr( st_fx->prev_enerLH_fx, 2 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ + || ( GT_32( L_shr( st_fx->enerLL_fx, 1 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/ + LT_16( st_fx->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/ + ) { - IF( EQ_16( st_fx->use_partial_copy, 1 ) ) + is_fractive = 0; + move16(); + } + ELSE + { + is_fractive = 1; + move16(); + } + } + + /* WB/SWB bandwidth switching */ + IF( st_fx->bws_cnt > 0 ) + { + f_fx = 1489; /*Q15*/ + move16(); + inc_fx = 1489; /*Q15*/ + move16(); + IF( EQ_16( is_fractive, 1 ) ) + { + Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); + } + ELSE + { + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - IF( NE_16( st_fx->last_extl, WB_TBE ) ) - { - hBWE_TD->GainFrame_prevfrm_fx = 0; - move32(); - hBWE_TD->lsp_prevfrm_fx[0] = 3277 /*0.1f Q15*/; - move16(); - FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); /*Q15*/ - move16(); - } - } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + move16(); + f_fx = add( f_fx, inc_fx ); + } + } + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && + !( ( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 ) && L_sub( st_fx->prev_enerLH_fx, ( L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) ) || + ( sub( st_fx->last_core, ACELP_CORE ) != 0 ) || ( ( sub( st_fx->last_core, ACELP_CORE ) == 0 ) && ( L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) ) || ( sub( s_xor( is_fractive, st_fx->prev_fractive ), 1 ) == 0 ) ) + { + set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); + } + ELSE + { + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + { + hBWE_TD->prev_GainShape_fx = 11587; + move16(); + } + set16_fx( GainShape, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); + } + + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ + } + ELSE /* No bandwidth switching */ + { + test(); + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) + { + f_fx = 1489; /*Q15*/ + move16(); + inc_fx = 1489; /*Q15*/ + move16(); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + move16(); + f_fx = add( f_fx, inc_fx ); + } + } + + IF( !st_fx->bfi ) + { + IF( st_fx->use_partial_copy ) + { + IF( NE_16( st_fx->last_extl, SWB_TBE ) ) + { + hBWE_TD->GainFrame_prevfrm_fx = 0; + move16(); + f_fx = 1489 /*0.045454f Q15*/; + move16(); + inc_fx = 1489 /*0.045454f Q15*/; + move16(); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + move16(); + f_fx = add( f_fx, inc_fx ); + } + } + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { /* Frame gain */ - st_fx->rf_indx_tbeGainFr = s_and( st_fx->rf_indx_tbeGainFr, 0xF ); /* only four LSBs are valid */ - move16(); - Copy32( SHBCB_FrameGain16_fx + st_fx->rf_indx_tbeGainFr, &GainFrame, 1 ); + GainFrame = L_mac( SHB_GAIN_QLOW_FX, st_fx->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX ); + move32(); /*Q18*/ + L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ + + frac = L_Extract_lc( L_tmp, &exp ); + L_tmp = Pow2( 30, frac ); + GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ test(); test(); test(); test(); test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); /*Q18*/ + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); } } ELSE @@ -1504,7 +1638,7 @@ void wb_tbe_dec_fx( GainFrame = 2097152; /* 8.0f in Q18 */ move32(); test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16 Q18*/ ) ) + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) { temp = 26214 /*0.8 Q15*/; move16(); @@ -1513,9 +1647,8 @@ void wb_tbe_dec_fx( default: fprintf( stderr, "RF SWB-TBE gain bits not supported." ); } - IF( EQ_16( st_fx->last_extl, WB_TBE ) ) + IF( EQ_16( st_fx->last_extl, SWB_TBE ) ) { - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); } test(); @@ -1525,9 +1658,9 @@ void wb_tbe_dec_fx( test(); test(); test(); - IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) + if ( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); /*Q18*/ + GainFrame = Mult_32_16( GainFrame, 9830 ); } } } @@ -1535,2964 +1668,1681 @@ void wb_tbe_dec_fx( ELSE { /* de-quantization */ - dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0 ); + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, + &shb_ener_sf_32, shb_res_gshape, &mixFactors, &j /*temp*/ ); + Q_shb = 0; + move16(); + /* o: shb_ener_sf_32 in (2*Q_shb) */ + /* o: shb_res_gshape in Q14 */ + /* o: GainShape Q15 */ + /* o: GainFrame Q18 */ } } - ELSE + ELSE /* FER concealment of TBE parameters */ { - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + + /* Gain shape concealment */ + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ + /* Gradient based GS estimation */ + gradientGainShape( st_fx, GainShape, &GainFrame ); + /* o: GainShape[16] in Q15 */ + /* o: GainFrame in Q18 */ } ELSE { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); /*Q15*/ + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, hBWE_TD->GainShape_Delay_fx[4 + i] ); + move16(); + } + } + IF( GT_16( tilt_swb_fec, ( 8 << 11 ) ) ) /* tilt_swb_fec in Q11 */ + { + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) + { + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ ); + } + ELSE IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) + { + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ ); + } + ELSE + { + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ ); + } + GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping ); + } + ELSE + { + GainFrame = hBWE_TD->GainFrame_prevfrm_fx; + move16(); /* gain locking */ + } + } + + /* FER concealment for 24.4kbps and 32kbps */ + test(); + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) + { + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) + { + /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ + L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/ + tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */ + tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/ + i = sub( norm_s( tmp1 ), 1 ); + tmp1 = shl( tmp1, i ); /* Qi */ + IF( tmp == 0 ) + { + tmp = 32767 /*1.0f Q15*/; + move16(); /*Q15*/ + } + ELSE + { + scale = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */ + scale = s_max( scale, 0 ); + /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ + tmp = shl_sat( scale, sub( sub( 15, exp ), i ) ); /*Q15*/ + } + scale = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */ + + test(); + IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || + GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) + { + /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ + shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale ); + + if ( GT_16( st_fx->nbLostCmpt, 1 ) ) + { + /* shb_ener_sf_32 *= 0.5f; */ + shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 ); + } + } + ELSE + { + /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ + L_tmp = L_mult( scale, scale ); /* Q29 */ + shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 ); + } + } + ELSE + { + test(); + IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || + GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) + { + /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ + shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); + } + ELSE + { + shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); + } + } } - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 ); + shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ ); + mixFactors = hBWE_TD->prev_mixFactors_fx; move16(); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ + set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, 5 ); /* Q14 */ } ELSE { - GainFrame = hBWE_TD->GainFrame_prevfrm_fx; /*Q18*/ - move32(); + set16_fx( shb_res_gshape, 16384 /*1.0f Q14*/, 5 ); /* Q14 */ } } + } - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) + /* get the gainshape delay */ + Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); + test(); + IF( ( st_fx->rf_flag != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; + hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); move16(); } - ELSE + } + ELSE + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; + hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape[i * 4]; move16(); } + } - Copy( voice_factors, vf_modified, NB_SUBFR16k ); - IF( EQ_16( coder_type, VOICED ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - vf_modified[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6554, voice_factors[i - 1] ) ); /* Q15 */ - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - vf_modified[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6554, voice_factors[3] ) ); /* Q15 */ - move16(); - } - } + /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ + /* mean(voice_factors[i], 4); */ + L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); + mean_vf = mac_r( L_tmp, voice_factors[3], 8192 ); - /* From low band excitation, generate highband excitation */ - Lmax = 0; - move32(); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - IF( Lmax == 0 ) + Copy( voice_factors, vf_modified, NB_SUBFR16k ); + + test(); + IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) + { + FOR( i = 1; i < NB_SUBFR; i++ ) { - Q_bwe_exc = 31; + L_tmp = L_mult( voice_factors[i], 26214 /*0.8f Q15*/ ); + vf_modified[i] = mac_r( L_tmp, voice_factors[i - 1], 6554 /*0.2f Q15*/ ); move16(); } - ELSE - { - Q_bwe_exc = norm_l( Lmax ); - } - Q_bwe_exc = sub( Q_bwe_exc, 1 ); - Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - find_max_mem_wb( st_fx, &n_mem ); - - if ( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) - { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); - } - - test(); - if ( uv_flag && GT_16( Q_bwe_exc, 20 ) ) - { - Q_bwe_exc = 20; - move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ - } - - prev_pow = 0; - move32(); - IF( st_fx->element_mode > EVS_MONO ) - { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0_sat( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ - } - - rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - 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 ) ); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); - - Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, - bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); - - curr_pow = 0; - move32(); - IF( st_fx->element_mode > EVS_MONO ) - { - tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - curr_pow = L_mac0_sat( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ - } - - if ( GT_16( voice_factors[0], 24576 ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ - } - - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, - shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); - - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + L_tmp = L_mult( voice_factors[4], 26214 /*0.8f Q15*/ ); + vf_modified[4] = mac_r( L_tmp, voice_factors[3], 6554 /*0.2f Q15*/ ); move16(); } - Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - - /* Update SHB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - + } - /* Adjust the subframe and frame gain of the synthesized shb signal */ - /* Scale the shaped excitation */ - ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, - window_wb_fx, subwin_wb_fx, - Q_bwe_exc_ext, st_fx->L_frame, 0, &dummy, dummy, dummy2 ); + /* convert quantized LSFs to LSPs for interpolation */ + E_LPC_lsf_lsp_conversion( lsf_shb, lsp_shb_2, LPC_SHB_ORDER ); - max = 0; - move16(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - max = s_max( max, shaped_wb_excitation[i] ); /*Q0*/ - } + test(); + IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) + { + /* SHB LSP values from prev. frame for interpolation */ + Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER ); + } + ELSE + { + /* Use current frame's LSPs; in effect no interpolation */ + Copy( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); + } - IF( max == 0 ) + test(); + test(); + test(); + IF( ( st_fx->bws_cnt == 0 ) && ( st_fx->bws_cnt1 == 0 ) && ( st_fx->prev_use_partial_copy == 0 ) && ( st_fx->use_partial_copy == 0 ) ) + { + lsf_diff[0] = 16384; + move16(); /*Q15*/ + lsf_diff[LPC_SHB_ORDER - 1] = 16384; + move16(); /*Q15*/ + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - curr_frame_pow = 1; - move32(); - n = 0; + lsf_diff[i] = sub( lsf_shb[i], lsf_shb[i - 1] ); move16(); } - ELSE - { - n = norm_s( max ); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - shaped_wb_excitation_frac[i] = shl_sat( shaped_wb_excitation[i], n ); /*Q14*/ - move16(); - } - n = sub( 14, n ); - curr_frame_pow = 1; - move32(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - L_tmp = L_mult_sat( shaped_wb_excitation_frac[i], shaped_wb_excitation_frac[i] ); /*Q29*/ - curr_frame_pow = L_add_sat( curr_frame_pow, L_shr( L_tmp, 7 ) ); /*Q22*/ - } - } - curr_frame_pow_exp = add( n, n ); - IF( GT_16( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ) - { - curr_frame_pow = L_shr( curr_frame_pow, sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ); - curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; - move16(); - } - ELSE - { - hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, hBWE_TD->prev_frame_pow_exp ) ); - move32(); - } + a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); + tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ + tmp1 = mult( 27425, tmp ); + tmp1 = mult( tmp1, tmp ); /*Q10*/ + tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/ + tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ test(); - IF( !st_fx->bfi && st_fx->prev_bfi ) + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) { - IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, exp ) ); /* Q15 */ - } - ELSE + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - scale = temp = 32767; - move16(); /* Q15 */ + hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff[i], 1 ); move16(); } + } - FOR( j = 0; j < 8; j++ ) + IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) + { + test(); + test(); + test(); + test(); + test(); + IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && + !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st_fx->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) { - GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); - FOR( i = 0; i < L_FRAME16k / ( 4 * 8 ); i++ ) - { - shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )] = mult_r( shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )], scale ); - } - IF( temp > 0 ) + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - IF( LT_16( scale, temp ) ) + IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) { - scale = div_s( scale, temp ); + tmp = mult( 26214, lsf_diff[i] ); + + test(); + IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ + { + st_fx->BER_detect = 1; + move16(); + tmp = 0; + move16(); + } + ELSE + { + tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); + } + + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); + move16(); } ELSE { - scale = 32767; + tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); + + test(); + IF( ( lsf_diff[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ + { + st_fx->BER_detect = 1; + move16(); + tmp = 0; + move16(); + } + ELSE + { + tmp = div_s( tmp, lsf_diff[i] ); + } + + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); move16(); } } - ELSE + w[0] = w[1]; + move16(); + w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; + move16(); + + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - scale = 0; + tmp1 = mult( lsp_shb_1[i], sub( 32767, w[i] ) ); + tmp2 = mult( lsp_shb_2[i], w[i] ); + lsp_temp[i] = add( tmp1, tmp2 ); move16(); } } - } - - hBWE_TD->prev_wb_bwe_frame_pow_fx = curr_frame_pow; - move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - - /* generate 16kHz SHB signal (6 - 8 kHz) from 2kHz signal */ - max = 0; - move16(); - FOR( cnt = 0; cnt < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; cnt++ ) - { - if ( GT_16( abs_s( shaped_wb_excitation[cnt] ), max ) ) + ELSE { - max = abs_s( shaped_wb_excitation[cnt] ); + Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); } } - Qx = norm_s( max ); - if ( max == 0 ) - { - Qx = 15; - move16(); - } - Qx = sub( Qx, 1 ); /* 1 bit space for saturation */ - - max = 0; + Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); + hBWE_TD->prev_tilt_para_fx = tilt_para; move16(); - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ), max ) ) - { - max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); - } - } - - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ), max ) ) - { - max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); - } - } + } + ELSE + { + Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); + } - IF( EQ_32( st_fx->output_Fs, 32000 ) ) - { - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - max = s_max( max, abs_s( hBWE_TD->state_32and48k_WB_upsample_fx[i] ) ); - } - } - IF( EQ_32( st_fx->output_Fs, 48000 ) ) + test(); + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) + { + /* ---------- SHB LSP interpolation ---------- */ + ptr_lsp_interp_coef = interpol_frac_shb; /*Q15*/ + FOR( j = 0; j < 4; j++ ) { - FOR( i = 0; i < INTERP_3_1_MEM_LEN; i++ ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - max = s_max( max, abs_s( hBWE_TD->mem_resamp_HB_fx[i] ) ); + /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ + /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1));*/ + L_tmp = L_mult( lsp_shb_1[i], ( *ptr_lsp_interp_coef ) ); + lsp_temp[i] = mac_r( L_tmp, lsp_shb_2[i], ( *( ptr_lsp_interp_coef + 1 ) ) ); + move16(); } - } - n_mem = 15; - move16(); - if ( max != 0 ) - { - n_mem = norm_s( max ); - } - n_mem = s_max( n_mem, 0 ); - - if ( GT_16( sub( Qx, hBWE_TD->prev_Qx ), n_mem ) ) - { - Qx = add( hBWE_TD->prev_Qx, n_mem ); - } - - FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) - { - shaped_wb_excitation[i] = shl( shaped_wb_excitation[i], Qx ); - move16(); - } + ptr_lsp_interp_coef += 2; - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - hBWE_TD->state_lsyn_filt_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); - move16(); - } + /* convert from lsp to lsf */ + /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); - move16(); + tmp = i_mult( j, LPC_SHB_ORDER + 1 ); + /* convert LSPs to LP coefficients */ + E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb_sf + tmp, LPC_SHB_ORDER ); + /* Bring the LPCs to Q12 */ + Copy_Scale_sig( lpc_shb_sf + tmp, lpc_shb_sf + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf[tmp] ), 2 ) ); } + } + /*ELSE*/ + { + /* for 13.2 and 16.4kbps */ + E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb, LPC_SHB_ORDER ); + Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb[0] ), 2 ) ); /* Q12 */ + } - GenWBSynth_fx( shaped_wb_excitation, error, hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx ); - - Copy( error + L_FRAME16k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - synth[i] = mult_r( error[i], 21299 ); - move16(); - } + /* Save the SWB LSP values from current frame for interpolation */ + Copy( lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); + /* lsp_shb_2_fx in Q15 */ - IF( st_fx->hBWE_FD != NULL ) - { - max = 0; - move16(); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) - { - max = s_max( max, abs_s( synth[cnt] ) ); - } + /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ + hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx; + move32(); + hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx; + move32(); + hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32; + move32(); + hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape[4]; + move16(); + hBWE_TD->prev_mixFactors_fx = mixFactors; + move16(); - IF( max == 0 ) - { - st_fx->hBWE_FD->last_wb_bwe_ener_fx = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) - { - synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ - move16(); - } - n = sub( sub( 14, n ), Qx ); + /* SWB CNG/DTX - update memories */ + if ( st_fx->hTdCngDec != NULL ) + { + Copy( st_fx->hTdCngDec->lsp_shb_prev_fx, st_fx->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ + Copy( lsf_shb, st_fx->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ + } - Lacc = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ - Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ - } + /* vind = (short)(mixFactors*8.0f); */ + vind = shl( mixFactors, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ + /* i: mixFactors in Q15 */ + /* o: vind in Q0 */ - L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ - exp = norm_l( L_tmp ); - tmp = round_fx_sat( L_shl( L_tmp, exp ) ); - exp = sub( add( exp, 22 ), 30 ); - tmp = div_s( 16384, tmp ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - st_fx->hBWE_FD->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ - move16(); - } - } + /* Determine formant PF strength */ + formant_fac = swb_formant_fac_fx( lpc_shb[1], &hBWE_TD->tilt_mem_fx ); + /* o: formant_fac in Q15 */ - IF( EQ_32( st_fx->output_Fs, 32000 ) ) /* 32kHz sampling rate, but only WB output - interpolate */ - { - Scale_sig( hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP, sub( Qx, hBWE_TD->prev_Qx ) ); - Interpolate_allpass_steep_fx( synth, hBWE_TD->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); - Copy( upsampled_synth, synth, L_FRAME32k ); - } - ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); - interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); - Copy( upsampled_synth, synth, L_FRAME48k ); - } + /* -------- start of memory rescaling -------- */ + /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ + Lmax = 0; + move32(); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } - ELSE + Q_bwe_exc = norm_l( Lmax ); + if ( Lmax == 0 ) { - f = 5461; - move16(); /* Q15 */ - inc = 5461; - move16(); /* Q15 */ - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - lsf_wb[i] = f; - move16(); /*Q15*/ - f = add_sat( f, inc ); - move16(); - } - GainFrame = 0; /* Q18 */ - move32(); - Qx = 0; - move16(); Q_bwe_exc = 31; move16(); - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ - move32(); - hBWE_TD->prev_frame_pow_exp = 0; - move16(); } + Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); - /* Update previous frame parameters for FEC */ - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) + /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ + find_max_mem_dec( st_fx, &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_fx->prev_Q_bwe_exc, n_mem ); + if ( GT_16( Q_bwe_exc, tmp ) ) { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ + Q_bwe_exc = tmp; + move16(); } - ELSE + + /* rescale the memories if Q_bwe_exc is different from previous frame */ + sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); + IF( sc != 0 ) { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); /*Q15*/ + rescale_genSHB_mem_dec( st_fx, sc ); } - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ - move32(); - IF( !st_fx->bfi ) + /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); + + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ - move16(); + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - *Q_synth = Qx; - 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 */ + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); + /* save the previous Q factor (32-bit) of the buffer */ st_fx->prev_Q_bwe_exc = Q_bwe_exc; move16(); - hBWE_TD->prev_Qx = Qx; + + 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; move16(); - return; -} -#endif + IF( GT_32( st_fx->total_brate, ACELP_32k ) ) + { + FOR( j = 0; j < 4; j++ ) + { + Copy( lpc_shb, &lpc_shb_sf[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); + } + } -/*======================================================================================*/ -/* FUNCTION : void swb_tbe_dec_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) coder_type : coding type */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ -/* _(Word16[]) voice_factors :voicing factors Q15 */ -/* _(Word16*) Q_white_exc :Q Format of White Exc */ -/* _(Word16*) Q_synth :Q Format of Synthesis */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)synth : SHB synthesis/final synthesis Q_white_exc */ -/* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State *st_fx: : Decoder state structure */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*======================================================================================*/ - -void swb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ - Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16 *Q_white_exc, - Word16 *synth, /* o : SHB synthesis/final synthesis */ - Word16 *Q_synth, - Word16 *pitch_buf /* i : pitch buffer Q6 */ -) -{ - Word16 i; - Word16 shaped_shb_excitation[L_FRAME16k + L_SHB_LAHEAD]; - Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR]; - Word32 GainFrame; - Word16 error[L_FRAME32k]; - Word32 L_ener; - Word16 ener; - Word16 is_fractive; - Word32 prev_pow, curr_pow, Lscale; - Word16 scale; - Word16 exp, tmp; - Word16 j, cnt; - Word16 n_mem, n_mem2, Qx, sc; - Word16 n_mem3; - Word32 Lmax, L_tmp; - Word16 frac; - - Word32 L_tmp1, L_tmp2; - Word16 expa, expb; - Word16 fraca, fracb; - Word16 GainShape_tmp[NUM_SHB_SUBGAINS]; - Word16 Q_bwe_exc; - Word16 Q_shb; - Word16 vf_modified[NB_SUBFR16k]; - Word16 stemp; - - Word16 tilt_swb_fec; - Word16 Q_bwe_exc_fb; - - Word16 lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; - Word16 lpc_shb_sf[4 * ( LPC_SHB_ORDER + 1 )]; - const Word16 *ptr_lsp_interp_coef; - Word32 shb_ener_sf_32; - Word16 shb_res_gshape[NB_SUBFR16k]; - Word16 mixFactors; - Word16 vind; - Word16 shb_res_dummy[L_FRAME16k]; - Word16 shaped_shb_excitationTemp[L_FRAME16k]; - Word32 ener_tmp[NUM_SHB_SUBGAINS]; - Word16 pitch_fx; - Word16 l_subframe_fx; - Word16 formant_fac; - Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; - Word16 refl[M]; - Word16 tilt_para; - Word16 tmp1, tmp2; - Word16 f_fx, inc_fx; - Word32 GainFrame_prevfrm_fx; - - Word16 synth_scale_fx; - Word16 mean_vf; - Word16 exp_ener, inv_ener; - Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */ - move32(); - Word16 max, n, temp, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD]; - Word32 curr_frame_pow; - Word16 curr_frame_pow_exp; - Word32 L_prev_ener_shb; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - - /* initializations */ - GainFrame = L_deposit_l( 0 ); - mixFactors = 0; - move16(); - shb_ener_sf_32 = L_deposit_l( 0 ); - set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); - st_fx->hTdCngDec->shb_dtx_count_fx = 0; - move16(); - is_fractive = 0; - move16(); - set16_fx( shb_res_gshape, 1638 /*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ - Q_shb = 0; /* high band target Q factor set to zero */ - move16(); - L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame ); - tilt_swb_fec = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); - /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ - /* o: tilt_swb_fec in Q11 */ - test(); - if ( st_fx->bfi && st_fx->clas_dec != UNVOICED_CLAS ) - { - tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; - move16(); - } - - /* WB/SWB bandwidth switching */ - test(); - test(); - IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && ( st_fx->clas_dec == UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( st_fx->prev_fractive == 0 ) && - ( LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) ) || - ( EQ_16( st_fx->prev_fractive, 1 ) && - GT_32( L_shr( st_fx->prev_enerLH_fx, 2 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ - || ( GT_32( L_shr( st_fx->enerLL_fx, 1 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/ - LT_16( st_fx->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/ - ) - { - is_fractive = 0; - move16(); - } - ELSE - { - is_fractive = 1; - move16(); - } - } - - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt > 0 ) - { - f_fx = 1489; /*Q15*/ - move16(); - inc_fx = 1489; /*Q15*/ - move16(); - IF( EQ_16( is_fractive, 1 ) ) - { - Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); - } - ELSE - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && - !( ( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 ) && L_sub( st_fx->prev_enerLH_fx, ( L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) ) || - ( sub( st_fx->last_core, ACELP_CORE ) != 0 ) || ( ( sub( st_fx->last_core, ACELP_CORE ) == 0 ) && ( L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) ) || ( sub( s_xor( is_fractive, st_fx->prev_fractive ), 1 ) == 0 ) ) - { - set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); - } - ELSE - { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) - { - hBWE_TD->prev_GainShape_fx = 11587; - move16(); - } - set16_fx( GainShape, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); - } - - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ - } - ELSE /* No bandwidth switching */ - { - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) - { - f_fx = 1489; /*Q15*/ - move16(); - inc_fx = 1489; /*Q15*/ - move16(); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - - IF( !st_fx->bfi ) - { - IF( st_fx->use_partial_copy ) - { - IF( NE_16( st_fx->last_extl, SWB_TBE ) ) - { - hBWE_TD->GainFrame_prevfrm_fx = 0; - move16(); - f_fx = 1489 /*0.045454f Q15*/; - move16(); - inc_fx = 1489 /*0.045454f Q15*/; - move16(); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); - - IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) - { - /* Frame gain */ - GainFrame = L_mac( SHB_GAIN_QLOW_FX, st_fx->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX ); - move32(); /*Q18*/ - L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ - - frac = L_Extract_lc( L_tmp, &exp ); - L_tmp = Pow2( 30, frac ); - GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) - { - /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); - } - } - ELSE - { - temp = 0; - move16(); - /* Frame gain */ - SWITCH( st_fx->rf_indx_tbeGainFr ) - { - case 0: - GainFrame = 131072; /* 0.5f in Q18 */ - move32(); - if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 1: - GainFrame = 524288; /* 2.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 2: - GainFrame = 1048576; /* 4.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 3: - GainFrame = 2097152; /* 8.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - default: - fprintf( stderr, "RF SWB-TBE gain bits not supported." ); - } - IF( EQ_16( st_fx->last_extl, SWB_TBE ) ) - { - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); - } - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) ) - { - test(); - test(); - test(); - test(); - if ( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) - { - GainFrame = Mult_32_16( GainFrame, 9830 ); - } - } - } - } - ELSE - { - /* de-quantization */ -#ifdef HARMONIZE_TBE - dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, - &shb_ener_sf_32, shb_res_gshape, &mixFactors, &j /*temp*/ ); -#else - dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, - &shb_ener_sf_32, shb_res_gshape, &mixFactors ); -#endif - Q_shb = 0; - move16(); - /* o: shb_ener_sf_32 in (2*Q_shb) */ - /* o: shb_res_gshape in Q14 */ - /* o: GainShape Q15 */ - /* o: GainFrame Q18 */ - } - } - ELSE /* FER concealment of TBE parameters */ - { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - - /* Gain shape concealment */ - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - /* Gradient based GS estimation */ - gradientGainShape( st_fx, GainShape, &GainFrame ); - /* o: GainShape[16] in Q15 */ - /* o: GainFrame in Q18 */ - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, hBWE_TD->GainShape_Delay_fx[4 + i] ); - move16(); - } - } - IF( GT_16( tilt_swb_fec, ( 8 << 11 ) ) ) /* tilt_swb_fec in Q11 */ - { - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ ); - } - ELSE IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ ); - } - ELSE - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ ); - } - GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping ); - } - ELSE - { - GainFrame = hBWE_TD->GainFrame_prevfrm_fx; - move16(); /* gain locking */ - } - } - - /* FER concealment for 24.4kbps and 32kbps */ - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ - L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/ - tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */ - tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/ - i = sub( norm_s( tmp1 ), 1 ); - tmp1 = shl( tmp1, i ); /* Qi */ - IF( tmp == 0 ) - { - tmp = 32767 /*1.0f Q15*/; - move16(); /*Q15*/ - } - ELSE - { - scale = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */ - scale = s_max( scale, 0 ); - /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ - tmp = shl_sat( scale, sub( sub( 15, exp ), i ) ); /*Q15*/ - } - scale = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */ - - test(); - IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || - GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) - { - /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale ); - - if ( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - /* shb_ener_sf_32 *= 0.5f; */ - shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 ); - } - } - ELSE - { - /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ - L_tmp = L_mult( scale, scale ); /* Q29 */ - shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 ); - } - } - ELSE - { - test(); - IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || - GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) - { - /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); - } - ELSE - { - shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); - } - } - } - - shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ ); - mixFactors = hBWE_TD->prev_mixFactors_fx; - move16(); - - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, 5 ); /* Q14 */ - } - ELSE - { - set16_fx( shb_res_gshape, 16384 /*1.0f Q14*/, 5 ); /* Q14 */ - } - } - } - - /* get the gainshape delay */ - Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); - test(); - IF( ( st_fx->rf_flag != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape[i * 4]; - move16(); - } - } - - /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ - /* mean(voice_factors[i], 4); */ - L_tmp = L_mult( voice_factors[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); - mean_vf = mac_r( L_tmp, voice_factors[3], 8192 ); - - Copy( voice_factors, vf_modified, NB_SUBFR16k ); - - test(); - IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mult( voice_factors[i], 26214 /*0.8f Q15*/ ); - vf_modified[i] = mac_r( L_tmp, voice_factors[i - 1], 6554 /*0.2f Q15*/ ); - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - L_tmp = L_mult( voice_factors[4], 26214 /*0.8f Q15*/ ); - vf_modified[4] = mac_r( L_tmp, voice_factors[3], 6554 /*0.2f Q15*/ ); - move16(); - } - } - - /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion( lsf_shb, lsp_shb_2, LPC_SHB_ORDER ); - - test(); - IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) - { - /* SHB LSP values from prev. frame for interpolation */ - Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER ); - } - ELSE - { - /* Use current frame's LSPs; in effect no interpolation */ - Copy( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); - } - - test(); - test(); - test(); - IF( ( st_fx->bws_cnt == 0 ) && ( st_fx->bws_cnt1 == 0 ) && ( st_fx->prev_use_partial_copy == 0 ) && ( st_fx->use_partial_copy == 0 ) ) - { - lsf_diff[0] = 16384; - move16(); /*Q15*/ - lsf_diff[LPC_SHB_ORDER - 1] = 16384; - move16(); /*Q15*/ - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - lsf_diff[i] = sub( lsf_shb[i], lsf_shb[i - 1] ); - move16(); - } - - a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); - tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ - tmp1 = mult( 27425, tmp ); - tmp1 = mult( tmp1, tmp ); /*Q10*/ - tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/ - tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff[i], 1 ); - move16(); - } - } - - IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && - !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st_fx->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) - { - tmp = mult( 26214, lsf_diff[i] ); - - test(); - IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - } - - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - ELSE - { - tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - - test(); - IF( ( lsf_diff[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s( tmp, lsf_diff[i] ); - } - - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - } - w[0] = w[1]; - move16(); - w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; - move16(); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp1 = mult( lsp_shb_1[i], sub( 32767, w[i] ) ); - tmp2 = mult( lsp_shb_2[i], w[i] ); - lsp_temp[i] = add( tmp1, tmp2 ); - move16(); - } - } - ELSE - { - Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); - } - } - - Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = tilt_para; - move16(); - } - ELSE - { - Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); - } - - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - /* ---------- SHB LSP interpolation ---------- */ - ptr_lsp_interp_coef = interpol_frac_shb; /*Q15*/ - FOR( j = 0; j < 4; j++ ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ - /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1));*/ - L_tmp = L_mult( lsp_shb_1[i], ( *ptr_lsp_interp_coef ) ); - lsp_temp[i] = mac_r( L_tmp, lsp_shb_2[i], ( *( ptr_lsp_interp_coef + 1 ) ) ); - move16(); - } - ptr_lsp_interp_coef += 2; - - /* convert from lsp to lsf */ - /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - - tmp = i_mult( j, LPC_SHB_ORDER + 1 ); - /* convert LSPs to LP coefficients */ - E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb_sf + tmp, LPC_SHB_ORDER ); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf + tmp, lpc_shb_sf + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf[tmp] ), 2 ) ); - } - } - /*ELSE*/ - { - /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb, LPC_SHB_ORDER ); - Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb[0] ), 2 ) ); /* Q12 */ - } - - /* Save the SWB LSP values from current frame for interpolation */ - Copy( lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); - /* lsp_shb_2_fx in Q15 */ - - /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ - hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx; - move32(); - hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx; - move32(); - hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32; - move32(); - hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape[4]; - move16(); - hBWE_TD->prev_mixFactors_fx = mixFactors; - move16(); - - /* SWB CNG/DTX - update memories */ - if ( st_fx->hTdCngDec != NULL ) - { - Copy( st_fx->hTdCngDec->lsp_shb_prev_fx, st_fx->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - Copy( lsf_shb, st_fx->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - } - - /* vind = (short)(mixFactors*8.0f); */ - vind = shl( mixFactors, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ - /* i: mixFactors in Q15 */ - /* o: vind in Q0 */ - - /* Determine formant PF strength */ - formant_fac = swb_formant_fac_fx( lpc_shb[1], &hBWE_TD->tilt_mem_fx ); - /* o: formant_fac in Q15 */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = 0; - move32(); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if ( Lmax == 0 ) - { - Q_bwe_exc = 31; - 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_fx, &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_fx->prev_Q_bwe_exc, n_mem ); - if ( GT_16( Q_bwe_exc, tmp ) ) - { - Q_bwe_exc = tmp; - move16(); - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_dec( st_fx, sc ); - } - - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - 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 ) ); - } - 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_fx->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, L_SHB_LAHEAD ); - - /* save the previous Q factor (32-bit) of the buffer */ - st_fx->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; - move16(); - - IF( GT_32( st_fx->total_brate, ACELP_32k ) ) - { - FOR( j = 0; j < 4; j++ ) - { - Copy( lpc_shb, &lpc_shb_sf[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 + L_SHB_LAHEAD, lpc_shb, White_exc16k, - hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, - shb_res_gshape, shb_res_dummy, &vind, formant_fac, 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, st_fx->prev_bfi ); - - *Q_white_exc = Q_bwe_exc_fb; - move16(); - IF( EQ_16( st_fx->extl, FB_TBE ) ) - { - hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; - move16(); - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - hBWE_TD->prev_Q_bwe_exc_fb = 51; - move16(); - } - /* rescale the TBE post proc memory */ - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) - { - /* TD BWE post-processing */ - PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD + i], lpc_shb, &shaped_shb_excitationTemp[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 ); - } - Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ - - tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow = L_mac0_sat( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ - curr_pow = L_mac0_sat( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - - if ( GT_16( voice_factors[0], 24576 /*0.75f Q15*/ ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ - } - - Lscale = root_a_over_b_fx( curr_pow, shl( Q_bwe_exc, 1 ), prev_pow, shl( Q_bwe_exc, 1 ), &exp ); - - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - IF( exp < 0 ) - { - Lscale = L_shl( Lscale, exp ); - 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++ ) - { - temp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ - temp = sub( 32767 /*1.0f Q15*/, temp ); - Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - ELSE - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - temp = 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 ) ), temp ); /* Q31-exp */ - temp = sub( 32767 /*1.0f Q15*/, temp ); - Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - - /* Update SHB excitation */ - Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - - l_subframe_fx = L_FRAME16k / NUM_SHB_SUBGAINS; - L_ener = 0; - move32(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - L_tmp = 0; - move32(); - ener_tmp[i] = 0; - move32(); - { - Word64 tmp64 = 0; - move64(); - FOR( j = 0; j < l_subframe_fx; j++ ) - { - tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )], shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )] ); /* 2*Q_bwe_exc */ - } - L_tmp = W_sat_l( tmp64 ); - } - - L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - ener_tmp[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ - move32(); - L_ener = L_add_sat( L_ener, L_shr( ener_tmp[i], 2 ) ); /* 2*Q_bwe_exc */ - } - } - ener = 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 */ - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt > 0 ) - { - ener = mult( ener, 11587 ); - /*bandwidth switching should be updated*/ - if ( GT_16( st_fx->tilt_swb_fx, 16384 ) ) - { - st_fx->prev_fractive = 1; - move16(); - } - - IF( is_fractive == 0 ) - { - IF( GT_16( st_fx->tilt_wb_fx, 2048 ) ) /*assuming st_fx->tilt_wb_fx in Q11*/ - { - st_fx->tilt_wb_fx = 2048; - move16(); - } - ELSE IF( LT_16( st_fx->tilt_wb_fx, 1024 ) ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - test(); - if ( EQ_16( st_fx->prev_fractive, 1 ) && GT_16( st_fx->tilt_wb_fx, 1024 ) ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - } - ELSE - { - IF( GT_16( st_fx->tilt_wb_fx, 8192 ) ) - { - IF( st_fx->prev_fractive == 0 ) - { - st_fx->tilt_wb_fx = 8192; - move16(); - } - ELSE - { - st_fx->tilt_wb_fx = 16384; - move16(); - } - } - ELSE - { - st_fx->tilt_wb_fx = shl( st_fx->tilt_wb_fx, 2 ); - move16(); - } - } - - IF( ener != 0 ) - { - L_tmp = L_shl( L_mult0( ener, st_fx->tilt_wb_fx ), sub( st_fx->Q_syn2, 14 ) ); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ - exp_ener = norm_s( ener ); - tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ - - test(); - IF( GT_32( L_tmp, st_fx->enerLH_fx ) ) /*st_fx->Q_syn2*/ - { - st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ - move16(); - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ - } - ELSE IF( LT_32( L_tmp, Mult_32_16( st_fx->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) - { - st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ - move16(); - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ - } - L_tmp = L_mult0( st_fx->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ - } - ELSE - { - GainFrame_prevfrm_fx = 0; - move32(); - } - - IF( EQ_16( is_fractive, 1 ) ) - { - GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 10 ); - } - ELSE - { - GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 8 ); - } - - test(); - IF( EQ_16( s_and( is_fractive, st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) - { - GainFrame = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); /* 18 +15 -15 = 18*/ - } - ELSE - { - test(); - test(); - test(); - test(); - IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st_fx->prev_fractive ) == 0 ) ) - { - GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); - } - ELSE - { - test(); - IF( ( is_fractive == 0 ) && EQ_16( st_fx->prev_fractive, 1 ) ) - { - L_tmp1 = L_shl( Mult_32_16( GainFrame, 3277 ), 13 ); /* 31 */ - L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ - GainFrame = L_add( Mult_32_32( GainFrame, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */ - } - ELSE - { - GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame ), 1 ) ); /* 18 */ - } - } - } - - GainFrame = Mult_32_16( GainFrame, i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ) ); /*Q18*/ - } - ELSE - { - if ( st_fx->bws_cnt1 > 0 ) - { - GainFrame = Mult_32_16( GainFrame, i_mult( st_fx->bws_cnt1, 819 ) ); /*Q18*/ - } - IF( GE_16( st_fx->nbLostCmpt, 1 ) ) - { - ener = s_max( 1, ener ); - exp_ener = norm_s( ener ); - tmp = shl( ener, 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_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ - } - - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->clas_dec != UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && - ( ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ) ) - { - IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) ) /*18*/ - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame, 19661 ) ); /*18*/ - } - ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); - } - ELSE - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } + /* 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 + L_SHB_LAHEAD, lpc_shb, White_exc16k, + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, + shb_res_gshape, shb_res_dummy, &vind, formant_fac, 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, st_fx->prev_bfi ); - test(); - IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) ) - { - exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); - tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ - tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/ - tmp = extract_h( L_shl( L_mult0( tmp, st_fx->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */ - GainFrame = L_shl( Mult_32_16( GainFrame, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ - } - } - ELSE IF( ( ( st_fx->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) - { - test(); - IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) - { - GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ - } - ELSE - { - GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ - } - } - ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) - { - test(); - IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ); - } - ELSE - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - } - } - } - st_fx->prev_fractive = is_fractive; + *Q_white_exc = Q_bwe_exc_fb; move16(); - - /* Adjust the subframe and frame gain of the synthesized shb signal */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - /* pitch = 0.25f*sum_s(pitch_buf, 4); */ - L_tmp = L_mult( pitch_buf[0], 8192 ); - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mac( L_tmp, pitch_buf[i], 8192 ); /* pitch_buf in Q6 x 0.25 in Q15 */ - } - pitch_fx = round_fx( L_tmp ); /* Q6 */ + hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + move16(); } ELSE { - /* pitch_fx = 0.2f*sum_s(pitch_buf, 5); */ - L_tmp = L_mult( pitch_buf[0], 6554 ); - FOR( i = 1; i < NB_SUBFR16k; i++ ) - { - L_tmp = L_mac( L_tmp, pitch_buf[i], 6554 ); /* pitch_buf in Q6 x 0.2 in Q15 */ - } - pitch_fx = round_fx( L_tmp ); /* Q6 */ - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->prev_coder_type, coder_type ) && NE_16( coder_type, UNVOICED ) ) || ( LE_32( st_fx->total_brate, ACELP_16k40 ) && ( EQ_16( st_fx->prev_coder_type, coder_type ) || ( EQ_16( st_fx->prev_coder_type, VOICED ) && EQ_16( coder_type, GENERIC ) ) || ( EQ_16( st_fx->prev_coder_type, GENERIC ) && EQ_16( coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st_fx->extl, FB_TBE ) ) - { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - GainShape_tmp[i] = GainShape[i * 4]; /* Q15 */ - move16(); - } - - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* if( ener_tmp_fx[i]*GainShape_tmp_fx[i] > st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ - L_tmp1 = Mult_32_16( ener_tmp[i], GainShape_tmp[i] ); /* (2*Q_bwe_exc) */ - L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st_fx->prev_ener_fx_Q) */ - tmp = sub( shl( Q_bwe_exc, 1 ), shl( hBWE_TD->prev_ener_fx_Q, 1 ) ); - L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ - IF( GT_32( L_tmp1, L_tmp2 ) ) - { - /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ - /* tmp = L_tmp2/ener_tmp_fx[i]*/ - L_tmp = L_tmp2; - move32(); - if ( L_tmp2 < 0 ) - { - L_tmp = L_negate( L_tmp2 ); - } - - expb = norm_l( L_tmp ); - fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) ); - expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */ - - expa = norm_l( ener_tmp[i] ); - fraca = extract_h( L_shl( ener_tmp[i], expa ) ); - expa = sub( 30, expa ); - - scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); - expb = sub( expb, scale ); - - tmp = div_s( fracb, fraca ); - exp = sub( sub( expb, expa ), 1 ); - tmp = shl( tmp, exp ); - GainShape_tmp[i] = add( tmp, shr( GainShape_tmp[i], 1 ) ); /* Q15 */ - move16(); - } - - hBWE_TD->prev_ener_fx = ener_tmp[i]; - move32(); - hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; - move16(); - hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; - move16(); - } - FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) - { - Word16 idx = 0; - move16(); - IF( i != 0 ) - { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); - } - GainShape[i] = GainShape_tmp[idx]; - move16(); - } + /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. + 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ + hBWE_TD->prev_Q_bwe_exc_fb = 51; + move16(); } - ELSE + /* rescale the TBE post proc memory */ + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } + FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) + { + /* TD BWE post-processing */ + PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD + i], lpc_shb, &shaped_shb_excitationTemp[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 ); + } + Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ - /* Back up the Q_bwe_exc associated with shaped_shb_excitation for the next frame*/ - hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; - move16(); - - /* Scale the shaped excitation */ - ScaleShapedSHB_fx( SHB_OVERLAP_LEN, - shaped_shb_excitation, /* i/o: Q_bwe_exc */ - hBWE_TD->syn_overlap_fx, - GainShape, /* Q15 */ - GainFrame, /* Q18 */ - window_shb_fx, - subwin_shb_fx, - &Q_bwe_exc, &Qx, n_mem3, hBWE_TD->prev_Q_bwe_syn2 ); - - max = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) + tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 ); + prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ + FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ + prev_pow = L_mac0_sat( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ + curr_pow = L_mac0_sat( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ } - IF( max == 0 ) + if ( GT_16( voice_factors[0], 24576 /*0.75f Q15*/ ) ) { - curr_frame_pow = 0; - move16(); - n = 0; + curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ + } + + Lscale = root_a_over_b_fx( curr_pow, shl( Q_bwe_exc, 1 ), prev_pow, shl( Q_bwe_exc, 1 ), &exp ); + + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) + { + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } - ELSE + IF( exp < 0 ) { - n = norm_s( max ); - max = 0; + Lscale = L_shl( Lscale, exp ); + exp = 0; move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ - move16(); - } - - curr_frame_pow = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ - curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ - } } - curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - - - tmp = sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ); - IF( tmp > 0 ) /* shifting prev */ + /* + 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 ) ) { - IF( GT_16( tmp, 32 ) ) + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { - hBWE_TD->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); - move16(); - tmp = 32; + temp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ + temp = sub( 32767 /*1.0f Q15*/, temp ); + Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } - hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); - move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); } - ELSE /* shifting curr */ + ELSE { - IF( LT_16( tmp, -32 ) ) + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { - curr_frame_pow_exp = sub( hBWE_TD->prev_frame_pow_exp, 32 ); - tmp = -32; + temp = 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 ) ), temp ); /* Q31-exp */ + temp = sub( 32767 /*1.0f Q15*/, temp ); + Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } - curr_frame_pow = L_shr( curr_frame_pow, -tmp ); - curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; - move16(); } - test(); - IF( !st_fx->bfi && st_fx->prev_bfi ) - { - L_tmp = L_shr( curr_frame_pow, 4 ); - L_tmp = Mult_32_16( L_tmp, 17476 ); - test(); - test(); - IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && - ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st_fx->prev_coder_type, UNVOICED ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ + /* Update SHB excitation */ + Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - } - ELSE - { - scale = temp = 32767; - move16(); /*Q15*/ - } - FOR( j = 0; j < 8; j++ ) + l_subframe_fx = L_FRAME16k / NUM_SHB_SUBGAINS; + L_ener = 0; + move32(); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + L_tmp = 0; + move32(); + ener_tmp[i] = 0; + move32(); { - GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - move16(); - GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); - move16(); - FOR( i = 0; i < L_FRAME16k / 8; i++ ) + Word64 tmp64 = 0; + move64(); + FOR( j = 0; j < l_subframe_fx; j++ ) { - shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )], scale ); - move16(); + tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )], shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )] ); /* 2*Q_bwe_exc */ } + L_tmp = W_sat_l( tmp64 ); + } - IF( temp > 0 ) - { - /* scale <= temp, due to scale = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow ), temp = sqrt( scale, 1.f/8.f ) - and curr_frame_pow > st->prev_swb_bwe_frame_pow_fx -> scale <= 1.0, sqrt(scale, 1.f/8.f) >= scale */ - IF( LT_16( scale, temp ) ) - { - scale = div_s( scale, temp ); - } - ELSE - { - scale = 32767; - move16(); - } - } - ELSE - { - scale = 0; - move16(); - } + L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ + IF( L_tmp != 0 ) + { + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) ); + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + ener_tmp[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ + move32(); + L_ener = L_add_sat( L_ener, L_shr( ener_tmp[i], 2 ) ); /* 2*Q_bwe_exc */ } } - - /* adjust the FEC frame energy */ - IF( st_fx->bfi ) + ener = 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 */ + /* WB/SWB bandwidth switching */ + IF( st_fx->bws_cnt > 0 ) { - scale = temp = 4096; - move16(); /*Q12*/ - - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) + ener = mult( ener, 11587 ); + /*bandwidth switching should be updated*/ + if ( GT_16( st_fx->tilt_swb_fx, 16384 ) ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && - NE_16( st_fx->prev_coder_type, UNVOICED ) && - ( st_fx->last_good != UNVOICED_CLAS ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } + st_fx->prev_fractive = 1; + move16(); } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) + + IF( is_fractive == 0 ) { - test(); - test(); - test(); - test(); - test(); - IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) + IF( GT_16( st_fx->tilt_wb_fx, 2048 ) ) /*assuming st_fx->tilt_wb_fx in Q11*/ { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + st_fx->tilt_wb_fx = 2048; + move16(); } - ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) + ELSE IF( LT_16( st_fx->tilt_wb_fx, 1024 ) ) { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + st_fx->tilt_wb_fx = 1024; + move16(); } - } - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = shl_sat( mult_r( GainShape[2 * j], scale ), 3 ); - move16(); /* 15 +12 +3-15 =15*/ - GainShape[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape[add( 2 * j, 1 )], scale ), 3 ); - move16(); - FOR( i = 0; i < 40; i++ ) + test(); + if ( EQ_16( st_fx->prev_fractive, 1 ) && GT_16( st_fx->tilt_wb_fx, 1024 ) ) { - shaped_shb_excitation[add( i, j * 40 )] = shl_sat( mult_r( shaped_shb_excitation[add( i, j * 40 )], scale ), 3 ); - move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ + st_fx->tilt_wb_fx = 1024; + move16(); } - - IF( temp > 0 ) + } + ELSE + { + IF( GT_16( st_fx->tilt_wb_fx, 8192 ) ) { - IF( LT_16( scale, temp ) ) + IF( st_fx->prev_fractive == 0 ) { - scale = shr( div_s( scale, temp ), 3 ); + st_fx->tilt_wb_fx = 8192; + move16(); } ELSE { - tmp1 = sub( norm_s( scale ), 1 ); - tmp2 = norm_s( temp ); - scale = div_s( shl( scale, tmp1 ), shl( temp, tmp2 ) ); - scale = shr( scale, add( sub( tmp1, tmp2 ), 3 ) ); + st_fx->tilt_wb_fx = 16384; + move16(); } } ELSE { - scale = 0; + st_fx->tilt_wb_fx = shl( st_fx->tilt_wb_fx, 2 ); move16(); } } - } - hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow; - move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); + IF( ener != 0 ) + { + L_tmp = L_shl( L_mult0( ener, st_fx->tilt_wb_fx ), sub( st_fx->Q_syn2, 14 ) ); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ + exp_ener = norm_s( ener ); + tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ - { - Word64 prev_ener_shb64 = 0; - move64(); - FOR( i = 0; i < L_FRAME16k; i++ ) + test(); + IF( GT_32( L_tmp, st_fx->enerLH_fx ) ) /*st_fx->Q_syn2*/ + { + st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ + move16(); + /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ + } + ELSE IF( LT_32( L_tmp, Mult_32_16( st_fx->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) + { + st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ + move16(); + /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ + } + L_tmp = L_mult0( st_fx->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ + GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + } + ELSE { - prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /* Q0 */ + GainFrame_prevfrm_fx = 0; + move32(); } - L_prev_ener_shb = W_sat_l( prev_ener_shb64 ); - } - - /* st->prev_ener_shb = sqrt(st->prev_ener_shb/L_FRAME16k) */ - L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */ - st_fx->prev_ener_shb_fx = 0; - move16(); - - IF( L_prev_ener_shb != 0 ) - { - exp = norm_l( L_prev_ener_shb ); - tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); - exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - st_fx->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ - move16(); - } - /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ - L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ - tmp = 0; - move16(); - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ - } - set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ - /* 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++ ) + IF( EQ_16( is_fractive, 1 ) ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); - move16(); + GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 10 ); + } + ELSE + { + GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 8 ); } - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + test(); + IF( EQ_16( s_and( is_fractive, st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) { - FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) + GainFrame = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); /* 18 +15 -15 = 18*/ + } + ELSE + { + test(); + test(); + test(); + test(); + IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st_fx->prev_fractive ) == 0 ) ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); - move32(); + GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); + } + ELSE + { + test(); + IF( ( is_fractive == 0 ) && EQ_16( st_fx->prev_fractive, 1 ) ) + { + L_tmp1 = L_shl( Mult_32_16( GainFrame, 3277 ), 13 ); /* 31 */ + L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ + GainFrame = L_add( Mult_32_32( GainFrame, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */ + } + ELSE + { + GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame ), 1 ) ); /* 18 */ + } } } - IF( EQ_32( st_fx->output_Fs, 48000 ) ) + + GainFrame = Mult_32_16( GainFrame, i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ) ); /*Q18*/ + } + ELSE + { + if ( st_fx->bws_cnt1 > 0 ) { - Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); + GainFrame = Mult_32_16( GainFrame, i_mult( st_fx->bws_cnt1, 819 ) ); /*Q18*/ } - IF( EQ_32( st_fx->output_Fs, 16000 ) ) + IF( GE_16( st_fx->nbLostCmpt, 1 ) ) { - Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); + ener = s_max( 1, ener ); + exp_ener = norm_s( ener ); + tmp = shl( ener, 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_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ } - } - /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_Hilbert_Mem_fx in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ - /* o: error in (Qx) */ - GenSHBSynth_fx( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); - - Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); - /* resample SHB synthesis (if needed) and scale down */ - synth_scale_fx = 32767; - move16(); /* 1.0 in Q15 */ - if ( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - synth_scale_fx = 29491; - move16(); /* 0.9 in Q15 */ - } - - IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - IF( EQ_32( st_fx->extl, FB_TBE ) ) + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { - tmp = norm_l( GainFrame ); - if ( GainFrame == 0 ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->clas_dec != UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && + ( ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ) ) { - tmp = 31; - move16(); - } - L_tmp = L_shl( GainFrame, tmp ); /* 18 + tmp */ + IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) ) /*18*/ + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame, 19661 ) ); /*18*/ + } + ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame ) ) + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); + } + ELSE + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); + } - tmp1 = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - Word16 idx = 0; - IF( i != 0 ) + test(); + IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) ) { - idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); + exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); + tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ + tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/ + tmp = extract_h( L_shl( L_mult0( tmp, st_fx->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */ + GainFrame = L_shl( Mult_32_16( GainFrame, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } - L_tmp1 = Mult_32_16( L_tmp, GainShape[idx] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ - move16(); - tmp1 = s_max( tmp1, abs_s( White_exc16k[i] ) ); } - - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ - move16(); - tmp = norm_s( tmp1 ); - if ( tmp1 == 0 ) + ELSE IF( ( ( st_fx->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) ) { - tmp = 15; - move16(); + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); } - - FOR( i = 0; i < L_FRAME16k; i++ ) + } + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) { - White_exc16k[i] = shl( White_exc16k[i], sub( tmp, 1 ) ); - move16(); + test(); + IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + { + GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ + } + ELSE + { + GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ + } } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); - move16(); - } - - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) + ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) { - error[i] = mult_r( error[i], synth_scale_fx ); - move16(); + test(); + IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ); + } + ELSE + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); + } } } - - interpolate_3_over_2_allpass_fx( error, L_FRAME32k, synth, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); } - ELSE IF( EQ_32( st_fx->output_Fs, 32000 ) ) + st_fx->prev_fractive = is_fractive; + move16(); + + /* Adjust the subframe and frame gain of the synthesized shb signal */ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - synth[i] = mult_r( synth_scale_fx, error[i] ); - move16(); /*Qx*/ - } - } - ELSE + /* pitch = 0.25f*sum_s(pitch_buf, 4); */ + L_tmp = L_mult( pitch_buf[0], 8192 ); + FOR( i = 1; i < NB_SUBFR; i++ ) { - Copy( error, synth, L_FRAME32k ); + L_tmp = L_mac( L_tmp, pitch_buf[i], 8192 ); /* pitch_buf in Q6 x 0.25 in Q15 */ } + pitch_fx = round_fx( L_tmp ); /* Q6 */ } - ELSE IF( EQ_32( st_fx->output_Fs, 16000 ) ) + ELSE { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + /* pitch_fx = 0.2f*sum_s(pitch_buf, 5); */ + L_tmp = L_mult( pitch_buf[0], 6554 ); + FOR( i = 1; i < NB_SUBFR16k; i++ ) { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - error[i] = mult_r( error[i], synth_scale_fx ); - move16(); - } + L_tmp = L_mac( L_tmp, pitch_buf[i], 6554 ); /* pitch_buf in Q6 x 0.2 in Q15 */ } - - Decimate_allpass_steep_fx( error, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); + pitch_fx = round_fx( L_tmp ); /* Q6 */ } - /* Update previous frame parameters for FEC */ - Copy( lsf_shb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->prev_coder_type, coder_type ) && NE_16( coder_type, UNVOICED ) ) || ( LE_32( st_fx->total_brate, ACELP_16k40 ) && ( EQ_16( st_fx->prev_coder_type, coder_type ) || ( EQ_16( st_fx->prev_coder_type, VOICED ) && EQ_16( coder_type, GENERIC ) ) || ( EQ_16( st_fx->prev_coder_type, GENERIC ) && EQ_16( coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st_fx->extl, FB_TBE ) ) { - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; - move16(); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + GainShape_tmp[i] = GainShape[i * 4]; /* Q15 */ + move16(); + } - if ( !st_fx->bfi ) + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ + /* if( ener_tmp_fx[i]*GainShape_tmp_fx[i] > st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ + L_tmp1 = Mult_32_16( ener_tmp[i], GainShape_tmp[i] ); /* (2*Q_bwe_exc) */ + L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st_fx->prev_ener_fx_Q) */ + tmp = sub( shl( Q_bwe_exc, 1 ), shl( hBWE_TD->prev_ener_fx_Q, 1 ) ); + L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ + IF( GT_32( L_tmp1, L_tmp2 ) ) + { + /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ + /* tmp = L_tmp2/ener_tmp_fx[i]*/ + L_tmp = L_tmp2; + move32(); + if ( L_tmp2 < 0 ) + { + L_tmp = L_negate( L_tmp2 ); + } + + expb = norm_l( L_tmp ); + fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) ); + expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */ + + expa = norm_l( ener_tmp[i] ); + fraca = extract_h( L_shl( ener_tmp[i], expa ) ); + expa = sub( 30, expa ); + + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); + + tmp = div_s( fracb, fraca ); + exp = sub( sub( expb, expa ), 1 ); + tmp = shl( tmp, exp ); + GainShape_tmp[i] = add( tmp, shr( GainShape_tmp[i], 1 ) ); /* Q15 */ + move16(); + } + + hBWE_TD->prev_ener_fx = ener_tmp[i]; + move32(); + hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; + move16(); + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; move16(); } - } - ELSE - { - IF( !st_fx->bfi ) + FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) { - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; + Word16 idx = 0; move16(); - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ + IF( i != 0 ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + GainShape[i] = GainShape_tmp[idx]; move16(); } } + ELSE + { + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; + move16(); + } - hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS - 1]; - move32(); - hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR - 1]; - move32(); - *Q_synth = Q_bwe_exc; - move16(); - hBWE_TD->prev_Q_bwe_syn2 = Q_bwe_exc; - move16(); - hBWE_TD->prev_Qx = Q_bwe_exc; - move16(); - return; -} + /* Back up the Q_bwe_exc associated with shaped_shb_excitation for the next frame*/ + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; + move16(); -static void gradientGainShape( - Decoder_State *st_fx, - Word16 *GainShape, - Word32 *GainFrame ) -{ - Word16 i, j, tmp; - Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; - Word16 GainGrad0[3]; - Word16 GainGrad1[3]; - Word16 GainGradFEC[4]; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; + /* Scale the shaped excitation */ + ScaleShapedSHB_fx( SHB_OVERLAP_LEN, + shaped_shb_excitation, /* i/o: Q_bwe_exc */ + hBWE_TD->syn_overlap_fx, + GainShape, /* Q15 */ + GainFrame, /* Q18 */ + window_shb_fx, + subwin_shb_fx, + &Q_bwe_exc, &Qx, n_mem3, hBWE_TD->prev_Q_bwe_syn2 ); - /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ - FOR( j = 0; j < 3; j++ ) + max = 0; + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - GainGrad0[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 1], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j], 1 ) ); - move16(); /* Q14 */ - GainGrad1[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 5], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j + 4], 1 ) ); - move16(); /* Q14 */ - GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); - move16(); /* Q14 */ + max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ } - /* gradient for the first gainshape */ - test(); - test(); - test(); - IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || - ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) - { - GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); - move16(); /* Q14 */ - } - ELSE + IF( max == 0 ) { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + curr_frame_pow = 0; move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); - move16(); /* Q14 */ - } - - /* get the first gainshape template */ - test(); - test(); - IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) ) - { - GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), GainGradFEC[0] ); + n = 0; move16(); } - ELSE IF( GainGradFEC[0] > 0 ) - { - GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); - move16(); /* Q14 */ - } ELSE { - GainShapeTemp[0] = shr( hBWE_TD->GainShape_Delay_fx[7], 1 ); - move16(); /* Q14 */ - } + n = norm_s( max ); + max = 0; + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ + move16(); + } - /*Get the second the third and the fourth gainshape template*/ + curr_frame_pow = 0; + move32(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ + curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ + } + } + curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ - tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ - test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] > 0 ) ) + tmp = sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ); + IF( tmp > 0 ) /* shifting prev */ + { + IF( GT_16( tmp, 32 ) ) + { + hBWE_TD->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); + move16(); + tmp = 32; + move16(); + } + hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); + move32(); + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; + move16(); + } + ELSE /* shifting curr */ { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + IF( LT_16( tmp, -32 ) ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); - move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); + curr_frame_pow_exp = sub( hBWE_TD->prev_frame_pow_exp, 32 ); + tmp = -32; move16(); } + curr_frame_pow = L_shr( curr_frame_pow, -tmp ); + curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; + move16(); } - ELSE + test(); + IF( !st_fx->bfi && st_fx->prev_bfi ) { + L_tmp = L_shr( curr_frame_pow, 4 ); + L_tmp = Mult_32_16( L_tmp, 17476 ); + test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] < 0 ) ) + test(); + IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && + ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st_fx->prev_coder_type, UNVOICED ) ) { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) - { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); - move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); - move16(); /* Q14 */ - } + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ + + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ } ELSE { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + scale = temp = 32767; + move16(); /*Q15*/ + } + FOR( j = 0; j < 8; j++ ) + { + GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); + move16(); + GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); + move16(); + FOR( i = 0; i < L_FRAME16k / 8; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] ); - move16(); - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); + shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )], scale ); move16(); } - } - } - /* Get the gainshape and gain frame for the current frame*/ - test(); - test(); - test(); - IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) + IF( temp > 0 ) { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ - - IF( GT_16( 8192, tmp ) ) + /* scale <= temp, due to scale = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow ), temp = sqrt( scale, 1.f/8.f ) + and curr_frame_pow > st->prev_swb_bwe_frame_pow_fx -> scale <= 1.0, sqrt(scale, 1.f/8.f) >= scale */ + IF( LT_16( scale, temp ) ) { - GainShape[i * 4 + j] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ + scale = div_s( scale, temp ); } ELSE { - GainShape[i * 4 + j] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ + scale = 32767; + move16(); } } + ELSE + { + scale = 0; + move16(); + } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); - move16(); } - ELSE IF( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) + + /* adjust the FEC frame energy */ + IF( st_fx->bfi ) { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + scale = temp = 4096; + move16(); /*Q12*/ + + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { - FOR( j = 0; j < 4; j++ ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && + NE_16( st_fx->prev_coder_type, UNVOICED ) && + ( st_fx->last_good != UNVOICED_CLAS ) ) { - IF( LT_16( GainShapeTemp[i], 16384 ) ) - { - GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); - move16(); - } - ELSE - { - GainShape[i * 4 + j] = 32767; - move16(); - } + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + } + ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && + ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) + { + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + scale = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); - move16(); - } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) { - FOR( j = 0; j < 4; j++ ) + test(); + test(); + test(); + test(); + test(); + IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) { - GainShape[add( i * 4, j )] = GainShapeTemp[i]; - move16(); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + } + ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && + ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) + { + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/ + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); - move16(); - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + FOR( j = 0; j < 8; j++ ) { - FOR( j = 0; j < 4; j++ ) + GainShape[2 * j] = shl_sat( mult_r( GainShape[2 * j], scale ), 3 ); + move16(); /* 15 +12 +3-15 =15*/ + GainShape[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape[add( 2 * j, 1 )], scale ), 3 ); + move16(); + FOR( i = 0; i < 40; i++ ) { - IF( LT_16( GainShapeTemp[i], 16384 ) ) + shaped_shb_excitation[add( i, j * 40 )] = shl_sat( mult_r( shaped_shb_excitation[add( i, j * 40 )], scale ), 3 ); + move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ + } + + IF( temp > 0 ) + { + IF( LT_16( scale, temp ) ) { - GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); - move16(); + scale = shr( div_s( scale, temp ), 3 ); } ELSE - { - GainShape[i * 4 + j] = 32767; - move16(); - } - } - } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); - move16(); - } - - *GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ - move32(); -} - -/*-------------------------------------------------------------------* - * Dequant_lower_LSF() - * - * Dequantized the lower LSFs - *-------------------------------------------------------------------*/ - - -static void Dequant_lower_LSF_fx( - const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs Q15*/ -) -{ - Word16 i; - - lsf_q[0] = lsf_q_cb_fx[0][lsf_idx[0]]; - move16(); - FOR( i = 1; i < NUM_Q_LSF; i++ ) - { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ - move16(); - } - - return; -} - -/*-------------------------------------------------------------------* - * Map_higher_LSF() - * - * Map the higher LSFs from the lower LSFs - *-------------------------------------------------------------------*/ - -static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ - const Word16 m, /* i : Mirroring point Q15*/ - const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ -) -{ - Word16 lsf_map[NUM_MAP_LSF]; - Word16 grid[NUM_MAP_LSF]; - Word16 last_q_lsf; - Word16 lsf_smooth[NUM_MAP_LSF]; - Word16 offset; - Word16 i; - Word16 scale; - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ - move16(); + { + tmp1 = sub( norm_s( scale ), 1 ); + tmp2 = norm_s( temp ); + scale = div_s( shl( scale, tmp1 ), shl( temp, tmp2 ) ); + scale = shr( scale, add( sub( tmp1, tmp2 ), 3 ) ); + } + } + ELSE + { + scale = 0; + move16(); + } + } } - IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) + hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow; + move32(); + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; + move16(); + { - offset = lsf_map[0]; /*Q15*/ - move16(); - scale = div_s( sub( MAX_LSF_FX, m ), m ); - FOR( i = 0; i < NUM_MAP_LSF; i++ ) + Word64 prev_ener_shb64 = 0; + move64(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ - move16(); + prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /* Q0 */ } + L_prev_ener_shb = W_sat_l( prev_ener_shb64 ); } - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ + /* st->prev_ener_shb = sqrt(st->prev_ener_shb/L_FRAME16k) */ + L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */ + st_fx->prev_ener_shb_fx = 0; move16(); - scale = sub( MAX_LSF_FX, last_q_lsf ); - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ - move16(); - } - FOR( i = 0; i < NUM_MAP_LSF; i++ ) + IF( L_prev_ener_shb != 0 ) { - lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ - move16(); - } + exp = norm_l( L_prev_ener_shb ); + tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); + exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) ); - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + st_fx->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ move16(); } - - return; -} - - -static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ - const Word16 m_idx, /* i : Mirror point index Q0 */ - Word16 *m /* i : Mirroring point Q15*/ -) -{ - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ + /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ + L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ + tmp = 0; move16(); + IF( L_tmp != 0 ) + { + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) ); - return; -} + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ + } + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ + /* 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(); + } -static Word16 dotp_loc( - const Word16 x[], /* i : vector x[] Qx */ - const Word32 y[], /* i : vector y[] Qy */ - const Word16 n /* i : vector length */ -) -{ - Word16 i; - Word32 suma; - Word16 guarded_bits = find_guarded_bits_fx( n ); + IF( EQ_16( st_fx->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_fx->output_Fs, 48000 ) ) + { + Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); + } + IF( EQ_32( st_fx->output_Fs, 16000 ) ) + { + Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); + } + } + /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ + /* i/o: st_fx->genSHBsynth_Hilbert_Mem_fx in (Q_bwe_exc) */ + /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ + /* o: error in (Qx) */ + GenSHBSynth_fx( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); - suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ + Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); - FOR( i = 1; i < n; i++ ) + /* resample SHB synthesis (if needed) and scale down */ + synth_scale_fx = 32767; + move16(); /* 1.0 in Q15 */ + if ( EQ_16( st_fx->codec_mode, MODE1 ) ) { - suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ + synth_scale_fx = 29491; + move16(); /* 0.9 in Q15 */ } - suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - - return extract_h( suma ); /*Qx + Qy - 16*/ -} - - -/*-------------------------------------------------------------------* - * dequantizeSHBparams() - * - * Dequantize super highband spectral envolope, temporal gains and frame gain - *-------------------------------------------------------------------*/ - -#ifdef HARMONIZE_TBE -static void dequantizeSHBparams_fx( -#else -void ivas_dequantizeSHBparams_fx_9_1( -#endif - Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ - Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ - Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ - Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors, /* o : Q15 */ - Word16 *MSFlag ) -{ - Word16 i, j, idxLSF, idxSubGain, idxFrameGain; - Word16 Q_combined_gains[NUM_SHB_SUBFR / 4]; - Word16 lsf_q[LPC_SHB_ORDER]; - Word16 lsf_idx[NUM_Q_LSF]; - Word16 m_idx, grid_idx; - Word16 m; - Word32 L_tmp; - Word16 tmp, frac, exp; - Word16 idx_shb_fr_gain, idx_res_gs[5], idx_mixFac; - Word16 temp_shb_ener_sf_fx; - TD_BWE_DEC_HANDLE hBWE_TD; - - UWord32 Idx_lvq; - Word16 Idx, Idx_pred; - Word16 num_bits_lvq; - Word16 out[LATTICE_DIM]; - const Word16 *cb_stage; - Word16 predictor_bits; - Word16 nbits = NUM_BITS_SHB_MSLVQ; - move16(); - hBWE_TD = st_fx->hBWE_TD; - /* LSFs */ - - IF( EQ_16( extl, WB_TBE ) ) + IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) + IF( EQ_32( st_fx->extl, FB_TBE ) ) { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + tmp = norm_l( GainFrame ); + if ( GainFrame == 0 ) { - idxFrameGain = hBWE_TD->gFrame_WB; - move16(); - idxLSF = hBWE_TD->lsf_WB; + tmp = 31; move16(); } - ELSE + L_tmp = L_shl( GainFrame, tmp ); /* 18 + tmp */ + + tmp1 = 0; + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); - idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_LBR_WB_LSF ); + Word16 idx = 0; + IF( i != 0 ) + { + idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); + } + L_tmp1 = Mult_32_16( L_tmp, GainShape[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); + tmp1 = s_max( tmp1, abs_s( White_exc16k[i] ) ); } - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_LBR_WB ), Q_lsf, LPC_SHB_ORDER_LBR_WB ); - set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - Copy32( SHBCB_FrameGain16_fx + idxFrameGain, Q_framegrain, 1 ); - } - ELSE - { - *uv_flag = (Word16) get_next_indice_fx( st_fx, 1 ); + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ move16(); - idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain ); - idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_WB_LSF ); - Copy( wb_bwe_lsfvq_cbook_8bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_WB ), Q_lsf, LPC_SHB_ORDER_WB ); - Copy( HBCB_SubGain5bit_fx + i_mult( idxSubGain, NUM_SHB_SUBFR / 4 ), Q_combined_gains, NUM_SHB_SUBFR / 4 ); - - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + tmp = norm_s( tmp1 ); + if ( tmp1 == 0 ) { - - L_tmp = L_mult( Q_combined_gains[i], 21771 ); /*Q26 0.166096 in Q17 */ - L_tmp = L_shr( L_tmp, 10 ); - frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Q_combined_gains[i] = shl( tmp, add( exp, 1 ) ); /* Q15 */ + tmp = 15; move16(); } - FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) + FOR( i = 0; i < L_FRAME16k; i++ ) { - Q_subgain[i] = Q_combined_gains[i / 2]; // Q15 - move16(); - Q_subgain[i + 1] = Q_combined_gains[i / 2]; // Q15 + White_exc16k[i] = shl( White_exc16k[i], sub( tmp, 1 ) ); move16(); } + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); + move16(); + } - /* frame gain */ - Copy32( SHBCB_FrameGain64_fx + idxFrameGain, Q_framegrain, 1 ); + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error[i] = mult_r( error[i], synth_scale_fx ); + move16(); + } } + + interpolate_3_over_2_allpass_fx( error, L_FRAME32k, synth, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); } - ELSE /* SWB TBE DEC */ + ELSE IF( EQ_32( st_fx->output_Fs, 32000 ) ) { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { - idxSubGain = hBWE_TD->idxSubGains; - move16(); - idxFrameGain = hBWE_TD->idxFrameGain; - move16(); + FOR( i = 0; i < L_FRAME32k; i++ ) + { + synth[i] = mult_r( synth_scale_fx, error[i] ); + move16(); /*Qx*/ + } } ELSE { - idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); - } - ELSE + Copy( error, synth, L_FRAME32k ); + } + } + ELSE IF( EQ_32( st_fx->output_Fs, 16000 ) ) + { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) { - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + error[i] = mult_r( error[i], synth_scale_fx ); + move16(); } } - /* Multi Source Flag */ - test(); - test(); - IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) + Decimate_allpass_steep_fx( error, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); + } + + /* Update previous frame parameters for FEC */ + Copy( lsf_shb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) + { + hBWE_TD->GainFrame_prevfrm_fx = GainFrame; + move16(); /*Q18*/ + hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; + move16(); + + if ( !st_fx->bfi ) { - *MSFlag = (Word16) get_next_indice_fx( st_fx, STEREO_ICBWE_MSFLAG_BITS ); + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } - ELSE + } + ELSE + { + IF( !st_fx->bfi ) { - *MSFlag = 0; + hBWE_TD->GainFrame_prevfrm_fx = GainFrame; + move16(); /*Q18*/ + hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; + move16(); + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } + } - IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain; - move16(); - } - ELSE - { - 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 */ + hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS - 1]; + move32(); + hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR - 1]; + move32(); + *Q_synth = Q_bwe_exc; + move16(); + hBWE_TD->prev_Q_bwe_syn2 = Q_bwe_exc; + move16(); + hBWE_TD->prev_Qx = Q_bwe_exc; + move16(); - /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ - /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2( 14, frac ); - *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /*exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ - move32(); + return; +} - FOR( i = 0; i < 5; i++ ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; - move16(); - } - ELSE - { - 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 */ - ); - move16(); - /* o: Q_shb_res_gshape in Q14 */ - } +static void gradientGainShape( + Decoder_State *st_fx, + Word16 *GainShape, + Word32 *GainFrame ) +{ + Word16 i, j, tmp; + Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; + Word16 GainGrad0[3]; + Word16 GainGrad1[3]; + Word16 GainGradFEC[4]; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - idx_mixFac = hBWE_TD->idx_mixFac; - move16(); - } - ELSE + /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ + FOR( j = 0; j < 3; j++ ) + { + GainGrad0[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 1], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j], 1 ) ); + move16(); /* Q14 */ + GainGrad1[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 5], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j + 4], 1 ) ); + move16(); /* Q14 */ + GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); + move16(); /* Q14 */ + } + + /* gradient for the first gainshape */ + test(); + test(); + test(); + IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || + ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) + { + GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); + move16(); /* Q14 */ + } + ELSE + { + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + move16(); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); + move16(); /* Q14 */ + } + + /* get the first gainshape template */ + test(); + test(); + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) ) + { + GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), GainGradFEC[0] ); + move16(); + } + ELSE IF( GainGradFEC[0] > 0 ) + { + GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); + move16(); /* Q14 */ + } + ELSE + { + GainShapeTemp[0] = shr( hBWE_TD->GainShape_Delay_fx[7], 1 ); + move16(); /* Q14 */ + } + + /*Get the second the third and the fourth gainshape template*/ + + tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ + tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ + + test(); + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] > 0 ) ) + { + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + { + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); + move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); + move16(); + } + } + ELSE + { + test(); + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] < 0 ) ) + { + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); + move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); + move16(); /* Q14 */ } - *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); - move16(); - /* o: Q_mixFactors in Q15 */ } ELSE { - *Q_shb_ener_sf = L_deposit_l( 0 ); - move32(); - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); - *Q_mixFactors = usdequant_fx( idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/ ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] ); move16(); - } - ELSE - { - *Q_mixFactors = 0; + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); } - set16_fx( Q_shb_res_gshape, 0, 5 ); } + } - /* LSFs */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) && EQ_16( st_fx->codec_mode, MODE1 ) ) - { - set16_fx( lsf_idx, 0, 5 ); - lsf_idx[0] = (Word16) get_next_indice_fx( st_fx, 8 ); - move16(); - grid_idx = 0; - move16(); - m_idx = 0; - move16(); - - Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); - } - ELSE IF( ( st_fx->rf_flag == 0 ) && !( ( ( st_fx->element_mode == EVS_MONO ) && EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && st_fx->rf_flag_last ) ) ) ) ) + /* Get the gainshape and gain frame for the current frame*/ + test(); + test(); + test(); + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + FOR( j = 0; j < 4; j++ ) { - /* read multi-stage LVQ quantizer */ - IF( GE_16( nbits, 19 ) ) - { - cb_stage = cb_LSF_BWE_fx[0]; - move16(); - } - ELSE - { - cb_stage = cb_LSF_BWE_fx[1]; - move16(); - } - set16_fx( lsf_q, 0, LPC_SHB_ORDER ); - - /* VQ part */ - num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; - Idx = get_next_indice_fx( st_fx, num_bits_lvq ); - v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); - - /* MSLVQ part */ - num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); - predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; - Idx_pred = 0; - move16(); + tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ - IF( EQ_16( num_bits_lvq, 16 ) ) + IF( GT_16( 8192, tmp ) ) { - /* MSLVQ part */ - Idx_lvq = L_add( get_next_indice_fx( st_fx, sub( num_bits_lvq, 1 ) ), L_shl( get_next_indice_fx( st_fx, 1 ), 15 ) ); - deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, 0 ); + GainShape[i * 4 + j] = shl( tmp, 2 ); + move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - /* MSLVQ part */ - Idx_lvq = get_next_indice_fx( st_fx, num_bits_lvq ); - deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, extract_l( LT_16( nbits, 19 ) ) ); + GainShape[i * 4 + j] = 32767; + move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } - - /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */ - v_add_16( lsf_q, out, lsf_q, LATTICE_DIM ); /* quantized mean removed data for first 8 dim*/ - - /* predict last 2 components */ - IF( predictor_bits == 0 ) + } + } + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); + } + ELSE IF( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + IF( LT_16( GainShapeTemp[i], 16384 ) ) { - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, LastCoefPred_0bit_fx, LATTICE_DIM ); - move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_0bit_fx[LATTICE_DIM + 1], LATTICE_DIM ); + GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); - move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); + GainShape[i * 4 + j] = 32767; move16(); } - - IF( LT_16( nbits, NUM_BITS_SHB_MSLVQ ) ) - { - Idx_pred = (Word16) get_next_indice_fx( st_fx, sub( NUM_BITS_SHB_MSLVQ, nbits ) ); - } - - v_add_16( SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER ); - v_sort( lsf_q, 0, LPC_SHB_ORDER - 1 ); } - ELSE + } + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); + } + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) { - /* LSFs */ - test(); - test(); - test(); - IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - lsf_idx[i] = hBWE_TD->lsf_idx[i]; - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); - move16(); - } - } - } - Dequant_lower_LSF_fx( lsf_idx, lsf_q ); - - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + GainShape[add( i * 4, j )] = GainShapeTemp[i]; + move16(); + } + } + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + move16(); + } + ELSE + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + IF( LT_16( GainShapeTemp[i], 16384 ) ) { - m_idx = hBWE_TD->m_idx; + GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); + GainShape[i * 4 + j] = 32767; + move16(); } + } + } + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + move16(); + } - Dequant_mirror_point_fx( lsf_q, m_idx, &m ); + *GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ + move32(); +} - /* safety check in case of bit errors */ - IF( GT_16( m, MAX_LSF_FX ) ) - { - st_fx->BER_detect = 1; - move16(); - m = MAX_LSF_FX - 1; - move16(); - } +/*-------------------------------------------------------------------* + * Dequant_lower_LSF() + * + * Dequantized the lower LSFs + *-------------------------------------------------------------------*/ - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - grid_idx = hBWE_TD->grid_idx; - move16(); - } - ELSE - { - grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); - } - Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); - } - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /* safety check in case of bit errors */ - IF( GT_16( lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX ) ) - { - st_fx->BER_detect = 1; - move16(); - lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; - move16(); - } - Q_lsf[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - } - ELSE +static void Dequant_lower_LSF_fx( + const Word16 lsf_idx[], /* i : LSF indices */ + Word16 lsf_q[] /* o : Quantized LSFs Q15*/ +) +{ + Word16 i; + + lsf_q[0] = lsf_q_cb_fx[0][lsf_idx[0]]; + move16(); + FOR( i = 1; i < NUM_Q_LSF; i++ ) + { + lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ + move16(); + } + + return; +} + +/*-------------------------------------------------------------------* + * Map_higher_LSF() + * + * Map the higher LSFs from the lower LSFs + *-------------------------------------------------------------------*/ + +static void Map_higher_LSF_fx( + Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m, /* i : Mirroring point Q15*/ + const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ +) +{ + Word16 lsf_map[NUM_MAP_LSF]; + Word16 grid[NUM_MAP_LSF]; + Word16 last_q_lsf; + Word16 lsf_smooth[NUM_MAP_LSF]; + Word16 offset; + Word16 i; + Word16 scale; + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ + move16(); + } + + IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) + { + offset = lsf_map[0]; /*Q15*/ + move16(); + scale = div_s( sub( MAX_LSF_FX, m ), m ); + FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - set16_fx( lsf_idx, 0, 5 ); - Copy( hBWE_TD->lsf_idx, lsf_idx, 5 ); - grid_idx = 0; - move16(); - m_idx = 0; + lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ move16(); - Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); } + } + + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ + move16(); + scale = sub( MAX_LSF_FX, last_q_lsf ); + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ + move16(); + } + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ + move16(); + } + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ + move16(); + } - space_lsfs_fx( Q_lsf, LPC_SHB_ORDER ); + return; +} - /* Dequantize subgain indices */ - j = i_mult( idxSubGain, NUM_SHB_SUBGAINS ); - move16(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ - L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 12 ); - frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Q_subgain[i] = shl( tmp, add( exp, 1 ) ); /*Q15*/ - move16(); - } +static void Dequant_mirror_point_fx( + const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m_idx, /* i : Mirror point index Q0 */ + Word16 *m /* i : Mirroring point Q15*/ +) +{ + *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ + move16(); - FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) - { - Word16 idx = 0; - move16(); - IF( i != 0 ) - { - idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); - } - Q_subgain[i] = Q_subgain[idx]; - move16(); - } + return; +} - /* Frame gain */ - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - *Q_framegrain = L_mac( SHB_GAIN_QLOW_1k75_FX, idxFrameGain, SHB_GAIN_QDELTA_1k75_FX ); - move32(); - } - ELSE - { - *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); - move32(); - } /*Q18*/ - L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ - frac = L_Extract_lc( L_tmp, &exp ); - L_tmp = Pow2( 30, frac ); - *Q_framegrain = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - move32(); + +static Word16 dotp_loc( + const Word16 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ + const Word16 n /* i : vector length */ +) +{ + Word16 i; + Word32 suma; + Word16 guarded_bits = find_guarded_bits_fx( n ); + + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ + + FOR( i = 1; i < n; i++ ) + { + suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ } + suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - return; + return extract_h( suma ); /*Qx + Qy - 16*/ } -#ifndef HARMONIZE_TBE -/*==========================================================================*/ -/* FUNCTION : static void dequantizeSHBparams_fx_9_1 () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Dequantize super highband spectral envolope */ -/* temporal gains and frame gain */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 extl i : extension layer */ -/* _Word32 extl_brate i : extensiuon layer bitrate */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *Q_lsf, o : SHB LSF from de-quantization Q15 */ -/* _Word16 *Q_subgain, o : SHB subframe gains from de-quantization Q15*/ -/* _Word32 *Q_framegrain o : SHB frame gain from de-quantization Q18 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -static void dequantizeSHBparams_fx_9_1( +/*-------------------------------------------------------------------* + * dequantizeSHBparams() + * + * Dequantize super highband spectral envolope, temporal gains and frame gain + *-------------------------------------------------------------------*/ + +static void dequantizeSHBparams_fx( Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ Word32 extl_brate, /* i : extensiuon layer bitrate */ @@ -4500,10 +3350,10 @@ static void dequantizeSHBparams_fx_9_1( Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15*/ - Word16 *Q_shb_res_gshape, /* o : Q14*/ - Word16 *Q_mixFactors /* o : Q15*/ -) + Word32 *Q_shb_ener_sf, /* o : Q15 */ + Word16 *Q_shb_res_gshape, /* o : Q14 */ + Word16 *Q_mixFactors, /* o : Q15 */ + Word16 *MSFlag ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; Word16 Q_combined_gains[NUM_SHB_SUBFR / 4]; @@ -4516,6 +3366,15 @@ static void dequantizeSHBparams_fx_9_1( Word16 idx_shb_fr_gain, idx_res_gs[5], idx_mixFac; Word16 temp_shb_ener_sf_fx; TD_BWE_DEC_HANDLE hBWE_TD; + + UWord32 Idx_lvq; + Word16 Idx, Idx_pred; + Word16 num_bits_lvq; + Word16 out[LATTICE_DIM]; + const Word16 *cb_stage; + Word16 predictor_bits; + Word16 nbits = NUM_BITS_SHB_MSLVQ; + move16(); hBWE_TD = st_fx->hBWE_TD; /* LSFs */ @@ -4524,10 +3383,18 @@ static void dequantizeSHBparams_fx_9_1( { IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) { - idxFrameGain = hBWE_TD->gFrame_WB; - move16(); - idxLSF = hBWE_TD->lsf_WB; - move16(); + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + idxFrameGain = hBWE_TD->gFrame_WB; + move16(); + idxLSF = hBWE_TD->lsf_WB; + move16(); + } + ELSE + { + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_LBR_WB_LSF ); + } Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_LBR_WB ), Q_lsf, LPC_SHB_ORDER_LBR_WB ); set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -4558,9 +3425,9 @@ static void dequantizeSHBparams_fx_9_1( FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) { - Q_subgain[i] = Q_combined_gains[i / 2]; + Q_subgain[i] = Q_combined_gains[i / 2]; // Q15 move16(); - Q_subgain[i + 1] = Q_combined_gains[i / 2]; + Q_subgain[i + 1] = Q_combined_gains[i / 2]; // Q15 move16(); } @@ -4580,11 +3447,31 @@ static void dequantizeSHBparams_fx_9_1( ELSE { idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); + } + ELSE + { + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + } } + /* Multi Source Flag */ + test(); test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) + IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) + { + *MSFlag = (Word16) get_next_indice_fx( st_fx, STEREO_ICBWE_MSFLAG_BITS ); + move16(); + } + ELSE + { + *MSFlag = 0; + move16(); + } + + IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) { IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { @@ -4598,126 +3485,218 @@ static void dequantizeSHBparams_fx_9_1( 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 */ - /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ - /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2( 14, frac ); - *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /* exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ - move32(); + /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ + /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ + L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = Pow2( 14, frac ); + *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /*exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + move32(); + + FOR( i = 0; i < 5; i++ ) + { + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; + move16(); + } + ELSE + { + 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 */ + ); + move16(); + /* o: Q_shb_res_gshape in Q14 */ + } + + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + idx_mixFac = hBWE_TD->idx_mixFac; + move16(); + } + ELSE + { + idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); + } + *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); + move16(); + /* o: Q_mixFactors in Q15 */ + } + ELSE + { + *Q_shb_ener_sf = L_deposit_l( 0 ); + move32(); + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); + *Q_mixFactors = usdequant_fx( idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/ ); + move16(); + } + ELSE + { + *Q_mixFactors = 0; + move16(); + } + set16_fx( Q_shb_res_gshape, 0, 5 ); + } + + /* LSFs */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) && EQ_16( st_fx->codec_mode, MODE1 ) ) + { + set16_fx( lsf_idx, 0, 5 ); + lsf_idx[0] = (Word16) get_next_indice_fx( st_fx, 8 ); + move16(); + grid_idx = 0; + move16(); + m_idx = 0; + move16(); + + Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); + } + ELSE IF( ( st_fx->rf_flag == 0 ) && !( ( ( st_fx->element_mode == EVS_MONO ) && EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && st_fx->rf_flag_last ) ) ) ) ) + { + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + /* read multi-stage LVQ quantizer */ + IF( GE_16( nbits, 19 ) ) + { + cb_stage = cb_LSF_BWE_fx[0]; + move16(); + } + ELSE + { + cb_stage = cb_LSF_BWE_fx[1]; + move16(); + } + set16_fx( lsf_q, 0, LPC_SHB_ORDER ); + + /* VQ part */ + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; + Idx = get_next_indice_fx( st_fx, num_bits_lvq ); + v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); + + /* MSLVQ part */ + num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); + predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; + Idx_pred = 0; + move16(); + + IF( EQ_16( num_bits_lvq, 16 ) ) + { + /* MSLVQ part */ + Idx_lvq = L_add( get_next_indice_fx( st_fx, sub( num_bits_lvq, 1 ) ), L_shl( get_next_indice_fx( st_fx, 1 ), 15 ) ); + deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, 0 ); + } + ELSE + { + /* MSLVQ part */ + Idx_lvq = get_next_indice_fx( st_fx, num_bits_lvq ); + deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, extract_l( LT_16( nbits, 19 ) ) ); + } + + /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */ + v_add_16( lsf_q, out, lsf_q, LATTICE_DIM ); /* quantized mean removed data for first 8 dim*/ - FOR( i = 0; i < 5; i++ ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + /* predict last 2 components */ + IF( predictor_bits == 0 ) { - idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, LastCoefPred_0bit_fx, LATTICE_DIM ); + move16(); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_0bit_fx[LATTICE_DIM + 1], LATTICE_DIM ); move16(); } ELSE { - idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); + Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); + move16(); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); 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 */ - ); - move16(); - /* o: Q_shb_res_gshape in Q14 */ - } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - idx_mixFac = hBWE_TD->idx_mixFac; - move16(); + IF( LT_16( nbits, NUM_BITS_SHB_MSLVQ ) ) + { + Idx_pred = (Word16) get_next_indice_fx( st_fx, sub( NUM_BITS_SHB_MSLVQ, nbits ) ); + } + + v_add_16( SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER ); + v_sort( lsf_q, 0, LPC_SHB_ORDER - 1 ); } ELSE { - idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); - } - *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); - move16(); - /* o: Q_mixFactors in Q15 */ - } - ELSE - { - *Q_shb_ener_sf = L_deposit_l( 0 ); - move32(); - *Q_mixFactors = 0; - move16(); - set16_fx( Q_shb_res_gshape, 0, 5 ); - } - - /* LSFs */ - - - test(); - test(); - test(); - test(); - test(); - IF( ( ( st_fx->rf_flag == 0 ) ) && !( ( EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && EQ_16( st_fx->rf_flag_last, 1 ) ) ) ) ) ) - - { - /* LSFs */ - test(); - test(); - test(); - IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + /* LSFs */ + test(); + test(); + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) { - FOR( i = 0; i < NUM_Q_LSF; i++ ) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { - lsf_idx[i] = hBWE_TD->lsf_idx[i]; - move16(); + FOR( i = 0; i < NUM_Q_LSF; i++ ) + { + lsf_idx[i] = hBWE_TD->lsf_idx[i]; + move16(); + } + } + ELSE + { + FOR( i = 0; i < NUM_Q_LSF; i++ ) + { + lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); + move16(); + } } } + Dequant_lower_LSF_fx( lsf_idx, lsf_q ); + + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + m_idx = hBWE_TD->m_idx; + move16(); + } ELSE { - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); - move16(); - } + m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); } - } - Dequant_lower_LSF_fx( lsf_idx, lsf_q ); - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - m_idx = hBWE_TD->m_idx; - move16(); - } - ELSE - { - m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); - } + Dequant_mirror_point_fx( lsf_q, m_idx, &m ); - Dequant_mirror_point_fx( lsf_q, m_idx, &m ); + /* safety check in case of bit errors */ + IF( GT_16( m, MAX_LSF_FX ) ) + { + st_fx->BER_detect = 1; + move16(); + m = MAX_LSF_FX - 1; + move16(); + } - /* safety check in case of bit errors */ - IF( GT_16( m, MAX_LSF_FX ) ) - { - st_fx->BER_detect = 1; - move16(); - m = MAX_LSF_FX - 1; - move16(); - } + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + grid_idx = hBWE_TD->grid_idx; + move16(); + } + ELSE + { + grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); + } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - grid_idx = hBWE_TD->grid_idx; - move16(); - } - ELSE - { - grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); + Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); } - - Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { /* safety check in case of bit errors */ @@ -4752,8 +3731,7 @@ static void dequantizeSHBparams_fx_9_1( { /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ - L_tmp = L_mult( SHBCB_SubGain5bit_fx[j], 27213 ); /*Q28 3.321928 in Q13 */ - j = add( j, 1 ); + L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 12 ); frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ @@ -4776,8 +3754,16 @@ static void dequantizeSHBparams_fx_9_1( } /* Frame gain */ - *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); /*Q18*/ - move32(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + *Q_framegrain = L_mac( SHB_GAIN_QLOW_1k75_FX, idxFrameGain, SHB_GAIN_QDELTA_1k75_FX ); + move32(); + } + ELSE + { + *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); + move32(); + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); @@ -4787,7 +3773,7 @@ static void dequantizeSHBparams_fx_9_1( return; } -#endif + /*-------------------------------------------------------------------* * fb_tbe_dec() @@ -4796,68 +3782,10 @@ static void dequantizeSHBparams_fx_9_1( *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( -#ifndef HARMONIZE_TBE - 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_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word16 hb_synth_exp ) - -{ - Word16 i; - Word16 ratio = 0; - move16(); - Word32 fb_exc_energy = 0; - move32(); - Word16 fb_synth[L_FRAME48k]; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st->hBWE_TD; - - /* decode FB slope information */ - test(); - test(); - IF( EQ_16( st->extl, FB_TBE ) && !st->bfi ) - { - IF( EQ_16( st->codec_mode, MODE2 ) ) - { - i = hBWE_TD->idxGain; - move16(); - } - ELSE - { - i = (Word16) get_next_indice_fx( st, 4 ); - } - ratio = shl_sat( 1, i ); - } - ELSE IF( EQ_16( st->extl, FB_TBE ) && st->bfi ) - { - ratio = hBWE_TD->prev_fbbwe_ratio_fx; - move16(); - } - 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 ); - - /* add the fb_synth component to the hb_synth component */ - /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ - FOR( i = 0; i < L_FRAME48k; i++ ) - { - hb_synth[i] = add_sat( hb_synth[i], fb_synth[i] ); - move16(); - } - return; -} - -void fb_tbe_dec_ivas_fx( -#endif 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, -#ifdef HARMONIZE_TBE Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ -#endif Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ @@ -4921,7 +3849,6 @@ void fb_tbe_dec_ivas_fx( } /* add the fb_synth component to the hb_synth component */ -#ifdef HARMONIZE_TBE IF( st->element_mode == EVS_MONO ) { FOR( i = 0; i < L_FRAME48k; i++ ) @@ -4931,7 +3858,6 @@ void fb_tbe_dec_ivas_fx( } } ELSE -#endif { FOR( i = 0; i < L_FRAME48k; i++ ) { @@ -5560,54 +4486,6 @@ static void calc_tilt_bwe_fx_loc( return; } -#ifndef HARMONIZE_TBE -/*-------------------------------------------------------------------* - * swb_tbe_dec() - * - * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module - *-------------------------------------------------------------------*/ -static void rescale_genSHB_mem_dec_ivas( - Decoder_State *st_fx, - Word16 sf /*Q0*/ -) -{ - Word16 i; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - - FOR( i = 0; i < 7; i++ ) - { - hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); - move16(); - } - - /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/ - IF( LT_32( st_fx->total_brate, ACELP_24k40 ) ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf ); - move16(); - } - } - - hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); - move32(); - - hBWE_TD->tbe_demph_fx = shl_r( hBWE_TD->tbe_demph_fx, sf ); - move16(); - hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); - move16(); - - return; -} -#endif static void find_max_mem_dec_m3( Decoder_State *st, @@ -5978,13 +4856,8 @@ void swb_tbe_dec_ivas_fx( ELSE { /* de-quantization */ -#ifdef HARMONIZE_TBE dequantizeSHBparams_fx( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); -#else - ivas_dequantizeSHBparams_fx_9_1( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, - &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); -#endif if ( hStereoICBWE != NULL ) { hStereoICBWE->MSFlag = MSFlag; @@ -6378,11 +5251,7 @@ void swb_tbe_dec_ivas_fx( sc = sub( Q_bwe_exc, st->prev_Q_bwe_exc ); IF( sc != 0 ) { -#ifdef HARMONIZE_TBE rescale_genSHB_mem_dec( st, sc ); -#else - rescale_genSHB_mem_dec_ivas( st, sc ); -#endif } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 7491697ed..c282f1c4f 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -444,11 +444,7 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ -#ifdef HARMONIZE_TBE wb_tbe_enc_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); -#else - wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); -#endif IF( EQ_16( st->codec_mode, MODE2 ) ) { tbe_write_bitstream_fx( st ); @@ -502,11 +498,7 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ -#ifdef HARMONIZE_TBE fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc, 0 ); -#else - fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc ); -#endif } IF( EQ_16( st->codec_mode, MODE2 ) ) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index e06b42f68..a4f06e932 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -847,9 +847,6 @@ ivas_error init_encoder_fx( { return error; } -#ifndef HARMONIZE_TBE - InitSWBencBuffer_fx( st->hBWE_TD ); -#endif } ELSE { @@ -857,13 +854,8 @@ ivas_error init_encoder_fx( { return error; } -#ifndef HARMONIZE_TBE - InitSWBencBuffer_ivas_fx( st->hBWE_TD ); -#endif } -#ifdef HARMONIZE_TBE InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); -#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index e5e38904d..0abba7ce9 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -646,11 +646,7 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ -#ifdef HARMONIZE_TBE wb_tbe_enc_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); -#else - wb_tbe_enc_ivas_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); -#endif } ELSE IF( EQ_16( st->extl, WB_BWE ) && n == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -755,11 +751,7 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ -#ifdef HARMONIZE_TBE fb_tbe_enc_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); -#else - fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); -#endif } } } diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 32d54deb6..98fad5780 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -438,11 +438,7 @@ ivas_error stereo_memory_enc_fx( } } -#ifdef HARMONIZE_TBE InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); -#else - InitSWBencBuffer_ivas_fx( st->hBWE_TD ); -#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index 4e3b5fdd1..0066efbe4 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -325,11 +325,7 @@ ivas_error stereo_set_tdm_fx( return error; } -#ifdef HARMONIZE_TBE InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); -#else - InitSWBencBuffer_ivas_fx( st->hBWE_TD ); -#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 840b2a516..8014a9216 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -160,14 +160,6 @@ Word16 dtx_hangover_addition_fx( Word16 *rem_dtx_ho ); void fb_tbe_enc_fx( -#ifndef HARMONIZE_TBE - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - const Word16 Q_fb_exc ); - -void fb_tbe_enc_ivas_fx( -#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ @@ -717,19 +709,6 @@ void wb_pre_proc_ivas_fx( ); void wb_tbe_enc_fx( -#ifndef HARMONIZE_TBE - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : i HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing[] /* i : OL maximum normalized correlation */ -); - -void wb_tbe_enc_ivas_fx( -#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ @@ -3940,17 +3919,10 @@ void noise_est_init_ivas_fx( ); void InitSWBencBuffer_fx( -#ifdef HARMONIZE_TBE const Word16 element_mode, /* i : element mode */ -#endif TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); -#ifndef HARMONIZE_TBE -void InitSWBencBuffer_ivas_fx( - TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ -); -#endif void ResetSHBbuffer_Enc_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 9f92208e4..5e2043263 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -30,29 +30,14 @@ static void singlevectortest_gain_fx( const Word32 *inp, const Word16 dimen, con static void determine_gain_weights_fx( const Word32 *gain, Word16 *weights, const Word16 dims ); static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, Word16 *subgains, const Word16 extl ); -#ifndef HARMONIZE_TBE -static void QuantizeSHBsubgains_ivas_fx( Encoder_State *st_fx, Word16 subgains[], const Word16 extl ); -#endif -#ifdef HARMONIZE_TBE static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); -#else -static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind ); - -static void QuantizeSHBframegain_ivas_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); -#endif static Word16 closest_centroid_fx( const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length ); static Word16 closest_centroid_lc_fx( const Word16 *data, const Word16 *quantizer, const Word16 centroids ); -#ifdef HARMONIZE_TBE static void EstimateSHBFrameGain_fx( const Word16 element_mode, const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); -#else -static void EstimateSHBFrameGain_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); - -static void EstimateSHBFrameGain_ivas_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); -#endif static void EstimateSHBGainShape_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, const Word16 *subwin, Word16 *n_subfr_saturation, const Flag limit_min_gain ); @@ -74,7 +59,6 @@ static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], W static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], const Word16 m ); -#ifdef HARMONIZE_TBE static void Quant_BWE_LSF_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, const Word16 Q_ener ); @@ -82,23 +66,6 @@ static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, static void Quant_shb_res_gshape_fx( Encoder_State *st, Word16 shb_res_gshape_fx[] ); static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); -#else -static void Quant_BWE_LSF_fx( Encoder_State *st_fx, const Word16 lsp_shb[], Word16 Q_lsfs[] ); - -static void Quant_BWE_LSF_ivas_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); - -static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_fx_32, Word16 Q_shb ); - -static void Quant_shb_ener_sf_ivas_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, Word16 Q_ener ); - -static void Quant_shb_res_gshape_fx( Encoder_State *st_fx, Word16 *shb_res_gshape_fx ); - -static void Quant_shb_res_gshape_ivas_fx( Encoder_State *st, Word16 shb_res_gshape_fx[] ); - -static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, const Word16 *lsp_shb_fx, Word16 *MA_lsp_shb_spacing, Word16 *frGainAttenuate, Word16 *frGainSmoothEn ); - -static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); -#endif /*-------------------------------------------------------------------* @@ -412,110 +379,9 @@ static void rescale_genWB_mem_enc( *-------------------------------------------------------------------*/ void InitSWBencBuffer_fx( -#ifdef HARMONIZE_TBE const Word16 element_mode, /* i : element mode */ -#endif - TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ -) -#ifndef HARMONIZE_TBE -{ - Word16 i; - - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - hBWE_TD->bwe_seed[0] = 23; - move16(); - hBWE_TD->bwe_seed[1] = 59; - move16(); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - move32(); - - set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); - hBWE_TD->prev_fb_energy_fx = 0; - move16(); - - set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); - set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); - - // IVAS_CODE - // InitSWBencBufferStates_fx(hBWE_TD, NULL ); - set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, LPC_SHB_ORDER ); - - hBWE_TD->cldfbHBLT = 8192 /*1.0f Q13*/; - move16(); - hBWE_TD->prev_gainFr_SHB_fx = 0; - move32(); - set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277, 3 ); - set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); - - hBWE_TD->prev_swb_GainShape_fx = 0; - move16(); - hBWE_TD->prev_frGainAtten = 0; - move16(); - hBWE_TD->prev_wb_GainShape = 0; - move16(); - hBWE_TD->prev_Q_bwe_exc_fb = 51; - move16(); - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - hBWE_TD->tilt_mem_fx = 0; - move16(); - - hBWE_TD->prev_coder_type = GENERIC; - move16(); - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = 0; - move16(); - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); - - /* TD BWE post-processing */ - hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; - move16(); - } - - set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); - set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); - - - hBWE_TD->prev_fb_energy_fx_Q = 0; - move16(); - - hBWE_TD->prev_Q_bwe_exc = 31; - move16(); - hBWE_TD->prev_Q_bwe_syn = 31; - move16(); - set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); - set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); - - return; -} - - -/*-------------------------------------------------------------------* - * InitSWBencBufferStates() - * - * Initialize SWB buffer states - *-------------------------------------------------------------------*/ - -void InitSWBencBuffer_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) -#endif { Word16 i; @@ -597,7 +463,6 @@ void InitSWBencBuffer_ivas_fx( hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); -#ifdef HARMONIZE_TBE IF( element_mode == EVS_MONO ) { hBWE_TD->prev_Q_bwe_exc = 31; @@ -606,7 +471,6 @@ void InitSWBencBuffer_ivas_fx( move16(); } ELSE -#endif { hBWE_TD->prev_Q_bwe_exc = 15; move16(); @@ -693,22 +557,20 @@ void ResetSHBbuffer_Enc_fx( #define WBTBE_LPCWIN_LENGTH ( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16 - 1 void wb_tbe_enc_fx( -#ifndef HARMONIZE_TBE - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz at Q-1 */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : input HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing_fx[] /* i : OL maximum normalized correlation */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ + const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ + const Word16 Q_new, /* i : input HB speech Q factor */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + const Word16 pitch_buf[] /* i : pitch for each subframe Q6 */ ) { - Word16 i, j; + Word16 i, j, k; Word16 hb_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16]; Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; + Word16 shaped_wb_exc_scale[L_SHB_LAHEAD / 4]; Word16 exc4kWhtnd[L_FRAME16k / 4]; /*Word16 ana_align_delay = WBTBE_ANA_ALIGNDELAY; */ /* -L_SHB_LAHEAD/4 - 5 */ Word32 GainFrame; @@ -724,11 +586,8 @@ void wb_tbe_enc_fx( Word32 LepsP[LPC_SHB_ORDER_WB + 1]; Word32 prev_pow, curr_pow, Lscale; - /* Word16 scale; */ - /*Word16 ramp_flag;*/ Word32 p2m_in, p2m_out; - /*Word16 cnt, max =0;*/ - Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out; /* Q_hb_frame; */ + Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out, Q_cur_pow, Q_prev_pow; /* Q_hb_frame; */ Word32 L_tmp, Lmax; Word16 tmp, exp, Q_out, sc; Word16 Q_ns = -1; @@ -743,13 +602,11 @@ void wb_tbe_enc_fx( Word16 frac, exp1; Word16 uv_flag; Word16 dummy = 0; - move16(); Word16 avg_voice_fac; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - RF_ENC_HANDLE hRF = st_fx->hRF; - - /*Word16 att = 32767;*/ + move16(); + set16_fx( bwe_exc_extended_16, 0, L_FRAME32k + NL_BUFF_OFFSET ); hb_new_speech = hb_old_speech + WBTBE_LOOK_LSUFBR_5_OVER_16; hb_frame = hb_old_speech + WBTBE_LSUBFR_5_OVER_16 + WBTBE_ANA_ALIGNDELAY; @@ -763,44 +620,77 @@ void wb_tbe_enc_fx( test(); test(); test(); - IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( voicing_fx[0], 16384 ) && LT_16( voicing_fx[1], 16384 ) && LT_16( voicing_fx[2], 16384 ) ) ) && st_fx->igf == 0 ) + IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( st_fx->voicing_fx[0], 16384 ) && LT_16( st_fx->voicing_fx[1], 16384 ) && LT_16( st_fx->voicing_fx[2], 16384 ) ) ) && !st_fx->igf ) { /* In case of unvoiced signals after switching cores, back-propagate the target signal */ Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); i = WBTBE_LOOK_LSUFBR_5_OVER_16; move16(); + k = 0; + move16(); - FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + IF( st_fx->element_mode == EVS_MONO ) { - L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); - move16(); - i--; + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + } + } + ELSE + { + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + k++; + } } } - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); - - if ( st_fx->element_mode > EVS_MONO ) + IF( st_fx->element_mode == EVS_MONO ) + { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); + } + ELSE { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); + /* Ensure R[0] isn't zero when entering Levinson-Durbin */ R_l[0] = s_max( R_l[0], 1 ); move16(); } - E_LPC_lev_dur_fx( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); // Since 0th index will be 1 in floating point buffer, in fixed point one has to take norm of 0th index to identify the Q-factor - Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); + Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); // Q12 - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + IF( st_fx->element_mode == EVS_MONO ) { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); - move32(); - } + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); + move32(); + } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } + ELSE + { + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 + move32(); + } + lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { @@ -808,20 +698,11 @@ void wb_tbe_enc_fx( move16(); } - /* lsp_spacing_fx = 16384; move16(); */ lsp_spacing_fx = lsp_wb_temp_fx[0]; move16(); FOR( i = 1; i < LPC_SHB_ORDER_WB; i++ ) { - /*if ( i == 0 ) - { - tmp = lsp_wb_temp_fx[0]; move16(); - } - else - {*/ tmp = sub( lsp_wb_temp_fx[i], lsp_wb_temp_fx[i - 1] ); - /*} */ - lsp_spacing_fx = s_min( lsp_spacing_fx, tmp ); } @@ -963,16 +844,18 @@ void wb_tbe_enc_fx( } Copy( voice_factors, vf_modified_fx, NB_SUBFR16k ); - IF( EQ_16( coder_type, VOICED ) ) + IF( EQ_16( st_fx->coder_type, VOICED ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { /*vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1];*/ vf_modified_fx[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6553, voice_factors[i - 1] ) ); + move16(); } IF( NE_16( st_fx->L_frame, L_FRAME ) ) { vf_modified_fx[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6553, voice_factors[3] ) ); + move16(); } } @@ -1010,735 +893,97 @@ void wb_tbe_enc_fx( prev_pow = 0; move32(); - IF( st_fx->element_mode > EVS_MONO ) + IF( st_fx->element_mode == EVS_MONO ) { - tmp = sub( shl( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ + } + + Q_prev_pow = 0; + move32(); } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + ELSE { - prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ + Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_prev_pow, 3 ) ) + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); + move16(); + } + Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); + move16(); + } + ELSE + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; + move16(); + } + Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); + move16(); + } + + tmp = sub( Q_prev_pow, 31 + 16 ); + prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ + + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ + } } rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + IF( st_fx->element_mode == EVS_MONO ) + { + 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( i = 0; i < L_FRAME32k; i++ ) { bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); move16(); } - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); +#ifdef HARMONIZE_TBE2 GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, - vf_modified_fx, uv_flag, st_fx->igf ); - - curr_pow = 0; - move16(); - IF( st_fx->element_mode > EVS_MONO ) + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified_fx, uv_flag, st_fx->igf ); +#else + IF( st_fx->element_mode == EVS_MONO ) { - tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + ELSE { - curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); } - - IF( GT_16( voice_factors[0], 24576 ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ - } - - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), &exp ); - - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - move16(); - } - - Lscale = root_a_fx( Lscale, 31 - exp, &exp ); - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - move16(); - /* Update WB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, - shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL, 1 ); - - /* Gain frame adjustment factor */ - test(); - IF( GainShape[0] && hBWE_TD->prev_wb_GainShape ) - { - exp = norm_s( hBWE_TD->prev_wb_GainShape ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_wb_GainShape ); - L_tmp = L_mult( GainShape[0], 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_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_wb_fac_fx = 0; - move16(); - } - L_feedback = L_mult0( temp_wb_fac_fx, temp_wb_fac_fx ); - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) - { - /* temp_swb_fac = (float)log( (GainShape[i]+0.00001f) / (GainShape[i-1]+0.0001f) ); */ - test(); - IF( GainShape[i] && GainShape[i - 1] ) - { - exp = norm_s( GainShape[i - 1] ); - tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape[i - 1] ); - L_tmp = L_mult( GainShape[i], tmp ); /*Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - move16(); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_wb_fac_fx = 0; - move16(); - } - - L_feedback = L_mac( L_feedback, temp_wb_fac_fx, temp_wb_fac_fx ); - } - L_tmp = L_add( L_shr( L_feedback, 1 ), 1 << 21 ); /* Q30 */ - - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /* Q(15+exp) */ - L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /* Q31 */ - feedback_fx = round_fx( L_tmp ); /* Q15 */ - } - ELSE - { - feedback_fx = 8738; - move16(); /* Q15 */ - } - - temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; - move16(); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - GainShape[i] = add( mult_r( sub( 32767, feedback_fx ), GainShape[i] ), mult_r( feedback_fx, temp_wb_fac_fx ) ); - move16(); - temp_wb_fac_fx = GainShape[i]; - move16(); - } - - hBWE_TD->prev_wb_GainShape = GainShape[sub( shr( NUM_SHB_SUBFR, 2 ), 1 )]; - move16(); - p2m_in = pow_off_pk_fx( GainShape, shr( NUM_SHB_SUBFR, 2 ), 1 ); - move16(); - - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) - { - FOR( i = 0; i < 8; i++ ) - { - GainShape[i] = RECIP_ROOT_EIGHT_FX; - move16(); - } - } - ELSE - { - push_indice( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); - - /* Quantization of the subframe gain parameter */ - QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl ); - } - - /* Compute the power of gains away from the peak gain after quantization */ - p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); - - /* Estimate the gain parameter */ -#ifdef HARMONIZE_TBE - EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, - &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); -#else - EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, - &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); -#endif - - /* If there's a big difference in the power of gains away from the peak gain */ - /* due to poor quantization then suppress energy of the high band. */ - - IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) - { - L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); - GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ - } - - pitBufAvg_fx = 0; - move16(); - - FOR( i = 0; i < NB_SUBFR; i++ ) - { - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[i], 82 ) ); /*Q6 */ - } - voicingBufAvg_fx = 0; - move16(); - FOR( i = 0; i < 3; i++ ) - { - voicingBufAvg_fx = add( voicingBufAvg_fx, mult_r( voicing_fx[i], 10912 ) ); /*Q15 */ - } - /* GainFrame *= max(min((float)(pitBufAvg/voicingBufAvg), 1.0f), 0.7f); */ - tmp = 32767; - move16(); - IF( voicingBufAvg_fx > 0 ) - { - exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ - L_tmp = L_mult( pitBufAvg_fx, tmp ); /* (21-exp) */ - L_tmp = L_shl_sat( L_tmp, add( exp, 10 ) ); - tmp = round_fx_sat( L_tmp ); /* Q15 */ - } - - tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ - - test(); - IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) - { - GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ - } - - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - /*wbbwe_em_factor = add( mult_r( 29491, st_fx->prev_wbbwe_em_factor_fx ), mult_r( 3277, wbbwe_em_factor ) ); */ /* Q15 */ - } - - /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult( voice_factors[0], 8192 ); - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mac( L_tmp, voice_factors[i], 8192 ); - } - avg_voice_fac = round_fx( L_tmp ); - - test(); - test(); - IF( st_fx->igf != 0 && EQ_16( coder_type, VOICED ) ) - { - /*GainFrame *= 0.5f;*/ - - GainFrame = Mult_32_16( GainFrame, 16384 ); - } - ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ - { - /*GainFrame *= 0.75f;*/ - GainFrame = Mult_32_16( GainFrame, 24576 ); - } - - /* Quantization of the frame gain parameter */ -#ifdef HARMONIZE_TBE - QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind, 0 ); -#else - QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind ); -#endif - - /* Adjust the subframe and frame gain of the synthesized SHB signal */ - /* Scale the shaped excitation*/ - - ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, - &Q_bwe_exc_ext, &dummy, dummy, dummy ); - - hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : void wb_tbe_enc_ivas_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : WB TBE encoder, 6 - 8 kHz band encoding module */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 *new_speech i : original input signal Q(-1) */ -/* Word32 *bwe_exc_extended i : bandwidth extended exciatation Q(2*Q_new) */ -/* Word16 voice_factors[] i : voicing factors Q15 */ -/* Word16 pitch_buf[] i : pitch for each subframe Q6 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 *synth o : WB SHB final synthesis */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State *st_fx i/o: encoder state structure */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* */ -/*==========================================================================*/ - -void wb_tbe_enc_ivas_fx( -#endif - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ - const Word16 Q_new, /* i : input HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors Q15 */ - const Word16 pitch_buf[] /* i : pitch for each subframe Q6 */ -) -{ - Word16 i, j, k; - Word16 hb_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16]; - Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - - Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; - Word16 shaped_wb_exc_scale[L_SHB_LAHEAD / 4]; - Word16 exc4kWhtnd[L_FRAME16k / 4]; - /*Word16 ana_align_delay = WBTBE_ANA_ALIGNDELAY; */ /* -L_SHB_LAHEAD/4 - 5 */ - Word32 GainFrame; - Word16 GainShape[NUM_SHB_SUBFR]; - Word16 lpc_wb[LPC_SHB_ORDER_WB + 1]; - Word32 lpc_wb_32_fx[LPC_SHB_ORDER_WB + 1]; - Word16 lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = { 32767, 32767 }; - move16(); - move16(); - Word16 *hb_new_speech, *hb_frame /*, hb_speech[ L_FRAME16k ]*/; - Word16 R_h[LPC_SHB_ORDER_WB + 2], R_l[LPC_SHB_ORDER_WB + 2]; - Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER_WB + 1]; - - Word32 prev_pow, curr_pow, Lscale; - Word32 p2m_in, p2m_out; - Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out, Q_cur_pow, Q_prev_pow; /* Q_hb_frame; */ - Word32 L_tmp, Lmax; - Word16 tmp, exp, Q_out, sc; - Word16 Q_ns = -1; - move16(); - - Word16 pitBufAvg_fx, voicingBufAvg_fx; - Word16 vf_modified_fx[NB_SUBFR16k]; - Word16 temp_wb_fac_fx, feedback_fx; - Word16 lsp_spacing_fx; - Word16 lsp_wb_temp_fx[LPC_SHB_ORDER_WB], lpc_wb_temp_fx[LPC_SHB_ORDER_WB + 1]; - Word32 L_feedback; - Word16 frac, exp1; - Word16 uv_flag; - Word16 dummy = 0; - Word16 avg_voice_fac; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - move16(); - - set16_fx( bwe_exc_extended_16, 0, L_FRAME32k + NL_BUFF_OFFSET ); - hb_new_speech = hb_old_speech + WBTBE_LOOK_LSUFBR_5_OVER_16; - hb_frame = hb_old_speech + WBTBE_LSUBFR_5_OVER_16 + WBTBE_ANA_ALIGNDELAY; - - Copy( hBWE_TD->old_speech_wb_fx, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); - Copy( hb_speech, hb_new_speech, LFRAME16K_OVER_4 ); - Copy( hb_old_speech + LFRAME16K_OVER_4, hBWE_TD->old_speech_wb_fx, WBTBE_LOOK_LSUFBR_5_OVER_16 ); - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( st_fx->voicing_fx[0], 16384 ) && LT_16( st_fx->voicing_fx[1], 16384 ) && LT_16( st_fx->voicing_fx[2], 16384 ) ) ) && !st_fx->igf ) - { - /* In case of unvoiced signals after switching cores, back-propagate the target signal */ - Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); - - i = WBTBE_LOOK_LSUFBR_5_OVER_16; - move16(); - k = 0; - move16(); - -#ifdef HARMONIZE_TBE - IF( st_fx->element_mode == EVS_MONO ) - { - FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) - { - L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); - move16(); - i--; - } - } - ELSE -#endif - { - FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) - { - L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); - move16(); - i--; - k++; - } - } - } - -#ifdef HARMONIZE_TBE - IF( st_fx->element_mode == EVS_MONO ) - { - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); - } - ELSE -#endif - { - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); - - /* Ensure R[0] isn't zero when entering Levinson-Durbin */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); - } - - E_LPC_lev_dur_fx( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); // Since 0th index will be 1 in floating point buffer, in fixed point one has to take norm of 0th index to identify the Q-factor - - Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); // Q12 - -#ifdef HARMONIZE_TBE - IF( st_fx->element_mode == EVS_MONO ) - { - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); - move32(); - } - - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); - } - ELSE -#endif - { - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 - move32(); - } - lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); - } - - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; - move16(); - } - - lsp_spacing_fx = lsp_wb_temp_fx[0]; - move16(); - FOR( i = 1; i < LPC_SHB_ORDER_WB; i++ ) - { - tmp = sub( lsp_wb_temp_fx[i], lsp_wb_temp_fx[i - 1] ); - lsp_spacing_fx = s_min( lsp_spacing_fx, tmp ); - } - - /* Spectral smoothing of autocorrelation coefficients */ - FOR( i = 1; i <= LPC_SHB_ORDER_WB; i++ ) - { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); - } - R_l[0] = s_max( R_l[0], 1 ); - move16(); - - test(); - IF( EQ_16( st_fx->rf_mode, 1 ) || EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) - { - E_LPC_lev_dur_fx( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_LBR_WB, NULL ); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_LBR_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); - - /* Expand bandwidth of the LP coeffs */ - FOR( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) - { - lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); - move16(); - } - - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); - move32(); /*Q27 */ - } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); - - FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) - { - hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; - move16(); - } - - lsp_weights_fx( lsp_wb, weights_lsp, LPC_SHB_ORDER_LBR_WB, &Q_out ); - - /* Quantization of LSFs */ - i = closest_centroid_fx( lsp_wb, weights_lsp, lbr_wb_bwe_lsfvq_cbook_2bit_fx, 4, LPC_SHB_ORDER_LBR_WB ); - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - hBWE_TD->lsf_WB = i; - move16(); - } - ELSE - { - push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_LBR_WB_LSF ); - } - - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); - - lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); - - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - - FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; - move16(); - } - ELSE /* 13.2kbps */ - { - E_LPC_lev_dur_fx( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_WB, NULL ); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); - - /* Expand bandwidth of the LP coeffs */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); - move16(); - } - - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); - move32(); /*Q27 */ - } - - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); - - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; - move16(); - } - - lsp_weights_fx( lsp_wb, weights_lsp, LPC_SHB_ORDER_WB, &Q_out ); - - /* Quantization of LSFs */ - i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ - -#ifdef HARMONIZE_TBE - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - hBWE_TD->lsf_WB = i; - move16(); - } - ELSE -#endif - { - push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); - } - Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); - - lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; - move16(); - } - - uv_flag = 0; - move16(); - test(); - if ( EQ_32( st_fx->extl_brate, WB_TBE_1k05 ) && EQ_16( st_fx->coder_type_raw, UNVOICED ) ) - { - uv_flag = 1; - move16(); - } - - Copy( voice_factors, vf_modified_fx, NB_SUBFR16k ); - IF( EQ_16( st_fx->coder_type, VOICED ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - /*vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1];*/ - vf_modified_fx[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6553, voice_factors[i - 1] ) ); - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - vf_modified_fx[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6553, voice_factors[3] ) ); - move16(); - } - } - - /* From low band excitation, generate highband excitation */ - Lmax = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME32k; i++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[i] ) ); - } - - Q_bwe_exc = 31; - move16(); - if ( Lmax != 0 ) - { - Q_bwe_exc = norm_l( Lmax ); - } - Q_bwe_exc = sub( Q_bwe_exc, 3 ); - Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); - - find_max_mem_wb_enc( st_fx, &n_mem ); - - IF( GT_16( sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ), n_mem ) ) - { - Q_bwe_exc = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); - } - - IF( uv_flag ) - { - if ( GT_16( Q_bwe_exc, 20 ) ) - { - Q_bwe_exc = 20; - move16(); /* restrict this to 20 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ - } - } - - prev_pow = 0; - move32(); -#ifdef HARMONIZE_TBE - IF( st_fx->element_mode == EVS_MONO ) - { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ - } - - Q_prev_pow = 0; - move32(); - } - ELSE -#endif - { - Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - /* Compare with the guard bits needed in the subsequent operations. - * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. - */ - IF( LT_16( Q_prev_pow, 3 ) ) - { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); - move16(); - } - Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); - move16(); - } - ELSE - { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; - move16(); - } - Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); - move16(); - } - - tmp = sub( Q_prev_pow, 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ - - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ - } - } - - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); - -#ifdef HARMONIZE_TBE - IF( st_fx->element_mode == EVS_MONO ) - { - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - } -#endif - - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - FOR( i = 0; i < L_FRAME32k; i++ ) - { - bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); - move16(); - } - -#ifdef HARMONIZE_TBE - IF( st_fx->element_mode == EVS_MONO ) - { - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - } -#endif - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); - Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - -#ifdef HARMONIZE_TBE2 - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, - bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified_fx, uv_flag, st_fx->igf ); -#else -#ifdef HARMONIZE_TBE - IF( st_fx->element_mode == EVS_MONO ) - { - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, - vf_modified_fx, uv_flag, st_fx->igf ); - } - ELSE -#endif - { - GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, - vf_modified_fx, uv_flag, st_fx->igf ); - } -#endif +#endif curr_pow = 0; move32(); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) @@ -1766,7 +1011,6 @@ void wb_tbe_enc_ivas_fx( move16(); } ELSE -#endif { Q_cur_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); /* Compare with the guard bits needed in the subsequent operations. @@ -1925,11 +1169,7 @@ void wb_tbe_enc_ivas_fx( push_indice( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); /* Quantization of the subframe gain parameter */ -#ifdef HARMONIZE_TBE QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl ); -#else - QuantizeSHBsubgains_ivas_fx( st_fx, GainShape, st_fx->extl ); -#endif } /* Compute the power of gains away from the peak gain after quantization */ @@ -1943,13 +1183,8 @@ void wb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ -#ifdef HARMONIZE_TBE EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); -#else - EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, - &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); -#endif /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1957,13 +1192,11 @@ void wb_tbe_enc_ivas_fx( IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) { L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ } ELSE -#endif { GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ } @@ -1995,26 +1228,22 @@ void wb_tbe_enc_ivas_fx( } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ } ELSE -#endif { GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ } IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) { -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ } ELSE -#endif { GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ } @@ -2033,13 +1262,11 @@ void wb_tbe_enc_ivas_fx( IF( st_fx->igf != 0 && EQ_16( st_fx->coder_type, VOICED ) ) { /*GainFrame *= 0.5f;*/ -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, 16384 ); } ELSE -#endif { GainFrame = Mpy_32_16_1( GainFrame, 16384 ); } @@ -2047,13 +1274,11 @@ void wb_tbe_enc_ivas_fx( ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ { /*GainFrame *= 0.75f;*/ -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, 24576 ); } ELSE -#endif { GainFrame = Mpy_32_16_1( GainFrame, 24576 ); } @@ -2062,26 +1287,16 @@ void wb_tbe_enc_ivas_fx( /* Quantization of the frame gain parameter */ IF( st_fx->rf_mode ) { -#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); -#else - QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); -#endif } ELSE { -#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); -#else - QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); -#endif } /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ -#ifdef HARMONIZE_TBE IF( st_fx->element_mode > EVS_MONO ) -#endif { scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); @@ -2091,9 +1306,7 @@ void wb_tbe_enc_ivas_fx( ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode > EVS_MONO ) -#endif { Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); } @@ -2348,11 +1561,7 @@ void swb_tbe_enc_fx( ELSE { /* LSF quantization (21 bits) */ -#ifdef HARMONIZE_TBE Quant_BWE_LSF_fx( st_fx->hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); -#else - Quant_BWE_LSF_fx( st_fx, lsf_shb_fx, lsf_shb_fx ); -#endif } /* space the lsfs to assert a minimum distance */ @@ -2888,13 +2097,8 @@ void swb_tbe_enc_fx( p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); /* Estimate the gain parameter */ -#ifdef HARMONIZE_TBE 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 ); -#else - EstimateSHBFrameGain_fx( 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 ); -#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -3003,11 +2207,7 @@ void swb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ -#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); -#else - QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind ); -#endif /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation */ @@ -3196,9 +2396,6 @@ void swb_tbe_enc_ivas_fx( move16(); TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; -#ifndef HARMONIZE_TBE - RF_ENC_HANDLE hRF = st_fx->hRF; -#endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; /* init and buffers set up */ @@ -3369,11 +2566,7 @@ void swb_tbe_enc_ivas_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ -#ifdef HARMONIZE_TBE gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); -#else - gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); -#endif test(); test(); @@ -3407,11 +2600,7 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ -#ifdef HARMONIZE_TBE Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); -#else - Quant_BWE_LSF_ivas_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); -#endif } /* space the lsfs to assert a minimum distance */ @@ -3585,11 +2774,7 @@ void swb_tbe_enc_ivas_fx( } 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 ); -#ifdef HARMONIZE_TBE Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); -#else - Quant_shb_ener_sf_ivas_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); -#endif /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ set16_fx( shb_res_fx, 0, L_FRAME16k ); @@ -3636,11 +2821,7 @@ void swb_tbe_enc_ivas_fx( move16(); } -#ifdef HARMONIZE_TBE Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); -#else - Quant_shb_res_gshape_ivas_fx( st_fx, shb_res_gshape_fx ); -#endif } ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { @@ -4352,11 +3533,7 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the gain shape parameter */ -#ifdef HARMONIZE_TBE QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); -#else - QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); -#endif /* Compute the power of gains away from the peak gain after quantization */ IF( st_fx->element_mode > EVS_MONO ) @@ -4402,13 +3579,8 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ -#ifdef HARMONIZE_TBE 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 ); -#else - EstimateSHBFrameGain_ivas_fx( 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 ); -#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -4641,315 +3813,117 @@ void swb_tbe_enc_ivas_fx( // GainFrame *= 0.85f; GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 ); } - } - ELSE - { - test(); - 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 */ - } - } - - /* Quantization of the frame gain parameter */ -#ifdef HARMONIZE_TBE - 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 ); -#else - IF( st_fx->rf_mode ) - { - QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); - } - ELSE - { - QuantizeSHBframegain_ivas_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 ); - } -#endif - - IF( hStereoICBWE != NULL ) - { - push_indice( hBstr, IND_STEREO_ICBWE_MSFLAG, hStereoICBWE->MSFlag, STEREO_ICBWE_MSFLAG_BITS ); - } - - /* Backup for the IC BWE parameters */ - test(); - IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) - { - // Check Qs - Copy_Scale_sig_16_32_DEPREC( lpc_shb_fx, hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 0 ); - hStereoICBWE->lpSHBRef_e = 31 - Q12; - move16(); - } - - /* Adjust the subframe and frame gain of the synthesized SHB signal */ - /* Scale the shaped excitation */ - IF( EQ_32( st_fx->extl, FB_TBE ) ) - { - tmp = norm_l( GainFrame_fx ); - if ( GainFrame_fx == 0 ) - { - tmp = 31; - move16(); - } - L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ - - tmp1 = 0; - move16(); - 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 */ - 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(); - tmp = norm_s( tmp1 ); - if ( tmp1 == 0 ) - { - tmp = 15; - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) ); - move16(); - } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); - move16(); - } - - hBWE_TD->prev_Env_error_fx = Env_error_fx; - move16(); - - /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; - move16(); - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : static void EstimateSHBFrameGain_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Estimate the overall gain factor needed to scale */ -/* synthesized highband to original highband signal level. */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) length : SHB overlap length Q0 */ -/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ -/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ -/* _(Word16*) win_shb : SHB window Q15 */ -/* _(Word16*) subwin_shb_local : SHB subframe window Q15 */ -/* _(Word16) Q_oriSHB : Q format of oriSHB */ -/* _(Word16) Q_synSHB : Q format of synSHB */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word32*)GainFrame :estimat of gain frame Q18 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ - -static void EstimateSHBFrameGain_fx( -#ifdef HARMONIZE_TBE - const Word16 element_mode, /* i : element mode */ -#endif - 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 arget 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, /* i : estimate of gain shape Q15 */ - Word32 *GainFrame, /* o : estimat of gain frame Q18 */ - const Word16 *win_shb, /* i : SHB window Q15 */ - const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ - const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ -) -#ifndef HARMONIZE_TBE -{ - const Word16 *skip; - Word16 i, j, k, l_shb_lahead, l_frame; - Word16 join_length, num_join, sig; - Word32 mod_syn[L_FRAME16k + L_SHB_LAHEAD]; - Word32 oriNrg, synNrg; - Word16 sum_gain; - Word32 frame_gain; - Word32 L_tmp; - Word16 exp_out; - Word16 tmp; - Word16 scaling = 0; - move16(); - - /* initilaization */ - l_frame = L_FRAME16k; - move16(); - l_shb_lahead = L_SHB_LAHEAD; - move16(); - skip = skip_bands_SWB_TBE; - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - skip = skip_bands_WB_TBE; - l_frame = L_FRAME16k / 4; - move16(); - l_shb_lahead = L_SHB_LAHEAD / 4; - move16(); - } - - /* apply gain for each subframe, and store noise output signal using overlap-add*/ - set32_fx( mod_syn, 0, l_frame + l_shb_lahead ); - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - sum_gain = 0; - move16(); - j = skip[0]; - move16(); - FOR( k = 0; k < length / 2; k++ ) - { - sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ - mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - mod_syn[j + k + length / 2] = L_mult( synSHB[j + k + length / 2], subgain[0] ); - move32(); /* Q(16+Q_synSHB) */ - } - - FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) - { - j = skip[i]; - move16(); - FOR( k = 0; k < length; k++ ) - { - L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ - mod_syn[j + k] = L_shl( L_mult( sum_gain, synSHB[j + k] ), 1 ); - move32(); /* Q(16+Q_synSHB) */ - } - } - FOR( k = 0; k < length / 2; k++ ) - { - j = skip[i]; - move16(); - sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ - mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - } - } - ELSE - { - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - move16(); - join_length = i_mult2( num_join, length ); - j = 0; - move16(); - FOR( k = 0; k < length; k++ ) - { - sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ - mod_syn[j] = L_mult( synSHB[j], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) - { - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - - FOR( k = 0; k < length; k++ ) - { - L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); - tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ - mod_syn[j] = L_shl( L_mult( tmp, synSHB[j] ), 1 ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - } - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); - move32(); /* Q(16+Q_synSHB)*/ - j++; - } - FOR( k = 0; k < length; k++ ) + } + ELSE + { + test(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) { - tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ - mod_syn[j] = L_mult( tmp, synSHB[j] ); - move32(); /* Q(16+Q_synSHB ) */ - j++; + /* Compensate for energy increase mismatch due to memory-less synthesis*/ + GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ } } - /* adjust frame energy */ - oriNrg = L_deposit_l( 0 ); - synNrg = L_deposit_l( 0 ); - FOR( i = 0; i < l_shb_lahead; i++ ) - { - sig = mult_r_sat( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_orisHB*/ - sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB */ - } + /* 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 ); - FOR( ; i < l_frame; i++ ) + IF( hStereoICBWE != NULL ) { - oriNrg = L_mac0_sat( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ - sig = round_fx_sat( mod_syn[i] ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB */ + push_indice( hBstr, IND_STEREO_ICBWE_MSFLAG, hStereoICBWE->MSFlag, STEREO_ICBWE_MSFLAG_BITS ); } - tmp = add( l_frame, l_shb_lahead ); - FOR( ; i < tmp; i++ ) + /* Backup for the IC BWE parameters */ + test(); + IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) { - sig = mult_r_sat( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB */ - sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB */ + // Check Qs + Copy_Scale_sig_16_32_DEPREC( lpc_shb_fx, hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 0 ); + hStereoICBWE->lpSHBRef_e = 31 - Q12; + move16(); } - IF( EQ_32( oriNrg, MAX_32 ) ) + + /* Adjust the subframe and frame gain of the synthesized SHB signal */ + /* Scale the shaped excitation */ + IF( EQ_32( st_fx->extl, FB_TBE ) ) { - scaling = negate( add( shr( n_subfr_saturation, 1 ), 1 ) ); - oriNrg = 0; - move32(); - FOR( i = 0; i < l_shb_lahead; i++ ) + tmp = norm_l( GainFrame_fx ); + if ( GainFrame_fx == 0 ) { - sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ + tmp = 31; + move16(); } - FOR( ; i < l_frame; i++ ) + L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ + + tmp1 = 0; + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - sig = shl_sat( oriSHB[i], scaling ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ + 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 */ + 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);*/ } - FOR( ; i < tmp; i++ ) + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ + move16(); + tmp = norm_s( tmp1 ); + if ( tmp1 == 0 ) { - sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ + tmp = 15; + move16(); + } + + FOR( i = 0; i < L_FRAME16k; i++ ) + { + White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) ); + move16(); } + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); + move16(); } - L_tmp = root_a_over_b_fx( oriNrg, 2 * Q_oriSHB, synNrg, 2 * Q_synSHB, &exp_out ); - exp_out = sub( exp_out, scaling ); - frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ - *GainFrame = frame_gain; - move32(); + + hBWE_TD->prev_Env_error_fx = Env_error_fx; + move16(); + + /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; + move16(); return; } -static void EstimateSHBFrameGain_ivas_fx( + +/*==========================================================================*/ +/* FUNCTION : static void EstimateSHBFrameGain_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Estimate the overall gain factor needed to scale */ +/* synthesized highband to original highband signal level. */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _(Word16) length : SHB overlap length Q0 */ +/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ +/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ +/* _(Word16*) win_shb : SHB window Q15 */ +/* _(Word16*) subwin_shb_local : SHB subframe window Q15 */ +/* _(Word16) Q_oriSHB : Q format of oriSHB */ +/* _(Word16) Q_synSHB : Q format of synSHB */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _(Word32*)GainFrame :estimat of gain frame Q18 */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*--------------------------------------------------------------------------*/ + +static void EstimateSHBFrameGain_fx( + const Word16 element_mode, /* i : element mode */ 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 arget original SHB frame */ @@ -4961,7 +3935,6 @@ static void EstimateSHBFrameGain_ivas_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) -#endif { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -5002,7 +3975,6 @@ static void EstimateSHBFrameGain_ivas_fx( j = skip[0]; move16(); -#ifdef HARMONIZE_TBE IF( element_mode == EVS_MONO ) { FOR( k = 0; k < length / 2; k++ ) @@ -5035,7 +4007,6 @@ static void EstimateSHBFrameGain_ivas_fx( } } ELSE -#endif { FOR( k = 0; k < length / 2; k++ ) { @@ -5075,7 +4046,6 @@ static void EstimateSHBFrameGain_ivas_fx( j = 0; move16(); -#ifdef HARMONIZE_TBE IF( element_mode == EVS_MONO ) { FOR( k = 0; k < length; k++ ) @@ -5118,7 +4088,6 @@ static void EstimateSHBFrameGain_ivas_fx( } } ELSE -#endif { FOR( k = 0; k < length; k++ ) { @@ -5210,13 +4179,11 @@ static void EstimateSHBFrameGain_ivas_fx( } } -#ifdef HARMONIZE_TBE IF( element_mode == EVS_MONO ) { L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &exp_out ); } ELSE -#endif { L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); } @@ -5630,178 +4597,43 @@ static Word16 closest_centroid_lc_fx( index = 0; move16(); - best_werr = MAX_32; - move32(); - - FOR( i = 0; i < centroids; i++ ) - { - /* Gain shape dimension 4 */ - tmpL = shl( i, 2 ); - - /* index 0 */ - tmp = sub( data[0], quantizer[tmpL] ); - werr = L_mult( tmp, tmp ); - - /* index 1 */ - tmp = sub( data[1], quantizer[tmpL + 1] ); - werr = L_mac( werr, tmp, tmp ); - - /* index 2 */ - tmp = sub( data[2], quantizer[tmpL + 2] ); - werr = L_mac( werr, tmp, tmp ); - - /* index 3 */ - tmp = sub( data[3], quantizer[tmpL + 3] ); - werr = L_mac( werr, tmp, tmp ); - - if ( LT_32( werr, best_werr ) ) - { - index = i; - move16(); - } - best_werr = L_min( best_werr, werr ); - } - - return index; -} - -/*============================================================*/ -/* FUNCTION : static void QuantizeSHBsubgains_fx() */ -/*------------------------------------------------------------*/ -/* PURPOSE : Quantize super highband temporal gains */ -/*------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) extl : extension layer Q0 */ -/*------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16[])subgains :super highband temporal gains Q15 */ -/*------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ - -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 */ -) -{ - Word16 i, idxSubGain; - Word16 Unit_weights10[NUM_SHB_SUBFR]; - Word16 exp, frac; - Word32 L_tmp; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - IF( EQ_16( extl, WB_TBE ) ) - { - set16_fx( Unit_weights10, 32767, (Word16) NUM_SHB_SUBFR / 4 ); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - IF( EQ_16( subgains[i], 0 ) ) - { - subgains[i + NUM_SHB_SUBFR / 4] = -18432; - move16(); /* (-72) in Q8 */ - } - ELSE - { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); /* move16(); */ - /*exp = -1 - exp; */ - exp = sub( -1, exp ); - L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q13 ; 20.0 * log10(2) in Q12*/ - subgains[i + NUM_SHB_SUBFR / 4] = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ - move16(); - } - } - idxSubGain = closest_centroid_lc_fx( subgains + NUM_SHB_SUBFR / 4, HBCB_SubGain5bit_fx, 1 << NUM_BITS_SHB_SUBGAINS ); - Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, subgains, NUM_SHB_SUBFR / 4 ); - - push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); - - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - L_tmp = L_mult( subgains[i], 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - move16(); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], add( exp, 1 ) ); - move16(); /*Q15 */ - } - - FOR( i = NUM_SHB_SUBFR / 2 - 1; i >= 0; i-- ) - { - subgains[i] = subgains[i / 2]; - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - IF( EQ_16( subgains[i], 0 ) ) - { - subgains[i] = -12288; - move16(); /* (-3) in Q12 */ - } - ELSE - { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); - /*exp = -1 - exp; */ - exp = sub( -1, exp ); + best_werr = MAX_32; + move32(); - L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ - subgains[i] = round_fx( L_shl( L_tmp, 12 ) ); /*Q12 */ - move16(); - } - } + FOR( i = 0; i < centroids; i++ ) + { + /* Gain shape dimension 4 */ + tmpL = shl( i, 2 ); - idxSubGain = (Word16) vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); + /* index 0 */ + tmp = sub( data[0], quantizer[tmpL] ); + werr = L_mult( tmp, tmp ); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - L_tmp = L_mult( subgains[i], 27213 ); /* *3.321928 in Q13 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - move16(); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], add( exp, 1 ) ); - move16(); /*Q15 */ - } + /* index 1 */ + tmp = sub( data[1], quantizer[tmpL + 1] ); + werr = L_mac( werr, tmp, tmp ); - FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) - { - subgains[i] = subgains[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; - move16(); - } + /* index 2 */ + tmp = sub( data[2], quantizer[tmpL + 2] ); + werr = L_mac( werr, tmp, tmp ); - hBWE_TD->idxSubGains = idxSubGain; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) + /* index 3 */ + tmp = sub( data[3], quantizer[tmpL + 3] ); + werr = L_mac( werr, tmp, tmp ); + + if ( LT_32( werr, best_werr ) ) { - push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); + index = i; + move16(); } + best_werr = L_min( best_werr, werr ); } - return; + return index; } -#ifndef HARMONIZE_TBE /*============================================================*/ -/* FUNCTION : static void QuantizeSHBsubgains_ivas_fx() */ +/* FUNCTION : static void QuantizeSHBsubgains_fx() */ /*------------------------------------------------------------*/ /* PURPOSE : Quantize super highband temporal gains */ /*------------------------------------------------------------*/ @@ -5818,10 +4650,10 @@ static void QuantizeSHBsubgains_fx( /* _ None */ /*------------------------------------------------------------*/ -static void QuantizeSHBsubgains_ivas_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 */ +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 */ ) { Word16 i, idxSubGain; @@ -5833,7 +4665,7 @@ static void QuantizeSHBsubgains_ivas_fx( IF( EQ_16( extl, WB_TBE ) ) { - set16_fx( Unit_weights10, 32767, NUM_SHB_SUBFR / 4 ); + set16_fx( Unit_weights10, 32767, (Word16) NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { IF( EQ_16( subgains[i], 0 ) ) @@ -5901,7 +4733,7 @@ static void QuantizeSHBsubgains_ivas_fx( } } - idxSubGain = vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); + idxSubGain = (Word16) vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -5923,12 +4755,9 @@ static void QuantizeSHBsubgains_ivas_fx( move16(); } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - hBWE_TD->idxSubGains = idxSubGain; - move16(); - } - ELSE + hBWE_TD->idxSubGains = idxSubGain; + move16(); + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); } @@ -5936,7 +4765,7 @@ static void QuantizeSHBsubgains_ivas_fx( return; } -#endif + /*-------------------------------------------------------------------* * Quant_shb_ener_sf_fx_fx() @@ -5945,64 +4774,6 @@ static void QuantizeSHBsubgains_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_fx( -#ifndef HARMONIZE_TBE - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ - Word16 Q_ener ) -{ - Word16 idxSubEner_fx; - Word16 temp_shb_ener_sf_fx; - Word16 exp /*, exp2*/, frac; - Word32 L_tmp1, L_tmp; - Word32 sum; - Word16 tmp; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ - sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ - move32(); - - exp = norm_l( sum ); - frac = Log2_norm_lc( L_shl( sum, exp ) ); - exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ - - tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */ - - temp_shb_ener_sf_fx = 0; - move16(); - idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ - - /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ - /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2( 14, frac ); - // *shb_ener_sf_Q31 = L_shl( L_tmp, exp - 14 + Q_ener ); /* In Q_ener */ - *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ - move32(); - - hBWE_TD->idx_shb_fr_gain = idxSubEner_fx; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( st_fx->hBstr, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF ); - } - - return; -} - - -/*-------------------------------------------------------------------* - * Quant_shb_ener_sf_ivas_fx() - * - * Quantize SHB subframe energies - *-------------------------------------------------------------------*/ - -static void Quant_shb_ener_sf_ivas_fx( -#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies Q_ener */ const Word16 Q_ener ) @@ -6013,9 +4784,7 @@ static void Quant_shb_ener_sf_ivas_fx( Word32 L_tmp1, L_tmp; Word32 sum; Word16 tmp; -#ifdef HARMONIZE_TBE Word16 Q_fac; -#endif TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ @@ -6025,7 +4794,6 @@ static void Quant_shb_ener_sf_ivas_fx( exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ @@ -6041,7 +4809,6 @@ static void Quant_shb_ener_sf_ivas_fx( move16(); } ELSE -#endif { L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ @@ -6051,20 +4818,14 @@ static void Quant_shb_ener_sf_ivas_fx( move16(); idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q11 */ -#ifdef HARMONIZE_TBE Q_fac = -Q9; move16(); -#endif } /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12/Q11+Q13+1 = Q26/Q25 */ -#ifdef HARMONIZE_TBE L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ -#else - L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ -#endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ @@ -6088,42 +4849,6 @@ static void Quant_shb_ener_sf_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_fx( -#ifndef HARMONIZE_TBE - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ -) -{ - Word16 i, idxSubGain_fx[NB_SUBFR16k]; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - FOR( i = 0; i < NB_SUBFR16k; i++ ) - { - idxSubGain_fx[i] = usquant_fx( shb_res_gshape_fx[i], - &shb_res_gshape_fx[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/, /*1024 = 0.125 in Q13 */ - shl( 1, NUM_BITS_SHB_RES_GS ) ); - move16(); - - hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( st_fx->hBstr, IND_SHB_RES_GS + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); - } - } - - return; -} - -/*-------------------------------------------------------------------* - * Quant_shb_res_gshape_ivas_fx() - * - * Quantize SHB gain shapes in residual domain - *-------------------------------------------------------------------*/ - -static void Quant_shb_res_gshape_ivas_fx( -#endif Encoder_State *st, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -6145,186 +4870,18 @@ static void Quant_shb_res_gshape_ivas_fx( hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; move16(); } - ELSE - { - push_indice( st->hBstr, IND_SHB_RES_GS + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); - } - } - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : static void QuantizeSHBframegain_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : QQuantize super highband frame gain */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 extl i : extension layer */ -/* Word32 extl_brate i : extension layer bitrate */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word32 *GainFrame i/o: Gain Q18 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* */ -/*==========================================================================*/ - -static void QuantizeSHBframegain_fx( -#ifndef HARMONIZE_TBE - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word32 *GainFrame, /* i/o: Gain Q18 */ - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extension layer bitrate */ - Word16 *rf_gainFrame_ind ) -{ - Word16 idxFrameGain; - Word32 Q_GainFrame; - Word16 Unit_weights1 = 1; - move16(); - Word16 exp, frac, tmp; - Word32 L_tmp; - Word32 GainFrameLog; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - RF_ENC_HANDLE hRF = st_fx->hRF; - - IF( EQ_16( extl, WB_TBE ) ) - { - determine_gain_weights_fx( GainFrame, &( Unit_weights1 ), 1 ); - IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) - { - singlevectortest_gain_fx( GainFrame, 1, - 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, - &Q_GainFrame, SHBCB_FrameGain16_fx ); - test(); - IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ - { - idxFrameGain--; - Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ - } - hBWE_TD->gFrame_WB = idxFrameGain; - move16(); - *rf_gainFrame_ind = idxFrameGain; - } - ELSE - { - singlevectortest_gain_fx( GainFrame, 1, - 1 << NUM_BITS_SHB_FrameGain, &idxFrameGain, &Q_GainFrame, - SHBCB_FrameGain64_fx ); - - push_indice( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FrameGain ); - *rf_gainFrame_ind = idxFrameGain; - move16(); /* Q18 */ - } - } - ELSE - { - IF( *GainFrame == 0 ) - { - GainFrameLog = -196608; - move32(); - } - ELSE - { - exp = norm_l( *GainFrame ); - frac = Log2_norm_lc( L_shl( *GainFrame, exp ) ); - // exp = ( 30 - exp - 18 ); - exp = sub( 30 - 18, exp ); - GainFrameLog = Mpy_32_16( exp, frac, 9864 ); - /*GainFrameLog= round_fx(L_shl(L_tmp,12)); //Q12 */ - } - - exp = norm_s( SHB_GAIN_QDELTA_FX_15 ); - tmp = div_s( shl( 1, sub( 14, exp ) ), SHB_GAIN_QDELTA_FX_15 ); - L_tmp = Mult_32_16( L_sub( GainFrameLog, SHB_GAIN_QLOW_FX_16 ), tmp ); - idxFrameGain = extract_l( L_shr( L_add( L_tmp, shl( 1, sub( 14, exp ) ) ), sub( 15, exp ) ) ); /*Q0*/ - IF( GT_16( idxFrameGain, ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1 ) ) - { - idxFrameGain = ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1; - move16(); - } - ELSE - { - if ( idxFrameGain < 0 ) - { - idxFrameGain = 0; - move16(); - } - } - - L_tmp = SHB_GAIN_QLOW_FX_16; - Q_GainFrame = L_mac( L_tmp, idxFrameGain, SHB_GAIN_QDELTA_FX_15 ); - - test(); - WHILE( GT_32( Q_GainFrame, L_add( GainFrameLog, 4866 ) ) && - idxFrameGain != 0 ) - { - test(); - idxFrameGain = sub( idxFrameGain, 1 ); - Q_GainFrame = L_mac0( SHB_GAIN_QLOW_FX_16, idxFrameGain, SHB_GAIN_QDELTA_FX_16 ); - } - - /* Q_GainFrame = (float) pow(10.0, Q_GainFrame ); */ - /* i: Q_GainFrame in Q16 */ - L_tmp = Mult_32_16( Q_GainFrame, 27213 ); /* *3.321928 in Q13 -> Q25 */ - L_tmp = L_shr( L_tmp, -2 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - Q_GainFrame = Pow2( 30, frac ); - exp = sub( exp, 30 ); - Q_GainFrame = L_shl( Q_GainFrame, add( exp, 18 ) ); /* Q18 */ - - hBWE_TD->idxFrameGain = idxFrameGain; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) + ELSE { - push_indice( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); + push_indice( st->hBstr, IND_SHB_RES_GS + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); } - *rf_gainFrame_ind = idxFrameGain; - move16(); - } - - IF( EQ_16( st_fx->rf_mode, 1 ) ){ - /*Currently intended for SWB only. Modify for WB is needed later!*/ - IF( EQ_16( hRF->rf_frame_type, RF_NELP ) ){ - *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ - move16(); -} -ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ -{ - IF( *GainFrame <= 327680 /*1.25 in Q18*/ ) /* [0 to 1.25] range --> 0.5*/ - { - *rf_gainFrame_ind = 0; - } - ELSE IF( *GainFrame <= 786432 /*3 in Q18*/ ) /* (1.25 to 3] --> 2 */ - { - *rf_gainFrame_ind = 1; - } - ELSE IF( *GainFrame <= 1572864 /*6 in Q18*/ ) /* (3 to 6] --> 4 */ - { - *rf_gainFrame_ind = 2; - } - ELSE /* (6 to Inf) --> 8 */ - { - *rf_gainFrame_ind = 3; } - move16(); -} -} -*GainFrame = Q_GainFrame; -move32(); /* Q18 */ - -return; + return; } /*==========================================================================*/ -/* FUNCTION : static void QuantizeSHBframegain_ivas_fx() */ +/* FUNCTION : static void QuantizeSHBframegain_fx() */ /*--------------------------------------------------------------------------*/ /* PURPOSE : QQuantize super highband frame gain */ /*--------------------------------------------------------------------------*/ @@ -6343,8 +4900,7 @@ return; /* */ /*==========================================================================*/ -static void QuantizeSHBframegain_ivas_fx( -#endif +static void QuantizeSHBframegain_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -6374,7 +4930,6 @@ static void QuantizeSHBframegain_ivas_fx( 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, &Q_GainFrame, SHBCB_FrameGain16_fx ); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ @@ -6384,7 +4939,6 @@ static void QuantizeSHBframegain_ivas_fx( } } ELSE -#endif { test(); IF( GT_64( W_deposit32_l( Q_GainFrame ), W_shl( W_mult_32_16( *GainFrame, 17367 ), 15 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ @@ -6968,136 +5522,8 @@ static Word16 Find_LSF_grid_fx( * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ -#ifndef HARMONIZE_TBE -static void gainFrSmooth_En_fx( Encoder_State *st_fx, - Word16 *shb_frame_fx, - const Word16 *lpc_shb_fx, - const Word16 *lsp_shb_fx, - Word16 *MA_lsp_shb_spacing, - Word16 *frGainAttenuate, - Word16 *frGainSmoothEn ) -{ - Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; - Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; - Word16 lsp_spacing; - - Word32 tempQ31; - Word16 tempQ15_1, tempQ15_2; - Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - /* inits */ - *frGainAttenuate = 0; - move16(); - *frGainSmoothEn = 0; - move16(); - *MA_lsp_shb_spacing = 16384; - move16(); - lsp_spacing = lsp_shb_fx[0]; - move16(); - - /* estimate the mean square error in lsps from current frame to past frames */ - tempQ15_1 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_slow_interpl_fx[0] ); - tempQ15_2 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_fast_interpl_fx[0] ); - lsp_slow_evol_rate = L_mult( tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mult( tempQ15_2, tempQ15_2 ); - - /* update the slow and fast lsp interp for next frame */ - tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 ); - hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 9830 ); - move16(); - tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 ); - hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 22937 ); - move16(); - - FOR( i = 1; i < LPC_SHB_ORDER; i++ ) - { - tempQ15_1 = sub( lsp_shb_fx[i], lsp_shb_fx[i - 1] ); - lsp_spacing = s_min( lsp_spacing, tempQ15_1 ); - - /* estimate the mean square error in lsps from current frame to past frames */ - tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); - tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); - lsp_slow_evol_rate = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mac( lsp_fast_evol_rate, tempQ15_2, tempQ15_2 ); - - /* update the slow and fast interpolation lsps for next frame */ - tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 ); - hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 9830 ); - move16(); - tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 ); - hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 22937 ); - move16(); - } - - test(); - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && LT_16( lsp_spacing, 262 ) ) - { - hBWE_TD->lsp_shb_spacing_fx[0] = lsp_spacing; - move16(); - hBWE_TD->lsp_shb_spacing_fx[1] = lsp_spacing; - move16(); - hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; - move16(); - hBWE_TD->prev_frGainAtten = 1; - move16(); - set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - } - - /* Estimate the moving average LSP spacing */ - tempQ31 = L_mult( hBWE_TD->lsp_shb_spacing_fx[0], 3277 ); /* 0.1f */ - tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f */ - tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f */ - *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 ); /* 0.4f */ - move16(); - - hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; - move16(); - hBWE_TD->lsp_shb_spacing_fx[1] = hBWE_TD->lsp_shb_spacing_fx[2]; - move16(); - hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; - move16(); - - test(); - test(); - test(); - IF( ( LT_16( lsp_spacing, 262 ) && ( LT_16( *MA_lsp_shb_spacing, 164 ) || EQ_16( hBWE_TD->prev_frGainAtten, 1 ) ) ) || LE_16( lsp_spacing, 105 ) ) - { - *frGainAttenuate = 1; - move16(); - - IF( NE_32( st_fx->total_brate, ACELP_24k40 ) ) - { - Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD ); - fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1, 3 ); - } - ELSE - { - set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - } - - test(); - if ( LT_32( lsp_slow_evol_rate, INV_1000_Q31 ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) - { - *frGainSmoothEn = 1; - move16(); - } - } -} - -/*-------------------------------------------------------------------* - * gainFrSmooth_En_ivas_fx() - * - * Gain frame smoothing and attenuation control - *-------------------------------------------------------------------*/ -#endif -#ifdef HARMONIZE_TBE static void gainFrSmooth_En_fx( -#else -static void gainFrSmooth_En_ivas_fx( -#endif Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, @@ -7152,14 +5578,12 @@ static void gainFrSmooth_En_ivas_fx( /* estimate the mean square error in lsps from current frame to past frames */ tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { lsp_slow_evol_rate = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); lsp_fast_evol_rate = L_mac( lsp_fast_evol_rate, tempQ15_2, tempQ15_2 ); } ELSE -#endif { lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); @@ -7222,14 +5646,12 @@ static void gainFrSmooth_En_ivas_fx( } test(); -#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO && LT_32( lsp_slow_evol_rate, INV_1000_Q31 ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) { *frGainSmoothEn = 1; move16(); } ELSE IF( st_fx->element_mode > EVS_MONO ) -#endif { test(); if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, INV_1000_Q31, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) @@ -7612,78 +6034,9 @@ static void LVQQuant_BWE_LSF_fx( * * Quantize super highband spectral envolope *-------------------------------------------------------------------*/ -#ifndef HARMONIZE_TBE -static void Quant_BWE_LSF_fx( - - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 lsf_shb[], /* i : unquanitzed LSFs */ - Word16 Q_lsfs[] /* o : quanitzed LSFs */ -) -{ - Word16 lsf[LPC_SHB_ORDER]; - Word16 lsf_q[LPC_SHB_ORDER]; - Word16 lsf_idx[NUM_Q_LSF]; - Word16 i; - Word16 m_idx; - Word16 m; - Word16 grid_idx; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - lsf[i] = sub( 16384, lsf_shb[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - - Quant_lower_LSF_fx( lsf, lsf_q, lsf_idx ); - /* i: lsf in Q15 */ - /* o: lsf_q in Q15 */ - - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - hBWE_TD->lsf_idx[i] = lsf_idx[i]; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( hBstr, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); - } - } - - m_idx = Quant_mirror_point_fx( lsf, lsf_q, &m ); - - hBWE_TD->m_idx = m_idx; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( hBstr, IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS ); - } - - grid_idx = Find_LSF_grid_fx( lsf, lsf_q, m ); - - hBWE_TD->grid_idx = grid_idx; - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( hBstr, IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS ); - } - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - Q_lsfs[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - - return; -} -#endif -#ifdef HARMONIZE_TBE static void Quant_BWE_LSF_fx( -#else -static void Quant_BWE_LSF_ivas_fx( -#endif 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 */ @@ -7767,129 +6120,6 @@ static void Quant_BWE_LSF_ivas_fx( *-------------------------------------------------------------------*/ void fb_tbe_enc_fx( -#ifndef HARMONIZE_TBE - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - const Word16 Q_fb_exc ) -{ - Word16 ratio; - Word16 tmp_vec[L_FRAME48k]; - Word16 idxGain; - Word16 input_fhb_buffer[L_FRAME48k + 4]; - Word16 *input_fhb = &input_fhb_buffer[0] + 4; - Word16 Sample_Delay_HP; - Word32 fb_exc_energy, temp2; - Word32 L_tmp; - Word16 tmp, tmp1, tmp2, exp, exp2, exp_norm; - Word16 s_max_value, exp_temp, i; - TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; - - s_max_value = 0; - FOR( i = 0; i < L_FRAME48k; i++ ) - { - s_max_value = s_max( s_max_value, abs_s( new_input[i] ) ); - } - exp_temp = norm_s( s_max_value ); - if ( s_max_value == 0 ) - { - exp_temp = 15; - move16(); - } - exp_temp = sub( exp_temp, 1 ); - - Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); - - elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); - Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; - - IF( NE_16( st->last_extl, FB_TBE ) ) - { - set16_fx( hBWE_TD->old_input_fhb_fx, 0, Sample_Delay_HP ); - hBWE_TD->old_input_fhb_fx_Q = 0; - move16(); - set16_fx( tmp_vec, 0, L_FRAME16k ); - } - Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ) ); - hBWE_TD->old_input_fhb_fx_Q = exp_temp; - Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); - Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k - Sample_Delay_HP ); - Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); - temp2 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ - temp2 = L_add_sat( temp2, L_shl_sat( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); /* Q11 */ - hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q11*/ - hBWE_TD->prev_fb_energy_fx_Q = sub( add( exp_temp, exp_temp ), 6 ); - fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc+1 -7) */ - - /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - L_tmp = L_max( 1, temp2 ); /*Q6*/ - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 31, sub( add( exp_temp, exp_temp ), 8 ) ), exp ); /* in Q15 (L_tmp in Q6)*/ - - exp2 = norm_l( fb_exc_energy ); - tmp2 = extract_h( L_shl( fb_exc_energy, exp2 ) ); - tmp1 = sub( add( Q_fb_exc, Q_fb_exc ), 8 ); /*1 - 9*/ - exp2 = sub( sub( 31, tmp1 ), exp2 ); /* in Q15 (L_tmp in Q6)*/ - - exp = sub( exp2, exp ); /* Denormalize and substract */ - IF( GT_16( tmp2, tmp ) ) - { - tmp2 = shr( tmp2, 1 ); - exp = add( exp, 1 ); - } - IF( 0 != tmp ) - { - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ - L_tmp = L_max( L_shr_sat( L_tmp, sub( 31, exp ) ), 0x1 ); /* Q0 */ - } - ELSE - { - L_tmp = 0; - } - - /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); - idxGain = max( 0, min(15,idxGain) ); */ - ratio = 0; - move16(); - IF( GE_32( L_tmp, 32768 ) ) - { - idxGain = 15; - move16(); - } - ELSE - { - ratio = extract_l( L_tmp ); - exp_norm = norm_s( ratio ); - idxGain = sub( 14, exp_norm ); - idxGain = s_max( 0, idxGain ); - } - - test(); - test(); - IF( GT_16( idxGain, 2 ) && LT_16( idxGain, 15 ) && GT_16( ratio, add( shl( 2, sub( idxGain, 1 ) ), shl( 2, sub( idxGain, 2 ) ) ) ) ) - { - idxGain = add( idxGain, 1 ); - } - - /* ratio = (float)(1 << idxGain);*/ - IF( st->codec_mode == MODE2 ) - { - hBWE_TD->idxGain = idxGain; - move16(); - } - ELSE - { - push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); - } - - return; -} - -void fb_tbe_enc_ivas_fx( -#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate Q_new_input */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ @@ -7909,7 +6139,6 @@ void fb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; Word16 q_diff, q_input_fhb; Word64 temp1, temp2; -#ifdef HARMONIZE_TBE Word16 offset; offset = 0; @@ -7918,21 +6147,13 @@ void fb_tbe_enc_ivas_fx( { offset = NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); } -#endif s_max_value = 0; move16(); -#ifdef HARMONIZE_TBE FOR( i = 0; i < add( L_FRAME48k, offset ); i++ ) { s_max_value = s_max( s_max_value, abs_s( new_input[i - offset] ) ); } -#else - FOR( i = 0; i < L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); i++ ) - { - s_max_value = s_max( s_max_value, abs_s( new_input[i - NS2SA( 48000, DELAY_FIR_RESAMPL_NS )] ) ); - } -#endif exp_temp = norm_s( s_max_value ); if ( s_max_value == 0 ) { @@ -7940,18 +6161,12 @@ void fb_tbe_enc_ivas_fx( move16(); } -#ifdef HARMONIZE_TBE if ( st->element_mode == EVS_MONO ) { exp_temp = sub( exp_temp, 1 ); } -#endif -#ifdef HARMONIZE_TBE Copy_Scale_sig( new_input - offset, input_fhb_new, add( L_FRAME48k, offset ), exp_temp ); -#else - Copy_Scale_sig( new_input - NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_fhb_new, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), exp_temp ); -#endif exp_temp = add( exp_temp, Q_new_input ); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) @@ -7960,11 +6175,7 @@ void fb_tbe_enc_ivas_fx( } ELSE { -#ifdef HARMONIZE_TBE elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + offset, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); -#else - elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); -#endif } test(); @@ -7992,7 +6203,6 @@ void fb_tbe_enc_ivas_fx( set16_fx( tmp_vec, 0, L_FRAME16k ); } -#ifdef HARMONIZE_TBE IF( st->element_mode == EVS_MONO ) { Word32 L_tmp, temp32, fb_exc_energy32; @@ -8062,7 +6272,6 @@ void fb_tbe_enc_ivas_fx( } } ELSE -#endif { q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q -- GitLab From 6e9e23d1a15c2274f7a9bcace24e912ab9acb4f8 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:57:00 +0100 Subject: [PATCH 05/20] [cleanup] accept FIX_2405_HARM_SMC_INIT --- lib_com/options.h | 1 - lib_enc/init_enc_fx.c | 11 -- lib_enc/ivas_stereo_switching_enc_fx.c | 4 - lib_enc/prot_fx_enc.h | 7 -- lib_enc/speech_music_classif_fx.c | 157 ------------------------- 5 files changed, 180 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index e77f7f402..f50c56e85 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2405_HARM_SMC_INIT /* VA, basop 2405, harmonisation of SMC init */ #define FIX_2280_REDUCTION_UNNECESSARY_SCALING /* VA: reduction of unnecessary scaling */ #define FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE /* VA: reduction of unnecessary scaling, non-BE part */ #define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index a4f06e932..f042b4a10 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -545,18 +545,7 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } -#ifndef FIX_2405_HARM_SMC_INIT - IF( st->element_mode == EVS_MONO ) - { - speech_music_clas_init_fx( st->hSpMusClas ); - } - ELSE - { - speech_music_clas_init_ivas_fx( st->hSpMusClas ); - } -#else speech_music_clas_init_fx( st->element_mode, st->hSpMusClas ); -#endif st->sp_aud_decision0 = 0; move16(); diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 98fad5780..573edd197 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -93,11 +93,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } -#ifndef FIX_2405_HARM_SMC_INIT - speech_music_clas_init_ivas_fx( st->hSpMusClas ); -#else speech_music_clas_init_fx( st->element_mode, st->hSpMusClas ); -#endif } return IVAS_ERR_OK; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 8014a9216..db08161e5 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1090,17 +1090,10 @@ void coder_type_modif_fx( ); void speech_music_clas_init_fx( -#ifdef FIX_2405_HARM_SMC_INIT const Word16 element_mode, /* i : element mode */ -#endif SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ); -#ifndef FIX_2405_HARM_SMC_INIT -void speech_music_clas_init_ivas_fx( - SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ -); -#endif void pitchDoubling_det_fx( Word16 *wspeech, diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 9db4b6b04..5218fb42f 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -75,163 +75,8 @@ static void detect_sparseness_fx( Encoder_State *st_fx, const Word16 localVAD_HE * Initialization of speech/music classifier *---------------------------------------------------------------------*/ -#ifndef FIX_2405_HARM_SMC_INIT -void speech_music_clas_init_fx( - SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ -) -{ - Word16 i; - - - hSpMusClas->inact_cnt = 0; - move16(); - set16_fx( hSpMusClas->past_dec, 0, HANG_LEN - 1 ); - set16_fx( hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1 ); - set16_fx( hSpMusClas->past_log_enr_fx, -1448, NB_BANDS_SPMUS ); /* log(E_MIN) in Q8 */ - - hSpMusClas->sp_mus_state = -8; - move16(); - hSpMusClas->wdrop_fx = 0; - move16(); - hSpMusClas->wdlp_0_95_sp_fx = 0; - move16(); - set16_fx( hSpMusClas->last_lsp_fx, 0, M_LSP_SPMUS ); - hSpMusClas->last_cor_map_sum_fx = 0; - move16(); - hSpMusClas->last_non_sta_fx = 0; - move16(); - set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); - hSpMusClas->past_ps_diff_fx = 0; - move16(); - hSpMusClas->past_epsP2_fx = 1024; - move16(); - - - hSpMusClas->gsc_thres_fx[0] = TH_0_MIN_FX; - move16(); - hSpMusClas->gsc_thres_fx[1] = TH_1_MIN_FX; - move16(); - hSpMusClas->gsc_thres_fx[2] = TH_2_MIN_FX; - move16(); - hSpMusClas->gsc_thres_fx[3] = TH_3_MIN_FX; - move16(); - set16_fx( hSpMusClas->gsc_lt_diff_etot_fx, 0, 40 ); - hSpMusClas->gsc_mem_etot_fx = 0; - move16(); - hSpMusClas->gsc_last_music_flag = 0; - move16(); - hSpMusClas->gsc_nb_thr_1 = 0; - move16(); - hSpMusClas->gsc_nb_thr_3 = 0; - move16(); - hSpMusClas->mold_corr_fx = 29491; - move16(); - hSpMusClas->mean_avr_dyn_fx = 64; - move16(); /*Q7 */ - hSpMusClas->last_sw_dyn_fx = 2560; - move16(); - /* speech/music classifier improvement */ - FOR( i = 0; i < BUF_LEN; i++ ) - { - hSpMusClas->buf_flux_fx[i] = -12800; - move16(); /*-100.0 in Q7 */ - hSpMusClas->buf_pkh_fx[i] = 0; - move16(); - hSpMusClas->buf_epsP_tilt_fx[i] = 0; - move16(); - hSpMusClas->buf_cor_map_sum_fx[i] = 0; - move16(); - hSpMusClas->buf_Ntonal_fx[i] = 0; - move16(); - hSpMusClas->buf_Ntonal2_fx[i] = 0; - move16(); - hSpMusClas->buf_Ntonal_lf_fx[i] = 0; - move16(); - } - - set16_fx( hSpMusClas->lpe_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->voicing_buf_fx, 0, HANG_LEN_INIT ); - hSpMusClas->gsc_hangover = 0; - move16(); - set16_fx( hSpMusClas->sparse_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->hf_spar_buf_fx, 0, HANG_LEN_INIT ); - hSpMusClas->LT_sparse_fx = 0; - move16(); - hSpMusClas->gsc_cnt = 0; - move16(); - set16_fx( hSpMusClas->old_Bin_E_fx, 0, 3 * N_OLD_BIN_E ); - set16_fx( hSpMusClas->buf_etot_fx, 0, 4 ); - set16_fx( hSpMusClas->buf_dlp_fx, 0, 10 ); - - hSpMusClas->UV_cnt1 = 300; - move16(); - hSpMusClas->LT_UV_cnt1_fx = 16000; - move16(); /*250.0f in Q6 */ - hSpMusClas->onset_cnt = 0; - move16(); - hSpMusClas->attack_hangover = 0; - move16(); - hSpMusClas->dec_mov_fx = 0; - move16(); - hSpMusClas->dec_mov1_fx = 0; - move16(); - hSpMusClas->mov_log_max_spl_fx = 25600; - move16(); /*200.0 in Q7 */ - hSpMusClas->old_lt_diff_fx[0] = 0; - move16(); - hSpMusClas->old_lt_diff_fx[1] = 0; - move16(); - - /* GSC - pitch excitation parameters */ - hSpMusClas->high_stable_cor = 0; - move16(); - set16_fx( hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN ); - - hSpMusClas->lps_fx = 0; - move16(); - hSpMusClas->lpm_fx = 0; - move16(); - hSpMusClas->lt_dec_thres_fx = 5120; - move16(); /*10 in Q9 */ - hSpMusClas->ener_RAT_fx = 0; - move16(); - - /* speech/music classification */ - set16_fx( hSpMusClas->lt_old_mode, 1, 3 ); - hSpMusClas->lt_voicing = 16384 /*0.5f Q15*/; - move16(); - hSpMusClas->lt_corr = 16384 /*0.5f Q15*/; - move16(); - hSpMusClas->lt_tonality = 0; - move32(); - set16_fx( hSpMusClas->lt_corr_pitch, 0, 3 ); - hSpMusClas->lt_hangover = 0; - move16(); - hSpMusClas->lowrate_pitchGain = 0; - move16(); - - - hSpMusClas->lt_music_hangover = 0; - move16(); - set16_fx( hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->tonality3_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->LPCErr_buf_fx, 0, HANG_LEN_INIT ); - hSpMusClas->lt_music_state = 0; - move16(); - hSpMusClas->lt_speech_state = 0; - move16(); - hSpMusClas->lt_speech_hangover = 0; - move16(); - - - return; -} - -void speech_music_clas_init_ivas_fx( -#else void speech_music_clas_init_fx( const Word16 element_mode, /* i : element mode */ -#endif SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ) @@ -379,7 +224,6 @@ void speech_music_clas_init_fx( hSpMusClas->lt_speech_hangover = 0; move16(); -#ifdef FIX_2405_HARM_SMC_INIT IF( element_mode > EVS_MONO ) { set32_fx( hSpMusClas->FV_st_fx, 0, N_SMC_FEATURES ); @@ -451,7 +295,6 @@ void speech_music_clas_init_fx( hSpMusClas->lpn_fx = 0; move16(); } -#endif return; } -- GitLab From 45db640874c5c68bfb813633283ac59520514b28 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:57:37 +0100 Subject: [PATCH 06/20] [cleanup] accept FIX_2280_REDUCTION_UNNECESSARY_SCALING --- lib_com/ivas_prot_fx.h | 13 ----- lib_com/options.h | 1 - lib_com/prot_fx.h | 13 ----- lib_dec/acelp_core_dec_fx.c | 29 ---------- lib_dec/core_switching_dec_fx.c | 37 ------------- lib_dec/hq_core_dec_fx.c | 25 --------- lib_dec/ivas_core_dec_fx.c | 98 --------------------------------- lib_dec/ivas_mct_dec_fx.c | 15 ----- lib_dec/ivas_tcx_core_dec_fx.c | 11 ---- lib_dec/swb_bwe_dec_fx.c | 8 --- 10 files changed, 250 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index c32f62933..ff6e48db0 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1587,12 +1587,7 @@ void ivas_hq_core_dec_fx( const Word16 output_frame, /* i : output frame length */ const Word16 hq_core_type, /* i : HQ core type */ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ -#else - Word16 output[], - Word16 *Q_output -#endif ); /* o : Consumed bits Q0 */ @@ -1848,11 +1843,7 @@ void stereoFdCngCoherence_fx( /* o : Q_syn_hb*/ Word16 ivas_wb_bwe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ -#else - const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ - #endif Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ @@ -2050,11 +2041,7 @@ void ivas_buffer_deinterleaved_to_interleaved_fx( void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11 */ -#else - Word16 *signal_out, /* o : synthesis @internal_Fs, Q0 */ -#endif Word16 *signal_outFB, /* o : synthesis @output_Fs, Q0 */ Word16 pitch_buf[], /* o : floating pitch for each subframe, Q6 */ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ diff --git a/lib_com/options.h b/lib_com/options.h index f50c56e85..a76c4b2cc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2280_REDUCTION_UNNECESSARY_SCALING /* VA: reduction of unnecessary scaling */ #define FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE /* VA: reduction of unnecessary scaling, non-BE part */ #define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ #define FIX_2404_HARM_SIGNAL_CLAS /* VA: basop-2404, harmonize signal_clas and signa_ivas_clas */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index db29ad2a3..70ceda92e 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7343,13 +7343,8 @@ ivas_error core_switching_pre_dec_fx( ivas_error core_switching_post_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *synth, /* i/o: output synthesis Qsynth*/ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ -#else - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ - Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ -#endif const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -9899,17 +9894,9 @@ Word16 swb_bwe_dec_fx32( ivas_error acelp_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ -#else - Word16 output_fx[], /* o : synthesis @internal Fs */ -#endif Word16 synth_fx16[], /* o : synthesis */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ -#else - Word16 save_hb_synth_fx16[], /* o : HB synthesis */ -#endif Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ Word16 *voice_factors_fx, /* o : voicing factors */ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 07ebbcdb8..5838fae17 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -53,17 +53,9 @@ ivas_error acelp_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ -#else - Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ -#endif Word16 synth_fx16[], /* o : synthesis Q_syn2*/ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ -#else - Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ -#endif Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ @@ -213,11 +205,7 @@ ivas_error acelp_core_dec_fx( Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/ } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING set32_fx( output_fx32, 0, st->L_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ -#else - set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ -#endif set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ /* CN generation done in DFT domain */ @@ -2020,11 +2008,7 @@ ivas_error acelp_core_dec_fx( } } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING IF( save_hb_synth_fx32 != NULL ) -#else - IF( save_hb_synth_fx16 != NULL ) -#endif { /* save and then zero-out lowband */ max_real = 0; @@ -2065,13 +2049,7 @@ ivas_error acelp_core_dec_fx( } } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx32, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); -#else - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*tmp buffer for save_hb_synth_fx[] */, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); - - Copy_Scale_sig_32_16( synth_fx, save_hb_synth_fx16, output_frame, 0 ); // Q0 -#endif /* restore lowband */ FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) @@ -2214,14 +2192,7 @@ ivas_error acelp_core_dec_fx( /* Copy output signal */ Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_16_32_no_sat( psyn_fx, output_fx32, st->L_frame, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 -#else - IF( st->element_mode > EVS_MONO ) - { - Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ - } -#endif Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 st->Q_syn2 = 0; diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index ee7fdb5a8..dabb48fcb 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -215,16 +215,8 @@ void bw_switching_pre_proc_fx( ivas_error core_switching_post_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *synth, /* i/o: output synthesis Qsynth*/ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ -#else - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ -#endif -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ -#else - Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ -#endif const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -446,11 +438,7 @@ ivas_error core_switching_post_dec_fx( test(); IF( ( ( NE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_core_brate, FRAME_NO_DATA ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) && NE_16( st_fx->element_mode, IVAS_CPE_TD ) ) || EQ_16( nchan_out, 1 ) ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_fx->idchan, 1 ) && ( EQ_16( nchan_out, 1 ) || EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) ) { -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Scale_sig32( output_fx, L_FRAME48k, Q10 - Q11 ); /* Q10 */ -#else - Scale_sig32( output_fx, L_FRAME48k, Q10 - Q4 ); /* Q10 */ -#endif core_switch_lb_upsamp_fx( st_fx, output_fx ); } @@ -508,11 +496,7 @@ ivas_error core_switching_post_dec_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ -#else - Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ -#endif move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -561,11 +545,7 @@ ivas_error core_switching_post_dec_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ -#else - Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ -#endif move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -627,18 +607,11 @@ ivas_error core_switching_post_dec_fx( hHQ_core->Q_old_wtda = Qtmp; move16(); } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 output_mem_fx[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; IF( output_mem_fx32 != NULL ) { Copy_Scale_sig_32_16( output_mem_fx32, output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Qtmp, Q11 ) ); // Qtmp } -#else - IF( output_mem_fx != NULL ) - { - Scale_sig( output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */ - } -#endif *Qsynth = Qtmp; move16(); @@ -1073,25 +1046,15 @@ static void core_switch_lb_upsamp_fx( no_col = s_min( no_col, temp ); } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( st->hTcxDec->L_frameTCX, imult1616( no_col, st->cldfbSyn->no_channels ) ), Q11 - Q10 ); /* Q11 */ -#else - Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( L_FRAME48k, imult1616( no_col, st->cldfbSyn->no_channels ) ), 4 - 10 ); /* Q4 */ -#endif /* save synthesis - needed in case of core switching */ IF( st->hTcxDec != NULL ) { -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */ -#else - Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */ -#endif } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Scale_sig32( output, imult1616( no_col, st->cldfbSyn->no_channels ), Q11 - Q4 ); /* Q11 */ -#endif return; } diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index dcc99bbdc..f3517891a 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -468,12 +468,7 @@ void ivas_hq_core_dec_fx( const Word16 output_frame, /* i : output frame length Q0*/ const Word16 hq_core_type, /* i : HQ core type Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ -#else - Word16 output[], /* Q_ouput */ - Word16 *Q_output -#endif ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -509,9 +504,6 @@ void ivas_hq_core_dec_fx( Word16 mdctWindowLength; Word16 mdctWindowLengthFB; Word16 tmp_e; -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING - Word16 tmp_out[L_FRAME48k]; -#else Word16 output[L_FRAME16k]; Word16 Q_output; @@ -521,7 +513,6 @@ void ivas_hq_core_dec_fx( move16(); st_fx->Q_syn_factor = 0; move16(); -#endif /*-------------------------------------------------------------------------- * Initializations @@ -903,11 +894,7 @@ void ivas_hq_core_dec_fx( move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Q_output = Q_audio; -#else - *Q_output = Q_audio; -#endif move16(); } @@ -933,11 +920,7 @@ void ivas_hq_core_dec_fx( IF( st_fx->element_mode > EVS_MONO ) { /* LB synthesis for potential switch to ACELP */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING window_ola_fx( wtda_audio_LB, output, &Q_output, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, L_FRAME16k, st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); -#else - window_ola_fx( wtda_audio_LB, output, Q_output, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, L_FRAME16k, st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); -#endif } test(); test(); @@ -1001,18 +984,10 @@ void ivas_hq_core_dec_fx( } /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig( output, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame, negate( Q_output ) ); /* Q0 */ Copy_Scale_sig_16_32_DEPREC( output, output_32_fx, L_FRAME16k, sub( Q11, Q_output ) ); // Q11 st_fx->Q_syn_factor = s_min( 0, s_min( *Q_synth, Q_output ) ); -#else - IF( st_fx->element_mode > EVS_MONO ) - { - Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ - Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ - } -#endif return; } diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 2554c7c78..8113a0796 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -284,9 +284,7 @@ ivas_error ivas_core_dec_fx( } set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING set32_fx( output_32_fx[n], 0, L_FRAME48k ); -#endif set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */ @@ -476,18 +474,6 @@ ivas_error ivas_core_dec_fx( IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING - Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; - - IF( save_hb_synth_32_fx ) - { - save_hb_synth_16_fx = save_hb_synth_fx_arr; - } - ELSE - { - save_hb_synth_16_fx = NULL; - } -#endif IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q11 - Q10 ); // Q11 @@ -527,19 +513,11 @@ ivas_error ivas_core_dec_fx( st->Q_syn_factor = 0; move16(); -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING IF( NE_32( ( error = acelp_core_dec_fx( st, output_32_fx[n], synth_16_fx[n], save_hb_synth_32_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) -#endif { return error; } -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING - Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 - Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); // Q0 -#endif IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q10 - Q11 ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) , Q10 */ @@ -562,11 +540,7 @@ ivas_error ivas_core_dec_fx( IF( save_hb_synth_32_fx ) { -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING - Copy_Scale_sig_16_32_DEPREC( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); // Q11 -#else Scale_sig32( save_hb_synth_32_fx, output_frame, Q11 ); // Q0 -> Q11 -#endif hSCE->q_save_hb_synth_fx = Q11; move16(); } @@ -607,13 +581,7 @@ ivas_error ivas_core_dec_fx( move32(); } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING stereo_tcx_core_dec_fx( st, frameMode[n], output_32_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); -#else - stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); - - Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, sub( Q11, st->Q_syn_factor ) ); // Q11 -#endif IF( st->hTcxDec ) { @@ -631,27 +599,9 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_32_fx[n] ); Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor -#else - Word16 Q_output; - - Q_output = 0; - move16(); - Q_synth = 0; - move16(); - st->Q_syn_factor = 0; - move16(); - - ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); - - Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); // Q11 - st->Q_syn_factor = s_min( 0, s_min( Q_synth, Q_output ) ); - Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor - Scale_sig( output_16_fx[n], L_FRAME48k, sub( st->Q_syn_factor, Q_output ) ); // st->Q_syn_factor -#endif } /*---------------------------------------------------------------------* @@ -831,28 +781,6 @@ ivas_error ivas_core_dec_fx( /*core_switching_post_dec*/ Q_synth = add( sub( 15, e_sig[0] ), st->Q_syn_factor ); -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING - /*------------------fix-to-fix-end-----------------------*/ - - Word16 output_mem_16_fx[L_FRAME48k]; - Word16 *p_output_mem_16; - - IF( p_output_mem_fx != NULL ) - { - p_output_mem_16 = output_mem_16_fx; - Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), -Q11 ); // Q(q_output_mem_fx-11) - } - ELSE - { - p_output_mem_16 = NULL; - set16_fx( output_mem_16_fx, 0, NS2SA_FX2( st->output_Fs, 3125000 ) ); - } - - Scale_sig32( output_32_fx[n], L_FRAME48k, Q4 - Q11 ); // Q4 - - /*size of synth is choosen as delay comp to start with*/ - /*-------------------cldfb-start-------------------------*/ -#endif IF( st->cldfbSyn != NULL ) { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q4 - Q11 ); // Q4 @@ -911,11 +839,7 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING IF( NE_32( ( error = core_switching_post_dec_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_fx, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = core_switching_post_dec_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -956,14 +880,10 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING #ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE Scale_sig32( output_32_fx[n], output_frame, ( Q4 - Q11 ) ); // Q4 Scale_sig32( output_32_fx[n], output_frame, ( Q11 - Q4 ) ); // Q11 #endif -#else - Scale_sig32( output_32_fx[n], L_FRAME48k, ( Q11 - Q4 ) ); // Q11 -#endif /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -1068,14 +988,10 @@ ivas_error ivas_core_dec_fx( ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) { /* WB BWE decoder */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING #ifdef HARM_FD_BWE Q_hb_synth_fx = wb_bwe_dec_fx( st, output_32_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); #else Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_32_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); -#endif -#else - Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); #endif } @@ -1192,26 +1108,12 @@ ivas_error ivas_core_dec_fx( IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) { /* SHB CNG decoder */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], output_frame, -( Q11 ) ); // Q0 Copy_Scale_sig_32_16( synth_32_fx[n], synth_16_fx[n], output_frame, -( Q11 + Q2 ) ); // Q0 Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ); // Q8 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 ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 swb_CNG_dec_fx( st, synth_16_fx[n], hb_synth_16_fx[n], sid_bw[n], -Q2 ); -#else - Word16 synth_fxl[960]; /* Q-2 */ - Word16 q; - - q = 2; - move16(); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], output_frame, -( Q11 ) ); // Q0 - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); // Q0 - Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ); // Q8 - 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 ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 - - swb_CNG_dec_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); -#endif test(); IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 2aca72cf1..dd889e83b 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -354,17 +354,6 @@ ivas_error ivas_mct_dec_fx( } /* Postprocessing for ACELP/MDCT core switching and synchronization */ -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING - Word16 output_mem_fx[L_FRAME48k]; - IF( hCPE->output_mem_fx[1] != NULL ) - { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA_FX2( sts[n]->output_Fs, 3125000 ), -Q11 ); - } - ELSE - { - set16_fx( output_mem_fx, 0, NS2SA_FX2( sts[n]->output_Fs, 3125000 ) ); - } -#endif Word16 Q_synth = sub( 15, e_sig[n] ); move16(); @@ -379,11 +368,7 @@ ivas_error ivas_mct_dec_fx( dirac_stereo_flag = 0; } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING IF( NE_32( ( error = core_switching_post_dec_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], hCPE->output_mem_fx[1], 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = core_switching_post_dec_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) -#endif { return error; } diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 4c780bc1c..f317320aa 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -190,11 +190,7 @@ void stereo_tcx_init_dec_fx( void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11*/ -#else - Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0*/ -#endif Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0*/ Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6*/ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ @@ -236,9 +232,7 @@ void stereo_tcx_core_dec_fx( Word32 psd_fx[L_FRAME16k]; Word32 psd_part_fx[NPART_SHAPING]; Word16 psd_part_e; -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 signal_out_fx[L_FRAME48k]; -#endif TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -876,9 +870,6 @@ void stereo_tcx_core_dec_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING - Word32 signal_out_32_fx[L_FRAME48k]; -#endif Word16 exp; Copy_Scale_sig_16_32_no_sat( signal_out_fx, signal_out_32_fx, st->hFdCngDec->hFdCngCom->frameSize, Q6 ); generate_masking_noise_ivas_fx( signal_out_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); @@ -894,9 +885,7 @@ void stereo_tcx_core_dec_fx( } } -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_16_32_DEPREC( signal_out_fx, signal_out_32_fx, st->L_frame, sub( Q11, st->Q_syn_factor ) ); -#endif pop_wmops(); return; diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 1d9ec7444..f028824e9 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -360,11 +360,7 @@ Word16 wb_bwe_dec_fx( Word16 ivas_wb_bwe_dec_fx( #endif Decoder_State *st_fx, /* i/o: decoder state structure */ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ -#else - const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ -#endif Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ @@ -378,10 +374,8 @@ Word16 ivas_wb_bwe_dec_fx( Word16 ysynth_fx[L_FRAME48k]; Word16 Q_syn, exp, Q_syn_hb; Word32 L_wtda_synth_fx[2 * L_FRAME48k], ysynth_32[L_FRAME48k], t_audio32_tmp[L_FRAME48k]; -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 output[L_FRAME16k]; Word16 Q_input, sf; -#endif Word16 scl, new_input_fx_exp; Word16 i; FD_BWE_DEC_HANDLE hBWE_FD; @@ -397,7 +391,6 @@ Word16 ivas_wb_bwe_dec_fx( test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING sf = getScaleFactor32( output_fx32, st_fx->L_frame ); Q_input = 0; @@ -409,7 +402,6 @@ Word16 ivas_wb_bwe_dec_fx( Copy_Scale_sig_32_16( output_fx32, output, st_fx->L_frame, sub( Q_input, Q11 ) ); // Q_input -#endif lerp( output, ysynth_fx, L_FRAME16k, st_fx->L_frame ); wtda_fx( ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k ); -- GitLab From 49d6b653edf1e50d4f95bb08d4e007deabe8c5b7 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:58:19 +0100 Subject: [PATCH 07/20] [cleanup] accept FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE --- lib_com/options.h | 1 - lib_dec/ivas_core_dec_fx.c | 34 ---------------------------------- 2 files changed, 35 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a76c4b2cc..aab5f6f01 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE /* VA: reduction of unnecessary scaling, non-BE part */ #define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ #define FIX_2404_HARM_SIGNAL_CLAS /* VA: basop-2404, harmonize signal_clas and signa_ivas_clas */ #define HARMONIZE_ACELP_ENC /* VA: basop issue 2400: Remove duplicated main ACELP encoder function */ diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 8113a0796..5a208446f 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -93,9 +93,6 @@ ivas_error ivas_core_dec_fx( ivas_error error; Word32 L_tmp; Word16 Q_synth; -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE - Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; -#endif Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; @@ -468,9 +465,6 @@ ivas_error ivas_core_dec_fx( * HQ core decoding *---------------------------------------------------------------------*/ -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE - set16_fx( output_16_fx[n], 0, L_FRAME48k ); /* this is needed for instances like L_norm_arr( p_output_fx[i], L_FRAME48k ) */ -#endif IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ @@ -880,10 +874,6 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 } -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE - Scale_sig32( output_32_fx[n], output_frame, ( Q4 - Q11 ) ); // Q4 - Scale_sig32( output_32_fx[n], output_frame, ( Q11 - Q4 ) ); // Q11 -#endif /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -924,7 +914,6 @@ ivas_error ivas_core_dec_fx( * WB BWE decoding *---------------------------------------------------------------------*/ -#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE Word16 Q_hb_synth_fx, Q_synth_fx; Word16 Q_syn_hb; @@ -932,10 +921,6 @@ ivas_error ivas_core_dec_fx( move16(); Q_synth_fx = Q_synth; move16(); -#else - Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; - Word16 Q_syn_hb, sf; -#endif flaf_swb_tbe = 0; move16(); @@ -953,22 +938,6 @@ ivas_error ivas_core_dec_fx( move16(); } -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE - sf = getScaleFactor32( output_32_fx[n], L_FRAME48k ); - - Q_input = 0; - move16(); - if ( LT_16( sf, 5 ) ) - { - Q_input = sub( sf, 5 ); - } - Q_hb_synth_fx = 0; - move16(); - Q_synth_fx = Q_synth; - move16(); - - Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, sub( Q_input, Q11 ) ); // Q_input -#endif Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 test(); test(); @@ -1000,9 +969,6 @@ ivas_error ivas_core_dec_fx( { Copy_Scale_sig_16_32_no_sat( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 } -#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE - Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 -#endif Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], synth_32_fx[n], output_frame, sub( Q11, Q_synth_fx ) ); // Q11 IF( hBWE_FD != NULL ) -- GitLab From 86554a2b66b58d26e0642092f9d0941ef5bd3f51 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:59:00 +0100 Subject: [PATCH 08/20] [cleanup] accept FIX_2403_COMBINE_PITCH_OL --- lib_com/options.h | 1 - lib_enc/pitch_ol_fx.c | 546 ------------------------------------------ 2 files changed, 547 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index aab5f6f01..186182ded 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ #define FIX_2404_HARM_SIGNAL_CLAS /* VA: basop-2404, harmonize signal_clas and signa_ivas_clas */ #define HARMONIZE_ACELP_ENC /* VA: basop issue 2400: Remove duplicated main ACELP encoder function */ #define FIX_2392_MSAN_DESTROY_DEC /* VA: basop issue 2392: fix MSAN in ivas_destroy_dec_fx() */ diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index b7f79eeea..571b73500 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -59,9 +59,7 @@ static Word32 Dot_product12_OL( Word16 *sum1, const Word16 x[], const Word16 y[] static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); -#ifdef FIX_2403_COMBINE_PITCH_OL static void pitch_ol_resolve_fx( Word16 pitch[3], Word16 voicing[3], Word16 *old_pitch, Word16 *old_corr, Word16 *old_thres, Word16 *delta_pit, const Word16 element_mode, const Word16 corr_shift, const Word16 relE, const Word16 Opt_SC_VBR, Word16 pitchX[NHFR][2 * NSECT], Word16 corX[NHFR][2 * NSECT], Word16 scaledX[NHFR][2 * NSECT], const Word16 sect0, const Word16 *pit_max, const Word16 pit_min_coding ); -#endif /*-----------------------------------------------------------------* @@ -89,7 +87,6 @@ void pitch_ol_init_fx( return; } -#ifdef FIX_2403_COMBINE_PITCH_OL /*-----------------------------------------------------------------* * pitch_ol_resolve_fx() * @@ -399,7 +396,6 @@ static void pitch_ol_resolve_fx( return; } -#endif /*==================================================================================*/ /* FUNCTION : pitch_ol_fx() */ @@ -486,33 +482,15 @@ void pitch_ol_fx( Word16 *pt_exp1, *pt_exp2, *pt_exp3, *pt_exp4; Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4, *pt_cor5, *pt_cor6; -#ifndef FIX_2403_COMBINE_PITCH_OL - Word16 thres1[6]; - Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; - Word16 ind_corX, ind1_corX; - - Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; -#else Word16 cnt, ind, ind1, offset, offset1, offset_la, offset_la1; Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1; -#endif Word16 len_temp; -#ifndef FIX_2403_COMBINE_PITCH_OL - Word16 pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1]; - - Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; - Word32 enr, enr2, Ltmp; - Word16 fac, tmp16, tmp16_2; - Word16 qCorX, qScaledX; - Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; -#else Word16 pitchX[NHFR][2 * NSECT]; Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; Word32 enr, enr2, Ltmp; Word16 tmp16, tmp16_2; Word16 qCorX, qScaledX; Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT]; -#endif const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; Word16 pit_min_coding; @@ -1142,258 +1120,7 @@ void pitch_ol_fx( } /* FOR j < NSECT */ } /* FOR i < NHFR */ -#ifdef FIX_2403_COMBINE_PITCH_OL pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, EVS_MONO, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); -#else - /*-----------------------------------------------------------------* - * Favor a smaller delay if it happens that it has its multiple - * in the longer-delay sections (harmonics check) - *-----------------------------------------------------------------*/ - - FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ - { - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - } - - fac = THRES0; - move16(); /* the look-ahead */ - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ - } - - /*-----------------------------------------------------------------* - * Do 1st estimate for pitch values - * Adjust the normalized correlation using estimated noise level - * Compute the maximum scaling for the neighbour correlation - * reinforcement - *-----------------------------------------------------------------*/ - add_sect0 = add( NSECT, sect0 ); - sub_sect0 = sub( NSECT, sect0 ); - FOR( i = 0; i < NHFR; i++ ) - { - /* 1st set of pitch candidates */ - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_tmp[i] = ind; - move16(); - pitch_tmp[i] = pitchX[i][ind]; - move16(); - cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); - move16(); - - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i] = mult( THRES1, cor_tmp[i] ); - move16(); - - /* 2nd set of pitch candidates */ - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind_tmp[i + NHFR] = ind1; - move16(); - pitch_tmp[i + NHFR] = pitchX[i][ind1]; - move16(); - cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); - move16(); - - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); - move16(); - } - /*-----------------------------------------------------------------* - * Take into account previous and next pitch values of the present - * frame and look-ahead. Choose the pitch lags and normalize - * correlations for each half-frame & look-ahead - *-----------------------------------------------------------------*/ - - pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); - FOR( i = 0; i < NHFR; i++ ) - { - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - - if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) - { - ind = ind1; - move16(); - } - test(); - if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) - { - ind_corX = ind1_corX; - move16(); - } - test(); - test(); - test(); - IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) - { - pitch[i] = pitchX[i][ind_corX]; - move16(); - voicing[i] = corX[i][ind_corX]; - move16(); - } - ELSE - { - pitch[i] = pitchX[i][ind]; - move16(); - voicing[i] = corX[i][ind]; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Increase the threshold for correlation reinforcement with - * the past if correlation high and pitch stable - *-----------------------------------------------------------------*/ - - /* all Q15 here */ - /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ - Ltmp = L_mult( voicing[0], 16384 ); - Ltmp = L_mac( Ltmp, voicing[1], 16384 ); - cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); - - /* pitch unstable in present frame or from previous frame or normalized correlation too low */ - coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); - move16(); - coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); - move16(); - - test(); - test(); - test(); - IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) - { - /* Reset the threshold */ - *old_thres = 0; - move16(); - } - ELSE - { - /* The threshold increase is directly dependent on normalized correlation */ - /* *old_thres += (0.16f * cor_mean); */ - *old_thres = round_fx( L_mac( L_deposit_h( *old_thres ), 5243, cor_mean ) ); - } - - *old_thres = s_min( *old_thres, THRES3 ); - move16(); - - IF( GT_16( voicing[1], voicing[0] ) ) - { - *old_corr = voicing[1]; - move16(); - } - ELSE - { - *old_corr = cor_mean; - move16(); - } - - /*-----------------------------------------------------------------* - * Extrapolate the pitch value for the next frame by estimating - * the pitch evolution. This value is added to the old_pitch - * in the next frame and is then used when the normalized - * correlation is reinforced by the past estimate - *-----------------------------------------------------------------*/ - tmp_buf[0] = *old_pitch; - move16(); - FOR( i = 0; i < NHFR; i++ ) - { - tmp_buf[i + 1] = pitch[i]; - move16(); - } - - *delta_pit = 0; - move16(); - cnt = 0; - move16(); - - FOR( i = 0; i < NHFR; i++ ) - { - diff = sub( tmp_buf[i + 1], tmp_buf[i] ); - move16(); - coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); - - if ( coh_flag != 0 ) - { - *delta_pit = add( *delta_pit, diff ); - move16(); - } - cnt = add( cnt, coh_flag ); - } - if ( EQ_16( cnt, 2 ) ) - { - /* *delta_pit /= 2; */ - *delta_pit = shr( *delta_pit, 1 ); - move16(); - } - IF( EQ_16( cnt, 3 ) ) - { - k = *delta_pit; - move16(); - /* *delta_pit /= 3; */ - if ( k < 0 ) - { - *delta_pit = mult( *delta_pit, -32768 ); - move16(); - } - tmp16 = mult( *delta_pit, 10923 ); - if ( k < 0 ) - { - tmp16 = mult( tmp16, -32768 ); - } - *delta_pit = tmp16; - move16(); - } - - /*--------------------------------------------------------------* - * Update old pitch, upsample pitch, - *--------------------------------------------------------------*/ - - *old_pitch = pitch[1]; - move16(); - - FOR( i = 0; i < NHFR; i++ ) - { - /* compensate decimation */ - pitch[i] = i_mult2( pitch[i], OPL_DECIM ); - move16(); - } -#endif return; } @@ -1417,11 +1144,7 @@ void pitch_ol_ivas_fx( Word16 qwsp /* i : Q factor for wsp Q0 */ ) { -#ifndef FIX_2403_COMBINE_PITCH_OL - Word16 ftmp, old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; -#else Word16 old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; -#endif Word16 tmp_mem[3]; Word16 scale1[2 * DELTA_COH - 1]; @@ -1431,22 +1154,6 @@ void pitch_ol_ivas_fx( Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4; Word16 *pt_cor0_exp, *pt_cor1_exp, *pt_cor2_exp, *pt_cor3_exp, *pt_cor4_exp; -#ifndef FIX_2403_COMBINE_PITCH_OL - Word16 thres1[6]; - Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; - Word16 ind_corX, ind1_corX; - - Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; - Word16 len_temp; - Word16 pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1]; - - Word16 enr0_exp[NSECT], enr0_1_exp[NSECT], enr1_exp; - Word32 enr0[NSECT], enr0_1[NSECT], enr1; - Word64 temp, temp1; - Word32 Ltmp; - Word16 fac, tmp16, tmp16_2; - Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; -#else Word16 cnt, ind, ind1, offset, offset1, offset_la, offset_la1; Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1; Word16 len_temp; @@ -1458,7 +1165,6 @@ void pitch_ol_ivas_fx( Word32 Ltmp; Word16 tmp16, tmp16_2; Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT]; -#endif const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; @@ -2128,259 +1834,7 @@ void pitch_ol_ivas_fx( } /* FOR j < NSECT */ } /* FOR i < NHFR */ -#ifdef FIX_2403_COMBINE_PITCH_OL pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, IVAS_SCE, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); /* any element mode other than EVS_MONO is OK here */ -#else - /*-----------------------------------------------------------------* - * Favor a smaller delay if it happens that it has its multiple - * in the longer-delay sections (harmonics check) - *-----------------------------------------------------------------*/ - - FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ - { - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - } - - fac = THRES0; - move16(); /* the look-ahead */ - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ - } - - /*-----------------------------------------------------------------* - * Do 1st estimate for pitch values - * Adjust the normalized correlation using estimated noise level - * Compute the maximum scaling for the neighbour correlation - * reinforcement - *-----------------------------------------------------------------*/ - add_sect0 = add( NSECT, sect0 ); - sub_sect0 = sub( NSECT, sect0 ); - FOR( i = 0; i < NHFR; i++ ) - { - /* 1st set of pitch candidates */ - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_tmp[i] = ind; - move16(); - pitch_tmp[i] = pitchX[i][ind]; - move16(); - cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); - move16(); - - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i] = mult( THRES1, cor_tmp[i] ); - move16(); - - /* 2nd set of pitch candidates */ - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind_tmp[i + NHFR] = ind1; - move16(); - pitch_tmp[i + NHFR] = pitchX[i][ind1]; - move16(); - cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); - move16(); - - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); - move16(); - } - /*-----------------------------------------------------------------* - * Take into account previous and next pitch values of the present - * frame and look-ahead. Choose the pitch lags and normalize - * correlations for each half-frame & look-ahead - *-----------------------------------------------------------------*/ - - pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); - FOR( i = 0; i < NHFR; i++ ) - { - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - - if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) - { - ind = ind1; - move16(); - } - test(); - if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) - { - ind_corX = ind1_corX; - move16(); - } - test(); - test(); - test(); - IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) - { - pitch[i] = pitchX[i][ind_corX]; - move16(); - voicing[i] = corX[i][ind_corX]; - move16(); - } - ELSE - { - pitch[i] = pitchX[i][ind]; - move16(); - voicing[i] = corX[i][ind]; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Increase the threshold for correlation reinforcement with - * the past if correlation high and pitch stable - *-----------------------------------------------------------------*/ - - /* all Q15 here */ - /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ - Ltmp = L_mult( voicing[0], 16384 /*.5 Q15*/ ); - Ltmp = L_mac( Ltmp, voicing[1], 16384 /*.5 Q15*/ ); - cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); - - /* pitch unstable in present frame or from previous frame or normalized correlation too low */ - coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); - move16(); - coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); - move16(); - - test(); - test(); - test(); - IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) - { - /* Reset the threshold */ - *old_thres = 0; - move16(); - } - ELSE - { - /* The threshold increase is directly dependent on normalized correlation */ - /* *old_thres += (0.16f * cor_mean); */ - *old_thres = round_fx( L_mac0( L_deposit_h( *old_thres ), 5243 /* 0.16f in Q15 */, cor_mean ) ); // Q14 - move16(); - } - - *old_thres = s_min( *old_thres, 11469 /* 0.7f in Q14 */ ); // Q14 - move16(); - - IF( GT_16( voicing[1], voicing[0] ) ) - { - *old_corr = voicing[1]; - move16(); - } - ELSE - { - *old_corr = cor_mean; - move16(); - } - - /*-----------------------------------------------------------------* - * Extrapolate the pitch value for the next frame by estimating - * the pitch evolution. This value is added to the old_pitch - * in the next frame and is then used when the normalized - * correlation is reinforced by the past estimate - *-----------------------------------------------------------------*/ - tmp_buf[0] = *old_pitch; - move16(); - FOR( i = 0; i < NHFR; i++ ) - { - tmp_buf[i + 1] = pitch[i]; - move16(); - } - - *delta_pit = 0; - move16(); - cnt = 0; - move16(); - - FOR( i = 0; i < NHFR; i++ ) - { - diff = sub( tmp_buf[i + 1], tmp_buf[i] ); - move16(); - coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); - - if ( coh_flag != 0 ) - { - *delta_pit = add( *delta_pit, diff ); - move16(); - } - cnt = add( cnt, coh_flag ); - } - if ( EQ_16( cnt, 2 ) ) - { - /* *delta_pit /= 2; */ - *delta_pit = shr( *delta_pit, 1 ); - move16(); - } - IF( EQ_16( cnt, 3 ) ) - { - k = *delta_pit; - move16(); - /* *delta_pit /= 3; */ - if ( k < 0 ) - { - *delta_pit = mult( *delta_pit, -32768 /*-1 Q15*/ ); - move16(); - } - tmp16 = mult( *delta_pit, 10923 /*1/3 Q15*/ ); - if ( k < 0 ) - { - tmp16 = mult( tmp16, -32768 /*-1 Q15*/ ); - } - *delta_pit = tmp16; - move16(); - } - - /*--------------------------------------------------------------* - * Update old pitch, upsample pitch, - *--------------------------------------------------------------*/ - - *old_pitch = pitch[1]; - move16(); - - FOR( i = 0; i < NHFR; i++ ) - { - /* compensate decimation */ - pitch[i] = i_mult2( pitch[i], OPL_DECIM ); - move16(); - } -#endif return; } -- GitLab From 6bedec5cb5530620c6f60286c351b2d7973405e9 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 20:59:36 +0100 Subject: [PATCH 09/20] [cleanup] accept FIX_2404_HARM_SIGNAL_CLAS --- lib_com/options.h | 1 - lib_enc/ivas_core_pre_proc_front_fx.c | 4 - lib_enc/prot_fx_enc.h | 11 -- lib_enc/sig_clas_fx.c | 235 -------------------------- 4 files changed, 251 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 186182ded..384d374c8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2404_HARM_SIGNAL_CLAS /* VA: basop-2404, harmonize signal_clas and signa_ivas_clas */ #define HARMONIZE_ACELP_ENC /* VA: basop issue 2400: Remove duplicated main ACELP encoder function */ #define FIX_2392_MSAN_DESTROY_DEC /* VA: basop issue 2392: fix MSAN in ivas_destroy_dec_fx() */ #define FIX_FLOAT_1522_LTV_MSAN_QMETADATA_ENC_EC3 /* Nokia: float issue 1522: fix uninit MSAN in EC3 of qmetadata encoding */ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 284bf3689..0b2bcb026 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1278,11 +1278,7 @@ void pre_proc_front_ivas_fx( * TC frame selection *-----------------------------------------------------------------*/ -#ifndef FIX_2404_HARM_SIGNAL_CLAS - st->clas = signal_clas_ivas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ -#else st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ -#endif move16(); select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index db08161e5..4a5cb60b5 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -503,17 +503,6 @@ Word16 signal_clas_fx( const Word16 L_look, /* i : look-ahead */ Word16 *uc_clas /* o : temporary classification used in music/speech class*/ ); -#ifndef FIX_2404_HARM_SIGNAL_CLAS -/* o : classification for current frames */ -Word16 signal_clas_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *speech, /* i : pointer to speech signal for E computation */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look, /* i : look-ahead */ - Word16 *uc_clas /* o : temporary classification used in music/speech class*/ -); -#endif void speech_music_classif_fx( Encoder_State *st, /* i/o: state structure */ diff --git a/lib_enc/sig_clas_fx.c b/lib_enc/sig_clas_fx.c index 19c17e404..86ba906eb 100644 --- a/lib_enc/sig_clas_fx.c +++ b/lib_enc/sig_clas_fx.c @@ -56,9 +56,7 @@ Word16 signal_clas_fx( Word16 i, clas, pc, zc, lo, lo2, hi, hi2, exp_ee, frac_ee; Word16 tmp16, tmpS; const Word16 *pt1; -#ifdef FIX_2404_HARM_SIGNAL_CLAS Word64 tmp64; -#endif Flag Overflow = 0; move32(); @@ -73,7 +71,6 @@ Word16 signal_clas_fx( Ltmp = L_mult( st->voicing_fx[1], 16384 ); /* Q15*Q14->Q30 */ mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 ); -#ifdef FIX_2404_HARM_SIGNAL_CLAS IF( st->element_mode != EVS_MONO ) { tmp64 = W_mult0_32_32( ee[0], ee[1] ); @@ -96,7 +93,6 @@ Word16 signal_clas_fx( } } ELSE -#endif { /* average spectral tilt in dB */ lo = L_Extract_lc( ee[0], &hi ); @@ -302,237 +298,6 @@ Word16 signal_clas_fx( return clas; } -#ifndef FIX_2404_HARM_SIGNAL_CLAS -Word16 signal_clas_ivas_fx( /* o : classification for current frames */ - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *speech, /* i : pointer to speech signal for E computation in Qx */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames in Q6 */ - const Word16 relE, /* i : frame relative E to the long term average in Q8 */ - const Word16 L_look, /* i : look-ahead */ - Word16 *clas_mod /* o : class flag for NOOP detection */ -) -{ - Word32 Ltmp; - Word16 mean_voi2, een, corn, zcn, relEn, pcn, fmerit1; - Word16 i, clas, pc, zc, exp_ee; - Word16 tmp16, tmpS; - const Word16 *pt1; - Word64 tmp64; - Flag Overflow = 0; - move32(); - - /*----------------------------------------------------------------* - * Calculate average voicing - * Calculate average spectral tilt - * Calculate zero-crossing rate - * Calculate pitch stability - *----------------------------------------------------------------*/ - - /* average voicing on second half-frame and look-ahead */ - Ltmp = L_mult( st->voicing_fx[1], 16384 ); /* Q15*Q14->Q30 */ - mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 ); - - /* average spectral tilt in dB */ - tmp64 = W_mult0_32_32( ee[0], ee[1] ); - exp_ee = W_norm( tmp64 ); - Ltmp = W_extract_h( W_shl( tmp64, exp_ee ) ); // Q = Q6+Q6 + exp_ee - 32 - exp_ee = sub( 31, sub( add( Q12, exp_ee ), 32 ) ); - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( Ltmp, exp_ee, ONE_IN_Q31, 0 ), -1 ) ) - { - een = 0; - move16(); - } - ELSE - { - /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */ - /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */ - Ltmp = BASOP_Util_Log10( Ltmp, exp_ee ); // Q25 - Ltmp = Mpy_32_32( Ltmp, 671088640 /*20.f in Q25*/ ); // Q25 + Q25 -Q31 = Q19 * 0.5 = Q20 - een = extract_l( L_shl( Mpy_32_16_1( Ltmp, K_EE_FX ), Q9 - Q20 ) ); // Q9 - - IF( GT_16( een, 512 ) ) - { - een = 512; - move16(); - } - ELSE IF( een < 0 ) - { - een = 0; - move16(); - } - } - /* compute zero crossing rate */ - pt1 = speech + sub( L_look, 1 ); - tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */ - Ltmp = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - tmp16 = add( 1, tmpS ); - pt1++; - tmpS = shr( *pt1, 15 ); /* pt1 >=0 ---> 0 OTHERWISE -1 */ - Ltmp = L_msu0( Ltmp, tmpS, tmp16 ); - } - zc = extract_l( Ltmp ); - - /* compute pitch stability */ - pc = add( abs_s( sub( st->pitch[1], st->pitch[0] ) ), abs_s( sub( st->pitch[2], st->pitch[1] ) ) ); - st->tdm_pc = pc; - move16(); - /*-----------------------------------------------------------------* - * Transform parameters to the range <0:1> - * Compute the merit function - *-----------------------------------------------------------------*/ - - /* corn = K_COR * mean_voi2 + C_COR */ - Ltmp = L_mult( C_COR_FX, 32767 ); - corn = round_fx( L_shl( L_mac( Ltmp, mean_voi2, K_COR_FX ), -4 ) ); /*Q13+Q13*Q15 =>Q13->Q9*/ - /* Limit [0, 1] */ - corn = s_max( corn, 0 ); - corn = s_min( corn, 512 ); - - Ltmp = L_mult( C_ZC_FX, 4 ); /*Q13*Q2 -> Q16*/ - zcn = round_fx( L_shl( L_mac( Ltmp, zc, K_ZC_FX ), 16 - 7 ) ); /*Q0*Q15 + Q16*/ - /* Limit [0, 1] */ - zcn = s_max( zcn, 0 ); - zcn = s_min( zcn, 512 ); - - Ltmp = L_mult( C_RELE_FX, 256 ); /*Q15*Q8 ->Q24*/ - relEn = round_fx( L_shl( L_mac( Ltmp, relE, K_RELE_FX ), 1 ) ); /*relE in Q8 but relEn in Q9*/ - /* Limit [0.5, 1] */ - relEn = s_max( relEn, 256 ); - relEn = s_min( relEn, 512 ); - - Ltmp = L_mult( C_PC_FX, 2 ); /*Q14*Q1 -> Q16*/ - pcn = round_fx( L_shl( L_mac( Ltmp, pc, K_PC_FX ), 16 - 7 ) ); /*Q16 + Q0*Q15*/ - /* Limit [0, 1] */ - pcn = s_max( pcn, 0 ); - pcn = s_min( pcn, 512 ); - - Ltmp = L_mult( een, 10923 ); - Ltmp = L_mac( Ltmp, corn, 21845 ); - Ltmp = L_mac( Ltmp, zcn, 10923 ); - Ltmp = L_mac( Ltmp, relEn, 10923 ); - Ltmp = L_mac( Ltmp, pcn, 10923 ); - - fmerit1 = round_fx_o( L_shl_o( Ltmp, 16 - 10 - 1, &Overflow ), &Overflow ); /* fmerit1 ->Q15 */ - - /*-----------------------------------------------------------------* - * FEC classification - *-----------------------------------------------------------------*/ - - st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); /*Q15*/ - move16(); - st->prev_fmerit = fmerit1; - move16(); - - /* FEC classification */ - test(); - test(); - IF( st->localVAD == 0 || EQ_16( st->coder_type, UNVOICED ) || LT_16( relE, -1536 ) ) - { - clas = UNVOICED_CLAS; - *clas_mod = clas; - move16(); - move16(); - } - ELSE - { - SWITCH( st->last_clas ) - { - case VOICED_CLAS: - case ONSET: - case VOICED_TRANSITION: - - IF( LT_16( fmerit1, 16056 ) ) /*0.49f*/ - { - clas = UNVOICED_CLAS; - move16(); - } - ELSE IF( LT_16( fmerit1, 21626 ) ) /*0.66*/ - { - clas = VOICED_TRANSITION; - move16(); - } - ELSE - { - clas = VOICED_CLAS; - move16(); - } - IF( LT_16( fmerit1, 14745 /* 0.45f*/ ) ) - { - *clas_mod = UNVOICED_CLAS; - move16(); - } - ELSE IF( LT_16( fmerit1, 21626 /* 0.66f*/ ) ) - { - *clas_mod = VOICED_TRANSITION; - move16(); - } - ELSE - { - *clas_mod = VOICED_CLAS; - move16(); - } - BREAK; - - case UNVOICED_CLAS: - case UNVOICED_TRANSITION: - IF( GT_16( fmerit1, 20643 ) ) /*0.63*/ - { - clas = ONSET; - move16(); - } - ELSE IF( GT_16( fmerit1, 19169 ) ) /*0.585*/ - { - clas = UNVOICED_TRANSITION; - move16(); - } - ELSE - { - clas = UNVOICED_CLAS; - move16(); - } - *clas_mod = clas; - move16(); - - BREAK; - - default: - clas = UNVOICED_CLAS; - *clas_mod = clas; - move16(); - move16(); - BREAK; - } - } - /* Onset classification */ - - /* tc_cnt == -1: frame after TC frame in continuous block of GC/VC frames */ - /* tc_cnt == 0: UC frame */ - /* tc_cnt == 1: onset/transition frame, coded by GC coder type */ - /* tc_cnt == 2: frame after onset/transition frame, coded by TC coder type */ - - if ( clas == 0 ) - { - st->tc_cnt = 0; - move16(); - } - - test(); - IF( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 ) - { - st->tc_cnt = add( st->tc_cnt, 1 ); - move16(); - } - - if ( GT_16( st->tc_cnt, 2 ) ) - { - st->tc_cnt = -1; - move16(); - } - return clas; -} -#endif /*-------------------------------------------------------------------* * select_TC_fx() -- GitLab From 27478a0dccf00223185181ef8422895f9ae006ff Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:00:18 +0100 Subject: [PATCH 10/20] [cleanup] accept HARMONIZE_ACELP_ENC --- lib_com/options.h | 1 - lib_com/prot_fx.h | 11 - lib_enc/acelp_core_enc_fx.c | 772 ------------------------------- lib_enc/decision_matrix_enc_fx.c | 2 - lib_enc/evs_enc_fx.c | 17 - lib_enc/ivas_core_enc_fx.c | 9 - lib_enc/pre_proc_fx.c | 8 - lib_enc/prot_fx_enc.h | 26 -- 8 files changed, 846 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 384d374c8..4f68ce73b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define HARMONIZE_ACELP_ENC /* VA: basop issue 2400: Remove duplicated main ACELP encoder function */ #define FIX_2392_MSAN_DESTROY_DEC /* VA: basop issue 2392: fix MSAN in ivas_destroy_dec_fx() */ #define FIX_FLOAT_1522_LTV_MSAN_QMETADATA_ENC_EC3 /* Nokia: float issue 1522: fix uninit MSAN in EC3 of qmetadata encoding */ #define OPT_2416_ACELP_FAST /* VA: basop issue 2426, optimisation of acelp_fast_fx ( reduc. compl. by 0.35 wmops ) */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 70ceda92e..136c96ed6 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10634,11 +10634,7 @@ ivas_error init_encoder_fx( const Word32 element_brate /* i : element bitrate */ ); -#ifdef HARMONIZE_ACELP_ENC ivas_error acelp_core_enc_fx( -#else -ivas_error acelp_core_enc_ivas_fx( -#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 inp[], /* i : input signal of the current frame Q_new*/ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ @@ -10651,19 +10647,12 @@ ivas_error acelp_core_enc_ivas_fx( Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ -#ifndef HARMONIZE_ACELP_ENC - Word16 *q_old_syn_12k8_16, /* o : Q factor of old_syn_12k8_16k[] */ -#endif Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits Q0*/ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ -#ifdef HARMONIZE_ACELP_ENC const Word16 Q_new, /* i : Scaling factor */ const Word16 shift /* i : Shift need to obtain 12 bits vectors */ -#else - const Word16 Q_new -#endif ); void flip_and_downmix_generic_fx32( diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 794aa6af9..537d60eba 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -20,663 +20,6 @@ *--------------------------------------------------------------------*/ ivas_error acelp_core_enc_fx( -#ifndef HARMONIZE_ACELP_ENC - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/ - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin Q6*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors Qx*/ - const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame Q15*/ - Word16 vad_hover_flag_fx, /* i : VAD hangover flag Q0*/ - const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn*/ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ - Word16 *unbits_fx, /* o : number of unused bits Q0*/ - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const Word16 Q_new, - const Word16 shift ) -{ - Word16 nBits; /* reserved bits */ - Word16 i; - Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ - Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ - Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ - Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ - Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ - Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ - Word16 Es_pred_fx; /* predicited scaled innovation energy */ - Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ - Word16 tc_subfr_fx, position; /* TC sub-frame indication */ - Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ - Word16 *bwe_exc_fx; /* excitation for SWB TBE */ - Word16 allow_cn_step_fx; - Word16 int_fs_fx; - Word32 L_epsP[2]; - /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - Word16 mCb1_fx, pstreaklen_fx; - Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; - Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2]; - Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; - Word16 nb_bits; - Word16 indice; - Word16 tmp16; - Word16 enr_index; - Word16 enr; - - Word16 tilt_code_bck_fx; - Word32 gc_threshold_bck_fx; - Word16 clip_var_bck_fx[6]; - Word16 next_force_sf_bck_fx; - Word32 q_env[NUM_ENV_CNG]; - Word16 sid_bw = -1; - Word16 coder_type; - Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_fx[L_FRAME16k]; - Word16 ppp_mode, nelp_mode; - Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - Word16 *tdm_Pri_pitch_buf; - Word16 uc_two_stage_flag; - Word16 att; - move16(); - - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - ivas_error error; - - error = IVAS_ERR_OK; - - (void) hStereoTD; - (void) ener_fx; - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - Es_pred_fx = 0; - move16(); - - coder_type = st_fx->coder_type; - move16(); - - exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // q_lpd_old_exc - - IF( hBWE_TD != NULL ) - { - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ - Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_exc - } - ELSE - { - bwe_exc_fx = NULL; - } - - st_fx->bpf_off = 0; - move16(); - test(); - test(); - test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || - EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) - { - /* in case of HQ->ACELP switching, do not apply BPF */ - st_fx->bpf_off = 1; - move16(); - if ( hGSCEnc != NULL ) - { - hGSCEnc->Last_frame_ener_fx = MAX_32; - move32(); - } - } - - /* force safety-net LSFQ in the first frames after CNG segment */ - if ( LE_32( st_fx->last_core_brate, SID_2k40 ) ) - { - st_fx->Nb_ACELP_frames = 0; - move16(); - } - st_fx->Nb_ACELP_frames = add_sat( st_fx->Nb_ACELP_frames, 1 ); // Q0 - move16(); - - int_fs_fx = INT_FS_16k_FX; - move16(); - if ( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - int_fs_fx = INT_FS_FX; - move16(); - } - - tmp_noise_fx = 0; - move16(); - tc_subfr_fx = -1; - move16(); - position = -1; - move16(); - - /* SC-VBR temporary variables */ - mCb1_fx = 0; //-> to be removed - move16(); - pstreaklen_fx = 0; - move16(); - clip_var_fx = 0; - move16(); - mem_w0_bck_fx = 0; - move16(); - streaklimit_fx = 0; - move16(); - - /* channel-aware mode */ - reset_rf_indices_fx( st_fx ); - /* VBR modes */ - IF( st_fx->Opt_SC_VBR ) - { - ppp_mode = hSC_VBR->ppp_mode; - nelp_mode = hSC_VBR->nelp_mode; - move16(); - move16(); - } - ELSE - { - ppp_mode = 0; - nelp_mode = 0; - move16(); - move16(); - } - - { - tdm_lp_reuse_flag = 0; - tdm_low_rate_mode = 0; - move16(); - move16(); - tdm_Pitch_reuse_flag = 0; - tdm_Pri_pitch_buf = NULL; - move16(); - move16(); - } - - /*-----------------------------------------------------------------* - * ACELP@12k8 / ACELP@16k switching - *-----------------------------------------------------------------*/ - test(); - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) - { - /* in case of switching, do not apply BPF */ - st_fx->bpf_off = 1; - move16(); - - /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */ - st_fx->Nb_ACELP_frames = 1; - move16(); - - /* convert old quantized LSP vector */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); // Q0 - move16(); - } - ELSE - { - st_fx->rate_switching_reset = st_fx->rate_switching_reset_16kHz; // Q0 - move16(); - Copy( st_fx->lsp_old16k_fx, st_fx->lsp_old_fx, M ); // Q15 - } - - /* convert old quantized LSF vector */ - lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs_fx ); - - /* interpolation of unquantized ISPs */ - IF( st_fx->rate_switching_reset ) - { - /*extrapolation in case of unstable LSP*/ - int_lsp4_fx( st_fx->L_frame, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); - } - ELSE - { - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); - } - - /* Reset LPC mem */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // x2.56 - set16_fx( st_fx->mem_MA_fx, 0, M ); - - /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); - Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // q_lpd_old_exc - Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); // q_mem_syn - Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); // q_mem_syn - - /* update Aw[] coefficients */ - weight_a_subfr_fx( shr( st_fx->L_frame, 6 ), A_fx, Aw_fx, st_fx->gamma, M ); - } - - test(); - test(); - if ( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->bwidth, NB ) && st_fx->ini_frame != 0 ) - { - st_fx->rate_switching_reset = 1; - move16(); - } - /*----------------------------------------------------------------* - * Encoding of CNG frames - *----------------------------------------------------------------*/ - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) - { - IF( EQ_16( st_fx->cng_type, LP_CNG ) ) - { - /* Run CNG post parameter update */ - cng_params_postupd_fx( hTdCngEnc->ho_circ_ptr, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, - hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx, EVS_MONO, -1 ); - - /* encode CNG parameters */ - CNG_enc_fx( st_fx, Aq_fx, inp_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); - - /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc_fx, exc2_fx, &hTdCngEnc->lp_ener_fx, st_fx->last_core_brate, - &hDtxEnc->first_CNG, &hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step_fx, &hTdCngEnc->last_allow_cn_step, sub( st_fx->prev_Q_new, 1 ), sub( Q_new, 1 ), hTdCngEnc->num_ho, - q_env, hTdCngEnc->lp_env_fx, hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); - } - ELSE - { - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - FdCng_encodeSID_fx( st_fx->hFdCngEnc, st_fx, st_fx->preemph_fac ); - hDtxEnc->last_CNG_L_frame = st_fx->L_frame; - move16(); - } - - generate_comfort_noise_enc_fx( st_fx, Q_new, 1 ); - - FdCng_exc( st_fx->hFdCngEnc->hFdCngCom, &hDtxEnc->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, - hDtxEnc->first_CNG, hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); - - Copy( exc2_fx, exc3_fx, st_fx->L_frame ); // Q12 - - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - IF( hTdCngEnc != NULL ) - { - enr = cng_energy_fx( st_fx->element_mode, st_fx->bwidth, hDtxEnc->CNG_mode, /*st_fx->hTdCngEnc->CNG_att*/ 0, exc_fx, st_fx->L_frame, Q_new ); // Q8 - - /* calculate the energy quantization index */ - enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ - enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ - - /* limit the energy quantization index */ - enr_index = s_min( enr_index, 127 ); // Q0 - enr_index = s_max( enr_index, 0 ); - - hTdCngEnc->old_enr_index = enr_index; /* Q0 */ - move16(); - } - } - } - /* Reset HO counter in the first SID frame */ - if ( hTdCngEnc != NULL ) - { - hTdCngEnc->burst_ho_cnt = 0; - move16(); - } - /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_new, st_fx->Q_syn ); - - /* reset the encoder */ - CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 0 ); - - /* update st->mem_syn1 for ACELP core switching */ - Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); - - /* update ACELP core synthesis filter memory */ - Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn1_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* st_fx->Q_syn */ - - IF( hBWE_FD != NULL ) - { - /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame, syn1_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); - } - /* Update MODE2 core switching memory */ - tmp16 = hLPDmem->syn[M]; - move16(); - E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &tmp16 ); - Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); /* st_fx->Q_syn */ - } - - /*----------------------------------------------------------------* - * Encoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - /*-----------------------------------------------------------------* - * Configure ACELP bit allocation - *-----------------------------------------------------------------*/ - - nb_bits = 0; - st_fx->acelp_cfg.FEC_mode = 0; - uc_two_stage_flag = 0; - move16(); - move16(); - move16(); - test(); - IF( !nelp_mode && !ppp_mode ) - { - config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - } - - /*-----------------------------------------------------------------* - * After inactive period, use the most up-to-date ISPs - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( st_fx->hDtxEnc != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) - { - Copy( hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M ); // Q15 - - lsp2lsf_fx( hDtxEnc->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx ); - } - - /*-----------------------------------------------------------------* - * Reset higher ACELP pre-quantizer in case of switching - *-----------------------------------------------------------------*/ - - IF( !st_fx->use_acelp_preq ) - { - st_fx->mem_deemp_preQ_fx = 0; - move16(); - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - } - - st_fx->use_acelp_preq = 0; - move16(); - - /*-----------------------------------------------------------------* - * LSF Quantization - * A[z] calculation - *-----------------------------------------------------------------*/ - - /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - lsf_syn_mem_backup_fx( st_fx, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, - lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx ); - - - if ( !tdm_lp_reuse_flag ) - { - lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, NULL, Q_new ); - } - - /*---------------------------------------------------------------* - * Calculation of LP residual (filtering through A[z] filter) - *---------------------------------------------------------------*/ - - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); - calculate_hangover_attenuation_gain_fx( st_fx, &att, vad_hover_flag_fx ); - v_multc_att( res_fx, att, res_fx, st_fx->L_frame ); - - /*-----------------------------------------------------------------* - * Determine TC subframe classification - *-----------------------------------------------------------------*/ - - IF( EQ_16( st_fx->coder_type, TRANSITION ) ) - { - tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch[0], res_fx ); - - config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - } - - /*---------------------------------------------------------------* - * Calculation of prediction for scaled innovation energy - * (for memory-less gain quantizer) - *---------------------------------------------------------------*/ - - IF( nb_bits > 0 ) - { - Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame, res_fx, st_fx->voicing_fx, nb_bits, 0, Q_new ); - push_indice( st_fx->hBstr, IND_ES_PRED, indice, nb_bits ); - } - - /*------------------------------------------------------------* - * Encode excitation according to coding type - *------------------------------------------------------------*/ - - test(); - test(); - IF( hSC_VBR->nelp_mode ) - { - /* SC-VBR - NELP frames */ - encod_nelp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, - voice_factors_fx, bwe_exc_fx, Q_new, shift ); - } - ELSE IF( EQ_16( coder_type, UNVOICED ) ) - { - /* UNVOICED frames (Gauss. excitation) */ - encod_unvoiced_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, - pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ); - } - ELSE IF( EQ_16( coder_type, TRANSITION ) ) - { - tc_subfr_fx = encod_tran_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr_fx, position, unbits_fx, shift, Q_new ); /* Q0 */ - } - ELSE IF( hSC_VBR->ppp_mode ) - { - IF( ( error = encod_ppp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) - { - return error; - } - - IF( hSC_VBR->bump_up ) /* PPP failed, bump up */ - { - /* restore memories of LSF quantizer and synthesis filter */ - lsf_syn_mem_restore_fx( st_fx, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, - lsp_mid_bck_fx, mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); - - /* Configure ACELP bit allocation */ - config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, st_fx->idchan, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - - /* redo LSF quantization */ - lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, 0, -1, NULL, Q_new ); - - /* recalculation of LP residual (filtering through A[z] filter) */ - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); - - hTdCngEnc->burst_ho_cnt = 0; - move16(); - /* VOICED frames in SC-VBR when bumped up*/ - encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); - } - } - ELSE IF( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_24k40 ) ) ) - { - /* AUDIO and INACTIVE frames (coded by GSC technology) */ - encod_audio_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, - attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); - } - ELSE - { - /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); - } - - /* update st->mem_syn1 for ACELP core switching */ - Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); /* q_mem_syn */ - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); - - /* save and delay synthesis to be used by SWB BWE */ - IF( hBWE_FD != NULL ) - { - save_old_syn_fx( st_fx->L_frame, syn_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); - } - /*Update MODE2 core switching memory*/ - Copy( syn_fx, syn1_fx, st_fx->L_frame ); // Q_syn - E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &hLPDmem->syn[M] ); - Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); // Q_syn - - /*--------------------------------------------------------------------------------------* - * Modify the excitation signal when the noise is stationary - *--------------------------------------------------------------------------------------*/ - - IF( NE_16( nelp_mode, 1 ) ) - { - L_epsP[0] = L_Comp( epsP_h_fx[2], epsP_l_fx[2] ); - move32(); - L_epsP[1] = L_Comp( epsP_h_fx[M], epsP_l_fx[M] ); - move32(); - Copy( exc_fx, exc2_fx, st_fx->L_frame ); // Q_new - stat_noise_uv_enc_fx( st_fx, L_epsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag, Q_new ); - } - - /*-----------------------------------------------------------------* - * Encode supplementary information for Frame Error Concealment - *-----------------------------------------------------------------*/ - - FEC_encode_fx( hBstr, st_fx->acelp_cfg, syn_fx, coder_type, st_fx->clas, pitch_buf_fx, res_fx, &st_fx->Last_pulse_pos, - st_fx->L_frame, st_fx->total_brate, Q_new, shift ); - - - IF( hBWE_TD != NULL ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 - } - ELSE - { - Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 - } - } - } /* end of active inp coding */ - - /*-----------------------------------------------------------------* - * Write ACELP unused bits - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( NE_32( st_fx->core_brate, SID_2k40 ) && NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, PPP_NELP_2k80 ) ) - { - /* reserved bits */ - nBits = st_fx->acelp_cfg.ubits; // Q0 - move16(); - - WHILE( nBits > 0 ) - { - i = s_min( nBits, 16 ); // Q0 - push_indice( st_fx->hBstr, IND_UNUSED, 0, i ); - nBits = sub( nBits, i ); // Q0 - } - } - - - /*-----------------------------------------------------------------* - * Apply non linearity in case of SWB TBE - *-----------------------------------------------------------------*/ - IF( hBWE_TD != NULL ) - { - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - - IF( ( EQ_16( st_fx->last_Opt_SC_VBR, 1 ) && st_fx->Opt_SC_VBR == 0 ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) ) - { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - - IF( !st_fx->Opt_SC_VBR ) - { - /* Apply a non linearity to the SHB excitation */ - non_linearity_fx( st_fx->element_mode, bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame ); - } - test(); - if ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) - { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - } - } - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - updt_enc_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); - - test(); - test(); - IF( hTdCngEnc != NULL && ( st_fx->Opt_DTX_ON != 0 ) && ( GT_32( st_fx->core_brate, SID_2k40 ) ) ) - { - /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, - Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate, EVS_MONO, -1 ); - - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st_fx->lsp_old16k_fx, &( hTdCngEnc->ho_lsp_circ2_fx[( hTdCngEnc->ho_circ_ptr ) * M] ), M ); // Q15 - } - - /* Set 16k LSP flag for CNG buffer */ - hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 0; - move16(); - if ( NE_16( st_fx->L_frame, L_FRAME ) ) - { - hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 1; - move16(); - } - - /* efficient DTX hangover control */ - IF( GT_16( hTdCngEnc->burst_ho_cnt, 1 ) ) - { - dtx_hangover_control_fx( st_fx, lsp_new_fx ); - } - } - - /* SC-VBR update of average data rate */ - test(); - IF( EQ_16( st_fx->vad_flag, 1 ) && ( hSC_VBR != NULL ) ) - { - update_average_rate_fx( hSC_VBR, st_fx->core_brate ); - } - - return error; -} - - -/*-------------------------------------------------------------------* - * acelp_core_enc_ivas_fx() - * - * ACELP core encoder - *--------------------------------------------------------------------*/ - -ivas_error acelp_core_enc_ivas_fx( -#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 inp[], /* i : input signal of the current frame Q_new*/ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ @@ -689,19 +32,12 @@ ivas_error acelp_core_enc_ivas_fx( Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ -#ifndef HARMONIZE_ACELP_ENC - Word16 *q_old_syn_12k8_16, /* o : Q factor of old_syn_12k8_16k[] */ -#endif Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits Q0*/ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ -#ifdef HARMONIZE_ACELP_ENC const Word16 Q_new, /* i : Scaling factor */ const Word16 shift /* i : Shift need to obtain 12 bits vectors */ -#else - const Word16 Q_new -#endif ) { Word16 i, nBits; /* reserved bits */ @@ -730,7 +66,6 @@ ivas_error acelp_core_enc_ivas_fx( Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer Q_new */ Word16 *bwe_exc_fx; /* excitation for SWB TBE Q_new */ -#ifdef HARMONIZE_ACELP_ENC /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ Word16 mCb1_fx, pstreaklen_fx; Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; @@ -742,18 +77,8 @@ ivas_error acelp_core_enc_ivas_fx( Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; Word16 ppp_mode, nelp_mode; Word16 enr, enr_index; -#else - set16_fx( old_bwe_exc_fx, 0, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); - set16_fx( old_exc_fx, 0, L_EXC ); - set16_fx( Aq, 0, NB_SUBFR16k * ( M + 1 ) ); - set16_fx( syn_fx, 0, L_FRAME16k ); -#endif Word32 q_env_fx[NUM_ENV_CNG]; -#ifndef HARMONIZE_ACELP_ENC - set32_fx( q_env_fx, 0, NUM_ENV_CNG ); - set16_fx( exc2_fx, 0, L_FRAME16k ); -#endif Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; Word16 *tdm_Pri_pitch_buf_fx; @@ -764,9 +89,7 @@ ivas_error acelp_core_enc_ivas_fx( hLPDmem = st->hLPDmem; -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode > EVS_MONO ) -#endif { test(); IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) @@ -820,11 +143,7 @@ ivas_error acelp_core_enc_ivas_fx( exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); /* Q_new */ -#ifdef HARMONIZE_ACELP_ENC set16_fx( old_exc_fx + L_EXC_MEM, 0, L_EXC - L_EXC_MEM ); -#else - Scale_sig( old_exc_fx, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); // Q_new -#endif IF( st->hBWE_TD != NULL ) { bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ @@ -881,7 +200,6 @@ ivas_error acelp_core_enc_ivas_fx( position = -1; move16(); -#ifdef HARMONIZE_ACELP_ENC /* SC-VBR temporary variables */ mCb1_fx = 0; move16(); @@ -912,7 +230,6 @@ ivas_error acelp_core_enc_ivas_fx( move16(); move16(); } -#endif test(); /* TD stereo */ @@ -1029,16 +346,13 @@ ivas_error acelp_core_enc_ivas_fx( &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho, q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO ); -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode > EVS_MONO ) -#endif { Scale_sig( exc_fx, st->L_frame, 1 ); // Q_new + 1 } } ELSE { -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { test(); @@ -1076,7 +390,6 @@ ivas_error acelp_core_enc_ivas_fx( } } ELSE -#endif { test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -1118,9 +431,6 @@ ivas_error acelp_core_enc_ivas_fx( { IF( st->hTdCngEnc != NULL ) { -#ifndef HARMONIZE_ACELP_ENC - Word16 enr, enr_index; -#endif enr = cng_energy_ivas_fx( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att_fx, exc_fx, st->L_frame, Q_new ); /* Q8 */ /* calculate the energy quantization index */ @@ -1144,14 +454,12 @@ ivas_error acelp_core_enc_ivas_fx( move16(); } -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { /* synthesis at 12.8kHz sampling rate */ syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_new, st->Q_syn ); } ELSE -#endif { Scale_sig( hLPDmem->mem_syn, M, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn Scale_sig( hLPDmem->mem_syn1_fx, M, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn @@ -1182,24 +490,17 @@ ivas_error acelp_core_enc_ivas_fx( /* save and delay synthesis to be used by SWB BWE */ IF( st->hBWE_FD != NULL ) { -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } ELSE -#endif { st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */ move16(); Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */ save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); -#ifdef HARMONIZE_ACELP_ENC Scale_sig( old_syn_12k8_16k, st->L_frame, sub( sub( Q_new, 1 ), st->Q_syn ) ); // Q_syn -#else - *q_old_syn_12k8_16 = st->Q_syn; - move16(); -#endif st->hBWE_FD->q_mem_deemph_old_syn = st->Q_syn; move16(); } @@ -1210,13 +511,11 @@ ivas_error acelp_core_enc_ivas_fx( move16(); /*Update MODE2 core switching memory*/ -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st->preemph_fac, st->L_frame, &hLPDmem->syn[M] ); } ELSE -#endif { deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); } @@ -1229,9 +528,7 @@ ivas_error acelp_core_enc_ivas_fx( ELSE { -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode > EVS_MONO ) -#endif { Word16 temp = getScaleFactor16( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k ); Scale_sig( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k, temp ); /* Q_last_exc_dct_in + temp */ @@ -1250,10 +547,8 @@ ivas_error acelp_core_enc_ivas_fx( uc_two_stage_flag = 0; move16(); -#ifdef HARMONIZE_ACELP_ENC test(); IF( !nelp_mode && !ppp_mode ) -#endif { config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } @@ -1293,11 +588,9 @@ ivas_error acelp_core_enc_ivas_fx( * A[z] calculation *-----------------------------------------------------------------*/ -#ifdef HARMONIZE_ACELP_ENC /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ lsf_syn_mem_backup_fx( st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, lsp_new, lsf_new_fx, lsp_mid, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx ); -#endif IF( !tdm_lp_reuse_flag ) { @@ -1416,31 +709,20 @@ ivas_error acelp_core_enc_ivas_fx( encod_gen_2sbfr_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); } } -#ifdef HARMONIZE_ACELP_ENC ELSE IF( nelp_mode ) { /* SC-VBR - NELP frames */ encod_nelp_fx( st, inp, Aw, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); } -#endif ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ -#ifdef HARMONIZE_ACELP_ENC encod_unvoiced_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); -#else - encod_unvoiced_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ); -#endif } ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { -#ifdef HARMONIZE_ACELP_ENC encod_tran_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new ); -#else - encod_tran_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, 0, Q_new ); -#endif } -#ifdef HARMONIZE_ACELP_ENC ELSE IF( ppp_mode ) { IF( ( error = encod_ppp_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) @@ -1470,24 +752,15 @@ ivas_error acelp_core_enc_ivas_fx( encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); } } -#endif ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ -#ifdef HARMONIZE_ACELP_ENC encod_audio_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, shift ); -#else - encod_audio_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); -#endif } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ -#ifdef HARMONIZE_ACELP_ENC encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); -#else - encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new ); -#endif } /* update mem_syn1_flt for ACELP core switching */ @@ -1495,37 +768,26 @@ ivas_error acelp_core_enc_ivas_fx( /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ Copy( syn_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); // hLPDmem->q_mem_syn -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode > EVS_MONO ) { Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, Q_new - 1 ) ); // Q_syn } -#else - Scale_sig( syn_fx, L_FRAME16k, sub( st->Q_syn, Q_new - 1 ) ); // Q_syn -#endif /* save and delay synthesis to be used by SWB BWE */ IF( st->hBWE_FD != NULL ) { -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } ELSE -#endif { st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) move16(); Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); -#ifdef HARMONIZE_ACELP_ENC Scale_sig( old_syn_12k8_16k, st->L_frame, sub( sub( Q_new, 1 ), st->Q_syn ) ); // Q_syn -#else - *q_old_syn_12k8_16 = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); - move16(); -#endif st->hBWE_FD->q_mem_deemph_old_syn = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); move16(); Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ) ); // st->Q_syn @@ -1539,13 +801,11 @@ ivas_error acelp_core_enc_ivas_fx( st->hLPDmem->q_lpd_syn = st->Q_syn; move16(); -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st->preemph_fac, st->L_frame, &hLPDmem->syn[M] ); } ELSE -#endif { deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); } @@ -1564,7 +824,6 @@ ivas_error acelp_core_enc_ivas_fx( * Modify the excitation signal when the noise is stationary *--------------------------------------------------------------------------------------*/ -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { IF( NE_16( nelp_mode, 1 ) ) @@ -1574,7 +833,6 @@ ivas_error acelp_core_enc_ivas_fx( } } ELSE -#endif { test(); test(); @@ -1593,13 +851,11 @@ ivas_error acelp_core_enc_ivas_fx( * Encode supplementary information for Frame Error Concealment *-----------------------------------------------------------------*/ -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { FEC_encode_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, Q_new, shift ); } ELSE -#endif { FEC_encode_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, add( st->Q_syn, 1 ), 0 ); } @@ -1650,13 +906,9 @@ ivas_error acelp_core_enc_ivas_fx( test(); test(); test(); -#ifdef HARMONIZE_ACELP_ENC test(); test(); IF( ( st->last_Opt_SC_VBR == 1 && st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) -#else - IF( ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) -#endif { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); @@ -1667,21 +919,15 @@ ivas_error acelp_core_enc_ivas_fx( test(); test(); test(); -#ifdef HARMONIZE_ACELP_ENC test(); IF( !st->Opt_SC_VBR && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) -#else - IF( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) -#endif { /* Apply a non linearity to the SHB excitation */ -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode == EVS_MONO ) { non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); } ELSE -#endif { Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); @@ -1701,42 +947,28 @@ ivas_error acelp_core_enc_ivas_fx( * Updates *-----------------------------------------------------------------*/ -#ifdef HARMONIZE_ACELP_ENC IF( st->element_mode > EVS_MONO ) -#endif { if ( st->hBWE_TD != NULL ) { st->Q_exc = Q_new; move16(); } -#ifdef HARMONIZE_ACELP_ENC hLPDmem->q_lpd_old_exc = Q_new; move16(); -#endif } updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx ); -#ifndef HARMONIZE_ACELP_ENC - st->hLPDmem->q_lpd_old_exc = Q_new; - move16(); -#endif test(); test(); IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && GT_32( st->core_brate, SID_2k40 ) ) { /* update CNG parameters in active frames */ -#ifdef HARMONIZE_ACELP_ENC Word16 q_exc = Q_new; move16(); IF( st->element_mode > EVS_MONO ) { -#endif -#ifndef HARMONIZE_ACELP_ENC - Word16 q_exc = st->hTdCngEnc->cng_Qexc_buf[0]; - move16(); -#endif FOR( i = 0; i < HO_HIST_SIZE; i++ ) { q_exc = s_min( q_exc, st->hTdCngEnc->cng_Qexc_buf[i] ); @@ -1750,9 +982,7 @@ ivas_error acelp_core_enc_ivas_fx( st->hTdCngEnc->cng_Qexc_buf[i] = q_exc; move16(); } -#ifdef HARMONIZE_ACELP_ENC } -#endif cng_params_upd_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); @@ -1781,14 +1011,12 @@ ivas_error acelp_core_enc_ivas_fx( } } -#ifdef HARMONIZE_ACELP_ENC /* SC-VBR update of average data rate */ test(); IF( EQ_16( st->vad_flag, 1 ) && ( st->hSC_VBR != NULL ) ) { update_average_rate_fx( st->hSC_VBR, st->core_brate ); } -#endif pop_wmops(); diff --git a/lib_enc/decision_matrix_enc_fx.c b/lib_enc/decision_matrix_enc_fx.c index ed6c09bb7..0bf5c8dfa 100644 --- a/lib_enc/decision_matrix_enc_fx.c +++ b/lib_enc/decision_matrix_enc_fx.c @@ -174,10 +174,8 @@ void decision_matrix_enc_fx( } } -#ifdef HARMONIZE_ACELP_ENC /* set inactive coder_type flag in ACELP core to GSC */ st_fx->inactive_coder_type_flag = 1; -#endif return; } diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index c282f1c4f..3dc01e782 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -43,10 +43,6 @@ ivas_error evs_enc_fx( Word32 ener; /* residual energy from Levinson-Durbin */ Word16 A[NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ -#ifndef HARMONIZE_ACELP_ENC - Word16 epsP_h[M + 1]; /* LP prediction errors */ - Word16 epsP_l[M + 1]; /* LP prediction errors */ -#endif Word32 epsP[M + 1]; /* LP prediction errors */ Word16 lsp_new[M]; /* LSPs at the end of the frame */ Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ @@ -176,18 +172,10 @@ ivas_error evs_enc_fx( *---------------------------------------------------------------------*/ #ifdef FIX_I4_OL_PITCH -#ifdef HARMONIZE_ACELP_ENC pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, -#else - pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, -#endif &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #else -#ifdef HARMONIZE_ACELP_ENC pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, pitch_orig, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, -#else - pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, -#endif &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #endif @@ -272,15 +260,10 @@ ivas_error evs_enc_fx( IF( EQ_16( st->core, ACELP_CORE ) ) { -#ifdef HARMONIZE_ACELP_ENC IF( NE_32( ( error = acelp_core_enc_fx( st, inp, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL, Q_new, shift ) ), IVAS_ERR_OK ) ) { return error; } -#else - acelp_core_enc_fx( st, inp, ener, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, vad_hover_flag, - attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, Q_new, shift ); -#endif } /*---------------------------------------------------------------------* diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 0abba7ce9..55956600d 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -301,19 +301,10 @@ ivas_error ivas_core_enc_fx( IF( st->core == ACELP_CORE ) { /* ACELP core encoder */ -#ifdef HARMONIZE_ACELP_ENC IF( NE_32( ( error = acelp_core_enc_fx( st, inp_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n], 0 ) ), IVAS_ERR_OK ) ) -#else - Word16 Q_old_syn_12k8_16k = 0; - move16(); - IF( NE_32( ( error = acelp_core_enc_ivas_fx( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ), IVAS_ERR_OK ) ) -#endif { return error; } -#ifndef HARMONIZE_ACELP_ENC - Scale_sig( old_syn_12k8_16k_fx[n], st->L_frame, sub( sub( Q_new[n], 1 ), Q_old_syn_12k8_16k ) ); // Q_old_syn_12k8_16k -> Q_new[n] - 1 -#endif } test(); diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 64b8b3089..32759eaf7 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -32,10 +32,6 @@ void pre_proc_fx( #endif Word16 A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ -#ifndef HARMONIZE_ACELP_ENC - Word16 epsP_h[M + 1], /* o : LP prediction errors */ - Word16 epsP_l[M + 1], /* o : LP prediction errors */ -#endif Word32 epsP[M + 1], /* o : LP prediction errors */ Word16 lsp_new[M], /* o : LSPs at the end of the frame */ Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ @@ -69,9 +65,7 @@ void pre_proc_fx( Word16 cor_map_sum, sp_div; /* speech/music clasif. parameters */ Word32 PS[128]; Word16 L_look; /* length of look-ahead */ -#ifdef HARMONIZE_ACELP_ENC Word16 epsP_h[M + 1], epsP_l[M + 1]; -#endif Word16 Q_sp_div, Q_esp; Word16 localVAD_HE_SAD; /* HE SAD parameters */ @@ -1346,12 +1340,10 @@ void pre_proc_fx( } } -#ifdef HARMONIZE_ACELP_ENC epsP[0] = L_Comp( epsP_h[2], epsP_l[2] ); move32(); epsP[1] = L_Comp( epsP_h[M], epsP_l[M] ); move32(); -#endif return; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 4a5cb60b5..bdd671d77 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -41,28 +41,6 @@ #include "ivas_stat_enc.h" -#ifndef HARMONIZE_ACELP_ENC -ivas_error acelp_core_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/ - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin Q6*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors Qx*/ - const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame 15*/ - Word16 vad_hover_flag_fx, /* i : VAD hangover flag Q0*/ - const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn*/ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ - Word16 *unbits_fx, /* o : number of unused bits Q0*/ - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const Word16 Q_new, - const Word16 shift ); -#endif void analy_lp_fx( const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ const Word16 L_frame, /* i :(q0) length of the frame */ @@ -3550,10 +3528,6 @@ void pre_proc_fx( #endif Word16 A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ -#ifndef HARMONIZE_ACELP_ENC - Word16 epsP_h[M + 1], /* o : LP prediction errors */ - Word16 epsP_l[M + 1], /* o : LP prediction errors */ -#endif Word32 epsP[M + 1], /* o : LP prediction errors */ Word16 lsp_new[M], /* o : LSPs at the end of the frame */ Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ -- GitLab From 4df2d6e0dec3185fe1bc3483ab5d3d690875cec7 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:00:51 +0100 Subject: [PATCH 11/20] [cleanup] accept FIX_2392_MSAN_DESTROY_DEC --- lib_com/options.h | 1 - lib_dec/lib_dec_fx.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 4f68ce73b..efa71d1d8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_2392_MSAN_DESTROY_DEC /* VA: basop issue 2392: fix MSAN in ivas_destroy_dec_fx() */ #define FIX_FLOAT_1522_LTV_MSAN_QMETADATA_ENC_EC3 /* Nokia: float issue 1522: fix uninit MSAN in EC3 of qmetadata encoding */ #define OPT_2416_ACELP_FAST /* VA: basop issue 2426, optimisation of acelp_fast_fx ( reduc. compl. by 0.35 wmops ) */ #define FIX_2410_HARM_MODIF_FS /* VA: basop issue 2410: Remove duplicated modif_Fs */ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 918e01f40..1d71a5613 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -337,9 +337,7 @@ static void init_decoder_config( ) { hDecoderConfig->Opt_AMR_WB = 0; -#ifdef FIX_2392_MSAN_DESTROY_DEC hDecoderConfig->output_Fs = -1; -#endif hDecoderConfig->nchan_out = 1; hDecoderConfig->output_config = IVAS_AUDIO_CONFIG_INVALID; hDecoderConfig->Opt_LsCustom = 0; @@ -357,9 +355,7 @@ static void init_decoder_config( hDecoderConfig->Opt_aeid_on = 0; hDecoderConfig->Opt_ObjEdit_on = 0; move16(); -#ifdef FIX_2392_MSAN_DESTROY_DEC move32(); -#endif move16(); move16(); move16(); -- GitLab From 14e730931700f9cbcda836302e30b153dbd0f490 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:01:30 +0100 Subject: [PATCH 12/20] [cleanup] accept FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT --- lib_com/options.h | 1 - lib_com/swb_tbe_com_fx.c | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index efa71d1d8..28e3d191c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT /* Dolby: Issue 2250: random vector generation in GenShapedSHBExcitation() */ #define FIX_2338_HARM_GSC_GAIN_COMP /* VA: basop issue 2338: harmonization of band gain computation for both EVS and IVAS */ #define FIX_BASOP_2361_OTR /* FhG: Basop issue 2361: Orientation tracking tests for equivalent rotations fail */ #define FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER /* FhG/VA: basop issue 2396: keep TC channel pointers in one constant place during decoding and rendering */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 3f962e16b..8a9aad1a6 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -6165,7 +6165,6 @@ void create_random_vector_fx( j and k values for any input (e.g. if Random() returns 5000) */ -#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT if ( element_mode != EVS_MONO ) { j = shr( abs_s( Random( &seed[0] ) ), 7 ); /* Random( &seed[0] * 0.0078125f ) */ @@ -6175,13 +6174,8 @@ void create_random_vector_fx( L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ j = extract_l( L_shr( L_tmp, 23 ) ); } -#else - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ - j = extract_l( L_shr( L_tmp, 23 ) ); -#endif j = s_and( j, 0xff ); -#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT if ( element_mode != EVS_MONO ) { k = shr( abs_s( Random( &seed[1] ) ), 7 ); /* Random( &seed[0] * 0.0078125f ) */ @@ -6191,16 +6185,11 @@ void create_random_vector_fx( L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ k = extract_l( L_shr( L_tmp, 23 ) ); } -#else - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ - k = extract_l( L_shr( L_tmp, 23 ) ); -#endif k = s_and( k, 0xff ); WHILE( EQ_16( k, j ) ) { -#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT if ( element_mode != EVS_MONO ) { k = shr( abs_s( Random( &seed[1] ) ), 7 ); @@ -6210,10 +6199,6 @@ void create_random_vector_fx( L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ k = extract_l( L_shr( L_tmp, 23 ) ); } -#else - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ - k = extract_l( L_shr( L_tmp, 23 ) ); -#endif k = s_and( k, 0xff ); } -- GitLab From 9369ec04a726581dc6237cdad03cc19fa8e97bc1 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:02:03 +0100 Subject: [PATCH 13/20] [cleanup] accept FIX_2338_HARM_GSC_GAIN_COMP --- lib_com/gs_gains_fx.c | 102 -------------------------------------- lib_com/gs_noisefill_fx.c | 42 +--------------- lib_com/options.h | 1 - lib_com/prot_fx.h | 10 ---- 4 files changed, 1 insertion(+), 154 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index c99b28bf7..fd26cf43d 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -189,108 +189,6 @@ void Comp_and_apply_gain_fx( return; #endif } -#ifndef FIX_2338_HARM_GSC_GAIN_COMP - - -void Comp_and_apply_gain_ivas_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ - Word16 Qexc_diff, - Word16 *Q_exc ) -{ - Word16 i, i_band; - Word16 StartBin, NB_Qbins; - Word16 y_gain; - Word16 L16, frac, exp1, tmp_exp; - Word32 L32; - Word16 Q_exc_diffQ[L_FRAME16k]; - - /* Recreate excitation for local synthesis and decoder */ - StartBin = 0; - move16(); - NB_Qbins = 0; - move16(); - - tmp_exp = add( 14, sub( *Q_exc, Qexc_diff ) ); /* In case of reuse, it can be computed outside the loop*/ - FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) - { - StartBin = add( StartBin, NB_Qbins ); - NB_Qbins = mfreq_bindiv_loc[i_band]; - move16(); - IF( EQ_16( ReUseGain, 1 ) ) - { - y_gain = Ener_per_bd_yQ[i_band]; /*Q13*/ - move16(); - - FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) - { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Q_exc+16-tmp_exp */ - exc_diffQ[i] = round_fx_sat( L32 ); /*Q_exc-tmp_exp */ - move16(); - IF( exc_diffQ[i] ) - { - Q_exc_diffQ[i] = sub( *Q_exc, tmp_exp ); - } - ELSE - { - Q_exc_diffQ[i] = *Q_exc; - } - move16(); - } - } - ELSE - { - /*-----------------------------------------------------------------* - * y_gain = pow(10.0, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) - * = pow(2, 3.321928*(Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) - *-----------------------------------------------------------------*/ - - L16 = sub_sat( Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band] ); /*Q12 */ - L32 = L_mult( L16, 27213 ); /* 3.321928 in Q13 -> Q26 */ - L32 = L_shr( L32, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L32, &exp1 ); /* Extract exponent of gcode0 */ - y_gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); /*Q13*/ - move16(); /*Q1 */ - tmp_exp = add( add( exp1, 1 ), sub( *Q_exc, Qexc_diff ) ); - - FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) - { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ - exc_diffQ[i] = round_fx_sat( L32 ); /*Q_exc-tmp_exp */ - move16(); - IF( exc_diffQ[i] ) - { - Q_exc_diffQ[i] = sub( *Q_exc, tmp_exp ); - } - ELSE - { - Q_exc_diffQ[i] = *Q_exc; - } - move16(); - } - } - } - - FOR( i = 0; i < StartBin + NB_Qbins; i++ ) - { - *Q_exc = s_min( *Q_exc, add( Q_exc_diffQ[i], norm_s( exc_diffQ[i] ) ) ); - move16(); - } - FOR( i = 0; i < StartBin + NB_Qbins; i++ ) - { - exc_diffQ[i] = shl( exc_diffQ[i], sub( *Q_exc, Q_exc_diffQ[i] ) ); /*Q_exc*/ - move16(); - } - - return; -} -#endif /*========================================================================*/ diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 0cc5b96c0..91c14675d 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -949,47 +949,7 @@ void highband_exc_dct_in_fx( move16(); } } -#if !defined FIX_2338_HARM_GSC_GAIN_COMP && !defined FIX_2380_HARM_GSC_GAIN_COMP_FX - IF( EQ_16( element_mode, EVS_MONO ) ) - { - Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); - - IF( exc_wo_nf != NULL ) - { - Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc ); - Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); - } - } - ELSE - { - Word16 Q_tmp = *Q_exc; - move16(); - Word16 Q_old = *Q_exc; - move16(); - Comp_and_apply_gain_ivas_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc ); - - IF( exc_wo_nf != NULL ) - { - Comp_and_apply_gain_ivas_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, &Q_tmp ); - IF( GT_16( Q_tmp, *Q_exc ) ) - { - Scale_sig( exc_wo_nf, L_frame, sub( *Q_exc, Q_tmp ) ); - } - ELSE IF( LT_16( Q_tmp, *Q_exc ) ) - { - Scale_sig( exc_diffQ, L_frame, sub( Q_tmp, *Q_exc ) ); - *Q_exc = Q_tmp; - move16(); - } - Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); - Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); - } - ELSE - { - Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); - } - } -#elif defined FIX_2380_HARM_GSC_GAIN_COMP_FX +#if defined FIX_2380_HARM_GSC_GAIN_COMP_FX Flag_adj_q_exc = 0; move16(); IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep all EVS BE */ diff --git a/lib_com/options.h b/lib_com/options.h index 28e3d191c..c3fda1f6b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2338_HARM_GSC_GAIN_COMP /* VA: basop issue 2338: harmonization of band gain computation for both EVS and IVAS */ #define FIX_BASOP_2361_OTR /* FhG: Basop issue 2361: Orientation tracking tests for equivalent rotations fail */ #define FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER /* FhG/VA: basop issue 2396: keep TC channel pointers in one constant place during decoding and rendering */ #define FIX_2408_FD_BWE_UPDATE /* VA: basop issue 2408: bug-fix in the FD BWE memory updates in wb_pre_proc_ivas_fx() */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 136c96ed6..968ceb380 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1698,16 +1698,6 @@ void Comp_and_apply_gain_fx( Word16 Qexc_diff, Word16 Q_exc ); -#ifndef FIX_2338_HARM_GSC_GAIN_COMP -void Comp_and_apply_gain_ivas_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ - Word16 Qexc_diff, - Word16 *Q_exc ); -#endif void pre_echo_att_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ -- GitLab From 38633f691f6463b29d09c38645f308ccf4043050 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:02:41 +0100 Subject: [PATCH 14/20] [cleanup] accept FIX_BASOP_2361_OTR --- lib_com/ivas_rotation_com_fx.c | 13 ------------ lib_com/options.h | 1 - lib_rend/ivas_orient_trk_fx.c | 31 ----------------------------- lib_util/vector3_pair_file_reader.c | 5 ----- 4 files changed, 50 deletions(-) diff --git a/lib_com/ivas_rotation_com_fx.c b/lib_com/ivas_rotation_com_fx.c index 5fc6261a9..27fdfb5a0 100644 --- a/lib_com/ivas_rotation_com_fx.c +++ b/lib_com/ivas_rotation_com_fx.c @@ -124,18 +124,11 @@ void modify_Quat_q_fx( Word16 q_new /* i : quaternion describing the rotation */ ) { -#ifdef FIX_BASOP_2361_OTR Word16 shift = sub( q_new, in_quat->q_fact ); out_quat->w_fx = L_shl_sat( in_quat->w_fx, shift ); // q_new out_quat->x_fx = L_shl_sat( in_quat->x_fx, shift ); // q_new out_quat->y_fx = L_shl_sat( in_quat->y_fx, shift ); // q_new out_quat->z_fx = L_shl_sat( in_quat->z_fx, shift ); // q_new -#else - out_quat->w_fx = L_shl_sat( in_quat->w_fx, sub( q_new, in_quat->q_fact ) ); // q_new - out_quat->x_fx = L_shl_sat( in_quat->x_fx, sub( q_new, in_quat->q_fact ) ); // q_new - out_quat->y_fx = L_shl_sat( in_quat->y_fx, sub( q_new, in_quat->q_fact ) ); // q_new - out_quat->z_fx = L_shl_sat( in_quat->z_fx, sub( q_new, in_quat->q_fact ) ); // q_new -#endif out_quat->q_fact = q_new; return; } @@ -155,19 +148,13 @@ void modify_Rmat_q_fx( ) { Word16 j, k; -#ifdef FIX_BASOP_2361_OTR Word16 shift = sub( q_new, q_cur ); -#endif FOR( j = 0; j < 3; j++ ) { FOR( k = 0; k < 3; k++ ) { -#ifdef FIX_BASOP_2361_OTR Rmat_out[j][k] = L_shl( Rmat_in[j][k], shift ); -#else - Rmat_out[j][k] = L_shl( Rmat_in[j][k], sub( q_new, q_cur ) ); -#endif move32(); } } diff --git a/lib_com/options.h b/lib_com/options.h index c3fda1f6b..8ef5b443e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_BASOP_2361_OTR /* FhG: Basop issue 2361: Orientation tracking tests for equivalent rotations fail */ #define FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER /* FhG/VA: basop issue 2396: keep TC channel pointers in one constant place during decoding and rendering */ #define FIX_2408_FD_BWE_UPDATE /* VA: basop issue 2408: bug-fix in the FD BWE memory updates in wb_pre_proc_ivas_fx() */ #define FIX_2380_HARM_GSC_GAIN_COMP_FX /* VA: basop issue 2380 & 2381: Fix issue when switching from CNG low energy to active content with high energy */ diff --git a/lib_rend/ivas_orient_trk_fx.c b/lib_rend/ivas_orient_trk_fx.c index 18fabc032..00d7f7da8 100644 --- a/lib_rend/ivas_orient_trk_fx.c +++ b/lib_rend/ivas_orient_trk_fx.c @@ -482,7 +482,6 @@ static Word32 VectorLength_fx( IVAS_VECTOR3 p, Word16 *q_fact ) { -#ifdef FIX_BASOP_2361_OTR Word16 sqrt_e; Word32 result_fx; result_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p.x_fx, p.x_fx ), p.y_fx, p.y_fx ), p.z_fx, p.z_fx ); @@ -490,13 +489,6 @@ static Word32 VectorLength_fx( result_fx = Sqrt32( result_fx, &sqrt_e ); *q_fact = sub( 31, sqrt_e ); /* back to Q again */ -#else - Word32 result_fx = 0; - move32(); - result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 - - *q_fact = sub( add( p.q_fact, p.q_fact ), 31 ); -#endif move16(); return result_fx; } @@ -712,14 +704,10 @@ ivas_error ivas_orient_trk_SetReferenceRotation_fx( Euler2Quat_fx( deg2rad_fx( refRot.x_fx ), deg2rad_fx( refRot.y_fx ), deg2rad_fx( refRot.z_fx ), &pOTR->refRot ); modify_Quat_q_fx( &pOTR->refRot, &pOTR->refRot, Q29 ); } -#ifdef FIX_BASOP_2361_OTR ELSE { -#endif pOTR->refRot = refRot; -#ifdef FIX_BASOP_2361_OTR } -#endif return IVAS_ERR_OK; } @@ -841,16 +829,8 @@ ivas_error ivas_orient_trk_SetReferenceVector_fx( return IVAS_ERR_WRONG_PARAMS; } -#ifdef FIX_BASOP_2361_OTR Word16 tmp_q; acousticFrontVectorLength = VectorLength_fx( acousticFrontVector, &tmp_q ); -#else - Word16 accoustic_q = acousticFrontVector.q_fact; - move16(); - acousticFrontVectorLength = VectorLength_fx( acousticFrontVector, &acousticFrontVector.q_fact ); - acousticFrontVector.q_fact = accoustic_q; - move16(); -#endif /* if the length is zero, the user has entered insensible listener and reference positions */ IF( LE_32( acousticFrontVectorLength, 0 ) ) { @@ -911,7 +891,6 @@ ivas_error ivas_orient_trk_Process_fx( /* Reset average orientation */ pOTR->absAvgRot = absRot; -#ifdef FIX_BASOP_2361_OTR Word16 scale_e; Word16 tmp; tmp = BASOP_Util_Divide3232_Scale( PI2_C_ADP_RATE_Q31, updateRate_fx, &scale_e ); @@ -922,16 +901,6 @@ ivas_error ivas_orient_trk_Process_fx( move32(); pOTR->Q_alpha = sub( Q31, scale_e ); move16(); -#else - Word16 scale_e; - Word32 div; - div = L_deposit_h( BASOP_Util_Divide3232_Scale( pOTR->centerAdaptationRate_fx, updateRate_fx, &scale_e ) ); - - scale_e = sub( scale_e, 8 ); // e+e1-e2// - // here div value is less so we can use sandwitch rule of sine// - pOTR->alpha_fx = div; - move32(); -#endif /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse_fx( pOTR->refRot, &pOTR->trkRot ); QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); diff --git a/lib_util/vector3_pair_file_reader.c b/lib_util/vector3_pair_file_reader.c index 27a21d21e..d2225b7f5 100644 --- a/lib_util/vector3_pair_file_reader.c +++ b/lib_util/vector3_pair_file_reader.c @@ -114,13 +114,8 @@ ivas_error Vector3PairFileReader_read( pSecond->y = y2; pSecond->z = z2; -#ifdef FIX_BASOP_2361_OTR pFirst->q_fact = 27; // Q27 pSecond->q_fact = 27; // Q27 -#else - pFirst->q_fact = 29; // Q29 - pSecond->q_fact = 29; // Q29 -#endif pFirst->x_fx = floatToFixed_32( pFirst->x, pFirst->q_fact ); pFirst->y_fx = floatToFixed_32( pFirst->y, pFirst->q_fact ); pFirst->z_fx = floatToFixed_32( pFirst->z, pFirst->q_fact ); -- GitLab From 7f8439ddd1038ed959fa2d593c637d022666190e Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:03:25 +0100 Subject: [PATCH 15/20] [cleanup] accept FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER --- lib_com/ivas_prot_fx.h | 18 ----------- lib_com/ivas_tools_fx.c | 62 ------------------------------------ lib_com/options.h | 1 - lib_dec/ivas_dec_render_fx.c | 23 ------------- lib_dec/lib_dec_fx.c | 8 ----- 5 files changed, 112 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ff6e48db0..ba65afec0 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2006,37 +2006,19 @@ UWord32 ivas_syn_output_fx( Word16 *synth_out /* o : integer 16 bits synthesis signal */ ); -#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER void ivas_buffer_interleaved_to_deinterleaved_fx( Word32 *audio_in, /* i : interleaved audio buffer */ Word32 *audio_out[], /* o : pointers to each channel of deinterleaved audio buffer */ const Word16 n_channels, /* i : number of channels */ const Word16 frame_length /* i : frame length (one channel) */ ); -#else -void ivas_buffer_interleaved_to_deinterleaved_fx( - Word32 *audio, /* i/o: audio buffer */ - const Word16 n_channels, /* i : number of channels */ - const Word16 frame_length, /* i : frame length (one channel) */ - const Word16 n_samp_full /* i : full frame length (one channel) */ -); -#endif -#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER void ivas_buffer_deinterleaved_to_interleaved_fx( Word32 *audio_in[], /* i : pointers to each channel of deinterleaved audio buffer */ Word32 *audio_out, /* o : interleaved audio buffer */ const Word16 n_channels, /* i : number of channels */ const Word16 frame_length /* i : frame length (one channel) */ ); -#else -void ivas_buffer_deinterleaved_to_interleaved_fx( - Word32 *audio[], /* i : deinterleaved audio buffer */ - const Word16 n_channels, /* i : number of channels */ - const Word16 frame_length, /* i : frame length (one channel) */ - Word32 *audio_out /* o : interleaved audio buffer */ -); -#endif void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ diff --git a/lib_com/ivas_tools_fx.c b/lib_com/ivas_tools_fx.c index fae273974..753c3ae29 100644 --- a/lib_com/ivas_tools_fx.c +++ b/lib_com/ivas_tools_fx.c @@ -160,7 +160,6 @@ UWord32 ivas_syn_output_fx( * Convert an interleaved buffer of audio channels to deinterleaved one *-------------------------------------------------------------------*/ -#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER void ivas_buffer_interleaved_to_deinterleaved_fx( Word32 *audio_in, /* i : interleaved audio buffer */ Word32 *audio_out[], /* o : pointers to each channel of deinterleaved audio buffer */ @@ -191,37 +190,6 @@ void ivas_buffer_interleaved_to_deinterleaved_fx( return; } -#else -void ivas_buffer_interleaved_to_deinterleaved_fx( - Word32 *audio, /* i/o: audio buffer */ - const Word16 n_channels, /* i : number of channels */ - const Word16 frame_length, /* i : frame length (one channel) */ - const Word16 n_samp_full /* i : full frame length (one channel) */ -) -{ - Word16 offset, ch, m; - Word32 buffer[MAX_TRANSPORT_CHANNELS][MAX_JBM_L_FRAME48k]; - - FOR( ch = 0; ch < n_channels; ch++ ) - { - FOR( m = 0; m < frame_length; m++ ) - { - buffer[ch][m] = audio[m * n_channels + ch]; - move32(); - } - } - - offset = 0; - move16(); - FOR( ch = 0; ch < n_channels; ch++ ) - { - Copy32( buffer[ch], audio + offset, frame_length ); - offset = add( offset, n_samp_full ); - } - - return; -} -#endif /*-------------------------------------------------------------------* @@ -230,7 +198,6 @@ void ivas_buffer_interleaved_to_deinterleaved_fx( * Convert a deinterleaved buffer of audio channels to interleaved one *-------------------------------------------------------------------*/ -#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER void ivas_buffer_deinterleaved_to_interleaved_fx( Word32 *audio_in[], /* i : pointers to each channel of deinterleaved audio buffer */ Word32 *audio_out, /* o : interleaved audio buffer */ @@ -261,35 +228,6 @@ void ivas_buffer_deinterleaved_to_interleaved_fx( return; } -#else -void ivas_buffer_deinterleaved_to_interleaved_fx( - Word32 *audio[], /* i/o: deinterleaved audio buffer */ - const Word16 n_channels, /* i : number of channels */ - const Word16 frame_length, /* i : frame length (one channel) */ - Word32 *audio_out /* o : interleaved audio buffer */ -) -{ - Word16 ch, m; - Word32 buffer[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; /* temp buffer needed when "*audio[]" and "*audio_out[]" are the same */ - - FOR( ch = 0; ch < n_channels; ch++ ) - { - Copy32( audio[ch], buffer[ch], frame_length ); - } - - - FOR( ch = 0; ch < n_channels; ch++ ) - { - FOR( m = 0; m < frame_length; m++ ) - { - audio_out[m * n_channels + ch] = buffer[ch][m]; - move32(); - } - } - - return; -} -#endif /*-------------------------------------------------------------------* diff --git a/lib_com/options.h b/lib_com/options.h index 8ef5b443e..0d927683f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER /* FhG/VA: basop issue 2396: keep TC channel pointers in one constant place during decoding and rendering */ #define FIX_2408_FD_BWE_UPDATE /* VA: basop issue 2408: bug-fix in the FD BWE memory updates in wb_pre_proc_ivas_fx() */ #define FIX_2380_HARM_GSC_GAIN_COMP_FX /* VA: basop issue 2380 & 2381: Fix issue when switching from CNG low energy to active content with high energy */ #define FIX_2406_FIX_GAIN_ON_INACTIVE /* VA: basop issue 2406: gain between 6.4 and 8kHz was too weak during inactive content with Fs=16kHz */ diff --git a/lib_dec/ivas_dec_render_fx.c b/lib_dec/ivas_dec_render_fx.c index 93e30218b..0e34d7570 100644 --- a/lib_dec/ivas_dec_render_fx.c +++ b/lib_dec/ivas_dec_render_fx.c @@ -83,12 +83,7 @@ void ivas_dec_feed_tc_to_renderer_fx( { Word32 tmp_buf_fx[MAX_JBM_L_FRAME48k]; Word32 *p_data_fx[FOA_CHANNELS + MAX_NUM_OBJECTS]; -#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER Word16 n, n_render_timeslots, n_ch_cldfb, ch; -#else - Word16 n, n_render_timeslots, n_ch_cldfb; - Word16 ch, offset, len_offset; -#endif DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; @@ -113,24 +108,6 @@ void ivas_dec_feed_tc_to_renderer_fx( n_ch_full_copy = s_min( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); n_ch_res_copy = sub( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); -#ifndef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER - /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]': - in case of 'length(hTcBuffer->tc[]) < length(p_output_f[])', reset of TC buffer - pointers is needed after ivas_buffer_interleaved_to_deinterleaved() */ - len_offset = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ); - IF( LT_16( len_offset, L_FRAME48k ) ) - { - offset = 0; - move16(); - FOR( ch = 0; ch < s_max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); ch++ ) - { - hTcBuffer->tc_fx[ch] = &hTcBuffer->tc_buffer_fx[offset]; - st_ivas->p_output_fx[ch] = hTcBuffer->tc_fx[ch]; - offset = add( offset, len_offset ); - } - } - -#endif FOR( ch = 0; ch < n_ch_full_copy; ch++ ) { Copy32( hTcBuffer->tc_fx[ch], tmp_buf_fx, nSamplesForRendering ); diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 1d71a5613..cbf282037 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -3930,11 +3930,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } /* convert deinterleaved decoded TC audio channels buffer to an interleaved one */ -#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER ivas_buffer_deinterleaved_to_interleaved_fx( st_ivas->p_output_fx, st_ivas->hTcBuffer->tc_buffer_fx, nTransportChannels, hIvasDec->nSamplesFrame ); -#else - ivas_buffer_deinterleaved_to_interleaved_fx( st_ivas->p_output_fx, nTransportChannels, hIvasDec->nSamplesFrame, st_ivas->hTcBuffer->tc_buffer_fx ); -#endif IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { @@ -3954,11 +3950,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( move16(); /* convert interleaved time-scaled TC audio channels buffer to deinterleaved one */ -#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER ivas_buffer_interleaved_to_deinterleaved_fx( st_ivas->hTcBuffer->tc_buffer_fx, st_ivas->p_output_fx, nTransportChannels, nSamplesTcsScaled ); -#else - ivas_buffer_interleaved_to_deinterleaved_fx( st_ivas->hTcBuffer->tc_buffer_fx, nTransportChannels, nSamplesTcsScaled, NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ) ); -#endif } else { -- GitLab From e52789e850baad3b41c0ca385beca8c8f0d52f3f Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:04:32 +0100 Subject: [PATCH 16/20] [cleanup] accept FIX_2408_FD_BWE_UPDATE --- lib_com/options.h | 1 - lib_enc/swb_pre_proc_fx.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0d927683f..d691a1f83 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2408_FD_BWE_UPDATE /* VA: basop issue 2408: bug-fix in the FD BWE memory updates in wb_pre_proc_ivas_fx() */ #define FIX_2380_HARM_GSC_GAIN_COMP_FX /* VA: basop issue 2380 & 2381: Fix issue when switching from CNG low energy to active content with high energy */ #define FIX_2406_FIX_GAIN_ON_INACTIVE /* VA: basop issue 2406: gain between 6.4 and 8kHz was too weak during inactive content with Fs=16kHz */ #define FIX_2407_FIX_RESIDU_IVAS /* VA: basop 2407, Implementation issue in residu_ivas + unnecessary complexity */ diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 6f8feb169..9e27f0d74 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -476,11 +476,7 @@ void wb_pre_proc_ivas_fx( test(); test(); test(); -#ifdef FIX_2408_FD_BWE_UPDATE IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && EQ_32( st_fx->extl_brate, 0 ) ) ) && !ppp_mode ) -#else - IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && EQ_32( st_fx->total_brate, 0 ) ) ) && !ppp_mode ) -#endif { Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); -- GitLab From 69ffef2d270f81ffdd7babdf9e81779194f455df Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:05:12 +0100 Subject: [PATCH 17/20] [cleanup] accept FIX_2380_HARM_GSC_GAIN_COMP_FX --- lib_com/gs_gains_fx.c | 14 -------------- lib_com/gs_noisefill_fx.c | 12 ------------ lib_com/options.h | 1 - lib_com/prot_fx.h | 6 ------ 4 files changed, 33 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index fd26cf43d..9a736b55f 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -70,19 +70,13 @@ static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const /* _ None */ /*========================================================================*/ -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX Word16 Comp_and_apply_gain_fx( -#else -void Comp_and_apply_gain_fx( -#endif Word16 exc_diffQ[], /* i/o: Quantized excitation */ Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ Word16 Mbands_gn, /* i : number of bands */ const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX const Word16 Flag_adj_q_exc, /* i : Flag allowing Q_exc adjustment */ -#endif Word16 Qexc_diff, Word16 Q_exc ) { @@ -90,11 +84,9 @@ void Comp_and_apply_gain_fx( Word16 StartBin, NB_Qbins; Word16 y_gain; Word16 L16, frac, exp1, tmp_exp; -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX Word16 Q_adapt; Word16 Q_exc_diffQ[L_FRAME16k]; Word32 exc_diffQ32[L_FRAME16k]; -#endif Word32 L32; /* Recreate excitation for local synthesis and decoder */ @@ -139,7 +131,6 @@ void Comp_and_apply_gain_fx( Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) ); -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX IF( Flag_adj_q_exc != 0 ) { FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) @@ -155,7 +146,6 @@ void Comp_and_apply_gain_fx( } } ELSE -#endif { FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { @@ -166,7 +156,6 @@ void Comp_and_apply_gain_fx( } } } -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX Q_adapt = Q_exc; move16(); test(); @@ -185,9 +174,6 @@ void Comp_and_apply_gain_fx( } } return Q_adapt; -#else - return; -#endif } diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 91c14675d..534f9edc2 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -683,9 +683,7 @@ void highband_exc_dct_in_fx( Word16 frac, exp, tmp1; Word16 tmp2; Word16 *end, Q_hb_exc; -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX Word16 Flag_adj_q_exc, old_Q_exc; -#endif FOR( j = 10; j < MBANDS_GN; j++ ) { @@ -949,7 +947,6 @@ void highband_exc_dct_in_fx( move16(); } } -#if defined FIX_2380_HARM_GSC_GAIN_COMP_FX Flag_adj_q_exc = 0; move16(); IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep all EVS BE */ @@ -967,15 +964,6 @@ void highband_exc_dct_in_fx( Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Flag_adj_q_exc, Qexc_diffQ, *Q_exc ); Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } -#else /* #if defined FIX_2338_HARM_GSC_GAIN_COMP */ - Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); - - IF( exc_wo_nf != NULL ) - { - Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc ); - Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); - } -#endif /*--------------------------------------------------------------------------------------* * add the correction layer to the LF bins, diff --git a/lib_com/options.h b/lib_com/options.h index d691a1f83..5240ce749 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2380_HARM_GSC_GAIN_COMP_FX /* VA: basop issue 2380 & 2381: Fix issue when switching from CNG low energy to active content with high energy */ #define FIX_2406_FIX_GAIN_ON_INACTIVE /* VA: basop issue 2406: gain between 6.4 and 8kHz was too weak during inactive content with Fs=16kHz */ #define FIX_2407_FIX_RESIDU_IVAS /* VA: basop 2407, Implementation issue in residu_ivas + unnecessary complexity */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 968ceb380..328eeae56 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1682,19 +1682,13 @@ void Ener_per_band_comp_ivas_fx( const Word16 L_frame /* i : frame length */ ); -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX Word16 Comp_and_apply_gain_fx( -#else -void Comp_and_apply_gain_fx( -#endif Word16 exc_diffQ[], /* i/o: Quantized excitation */ Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ Word16 Mbands_gn, /* i : number of bands */ const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX const Word16 Flag_adj_q_exc, /* i : Ener_per_bd_iQ of lt_ener_per_band_fx */ -#endif Word16 Qexc_diff, Word16 Q_exc ); -- GitLab From f55d58030039edf9d6609d1dae3674bbd5fbe854 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:05:44 +0100 Subject: [PATCH 18/20] [cleanup] accept FIX_2406_FIX_GAIN_ON_INACTIVE --- lib_com/gs_gains_fx.c | 4 ---- lib_com/options.h | 1 - 2 files changed, 5 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 9a736b55f..dd4660bba 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -342,11 +342,7 @@ static void GSC_gain_adj( } /*mimic ACELP decay of energy for low rates*/ -#ifndef FIX_2406_FIX_GAIN_ON_INACTIVE - FOR( i = 0; i < MBANDS_GN; i++ ) -#else FOR( i = 0; i < Mbands_gn; i++ ) -#endif { old_y_gain[i] = y_gain_tmp[i]; move16(); diff --git a/lib_com/options.h b/lib_com/options.h index 5240ce749..058465190 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2406_FIX_GAIN_ON_INACTIVE /* VA: basop issue 2406: gain between 6.4 and 8kHz was too weak during inactive content with Fs=16kHz */ #define FIX_2407_FIX_RESIDU_IVAS /* VA: basop 2407, Implementation issue in residu_ivas + unnecessary complexity */ /* ##################### End NON-BE switches ########################### */ -- GitLab From d6857152b045a0a3f7d9978794d3573630574628 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:06:27 +0100 Subject: [PATCH 19/20] [cleanup] accept FIX_2407_FIX_RESIDU_IVAS --- lib_com/options.h | 1 - lib_com/residu_fx.c | 17 ----------------- 2 files changed, 18 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 058465190..6f0d8e55e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,6 @@ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2407_FIX_RESIDU_IVAS /* VA: basop 2407, Implementation issue in residu_ivas + unnecessary complexity */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 7008b4cf0..d4de347d5 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -24,22 +24,6 @@ void residu_ivas_fx( const Word16 l /* i : size of filtering */ ) { -#ifndef FIX_2407_FIX_RESIDU_IVAS - Word32 s; - Word16 i, j; - - FOR( i = 0; i < l; i++ ) - { - s = x[i]; - move32(); - FOR( j = 1; j <= m; j++ ) - { - s = L_add( s, L_shl( Mpy_32_16_1( x[i - j], a[j] ), sub( Q15, a_exp ) ) ); // Qx - } - y[i] = s; - move32(); - } -#else Word64 s64; Word16 i, j, scaling; @@ -55,7 +39,6 @@ void residu_ivas_fx( move32(); } -#endif return; } -- GitLab From 9820c9174931ce04dc0d18a750a762de6837e391 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 10 Feb 2026 21:08:06 +0100 Subject: [PATCH 20/20] formatting --- lib_com/gs_gains_fx.c | 14 ++--- lib_com/gs_preech_fx.c | 4 +- lib_com/prot_fx.h | 75 +++++++++++++-------------- lib_com/tcx_utils_fx.c | 18 +++---- lib_com/tns_base.c | 17 +++--- lib_dec/acelp_core_dec_fx.c | 10 ++-- lib_dec/core_switching_dec_fx.c | 8 +-- lib_dec/hq_core_dec_fx.c | 2 +- lib_dec/ivas_tcx_core_dec_fx.c | 6 +-- lib_dec/swb_bwe_dec_fx.c | 4 +- lib_dec/swb_tbe_dec_fx.c | 2 +- lib_enc/acelp_core_enc_fx.c | 28 +++++----- lib_enc/enc_pit_exc_fx.c | 5 +- lib_enc/eval_pit_contr_fx.c | 1 - lib_enc/evs_enc_fx.c | 6 +-- lib_enc/gs_enc_fx.c | 8 ++- lib_enc/ivas_core_pre_proc_front_fx.c | 2 +- lib_enc/pre_proc_fx.c | 6 +-- lib_enc/prot_fx_enc.h | 19 ++++--- lib_enc/speech_music_classif_fx.c | 2 +- lib_enc/swb_tbe_enc_fx.c | 8 +-- 21 files changed, 118 insertions(+), 127 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index dd4660bba..c1654b433 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -71,11 +71,11 @@ static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const /*========================================================================*/ Word16 Comp_and_apply_gain_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 exc_diffQ[], /* i/o: Quantized excitation */ + Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ + Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ const Word16 Flag_adj_q_exc, /* i : Flag allowing Q_exc adjustment */ Word16 Qexc_diff, Word16 Q_exc ) @@ -227,8 +227,8 @@ void Ener_per_band_comp_fx( Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */ const Word16 Q_exc, /* i : frame length */ const Word16 Mband, /* i : Max band */ - const Word16 Eflag, /* i : flag of highest band */ - const Word16 L_frame /* i : frame length */ + const Word16 Eflag, /* i : flag of highest band */ + const Word16 L_frame /* i : frame length */ ) { const Word16 *pt_fx; diff --git a/lib_com/gs_preech_fx.c b/lib_com/gs_preech_fx.c index 5f2ab3b3e..3f7251041 100644 --- a/lib_com/gs_preech_fx.c +++ b/lib_com/gs_preech_fx.c @@ -56,8 +56,8 @@ void pre_echo_att_fx( const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, const Word16 last_coder_type, /* i : Last coding mode Q0*/ - const Word16 L_frame, /* i : Frame length Q0*/ - const Word16 element_mode /* i : Current IVAS element mode*/ + const Word16 L_frame, /* i : Frame length Q0*/ + const Word16 element_mode /* i : Current IVAS element mode*/ ) { Word32 etmp_fx; diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 328eeae56..49e042e2d 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1683,11 +1683,11 @@ void Ener_per_band_comp_ivas_fx( ); Word16 Comp_and_apply_gain_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 exc_diffQ[], /* i/o: Quantized excitation */ + Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ + Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ const Word16 Flag_adj_q_exc, /* i : Ener_per_bd_iQ of lt_ener_per_band_fx */ Word16 Qexc_diff, Word16 Q_exc ); @@ -2441,7 +2441,7 @@ Word32 Interpol_lc_fx( #ifndef FIX_2410_HARM_MODIF_FS Word16 modify_Fs_ivas_fx( /* o : length of output Q0 */ #else -Word16 modify_Fs_fx( /* o : length of output Q0 */ +Word16 modify_Fs_fx( /* o : length of output Q0 */ #endif const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ Word16 lg, /* i : length of input Q0 */ @@ -4061,15 +4061,14 @@ void tcx_noise_filling_with_shift( ); -void InitTnsConfigs_fx - ( - const Word16 bwidth, - const Word16 L_frame, - STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ); +void InitTnsConfigs_fx( + const Word16 bwidth, + const Word16 L_frame, + STnsConfig tnsConfig[2][2], + const Word16 igfStopFreq, + const Word32 total_brate, + const Word16 element_mode, + const Word16 is_mct ); void SetAllowTnsOnWhite( STnsConfig tnsConfig[2][2], @@ -5567,7 +5566,7 @@ void fb_tbe_dec_fx( 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 */ + Word32 *hb_synth, /* o : high-band synthesis */ Word16 hb_synth_exp, Word16 *fb_synth_ref, Word16 Q_fb_synth_ref, @@ -7325,10 +7324,10 @@ ivas_error core_switching_pre_dec_fx( Word16 *Q_olapBufferSynth2 ); ivas_error core_switching_post_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth*/ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ - Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth*/ + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -9877,10 +9876,10 @@ Word16 swb_bwe_dec_fx32( ); ivas_error acelp_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ - Word16 synth_fx16[], /* o : synthesis */ - Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ + Word16 synth_fx16[], /* o : synthesis */ + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ Word16 *voice_factors_fx, /* o : voicing factors */ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ @@ -10619,24 +10618,24 @@ ivas_error init_encoder_fx( ); ivas_error acelp_core_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 inp[], /* i : input signal of the current frame Q_new*/ - Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ - Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/ - const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ - const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 inp[], /* i : input signal of the current frame Q_new*/ + Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ + const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ + Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ + Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits Q0*/ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ - const Word16 Q_new, /* i : Scaling factor */ - const Word16 shift /* i : Shift need to obtain 12 bits vectors */ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift need to obtain 12 bits vectors */ ); void flip_and_downmix_generic_fx32( diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 69914bf66..7caf1b778 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -1973,16 +1973,14 @@ void tcx_noise_filling_with_shift( *--------------------------------------------------------------*/ - -void InitTnsConfigs_fx - ( - const Word16 bwidth, /*Q0*/ - const Word16 L_frame, /*Q0*/ - STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, /*Q0*/ - const Word32 total_brate, /*Q0*/ - const Word16 element_mode, /*Q0*/ - const Word16 MCT_flag /*Q0*/ ) +void InitTnsConfigs_fx( + const Word16 bwidth, /*Q0*/ + const Word16 L_frame, /*Q0*/ + STnsConfig tnsConfig[2][2], + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 MCT_flag /*Q0*/ ) { IF( GT_32( total_brate, ACELP_32k ) ) { diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 1a491bfd8..fe6f5d8ef 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -73,15 +73,14 @@ static void ITF_GetFilterParameters_fx( Word32 rxx[], const Word16 maxOrder, Wor /********************************/ -void InitTnsConfiguration_fx - ( - const Word16 bwidth, /*Q0*/ - const Word16 frameLength, /*Q0*/ - STnsConfig *pTnsConfig, - const Word16 igfStopFreq, /*Q0*/ - const Word32 total_brate, /*Q0*/ - const Word16 element_mode, /*Q0*/ - const Word16 is_mct /*Q0*/ ) +void InitTnsConfiguration_fx( + const Word16 bwidth, /*Q0*/ + const Word16 frameLength, /*Q0*/ + STnsConfig *pTnsConfig, + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 is_mct /*Q0*/ ) { Word16 iFilter = 0; move16(); diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 5838fae17..7b06d4b0d 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -52,10 +52,10 @@ *-------------------------------------------------------------------*/ ivas_error acelp_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ - Word16 synth_fx16[], /* o : synthesis Q_syn2*/ - Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ + Word16 synth_fx16[], /* o : synthesis Q_syn2*/ + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ @@ -2191,7 +2191,7 @@ ivas_error acelp_core_dec_fx( } /* Copy output signal */ - Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 Copy_Scale_sig_16_32_no_sat( psyn_fx, output_fx32, st->L_frame, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index dabb48fcb..b8f4cc63f 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -213,10 +213,10 @@ void bw_switching_pre_proc_fx( *---------------------------------------------------------------------*/ ivas_error core_switching_post_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth*/ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ - Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth*/ + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index f3517891a..8a8ee0236 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -468,7 +468,7 @@ void ivas_hq_core_dec_fx( const Word16 output_frame, /* i : output frame length Q0*/ const Word16 hq_core_type, /* i : HQ core type Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ - Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index f317320aa..4a57618e5 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -188,9 +188,9 @@ void stereo_tcx_init_dec_fx( *-------------------------------------------------------------------*/ void stereo_tcx_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const FRAME_MODE frameMode, /* i : Decoder frame mode */ - Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11*/ + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ + Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11*/ Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0*/ Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6*/ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index f028824e9..f7c6e8c16 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -359,8 +359,8 @@ Word16 wb_bwe_dec_fx( #else Word16 ivas_wb_bwe_dec_fx( #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 3c92eaa12..60f22396e 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3786,7 +3786,7 @@ void fb_tbe_dec_fx( 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) */ + 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, diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 537d60eba..2168e0e3a 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -20,24 +20,24 @@ *--------------------------------------------------------------------*/ ivas_error acelp_core_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 inp[], /* i : input signal of the current frame Q_new*/ - Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ - Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/ - const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ - const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 inp[], /* i : input signal of the current frame Q_new*/ + Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ + const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ + Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ + Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits Q0*/ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ - const Word16 Q_new, /* i : Scaling factor */ - const Word16 shift /* i : Shift need to obtain 12 bits vectors */ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift need to obtain 12 bits vectors */ ) { Word16 i, nBits; /* reserved bits */ diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 1ec7eac72..f93919b50 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -81,8 +81,8 @@ void enc_pit_exc_fx( Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ Word16 clip_gain, i; /* LSF clip gain and LP flag */ const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 cn[PIT_EXC_L_SUBFR]; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ - Word16 *pt_pitch; /* pointer to floating pitch */ + Word16 cn[PIT_EXC_L_SUBFR]; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ + Word16 *pt_pitch; /* pointer to floating pitch */ Word16 L_subfr; Word16 cum_gpit, gpit_tmp; Word32 Local_BR, Pitch_BR; @@ -589,4 +589,3 @@ void enc_pit_exc_fx( return; } - diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index c3505bfa1..b9c56e401 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -424,4 +424,3 @@ Word16 Pit_exc_contribution_len_fx( return last_pit_bin; } - diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 3dc01e782..8133da6e5 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -43,9 +43,9 @@ ivas_error evs_enc_fx( Word32 ener; /* residual energy from Levinson-Durbin */ Word16 A[NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ - Word32 epsP[M + 1]; /* LP prediction errors */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ + Word32 epsP[M + 1]; /* LP prediction errors */ + Word16 lsp_new[M]; /* LSPs at the end of the frame */ + Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ Word16 vad_hover_flag; Word16 hq_core_type; /* HQ core type (HQ, or LR-MDCT) */ diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 0af00565e..9f140f843 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -468,10 +468,9 @@ void gsc_enc_fx( const Word16 bits_used, const Word16 nb_subfr, const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ - Word16 *tmp_noise, /* o : noise energy Q2*/ - Word16 *Q_exc -) + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ + Word16 *tmp_noise, /* o : noise energy Q2*/ + Word16 *Q_exc ) { Word16 y2_filt[L_FRAME16k]; Word16 exc_diffQ[L_FRAME16k]; @@ -759,7 +758,6 @@ void gsc_enc_fx( } - /*======================================================================*/ /* FUNCTION : edyn_fx() */ /*----------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 0b2bcb026..44f57cf56 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1278,7 +1278,7 @@ void pre_proc_front_ivas_fx( * TC frame selection *-----------------------------------------------------------------*/ - st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ + st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ move16(); select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 32759eaf7..f29d734ff 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -32,9 +32,9 @@ void pre_proc_fx( #endif Word16 A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - Word32 epsP[M + 1], /* o : LP prediction errors */ - Word16 lsp_new[M], /* o : LSPs at the end of the frame */ - Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ + Word32 epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new[M], /* o : LSPs at the end of the frame */ + Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ Word16 *vad_hover_flag, Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index bdd671d77..d6b13aa6e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -779,11 +779,10 @@ void gsc_enc_fx( const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 *tmp_noise, /* o : noise energy */ - Word16 *Q_exc -); + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 *tmp_noise, /* o : noise energy */ + Word16 *Q_exc ); void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ @@ -1057,7 +1056,7 @@ void coder_type_modif_fx( ); void speech_music_clas_init_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ); @@ -3528,9 +3527,9 @@ void pre_proc_fx( #endif Word16 A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - Word32 epsP[M + 1], /* o : LP prediction errors */ - Word16 lsp_new[M], /* o : LSPs at the end of the frame */ - Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ + Word32 epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new[M], /* o : LSPs at the end of the frame */ + Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ Word16 *vad_hover_flag, Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ Word16 *new_inp_resamp16k, /* o : new i signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ @@ -3876,7 +3875,7 @@ void noise_est_init_ivas_fx( void InitSWBencBuffer_fx( const Word16 element_mode, /* i : element mode */ - TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); void ResetSHBbuffer_Enc_fx( diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 5218fb42f..2f184957a 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -76,7 +76,7 @@ static void detect_sparseness_fx( Encoder_State *st_fx, const Word16 localVAD_HE *---------------------------------------------------------------------*/ void speech_music_clas_init_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 5e2043263..6f270929b 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -380,7 +380,7 @@ static void rescale_genWB_mem_enc( void InitSWBencBuffer_fx( const Word16 element_mode, /* i : element mode */ - TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { Word16 i; @@ -3923,7 +3923,7 @@ void swb_tbe_enc_ivas_fx( /*--------------------------------------------------------------------------*/ static void EstimateSHBFrameGain_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ 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 arget original SHB frame */ @@ -4825,8 +4825,8 @@ static void Quant_shb_ener_sf_fx( /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12/Q11+Q13+1 = Q26/Q25 */ - L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ move32(); -- GitLab