diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 4ad2a85a190be22cc7d6ecf511fe6334f9bd7341..9d92d5d778c0c66690786a50daf91771d49569bb 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -33,6 +33,7 @@ /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ +#ifndef CLEANUP_ACELP_ENC Word16 est_tilt_fx( /* o : tilt of the code Q15 */ const Word16 *exc, /* i : adaptive excitation vector Qx */ const Word16 gain_pit, /* i : adaptive gain Q14 */ @@ -111,17 +112,25 @@ Word16 est_tilt_fx( /* o : tilt of the code /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ +#endif /* o : tilt of the code Q15 */ +#ifdef CLEANUP_ACELP_ENC +Word16 est_tilt_fx( +#else Word16 est_tilt_ivas_fx( +#endif const Word16 *exc, /* i : adaptive excitation vector Qx */ const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic excitation vector Q9 */ + const Word16 *code, /* i : algebraic excitation vector Q9 */ const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */ - const Word16 L_subfr, /* i : Sub frame length */ - const Word16 flag_tilt /* i : flag for special tilt */ + const Word16 L_subfr /* i : Sub frame length */ +#ifndef CLEANUP_ACELP_ENC + , + const Word16 flag_tilt /* i : flag for special tilt */ +#endif ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; @@ -161,6 +170,9 @@ Word16 est_tilt_ivas_fx( *voice_fac = exp; move16(); +#ifdef CLEANUP_ACELP_ENC + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ +#else IF( flag_tilt == 0 ) { /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ @@ -180,6 +192,7 @@ Word16 est_tilt_ivas_fx( // tilt_code = (float)(0.28f + (*voice_fac + 1.0f) * 0.14f); tilt_code = mac_r( 13763L /*0.42.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4588 /*0.14.Q15*/ ); /*Q15 */ } +#endif return tilt_code; } diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 7c0e1bc18edff4d6303e31c2bb790f21c998d7f6..fee62ca4c176372abb2a21d4168ad49dc719ec59 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2990,7 +2990,7 @@ Word16 ivas_acelp_tcx20_switching_fx( const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); -void encod_gen_2sbfr( +void encod_gen_2sbfr_fx( Encoder_State *st, /* i/o: state structure */ const Word16 speech[], /* i : input speech */ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ @@ -3004,8 +3004,8 @@ void encod_gen_2sbfr( Word16 *bwe_exc, /* o : excitation for SWB TBE */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : pitch values for primary channel */ - Word16 Q_new, - Word16 shift + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ ); void acelp_fast_fx( @@ -4483,7 +4483,7 @@ ivas_error signaling_enc_secondary_fx( const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag */ ); -void tdm_low_rate_enc( +void tdm_low_rate_enc_fx( Encoder_State *st, /* i/o: State structure */ const Word16 Aq[], /* i : 12k8 Lp coefficient */ const Word16 *res, /* i : residual signal Q_new*/ @@ -4494,8 +4494,8 @@ void tdm_low_rate_enc( Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ const Word16 attack_flag, /* i : attack flag */ const Word16 *lsf_new, /* i : current frame ISF vector x2.56 */ - Word16 *tmp_noise, /* o : long-term noise energy Q8 */ - Word16 Q_new + Word16 *tmp_noise, /* o : long-term noise energy Q8 */ + const Word16 Q_new /* i : Scaling factor */ ); void tdm_low_rate_dec_fx( diff --git a/lib_com/options.h b/lib_com/options.h index 6a07f86b9873807d5bc90848feaeff791b83bac8..d41b24ad3d784844b457332747db2c00a005a8fe 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -113,6 +113,7 @@ #define FIX_1872_REMOVE_UNUSED_PSNOISEGEN_ISAR /* Dolby: Remove unused psNoiseGen from ISAR */ #define FIX_1478_UNINIT_ON_BFI /* VA: Fix issue 1478 where a vector is partly un-initialized during bfi */ #define FIX_1487_ACCESS_OF_UNINIT_VAL_FROM_ARR_ISM_DTX /* FhG/VA: init nb_bits_metadata to zero */ +#define CLEANUP_ACELP_ENC /* VA: basop issue 2304: Remove duplicated code in excitation encoding in the ACELP core */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 577451b04676bb88400044207384bc5786ad1f56..8285b23b0db5c948059513f7c15f512a1952c768 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2910,6 +2910,9 @@ Word16 tbe_celp_exc_offset( const Word16 L_frame /* i : frame lenght */ ); +#ifdef CLEANUP_ACELP_ENC +void tbe_celp_exc_fx( +#else void tbe_celp_exc( const Word16 L_frame_fx, /* i : Frame lenght */ const Word16 i_subfr_fx, /* i : sub frame */ @@ -2918,8 +2921,8 @@ void tbe_celp_exc( Word16 *error_fx, /* i/o: Error */ Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ ); - void tbe_celp_exc_ivas( +#endif const Word16 element_mode, /* i : element mode */ const Word16 idchan, /* i : channel ID */ const Word16 L_frame_fx, /* i : Frame lenght */ @@ -4840,9 +4843,15 @@ Word16 est_tilt_fx( const Word16 *code, /* i : algebraic exctitation vector Q9 */ const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +#ifdef CLEANUP_ACELP_ENC + const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */ + const Word16 L_subfr /* i : Sub frame length */ +#else + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +#endif ); +#ifndef CLEANUP_ACELP_ENC /* o : tilt of the code Q15 */ Word16 est_tilt_ivas_fx( const Word16 *exc, /* i : adaptive excitation vector Qx */ @@ -4851,10 +4860,13 @@ Word16 est_tilt_ivas_fx( const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */ - const Word16 L_subfr, /* i : Sub frame length */ - const Word16 flag_tilt /* i : flag for special tilt */ + const Word16 L_subfr /* i : Sub frame length */ +#ifndef CLEANUP_ACELP_ENC + , + const Word16 flag_tilt /* i : flag for special tilt */ +#endif ); - +#endif /* o : tilt of the code */ Word16 Est_tilt2( const Word16 *exc, /* i : adaptive excitation vector Qx */ @@ -6847,6 +6859,9 @@ void gain_dec_lbr_fx( ); void lp_gain_updt_fx( +#ifdef CLEANUP_ACELP_ENC + const Word16 element_mode, /* i : element mode */ +#else const Word16 i_subfr, /* i : subframe number Q0 */ const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ @@ -6854,8 +6869,8 @@ void lp_gain_updt_fx( Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ const Word16 L_frame /* i : length of the frame */ ); - void lp_gain_updt_ivas_fx( +#endif const Word16 i_subfr, /* i : subframe number Q0 */ const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ @@ -7114,6 +7129,7 @@ void inov_decode_fx( const Word16 L_subfr /* i : subframe length Q0 */ ); +#ifndef CLEANUP_ACELP_ENC void inov_decode_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word32 core_brate, /* i : core bitrate Q0 */ @@ -7127,7 +7143,7 @@ void inov_decode_ivas_fx( Word16 *code, /* o : algebraic excitation Q12 */ const Word16 L_subfr /* i : subframe length Q0 */ ); - +#endif void dec_acelp_4t64_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 nbbits, /* i : number of bits per codebook */ @@ -10898,11 +10914,15 @@ ivas_error IGF_Reconfig_fx( ); void core_switching_post_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ + Encoder_State *st /* i/o: encoder state structure */ +#ifndef CLEANUP_ACELP_ENC + , Word16 *old_inp_12k8_fx, /* i : old input signal @12.8kHz */ Word16 *old_inp_16k_fx, /* i : old input signal @16kHz */ Word16 A_fx[], /* i : unquant. LP filter coefs. */ - Word16 Q_new ); + Word16 Q_new +#endif +); void residu_ivas_fx( const Word16 *a, /* i : LP filter coefficients Q31-a_exp*/ @@ -11194,7 +11214,7 @@ ivas_error acelp_core_enc_ivas_fx( 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*/ - Word16 Q_new ); + const Word16 Q_new ); void flip_and_downmix_generic_fx32( Word32 input[], /* i : input spectrum Qx*/ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index c9d307ef26b0bd5fefabb8f24f3d9941581893cc..610b9cae0951e5c7147f633edb00726170b9347e 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -160,6 +160,7 @@ Word16 tbe_celp_exc_offset( * * Compute tbe bwe celp excitation *-------------------------------------------------------------------*/ +#ifndef CLEANUP_ACELP_ENC void tbe_celp_exc( const Word16 L_frame_fx, /* i : Frame lenght */ const Word16 i_subfr_fx, /* i : sub frame */ @@ -238,7 +239,13 @@ void tbe_celp_exc( * * Compute tbe bwe celp excitation *-------------------------------------------------------------------*/ +#endif + +#ifdef CLEANUP_ACELP_ENC +void tbe_celp_exc_fx( +#else void tbe_celp_exc_ivas( +#endif const Word16 element_mode, /* i : element mode */ const Word16 idchan, /* i : channel ID */ const Word16 L_frame_fx, /* i : Frame lenght */ @@ -321,6 +328,8 @@ void tbe_celp_exc_ivas( *error_fx = add( *error_fx, tmp_fx ); /*error_fx in Q5*/ move16(); } + + return; } /*===========================================================================*/ @@ -349,6 +358,16 @@ void tbe_celp_exc_ivas( /* RETURN ARGUMENTS : */ /* _ None */ /*---------------------------------------------------------------------------*/ + +#ifdef CLEANUP_ACELP_ENC +static const Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, + -26319, -17530, -6393, 6393, 17530, 26319, + 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ +static const Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, + -19519, -27683, -32137, -32137, -27683, + -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ +#endif + void flip_and_downmix_generic_fx( Word16 input[], /* i : input spectrum Qx*/ Word16 output[], /* o : output spectrum Qx*/ @@ -371,6 +390,7 @@ void flip_and_downmix_generic_fx( /*Word16 s_tmp[L_FRAME32k];*/ /*Word16 factor;*/ Word16 period; +#ifndef CLEANUP_ACELP_ENC Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, -26319, -17530, -6393, 6393, 17530, 26319, 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ @@ -378,14 +398,16 @@ void flip_and_downmix_generic_fx( -19519, -27683, -32137, -32137, -27683, -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ Word16 *local_negsin_table, *local_cos_table; +#endif Word32 L_tmp; /* 1850 Hz downmix */ period = 17; move16(); +#ifndef CLEANUP_ACELP_ENC local_negsin_table = local_negsin_table17; local_cos_table = local_cos_table17; - +#endif FOR( i = 0; i < length; i = i + 2 ) { @@ -467,9 +489,14 @@ void flip_and_downmix_generic_fx( { WHILE( ( j < period ) && ( i < length ) ) { +#ifdef CLEANUP_ACELP_ENC + L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table17[j] ); /*//Qx+16 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table17[j] ); /*Qx+16 */ +#else L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = round_fx( L_tmp ); /*Qx */ +#endif + output[i] = round_fx( L_tmp ); /*Qx */ move16(); i++; j++; @@ -511,6 +538,7 @@ void flip_and_downmix_generic_fx32( /*Word16 s_tmp[L_FRAME32k];*/ /*Word16 factor;*/ Word16 period; +#ifndef CLEANUP_ACELP_ENC Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, -26319, -17530, -6393, 6393, 17530, 26319, 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ @@ -518,14 +546,16 @@ void flip_and_downmix_generic_fx32( -19519, -27683, -32137, -32137, -27683, -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ Word16 *local_negsin_table, *local_cos_table; +#endif Word32 L_tmp; /* 1850 Hz downmix */ period = 17; move16(); +#ifndef CLEANUP_ACELP_ENC local_negsin_table = local_negsin_table17; local_cos_table = local_cos_table17; - +#endif FOR( i = 0; i < length; i = i + 2 ) { @@ -597,9 +627,14 @@ void flip_and_downmix_generic_fx32( WHILE( ( j < period ) && ( i < length ) ) { test(); +#ifdef CLEANUP_ACELP_ENC + L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table17[j] ); /*//Qx+16 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table17[j] ); /*Qx+16 */ +#else L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = L_tmp; /*Qx */ +#endif + output[i] = L_tmp; /*Qx */ move32(); i++; j++; @@ -6136,7 +6171,7 @@ void create_random_vector_fx( L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ } #else - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ #endif j = extract_l( L_shr( L_tmp, 23 ) ); @@ -6153,7 +6188,7 @@ void create_random_vector_fx( } #else - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ #endif k = extract_l( L_shr( L_tmp, 23 ) ); @@ -6171,7 +6206,7 @@ void create_random_vector_fx( L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ } #else - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ #endif k = extract_l( L_shr( L_tmp, 23 ) ); diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 2df489cc115889a8c470e271a0024175d44b0235..049626e597e13ebd43166a24a1ca28a83980c630 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -936,11 +936,11 @@ static void decod_gen_voic_core_switch_fx( gain_dec_mless_fx( st_fx, L_frame, GENERIC, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); } - /* _ (Word16*) gain_pit : quantized pitch gain (Q14) */ - /* _ (Word32*) gain_code : quantized codebook gain (Q16) */ - /* _ (Word16*) gain_inov : gain of the innovation (used for normalization) (Q12) */ - /* _ (Word32*) norm_gain_code : norm. gain of the codebook excitation (Q16) */ +#ifdef CLEANUP_ACELP_ENC + st_fx->tilt_code_fx = est_tilt_fx( exc, gain_pit, code, gain_code, &voice_fac, *Q_exc, L_SUBFR ); /*Q15*/ +#else st_fx->tilt_code_fx = est_tilt_fx( exc, gain_pit, code, gain_code, &voice_fac, *Q_exc ); /*Q15*/ +#endif move16(); /*----------------------------------------------------------------------* diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 8bab0d0615082173235cbc1d82893dd6957d809d..d1040cb8075a3a6a4c4e305a81e8f55d50da934d 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1302,7 +1302,6 @@ ivas_error core_switching_post_dec_ivas_fx( test(); IF( st_fx->core == ACELP_CORE && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx ) { - /*needed to be converted to fixed curretnly using evs implementation not in line*/ if ( ( error = acelp_core_switch_dec_bfi_ivas_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 0d867fd6f0708fc01193345fa209e6302c4eabc9..9c1cd74acd7129e34163bd1467657e45842b5943 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -353,7 +353,11 @@ void decoder_acelp_fx( IF( st->igf != 0 ) { +#ifdef CLEANUP_ACELP_ENC + tbe_celp_exc_fx( EVS_MONO, 0, st->L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, 0 ); +#else tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); +#endif } pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); // Q6 diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index c65162afcdb24dac8a49a954240e671cfc1272eb..2a977033dc2a2da841a1ab0440a839d5b2583cfc 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -84,6 +84,7 @@ void decod_amr_wb_fx( *--------------------------------------------------------------*/ lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc_fx ); + /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ @@ -98,9 +99,17 @@ void decod_amr_wb_fx( gain_dec_amr_wb_fx( st_fx, st_fx->core_brate, &gain_pit_fx, &L_gain_code_fx, hAmrwb_IO->past_qua_en_fx, &gain_inov_fx, code_fx, &L_norm_gain_code_fx ); /* update LP filtered gains for the case of frame erasures */ +#ifdef CLEANUP_ACELP_ENC + lp_gain_updt_fx( EVS_MONO, i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); +#else lp_gain_updt_fx( i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); +#endif +#ifdef CLEANUP_ACELP_ENC + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); +#else st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); +#endif move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, 0, diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index f7640abe7f632fc12eede8fbd214f933d651677c..0288e3d85761f7c7d6bd813432cb95a27844f4d6 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -164,6 +164,7 @@ ivas_error decod_gen_voic_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ + IF( st_fx->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); @@ -173,13 +174,18 @@ ivas_error decod_gen_voic_fx( pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } - // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); +#ifdef CLEANUP_ACELP_ENC + tbe_celp_exc_fx( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); +#else tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); +#endif /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ + lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx ); + /*-----------------------------------------------------------------* * Transform-domain contribution decoding (active frames) *-----------------------------------------------------------------*/ @@ -215,12 +221,18 @@ ivas_error decod_gen_voic_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } + +#ifdef CLEANUP_ACELP_ENC + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); // Q15 +#else st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); // Q15 +#endif move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ + test(); IF( !st_fx->inactive_coder_type_flag && st_fx->coder_type == INACTIVE ) { @@ -228,6 +240,9 @@ ivas_error decod_gen_voic_fx( } /* update LP filtered gains for the case of frame erasures */ +#ifdef CLEANUP_ACELP_ENC + lp_gain_updt_fx( st_fx->element_mode, i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); +#else IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); @@ -236,6 +251,7 @@ ivas_error decod_gen_voic_fx( { lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); } +#endif /*----------------------------------------------------------------------* * Find the total excitation @@ -368,7 +384,6 @@ ivas_error decod_gen_voic_fx( } /* FEC fast recovery */ - IF( do_WI_fx ) { /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/ diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 645444e7da153aae1e206c04a23616839199f2c9..41fcb64c707b9457c54ce11dd1c1caaa2c23c34e 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -202,12 +202,15 @@ void dec_pit_exc_fx( gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); +#ifdef CLEANUP_ACELP_ENC + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx ); +#else st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 ); +#endif move16(); } ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */ { - /*inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);*/ inov_decode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, 0, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); /*--------------------------------------------------------------* @@ -217,7 +220,11 @@ void dec_pit_exc_fx( gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); +#ifdef CLEANUP_ACELP_ENC + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx ); +#else st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 ); +#endif move16(); } ELSE @@ -250,6 +257,7 @@ void dec_pit_exc_fx( /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); @@ -418,7 +426,11 @@ void dec_pit_exc_fx( move16(); pt_gain++; +#ifdef CLEANUP_ACELP_ENC + lp_gain_updt_fx( st_fx->element_mode, i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); +#else lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); +#endif } } diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index b00b445d791133d719b9027e7956584ccc86388f..43a948bba590f800334cb78f4ab7d393c5c66545 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -87,6 +87,7 @@ void decod_tran_fx( move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); // Q10 + /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ @@ -118,9 +119,11 @@ void decod_tran_fx( transition_dec_fx( st_fx, 0, L_frame_fx, i_subfr, tc_subfr_fx, &Jopt_flag, exc_fx, &T0, &T0_frac, &T0_min, &T0_max, &pt_pitch_fx, &position, bwe_exc_fx, &st_fx->Q_exc ); + /*-----------------------------------------------------------------* * Transform domain contribution decoding - active frames *-----------------------------------------------------------------*/ + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { gain_code_fx = 0; @@ -165,6 +168,12 @@ void decod_tran_fx( } /* update LP filtered gains for the case of frame erasures */ +#ifdef CLEANUP_ACELP_ENC + lp_gain_updt_fx( st_fx->element_mode, i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); + + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); + move16(); +#else IF( st_fx->element_mode == EVS_MONO ) { lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); @@ -179,10 +188,12 @@ void decod_tran_fx( st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); move16(); } +#endif /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ + test(); test(); test(); @@ -219,6 +230,7 @@ void decod_tran_fx( /*-----------------------------------------------------------------* * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { IF( ( st_fx->element_mode == EVS_MONO ) ) @@ -244,6 +256,7 @@ void decod_tran_fx( /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ + Word16 tmp_idx_2; tmp_idx_2 = 0; move16(); diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index b5c10232c4034725f0ef48a73c45102630738d31..9ced61d6864c6ef7ab4aca92a19552957e9a077a 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -5,6 +5,8 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ + + static void gain_dec_gacelp_uv_fx( Word16 index, /* i : Quantization index vector Q0 */ Word16 *code, /* i : algebraic code excitation Q9 */ @@ -90,19 +92,18 @@ void decod_unvoiced_fx( * Innovation decoding *--------------------------------------------------------------*/ - // inov_decode(st, st->core_brate, 0, L_FRAME, 1, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, L_SUBFR); inov_decode_fx( st_fx, st_fx->core_brate, 0, L_FRAME, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); /*-------------------------------------------------------* * Generate Gaussian excitation * *-------------------------------------------------------*/ - // gaus_L2_dec_flt(code2, st->tilt_code, p_Aq, FORMANT_SHARPENING_G1_FLT, &(st->seed_acelp)); gaus_L2_dec( code2_fx, st_fx->tilt_code_fx, p_Aq_fx, FORMANT_SHARPENING_G1, &( st_fx->seed_acelp ) ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ + Word16 tmp_idx_1; tmp_idx_1 = 0; move16(); @@ -115,10 +116,17 @@ void decod_unvoiced_fx( gain_dec_gacelp_uv_fx( index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &( st_fx->past_gpit ), &norm_gain_code_fx, &gain_inov_fx ); +#ifdef CLEANUP_ACELP_ENC + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); +#else st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); +#endif move16(); /* update LP filtered gains for the case of frame erasures */ +#ifdef CLEANUP_ACELP_ENC + lp_gain_updt_fx( st_fx->element_mode, i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); +#else IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); @@ -127,6 +135,7 @@ void decod_unvoiced_fx( { lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); } +#endif /*-------------------------------------------------------* * - Find the total excitation. * diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 0848104afa84f0eb798d41eb438c02502ccc57de..c145610f8af488659267ec34f64163ba66526f62 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -989,8 +989,7 @@ void gain_dec_lbr_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*=======================================================================*/ - - +#ifndef CLEANUP_ACELP_ENC void lp_gain_updt_fx( const Word16 i_subfr, /* i : subframe number Q0 */ const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ @@ -1101,9 +1100,14 @@ void lp_gain_updt_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*=======================================================================*/ +#endif - +#ifdef CLEANUP_ACELP_ENC +void lp_gain_updt_fx( + const Word16 element_mode, /* i : element mode */ +#else void lp_gain_updt_ivas_fx( +#endif const Word16 i_subfr, /* i : subframe number Q0 */ const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ @@ -1117,7 +1121,12 @@ void lp_gain_updt_ivas_fx( tmp = extract_h( L_shl_sat( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ /* To handle extremely low values */ test(); +#ifdef CLEANUP_ACELP_ENC + test(); + if ( element_mode != EVS_MONO && norm_gain_code != 0 && tmp == 0 ) +#else if ( norm_gain_code != 0 && tmp == 0 ) +#endif { tmp = 1; move16(); @@ -1195,7 +1204,12 @@ void lp_gain_updt_ivas_fx( /* To handle extremely low values */ test(); +#ifdef CLEANUP_ACELP_ENC + test(); + if ( element_mode != EVS_MONO && tmp != 0 && *lp_gainc == 0 ) +#else if ( tmp != 0 && *lp_gainc == 0 ) +#endif { *lp_gainc = 1; move16(); @@ -1245,6 +1259,7 @@ Word32 gain_dec_gaus_fx( L_enr_q = L_mult( index, stepSize ); /* Q0 * QstepSize_Exp -> QstepSize_Exp+1 */ L_enr_q = L_shl( L_enr_q, sub( 24 - 1, stepSize_Exp ) ); /* QstepSize_Exp+1 -> Q24 */ L_enr_q = L_add( L_enr_q, L_shl( L_deposit_h( lowBound ), 8 ) ); /* Q24 */ + /*------------------------------------------------------------* * gain = pow(10.0, enr/20) * = pow(2, 3.321928*enr/20) @@ -1402,7 +1417,6 @@ void gain_dec_amr_wb_fx( Word32 L_tmp; Word16 expg, exp_gcode0, fracg; - /**gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR );*/ L_tmp = Dot_product12( code, code, L_SUBFR, &expg ); /*Q31 - expg*/ @@ -1451,6 +1465,7 @@ void gain_dec_amr_wb_fx( * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q27 */ L_tmp = L_shr( L_tmp, 9 + 2 ); /* From Q27 to Q16 */ L_Extract( L_tmp, &exp_gcode0, &fracg ); /* Extract exponent of gcode0 */ @@ -1496,12 +1511,14 @@ void gain_dec_amr_wb_fx( past_qua_en[i] = past_qua_en[i - 1]; move16(); } + /*past_qua_en[0] = (float)(20.0*log10(qua_en));*/ /*----------------------------------------------------------* * past_qua_en[0] = 20*log10(t_qua_gain[indice*2+1]) * = 6.0206*log2(t_qua_gain[indice*2+1]) * = 6.0206*(log2(t_qua_gain[indice*2+1]Q11 -11) *----------------------------------------------------------*/ + tmp = norm_l( qua_en ); fracg = Log2_norm_lc( L_shl( qua_en, tmp ) ); expg = sub( 30, tmp ); @@ -1515,6 +1532,7 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Normalized code gain *-----------------------------------------------------------------*/ + /**norm_gain_code = *gain_code / *gain_inov;*/ expg = sub( norm_s( *gain_inov ), 1 ); expg = s_max( expg, 0 ); diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index d49ecb5b7a90acfa8ff9ef6503a90004bfe22adc..456a7a9028cb86e0e42adb2b0bd66ef87fc03200 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -87,6 +87,9 @@ void gaus_dec_fx( move32(); /* update LP filtered gains for the case of frame erasures */ +#ifdef CLEANUP_ACELP_ENC + lp_gain_updt_fx( st_fx->element_mode, i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ +#else IF( st_fx->element_mode == EVS_MONO ) { lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ @@ -95,6 +98,7 @@ void gaus_dec_fx( { lp_gain_updt_ivas_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ } +#endif /*------------------------------------------------------------------------------------------* * Updates diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 4d44e5b5b421cffb7f2d5faa669a5fbfd39ad139..30479dd045f1c35631ea87046bcb88c20713878f 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -191,7 +191,7 @@ void inov_decode_fx( cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); return; } - +#ifndef CLEANUP_ACELP_ENC /*======================================================================*/ /* FUNCTION : inov_decode_ivas_fx() */ /*-----------------------------------------------------------------------*/ @@ -376,3 +376,4 @@ void inov_decode_ivas_fx( cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); return; } +#endif diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 8c289393447276797bf23c6e8b803f52a6ced564..92d6d3153fad45660ab1e286ec99ab5811bd48fc 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -248,9 +248,6 @@ void decod_gen_2sbfr_fx( error = 0; move16(); - move16(); - move16(); - move16(); /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ @@ -270,12 +267,17 @@ void decod_gen_2sbfr_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) && !( st->tdm_LRTD_flag ) ) ) { +#ifdef CLEANUP_ACELP_ENC + tbe_celp_exc_fx( st->element_mode, st->idchan, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, 0 ); +#else tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); +#endif } /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ + IF( st->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); @@ -295,7 +297,11 @@ void decod_gen_2sbfr_fx( * Innovation decoding *--------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + inov_decode_fx( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code_fx, *pt_pitch, code, 2 * L_SUBFR ); +#else inov_decode_ivas_fx( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code_fx, *pt_pitch, code, 2 * L_SUBFR ); +#endif /*--------------------------------------------------------------* * Gain decoding @@ -303,12 +309,22 @@ void decod_gen_2sbfr_fx( *--------------------------------------------------------------*/ gain_dec_lbr_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); + +#ifdef CLEANUP_ACELP_ENC + st->tilt_code_fx = est_tilt_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR ); /* Q15 */ +#else st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */ +#endif move16(); /* update LP filtered gains for the case of frame erasures */ +#ifdef CLEANUP_ACELP_ENC + lp_gain_updt_fx( st->element_mode, i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_fx( st->element_mode, add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); +#else lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); lp_gain_updt_ivas_fx( add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); +#endif /*----------------------------------------------------------------------* * Find the total excitation diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 0596b2f2d3f5a59a9b0dff8a6ace4f25889e9f10..5a29164341d771772c58a91557d55d33464749cb 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -95,12 +95,17 @@ ivas_error acelp_core_enc_fx( ivas_error error; error = IVAS_ERR_OK; + +#ifdef CLEANUP_ACELP_ENC + (void) hStereoTD; +#else test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->core_brate, SID_2k40 ) ) { /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */ return error; } +#endif /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ @@ -196,6 +201,7 @@ ivas_error acelp_core_enc_fx( move16(); } +#ifndef CLEANUP_ACELP_ENC /* TD stereo */ test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) @@ -206,21 +212,25 @@ ivas_error acelp_core_enc_fx( tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf_fx; } ELSE +#endif { tdm_lp_reuse_flag = 0; tdm_low_rate_mode = 0; move16(); move16(); +#ifndef CLEANUP_ACELP_ENC if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); } +#endif tdm_Pitch_reuse_flag = 0; tdm_Pri_pitch_buf = NULL; move16(); move16(); } + /*-----------------------------------------------------------------* * ACELP@12k8 / ACELP@16k switching *-----------------------------------------------------------------*/ @@ -551,21 +561,26 @@ ivas_error acelp_core_enc_fx( 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 +#ifndef CLEANUP_ACELP_ENC test(); IF( st_fx->element_mode > EVS_MONO && st_fx->hTcxEnc != NULL ) { Copy( syn1_fx + st_fx->L_frame / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame / 2 ); // Q_syn } - +#endif /*--------------------------------------------------------------------------------------* * Modify the excitation signal when the noise is stationary *--------------------------------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + IF( NE_16( nelp_mode, 1 ) ) +#else test(); test(); test(); test(); IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) +#endif { L_epsP[0] = L_Comp( epsP_h_fx[2], epsP_l_fx[2] ); move32(); @@ -699,6 +714,7 @@ ivas_error acelp_core_enc_fx( * * ACELP core encoder *--------------------------------------------------------------------*/ + ivas_error acelp_core_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 inp[], /* i : input signal of the current frame Q_new*/ @@ -717,7 +733,7 @@ ivas_error acelp_core_enc_ivas_fx( 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*/ - Word16 Q_new ) + const Word16 Q_new ) { Word16 i, nBits; /* reserved bits */ LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ @@ -1318,11 +1334,11 @@ ivas_error acelp_core_enc_ivas_fx( { IF( LE_16( st->coder_type, UNVOICED ) ) { - tdm_low_rate_enc( st, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new ); + tdm_low_rate_enc_fx( st, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new ); } ELSE /* GENERIC */ { - encod_gen_2sbfr( 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 ); + 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 ); } } ELSE IF( nelp_mode ) @@ -1334,11 +1350,19 @@ ivas_error acelp_core_enc_ivas_fx( ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ +#ifdef CLEANUP_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, 0 ); +#else encod_unvoiced_ivas_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 CLEANUP_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, 0, Q_new ); +#else encod_tran_ivas_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 } ELSE IF( ppp_mode ) { @@ -1365,7 +1389,11 @@ ivas_error acelp_core_enc_ivas_fx( move16(); /* VOICED frames in SC-VBR */ +#ifdef CLEANUP_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, 0, Q_new ); +#else encod_gen_voic_ivas_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 } } ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) @@ -1380,7 +1408,11 @@ ivas_error acelp_core_enc_ivas_fx( ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ +#ifdef CLEANUP_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, 0, Q_new ); +#else encod_gen_voic_ivas_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 */ diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index 2f51be28e414ed30a524fe93305985f51a158c48..98ab17afbd9d84db4591b1165697ff818397334f 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -15,15 +15,18 @@ * Local function prototypes *---------------------------------------------------------------------*/ -static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); - -static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); +static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, const Word16 shift, const Word16 Q_new ); +#ifndef CLEANUP_ACELP_ENC +static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, const Word16 shift, const Word16 Q_new ); +#endif static void bwe_switch_enc_fx( Encoder_State *st_fx, const Word16 *new_speech ); +#ifndef CLEANUP_ACELP_ENC static void bwe_switch_enc_ivas_fx( Encoder_State *st_fx, const Word16 *new_speech ); +#endif +static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, const Word16 qx, const Word16 qy, Word16 *qo, const Word16 len, const Word16 delta ); -static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta ); /*-------------------------------------------------------------------* * acelp_core_switch_enc_fx() @@ -36,8 +39,8 @@ void acelp_core_switch_enc_fx( const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, + const Word16 Q_new ) { Word16 i, j, T_op[2]; Word16 old_exc[L_EXC], *exc; /* excitation signal buffer Qexc */ @@ -163,7 +166,7 @@ void acelp_core_switch_enc_fx( return; } - +#ifndef CLEANUP_ACELP_ENC void acelp_core_switch_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ @@ -273,7 +276,7 @@ void acelp_core_switch_enc_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------* * encod_gen_voic_core_switch() @@ -290,8 +293,8 @@ static void encod_gen_voic_core_switch_fx( const Word16 T_op[], /* i : open loop pitch Q0*/ Word16 *exc, /* i/o: current non-enhanced excitation Q_exc*/ const Word32 core_bitrate, /* i : switching frame bitrate Q0*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, + const Word16 Q_new ) { Word16 res[L_SUBFR]; /* residual signal Qexc */ Word16 Ap[M + 1]; /* A(z) with spectral expansion Q12 */ @@ -374,7 +377,6 @@ static void encod_gen_voic_core_switch_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - Copy( res, exc, L_SUBFR ); /* Q1 */ IF( EQ_16( L_frame, L_FRAME16k ) ) @@ -419,6 +421,7 @@ static void encod_gen_voic_core_switch_fx( /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ + lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */ lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ @@ -431,12 +434,18 @@ static void encod_gen_voic_core_switch_fx( * Innovation encoding *-----------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + inov_encode_fx( st_fx, core_bitrate, 0, L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, 0, -1, Aq, gain_pit, cn, exc, + h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift, 0 ); +#else inov_encode_fx( st_fx, core_bitrate, 0, L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, 0, -1, Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift ); +#endif /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ + IF( EQ_16( L_frame, L_FRAME ) ) { gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, @@ -489,6 +498,7 @@ static void encod_gen_voic_core_switch_fx( return; } +#ifndef CLEANUP_ACELP_ENC static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 L_frame, /* i : length of the frame Q0*/ @@ -498,8 +508,8 @@ static void encod_gen_voic_core_switch_ivas_fx( const Word16 T_op[], /* i : open loop pitch Q0*/ Word16 *exc, /* i/o: current non-enhanced excitation Q_exc*/ const Word32 core_bitrate, /* i : switching frame bitrate Q0*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, + const Word16 Q_new ) { Word16 res[L_SUBFR]; /* residual signal Qexc */ Word16 Ap[M + 1]; /* A(z) with spectral expansion Q12 */ @@ -664,6 +674,7 @@ static void encod_gen_voic_core_switch_ivas_fx( // Q_new or shift ?? ->Qexc hLPDmem->tilt_code = est_tilt_ivas_fx( exc + 0, gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); /* Q15 */ move16(); + /*-----------------------------------------------------------------* * Construct adaptive part of the excitation *-----------------------------------------------------------------*/ @@ -699,6 +710,7 @@ static void encod_gen_voic_core_switch_ivas_fx( return; } +#endif /*-------------------------------------------------------------------* * bwe_switch_enc() @@ -849,7 +861,7 @@ static void bwe_switch_enc_fx( return; } - +#ifndef CLEANUP_ACELP_ENC static void bwe_switch_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *new_speech_fx /* i : original input signal Q0 */ @@ -989,16 +1001,16 @@ static void bwe_switch_enc_ivas_fx( return; } - +#endif static Word16 dotprod_satcont( const Word16 *x, /* qx */ const Word16 *y, /* qy */ - Word16 qx, - Word16 qy, + const Word16 qx, + const Word16 qy, Word16 *qo, - Word16 len, /* Q0 */ - Word16 delta /* Q0 */ + const Word16 len, /* Q0 */ + const Word16 delta /* Q0 */ ) { Word16 tmp_tabx[L_FRAME48k], tmp_taby[L_FRAME48k]; diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index 8739661168a5dd90e7c596fd8b261f9b572ac612..ee8b57c6be351442a4d1903798d32a92d469c305 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -39,7 +39,7 @@ void analy_lp_fx( const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ const Word16 element_mode, /* i : element mode */ const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /* i : stores Q for speech */ + const Word16 Q_new, /* i : stores Q for speech */ Word16 *Q_r /*stores q for ener*/ ) { @@ -152,7 +152,7 @@ void analy_lp_AMR_WB_fx( Word16 isf_new[], /* o : current frame ISPs Q15*/ Word16 Top, /* i : open loop pitch lag Q0*/ Word16 Tnc, /* i : open loop pitch gain Qx*/ - Word16 Q_new, + const Word16 Q_new, Word16 *Q_r ) { Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 66819c4acfaff9185d2be31f54171452a3ba7286..0fbd01b3a2adb547dba3bd1a83e592bb85e80680 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -262,7 +262,11 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * IF( st->igf != 0 ) { +#ifdef CLEANUP_ACELP_ENC + tbe_celp_exc_fx( EVS_MONO, 0, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, 0 ); +#else tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); +#endif } pitch_buf[i_subfr / L_SUBFR] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 5d54b97292ae93d182c6d07be21bd4293ecc0772..e1a246817faa043ea9422931d70f1cbee6613680 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3908,8 +3908,8 @@ void coder_tcx_post_fx( const Word16 *A, const Word16 *Ai, Word16 *wsig, - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, + const Word16 shift ) { Word16 xn_buf[L_FRAME_MAX]; diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index aa06b12d20d5eeff4b7469045355661ab18be1d9..2d44ba36a7c493ad8f8df788c50bb5a5991bf56f 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -1052,16 +1052,22 @@ void core_switching_pre_enc_ivas_fx( *---------------------------------------------------------------------*/ void core_switching_post_enc_ivas_fx( +#ifdef CLEANUP_ACELP_ENC + Encoder_State *st /* i/o: encoder state structure */ +#else Encoder_State *st, /* i/o: encoder state structure */ Word16 *old_inp_12k8_fx, /* i : old input signal @12.8kHz Q_new-1 */ Word16 *old_inp_16k_fx, /* i : old input signal @16kHz Q_new-1 */ Word16 A_fx[], /* i : unquant. LP filter coefs. Q12 */ - Word16 Q_new ) + Word16 Q_new +#endif +) { IF( EQ_16( st->core, HQ_CORE ) ) { st->use_acelp_preq = 0; move16(); +#ifndef CLEANUP_ACELP_ENC test(); test(); IF( ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) && st->element_mode == EVS_MONO ) /* core switching ==> ACELP subframe encoding */ @@ -1079,6 +1085,7 @@ void core_switching_post_enc_ivas_fx( acelp_core_switch_enc_ivas_fx( st, old_inp_12k8_fx + L_INP_MEM - NS2SA( INT_FS_12k8, ACELP_LOOK_NS ), old_inp_16k_fx + L_INP_MEM - NS2SA( INT_FS_16k, ACELP_LOOK_NS ), A_fx, 0, sub( Q_new, 1 ) ); } +#endif st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index f68b94daf048b36d3bc6bced9833598f64a1c11a..022483f829ba12bba2bacca633691672f278e71f 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -29,8 +29,8 @@ void encod_amr_wb_fx( Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6*/ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain Q0*/ const Word16 *speech16k_fx, /* i : input speech @16kHz Qx*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, + const Word16 Q_new ) { Word16 xn[L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ @@ -174,8 +174,13 @@ void encod_amr_wb_fx( * Innovation encoding *-----------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + inov_encode_fx( st, st->core_brate, 1, L_FRAME, st->last_L_frame, -1, -1, 0, i_subfr, -1, p_Aq, gain_pit, cn, + exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, L_SUBFR, shift, 0 ); +#else inov_encode_fx( st, st->core_brate, 1, L_FRAME, st->last_L_frame, -1, -1, 0, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, L_SUBFR, shift ); +#endif /*-----------------------------------------------------------------* * Gain encoding diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index 1cf5c793e8a08245c98ceb8257308a97699727a3..a68d5be4eff6ee6643d035d64b3e31a77b667291 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -77,7 +77,7 @@ static void rem_offset( /* RETURN ARGUMENTS : */ /* _ None */ /*======================================================================*/ - +#ifndef CLEANUP_ACELP_ENC void encod_gen_voic_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ @@ -240,7 +240,6 @@ void encod_gen_voic_fx( *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ - tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); /*-----------------------------------------------------------------* @@ -436,26 +435,31 @@ void encod_gen_voic_fx( return; } +#endif - +#ifdef CLEANUP_ACELP_ENC +void encod_gen_voic_fx( +#else void encod_gen_voic_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Qnew -1 */ + const Word16 speech_fx[], /* i : input speech Q0 / Qnew -1 */ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* i/o: core synthesis Q_new - 1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* i/o: current enhanced excitation Q_new*/ + Word16 *syn_fx, /* i/o: core synthesis Qnew / Q_new - 1*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0 / Q_new*/ + Word16 *exc2_fx, /* i/o: current enhanced excitation Q0 / Q_new*/ Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ Word16 *unbits_fx, /* i/o: number of unused bits 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 shift, - Word16 Q_new ) + const Word16 shift, /* i : Shift needed to obtain 12 bits vectors */ + const Word16 Q_new /* i : Scaling factor */ +) { Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ Word16 xn2_fx[L_SUBFR]; /* Target vector for codebook search */ @@ -550,7 +554,12 @@ void encod_gen_voic_ivas_fx( set16_fx( code_preQ_fx, 0, L_SUBFR ); shift_wsp = add( Q_new, shift ); +#ifdef CLEANUP_ACELP_ENC + test(); + if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_32( st_fx->element_mode, EVS_MONO ) ) +#else if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) +#endif { shift_wsp = sub( shift_wsp, 1 ); } @@ -587,21 +596,39 @@ void encod_gen_voic_ivas_fx( Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/ - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - q_h1 = sub( 14, norm_s( h1_fx[0] ) ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ - Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn_fx, L_SUBFR, shift ); - test(); - test(); - IF( Es_pred_fx < 0 && LE_16( i_subfr_fx, L_SUBFR ) && NE_16( st_fx->last_core, ACELP_CORE ) ) + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); /*Q11*/ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q(14+shift)*/ + + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); + } + ELSE +#endif { - /* During core transition, when the temporal correlation is non existent */ - rem_offset( xn_fx, xn_fx, L_SUBFR ); - rem_offset( cn_fx, cn_fx, L_SUBFR ); + find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); + + q_h1 = sub( 14, norm_s( h1_fx[0] ) ); + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ + Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ + + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); + + test(); + test(); + IF( Es_pred_fx < 0 && LE_16( i_subfr_fx, L_SUBFR ) && NE_16( st_fx->last_core, ACELP_CORE ) ) + { + /* During core transition, when the temporal correlation is non existent */ + rem_offset( xn_fx, xn_fx, L_SUBFR ); + rem_offset( cn_fx, cn_fx, L_SUBFR ); + } } /*----------------------------------------------------------------* @@ -612,13 +639,26 @@ void encod_gen_voic_ivas_fx( L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ move16(); +#ifdef CLEANUP_ACELP_ENC + tbe_celp_exc_fx( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); +#else tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); +#endif /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ - pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure @@ -645,9 +685,16 @@ void encod_gen_voic_ivas_fx( push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } -#ifdef FIX_2306_MISSING_UPDATE_LOWRATE_PITCH_GAIN - /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ - st_fx->hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, st_fx->hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#ifdef CLEANUP_ACELP_ENC +#ifndef FIX_2306_MISSING_UPDATE_LOWRATE_PITCH_GAIN + IF( st_fx->element_mode == EVS_MONO ) + { +#endif + /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ + st_fx->hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, st_fx->hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#ifndef FIX_2306_MISSING_UPDATE_LOWRATE_PITCH_GAIN + } +#endif #endif /*-----------------------------------------------------------------* @@ -657,17 +704,27 @@ void encod_gen_voic_ivas_fx( test(); IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) { +#ifdef CLEANUP_ACELP_ENC + transf_cdbk_enc_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, + xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); +#else transf_cdbk_enc_ivas_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); +#endif } /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx, + gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift, Q_new ); +#else inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx, gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift, Q_new ); +#endif /*-----------------------------------------------------------------* * Gain encoding @@ -703,7 +760,18 @@ void encod_gen_voic_ivas_fx( Lgcode = L_shl_sat( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */ + } + ELSE + { + hLPDmem->tilt_code = est_tilt_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR ); /* Q15 */ + } +#else hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR, 0 ); /* Q15 */ +#endif move16(); /*-----------------------------------------------------------------* @@ -713,38 +781,60 @@ void encod_gen_voic_ivas_fx( test(); IF( !st_fx->inactive_coder_type_flag && EQ_16( st_fx->coder_type, INACTIVE ) ) { +#ifdef CLEANUP_ACELP_ENC + transf_cdbk_enc_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, + Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); +#else transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); +#endif } /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ - /*At this point - xn has to be in Qnew - yn has to be in Qnew - y2_fx has to be in Q9 - gcode16 in Q_new - gain_pit_fx in Q14 - */ - Scale_sig( xn_fx, L_SUBFR, 1 ); - Scale_sig( y1_fx, L_SUBFR, 1 ); - /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); - Ltmp = L_negate( Ltmp ); - Word32 Ltmp2 = L_mult0( xn_fx[L_SUBFR - 1], 16384 ); - Ltmp = L_add( Ltmp, Ltmp2 ); - Word32 Ltmp3 = L_mult0( y1_fx[L_SUBFR - 1], gain_pit_fx ); - Ltmp = L_sub( Ltmp, Ltmp3 ); - - /*Ltmp is in Q14 + Qnew here - We need memWo in Qnew -1 */ +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); /*Q10*/ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); /*Q15+shift*/ + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 /*Q14*/ ); /* Q_new-1+shift+14+1 */ + Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx /*Q14*/ ); /* Q_new-1+shift+14+1 */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* 15 + Q_new */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + } + ELSE +#endif + { + /*At this point + xn has to be in Qnew + yn has to be in Qnew + y2_fx has to be in Q9 + gcode16 in Q_new + gain_pit_fx in Q14 + */ + Scale_sig( xn_fx, L_SUBFR, 1 ); + Scale_sig( y1_fx, L_SUBFR, 1 ); + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Word32 Ltmp2 = L_mult0( xn_fx[L_SUBFR - 1], 16384 ); + Ltmp = L_add( Ltmp, Ltmp2 ); + Word32 Ltmp3 = L_mult0( y1_fx[L_SUBFR - 1], gain_pit_fx ); + Ltmp = L_sub( Ltmp, Ltmp3 ); + + /*Ltmp is in Q14 + Qnew here + We need memWo in Qnew -1 */ + + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); // Q14 + Qnew + 1 + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + move16(); + } - Ltmp = L_shl( Ltmp, sub( 1, shift ) ); // Q14 + Qnew + 1 - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ - move16(); IF( gain_preQ_fx != 0 ) { tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); @@ -761,10 +851,10 @@ void encod_gen_voic_ivas_fx( move16(); /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ - Ltmp = L_shl( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ - Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/ - Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1 */ /* saturation can occur here Q16*/ + Ltmp = L_mult( gcode16, code_fx[i] ); /*Q10 / Qnew + 9 + 1 */ + Ltmp = L_shl( Ltmp, 5 ); /*Q15 / Qnew + 9+ 1+5 */ + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Q15 / Qnew + 14 + 1*/ + Ltmp = L_shl_sat( Ltmp, 1 ); /*Q15 / Qnew + 14 + 1 +1 */ exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); move16(); } @@ -780,10 +870,10 @@ void encod_gen_voic_ivas_fx( { /* code in Q9, gain_pit in Q14 */ /*gcode16 in Qnew*/ - Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ - Ltmp = L_shl_sat( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ - Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/ - Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1 */ + Ltmp = L_mult( gcode16, code_fx[i] ); /*Q10 / Qnew + 9 + 1 */ + Ltmp = L_shl_sat( Ltmp, 5 ); /*Q15 / Qnew + 9+ 1+5 */ + Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Q15 / Qnew + 14 + 1*/ + Ltmp = L_shl_sat( Ltmp, 1 ); /*Q15 / Qnew + 14 + 1 +1 */ exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp ); } } @@ -802,7 +892,16 @@ void encod_gen_voic_ivas_fx( * Update A(z) filters *-----------------------------------------------------------------*/ - syn_filt_fx( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); + } + ELSE +#endif + { + syn_filt_fx( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); + } p_Aw_fx += ( M + 1 ); p_Aq_fx += ( M + 1 ); @@ -816,6 +915,7 @@ void encod_gen_voic_ivas_fx( push_indice( hBstr, IND_UNUSED, 0, i ); unbits_PI_fx -= i; } + IF( st_fx->Opt_SC_VBR ) { /* SC-VBR */ diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 82296aa4ad975fb14cbef71e8efb3c2410ae8f78..a7afd750c7374a8efb72ad654454eabb821d7928 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -22,6 +22,7 @@ static void find_cn_fx( const Word16 xn[], const Word16 Ap[], const Word16 *p_Aq *-----------------------------------------------------------------*/ #define Q_MINUS 4 +#ifndef CLEANUP_ACELP_ENC void transf_cdbk_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ @@ -375,9 +376,13 @@ void transf_cdbk_enc_fx( return; } +#endif - +#ifdef CLEANUP_ACELP_ENC +void transf_cdbk_enc_fx( +#else void transf_cdbk_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ const Word16 i_subfr, /* i : subframe index Q0*/ @@ -490,7 +495,16 @@ void transf_cdbk_enc_ivas_fx( * Split algebraic vector quantizer based on RE8 lattice *--------------------------------------------------------------*/ - AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, Qdct ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, 0 ); + } + ELSE +#endif + { + AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, Qdct ); + } /*--------------------------------------------------------------* * Find prequantizer excitation gain diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 2d5902bc3306e274426b7c99c3abe8e1ebc64486..bd9c429b2db79a6774f5088a902b1d8bf4f93ffb 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -63,8 +63,8 @@ void enc_pit_exc_fx( 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 ) + const Word16 Q_new, + const Word16 shift ) { Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ @@ -374,6 +374,14 @@ void enc_pit_exc_fx( } ELSE IF( use_fcb == 2 ) { +#ifdef CLEANUP_ACELP_ENC + /*-----------------------------------------------------------------* + * 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, Q_new ); +#else #ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { @@ -390,6 +398,7 @@ void enc_pit_exc_fx( 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 ); } +#endif /*-----------------------------------------------------------------* * Gain encoding @@ -402,6 +411,11 @@ void enc_pit_exc_fx( /*-----------------------------------------------------------------* * Innovation & gain encoding *-----------------------------------------------------------------*/ + +#ifdef CLEANUP_ACELP_ENC + 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, Q_new ); +#else #ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { @@ -414,6 +428,7 @@ void enc_pit_exc_fx( 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 ); } +#endif /*-----------------------------------------------------------------* * Gain encoding @@ -432,12 +447,17 @@ void enc_pit_exc_fx( Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); + IF( use_fcb != 0 ) { #ifdef FIX_1904_HARM_GSC_ENC IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { +#ifdef CLEANUP_ACELP_ENC + hLPDmem->tilt_code = est_tilt_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr ); /* Q15 */ +#else hLPDmem->tilt_code = est_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr, 0 ); /* Q15 */ +#endif } ELSE #endif diff --git a/lib_enc/enc_ppp_fx.c b/lib_enc/enc_ppp_fx.c index 70360f9d2c281e2c988ab6e82ac103f5d98dd708..66ce8e4e181aafca763104474960476c0395671c 100644 --- a/lib_enc/enc_ppp_fx.c +++ b/lib_enc/enc_ppp_fx.c @@ -1,17 +1,15 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ -/*Temporary location to be move in prot* when merge is done */ -void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); /*=======================================================================================*/ /* FUNCTION : encod_ppp_fx() */ @@ -51,6 +49,7 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); /*---------------------------------------------------------------------------------------*/ /* CALLED FROM : TX */ /*=======================================================================================*/ + ivas_error encod_ppp_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q_new*/ @@ -63,8 +62,9 @@ ivas_error encod_ppp_fx( Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors, /* o : voicing factors Q15*/ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 879ed6dd038b6eb099713e169b84888e116fe48d..975f62337808659a4170f17c0d2b4355fb966ac0 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -43,7 +43,7 @@ /* RETURN ARGUMENTS : */ /* _ None */ /*---------------------------------------------------------------------------------*/ - +#ifndef CLEANUP_ACELP_ENC Word16 encod_tran_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ @@ -417,9 +417,13 @@ Word16 encod_tran_fx( return tc_subfr; } +#endif - +#ifdef CLEANUP_ACELP_ENC +Word16 encod_tran_fx( +#else Word16 encod_tran_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ @@ -480,8 +484,9 @@ Word16 encod_tran_ivas_fx( L_frame_fx = st_fx->L_frame; move16(); +#ifndef CLEANUP_ACELP_ENC set16_fx( h1, 0, L_SUBFR + ( M + 1 ) ); - +#endif /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ @@ -523,7 +528,12 @@ Word16 encod_tran_ivas_fx( move16(); set16_fx( code_preQ, 0, L_SUBFR ); shift_wsp = add( Q_new, shift ); +#ifdef CLEANUP_ACELP_ENC + test(); + if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_32( st_fx->element_mode, EVS_MONO ) ) +#else if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) +#endif { shift_wsp = sub( shift_wsp, 1 ); } @@ -542,20 +552,33 @@ Word16 encod_tran_ivas_fx( Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, - res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - - q_h1 = sub( 14, norm_s( h1[0] ) ); - tmp = sub( 14, norm_arr( h1, L_SUBFR ) ); - shift = sub( q_h1, tmp ); /* shift is initialized to shift_r ( to 0) at the beginning of the scope, re-compute shift_wsp in case it has changed */ - shift_wsp = add( Q_new, shift ); - if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 ); + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + } + ELSE +#endif { - shift_wsp = sub( shift_wsp, 1 ); + find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + + q_h1 = sub( 14, norm_s( h1[0] ) ); + tmp = sub( 14, norm_arr( h1, L_SUBFR ) ); + shift = sub( q_h1, tmp ); /* shift is initialized to shift_r ( to 0) at the beginning of the scope, re-compute shift_wsp in case it has changed */ + shift_wsp = add( Q_new, shift ); + if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } + Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ + Scale_sig( h1, L_SUBFR, add( sub( 14, q_h1 ), shift ) ); } - Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ - Scale_sig( h1, L_SUBFR, add( sub( 14, q_h1 ), shift ) ); + /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_SUBFR, shift ); @@ -564,8 +587,13 @@ Word16 encod_tran_ivas_fx( * adaptive/glottal part of excitation construction *-----------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + transition_enc_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1, + h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift ); +#else transition_enc_ivas_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1, h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift ); +#endif /*-----------------------------------------------------------------* * Transform domain contribution encoding - active frames @@ -573,16 +601,26 @@ Word16 encod_tran_ivas_fx( IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { +#ifdef CLEANUP_ACELP_ENC + transf_cdbk_enc_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, + &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift ); +#else transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift ); +#endif } /*-----------------------------------------------------------------* * ACELP codebook search + pitch sharpening *-----------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, + i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); +#else inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); +#endif test(); test(); @@ -624,14 +662,36 @@ Word16 encod_tran_ivas_fx( Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); + +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ + } + ELSE + { + hLPDmem->tilt_code = est_tilt_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR ); // Q15 + } + move16(); +#else hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15 +#endif /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/ - L_tmp = L_mult0( gcode16, y2[L_SUBFR - 1] ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + L_tmp = L_mult( gcode16, y2[L_SUBFR - 1] ); /* Q10 + Q_new */ + } + ELSE +#endif + { + L_tmp = L_mult0( gcode16, y2[L_SUBFR - 1] ); + } L_tmp = L_shl( L_tmp, add( 5, shift ) ); // Q_new+14+shift L_tmp = L_negate( L_tmp ); L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 ); // Q_new-1+15+shift @@ -654,7 +714,7 @@ Word16 encod_tran_ivas_fx( { FOR( i = 0; i < L_SUBFR; i++ ) { - exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_exc */ + exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_new / Q_exc */ } } ELSE @@ -662,7 +722,7 @@ Word16 encod_tran_ivas_fx( Gain_pitX2 = shl( gain_pit, 1 ); FOR( i = 0; i < L_SUBFR; i++ ) { - exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_exc */ + exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_new / Q_exc */ } } diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index eb614935941d19c4b4c467a5fd05438dc2e914db..de7f281f282daf3e4e8858b9fb5c8471962a9ee7 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -16,7 +16,7 @@ * * Encode unvoiced (UC) frames *-------------------------------------------------------------------*/ - +#ifndef CLEANUP_ACELP_ENC void encod_unvoiced_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 *speech_fx, /* i : Input speech Q_new*/ @@ -247,24 +247,29 @@ void encod_unvoiced_fx( return; } +#endif - +#ifdef CLEANUP_ACELP_ENC +void encod_unvoiced_fx( +#else void encod_unvoiced_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: state structure */ const Word16 *speech_fx, /* i : Input speech Q_new*/ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* o : core synthesis Q_new*/ + Word16 *syn_fx, /* o : core synthesis Q_new-1 (EVS) / Qnew*/ Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ - const Word16 Q_new, - const Word16 shift ) + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ @@ -280,7 +285,7 @@ void encod_unvoiced_ivas_fx( Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ Word16 code2[L_SUBFR]; /* Gaussian excitation */ Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */ - // Word16 prm_t[2 * NPRM_DIV], *prm = prm_t; + Word16 prm_t[2 * NPRM_DIV], *prm = prm_t; const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ Word32 norm_gain_code_fx; ACELP_config *acelp_cfg; @@ -329,12 +334,25 @@ void encod_unvoiced_ivas_fx( i_subfr_idx = shr( i_subfr, 6 ); Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); + + /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + } + ELSE +#endif + { + find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - q_h1 = sub( 14, norm_s( h1_fx[0] ) ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); - Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); + q_h1 = sub( 14, norm_s( h1_fx[0] ) ); + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); + Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); + } /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift @@ -366,16 +384,36 @@ void encod_unvoiced_ivas_fx( *-----------------------------------------------------------------*/ Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); + *pt_pitch_fx = L_SUBFR << 6; move16(); +#ifdef CLEANUP_ACELP_ENC + if ( st_fx->element_mode == EVS_MONO ) + { + *pt_pitch_fx = L_SUBFR; + move16(); + } +#endif /*----------------------------------------------------------------------* * Encode the algebraic innovation * *----------------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate ); + } + ELSE + { + inov_encode_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx, + gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); + } +#else inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx, gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); +#endif E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn ); @@ -389,7 +427,16 @@ void encod_unvoiced_ivas_fx( move16(); assert( gain_pit_fx == 0 ); - gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) + { + gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); + } + ELSE +#endif + { + gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); + } /*----------------------------------------------------------* * - Compute the fixed codebook gain * diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index b2800da5bbf5dc972883570367762f07e53b0c7d..0498c0c339ae05f1d570273c3a44968100bd27c8 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -14,7 +14,7 @@ * Local function prototypes *-------------------------------------------------------------------*/ -static Word16 edyn_fx( const Word16 *vec, const Word16 lvec, Word16 Qnew ); +static Word16 edyn_fx( const Word16 *vec, const Word16 lvec, const Word16 Qnew ); /*-------------------------------------------------------------------* @@ -39,8 +39,9 @@ void encod_audio_fx( Word16 *tmp_noise, /* o : noise energy Q2 */ 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 ) + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { const Word16 *p_Aq; Word16 i, i_subfr, nb_subfr, last_pit_bin; @@ -1527,7 +1528,7 @@ void gsc_enc_ivas_fx( static Word16 edyn_fx( const Word16 *vec, /* i : input vector Qnew*/ const Word16 lvec, /* i : length of input vector */ - Word16 Qnew ) + const Word16 Qnew ) { Word16 j = 0; Word16 dyn; diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 81b9ba49e904333c5881cfc372e0e98dfe11db49..a1da64adfd7cd14bad83a66a888c9239df0845bf 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -54,7 +54,7 @@ /* RETURN ARGUMENTS : */ /* _ None */ /*==============================================================================*/ - +#ifndef CLEANUP_ACELP_ENC Word16 inov_encode_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 core_brate, /* i : core bitrate */ @@ -340,9 +340,13 @@ Word16 inov_encode_fx( return stack_pulses; } +#endif - +#ifdef CLEANUP_ACELP_ENC +Word16 inov_encode_fx( +#else Word16 inov_encode_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ @@ -365,7 +369,7 @@ Word16 inov_encode_ivas_fx( Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ Word16 *unbits, /* o : number of unused bits for PI */ const Word16 L_subfr, /* i : subframe length */ - Word16 shift, + const Word16 shift, Word16 Q_new ) { Word16 dn[2 * L_SUBFR], Qdn, Qcn, Qh2; @@ -395,16 +399,38 @@ Word16 inov_encode_ivas_fx( move16(); } - maximum_abs_16_fx( xn2, L_subfr, &max_xn2 ); - IF( max_xn2 ) +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) +#endif { - Qxn = add( sub( Q_new, 1 ), shift ); + maximum_abs_16_fx( xn2, L_subfr, &max_xn2 ); + IF( max_xn2 ) + { + Qxn = add( sub( Q_new, 1 ), shift ); + } + ELSE + { + Qxn = 0; + move16(); + } +#ifdef CLEANUP_ACELP_ENC + + Qcn = Q_new; + move16(); +#endif } +#ifdef CLEANUP_ACELP_ENC ELSE { + Q_new = 0; + move16(); + Qxn = 0; move16(); + Qcn = 0; + move16(); } +#endif /*----------------------------------------------------------------* * Update target vector for codebook search in residual domain @@ -414,8 +440,10 @@ Word16 inov_encode_ivas_fx( test(); test(); +#ifndef CLEANUP_ACELP_ENC Qcn = Q_new; move16(); +#endif IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) ) { acelpautoc = 1; @@ -436,23 +464,42 @@ Word16 inov_encode_ivas_fx( acelpautoc = 0; move16(); updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr ); + /* scaling of cn[] to limit dynamic at 12 bits */ Scale_sig( cn, L_subfr, shift ); - Word16 q_h1 = sub( 14, norm_s( h2[0] ) ); - Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/ - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 - IF( LT_16( Qdn, Qcn ) ) + +#ifdef CLEANUP_ACELP_ENC + IF( st_fx->element_mode == EVS_MONO ) { - scale_sig( cn, L_subfr, sub( Qdn, Qcn ) ); - Qcn = Qdn; + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); + + corr_xh_fx( xn2, dn, h2 ); + + Qdn = 0; move16(); } ELSE +#endif { - scale_sig( dn, L_subfr, sub( Qcn, Qdn ) ); - Qdn = Qcn; - move16(); + Word16 q_h1 = sub( 14, norm_s( h2[0] ) ); + Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/ + + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); + + corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 + + IF( LT_16( Qdn, Qcn ) ) + { + scale_sig( cn, L_subfr, sub( Qdn, Qcn ) ); + Qcn = Qdn; + move16(); + } + ELSE + { + scale_sig( dn, L_subfr, sub( Qcn, Qdn ) ); + Qdn = Qcn; + move16(); + } } } @@ -584,8 +631,13 @@ Word16 inov_encode_ivas_fx( set16_fx( y2, 0, L_SUBFR ); - Qh2 = sub( 14, norm_s( h2[0] ) ); - Scale_sig( h2, L_SUBFR, sub( Q12, Qh2 ) ); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) +#endif + { + Qh2 = sub( 14, norm_s( h2[0] ) ); + Scale_sig( h2, L_SUBFR, sub( Q12, Qh2 ) ); + } IF( !Opt_AMR_WB ) { @@ -683,7 +735,7 @@ Word16 inov_encode_ivas_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr >> 6]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; move16(); diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 2ee800325cef8975c0e7de509bf72419d0120ab9..c19ec47dbb63706630e15da26ed3b8526d9c7f2c 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -647,7 +647,11 @@ ivas_error ivas_core_enc_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + core_switching_post_enc_ivas_fx( st ); +#else core_switching_post_enc_ivas_fx( st, old_inp_12k8_fx[n], old_inp_16k_fx[n], A_fx[n], Q_new[n] ); +#endif /*---------------------------------------------------------------------* * WB TBE encoding diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index ef28b3c0ae1fc88453345b400f74a46e3adce2a5..b1018b917f39f590fcea671e93336ff47e9eb82a 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -47,20 +47,20 @@ * Encode secondary channel of TD Stereo with a low-bitrate encoder *-------------------------------------------------------------------*/ -void tdm_low_rate_enc( - Encoder_State *st, /* i/o: State structure */ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 *res, /* i : residual signal Q_new*/ - Word16 *synth, /* i/o: core synthesis Q_new*/ - Word16 *exc_fx, /* 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_fx, /* o : excitation for SWB TBE Q_new*/ - const Word16 attack_flag, /* i : GSC attack flag Q0*/ - const Word16 *lsf_new, /* i : current frame ISF vector Qx2.56*/ - Word16 *tmp_noise, /* o : long-term noise energy Q11*/ - Word16 Q_new ) +void tdm_low_rate_enc_fx( + Encoder_State *st, /* i/o: State structure */ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 *res, /* i : residual signal Q_new*/ + Word16 *synth, /* i/o: core synthesis Q_new*/ + Word16 *exc_fx, /* 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_fx, /* o : excitation for SWB TBE Q_new*/ + const Word16 attack_flag, /* i : GSC attack flag Q0*/ + const Word16 *lsf_new, /* i : current frame ISF vector Qx2.56*/ + Word16 *tmp_noise, /* o : long-term noise energy Q11*/ + const Word16 Q_new /* i : Scaling factor */ +) { const Word16 *p_Aq; Word16 i_subfr, nb_subfr, last_pit_bin; @@ -183,8 +183,8 @@ void tdm_low_rate_enc( * Encode GC, 2 subframes mode *-------------------------------------------------------------------*/ -void encod_gen_2sbfr( - Encoder_State *st, /* i/o: state structure */ +void encod_gen_2sbfr_fx( + Encoder_State *st, /* i/o: state structure */ const Word16 speech[], /* i : input speech Q_new-1 */ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes e(norm_s(Aw[0]+1)*/ const Word16 Aq[], /* i : LP coefficients e(norm_s(Aw[0]+1)*/ @@ -195,10 +195,11 @@ void encod_gen_2sbfr( 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 Q_new */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : pitch values for primary channel Q4 */ - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { Word16 xn[2 * L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[2 * L_SUBFR]; /* Target vector for codebook search */ @@ -288,7 +289,11 @@ void encod_gen_2sbfr( Scale_sig( h1, 2 * L_SUBFR, sub( 13, q_h1 ) ); // Q13 +#ifdef CLEANUP_ACELP_ENC + tbe_celp_exc_fx( st->element_mode, st->idchan, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, st->tdm_LRTD_flag ); +#else tbe_celp_exc_ivas( st->element_mode, st->idchan, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, st->tdm_LRTD_flag ); +#endif /*-----------------------------------------------------------------* * Find adaptive exitation @@ -322,14 +327,17 @@ void encod_gen_2sbfr( * Innovation encoding *-----------------------------------------------------------------*/ +#ifdef CLEANUP_ACELP_ENC + inov_encode_fx( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, st->sharpFlag, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &i, 2 * L_SUBFR, shift, Q_new ); +#else inov_encode_ivas_fx( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, st->sharpFlag, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &i, 2 * L_SUBFR, shift, Q_new ); +#endif /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - gain_enc_lbr_fx( st->hBstr, st->acelp_cfg.gains_mode, coder_type, i_subfr, xn, y1, add( sub( Q_new, 1 ), shift ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, - st->element_mode ); + gain_enc_lbr_fx( st->hBstr, st->acelp_cfg.gains_mode, coder_type, i_subfr, xn, y1, add( sub( Q_new, 1 ), shift ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, st->element_mode ); IF( st->Opt_SC_VBR ) { @@ -347,9 +355,14 @@ void encod_gen_2sbfr( gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); - Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_sat( Lgcode ); /*Q0*/ + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); /*Q0*/ + +#ifdef CLEANUP_ACELP_ENC + hLPDmem->tilt_code = est_tilt_fx( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, Q_new, 2 * L_SUBFR ); /* Q15 */ +#else hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, Q_new, 2 * L_SUBFR, 0 ); /* Q15 */ +#endif move16(); /*-----------------------------------------------------------------* diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 41078054cea37891352a3551c8538cc8db507a13..756ee4ac3b8ecfc06ec0bd61c050370787cac222 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -650,7 +650,7 @@ void noise_est_down_fx( Word16 Etot, /* i : Energy of current frame */ Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ - Word16 Q_new, + const Word16 Q_new, const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 13d11e72b0f9c1040975955ac25ed82b0afdb10b..ce74ed5a54e1855f4286db7b5ef598254971f40a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -78,7 +78,7 @@ void analy_lp_fx( const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ const Word16 element_mode, /* i : element mode */ const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /* i : stores Q for speech */ + const Word16 Q_new, /* i : stores Q for speech */ Word16 *Q_r /*stores q for ener*/ ); @@ -322,7 +322,7 @@ void noise_est_down_fx( Word16 Etot, /* i : Energy of current frame */ Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ - Word16 Q_new, + const Word16 Q_new, const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ ); @@ -1880,6 +1880,7 @@ void encod_nelp_ivas_fx( Word16 shift ); Word16 encod_tran_fx( +#ifndef CLEANUP_ACELP_ENC Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ @@ -1900,6 +1901,7 @@ Word16 encod_tran_fx( ); Word16 encod_tran_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ @@ -2007,10 +2009,12 @@ void encod_unvoiced_fx( Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ - const Word16 Q_new, - const Word16 shift ); + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +); +#ifndef CLEANUP_ACELP_ENC void encod_unvoiced_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 *speech_fx, /* i : Input speech Q_new*/ @@ -2027,7 +2031,7 @@ void encod_unvoiced_ivas_fx( Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ const Word16 Q_new, const Word16 shift ); - +#endif void enc_acelp_tcx_main_fx( const Word16 new_samples[], /* i : new samples Q15*/ Encoder_State *st, /* i/o: encoder state structure */ @@ -2047,14 +2051,15 @@ ivas_error encod_ppp_fx( const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q14*/ Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *synth_fx, /* o : core synthesis Q-1*/ + Word16 *synth_fx, /* o : core synthesis Q-1*/ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ Word16 *exc2_fx, /* o : current enhanced excitation Q0*/ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, - Word16 shift ); + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +); ivas_error encod_ppp_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ @@ -2072,6 +2077,7 @@ ivas_error encod_ppp_ivas_fx( Word16 shift ); void encod_gen_voic_fx( +#ifndef CLEANUP_ACELP_ENC Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : i speech Q0*/ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ @@ -2091,6 +2097,7 @@ void encod_gen_voic_fx( Word16 Q_new ); void encod_gen_voic_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ @@ -2104,14 +2111,15 @@ void encod_gen_voic_ivas_fx( Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ Word16 *unbits_fx, /* i/o: number of unused bits 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 shift, - Word16 Q_new ); + 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*/ + const Word16 shift, /* i : Shift needed to obtain 12 bits vectors */ + const Word16 Q_new /* i : Scaling factor */ +); void encod_audio_fx( Encoder_State *st_fx, /* i/o: State structure */ - const Word16 speech[], /* i : i speech Q_new */ + const Word16 speech[], /* i : input speech Q_new */ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ const Word16 Aq[], /* i : 12k8 Lp coefficient */ const Word16 *res, /* i : residual signal Q_new */ @@ -2119,15 +2127,17 @@ void encod_audio_fx( 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 */ + 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 */ Word16 *tmp_noise, /* o : noise energy */ 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 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +); +#ifndef CLEANUP_ACELP_ENC void encod_audio_ivas_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 speech[], /* i : input speech Q_new */ @@ -2146,7 +2156,7 @@ void encod_audio_ivas_fx( const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, Word16 shift ); - +#endif void stat_noise_uv_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors */ @@ -2558,8 +2568,8 @@ void coder_tcx_post_fx( const Word16 *A, const Word16 *Ai, Word16 *wsig, - Word16 Q_new, - Word16 shift ); + const Word16 Q_new, + const Word16 shift ); void coder_tcx_post_ivas_fx( Encoder_State *st, @@ -3513,6 +3523,7 @@ Word16 lp_filt_exc_enc_fx( ); Word16 inov_encode_fx( +#ifndef CLEANUP_ACELP_ENC Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ @@ -3537,7 +3548,8 @@ Word16 inov_encode_fx( const Word16 L_subfr, /* i : subframe length */ Word16 shift ); -Word16 inov_encode_ivas_fx( +Word16 inov_encode_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ @@ -3560,7 +3572,7 @@ Word16 inov_encode_ivas_fx( Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ Word16 *unbits, /* o : number of unused bits for PI */ const Word16 L_subfr, /* i : subframe length */ - Word16 shift, + const Word16 shift, Word16 Q_new ); void gain_enc_mless_fx( @@ -3608,7 +3620,7 @@ void analy_lp_AMR_WB_fx( Word16 isf_new[], /* o : current frame ISPs Q15*/ Word16 Top, /* i : open loop pitch lag Q0*/ Word16 Tnc, /* i : open loop pitch gain Qx*/ - Word16 Q_new, + const Word16 Q_new, Word16 *Q_r ); void encod_amr_wb_fx( @@ -3623,8 +3635,8 @@ void encod_amr_wb_fx( Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6*/ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain Q0*/ const Word16 *speech16k_fx, /* i : i speech @16kHz Qx*/ - Word16 shift, - Word16 Q_new ); + const Word16 shift, + const Word16 Q_new ); void re8_cod_fx( Word16 x[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ @@ -3644,9 +3656,10 @@ void acelp_core_switch_enc_fx( const Word16 inp12k8[], /* i : i signal @12.8 kHz Q0 */ const Word16 inp16k[], /* i : i signal @16 kHz Q0 */ const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12 */ - Word16 shift, - Word16 Q_new ); + const Word16 shift, + const Word16 Q_new ); +#ifndef CLEANUP_ACELP_ENC void acelp_core_switch_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 inp12k8[], /* i : i signal @12.8 kHz Q0 */ @@ -3654,7 +3667,7 @@ void acelp_core_switch_enc_ivas_fx( const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12 */ Word16 shift, Word16 Q_new ); - +#endif void gain_enc_amr_wb_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *xn, /* i : target vector Q_xn*/ @@ -3714,6 +3727,7 @@ void transf_cdbk_enc_fx( const Word16 shift /* i : shifting applied to y1, xn,... */ ); +#ifndef CLEANUP_ACELP_ENC void transf_cdbk_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ @@ -3738,7 +3752,7 @@ void transf_cdbk_enc_ivas_fx( const Word16 Q_new, /* i : Current frame scaling */ const Word16 shift /* i : shifting applied to y1, xn,... */ ); - +#endif void gain_enc_lbr_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 gains_mode[], /* i : gain bits Q0*/ @@ -3848,6 +3862,7 @@ void transition_enc_fx( Word16 shift /* i : downscaling needs for 12 bits convolutions */ ); +#ifndef CLEANUP_ACELP_ENC void transition_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 i_subfr, /* i : subframe index */ @@ -3873,7 +3888,7 @@ void transition_enc_ivas_fx( Word16 Q_new, /* i : Current scaling */ Word16 shift /* i : downscaling needs for 12 bits convolutions */ ); - +#endif void gain_enc_tc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 gains_mode[], /* i : gain bits Q0*/ @@ -4010,8 +4025,8 @@ void enc_pit_exc_fx( 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 ); + 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 */ diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 547502eab143cc2523cafebe01e169a2474fb28d..5ec3fe6882057f2fa1598200f92f9095119bc0b6 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -16,7 +16,9 @@ static void gain_trans_enc_fx( Word32 gain_trans32, Word16 exc[], Word16 *quant_index, Word16 *quant_sign, Word16 Q_new ); static void tc_enc_fx( Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new ); +#ifndef CLEANUP_ACELP_ENC static void tc_enc_ivas_fx( Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new ); +#endif /*==========================================================================*/ @@ -163,14 +165,29 @@ void transition_enc_fx( move16(); *clip_gain = 0; move16(); - g_corr_fx[0] = 16384; - move16(); - g_corr_fx[1] = add( shl( sub( shift_wsp, 1 ), 1 ), 1 ); - move16(); - g_corr_fx[2] = -16384; - move16(); - g_corr_fx[3] = shl( sub( shift_wsp, 1 ), 1 ); - move16(); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + g_corr_fx[0] = MAX16B /* 1.0f in Q15 */; + move16(); + g_corr_fx[1] = 0; + move16(); + g_corr_fx[2] = MAX16B /* 1.0f in Q15 */; + move16(); + g_corr_fx[3] = 0; + } + ELSE +#endif + { + g_corr_fx[0] = 16384; + move16(); + g_corr_fx[1] = add( shl( sub( shift_wsp, 1 ), 1 ), 1 ); + move16(); + g_corr_fx[2] = -16384; + move16(); + g_corr_fx[3] = shl( sub( shift_wsp, 1 ), 1 ); + move16(); + } set16_fx( &exc_fx[i_subfr], 0, L_SUBFR ); /* set excitation for current subrame to 0 */ @@ -197,6 +214,7 @@ void transition_enc_fx( /*-----------------------------------------------------------------* * glottal codebook contribution construction *-----------------------------------------------------------------*/ + ELSE IF( EQ_16( *tc_subfr, i_subfr ) ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -395,7 +413,16 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -443,11 +470,19 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; @@ -508,7 +543,16 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -533,11 +577,19 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; @@ -571,7 +623,16 @@ void transition_enc_fx( pit_Q_enc_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -807,10 +868,26 @@ void transition_enc_fx( move16(); *clip_gain = 0; move16(); - g_corr_fx[0] = 0; - move16(); - g_corr_fx[1] = 0; - move16(); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + g_corr_fx[0] = 328 /* 0.01f in Q15 */; + move16(); + g_corr_fx[1] = 0; + move16(); + g_corr_fx[2] = 328 /* 0.01f in Q15 */; + move16(); + g_corr_fx[3] = 0; + move16(); + } + ELSE +#endif + { + g_corr_fx[0] = 0; + move16(); + g_corr_fx[1] = 0; + move16(); + } *Jopt_flag = 0; move16(); @@ -824,7 +901,17 @@ void transition_enc_fx( ELSE { /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef CLEANUP_ACELP_ENC + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + offset = L_deposit_l( 0 ); tmp = extract_l( L_mult( *T0_frac, 32 ) ); /*Q8, 0.25 in Q7*/ @@ -889,6 +976,7 @@ void transition_enc_fx( return; } +#ifndef CLEANUP_ACELP_ENC void transition_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 i_subfr, /* i : subframe index */ @@ -1717,7 +1805,7 @@ void transition_enc_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------------------------------* * tc_enc() @@ -1959,7 +2047,7 @@ static void tc_enc_fx( return; } - +#ifndef CLEANUP_ACELP_ENC static void tc_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 i_subfr, /* i : subrame index */ @@ -2180,7 +2268,7 @@ static void tc_enc_ivas_fx( move16(); return; } - +#endif /*-----------------------------------------------------------------* * gain_trans_enc()