diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index f96fba710c9b17b78e3beb7cd3abd2dc2783605a..4d2d76baab7721f43e108f7afa85e6c893642d61 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -180,12 +180,14 @@ IF( GT_16( element_mode, IVAS_SCE ) ) { return; } + /*---------------------------------------------------------------------* * Generate white noise vector *---------------------------------------------------------------------*/ /*for ( i=0; i Q31*/ ); /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ + } + + test(); + IF( prev_scale <= 0 || ( GT_32( prev_scale_factor, scale /*Q31*/ ) ) ) +#else sc_factor = s_max( sub( 13, norm_s( add( j, 1 ) ) ), 0 ); /* Adapt the scaling factor allowed depending of max position */ sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ + test(); IF( prev_scale <= 0 || GT_32( L_shr( prev_scale, sub( sc_factor, 1 ) /*Q30 -> Q31*/ ), scale /*Q31*/ ) ) /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ +#endif { scale_step = 16384; move16(); /* Q14 */ @@ -5875,7 +5897,6 @@ void non_linearity_ivas_fx( } ELSE { - /* Computing log2(scale) */ IF( j == 0 ) { @@ -5912,7 +5933,16 @@ void non_linearity_ivas_fx( } } - prev_scale = non_linearity_scaled_copy_ivas( input, j, length_half, output, prev_scale, scale_step, en_abs ); +#ifdef HARM_NON_LINEARITY + IF( element_mode == EVS_MONO ) + { + prev_scale = non_linearity_scaled_copy( input, j, length_half, output, prev_scale, scale_step, en_abs ); + } + ELSE +#endif + { + prev_scale = non_linearity_scaled_copy_ivas( input, j, length_half, output, prev_scale, scale_step, en_abs ); + } max_val = 0; move16(); @@ -5940,12 +5970,28 @@ void non_linearity_ivas_fx( move32(); /* Q31; 0.67 in Q31 */ } - /* if ( element_mode > EVS_MONO ) */ /* element mode is not needed because the function is duplicated for IVAS */ - sc_factor = s_max( sub( 12, norm_s( add( sub( j, length_half ), 1 ) ) ), 0 ); /* allowed intra frame jump is smaller */ - sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ +#ifdef HARM_NON_LINEARITY + IF( element_mode == EVS_MONO ) + { + prev_scale_factor = Mult_32_16( prev_scale, 32 ); + } + ELSE + { + sc_factor = s_max( sub( 12, norm_s( add( sub( j, length_half ), 1 ) ) ), 0 ); /* allowed intra frame jump is smaller */ + sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ + prev_scale_factor = L_shr( prev_scale, sub( sc_factor, 1 ) /*Q30 -> Q31*/ ); /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ + } + + test(); + IF( prev_scale <= 0 || ( GT_32( prev_scale_factor, scale /*Q31*/ ) ) ) +#else + /* if ( element_mode > EVS_MONO ) */ /* element mode is not needed because the function is duplicated for IVAS */ + sc_factor = s_max( sub( 12, norm_s( add( sub( j, length_half ), 1 ) ) ), 0 ); /* allowed intra frame jump is smaller */ + sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ test(); IF( prev_scale <= 0 || GT_32( L_shr( prev_scale, sub( sc_factor, 1 ) /*Q30 -> Q31*/ ), scale /*Q31*/ ) ) /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ +#endif { scale_step = 16384; move16(); /*Q14 */ @@ -5989,7 +6035,16 @@ void non_linearity_ivas_fx( } } - prev_scale = non_linearity_scaled_copy_ivas( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); +#ifdef HARM_NON_LINEARITY + IF( element_mode == EVS_MONO ) + { + prev_scale = non_linearity_scaled_copy( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); + } + ELSE +#endif + { + prev_scale = non_linearity_scaled_copy_ivas( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); + } *pPrevScale = prev_scale; move32(); @@ -6035,7 +6090,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 ) ); @@ -6052,7 +6107,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 ) ); @@ -6070,7 +6125,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_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 71d8729aac44e7d78a358e5b54acd32ec6f815e9..b65b49a42b7f13f01f034978adbf2a77c2d9fc64 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -2281,12 +2281,20 @@ ivas_error acelp_core_dec_fx( { IF( EQ_16( st->element_mode, EVS_MONO ) ) { +#ifdef HARM_NON_LINEARITY + non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); +#else non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); +#endif } ELSE { Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), st->hBWE_TD->q_old_bwe_exc_extended_fx ) ) ); /* Q(q_old_bwe_exc_extended_fx) -> Q(2 * Q_exc) */ +#ifdef HARM_NON_LINEARITY + non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); +#else non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); +#endif exp = sub( L_norm_arr( bwe_exc_extended_fx + L_FRAME32k, NL_BUFF_OFFSET ), 16 ); Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, exp ); /* Q(2 * Q_exc) -> Q(q_old_bwe_exc_extended_fx) */ st->hBWE_TD->q_old_bwe_exc_extended_fx = add( shl( st->Q_exc, 1 ), exp ); @@ -2313,6 +2321,10 @@ ivas_error acelp_core_dec_fx( IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); +#else IF( EQ_16( st->element_mode, EVS_MONO ) ) { cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, @@ -2324,6 +2336,7 @@ ivas_error acelp_core_dec_fx( st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); } +#endif /* Set 16k LSP flag for CNG buffer */ st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 0006bacbbd2e6354d3e976b80a362a608103ee88..27c528b243574bb084a685113b874eaacba8423b 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -9,9 +9,11 @@ #include "prot_fx.h" #include "ivas_cnst.h" +#ifndef HARM_NON_LINEARITY /*Temporary location to be move in prot* when merge is done*/ void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); +#endif /*-----------------------------------------------------------------* * Local function prototypes @@ -19,7 +21,10 @@ void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); +#ifndef HARM_NON_LINEARITY static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); +#endif + /*-----------------------------------------------------------------* * CNG_dec_fx() @@ -723,7 +728,11 @@ void swb_CNG_dec_fx( { st_fx->last_vad_fx = 1; move16(); +#ifdef HARM_NON_LINEARITY + st_fx->hTdCngDec->burst_cnt_fx = add_sat( st_fx->hTdCngDec->burst_cnt_fx, 1 ); +#else st_fx->hTdCngDec->burst_cnt_fx = add( st_fx->hTdCngDec->burst_cnt_fx, 1 ); +#endif move16(); if ( GT_16( st_fx->hTdCngDec->burst_cnt_fx, 10 ) ) { @@ -735,6 +744,7 @@ void swb_CNG_dec_fx( return; } +#ifndef HARM_NON_LINEARITY void swb_CNG_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ @@ -772,6 +782,7 @@ void swb_CNG_dec_ivas_fx( return; } +#endif /*---------------------------------------------------------------------* * shb_CNG_decod() @@ -780,12 +791,17 @@ void swb_CNG_dec_ivas_fx( *---------------------------------------------------------------------*/ static void shb_CNG_decod_fx( - Decoder_State *st_fx, /* i/o: State structure */ +#ifdef HARM_NON_LINEARITY + Decoder_State *st, /* i/o: State structure */ +#else + Decoder_State *st_fx, /* i/o: State structure */ +#endif const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) +#ifndef HARM_NON_LINEARITY { Word16 i; Word16 idx_ener_fx; @@ -1052,6 +1068,7 @@ static void shb_CNG_decod_ivas_fx( Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ const Word16 Qsyn ) +#endif { Word16 i; Word16 idx_ener; @@ -1074,6 +1091,9 @@ static void shb_CNG_decod_ivas_fx( Word16 exp, exp1; Word16 fra; Word32 L_tmp; +#ifdef HARM_NON_LINEARITY + Word16 tmp_16, tmp_16_2, step_fx16, gain_fx16, ener_fx16; +#endif Word16 allow_cn_step_fx; Word16 q; TD_BWE_DEC_HANDLE hBWE_TD; @@ -1099,8 +1119,14 @@ static void shb_CNG_decod_ivas_fx( /* de-quantization of SHB CNG parameters */ IF( st->element_mode == EVS_MONO ) { +#ifdef HARM_NON_LINEARITY + L_tmp = L_mult( idx_ener, 27400 ); /*Q14 */ + hTdCngDec->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 295924 ), 6 ) ); /*Q8 */ + move16(); +#else hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 6850 ), 36991 ); // Q11 move32(); +#endif } ELSE { @@ -1114,10 +1140,25 @@ static void shb_CNG_decod_ivas_fx( interp_fx = s_min( hTdCngDec->shb_dtx_count_fx, 32 ); interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/ - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) +#ifdef HARM_NON_LINEARITY + IF( st->element_mode == EVS_MONO ) { - shb_lspCNG_fx[i] = add( mult_r( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14 - move16(); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + tmp_16_2 = mult( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ); /*Q14*/ + tmp_16 = mult( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ); /*Q14*/ + shb_lspCNG_fx[i] = add( tmp_16_2, tmp_16 ); + move16(); /*Q14*/ + } + } + ELSE +#endif + { + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + shb_lspCNG_fx[i] = add( mult_r( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14 + move16(); + } } IF( LE_16( hTdCngDec->shb_dtx_count_fx, 1000 ) ) @@ -1129,80 +1170,162 @@ static void shb_CNG_decod_ivas_fx( E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( shb_lpcCNG_fx, hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */ - +#ifdef HARM_NON_LINEARITY + IF( st->element_mode != EVS_MONO ) +#endif + { + Copy_Scale_sig( shb_lpcCNG_fx, hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */ + } Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ /* SHB energy estimation */ - wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) +#ifdef HARM_NON_LINEARITY + IF( st->element_mode == EVS_MONO ) { + wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ FOR( i = 0; i < L_FRAME32k; i++ ) { wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */ } - } - exp = norm_l( wb_ener_fx ); - fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); - exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); - wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ - Word32 wb_ener32_fx = L_shl( wb_ener16_fx, 3 ); /*wb_ener_fx in Q11 */ - if ( EQ_16( st->first_CNG, 0 ) ) - { - hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; - move32(); /*Q11 */ - } - if ( GT_32( L_abs( L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */ - { - allow_cn_step_fx = 1; - move16(); - } + exp = norm_l( wb_ener_fx ); + fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); + exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); + wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); + wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ + if ( !st->first_CNG ) + { + hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; + move16(); /*Q8 */ + } + if ( GT_16( abs_s( sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ) ), 3072 ) ) + { + allow_cn_step_fx = 1; + move16(); + } - IF( EQ_16( allow_cn_step_fx, 1 ) ) - { - hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; - move32(); /*Q11 */ + IF( EQ_16( allow_cn_step_fx, 1 ) ) + { + hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; + move16(); /*Q8 */ + } + ELSE + { + tmp_16 = sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ); /*Q8 */ + tmp_16 = mult_r( tmp_16, 29491 ); /*Q8 */ + hTdCngDec->wb_cng_ener_fx = add( hTdCngDec->wb_cng_ener_fx, tmp_16 ); /*Q8 */ + move16(); + } + + test(); + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && ( st->bfi == 0 ) ) + { + hTdCngDec->last_wb_cng_ener_fx = hTdCngDec->wb_cng_ener_fx; + move16(); + + if ( !st->first_CNG ) + { + hTdCngDec->shb_cng_ener_fx = hTdCngDec->last_shb_cng_ener_fx; + move16(); + } + } + + gain_fx16 = sub( hTdCngDec->wb_cng_ener_fx, hTdCngDec->last_wb_cng_ener_fx ); /* Q8 */ + if ( GT_16( gain_fx16, 15 ) ) + { + gain_fx16 = 15; + move16(); + } + step_fx16 = sub( add( gain_fx16, hTdCngDec->last_shb_cng_ener_fx ), hTdCngDec->shb_cng_ener_fx ); /*Q8 */ + + test(); + IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) + { + hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, step_fx16 ); /* Q8 */ + move16(); + } + ELSE + { + hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, mult( 8192, step_fx16 ) ); /*Q8 */ + move16(); + } } ELSE +#endif { - tmp = L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */ - tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */ - hTdCngDec->wb_cng_ener_fx_32 = L_add( hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */ - move32(); - } - test(); - test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) - { - hTdCngDec->last_wb_cng_ener_fx_32 = hTdCngDec->wb_cng_ener_fx_32; /* Q11 */ - move32(); + wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */ + } + } + exp = norm_l( wb_ener_fx ); + fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); + exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); + wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); + wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ + Word32 wb_ener32_fx = L_shl( wb_ener16_fx, 3 ); /*wb_ener_fx in Q11 */ + if ( EQ_16( st->first_CNG, 0 ) ) + { + hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; + move32(); /*Q11 */ + } + if ( GT_32( L_abs( L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */ + { + allow_cn_step_fx = 1; + move16(); + } - if ( !st->first_CNG ) + IF( EQ_16( allow_cn_step_fx, 1 ) ) + { + hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; + move32(); /*Q11 */ + } + ELSE { - hTdCngDec->shb_cng_ener_fx_32 = hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */ + tmp = L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */ + tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */ + hTdCngDec->wb_cng_ener_fx_32 = L_add( hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */ move32(); } - } - gain_fx = L_sub( hTdCngDec->wb_cng_ener_fx_32, hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */ - if ( GT_32( gain_fx, 30720 ) ) - { - gain_fx = 30720; - move32(); - } - step_fx = L_sub( L_add( gain_fx, hTdCngDec->last_shb_cng_ener_fx_32 ), hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */ - test(); - IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) - { - hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */ - move32(); - } - ELSE - { - hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */ - move32(); + test(); + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) + { + hTdCngDec->last_wb_cng_ener_fx_32 = hTdCngDec->wb_cng_ener_fx_32; /* Q11 */ + move32(); + + if ( !st->first_CNG ) + { + hTdCngDec->shb_cng_ener_fx_32 = hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */ + move32(); + } + } + + gain_fx = L_sub( hTdCngDec->wb_cng_ener_fx_32, hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */ + if ( GT_32( gain_fx, 30720 ) ) + { + gain_fx = 30720; + move32(); + } + step_fx = L_sub( L_add( gain_fx, hTdCngDec->last_shb_cng_ener_fx_32 ), hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */ + + test(); + IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) + { + hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */ + move32(); + } + ELSE + { + hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */ + move32(); + } } + /* generate white noise excitation */ FOR( i = 0; i < L_FRAME16k; i++ ) { @@ -1213,7 +1336,6 @@ static void shb_CNG_decod_ivas_fx( /* synthesis filtering */ Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, hBWE_TD->state_lpc_syn_fx, 1 ); - /* synthesis signal gain shaping */ L_tmp = 0; move32(); @@ -1238,56 +1360,112 @@ static void shb_CNG_decod_ivas_fx( } } - ener_fx = hTdCngDec->shb_cng_ener_fx_32; - move32(); /*Q11 */ - IF( GT_16( st->hTdCngDec->trans_cnt_fx, 0 ) ) +#ifdef HARM_NON_LINEARITY + IF( st->element_mode == EVS_MONO ) { - i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ - ener_fx = L_add( hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( hTdCngDec->last_shb_ener_fx_32, hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */ - hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); - move16(); - } + ener_fx16 = hTdCngDec->shb_cng_ener_fx; + move16(); /*Q8 */ + IF( hTdCngDec->trans_cnt_fx > 0 ) + { + i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ + ener_fx16 = add_sat( hTdCngDec->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( hTdCngDec->last_shb_ener_fx, hTdCngDec->shb_cng_ener_fx ) ) ); /*Q8 */ + hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); + move16(); + } - tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ - IF( GT_32( tmp, 32767 ) ) - abort(); - Word16 tmp_16; - tmp_16 = (Word16) tmp; - move16(); - L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ - L_tmp = L_add( L_tmp, L_shl( 10, 16 ) ); - if ( ( L_tmp < 0 ) ) - { - L_tmp = 0; - move32(); + tmp_16 = mult( 3277, ener_fx16 ); /*Q8 */ + L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ + L_tmp = L_add( L_tmp, 10 << 16 ); + if ( L_tmp < 0 ) + { + L_tmp = 0; + move32(); + } + fra = L_Extract_lc( L_tmp, &exp ); + L_tmp = L_shl_sat( Pow2( exp, fra ), 5 ); /*Q5 */ + L_tmp = L_shr( L_tmp, 10 ); + if ( !L_tmp ) + { + L_tmp = 1; /*Q5 */ + } + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /*Q31*/ + tmp_16 = extract_h( L_tmp ); /*Q15*/ + exp = sub( exp, 16 ); + exp1 = norm_s( ener_excSHB_fx ); + fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ + + IF( GT_16( fra, tmp_16 ) ) + { + fra = shr( fra, 1 ); /*Q15*/ + exp1 = sub( exp1, 1 ); + } + tmp_16 = div_s( fra, tmp_16 ); /*Q15*/ + + L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ + tmp_16 = sub( add( 5, exp ), add( q, exp1 ) ); + L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ } - fra = L_Extract_lc( L_tmp, &exp ); - L_tmp = L_shr( Pow2( exp, fra ), 5 ); /*Q5 */ - if ( !L_tmp ) + ELSE { - L_tmp = 1; - move32(); /*Q5 */ - } - exp = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp ); /*Q31*/ - tmp_16 = extract_h( L_tmp ); /*Q15*/ - exp = sub( exp, 16 ); - exp1 = norm_s( ener_excSHB_fx ); - fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ +#endif + ener_fx = hTdCngDec->shb_cng_ener_fx_32; + move32(); /*Q11 */ + IF( GT_16( st->hTdCngDec->trans_cnt_fx, 0 ) ) + { + i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ + ener_fx = L_add( hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( hTdCngDec->last_shb_ener_fx_32, hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */ + hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); + move16(); + } - IF( GT_16( fra, tmp_16 ) ) - { - fra = shr( fra, 1 ); /*Q15*/ - exp1 = sub( exp1, 1 ); + tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ + IF( GT_32( tmp, 32767 ) ) + abort(); +#ifndef HARM_NON_LINEARITY + Word16 tmp_16; +#endif + tmp_16 = (Word16) tmp; + move16(); + L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ + L_tmp = L_add( L_tmp, L_shl( 10, 16 ) ); + if ( L_tmp < 0 ) + { + L_tmp = 0; + move32(); + } + fra = L_Extract_lc( L_tmp, &exp ); + L_tmp = L_shr( Pow2( exp, fra ), 5 ); /*Q5 */ + if ( !L_tmp ) + { + L_tmp = 1; + move32(); /*Q5 */ + } + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /*Q31*/ + tmp_16 = extract_h( L_tmp ); /*Q15*/ + exp = sub( exp, 16 ); + exp1 = norm_s( ener_excSHB_fx ); + fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ + + IF( GT_16( fra, tmp_16 ) ) + { + fra = shr( fra, 1 ); /*Q15*/ + exp1 = sub( exp1, 1 ); + } + tmp_16 = div_s( fra, tmp_16 ); /*Q15*/ + + L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ + tmp_16 = sub( add( 5, exp ), add( q, exp1 ) ); + L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ + hTdCngDec->shb_cng_gain_fx_32 = ener_fx; + move32(); +#ifdef HARM_NON_LINEARITY } - tmp_16 = div_s( fra, tmp_16 ); /*Q15*/ +#endif - L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ - tmp_16 = sub( add( 5, exp ), add( q, exp1 ) ); - L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ - hTdCngDec->shb_cng_gain_fx_32 = ener_fx; - move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { shb_syn16k_fx[i] = extract_l( L_shr( Mpy_32_16_1( L_gain_fx, excSHB_fx[i] ), sub( 5, tmp_16 ) ) ); /*Q3 = 31-Qtmp-8-15-5+Qtmp */ @@ -1317,7 +1495,21 @@ static void shb_CNG_decod_ivas_fx( interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, hTdCngDec->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } +#ifdef HARM_NON_LINEARITY + IF( st->element_mode != EVS_MONO ) + { + IF( EQ_32( st->output_Fs, 32000 ) ) + { + Scale_sig( shb_synth_fx, L_FRAME32k, -3 ); /* Qx - 3 */ + } + ELSE + { + Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); /* Qx - 3 */ + } + } +#else Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); /* Qx - 3 */ +#endif ResetSHBbuffer_Dec_fx( st->hBWE_TD, st->extl ); diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 6a610063c8987b8bb6aa16ed9bbd59b20d2a84bd..07372eae0dfae33d3ee48a32e8789dd49f7d1eb0 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -934,16 +934,27 @@ void decoder_LPD_fx( E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); E_LPC_a_lsp_conversion( A, lsptmp, &xspnew_uw[0], M ); Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 1 ); + +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + Qexc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, EVS_MONO, -1 ); +#else cng_params_upd_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, Qexc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); +#endif } ELSE { +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( &lsp[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, EVS_MONO, -1 ); +#else cng_params_upd_fx( &lsp[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); +#endif } /* Set 16k LSP flag for CNG buffer */ diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 94d4486b1692b4bb9c0d9d76ae127ae2d526748a..b475a31d73412acb29abff6e345dbeb46f802d46 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -479,7 +479,11 @@ Word16 dec_acelp_tcx_frame_fx( test(); IF( st->core == ACELP_CORE && st->igf != 0 && st->con_tcx == 0 ) { +#ifdef HARM_NON_LINEARITY + non_linearity_fx( EVS_MONO, ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors, st->L_frame ); +#else non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors, st->L_frame ); +#endif /* update the old BWE exe memory */ Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index cdfb16699638fb27935ad844b7ee4e5da2879e28..9331f95f9a67f349c569c2914305024a9fc05d1d 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1181,17 +1181,29 @@ ivas_error ivas_core_dec_fx( q = 2; move16(); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 +#ifdef HARM_NON_LINEARITY + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], output_frame, -( Q11 ) ); // Q0 +#else + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 +#endif Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); // Q0 Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ); // Q8 Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 +#ifdef HARM_NON_LINEARITY + swb_CNG_dec_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); +#else swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); +#endif test(); IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { +#ifdef HARM_NON_LINEARITY + Copy_Scale_sig_16_32_DEPREC( hb_synth_16_fx[n], hb_synth_32_fx[n], output_frame, ( Q11 ) ); // Q11 +#else Copy_Scale_sig_16_32_DEPREC( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 ) ); // Q11 +#endif } Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ) ); // Q0 diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index eb0c7462cc248b58941e761b47a1824a7ae2a327..45588e7cc8542f364eb8d6986fb578e18ed8a976 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -753,13 +753,24 @@ void stereo_tcx_core_dec_fx( IF( st->hTdCngDec != NULL ) { +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); +#else cng_params_upd_ivas_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); +#endif } } ELSE IF( st->hTdCngDec != NULL ) { +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( &lsp_fx[M], st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); +#else cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); +#endif } + /* Set 16k LSP flag for CNG buffer */ // st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); IF( EQ_16( st->L_frame, L_FRAME ) ) diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 93b4b46e31a3bab62512842a247bbb1831a8310c..104e9bc96fdecff4a55e6bdc6c246be3a85b83cb 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -97,6 +97,9 @@ ivas_error acelp_core_enc_fx( error = IVAS_ERR_OK; (void) hStereoTD; +#ifdef HARM_NON_LINEARITY + (void) ener_fx; +#endif /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ @@ -274,10 +277,20 @@ ivas_error acelp_core_enc_fx( IF( EQ_16( st_fx->cng_type, LP_CNG ) ) { /* Run CNG post parameter update */ +#ifdef HARM_NON_LINEARITY + cng_params_postupd_fx( hTdCngEnc->ho_circ_ptr, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, + hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx, EVS_MONO, -1 ); +#else cng_params_postupd_fx( hTdCngEnc->ho_circ_ptr, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx ); +#endif + /* encode CNG parameters */ +#ifdef HARM_NON_LINEARITY + CNG_enc_fx( st_fx, Aq_fx, inp_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); +#else CNG_enc_fx( st_fx, Aq_fx, inp_fx, ener_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); +#endif /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc_fx, exc2_fx, &hTdCngEnc->lp_ener_fx, st_fx->last_core_brate, @@ -620,7 +633,11 @@ ivas_error acelp_core_enc_fx( IF( !st_fx->Opt_SC_VBR ) { /* Apply a non linearity to the SHB excitation */ +#ifdef HARM_NON_LINEARITY + non_linearity_fx( st_fx->element_mode, bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame ); +#else non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame ); +#endif } test(); if ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) @@ -638,9 +655,14 @@ ivas_error acelp_core_enc_fx( IF( hTdCngEnc != NULL && ( st_fx->Opt_DTX_ON != 0 ) && ( GT_32( st_fx->core_brate, SID_2k40 ) ) ) { /* update CNG parameters in active frames */ +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, + Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate, EVS_MONO, -1 ); +#else cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); +#endif IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { @@ -968,10 +990,18 @@ ivas_error acelp_core_enc_ivas_fx( IF( st->cng_type == LP_CNG ) { /* Run CNG post parameter update */ +#ifdef HARM_NON_LINEARITY + cng_params_postupd_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#else cng_params_postupd_ivas_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#endif /* encode CNG parameters */ +#ifdef HARM_NON_LINEARITY + CNG_enc_fx( st, Aq, inp, lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); +#else CNG_enc_ivas_fx( st, Aq, inp, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); +#endif /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate, @@ -1236,7 +1266,12 @@ ivas_error acelp_core_enc_ivas_fx( *---------------------------------------------------------------*/ calc_residu_fx( st, inp, res_fx, Aq ); + +#ifdef HARM_NON_LINEARITY + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); +#else calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); +#endif IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) ) { @@ -1434,7 +1469,11 @@ ivas_error acelp_core_enc_ivas_fx( { /* Apply a non linearity to the SHB excitation */ Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc +#ifdef HARM_NON_LINEARITY + non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); +#else non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); +#endif Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc } @@ -1480,10 +1519,16 @@ ivas_error acelp_core_enc_ivas_fx( st->hTdCngEnc->cng_Qexc_buf[ii] = q_exc; move16(); } + +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, + q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#else cng_params_upd_ivas_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#endif IF( EQ_16( st->L_frame, L_FRAME ) ) { diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 72f981259c934f9c3d38d8392f94085125eb43a9..c1865862f0af614da9626cc7f64166521510fbc0 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -471,7 +471,11 @@ void amr_wb_enc_fx( IF( EQ_32( st->core_brate, SID_1k75 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* encode CNG parameters */ +#ifdef HARM_NON_LINEARITY + CNG_enc_fx( st, Aq, inp, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); +#else CNG_enc_fx( st, Aq, inp, ener, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); +#endif /* comfort noise generation */ CNG_exc_fx( st->core_brate, L_FRAME, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc, exc2, &hTdCngEnc->lp_ener_fx, diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index de211162b805250f8985064aed20edfe56622ca6..1bc7cab41ad44d35c9169883c00f5bbb49a801b8 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1,6 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ @@ -8,9 +9,9 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -//#include "basop_mpy.h" - #include + + /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -20,18 +21,26 @@ #define INT_H 50 #define INT_L 8 + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ + static void shb_CNG_encod_fx( Encoder_State *st_fx, const Word16 update_fx ); static Word16 shb_DTX_fx( Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); +#ifndef HARM_NON_LINEARITY static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx ); static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update ); +#endif + + /*---------------------------------------------------------------------* * CNG_enc() * * Confort noise generation for the coder *---------------------------------------------------------------------*/ + +#ifndef HARM_NON_LINEARITY void CNG_enc_fx( Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ @@ -1169,11 +1178,13 @@ void CNG_enc_fx( } void CNG_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ - // Word32 L_ener, /* i : residual energy from Levinson-Durbin Q6 */ - const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ +#else +void CNG_enc_fx( +#endif + Encoder_State *st_fx, /* i/o: State structure */ + Word16 Aq[], /* o : LP coefficients Q12 */ + const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ + const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ Word16 *allow_cn_step, /* o : allow CN step Q0 */ @@ -1207,9 +1218,14 @@ void CNG_enc_ivas_fx( Word16 max_idx[2]; Word16 ftmp_fx; Word16 lsp_tmp[M]; +#ifdef HARM_NON_LINEARITY + Word32 dev, max_dev, dist; + Word16 dev16, max_dev16, dist16; +#else Word32 dev; Word32 max_dev; Word32 dist; +#endif Word16 max_idx1[2]; Word16 fft_io[L_FRAME16k]; Word16 *ptR, *ptI; @@ -1233,6 +1249,10 @@ void CNG_enc_ivas_fx( Word64 w_temp; Word32 inv_frame_len; Word32 L_ener; +#ifdef HARM_NON_LINEARITY + Word16 *pt_res; + const Word16 *pt_sp; +#endif step_inv = 0; move16(); @@ -1256,7 +1276,6 @@ void CNG_enc_ivas_fx( move16(); st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; move16(); - /* Temp variables for floating point functions */ lp_ener_thr_scale = 8; /* 4.0f*/ /* Q1 */ move16(); @@ -1266,58 +1285,94 @@ void CNG_enc_ivas_fx( move16(); } - w_temp = 1; - move64(); - - FOR( j = 0; j < st_fx->L_frame; j++ ) +#ifdef HARM_NON_LINEARITY + IF( st_fx->element_mode == EVS_MONO ) { - w_temp = W_mac0_16_16( w_temp, speech[j], speech[j] ); + pt_sp = speech; + L_ener = L_deposit_l( 1 ); + /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + FOR( j = 0; j < 128; j++ ) + { + L_tmp = L_mult0( *pt_sp, *pt_sp ); + pt_sp++; + L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); + pt_sp++; + L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ + } + } + ELSE /* L_FRAME16k */ + { + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 80; j++ ) + { + L_tmp = L_mult0( *pt_sp, *pt_sp ); + pt_sp++; + L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); + pt_sp++; + L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ + } + } + } } - exp = W_norm( w_temp ); + ELSE +#endif + { + w_temp = 1; + move64(); - inv_frame_len = 0; - move32(); + FOR( j = 0; j < st_fx->L_frame; j++ ) + { + w_temp = W_mac0_16_16( w_temp, speech[j], speech[j] ); + } + exp = W_norm( w_temp ); - SWITCH( st_fx->L_frame ) - { - case L_FRAME25_6k: - inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; - move16(); - BREAK; - case L_FRAME: - inv_frame_len = ONE_BY_L_FRAME_Q31; - move16(); - BREAK; - case L_FRAME48k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; - move16(); - BREAK; - case 240: - inv_frame_len = ONE_BY_240_Q31; - move16(); - BREAK; - case L_FRAME32k: - inv_frame_len = ONE_BY_L_FRAME32k_Q31; - move16(); - BREAK; - case L_FRAME16k: - inv_frame_len = ONE_BY_L_FRAME16k_Q31; - move16(); - BREAK; - case L_FRAME8k: - inv_frame_len = ONE_BY_L_FRAME8k_Q31; - move16(); - BREAK; - case L_FRAME4k: - inv_frame_len = ONE_BY_L_FRAME4k_Q31; - move16(); - BREAK; - default: - inv_frame_len = divide3216( 1, st_fx->L_frame ); + inv_frame_len = 0; + move32(); + + SWITCH( st_fx->L_frame ) + { + case L_FRAME25_6k: + inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; + move16(); + BREAK; + case L_FRAME: + inv_frame_len = ONE_BY_L_FRAME_Q31; + move16(); + BREAK; + case L_FRAME48k: + inv_frame_len = ONE_BY_L_FRAME48k_Q31; + move16(); + BREAK; + case 240: + inv_frame_len = ONE_BY_240_Q31; + move16(); + BREAK; + case L_FRAME32k: + inv_frame_len = ONE_BY_L_FRAME32k_Q31; + move16(); + BREAK; + case L_FRAME16k: + inv_frame_len = ONE_BY_L_FRAME16k_Q31; + move16(); + BREAK; + case L_FRAME8k: + inv_frame_len = ONE_BY_L_FRAME8k_Q31; + move16(); + BREAK; + case L_FRAME4k: + inv_frame_len = ONE_BY_L_FRAME4k_Q31; + move16(); + BREAK; + default: + inv_frame_len = divide3216( 1, st_fx->L_frame ); + } + L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ + L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ + L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ } - L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ - L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ - L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ hi = norm_l( L_ener ); lo = Log2_norm_lc( L_shl( L_ener, hi ) ); @@ -1358,6 +1413,7 @@ void CNG_enc_ivas_fx( move16(); } } + /* update the pointer to circular buffer of old LSP vectors */ hTdCngEnc->cng_hist_ptr = add( hTdCngEnc->cng_hist_ptr, 1 ); move16(); @@ -1374,6 +1430,7 @@ void CNG_enc_ivas_fx( * Find CNG spectral envelope * Find LSP median *-----------------------------------------------------------------*/ + test(); test(); IF( ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) && GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) @@ -1456,6 +1513,7 @@ void CNG_enc_ivas_fx( * Quantize CNG spectral envelope (only in SID frame) * Quantize the LSF vector *-----------------------------------------------------------------*/ + *allow_cn_step = 0; move16(); test(); @@ -1493,7 +1551,6 @@ void CNG_enc_ivas_fx( } } - test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { @@ -1531,6 +1588,7 @@ void CNG_enc_ivas_fx( * CNG spectral envelope update * Find A(z) coefficients *---------------------------------------------------------------------*/ + test(); test(); IF( ( st_fx->last_core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_1k75 ) || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) @@ -1635,8 +1693,26 @@ void CNG_enc_ivas_fx( IF( hTdCngEnc->burst_ho_cnt > 0 ) { - /**allow_cn_step |= ( hDtxEnc->first_CNG || st->element_mode == EVS_MONO ) && ( hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener );*/ - w_temp = W_msu_32_16( W_shl( W_deposit32_l( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 2 ), hTdCngEnc->lp_ener_fx, lp_ener_thr_scale ); /*Q8*/ +#ifdef HARM_NON_LINEARITY + IF( st_fx->element_mode == EVS_MONO ) + { + /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ + /*allow_cn_step |= (hDtxEnc->first_CNG || st->element_mode == EVS_MONO) && (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener);*/ + /* (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener); */ + L_tmp1 = L_shr( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2 ); + IF( NE_16( lp_ener_thr_scale, 8 ) ) + { + L_tmp1 = L_add( L_tmp1, L_shr( hTdCngEnc->lp_ener_fx, 8 ) ); + } + L_tmp1 = L_sub( L_tmp1, hTdCngEnc->lp_ener_fx ); + w_temp = W_deposit32_l( L_tmp1 ); + } + ELSE +#endif + { + /**allow_cn_step |= ( hDtxEnc->first_CNG || st->element_mode == EVS_MONO ) && ( hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener );*/ + w_temp = W_msu_32_16( W_shl( W_deposit32_l( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 2 ), hTdCngEnc->lp_ener_fx, lp_ener_thr_scale ); /*Q8*/ + } test(); test(); @@ -1646,6 +1722,7 @@ void CNG_enc_ivas_fx( move16(); } } + test(); IF( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) { @@ -1798,18 +1875,43 @@ void CNG_enc_ivas_fx( } } - dist = 0; /*Q15 */ - move32(); - max_dev = 0; /*Q15 */ - move32(); - FOR( i = 0; i < M; i++ ) +#ifdef HARM_NON_LINEARITY + IF( st_fx->element_mode == EVS_MONO ) + { + dist16 = 0; /*Q15 */ + move16(); + max_dev16 = 0; /*Q15 */ + move16(); + move16(); + FOR( i = 0; i < M; i++ ) + { + dev16 = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15 */ + dist16 = add_sat( dist16, dev16 ); /*Q15 */ + if ( GT_16( dev16, max_dev16 ) ) + { + max_dev16 = dev16; + move16(); + } + } + dist = L_deposit_l( dist16 ); + max_dev = L_deposit_l( max_dev16 ); + } + ELSE +#endif { - dev = L_abs( L_sub( L_deposit_l( lsp_tmp[i] ), L_deposit_l( lsp_new[i] ) ) ); /*Q15 */ - dist = L_add( dist, dev ); /*Q15 */ - if ( GT_32( dev, max_dev ) ) + dist = 0; /*Q15 */ + move32(); + max_dev = 0; /*Q15 */ + move32(); + FOR( i = 0; i < M; i++ ) { - max_dev = dev; - move32(); + dev = L_abs( L_sub( L_deposit_l( lsp_tmp[i] ), L_deposit_l( lsp_new[i] ) ) ); /*Q15 */ + dist = L_add( dist, dev ); /*Q15 */ + if ( GT_32( dev, max_dev ) ) + { + max_dev = dev; + move32(); + } } } @@ -1865,6 +1967,7 @@ void CNG_enc_ivas_fx( Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ } } + IF( st_fx->Opt_AMR_WB != 0 ) { E_LPC_f_isp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); @@ -1872,8 +1975,13 @@ void CNG_enc_ivas_fx( ELSE { E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); - exp = sub( Q14, norm_s( Aq[0] ) ); - Scale_sig( Aq, M + 1, sub( Q12, exp ) ); // Q12 +#ifdef HARM_NON_LINEARITY + IF( st_fx->element_mode != EVS_MONO ) +#endif + { + exp = sub( Q14, norm_s( Aq[0] ) ); + Scale_sig( Aq, M + 1, sub( Q12, exp ) ); // Q12 + } } tmp_loop = shr( st_fx->L_frame, 6 ); @@ -1881,6 +1989,7 @@ void CNG_enc_ivas_fx( { Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); } + /*-----------------------------------------------------------------* * Find residual signal * Calculate residual signal energy per sample @@ -1956,72 +2065,127 @@ void CNG_enc_ivas_fx( /* calculate the residual signal energy */ /*enr = dotp( res, res, L_frame ) / L_frame; */ - w_temp = 1; - move64(); - FOR( j = 0; j < st_fx->L_frame; j++ ) +#ifdef HARM_NON_LINEARITY + IF( st_fx->element_mode == EVS_MONO ) { - w_temp = W_mac0_16_16( w_temp, res[j], res[j] ); - } - exp = W_norm( w_temp ); + Word16 maxv, scale; - SWITCH( st_fx->L_frame ) - { - case L_FRAME25_6k: - inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; - move16(); - BREAK; - case L_FRAME: - inv_frame_len = ONE_BY_L_FRAME_Q31; - move16(); - BREAK; - case L_FRAME48k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; - move16(); - BREAK; - case 240: - inv_frame_len = ONE_BY_240_Q31; - move16(); - BREAK; - case L_FRAME32k: - inv_frame_len = ONE_BY_L_FRAME32k_Q31; - move16(); - BREAK; - case L_FRAME16k: - inv_frame_len = ONE_BY_L_FRAME16k_Q31; - move16(); - BREAK; - case L_FRAME8k: - inv_frame_len = ONE_BY_L_FRAME8k_Q31; - move16(); - BREAK; - case L_FRAME4k: - inv_frame_len = ONE_BY_L_FRAME4k_Q31; - move16(); - BREAK; - default: - inv_frame_len = divide3216( 1, st_fx->L_frame ); - } - L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ - L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ - L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ - - /* convert log2 of residual signal energy */ - /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ - - IF( L_ener == 0 ) - { - enr = -850; /*log(0.1) base 2 in Q8*/ + maxv = 0; move16(); + FOR( i = 0; i < st_fx->L_frame; i++ ) + { + maxv = s_max( maxv, abs_s( res[i] ) ); + } + scale = norm_s( maxv ); + pt_res = res; + L_ener = L_deposit_l( 1 ); + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + FOR( j = 0; j < 128; j++ ) + { + tmpv = shl( *pt_res, scale ); + L_tmp = L_mult0( tmpv, tmpv ); + pt_res++; + tmpv = shl( *pt_res, scale ); + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ + } + } + ELSE /* L_FRAME16k */ + { + FOR( j = 0; j < 160; j++ ) + { + tmpv = shl( *pt_res, scale ); + L_tmp = L_mult0( tmpv, tmpv ); + pt_res++; + tmpv = shl( *pt_res, scale ); + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ + } + } + + /* convert log2 of residual signal energy */ + /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ + hi = norm_l( L_ener ); + lo = Log2_norm_lc( L_shl( L_ener, hi ) ); + hi = sub( 29, hi ); /* log2 exp in Q2*(Q_new+scale) */ + hi = sub( hi, shl( add( Q_new, scale ), 1 ) ); /* Q0 */ + L_tmp = L_Comp( hi, lo ); /* Q16 */ + enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ } ELSE +#endif { - hi = norm_l( L_ener ); - lo = Log2_norm_lc( L_shl( L_ener, hi ) ); - hi = sub( 29, hi ); /* log2 exp in Q2*Q_new */ - hi = sub( hi, shl( Q_new, 1 ) ); /* Q0 */ - L_tmp = L_Comp( hi, lo ); /* Q16 */ - enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ + w_temp = 1; + move64(); + FOR( j = 0; j < st_fx->L_frame; j++ ) + { + w_temp = W_mac0_16_16( w_temp, res[j], res[j] ); + } + exp = W_norm( w_temp ); + + SWITCH( st_fx->L_frame ) + { + case L_FRAME25_6k: + inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; + move16(); + BREAK; + case L_FRAME: + inv_frame_len = ONE_BY_L_FRAME_Q31; + move16(); + BREAK; + case L_FRAME48k: + inv_frame_len = ONE_BY_L_FRAME48k_Q31; + move16(); + BREAK; + case 240: + inv_frame_len = ONE_BY_240_Q31; + move16(); + BREAK; + case L_FRAME32k: + inv_frame_len = ONE_BY_L_FRAME32k_Q31; + move16(); + BREAK; + case L_FRAME16k: + inv_frame_len = ONE_BY_L_FRAME16k_Q31; + move16(); + BREAK; + case L_FRAME8k: + inv_frame_len = ONE_BY_L_FRAME8k_Q31; + move16(); + BREAK; + case L_FRAME4k: + inv_frame_len = ONE_BY_L_FRAME4k_Q31; + move16(); + BREAK; + default: + inv_frame_len = divide3216( 1, st_fx->L_frame ); + } + L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ + L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ + L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ + + /* convert log2 of residual signal energy */ + /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ + + IF( L_ener == 0 ) + { + enr = -850; /*log(0.1) base 2 in Q8*/ + move16(); + } + ELSE + { + hi = norm_l( L_ener ); + lo = Log2_norm_lc( L_shl( L_ener, hi ) ); + hi = sub( 29, hi ); /* log2 exp in Q2*Q_new */ + hi = sub( hi, shl( Q_new, 1 ) ); /* Q0 */ + L_tmp = L_Comp( hi, lo ); /* Q16 */ + enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ + } } + /* update the circular buffer of old energies */ hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; move16(); /* Q8 */ @@ -2029,6 +2193,7 @@ void CNG_enc_ivas_fx( /*-----------------------------------------------------------------* * Quantize residual signal energy (only in SID frame) *-----------------------------------------------------------------*/ + test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { @@ -2348,6 +2513,7 @@ void CNG_enc_ivas_fx( /*-----------------------------------------------------------------* * Updates *-----------------------------------------------------------------*/ + /* update the SID frames counter */ test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) @@ -2368,6 +2534,8 @@ void CNG_enc_ivas_fx( return; } + +#ifndef HARM_NON_LINEARITY /*---------------------------------------------------------------------* * swb_CNG_enc() * @@ -2490,6 +2658,7 @@ static void shb_CNG_encod_fx( * * Decide if encoding SHB SID or not *---------------------------------------------------------------------*/ + static Word16 shb_DTX_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ @@ -2669,16 +2838,19 @@ static Word16 shb_DTX_fx( return ( update_fx ); } +#endif /*---------------------------------------------------------------------* * calculate_hangover_attenuation_gain_fx() * * *---------------------------------------------------------------------*/ + void calculate_hangover_attenuation_gain_fx( +#ifndef HARM_NON_LINEARITY Encoder_State *st, /* i : encoder state structure */ - Word16 *att, /* o : attenuation factor Q15 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + Word16 *att, /* o : attenuation factor Q15 */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { Word16 offset; @@ -2718,9 +2890,10 @@ void calculate_hangover_attenuation_gain_fx( } void calculate_hangover_attenuation_gain_ivas_fx( - Encoder_State *st, /* i : encoder state structure */ - Word16 *att, /* o : attenuation factor Q15 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ +#endif + Encoder_State *st, /* i : encoder state structure */ + Word16 *att, /* o : attenuation factor Q15 */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { Word16 lim, result_e; @@ -2742,6 +2915,22 @@ void calculate_hangover_attenuation_gain_ivas_fx( *att = extract_h( L_shl_sat( L_tmp, result_e ) ); move16(); } +#ifdef HARM_NON_LINEARITY + ELSE IF( st->element_mode == EVS_MONO ) + { + Word16 offset = 5; + move16(); + test(); + if ( EQ_16( st->bwidth, WB ) && st->hDtxEnc->CNG_mode >= 0 ) + { + offset = st->hDtxEnc->CNG_mode; + move16(); + } + assert( st->hTdCngEnc->burst_ho_cnt > 0 ); + *att = CNG_burst_att_fx[offset][st->hTdCngEnc->burst_ho_cnt - 1]; /*Q15*/ + move16(); + } +#endif ELSE { test(); @@ -2771,10 +2960,21 @@ void calculate_hangover_attenuation_gain_ivas_fx( return; } + +#ifdef HARM_NON_LINEARITY +/*---------------------------------------------------------------------* + * swb_CNG_enc() + * + * SWB DTX/CNG encoding + *---------------------------------------------------------------------*/ + +void swb_CNG_enc_fx( +#else void swb_CNG_enc_ivas_fx( +#endif Encoder_State *st, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ ) { Word16 shb_SID_updt; @@ -2788,10 +2988,18 @@ void swb_CNG_enc_ivas_fx( IF( GE_32( st->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) ) { /* decide if SHB SID encoding or not */ +#ifdef HARM_NON_LINEARITY + shb_SID_updt = shb_DTX_fx( st, shb_speech_fx, syn_12k8_16k_fx ); +#else shb_SID_updt = shb_DTX_ivas_fx( st, shb_speech_fx, syn_12k8_16k_fx ); +#endif /* SHB CNG encoding */ +#ifdef HARM_NON_LINEARITY + shb_CNG_encod_fx( st, shb_SID_updt ); +#else shb_CNG_encod_ivas_fx( st, shb_SID_updt ); +#endif } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_32( st->core_brate, SID_2k40 ) ) { @@ -2821,7 +3029,11 @@ void swb_CNG_enc_ivas_fx( * SID parameters encoding for SHB signal *---------------------------------------------------------------------*/ +#ifdef HARM_NON_LINEARITY +static void shb_CNG_encod_fx( +#else static void shb_CNG_encod_ivas_fx( +#endif Encoder_State *st, /* i/o: State structure */ const Word16 update /* i : SID update flag */ ) @@ -2829,17 +3041,17 @@ static void shb_CNG_encod_ivas_fx( Word16 idx_ener = 0; move16(); BSTR_ENC_HANDLE hBstr = st->hBstr; - Word16 ener_mid_dec_thr_fx; IF( EQ_16( update, 1 ) ) { IF( st->element_mode == EVS_MONO ) { - /* 6.0 in Q8 -> 1510 */ - /* 0.9 in Q15 29491 */ - /* ( 1 / log10(2.0) ) * 0.1 in Q15 ->10886 */ +#ifdef HARM_NON_LINEARITY + idx_ener = shr( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 9797 ), 1510 ), 8 ); /* Q0 */ +#else idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 29491 ), 8 ); /* Q0 */ +#endif } ELSE { @@ -2850,7 +3062,6 @@ static void shb_CNG_encod_ivas_fx( idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 22938 ), 8 ); /* Q0 */ } - if ( LT_16( st->bwidth, SWB ) ) { idx_ener = 0; @@ -2911,6 +3122,7 @@ static void shb_CNG_encod_ivas_fx( push_indice( hBstr, IND_SHB_CNG_GAIN, idx_ener, 4 ); push_indice( hBstr, IND_SID_BW, 1, 1 ); delete_indice( hBstr, IND_CNG_ENV1 ); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 ); @@ -2919,6 +3131,7 @@ static void shb_CNG_encod_ivas_fx( { push_indice( hBstr, IND_UNUSED, 0, 2 ); } + st->hTdCngEnc->ho_sid_bw = L_shl( L_and( st->hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); st->hTdCngEnc->ho_sid_bw = L_or( st->hTdCngEnc->ho_sid_bw, 0x1L ); move32(); @@ -2934,21 +3147,25 @@ static void shb_CNG_encod_ivas_fx( return; } + /*---------------------------------------------------------------------* * shb_DTX() * * Decide if encoding SHB SID or not *---------------------------------------------------------------------*/ +#ifdef HARM_NON_LINEARITY +static Word16 shb_DTX_fx( +#else static Word16 shb_DTX_ivas_fx( +#endif Encoder_State *st, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ ) { Word16 i; Word16 update; - Word16 allow_cn_step = 0; move16(); Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4]; @@ -2997,7 +3214,6 @@ static Word16 shb_DTX_ivas_fx( exp = sub( 30 - 1, exp ); shb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - test(); IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { @@ -3011,7 +3227,11 @@ static Word16 shb_DTX_ivas_fx( } ELSE { +#ifdef HARM_NON_LINEARITY + att_fx = 1664; /*6.5 in Q8*/ +#else att_fx = -1664; // Q8 +#endif move16(); } @@ -3019,8 +3239,6 @@ static Word16 shb_DTX_ivas_fx( IF( st->hDtxEnc->first_CNG == 0 ) { - - hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; // Q8 hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; // Q8 hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; // Q8 @@ -3030,6 +3248,7 @@ static Word16 shb_DTX_ivas_fx( move16(); move16(); } + IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12 in Q8*/ ) ) { allow_cn_step = 1; @@ -3067,7 +3286,6 @@ static Word16 shb_DTX_ivas_fx( hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); update = 0; - move16(); move16(); @@ -3081,7 +3299,11 @@ static Word16 shb_DTX_ivas_fx( update = 1; move16(); } +#ifdef HARM_NON_LINEARITY + ELSE IF( st->element_mode != EVS_MONO && hTdCngEnc->shb_cng_ini_cnt > 0 ) +#else ELSE IF( hTdCngEnc->shb_cng_ini_cnt > 0 ) +#endif { hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 ); update = 1; @@ -3098,6 +3320,15 @@ static Word16 shb_DTX_ivas_fx( update = 1; move16(); } +#ifdef HARM_NON_LINEARITY + ELSE IF( st->element_mode == EVS_MONO && hTdCngEnc->shb_cng_ini_cnt > 0 ) + { + hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 ); + update = 1; + move16(); + move16(); + } +#endif ELSE IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 ) ) { update = 1; diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index e1a246817faa043ea9422931d70f1cbee6613680..8e40d9530526cb03590365f4f444749d824cebc4 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3617,7 +3617,11 @@ void QuantizeTCXSpectrum_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { +#ifdef HARM_NON_LINEARITY + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); +#else calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); +#endif *gain_tcx_fx = mult( *gain_tcx_fx, att_fx ); move16(); } diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index cdecaf3d6f34caa5d7f2bce86f20c85b8bc0ace5..ce0a8f23e9eaba0c5d23dccb754279f2dfadc746 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -460,18 +460,29 @@ void core_encode_openloop_fx( E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); E_LPC_a_lsp_conversion( A, lsptmp, lsp_new, M ); Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 1 ); + +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsptmp, res, st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, + Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate, EVS_MONO, -1 ); +#else cng_params_upd_fx( lsptmp, res, st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); +#endif } ELSE { +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsp_new, hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, + Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate, EVS_MONO, -1 ); +#else cng_params_upd_fx( lsp_new, hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); +#endif } IF( EQ_16( st->L_frame, L_FRAME ) ) diff --git a/lib_enc/enc_acelp_tcx_main_fx.c b/lib_enc/enc_acelp_tcx_main_fx.c index da8443f06c0045c58772ae2284c051a81a7e5126..5e3c9241bc4cfcf81190db2bb71e82992fa81655 100644 --- a/lib_enc/enc_acelp_tcx_main_fx.c +++ b/lib_enc/enc_acelp_tcx_main_fx.c @@ -63,15 +63,19 @@ void enc_acelp_tcx_main_fx( { core_encode_twodiv_fx( new_samples, st, st->coder_type, Aw, vad_hover_flag, Q_new, shift ); } + /*-----------------------------------------------------------------* * Apply non linearity to the SHB excitation *-----------------------------------------------------------------*/ - test(); IF( EQ_16( st->core, ACELP_CORE ) && st->igf != 0 ) { +#ifdef HARM_NON_LINEARITY + non_linearity_fx( EVS_MONO, ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new, st->coder_type, voice_factors, st->L_frame ); +#else non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new, st->coder_type, voice_factors, st->L_frame ); +#endif /* update the old BWE exe memory */ Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/ diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index d9a1dd5b744bf213905424ff0f267a3ea921cee6..8f70a5b3642a8cc15c5ba7d1c23d6c0b5b6b73e5 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -337,7 +337,11 @@ void hq_hr_enc_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { +#ifdef HARM_NON_LINEARITY + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); +#else calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); +#endif v_multc_att32( t_audio_fx, att_fx, t_audio_fx, sfm_end[( num_sfm - 1 )] ); /* Q12 */ } diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 6c55e8b3114e4c40832bca74d7fe64226985b5fc..0adf23debdbcb6caa2b023afbd30a7090b1e6f70 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -4137,7 +4137,11 @@ void IGFEncApplyMono_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { +#ifdef HARM_NON_LINEARITY + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); +#else calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); +#endif } IGF_CalculateEnvelope_ivas_fx( st->hIGFEnc, pMDCTSpectrum_fx, e_mdct, pPowerSpectrumParameter_fx, pPowerSpectrumParameter_exp, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, st->element_mode, att_fx ); diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index ddbe6e7827157c7a696cd6f47aa8a78cdf55b1ae..5810358c0db87a00677096df00fd2834b983fefd 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -796,7 +796,11 @@ ivas_error ivas_core_enc_fx( { /* SHB DTX/CNG encoder */ Copy_Scale_sig_32_16( shb_speech_fx32, shb_speech_fx, L_FRAME16k, negate( Q_shb_spch ) ); // Q0 +#ifdef HARM_NON_LINEARITY + swb_CNG_enc_fx( st, shb_speech_fx /* Unmodified */, old_syn_12k8_16k_fx[n] ); +#else swb_CNG_enc_ivas_fx( st, shb_speech_fx /* Unmodified */, old_syn_12k8_16k_fx[n] ); +#endif } /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index b4defbc1caeafe47c4a84d772ccb0864db73f9de..1b2833473082992f2f84e2e27a9a1dbb744732a1 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -634,17 +634,27 @@ void stereo_tcx_core_enc( E_LPC_a_lsp_conversion( A_fx, lsptmp_fx, lsp_new_fx, M ); Residu3_fx( A_fx, buf_fx + L_LP - L_FRAME, res_fx, L_FRAME, 0 ); +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsptmp_fx, res_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, + Q_r, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#else cng_params_upd_ivas_fx( lsptmp_fx, res_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, Q_r, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#endif Q_exc = Q_r; move16(); } ELSE { +#ifdef HARM_NON_LINEARITY + cng_params_upd_fx( lsp_new_fx, st->hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, + st->hLPDmem->q_lpd_old_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#else cng_params_upd_ivas_fx( lsp_new_fx, st->hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, st->hLPDmem->q_lpd_old_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#endif } IF( EQ_16( st->L_frame, L_FRAME ) ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 0b607089f0a63240980fd341b1c1c2df2e237832..451cf3bc679e90281971ee149378b0f5437efe1f 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -645,12 +645,13 @@ void swb_CNG_enc_fx( const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz */ ); +#ifndef HARM_NON_LINEARITY void swb_CNG_enc_ivas_fx( Encoder_State *st, /* i/o: State structure */ const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ ); - +#endif void swb_pre_proc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *input_fx, /* i : original i signal */ @@ -1781,6 +1782,7 @@ void reset_rf_indices_fx( ); void CNG_enc_fx( +#ifndef HARM_NON_LINEARITY Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ @@ -1794,10 +1796,10 @@ void CNG_enc_fx( Word16 *sid_bw ); void CNG_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ - // Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ +#endif + Encoder_State *st_fx, /* i/o: State structure */ + Word16 Aq[], /* o : LP coefficients Q12 */ + const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */