diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 88e9f41d46bea75e5f37656e55e711c7b9b05f8f..87aa64ec8c2de2ebcd9a6f74a617b06d2381ab79 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -260,21 +260,24 @@ void Comp_and_apply_gain_ivas_fx( /* _ None */ /*========================================================================*/ -static Word16 Comp_band_log_ener( /* o : Band gain Q12 */ - const Word16 *pt_fx, /* i : Dct input Q_sc */ - const Word16 Len, /* i : Lenght en energy accumulation */ - const Word16 Q_sc, /* i : scaling of input */ - const Word16 E_sc /* i : Additional scaling factor for energy */ +/* o : Band gain Q12 */ +static Word16 Comp_band_log_ener( + const Word16 *pt_fx, /* i : Dct input Q_sc */ + const Word16 Len, /* i : Lenght en energy accumulation */ + const Word16 Q_sc, /* i : scaling of input */ + const Word16 E_sc /* i : Additional scaling factor for energy */ ) { Word32 L_tmp; Word16 e_tmp, f_tmp, tmp16, ener_exp; + L_tmp = Calc_Energy_Autoscaled( pt_fx, Q_sc, Len, &ener_exp ); e_tmp = norm_l( L_tmp ); f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); e_tmp = sub( sub( add( 30, E_sc ), e_tmp ), ener_exp ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 19728 ); /* Q16 */ /*log10(2) in Q17 */ tmp16 = round_fx( L_shl( L_tmp, 12 - 2 ) ); /* Q12 -1 is to compensate Q17 */ + return tmp16; } @@ -283,7 +286,12 @@ 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 */ +#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; @@ -311,9 +319,19 @@ 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*/ + move16(); + 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 */ @@ -359,6 +377,7 @@ void Ener_per_band_comp_ivas_fx( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 0829a934dcef39340f470260e9066e54aecbed4f..a8d2aa6823f103230af4c50772b1ca28b17379b4 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -77,7 +77,11 @@ 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++ ) @@ -91,7 +95,11 @@ 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++ ) @@ -104,7 +112,12 @@ 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 8489cd66de0015dd76d4f18bb75c3861a077fb21..a23ddb3433b3ea55a65486f5eb012e196398aa17 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -636,7 +636,7 @@ 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 */ @@ -801,12 +801,19 @@ void highband_exc_dct_in_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_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++ ) @@ -1010,8 +1017,14 @@ void highband_exc_dct_in_fx( 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 */ @@ -1168,19 +1181,29 @@ void highband_exc_dct_in_ivas_fx( { 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_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 ) ) @@ -1195,9 +1218,11 @@ void highband_exc_dct_in_ivas_fx( } } } + /*--------------------------------------------------------------------------------------* * Check potential energy excitation overshoot *--------------------------------------------------------------------------------------*/ + IF( bfi ) { test(); diff --git a/lib_com/gs_preech_fx.c b/lib_com/gs_preech_fx.c index 083f0d9ca636d684750d84b7c0e2bb9f208676e2..28092088e19351a9701a3282a4813901c58469a4 100644 --- a/lib_com/gs_preech_fx.c +++ b/lib_com/gs_preech_fx.c @@ -56,7 +56,12 @@ 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*/ +#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; @@ -68,7 +73,9 @@ 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 */ { @@ -107,33 +114,53 @@ 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 */ - L_tmp = sum32_fx( finc_fx, attack_pos_fx ); /*Q1 */ - L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */ - tmp = round_fx( Isqrt( L_tmp1 ) ); /*Q15 */ - L_tmp = L_shr( L_tmp, 2 ); /*Q1 ; ATT_SEG_LEN=4 */ - etmp_fx = Mult_32_16( L_tmp, tmp ); /*Q1 */ - - etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */ - /* Find the correction factor and apply it before the attack */ - /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/ - /* = isqrt(etmp/(*Last_frame_ener)) */ - etmp_fx = L_max( etmp_fx, 1 ); - *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 ); - move32(); - n1 = norm_l( etmp_fx ); - n2 = norm_l( *Last_frame_ener_fx ); - - n1 = sub( n1, 1 ); - exp = sub( n1, n2 ); - - frac1 = round_fx( L_shl( etmp_fx, n1 ) ); - frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) ); - L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */ - L_tmp = L_shr( L_tmp, exp ); /* add exponent */ - - L_tmp = Isqrt( L_tmp ); - ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */ +#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 ); + 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 */ + } + 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 */ + tmp = round_fx( Isqrt( L_tmp1 ) ); /*Q15 */ + L_tmp = L_shr( L_tmp, 2 ); /*Q1 ; ATT_SEG_LEN=4 */ + etmp_fx = Mult_32_16( L_tmp, tmp ); /*Q1 */ + + etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */ + /* Find the correction factor and apply it before the attack */ + /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/ + /* = isqrt(etmp/(*Last_frame_ener)) */ + etmp_fx = L_max( etmp_fx, 1 ); + *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 ); + move32(); + n1 = norm_l( etmp_fx ); + n2 = norm_l( *Last_frame_ener_fx ); + + n1 = sub( n1, 1 ); + exp = sub( n1, n2 ); + + frac1 = round_fx( L_shl( etmp_fx, n1 ) ); + frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) ); + L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */ + L_tmp = L_shr( L_tmp, exp ); /* add exponent */ + + L_tmp = Isqrt( L_tmp ); + ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* 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++ ) @@ -152,16 +179,32 @@ void pre_echo_att_fx( * In normal cases, just compute the energy of the frame *-------------------------------------------------------*/ - 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*/ - *Last_frame_ener_fx = etmp_fx; - move32(); /*2*Q_new+1*/ +#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 ); + 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*/ + } + 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*/ + *Last_frame_ener_fx = etmp_fx; + move32(); /*2*Q_new+1*/ + } } 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*/ @@ -266,3 +309,4 @@ void pre_echo_att_ivas_fx( return; } +#endif diff --git a/lib_com/options.h b/lib_com/options.h index 640bd4a74f87f4a289867c5ada7f964df94eef50..5e8a08b81622f9324e5c7de4553187075730025b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -100,6 +100,7 @@ #define FIX_2274_OOB_INDEXING_IN_CORRMATRIX /* FhG: fix OOB indexing complaint */ #define FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH /* FhG: fix oob indexing USAN complaint */ #define FIX_2287_MCT_MDCT_STEREO_DATA_MALLOC_SIZE /* FhG: correct allocation size for STEREO_MDCT_DEC_DATA struct */ +#define FIX_1904_HARM_GSC_ENC /* VA: #1904 Harmonization of EVS and IVAS GSC code */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index bba113ec0430e25ac92fbab05b02909dd86356f7..577451b04676bb88400044207384bc5786ad1f56 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1758,7 +1758,13 @@ 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 */ - const Word16 Eflag ); +#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( const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ @@ -1793,9 +1799,14 @@ 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*/ +#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*/ @@ -1804,6 +1815,7 @@ void pre_echo_att_ivas_fx( 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 */ @@ -5035,7 +5047,7 @@ void freq_dnw_scaling_fx( Word16 Qx, /* Q format of fy_norm*/ 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 */ @@ -5067,7 +5079,6 @@ void highband_exc_dct_in_fx( 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 */ @@ -5099,6 +5110,39 @@ void highband_exc_dct_in_ivas_fx( 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 */ + 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 */ +); +#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 5564dc1b8176c177c0076abf7362b40c43a02a26..c10306bc8a55b7cfb9bc90f9ab53f7b1013f4c68 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -241,6 +241,7 @@ void decod_audio_fx( nbits = 4; /* Q0 */ move16(); } + test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { @@ -276,6 +277,7 @@ void decod_audio_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -283,11 +285,13 @@ void decod_audio_fx( * Decode adaptive (pitch) excitation contribution * Reset unvaluable part of the adaptive (pitch) excitation contribution *--------------------------------------------------------------------------------------*/ + IF( GT_16( pit_band_idx, BAND1k2 ) ) { /*---------------------------------------------------------------* * Decode adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ + test(); test(); test(); @@ -351,6 +355,7 @@ void decod_audio_fx( /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ + edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); /*---------------------------------------------------------------* @@ -469,7 +474,6 @@ void decod_audio_fx( } } - Word16 Q_exc_old = st_fx->Q_exc; move16(); gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, &st_fx->Q_exc ); @@ -486,17 +490,23 @@ void decod_audio_fx( Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); /* Q_exc_old */ } } + /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ 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 ); + /*----------------------------------------------------------------------* * 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 @@ -530,6 +540,7 @@ void decod_audio_fx( return; } + /*==========================================================================*/ /* FUNCTION : void gsc_dec_fx () */ /*--------------------------------------------------------------------------*/ @@ -595,6 +606,7 @@ void gsc_dec_fx( /*--------------------------------------------------------------------------------------* * Initialization *--------------------------------------------------------------------------------------*/ + bit = bits_used; move16(); @@ -848,18 +860,24 @@ 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(); return; } + /*-------------------------------------------------------------------* * GSC_dec_init() * @@ -891,5 +909,6 @@ void GSC_dec_init_fx( hGSCDec->Last_frame_ener_fx = MAX_32; move32(); + return; } diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 8ed51cdab548697726070c48fe96262991bc444a..8c289393447276797bf23c6e8b803f52a6ced564 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -103,10 +103,6 @@ void tdm_low_rate_dec_fx( attack_flag = 0; move16(); - move16(); - move16(); - move16(); - move16(); /*--------------------------------------------------------------------------------------* * GSC decoder *--------------------------------------------------------------------------------------*/ @@ -152,12 +148,16 @@ void tdm_low_rate_dec_fx( Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[0], NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, L_FRAME * HIBND_ACB_L_FAC, L_shl( st->lp_gainc_fx, 13 /* Q3 -> Q16*/ ), &( st->Q_exc ), st->Q_subfr, NULL, 0, st->coder_type ); } + /*----------------------------------------------------------------------* * 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 ff4c684e838c33e383021cd56e61be3292302b23..0596b2f2d3f5a59a9b0dff8a6ace4f25889e9f10 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1371,7 +1371,11 @@ 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 + 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 { diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 200c22a1a1f61c5469a8bdaa6b8d6e580ccd925a..2d5902bc3306e274426b7c99c3abe8e1ebc64486 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -81,8 +81,12 @@ 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 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ - Word16 *pt_pitch; /* pointer to floating pitch */ +#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; Word32 Local_BR, Pitch_BR; @@ -103,6 +107,10 @@ 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 @@ -225,17 +233,27 @@ 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 ) { @@ -249,10 +267,23 @@ 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 */ - 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 ); - Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */ - Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ +#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, + 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*/ + } + 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 ); + Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */ + Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + } /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */ @@ -265,12 +296,27 @@ 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 *-----------------------------------------------------------------*/ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#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 ); + } /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure @@ -292,7 +338,16 @@ void enc_pit_exc_fx( } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ - hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#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*/ + } gpit_tmp = gain_pit; move16(); /*Q14*/ @@ -319,35 +374,58 @@ void enc_pit_exc_fx( } ELSE IF( use_fcb == 2 ) { - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + 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 ); + } + ELSE +#endif + { + /*-----------------------------------------------------------------* + * Innovation encoding + *-----------------------------------------------------------------*/ - inov_encode_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 ); + inov_encode_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 ); + } /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, 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 ); + gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, 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_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 ); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + 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 ); + } + ELSE +#endif + { + inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift ); + } /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ +#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 ); @@ -356,7 +434,16 @@ void enc_pit_exc_fx( gcode16 = round_fx_sat( Lgcode ); IF( use_fcb != 0 ) { - hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hLPDmem->tilt_code = est_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr, 0 ); /* Q15 */ + } + ELSE +#endif + { + hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ + } move16(); } ELSE @@ -371,13 +458,31 @@ void enc_pit_exc_fx( IF( use_fcb != 0 ) { - Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ +#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 */ + } Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); /* Q15 + Q_new + shift */ Ltmp = L_negate( Ltmp ); 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 */ - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ +#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 */ + } move16(); } ELSE @@ -385,7 +490,16 @@ 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 */ - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ +#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 */ + } move16(); } @@ -532,7 +646,7 @@ 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*/ @@ -1013,3 +1127,4 @@ void enc_pit_exc_ivas_fx( return; } +#endif diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index 33b35f0ccb1d91602065c2f701ed351ede04b744..dae547e35456e4dd0c35e24426621ba2c87234ad 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -89,7 +89,17 @@ Word16 Pit_exc_contribution_len_fx( move16(); } - minimum_fx( pitch_buf, nb_subfr, &low_pit ); +#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 ); + } + exp1 = norm_s( low_pit ); tmp = shl( low_pit, exp1 ); tmp_dec = 12800; @@ -381,13 +391,18 @@ 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 ); } delete_indice( hBstr, IND_ES_PRED ); } + IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) @@ -416,7 +431,7 @@ 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*/ @@ -778,3 +793,4 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher return last_pit_bin; } +#endif diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 19d7f599c1c3396a83a1370819289e6ad463c16d..b2800da5bbf5dc972883570367762f07e53b0c7d 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -60,6 +60,9 @@ 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(); @@ -70,9 +73,21 @@ void encod_audio_fx( move16(); T0_frac_tmp = 0; move16(); - Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); /* hLPDmem->q_mem_syn */ - hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; - 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; + move16(); + } + Es_pred = 0; move16(); @@ -82,6 +97,13 @@ 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 ) { push_indice( hBstr, IND_GSC_ATTACK, 1, 1 ); @@ -91,7 +113,6 @@ void encod_audio_fx( push_indice( hBstr, IND_GSC_ATTACK, 0, 1 ); } - test(); test(); test(); @@ -104,9 +125,11 @@ void encod_audio_fx( { 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 ) ) { @@ -120,6 +143,7 @@ void encod_audio_fx( } } } + test(); test(); test(); @@ -190,6 +214,7 @@ void encod_audio_fx( 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 ) ) { @@ -233,11 +258,14 @@ void encod_audio_fx( /*---------------------------------------------------------------* * 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++ ) { @@ -325,12 +353,12 @@ void encod_audio_fx( 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 ) @@ -339,7 +367,13 @@ 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 @@ -347,15 +381,29 @@ 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 *--------------------------------------------------------------------------------------*/ + IF( st_fx->hBWE_TD != NULL ) { IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) @@ -384,13 +432,25 @@ void encod_audio_fx( * Updates *--------------------------------------------------------------------------------------*/ - hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; - move16(); +#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(); + } + Copy( exc_wo_nf, exc, st_fx->L_frame ); return; } + +#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 */ @@ -599,10 +659,13 @@ void encod_audio_ivas_fx( 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 *---------------------------------------------------------------*/ @@ -674,8 +737,11 @@ void encod_audio_ivas_fx( /*---------------------------------------------------------------* * 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 ) { @@ -712,8 +778,11 @@ void encod_audio_ivas_fx( 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 *--------------------------------------------------------------------------------------*/ @@ -768,6 +837,7 @@ void encod_audio_ivas_fx( return; } +#endif /*================================================================================*/ /* FUNCTION : void gsc_enc_fx () */ /*--------------------------------------------------------------------------------*/ @@ -792,7 +862,6 @@ void encod_audio_ivas_fx( /* _None */ /*================================================================================*/ - void gsc_enc_fx( Encoder_State *st_fx, /* i/o: State structure */ Word16 res_dct_in[], /* i : dct of residual signal Q_exc*/ @@ -800,10 +869,19 @@ void gsc_enc_fx( const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ +#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*/ - Word16 Q_exc ) +#ifndef FIX_1904_HARM_GSC_ENC + Word16 Q_exc +#else + Word16 *Q_exc +#endif +) { Word16 y2_filt[L_FRAME16k]; Word16 exc_diffQ[L_FRAME16k]; @@ -816,7 +894,11 @@ 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]; @@ -827,6 +909,13 @@ 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 ); @@ -862,6 +951,7 @@ void gsc_enc_fx( * 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; @@ -873,11 +963,16 @@ 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 *--------------------------------------------------------------------------------------*/ + i = 0; move16(); WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) @@ -897,33 +992,60 @@ void gsc_enc_fx( { i--; } - - mean_gain = gsc_gainQ_fx( hBstr, /*st_fX->element_mode, st_fx->idchan,IVAS_CODE*/ Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth /*, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate*/ ); - - *tmp_noise = mult_r( 320, mean_gain ); /*10 in Q5 lp_gainc in Q3 */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could be harmonized, but won't be BE */ + { + mean_gain = gsc_gainQ_ivas_fx( hBstr, st_fx->element_mode, st_fx->idchan, Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate ); + *tmp_noise = mult( mean_gain, 20480 ); // 20480 => 10 in Q11 + } + ELSE +#endif + { + mean_gain = gsc_gainQ_fx( hBstr, /*st_fX->element_mode, st_fx->idchan,IVAS_CODE*/ Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth /*, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate*/ ); + *tmp_noise = mult_r( 320, mean_gain ); /*10 in Q5 lp_gainc in Q3 */ + } move16(); /*--------------------------------------------------------------------------------------* * 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 ) { set16_fx( concat_out, 0, L_FRAME16k ); } ELSE { - 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 ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ - bit = sub( bit, tmp ); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could probably be harmonized */ + { + Q_concat = Q12; + move16(); + 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 ); + + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_concat, Q_tmp ) ); /* Q_PVQ_OUT */ + bit = sub( bit, tmp ); + } } + /* write unused bits */ WHILE( bit > 0 ) { @@ -931,6 +1053,7 @@ void gsc_enc_fx( push_indice( hBstr, IND_UNUSED, 0, i ); bit = sub( bit, i ); } + /* Reorder Q bands */ seed_init = 0; move16(); @@ -938,6 +1061,32 @@ 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; + move16(); + + test(); + test(); + test(); + test(); + IF( ( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( st_fx->coder_type, UNVOICED ) ) || GE_16( st_fx->GSC_IVAS_mode, 1 ) ) + { + j = emaximum_fx( Q12, concat_out, shl( nb_subbands, 4 ), &L_tmp ); + IF( LE_16( add( abs_s( concat_out[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[j] ), 41 /* 0.01f in Q12 */ ) ); /* Q15 */ + } + } + } +#endif + FOR( j = 0; j < nb_subbands; j++ ) { Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); /*Q12*/ @@ -994,17 +1143,65 @@ 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(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { - freq_dnw_scaling_fx( hGSCEnc->cor_strong_limit, st_fx->coder_type, hGSCEnc->noise_lev, st_fx->core_brate, exc_diffQ, Q_PVQ_OUT, st_fx->L_frame ); + FOR( i = 64; i < st_fx->L_frame; i++ ) + { + exc_diffQ[i] = mult( exc_diffQ[i], max_eq ); /* Q12 */ + move16(); + } } + ELSE IF( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) && LE_16( st_fx->coder_type, UNVOICED ) ) + { + FOR( i = 0; i < L_FRAME; i++ ) + { + exc_diffQ[i] = mult( exc_diffQ[i], max_eq ); /* Q12 */ + move16(); + } + } + 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 ); + IF( NE_16( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ) + { + Scale_sig( hGSCEnc->last_exc_dct_in_fx, st_fx->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, st_fx->L_frame, sub( Q_exc_new, *Q_exc ) ); /* Q_exc_new */ + *Q_exc = Q_exc_new; + 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(); @@ -1012,7 +1209,7 @@ 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[], @@ -1098,9 +1295,11 @@ void gsc_enc_ivas_fx( 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 *--------------------------------------------------------------------------------------*/ @@ -1300,6 +1499,8 @@ void gsc_enc_ivas_fx( return; } +#endif + /*======================================================================*/ /* FUNCTION : edyn_fx() */ @@ -1322,10 +1523,11 @@ void gsc_enc_ivas_fx( /* _ None */ /*=======================================================================*/ -static Word16 edyn_fx( /* o : ratio of max to mean */ - const Word16 *vec, /* i : input vector Qnew*/ - const Word16 lvec, /* i : length of input vector */ - Word16 Qnew ) +/* o : ratio of max to mean */ +static Word16 edyn_fx( + const Word16 *vec, /* i : input vector Qnew*/ + const Word16 lvec, /* i : length of input vector */ + Word16 Qnew ) { Word16 j = 0; Word16 dyn; @@ -1371,6 +1573,7 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ dyn = 1280; /* 10.0f in Q7 */ move16(); } + return dyn; /* Q7 */ } @@ -1416,6 +1619,5 @@ void GSC_enc_init_fx( hGSCEnc->past_dyn_dec = 0; move16(); - return; } diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 05fabedfed7a11d7a76ee3fc3c551ab2cba2dae5..ef28b3c0ae1fc88453345b400f74a46e3adce2a5 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -112,7 +112,12 @@ void tdm_low_rate_enc( 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 @@ -126,7 +131,11 @@ void tdm_low_rate_enc( * 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 85465d0c51a001cb21fe9e4370f9b05e710df8b7..13d11e72b0f9c1040975955ac25ed82b0afdb10b 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -859,11 +859,21 @@ void gsc_enc_fx( const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - Word16 *lsf_new, /* i : ISFs at the end of the frame */ +#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 */ - Word16 Q_exc ); +#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 */ @@ -875,7 +885,7 @@ void gsc_enc_ivas_fx( 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 */ ); @@ -4002,7 +4012,7 @@ void enc_pit_exc_fx( const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ Word16 Q_new, 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*/ @@ -4022,6 +4032,7 @@ void enc_pit_exc_ivas_fx( 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( @@ -4032,7 +4043,7 @@ 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 */ @@ -4041,6 +4052,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( 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 */