diff --git a/lib_com/options.h b/lib_com/options.h index a5d5a4846c8ca6a0005aa7ef7bd9e2c4e3582dbd..a6ff23165c3283875aa18afa7e633656118dd207 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -104,6 +104,19 @@ #define TEST_HR #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ + +#define REUSE_EVS_ACELP +#ifdef REUSE_EVS_ACELP +//#define USE_NEW_TARGET +#define REUSE_EVS_ACELP_GEN +#define REUSE_EVS_ACELP_SHIFT +#define REUSE_EVS_ACELP_TC +#endif +#define REUSE_EVS_ACELP_2t32 +#define REUSE_EVS_ACELP_1t64 +#define USE_UC_EVS + +//#define REUSE_EVS_TBE_CELP_EXC // to be done , just a line to be added #define FIX_1713_EXP /* VA: proposed correction to exp in ic-BWE*/ #endif diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index f942a19ffd8db288686cc7642b6d994b245bef14..b27784c25b1494d2c37bf5179106182604d67642 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -775,6 +775,9 @@ ivas_error acelp_core_enc_ivas_fx( Word16 att_fx; Word16 tmpF_fx; +#ifdef REUSE_EVS_ACELP + Word16 shift = 0; +#endif test(); IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) @@ -1293,6 +1296,22 @@ ivas_error acelp_core_enc_ivas_fx( *---------------------------------------------------------------*/ calc_residu_fx( st, inp, res_fx, Aq ); +#ifdef REUSE_EVS_ACELP_SHIFT // This should be moved outside of ACELP + { + Word16 tmp, max; + max = 0; + FOR( i = 0; i < st->L_frame; i++ ) + { + tmp = s_max( abs_s( res_fx[i] ), abs_s( inp[i] ) ); + max = s_max( max, tmp ); + } + + shift = sub( norm_s( max ), 3 ); + shift = s_min( shift, 0 ); + // if ( shift != 0 ) + // printf( "shift %d\n", shift ); + } +#endif calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) ) @@ -1347,11 +1366,19 @@ ivas_error acelp_core_enc_ivas_fx( ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ +#ifndef USE_UC_EVS 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 ); +#else + encod_unvoiced_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); +#endif } ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { +#ifdef REUSE_EVS_ACELP_TC + encod_tran_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new ); +#else encod_tran_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 ) { @@ -1378,7 +1405,11 @@ ivas_error acelp_core_enc_ivas_fx( move16(); /* VOICED frames in SC-VBR */ +#ifdef REUSE_EVS_ACELP + encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); +#else encod_gen_voic_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 ) ) @@ -1389,7 +1420,11 @@ ivas_error acelp_core_enc_ivas_fx( ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ +#ifdef REUSE_EVS_ACELP + encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); +#else encod_gen_voic_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 76fa6f151d2f431e7062f1a41b00a099016082d7..d0f553bafd6543e32bb3c18c7a232ff33c53e4cb 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -16,9 +16,9 @@ *---------------------------------------------------------------------*/ 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 ); - +#ifndef REUSE_EVS_ACELP 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 ); - +#endif static void bwe_switch_enc_fx( Encoder_State *st_fx, const Word16 *new_speech ); static void bwe_switch_enc_ivas_fx( Encoder_State *st_fx, const Word16 *new_speech ); @@ -262,8 +262,11 @@ void acelp_core_switch_enc_ivas_fx( config_acelp1_fx( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); +#ifndef REUSE_EVS_ACELP encod_gen_voic_core_switch_ivas_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); - +#else + encod_gen_voic_core_switch_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); +#endif /*----------------------------------------------------------------* * bit-stream: modify the layer of sub frame CELP *----------------------------------------------------------------*/ @@ -505,7 +508,7 @@ static void encod_gen_voic_core_switch_fx( return; } - +#ifndef REUSE_EVS_ACELP 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*/ @@ -718,7 +721,7 @@ static void encod_gen_voic_core_switch_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------* * bwe_switch_enc() diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index b3a49c59ef44f47907cd76b13c71eb34b8156521..1e9c714647c45167ce9fc2b8288a214e9bb42fce 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -182,7 +182,9 @@ void AVQ_encmux_fx( Word16 bitsMod, Nsvm1, Nsvm2; Word16 unusedbitsFlag; Word16 svOrder[NSV_MAX], k, nullVec, dummy_bits; - +#ifdef REUSE_EVS_ACELP + Word16 tmp; +#endif test(); IF( EQ_16( extl, SWB_BWE_HIGHRATE ) || EQ_16( extl, FB_BWE_HIGHRATE ) ) { @@ -344,7 +346,19 @@ void AVQ_encmux_fx( test(); test(); test(); +#ifdef REUSE_EVS_ACELP + tmp = bits; + move16(); + WHILE( GE_16( tmp, 5 ) ) + { + tmp = sub( tmp, 5 ); + } + assert( tmp == bits % 5 ); + IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( tmp, 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, Nsvm1 ) ) + +#else IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( s_and( bits, 4 ), 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, Nsvm1 ) ) +#endif { ordr_esti( sub( Nsv, i ), &trgtSvPos, &svOrder[i], Nsv ); k = svOrder[i]; @@ -408,8 +422,19 @@ void AVQ_encmux_fx( test(); IF( avq_bit_sFlag > 0 && GT_16( bits, 8 ) ) { +#ifndef REUSE_EVS_ACELP // PMT("code not validated yet") bitsMod = s_and( bits, 4 /*bits%5*/ ); +#else + /* bitsMod = bits % 5;*/ + bitsMod = bits; + move16(); + WHILE( bitsMod >= 5 ) + { + bitsMod = sub( bitsMod, 5 ); + } + assert( bitsMod == bits % 5 ); +#endif i = svOrder[Nsvm1]; move16(); IF( NE_16( i, Nsvm1 ) ) @@ -449,7 +474,17 @@ void AVQ_encmux_fx( { overflow = 0; move16(); +#ifdef REUSE_EVS_ACELP + tmp = add( bitsMod, nullVec ); + WHILE( tmp >= 5 ) + { + tmp = sub( tmp, 5 ); + } + assert( tmp == add( bitsMod, nullVec ) % 5 ); + if ( tmp != 0 ) +#else if ( s_and( add( bitsMod, nullVec ), 4 ) != 0 ) +#endif { overflow = 1; move16(); @@ -476,7 +511,18 @@ void AVQ_encmux_fx( unused_bits = sub( unused_bits, 1 ); /*Stop Bit*/ } /*unused_bits_idx = (int16_t)unused_bits / 5;*/ +#ifdef REUSE_EVS_ACELP + IF( unused_bits >= 0 ) + { + unused_bits_idx = mult( unused_bits, 6554 /*1/5 in Q15*/ ); + } + ELSE + { + unused_bits_idx = negate( mult( negate( unused_bits ), 6554 /*1/5 in Q15*/ ) ); + } +#else unused_bits_idx = mult( unused_bits, 6554 ); +#endif assert( unused_bits_idx == unused_bits / 5 ); unusedbitsFlag = 0; move16(); @@ -506,7 +552,11 @@ void AVQ_encmux_fx( IF( j > 0 ) { /* write the unary code */ +#ifdef REUSE_EVS_ACELP + push_indice( hBstr, nq_ind, u_extract_l( L_sub( L_shl_sat( 1, j ), 1 ) ), j ); +#else push_indice( hBstr, nq_ind, sub( shl( 1, j ), 1 ), j ); +#endif } IF( nq[i] != 0 ) diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index dc967e656015c19b31d029321709cc01eef3608d..b8134388a4db86c7d95f1fbe86a8a32b7f540c87 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -296,7 +296,7 @@ void acelp_2t32_fx( } return; } - +#ifndef REUSE_EVS_ACELP_2t32 void acelp_2t32_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 dn[], /* i : corr. between target and h[]. Qx*/ @@ -568,6 +568,7 @@ void acelp_2t32_ivas_fx( } return; } +#endif /*---------------------------------------------------------------------------------- * Function acelp_1t64() * @@ -645,7 +646,7 @@ void acelp_1t64_fx( return; } - +#ifndef REUSE_EVS_ACELP_1t64 void acelp_1t64_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 dn[], /* i : corr. between target and h[]. Qx */ @@ -714,3 +715,4 @@ void acelp_1t64_ivas_fx( return; } +#endif diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 56b22c2069b96dd3ce2e6b283ebd2c5e7ccfb8ca..243b7c5966bacefbfb94ee65079c4a67ca28ba87 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -27,10 +27,18 @@ void corr_xh_fx( const Word16 x[], /* i : target signal Qx*/ Word16 dn[], /* o : correlation between x[] and h[] Qdn = Qx+j-1*/ const Word16 h[] /* i : impulse response (of weighted synthesis filter) Q14*/ +#ifdef REUSE_EVS_ACELP + , + const Word16 L_subfr /* i : sub-frame lenght Q0 */ +#endif ) { Word16 i, j, k; +#ifdef REUSE_EVS_ACELP + Word32 L_tmp, y32[2 * L_SUBFR], L_maxloc, L_tot; +#else Word32 L_tmp, y32[L_SUBFR], L_maxloc, L_tot; +#endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); @@ -42,10 +50,18 @@ void corr_xh_fx( FOR( k = 0; k < NB_TRACK; k++ ) { L_maxloc = L_deposit_l( 0 ); +#ifdef REUSE_EVS_ACELP + FOR( i = k; i < L_subfr; i += STEP ) +#else FOR( i = k; i < L_SUBFR; i += STEP ) +#endif { L_tmp = L_mac( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] Qx+15*/ +#ifdef REUSE_EVS_ACELP + FOR( j = i; j < L_subfr - 1; j++ ) +#else FOR( j = i; j < L_SUBFR - 1; j++ ) +#endif { L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); /*Qx+15*/ } @@ -66,7 +82,11 @@ void corr_xh_fx( j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */ +#ifdef REUSE_EVS_ACELP + FOR( i = 0; i < L_subfr; i++ ) +#else FOR( i = 0; i < L_SUBFR; i++ ) +#endif { dn[i] = round_fx( L_shl( y32[i], j ) ); /*Qx+15+j-16*/ } @@ -127,7 +147,6 @@ void corr_hh_ivas_fx( move16(); return; } - void corr_xh_ivas_fx( const Word16 x[], /* i : target signal Qx*/ const Word16 Qx, diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index 4317bdbb339419e21de8d9d597255c2083a32b4c..a8a1c0c5a9566a1f7b4f721f71e13d7fec73d14e 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -1143,7 +1143,13 @@ void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const scale = -2; move16(); } - +#ifdef REUSE_EVS_ACELP /* To be verified if it affects BE on 26.444, if yes, just a condition for IVAS here*/ + if ( EQ_16( val, 32767 ) ) + { + scale = -3; + move16(); + } +#endif Copy_Scale_sig( H, h, L_SUBFR, scale ); /*Q12+scale*/ E_ACELP_vec_neg_fx( h, h_inv, L_SUBFR ); diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index 240f9859c84f2748e544432bf47a9ff619bfae59..7ed52e946741d5a37c2553e5ff55000a46e1676b 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -553,7 +553,15 @@ void E_ACELP_4tsearchx_fx( &ind[j], dn, cor, sign, sign_val_1 ); } - +#ifdef REUSE_EVS_ACELP + IF( GT_16( alp, ONE_IN_Q14 ) ) + { + alp = shr( alp, 1 ); + Scale_sig( cor, L_SUBFR, -1 ); /*Q8*/ + Scale_sig( R_buf, 2 * L_SUBFR - 1, -1 ); /*Q8+scale*/ + Scale_sig( dn, L_SUBFR, -1 ); /*Qdn-1*/ + } +#endif st = add( st, 1 ); } diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index a485a1bf39cca3e3b503ba25c80494a3c8d25231..18c2dc358edb49ccff07d2396ea5608113ee07ab 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -115,6 +115,7 @@ void encod_gen_voic_fx( Flag Overflow = 0; move32(); #endif + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; @@ -165,7 +166,12 @@ void encod_gen_voic_fx( set16_fx( code_preQ_fx, 0, L_SUBFR ); shift_wsp = add( Q_new, shift ); - +#ifdef REUSE_EVS_ACELP + if ( st_fx->element_mode > EVS_MONO && LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } +#endif /* set and write harmonicity flag */ harm_flag_acelp = 0; move16(); @@ -196,20 +202,43 @@ void encod_gen_voic_fx( *----------------------------------------------------------------*/ Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/ +#ifdef USE_NEW_TARGET + IF( st_fx->element_mode > EVS_MONO && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + Word16 q_h1; + 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 ); - 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, add( sub( 14, q_h1 ), shift ) ); + } + ELSE +#endif + { - 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)*/ + 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 ); + 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 ); *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 ); /* Q6 */ - - tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); +#ifndef REUSE_EVS_TBE_CELP_EXC + IF( st_fx->element_mode > EVS_MONO ) + { + 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 ); + } + ELSE +#endif + { + // tbe_celp_exc, can be use EVS version in a bit-exact manner, just to add one condition and change L_SUBFR to L_subfr in the EVS version + tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); + } /*-----------------------------------------------------------------* * Find adaptive exitation @@ -305,7 +334,11 @@ void encod_gen_voic_fx( *-----------------------------------------------------------------*/ test(); +#ifdef REUSE_EVS_ACELP + IF( !st_fx->inactive_coder_type_flag && EQ_16( st_fx->coder_type, INACTIVE ) ) +#else IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) +#endif { 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 ); @@ -373,6 +406,7 @@ void encod_gen_voic_fx( T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. * Update A(z) filters @@ -403,7 +437,7 @@ void encod_gen_voic_fx( return; } - +#ifndef REUSE_EVS_ACELP void encod_gen_voic_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ @@ -794,3 +828,5 @@ void encod_gen_voic_ivas_fx( } return; } + +#endif diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index bf248bb5a3c0e5235e4e8f428535fac2daa6b53a..6ddd3d5491a540fd69eeb935bbc1a1fc5375d590 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -369,6 +369,8 @@ void transf_cdbk_enc_fx( return; } +#ifndef REUSE_EVS_ACELP_TC + 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*/ @@ -746,6 +748,7 @@ void transf_cdbk_enc_ivas_fx( return; } +#endif /*-------------------------------------------------------------------* * Find target in residual domain - cn[] *-------------------------------------------------------------------*/ diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index bfdf46ea07a7db5a2b3c6db64020d48167b02455..e031e1f79079113ebdb5868d595a229e32984530 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -573,7 +573,9 @@ void enc_pit_exc_ivas_fx( Word16 use_fcb; Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ +#ifdef USE_NEW_TARGET Word16 q_h1; +#endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -719,14 +721,25 @@ void enc_pit_exc_ivas_fx( * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */ - /* condition on target (compared to float) has been put outside the loop */ - + /* condition on target (compared to float) has been put outside the loop */ +#ifdef USE_NEW_TARGET find_targets_ivas_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq, res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); q_h1 = sub( 14, norm_s( h1[0] ) ); +#ifndef REUSE_EVS_ACELP Copy_Scale_sig( h1, h2, L_subfr, sub( 11, q_h1 ) ); /*Q11*/ - +#else + Copy_Scale_sig( h1, h2, L_subfr, add( sub( 11, q_h1 ), shift ) ); /*Q11*/ + move16(); + Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ +#endif +#else + find_targets_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq, + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + Copy_Scale_sig( h1, h2, L_subfr, -2 ); + Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ +#endif /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */ @@ -734,11 +747,15 @@ void enc_pit_exc_ivas_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ - +#ifndef REUSE_EVS_ACELP *pt_pitch = pit_encode_ivas_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new ); /* Q6 */ move16(); Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ +#else + *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, + L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ +#endif /*-----------------------------------------------------------------* * Find adaptive exitation @@ -756,8 +773,13 @@ void enc_pit_exc_ivas_fx( * Codebook target computation * (No LP filtering of the adaptive excitation) *-----------------------------------------------------------------*/ +#ifndef REUSE_EVS_ACELP lp_select = lp_filt_exc_enc_ivas_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ +#else + lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, + xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ +#endif IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); @@ -768,13 +790,14 @@ void enc_pit_exc_ivas_fx( gpit_tmp = gain_pit; move16(); /*Q14*/ test(); +#ifndef REUSE_EVS_ACELP IF( use_fcb > 0 ) { /* h2 in Q12 for codebook search */ /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) ); } - +#endif IF( use_fcb == 0 ) { IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) ) @@ -793,7 +816,7 @@ void enc_pit_exc_ivas_fx( /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ - +#ifndef REUSE_EVS_ACELP inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift, Q_new ); @@ -802,6 +825,16 @@ void enc_pit_exc_ivas_fx( *-----------------------------------------------------------------*/ gain_enc_lbr_ivas_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, sub( shift_wsp, 1 ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR ); +#else + inov_encode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift ); + + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + + gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR ); +#endif } ELSE { @@ -809,6 +842,7 @@ void enc_pit_exc_ivas_fx( * Innovation & gain encoding *-----------------------------------------------------------------*/ +#ifndef REUSE_EVS_ACELP inov_encode_ivas_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); /*-----------------------------------------------------------------* @@ -816,6 +850,15 @@ void enc_pit_exc_ivas_fx( *-----------------------------------------------------------------*/ gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); +#else + inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift ); + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); +#endif } gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); @@ -836,7 +879,11 @@ void enc_pit_exc_ivas_fx( *-----------------------------------------------------------------*/ IF( use_fcb != 0 ) { +#ifndef REUSE_EVS_ACELP Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); +#else + Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); +#endif Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); // Q_new+14+shift Ltmp = L_negate( Ltmp ); Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); // Q_new-1+15+shift diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 9802dc15b82071197c49514f3cfd2167ca4d2698..e6d27ab5b9e558e75b524f6ff3ee274bdd790299 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -100,7 +100,9 @@ Word16 encod_tran_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - +#ifdef REUSE_EVS_ACELP_TC + set16_fx( h1, 0, L_SUBFR + ( M + 1 ) ); +#endif L_frame_fx = st_fx->L_frame; move16(); /*------------------------------------------------------------------* @@ -143,7 +145,12 @@ Word16 encod_tran_fx( move16(); set16_fx( code_preQ, 0, L_SUBFR ); shift_wsp = add( Q_new, shift ); - +#ifdef REUSE_EVS_ACELP_TC + if ( st_fx->element_mode > EVS_MONO && LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } +#endif /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ @@ -157,13 +164,25 @@ Word16 encod_tran_fx( *----------------------------------------------------------------*/ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ +#ifdef USE_NEW_TARGET + IF( st_fx->element_mode > EVS_MONO && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + Word16 q_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] ) ); + Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ + Scale_sig( h1, L_SUBFR, add( sub( 14, q_h1 ), shift ) ); + } + ELSE +#endif + { + 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_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 ); - - 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 */ - + 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 */ + } /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_SUBFR, shift ); @@ -416,6 +435,7 @@ Word16 encod_tran_fx( return tc_subfr; } +#ifndef REUSE_EVS_ACELP_TC Word16 encod_tran_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ @@ -823,3 +843,4 @@ Word16 encod_tran_ivas_fx( return tc_subfr; } +#endif diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 887b4afb89415cb4b620ecf726a04924a72a21c9..5b75f2c1a8d9960225bb42b91321d893a0563cd3 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -14,6 +14,7 @@ * * Encode unvoiced (UC) frames *-------------------------------------------------------------------*/ +#ifndef USE_UC_EVS /*fixed point implementation of unvoiced_encoder*/ void encod_unvoiced_fx( Encoder_State *st_fx, /* i/o: state structure */ @@ -239,6 +240,9 @@ void encod_unvoiced_fx( } void encod_unvoiced_ivas_fx( +#else +void encod_unvoiced_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*/ @@ -269,7 +273,9 @@ 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; +#ifdef USE_UC_EVS + Word16 prm_t[2 * NPRM_DIV], *prm = prm_t; +#endif const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ Word32 norm_gain_code_fx; ACELP_config *acelp_cfg; @@ -279,7 +285,7 @@ void encod_unvoiced_ivas_fx( Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i; Word16 index, i_subfr_idx; Word16 unbits_PI; - Word16 q_h1; + acelp_cfg = &( st_fx->acelp_cfg ); SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -317,23 +323,47 @@ 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 USE_NEW_TARGET + IF( st_fx->element_mode > EVS_MONO && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + Word16 q_h1; + 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 + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift + } + ELSE +#endif + { + + 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 */ + + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); + } /*----------------------------------------------------------------* * Unvoiced subframe processing *----------------------------------------------------------------*/ IF( !uc_two_stage_flag ) { +#ifndef USE_UC_EVS *pt_pitch_fx = gaus_encode_ivas_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */ +#else + *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, + &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, + &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */ +#endif move16(); } ELSE @@ -341,7 +371,6 @@ void encod_unvoiced_ivas_fx( /*----------------------------------------------------------------* * Unvoiced subframe processing in two stages *----------------------------------------------------------------*/ - // PMT("The code below needs validation, never been tested") /* No adaptive codebook (UC) */ set16_fx( y1, 0, L_SUBFR ); set16_fx( exc_fx + i_subfr, 0, L_SUBFR ); @@ -356,11 +385,22 @@ void encod_unvoiced_ivas_fx( * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - // 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, st_fx->element_mode ); +#ifdef USE_UC_EVS + IF( st_fx->element_mode > EVS_MONO ) + { + inov_encode_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, + UNVOICED, st_fx->bwidth, st_fx->sharpFlag, 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 ); + } + ELSE + { + 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_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 ); g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */ @@ -373,8 +413,11 @@ void encod_unvoiced_ivas_fx( move16(); assert( gain_pit_fx == 0 ); +#ifdef USE_UC_EVS + 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 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 ); - +#endif /*----------------------------------------------------------* * - Compute the fixed codebook gain * * - quantize fixed codebook gain * diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index 989f309d2f2a5ee0305103ec476bc9ca9416ba80..66b61309b8ab5dbf439615bbdea2d2c1a1cafc37 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -65,6 +65,18 @@ void find_targets_fx( *--------------------------------------------------------------*/ IF( cn != NULL ) { +#ifdef REUSE_EVS_ACELP + /* first half: xn[] --> cn[] */ + temp[0] = 0; + move16(); + preemph_copy_fx( xn, cn, tilt_fac, L_subfr / 2, temp ); + syn_filt_s_lc_fx( 1, Ap, cn, temp, L_subfr / 2 ); /* Q-1 -> Q-2 */ + Residu3_lc_fx( p_Aq, M, temp, cn, L_subfr / 2, 1 ); /* Q-2 -> Q-1 */ + Scale_sig( cn, L_subfr / 2, 1 ); + + /* second half: res[] --> cn[] (approximated and faster) */ + Copy( &res[i_subfr + ( L_subfr / 2 )], cn + ( L_subfr / 2 ), L_subfr / 2 ); /* Q_new */ +#else /* first half: xn[] --> cn[] */ temp[0] = 0; move16(); @@ -75,6 +87,7 @@ void find_targets_fx( /* second half: res[] --> cn[] (approximated and faster) */ Copy( &res[i_subfr + ( L_SUBFR / 2 )], cn + ( L_SUBFR / 2 ), L_SUBFR / 2 ); /* Q_new */ +#endif } /*---------------------------------------------------------------* diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index 0ccb31ccfcf7e1eeb00cecab9149fa111b45bc8b..6e12deb4fddfa5043d73398bbc1d8197b41ed6f9 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -464,9 +464,12 @@ void gain_enc_mless_fx( case 6: { qua_table = gain_qua_mless_6b_fx; +#if defined REUSE_EVS_ACELP || defined REUSE_EVS_ACELP_TC if ( element_mode > EVS_MONO ) { + qua_table = gain_qua_mless_6b_stereo_fx; } +#endif move16(); if ( EQ_16( clip_gain, 1 ) ) { @@ -2083,7 +2086,11 @@ void gain_enc_lbr_fx( /* output gain_inov*/ exp_inov = sub( exp_code, add( 18, L_subfr_sf ) ); L_inov = Isqrt_lc( L_inov, &exp_inov ); +#ifdef REUSE_EVS_ACELP + *gain_inov = extract_h( L_shl_sat( L_inov, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ +#else *gain_inov = extract_h( L_shl( L_inov, sub( exp_inov, 3 ) ) ); /* gain_inov in Q12 */ +#endif move16(); diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 2aa9a5dfff887f9e1fd502971505046bb588201e..4c7d8c4793d853a29017dfb17576d6024366f5ca 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -73,8 +73,11 @@ Word16 gaus_encode_fx( *----------------------------------------------------------------*/ /* Correlation between target xn2[] and impulse response h1[] */ +#ifdef REUSE_EVS_ACELP + corr_xh_fx( xn, dn, h1, L_SUBFR ); +#else corr_xh_fx( xn, dn, h1 ); - +#endif tmp_idx = shr( i_subfr, 6 ); nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; /* Q0 */ move16(); @@ -171,8 +174,11 @@ Word16 gaus_encode_ivas_fx( *----------------------------------------------------------------*/ /* Correlation between target xn2[] and impulse response h1[] */ +#ifdef REUSE_EVS_ACELP + corr_xh_fx( xn, dn, h1, L_SUBFR ); +#else corr_xh_fx( xn, dn, h1 ); - +#endif tmp_idx = shr( i_subfr, 6 ); nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; /* Q0 */ move16(); diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index d019bf4747d93ff71f71c6e414e1826c8572237b..327d965bbf24cf92fe736966a2bd1ef07efbe40e 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -89,6 +89,9 @@ Word16 inov_encode_fx( Word16 Rw[L_SUBFR]; Word16 acelpautoc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; +#ifdef REUSE_EVS_ACELP // -> this might need ajsutement in acelp_fast + Word16 i, k, Qdn = 9 /*// -> this needs to be looked at in acelp_fast*/; +#endif (void) last_L_frame; stack_pulses = 0; move16(); @@ -139,7 +142,11 @@ Word16 inov_encode_fx( Scale_sig( cn, L_subfr, shift ); cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); +#ifdef REUSE_EVS_ACELP + corr_xh_fx( xn2, dn, h2, L_subfr ); +#else corr_xh_fx( xn2, dn, h2 ); +#endif } /*-----------------------------------------------------------------* @@ -159,109 +166,111 @@ Word16 inov_encode_fx( move16(); } } - ELSE IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) ) - { - test(); - test(); - if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - test(); - if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) ) - { - cmpl_flag = 3; - move16(); - } - } - - IF( EQ_16( L_frame, L_FRAME16k ) ) + ELSE { - IF( LE_32( core_brate, ACELP_32k ) ) + IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) ) { - cmpl_flag = 4; - move16(); - test(); - IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) ) + test(); + if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) { - IF( LE_16( i_subfr, L_SUBFR ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - ELSE - { - cmpl_flag = sub( cmpl_flag, 2 ); - } + cmpl_flag = 3; + move16(); } - } - ELSE IF( LE_32( core_brate, ACELP_48k ) ) - { - cmpl_flag = 3; - move16(); - - IF( EQ_16( coder_type, TRANSITION ) ) + test(); + test(); + test(); + test(); + test(); + if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) ) { - IF( LE_16( i_subfr, L_SUBFR ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - ELSE - { - cmpl_flag = sub( cmpl_flag, 2 ); - } + cmpl_flag = 3; + move16(); + } + test(); + test(); + test(); + test(); + if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) ) + { + cmpl_flag = 3; + move16(); } } - ELSE - { - cmpl_flag = 4; - move16(); - IF( EQ_16( coder_type, TRANSITION ) ) + IF( EQ_16( L_frame, L_FRAME16k ) ) + { + IF( LE_32( core_brate, ACELP_32k ) ) { - IF( LE_16( i_subfr, L_SUBFR ) ) + cmpl_flag = 4; + move16(); + + test(); + IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) ) { - cmpl_flag = sub( cmpl_flag, 1 ); + IF( LE_16( i_subfr, L_SUBFR ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } + ELSE + { + cmpl_flag = sub( cmpl_flag, 2 ); + } } - ELSE + } + ELSE IF( LE_32( core_brate, ACELP_48k ) ) + { + cmpl_flag = 3; + move16(); + + IF( EQ_16( coder_type, TRANSITION ) ) { - cmpl_flag = sub( cmpl_flag, 2 ); + IF( LE_16( i_subfr, L_SUBFR ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } + ELSE + { + cmpl_flag = sub( cmpl_flag, 2 ); + } } } - - if ( coder_type == INACTIVE ) + ELSE { cmpl_flag = 4; move16(); + + IF( EQ_16( coder_type, TRANSITION ) ) + { + IF( LE_16( i_subfr, L_SUBFR ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } + ELSE + { + cmpl_flag = sub( cmpl_flag, 2 ); + } + } + + if ( coder_type == INACTIVE ) + { + cmpl_flag = 4; + move16(); + } } } - } - test(); - test(); - test(); - IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) ) - { - if ( GT_16( cmpl_flag, 1 ) ) + test(); + test(); + test(); + IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) ) { - cmpl_flag = sub( cmpl_flag, 1 ); + if ( GT_16( cmpl_flag, 1 ) ) + { + cmpl_flag = sub( cmpl_flag, 1 ); + } } } - /*-----------------------------------------------------------------* * Find and encode the algebraic innovation *-----------------------------------------------------------------*/ @@ -272,6 +281,97 @@ Word16 inov_encode_fx( { IF( st_fx->acelp_cfg.fcb_mode ) { +#ifdef REUSE_EVS_ACELP + Word16 idx = 0, idx2 = 0; + move16(); + move16(); + + IF( i_subfr != 0 ) + { + idx = idiv1616( i_subfr, L_subfr ); + idx2 = idiv1616( i_subfr, L_SUBFR ); + } + + IF( LT_16( st_fx->acelp_cfg.fixed_cdk_index[idx], ACELP_FIXED_CDK_NB ) ) + { + Word16 wordcnt, bitcnt; + Word16 prm[8]; + + IF( st_fx->acelp_cfg.fixed_cdk_index[idx] >= 0 ) + { + test(); + test(); + test(); + IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) + { + nBits = st_fx->acelp_cfg.fixed_cdk_index[idx]; + move16(); + + IF( EQ_16( nBits, 8 ) ) + { + acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr ); + } + ELSE + { + acelp_fast_fx( hBstr, nBits, dn, Qdn, cn, 0, h2, code, y2, L_subfr ); + } + } + ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 7 ) ) || ( st_fx->idchan == 0 && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 3 ) ) ) + { + IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) + { + acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr ); + } + ELSE + { + acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, Qdn, cn, 0, h2, code, y2, L_SUBFR ); + } + } + ELSE + { + E_ACELP_4t_fx( dn, cn, h2, Rw, (Word8) acelpautoc, code, st_fx->acelp_cfg.fixed_cdk_index[idx2], prm, L_frame, last_L_frame, st_fx->total_brate, i_subfr, cmpl_flag ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 4 ); + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[idx2] ), 15 ); + + FOR( i = 0; i < wordcnt; i++ ) + { + push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], 16 ); + } + IF( bitcnt ) + { + push_indice( hBstr, IND_ALG_CDBK_4T64, prm[i], bitcnt ); + } + + /* Generate weighted code */ + set16_fx( y2, 0, L_SUBFR ); + Word16 sh = add( norm_s( h2[0] ), 1 ); + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* Code is sparse, so check which samples are non-zero */ + IF( code[i] != 0 ) + { + FOR( k = 0; k < L_SUBFR - i; k++ ) + { + y2[i + k] = add_sat( y2[i + k], round_fx( L_shl( L_mult( code[i], h2[k] ), sh ) ) ); // Q9 Added saturation: needs to be rechecked + move16(); + } + } + } + } + } + ELSE + { + set16_fx( code, 0, L_SUBFR ); + set16_fx( y2, 0, L_SUBFR ); + } + } +#ifdef DEBUGGING + else + { + IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid mode for acelp frame!\n" ); + } +#endif +#endif } ELSE { @@ -343,7 +443,6 @@ Word16 inov_encode_fx( return stack_pulses; } - Word16 inov_encode_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 core_brate, /* i : core bitrate */ @@ -617,7 +716,11 @@ Word16 inov_encode_ivas_fx( IF( EQ_16( nBits, 8 ) ) { +#ifndef REUSE_EVS_ACELP_1t64 acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr ); +#else + acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr ); +#endif } ELSE { @@ -628,7 +731,11 @@ Word16 inov_encode_ivas_fx( { IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { +#ifndef REUSE_EVS_ACELP_1t64 acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_subfr ); +#else + acelp_1t64_fx( hBstr, dn, h2, code, y2, L_subfr ); +#endif } ELSE { @@ -689,11 +796,19 @@ Word16 inov_encode_ivas_fx( IF( EQ_16( nBits, 7 ) ) { +#ifndef REUSE_EVS_ACELP_1t64 acelp_1t64_ivas_fx( hBstr, dn, h2, code, y2, L_SUBFR ); +#else + acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR ); +#endif } ELSE IF( EQ_16( nBits, 12 ) ) { +#ifndef REUSE_EVS_ACELP_2t32 acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 ); +#else + acelp_2t32_fx( hBstr, dn, h2, code, y2 ); +#endif } ELSE { @@ -706,7 +821,11 @@ Word16 inov_encode_ivas_fx( { IF( EQ_32( core_brate, ACELP_6k60 ) ) { +#ifndef REUSE_EVS_ACELP_2t32 acelp_2t32_ivas_fx( hBstr, dn, h2, code, y2 ); +#else + acelp_2t32_fx( hBstr, dn, h2, code, y2 ); +#endif } ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) ) { diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index 8eea1b3d52b398655e3a8b03fc5a76262f006ed9..036eadea6950ec6c2a5f8457e22102d76aeb2a81 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -80,8 +80,9 @@ Word16 pit_encode_fx( /* o : Fractional pitc Word16 pit_flag, delta, mult_Top, nBits; Word16 L_sufr_sft; Word16 T_op[2]; /* values for two half-frames */ +#ifndef REUSE_EVS_ACELP (void) tdm_Pitch_reuse_flag; - +#endif L_sufr_sft = 6; move16(); if ( EQ_16( L_subfr, 2 * L_SUBFR ) ) @@ -265,6 +266,59 @@ Word16 pit_encode_fx( /* o : Fractional pitc pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } +#ifdef REUSE_EVS_ACELP + ELSE IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) || EQ_16( nBits, 4 ) ) + { + /*-------------------------------------------------------* + * Pitch encoding with reusing primary channel information + *-------------------------------------------------------*/ + Word16 loc_T0, loc_frac; + + delta = 4; + move16(); + + pit_flag = L_SUBFR; + move16(); + + Word16 idx1 = shr( i_subfr, L_sufr_sft ); + Word16 idx2 = shr( add( i_subfr, 64 ), L_sufr_sft ); + + IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) + { + loc_T0 = add( shr( tdm_Pri_pitch_buf[idx1], 1 ), shr( tdm_Pri_pitch_buf[idx2], 1 ) ); // Q6 + loc_frac = shr( sub( loc_T0, shl( shr( loc_T0, 6 ), 6 ) ), 4 ); // Q2 + loc_T0 = shr( loc_T0, 6 ); // Q0 + } + ELSE + { + loc_T0 = tdm_Pri_pitch_buf[idx1]; // Q6 + loc_frac = shr( sub( loc_T0, shl( shr( loc_T0, 6 ), 6 ) ), 4 ); // Q2 + loc_T0 = shr( loc_T0, 6 ); // Q0 + } + + /* pitch lag search limitation */ + limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max ); + IF( nBits > 0 ) + { + /* search and encode the closed loop pitch period */ + *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); + IF( EQ_16( delta, 8 ) ) + { + *T0_frac = 0; + move16(); + } + pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + ELSE + { + *T0 = loc_T0; + move16(); + *T0_frac = loc_frac; + move16(); + } + } +#endif ELSE { /*-------------------------------------------------------* diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index c433dcb2cb5fa6e9668a3a2329f9a4fdf5ee9ea6..c3d2ef3ae1f24b22410a14c833c1e5d7a3367ba6 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2997,6 +2997,10 @@ void corr_xh_fx( const Word16 x[], /* i : target signal Qx*/ Word16 dn[], /* o : correlation between x[] and h[] Qdn*/ const Word16 h[] /* i : impulse response (of weighted synthesis filter) Q14*/ +#ifdef REUSE_EVS_ACELP + , + const Word16 L_subfr /* i : sub-frame lenght Q0 */ +#endif ); void corr_hh_ivas_fx( diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index d0d62769791a9dfe181c3452d45ef076c2b5167c..a384e8b12d51d74998fce29616c470de22101554 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -17,8 +17,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 REUSE_EVS_ACELP_TC 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 /*==========================================================================*/ /* FUNCTION : void transition_enc_fx () */ @@ -877,6 +878,7 @@ void transition_enc_fx( return; } +#ifndef REUSE_EVS_ACELP_TC void transition_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -1701,7 +1703,7 @@ void transition_enc_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------------------------------* * tc_enc() * @@ -1937,6 +1939,7 @@ static void tc_enc_fx( move16(); return; } +#ifndef REUSE_EVS_ACELP_TC static void tc_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -2157,7 +2160,7 @@ static void tc_enc_ivas_fx( move16(); return; } - +#endif /*-----------------------------------------------------------------* * gain_trans_enc()