From 768f1e1bdfd206652ee0c77678b27a6f78fb17ca Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 19 Jul 2024 13:56:10 +0530 Subject: [PATCH] acelp core dec basop updates, generate_comfort_noise_dec_ivas_fx integration [x] Integration of generate_comfort_noise_dec_ivas_fx [x] Corrected incorrect basop usage in acelp_core_dec_ivas_fx [x] Basop and Instrumentation changes for acelp_core_dec_ivas_fx [x] Restoring some float functions --- lib_com/gs_bitallocation.c | 334 ++++ lib_com/options.h | 1 + lib_dec/acelp_core_dec_fx.c | 4 +- lib_dec/acelp_core_dec_ivas_fx.c | 2114 ++++++++++++------------ lib_dec/fd_cng_dec_fx.c | 2 +- lib_dec/ivas_cpe_dec_fx.c | 6 - lib_dec/ivas_mc_param_dec.c | 86 - lib_dec/ivas_out_setup_conversion.c | 46 +- lib_dec/ivas_stereo_cng_dec.c | 2 - lib_dec/ivas_stereo_mdct_core_dec.c | 153 +- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 271 +-- 11 files changed, 1501 insertions(+), 1518 deletions(-) diff --git a/lib_com/gs_bitallocation.c b/lib_com/gs_bitallocation.c index 6d24ab7bb..3898daf95 100644 --- a/lib_com/gs_bitallocation.c +++ b/lib_com/gs_bitallocation.c @@ -43,6 +43,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" + /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -51,6 +52,29 @@ static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in ); +#ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING +#define Q15_0_33 10922 /* 0.33 */ +#define Q18_0_1 26214 /* 0.1 */ +#define Q18_0_50 131072 /* 0.50 */ +#define Q18_0_75 196608 /* 0.75 */ +#define Q18_0_76 199229 /* 76/100 */ +#define Q18_1_0 262144 /* 1.0 */ +#define Q18_1_2 314573 /* 1.2 */ +#define Q18_112 29360128 /* 112 */ +#define Q18_DSR_NB_PULSE 1179648 /* 4.5 */ +#define Q18_1_5xDSR_NB_PULSE 1769472 /* 1.5x4.5 */ +#define Q18_2_0xDSR_NB_PULSE ( Q18_DSR_NB_PULSE << 1 ) /* 2.0x4.5 */ + +#define Q31_0_00125 2684355 /* 0.125/100 */ +#define Q31_0_0125 26843546 /* 0.0125 */ +#define Q31_0_015 32212255 /* 0.0125 */ +#define Q31_0_02 42949673 /* 0.02 */ +#define Q31_0_17 365072220 /* 0.17 */ +#define Q31_0_23 493921239 /* 0.23 */ +static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ); +static Word16 Find_bit_alloc_IVAS_int( const Word32 core_brate, const Word16 GSC_IVAS_mode, const Word16 Diff_len, const Word16 nb_tot_bands, const Word16 L_frame, Word16 *bit, Word16 *max_ener_band, float *ener_vec, float *bits_per_bands ); +static Word16 maximum_fx( const Word16 *vec_fx, const Word16 lvec_fx, Word16 *max_fx ); +#endif /*-------------------------------------------------------------------* * bands_and_bit_alloc() @@ -89,8 +113,12 @@ void bands_and_bit_alloc( int16_t pos, band; float SWB_bit_budget; float bits_per_bands[MBANDS_GN_BITALLOC16k]; +#ifndef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING float fzero_val, mp, mb, nb_bands_adj, bit_adj; int16_t nb_pulse_per_band[MBANDS_GN_BITALLOC16k]; +#else + float fzero_val; +#endif /* initializations */ nb_tot_bands = 16; @@ -190,6 +218,7 @@ void bands_and_bit_alloc( { if ( GSC_IVAS_mode > 0 ) { +#ifndef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING SWB_bit_budget = *bit; st_band = 5; @@ -368,6 +397,10 @@ void bands_and_bit_alloc( bits_per_bands[i] += sum_bit; } } +#else + nb_tot_bands = Find_bit_alloc_IVAS_int( core_brate, GSC_IVAS_mode, Diff_len, nb_tot_bands, L_frame, bit, max_ener_band, ener_vec, bits_per_bands ); + nb_bands = nb_tot_bands; +#endif } else if ( GSC_noisy_speech ) { @@ -927,3 +960,304 @@ static float Find_bit_frac( return ( var_out ); } + +#ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING +static Word16 Find_bit_alloc_IVAS_int( /* o : Number of band to encode */ + const Word32 core_brate, /* i : core bit rate */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 Diff_len, /* i : Length of the difference signal (before pure spectral)*/ + const Word16 nb_tot_bands_in, /* i : total number of band */ + const Word16 L_frame, /* i : frame length */ + Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ + Word16 *max_ener_band, /* i/o: Energy based sorted order */ + float *ener_vec_io, /* i/o: Energy per band order */ + float *bits_per_bands_o /* o : Number of bit allowed per allowed sub-band Q3 */ +) +{ + Word32 mp, mb, nb_bands_adj, bit_adj; + Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k]; + Word32 SWB_bit_budget; // Q0 -> Q18 + Word16 i, j, nb_bands_max, st_band, nb_tot_bands_loc, etmp; + Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/; + Word16 d_tmp, e_div, tmp16, ener_vec[MBANDS_GN_BITALLOC16k]; + Word32 Ltmp, etmp_32fx, bits_per_bands[MBANDS_GN_BITALLOC16k]; + + SWB_bit_budget = *bit; // Q0 + st_band = 5; + nb_bands_max = nb_tot_bands_in; + + for ( i = 0; i < MBANDS_GN; i++ ) + { + ener_vec[i] = (short) ( ener_vec_io[i] ); /* Q12 -> Q12 */ + } + + if ( L_frame == L_FRAME16k ) + { + for ( i = MBANDS_GN; i < MBANDS_GN_BITALLOC16k; i++ ) + { + ener_vec[i] = (short) ( ener_vec_io[i] * 4096.0 + 0.5f ); /* Q0 -> Q12 */ + } + } + + set_l( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); + + /* Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */ + /* bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100; */ + bit_fracf = L_add( Mpy_32_32( -Q31_0_00125, L_shl( Diff_len, 18 ) ), Q18_0_76 ); /* Q18 */ + + /* bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f); */ + bit_fracf = min( max( bit_fracf, Q18_0_50 ), Q18_0_75 ); + + /* Adjusment of the bitrate between LF and HF base on the content type */ + /* 1 = new GSC bit alloc + 2 = GSC bit alloc for tc frame + 3 = more music like (should not happen often given music is coded with dft) */ + + if ( GSC_IVAS_mode <= 3 ) + { + nb_bands_max -= 6; + } + + if ( GSC_IVAS_mode == 2 ) + { + /* bit_fracf += 0.1f; */ + bit_fracf += Q18_0_1; /* Q18*/ + nb_bands_max -= 1; + } + + if ( GSC_IVAS_mode == 3 ) + { + /* bit_fracf -= 0.1f; */ + bit_fracf -= Q18_0_1; /* Q18*/ + nb_bands_max += 3; + } + + /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/ + /* Adjust the number of band based on the content type and bitrate */ + + /* nb_bands_adj = 1.0f; */ + nb_bands_adj = Q18_1_0; + if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG ) + { + /* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/ + nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, 18 ) ), Q18_0_75 ); // Q18 + } + else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG ) + { + /*nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;*/ + nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, 18 ) ), Q18_1_2 ); // Q18 + } + /*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/ + + nb_bands_max = round_fx( Mpy_32_16_1( L_shl( nb_bands_adj, 5 ), shl( nb_bands_max, 10 - 2 ) ) ); /* Q0 */ + nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands_in ); + + /* bit_fracf *= SWB_bit_budget;*/ + /* At this point bit_fracf has a value below 1.0 */ + bit_fracf = Mpy_32_16_1( L_shl( bit_fracf, 10 ), extract_l( L_shl( SWB_bit_budget, 5 ) ) ); /* (Q(18+10)*Q(0+5) + 1 - 16 = Q18 */ + + /* Estimation of the number of bit used in HF */ + /* with only the first weighting The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */ + /* mb = .17f * bit_fracf;*/ + mb = Mpy_32_32( Q31_0_17, bit_fracf ); /* Q18 */ + + /* mp = 2 * DSR_NB_PULSE;*/ + mp = Q18_2_0xDSR_NB_PULSE; + if ( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 ) + { + /* mp = 1.5f * DSR_NB_PULSE;*/ + mp = Q18_1_5xDSR_NB_PULSE; + } + else if ( core_brate < GSC_L_RATE_STG ) + { + /* mp = DSR_NB_PULSE;*/ + mp = Q18_DSR_NB_PULSE; + } + + /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/ + /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */ + /* compute the total possible number of band to be coded */ + + /* nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); */ + d_tmp = Find_norm_inv( L_add( mp, mb ), &e_div ); + Ltmp = Mpy_32_16_1( L_sub( L_shl( SWB_bit_budget, 18 ), bit_fracf ), d_tmp ); /* Perform mult by 1/den */ + nb_tot_bands_loc = extract_h( L_shl( Ltmp, sub( 1, e_div ) ) ); /* adjust exponent: 1 is to take into account the / 2.0f, and e_div for the num and den of the division*/ + + mp = min( mp, mb ); + tmp16 = sub( add( nb_tot_bands_loc, st_band ), nb_bands_max ); + if ( tmp16 > 0 ) + { + /* bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands_loc + st_band - nb_bands_max ); */ + bit_adj = Mpy_32_16_1( L_shl( L_add( mb, mp ), 5 ), shl( tmp16, 10 - 1 ) ); /* Q18+5 * Q0+10 + 1 -1 - 16 = Q18 (-1 is to cover for the /2 in the equation) */ + bit_adj = L_max( 0, bit_adj ); + nb_tot_bands_loc = nb_bands_max - st_band; + bit_fracf += bit_adj; /* Q18 */ + } + nb_tot_bands_loc += st_band; + + /* Allocate bits to LF */ + /* etmp = 0.23f; */ + etmp_32fx = Q31_0_23; + for ( j = 0; j < st_band; j++ ) + { + i = j; + max_ener_band[j] = i; + ener_vec[i] = MIN16B; + /* bits_per_bands[j] = etmp * bit_fracf; */ + bits_per_bands[j] = Mpy_32_32( bit_fracf, etmp_32fx ); /* 18 + 31 + 1 - 32 = Q18 */ + /* etmp -= 0.015f; */ + etmp_32fx -= Q31_0_015; /* Q18 */ + } + + /* SWB_bit_budget -= bit_fracf; */ + SWB_bit_budget = L_sub( L_shl( SWB_bit_budget, 18 ), bit_fracf ); /* Q0->Q18 */ + + /* Find low energy band in HF */ + set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k ); + for ( i = st_band + 2; i < nb_tot_bands_loc - 1; i++ ) + { + if ( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] ) /* i +1 and i -1 can be considered as 2 ptrs */ + { + nb_pulse_per_band[i] = 1; + } + } + + for ( j = st_band; j < nb_tot_bands_loc; j++ ) + { + if ( j > 6 ) + { + i = maximum_fx( ener_vec, nb_tot_bands_loc, &etmp ); + } + else + { + i = j; + } + max_ener_band[j] = i; + ener_vec[i] = MIN16B; + } + + /* Recompute the final bit distribution for HF */ + if ( nb_tot_bands_loc > st_band ) + { + /* This is not bit exact because of the precision lost */ + /* mb = ( SWB_bit_budget * 2 / ( nb_tot_bands_loc - st_band ) ) - mp; */ + d_tmp = Find_norm_inv( L_deposit_h( sub( nb_tot_bands_loc, st_band ) ), &e_div ); + mb = L_sub( L_shr( Mpy_32_16_1( L_shl( SWB_bit_budget, 1 ), d_tmp ), e_div ), mp ); /* Q18 */ + /* bit_fracf = ( mb - mp ) / ( nb_tot_bands_loc - st_band ); */ + bit_fracf = L_shr( Mpy_32_16_1( L_sub( mb, mp ), d_tmp ), e_div ); /* Q18 */ + + mb -= bit_fracf; + /* Do the distribution */ + for ( j = st_band; j < nb_tot_bands_loc; j++ ) + { + bits_per_bands[max_ener_band[j]] = Q18_DSR_NB_PULSE; + if ( nb_pulse_per_band[max_ener_band[j]] > 1 ) + { + bits_per_bands[max_ener_band[j]] = mb; + } + mb -= bit_fracf; + SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; // Q18 + } + } + + /* Series of verification in case bit allocated != the budget */ + if ( SWB_bit_budget > 0 ) + { + i = st_band - 1; + while ( SWB_bit_budget > 0 ) + { + /* bits_per_bands[i]++; */ + bits_per_bands[i] += Q18_1_0; + /* SWB_bit_budget--; */ + SWB_bit_budget -= Q18_1_0; + i--; + if ( i == -1 ) + { + i = st_band - 1; + } + } + } + + /*nb_bands = nb_tot_bands_loc;*/ + + sum_bit = 0; + j = 0; + for ( i = 0; i < nb_tot_bands_loc; i++ ) + { + /* if (bits_per_bands[i] > 112) */ + if ( bits_per_bands[i] > Q18_112 ) + { + /* sum_bit += bits_per_bands[i] - 112; */ + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], Q18_112 ) ); + /* bits_per_bands[i] = 112; */ + bits_per_bands[i] = Q18_112; + j = add( j, add( i, 1 ) ); + } + + /* safety check for overage bit reallocation */ + /* else if (bits_per_bands[i] + sum_bit / 3 > 112) */ + else if ( L_add( bits_per_bands[i], Mpy_32_16_1( sum_bit, Q15_0_33 ) ) > Q18_112 ) + { + j = add( j, add( i, 1 ) ); + } + } + + if ( sum_bit != 0 ) + { + /* sum_bit /= (nb_bands - j); */ + d_tmp = Find_norm_inv( L_deposit_h( sub( nb_tot_bands_loc, j ) ), &e_div ); + sum_bit = L_shr( Mpy_32_16_1( sum_bit, d_tmp ), e_div ); /* Q18 */ + for ( i = j; i < nb_tot_bands_loc; i++ ) + { + bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit ); + } + } + + for ( i = 0; i < MBANDS_GN_BITALLOC16k; i++ ) + { + bits_per_bands_o[i] = (float) bits_per_bands[i] / 262144.0f; /* Q18 -> float */ + } + + return nb_tot_bands_loc; +} + +/* Find normalized 1 / ToDivide */ +static Word16 Find_norm_inv( + const Word32 ToDivide, + Word16 *e_div ) +{ + Word16 d_tmp, e_tmp; + + e_tmp = norm_l( ToDivide ); + d_tmp = round_fx( L_shl( ToDivide, e_tmp ) ); + d_tmp = div_s( 16384, d_tmp ); /* 1.0 in Q14, dividend is normalize so >= 16384 as required for the division */ + *e_div = sub( 14, e_tmp ); + + return d_tmp; +} + +static Word16 maximum_fx( /* o : index of the maximum value in the input vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word16 *max_fx /* o : maximum value in the input vector */ +) +{ + Word16 j, ind; + Word16 tmp; + + ind = 0; + tmp = vec_fx[0]; + + for ( j = 1; j < lvec_fx; j++ ) + { + if ( vec_fx[j] > tmp ) + { + ind = j; + } + tmp = s_max( tmp, vec_fx[j] ); + } + *max_fx = tmp; + + return ind; +} +#endif diff --git a/lib_com/options.h b/lib_com/options.h index 32b4203c0..34e869556 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -77,6 +77,7 @@ #define FIX_1027_GSC_INT_OVERFLOW /* VA: issue 2207: overflow in GSC */ #define NONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO /* FhG: avoid sidegain DFT-Stereo param to be larger than 1 when converting from Dirac parameters */ #define NON_BE_1055_RESET_LP_MEMORIES /* VA: issue 1055: Correctly reset LP filter MA and AR memories in bitrate switching */ +#define NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING /* VA: Add fix point bit allocation for special GSC mode such that float and fixed point have the same final bit allocation */ /* #################### End FIXES switches ############################ */ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 4f21a81a8..7fb5ff3bc 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -984,7 +984,7 @@ ivas_error acelp_core_dec_fx( Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; /* SC-VBR - PPP frames */ - IF( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1007,7 +1007,7 @@ ivas_error acelp_core_dec_fx( } ELSE { - IF( ( error = decod_gen_voic_fx( st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf /*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/ ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = decod_gen_voic_fx( st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf /*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/ ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index d724b48ae..62d6dc171 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -140,7 +140,7 @@ ivas_error acelp_core_dec_ivas_fx( #endif Word16 bpf_error_signal_16fx[L_FRAME16k]; #ifdef MSAN_FIX - set_s( bpf_error_signal_16fx, 0, L_FRAME16k ); + set16_fx( bpf_error_signal_16fx, 0, L_FRAME16k ); #endif Word16 tmp; @@ -185,7 +185,7 @@ ivas_error acelp_core_dec_ivas_fx( ApplyFdCng_ivas_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); - IF( LT_16( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 0 ) ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; @@ -209,8 +209,8 @@ ivas_error acelp_core_dec_ivas_fx( Copy( lsp_new_fx, st->lsp_old_fx, M ); } - set_s( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ - set_s( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ + set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ + set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ /* CN generation done in DFT domain */ pop_wmops(); @@ -238,7 +238,7 @@ ivas_error acelp_core_dec_ivas_fx( LSF_Q_prediction = -1; move16(); - set_s( syn_tmp_fx, 0, L_SUBFR ); + set16_fx( syn_tmp_fx, 0, L_SUBFR ); psyn_fx = syn_tmp_fx + L_SUBFR; syn1_tmp_fx[0] = 0; move16(); @@ -252,7 +252,9 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) ) + test(); + test(); + IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->last_core_brate, SID_2k40 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st->bpf_off = 1; @@ -272,6 +274,7 @@ ivas_error acelp_core_dec_ivas_fx( } } + test(); IF( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) { /* reset the GSC pre echo energy threshold in case of FEC */ @@ -281,10 +284,10 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || EQ_32( st->last_core_brate, FRAME_NO_DATA ) ) ) + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || st->last_core_brate == FRAME_NO_DATA ) ) { - set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN ); - set_s( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); } st->clas_dec = st->last_good; @@ -304,7 +307,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - set_s( old_exc2_fx, 0, L_EXC_MEM ); + set16_fx( old_exc2_fx, 0, L_EXC_MEM ); } exc2_fx = old_exc2_fx + L_EXC_MEM; @@ -326,7 +329,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); st->relax_prev_lsf_interp = 0; move16(); - set_s( gain_buf_fx, 0, NB_SUBFR16k ); + set16_fx( gain_buf_fx, 0, NB_SUBFR16k ); IF( EQ_16( st->L_frame, L_FRAME ) ) { @@ -352,7 +355,7 @@ ivas_error acelp_core_dec_ivas_fx( } test(); /* reset post-filter in case of switching */ - IF( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) + if ( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) { st->hPFstat->reset = 1; move16(); @@ -362,7 +365,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); test(); - IF( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) ) + if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -386,7 +389,7 @@ ivas_error acelp_core_dec_ivas_fx( tdm_low_rate_mode = 0; move16(); test(); - IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) + if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); @@ -401,7 +404,7 @@ ivas_error acelp_core_dec_ivas_fx( *----------------------------------------------------------------*/ test(); test(); - IF( NE_16( st->last_L_frame, st->L_frame ) && ( EQ_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) + IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { Word16 dec; @@ -434,12 +437,12 @@ ivas_error acelp_core_dec_ivas_fx( { Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); } - set_s( st->mem_MA_fx, 0, M ); + set16_fx( st->mem_MA_fx, 0, M ); /* update synthesis filter memories */ dec = DEC; move16(); - IF( NE_16( st->element_mode, EVS_MONO ) ) + if ( st->element_mode != EVS_MONO ) { dec = DEC_IVAS; move16(); @@ -485,23 +488,25 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - move16(); Word16 exp = 0; + move16(); IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { tmpF_fx = 16384; + move16(); } ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { tmpF_fx = 20480; + move16(); } ELSE /* st->last_L_frame == L_FRAME12k8 */ { tmpF_fx = 20480; // Q14 + move16(); exp = 1; move16(); } - move16(); FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); @@ -524,50 +529,56 @@ ivas_error acelp_core_dec_ivas_fx( { IF( EQ_16( st->L_frame, L_FRAME ) ) { - move16(); IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { tmpF_fx = 13107; + move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { tmpF_fx = 16384; + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { tmpF_fx = 26214; + move16(); } st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx ); + move16(); st->bfi_pitch_frame = L_FRAME; move16(); } ELSE { - move16(); Word16 exp = 0; + move16(); IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { tmpF_fx = 16384; + move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { tmpF_fx = 20480; + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ { tmpF_fx = 20480; // Q14 + move16(); exp = 1; move16(); } - move16(); st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); + move16(); st->bfi_pitch_frame = L_FRAME16k; move16(); } } test(); test(); - IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) ) + if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) ) { st->rate_switching_reset = 1; move16(); @@ -598,13 +609,14 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->idchan, 0 ) && !( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) + IF( GT_16( st->element_mode, EVS_MONO ) && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { test(); test(); - IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + if ( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { st->GSC_IVAS_mode = get_next_indice( st, 2 ); + move16(); } } @@ -612,10 +624,10 @@ ivas_error acelp_core_dec_ivas_fx( * Decoding of inactive CNG frames *----------------------------------------------------------------*/ test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) + IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { /* decode CNG parameters */ - IF( EQ_16( st->cng_type, LP_CNG ) ) + IF( st->cng_type == LP_CNG ) { CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); FOR( Word32 nsf = 0; nsf < NB_SUBFR16k; nsf++ ) @@ -631,7 +643,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); test(); - IF( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) ) + if ( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) ) { local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ move16(); @@ -640,10 +652,11 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - + test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; + move16(); FdCng_decodeSID_ivas_fx( st ); rescale_fdCngDec( st->hFdCngDec, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); @@ -662,16 +675,20 @@ ivas_error acelp_core_dec_ivas_fx( move32(); } Word16 new_sidNoiseEstExp = 31 - Q4; - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp ); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp ); + move16(); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; + move16(); Word16 new_cngNoiseLevelExp = 31 - Q4; + move16(); Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; + move16(); ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - IF( LT_16( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 0 ) ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; @@ -683,7 +700,8 @@ ivas_error acelp_core_dec_ivas_fx( { Word32 noise_lvl_highest_fx; - noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand - 1]; + noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[sub( sub( st->hFdCngDec->hFdCngCom->stopFFTbin, st->hFdCngDec->hFdCngCom->startBand ), 1 )]; + move32(); FOR( Word16 b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) { st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx; @@ -819,7 +837,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( st->hTdCngDec != NULL && ( EQ_32( st->last_core_brate, FRAME_NO_DATA ) || EQ_32( st->last_core_brate, SID_2k40 ) ) ) + IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) ) { Copy( st->lspCNG_fx, st->lsp_old_fx, M ); lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs ); @@ -832,10 +850,10 @@ ivas_error acelp_core_dec_ivas_fx( IF( !st->use_acelp_preq ) { st->mem_preemp_preQ_fx = 0; - st->last_nq_preQ = 0; - st->last_code_preq = 0; move16(); + st->last_nq_preQ = 0; move16(); + st->last_code_preq = 0; move16(); } st->use_acelp_preq = 0; @@ -877,12 +895,10 @@ ivas_error acelp_core_dec_ivas_fx( } pt_interp_2_fx = interpol_frac_fx; - move16(); test(); - IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) ) + if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) ) { pt_interp_2_fx = interpol_frac2_fx; - move16(); } IF( EQ_16( st->active_cnt, 1 ) ) @@ -895,1096 +911,1039 @@ ivas_error acelp_core_dec_ivas_fx( int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 ); /* Check LSF stability (distance between old LSFs and current LSFs) */ st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); + move16(); } #ifndef MSAN_FIX for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) - { #else FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif - { - Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); - Aq_fx[imult3216( nsf, add( M, 1 ) )] = ONE_IN_Q12; - move16(); - } - test(); - IF( EQ_16( st->last_core, HQ_CORE ) && GT_16( st->element_mode, EVS_MONO ) ) - { - /* Prepare ACB memory from last HQ frame */ - old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; - tmpF_fx = *old_exc_s_fx; - st->mem_deemph_fx = old_exc_s_fx[st->L_frame - 1]; - preemph_fx( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); - Copy( old_exc_s_fx + st->L_frame - M, st->mem_syn2_fx, M ); - Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 0 ); + { + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); + Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + move16(); + } + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; + tmpF_fx = *old_exc_s_fx; + st->mem_deemph_fx = old_exc_s_fx[sub( st->L_frame, 1 )]; + move16(); + preemph_fx( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); + Copy( old_exc_s_fx + st->L_frame - M, st->mem_syn2_fx, M ); + Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 0 ); #ifdef FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR - Scale_sig( old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, st->Q_exc ); + Scale_sig( old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, st->Q_exc ); #endif + } + test(); + IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); } - test(); - IF( NE_16( st->last_core, ACELP_CORE ) && GT_16( st->element_mode, EVS_MONO ) ) + ELSE { - /* Prepare ACB memory of old_bwe_exc */ - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); - } - ELSE - { - lerp( old_exc_fx, old_bwe_exc_fx, shl( L_EXC_MEM_DEC, 1 ), L_EXC_MEM_DEC ); - } + lerp( old_exc_fx, old_bwe_exc_fx, shl( L_EXC_MEM_DEC, 1 ), L_EXC_MEM_DEC ); } + } - /*-----------------------------------------------------------------* - * FEC - first good frame after lost frame(s) (possibility to correct the ACB) - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * FEC - first good frame after lost frame(s) (possibility to correct the ACB) + *-----------------------------------------------------------------*/ - IF( st->acelp_cfg.FEC_mode > 0 ) + IF( st->acelp_cfg.FEC_mode > 0 ) + { + last_pulse_pos = 0; + move16(); + /* decode the last glottal pulse position */ + T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); + test(); + test(); + IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) ) { - last_pulse_pos = 0; - move16(); - /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); test(); test(); - IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( st->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st->prev_bfi, 1 ) ) { - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->clas_dec, SIN_ONSET ) && NE_16( last_pulse_pos, 0 ) && EQ_16( st->prev_bfi, 1 ) ) - { - FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); - } - ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && NE_16( last_pulse_pos, 0 ) && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL ) - { - do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); - } + FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); + } + ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL ) + { + do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); } } + } - /*------------------------------------------------------------* - * In case of first frame after an erasure and transition from voiced to unvoiced or inactive - * redo the LPC interpolation - *------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) - { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); - } + /*------------------------------------------------------------* + * In case of first frame after an erasure and transition from voiced to unvoiced or inactive + * redo the LPC interpolation + *------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) + { + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + } - /*---------------------------------------------------------------* - * Decoding of the scaled predicted innovation energy - *---------------------------------------------------------------*/ + /*---------------------------------------------------------------* + * Decoding of the scaled predicted innovation energy + *---------------------------------------------------------------*/ - IF( GT_16( nb_bits, 0 ) ) + IF( nb_bits > 0 ) + { + indice = get_next_indice( st, nb_bits ); + Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); + } + + /*------------------------------------------------------------* + * Decode excitation according to coding type + *------------------------------------------------------------*/ + test(); + test(); + IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + IF( LE_16( st->coder_type, UNVOICED ) ) { - indice = get_next_indice( st, nb_bits ); - Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); + tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - - /*------------------------------------------------------------* - * Decode excitation according to coding type - *------------------------------------------------------------*/ - test(); - test(); - IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + ELSE /* GENERIC */ { - IF( LE_16( st->coder_type, UNVOICED ) ) + decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + + if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - ELSE /* GENERIC */ - { - decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - } - } - ELSE IF( st->nelp_mode_dec ) - { - /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); - st->Q_exc = 0; - move16(); - /* SC-VBR - NELP frames */ - decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } - ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) + } + ELSE IF( st->nelp_mode_dec ) + { + /* SC-VBR - NELP frames */ + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + st->Q_exc = 0; + move16(); + /* SC-VBR - NELP frames */ + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) + { + /* UNVOICED frames */ + decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + ELSE IF( st->ppp_mode_dec ) + { + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + st->Q_exc = 0; + move16(); + /* SC-VBR - PPP frames */ + IF( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) { - /* UNVOICED frames */ - decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + return error; } - ELSE IF( st->ppp_mode_dec ) - { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); - st->Q_exc = 0; - move16(); - /* SC-VBR - PPP frames */ - IF( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) - { - return error; - } - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); - } - ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) + { + decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); + } + ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx +#if 1 // def ADD_LRTD + , + tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx +#endif + ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + ELSE + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + IF( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) { - decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); + return error; } - ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) + + if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - /* AUDIO and INACTIVE frames (coded by GSC technology) */ - decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx -#if 1 // def ADD_LRTD - , - tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx -#endif - ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - ELSE - { - /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - IF( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) - { - return error; - } + } - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - } + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); + + /* save and delay synthesis to be used by SWB BWE */ + IF( st->hBWE_FD != NULL ) + { + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); + } - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); + /*-----------------------------------------------------------------* + * Apply energy matching when switching to inactive frames + *-----------------------------------------------------------------*/ - /* save and delay synthesis to be used by SWB BWE */ - IF( st->hBWE_FD != NULL ) - { - save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - } + Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - /*-----------------------------------------------------------------* - * Apply energy matching when switching to inactive frames - *-----------------------------------------------------------------*/ + /*------------------------------------------------------------* + * Decode information and modify the excitation signal of stationary unvoiced frames + *------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + { + stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); + } - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + /*------------------------------------------------------------* + * Save filter memory in case the synthesis is redone after scaling + * Synthesis at 12k8 Hz sampling rate + *------------------------------------------------------------*/ - /*------------------------------------------------------------* - * Decode information and modify the excitation signal of stationary unvoiced frames - *------------------------------------------------------------*/ - test(); + /* update past excitation signals for LD music post-filter */ + IF( st->hMusicPF != NULL ) + { + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); + } + + test(); + test(); + test(); + IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) ) + { + Word16 last_coder_type = st->last_coder_type; + move16(); test(); test(); test(); - IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + if ( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) ) { - stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); + last_coder_type = AUDIO; + move16(); } - /*------------------------------------------------------------* - * Save filter memory in case the synthesis is redone after scaling - * Synthesis at 12k8 Hz sampling rate - *------------------------------------------------------------*/ + Word16 qdct = 0; + move16(); + /* Extrapolation of the last future part, windowing and high resolution DCT transform */ + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); - /* update past excitation signals for LD music post-filter */ - IF( st->hMusicPF != NULL ) + /* LD music post-filter */ + LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); + + /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, + &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, + &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); + } + ELSE + { + /* Core synthesis at 12.8kHz or 16kHz */ + i = 1; + move16(); + if ( st->coder_type == INACTIVE ) { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, sub( sub( DCT_L_POST, L_FRAME ), OFFSET2 ) ); - Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, sub( DCT_L_POST, OFFSET2 ) ); + i = 0; + move16(); } + /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ + Word16 k = 0; + move16(); test(); test(); - test(); - - IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) ) + if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) { - Word16 last_coder_type = st->last_coder_type; + k = 1; move16(); - test(); - test(); - test(); - IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) ) - { - last_coder_type = AUDIO; - move16(); - } + } - Word16 qdct = 0; - move16(); - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); - /* LD music post-filter */ - LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); - Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, - &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, - &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); - } - ELSE + IF( st->hMusicPF != NULL ) { - /* Core synthesis at 12.8kHz or 16kHz */ - i = 1; - move16(); - if ( EQ_16( st->coder_type, INACTIVE ) ) - { - i = 0; - move16(); - } - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; - move16(); - test(); - test(); - IF( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + FOR( i = 0; i < DCT_L_POST; i++ ) { - k = 1; + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); move16(); } + } + } - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); - - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); + /*------------------------------------------------------------* + * FEC - Estimate the classification information + *------------------------------------------------------------*/ - IF( st->hMusicPF != NULL ) - { - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); - } - } - } + FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, + psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, + NULL, NULL, NULL, NULL, 0, NULL, st->core_brate, st->Q_syn, temp_buf_fx, + st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, + 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode ); + /*------------------------------------------------------------* + * FEC - Estimate pitch + *------------------------------------------------------------*/ - /*------------------------------------------------------------* - * FEC - Estimate the classification information - *------------------------------------------------------------*/ + FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, + &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode ); - FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, - psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, - NULL, NULL, NULL, NULL, 0, NULL, st->core_brate, st->Q_syn, temp_buf_fx, - st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, - 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode ); - /*------------------------------------------------------------* - * FEC - Estimate pitch - *------------------------------------------------------------*/ + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ - FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, - &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode ); + move16(); + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + test(); + test(); + test(); + test(); + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) + { + frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + } + } - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ + } /* End of GOOD FRAME */ - move16(); - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); - FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - test(); - test(); - test(); - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) - { - frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); - } - } - - } /* End of GOOD FRAME */ - - /*----------------------------------------------------------------* - * BAD frame - *----------------------------------------------------------------*/ + /*----------------------------------------------------------------* + * BAD frame + *----------------------------------------------------------------*/ - ELSE + ELSE + { + /* SC-VBR */ + if ( EQ_16( st->last_nelp_mode_dec, 1 ) ) { - /* SC-VBR */ - if ( EQ_16( st->last_nelp_mode_dec, 1 ) ) - { - st->nelp_mode_dec = 1; - move16(); - } - test(); - test(); - test(); - /* long burst frame erasures */ - IF( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) - { - st->last_good = VOICED_TRANSITION; - move16(); - } + st->nelp_mode_dec = 1; + move16(); + } + test(); + test(); + /* long burst frame erasures */ + if ( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) + { + st->last_good = VOICED_TRANSITION; + move16(); + } - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth ); + /* LSF estimation and A(z) calculation */ + lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth ); - FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); + FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); #ifndef MSAN_FIX - for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) - { + for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) + { #else FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) { #endif - Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); - Aq_fx[imult3216( nsf, add( M, 1 ) )] = ONE_IN_Q12; - move16(); - } - IF( EQ_16( st->nelp_mode_dec, 1 ) ) - { - /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); - st->Q_exc = 0; - move16(); - - decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); - FEC_pitch_fx = pitch_buf_fx[3]; - move16(); - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); - } - ELSE - { - /* calculation of excitation signal */ - FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); + Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + move16(); + } + IF( EQ_16( st->nelp_mode_dec, 1 ) ) + { + /* SC-VBR */ + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + st->Q_exc = 0; + move16(); - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0, - &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type ); + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); + FEC_pitch_fx = pitch_buf_fx[3]; + move16(); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + ELSE + { + /* calculation of excitation signal */ + FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0, + &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type ); - /* SC-VBR */ - st->prev_gain_pit_dec_fx = st->lp_gainp_fx; - move16(); - } + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); + /* SC-VBR */ + st->prev_gain_pit_dec_fx = st->lp_gainp_fx; + move16(); + } - /* save and delay synthesis to be used by SWB BWE */ - IF( st->hBWE_FD != NULL ) - { - save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - } + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); - /* Apply energy matching when switching to inactive frames */ - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + /* save and delay synthesis to be used by SWB BWE */ + IF( st->hBWE_FD != NULL ) + { + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); + } - /* update past excitation signals for LD music post-filter */ - IF( st->hMusicPF != NULL ) - { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + /* Apply energy matching when switching to inactive frames */ + Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_shl( 1228, ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; i < MAX_LT; i++ ) - { - st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; - move16(); - } - } + /* update past excitation signals for LD music post-filter */ + IF( st->hMusicPF != NULL ) + { + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - /* synthesis at 12k8 Hz sampling rate */ - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; - move16(); - test(); - test(); - IF( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + /* Update music post processing values */ + /* Filter energies update */ + FOR( i = 0; i < DCT_L_POST; i++ ) { - k = 1; + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_shl( 1228, ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); move16(); } - - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); - test(); - IF( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + /* Update circular buffer, keep last energy difference unchanged */ + FOR( i = 1; i < MAX_LT; i++ ) { - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; + move16(); } - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); + } - /* update buffer for classifier */ - IF( st->hWIDec != NULL ) - { - Copy( exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM ); - Copy( psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM ); - } - st->prev_Q_exc_fr = st->Q_exc; - st->prev_Q_syn_fr = st->Q_syn; - move16(); + /* synthesis at 12k8 Hz sampling rate */ + /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ + Word16 k = 0; + move16(); + test(); + test(); + if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + { + k = 1; move16(); - Copy( psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + } - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - test(); - IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) - { - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); + test(); + IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) + { + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + } + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - } + /* update buffer for classifier */ + IF( st->hWIDec != NULL ) + { + Copy( exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM ); + Copy( psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM ); + } + st->prev_Q_exc_fr = st->Q_exc; + move16(); + st->prev_Q_syn_fr = st->Q_syn; + move16(); + Copy( psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ + test(); + IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) + { + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); - IF( NE_16( st->nelp_mode_dec, 1 ) ) - { - /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, - &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, - &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); - } + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); } - IF( st->hBWE_TD != NULL ) + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + + IF( NE_16( st->nelp_mode_dec, 1 ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } - ELSE - { - Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } + /* modify the excitation signal of stationary unvoiced frames */ + stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, + &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, + &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); } + } - /*--------------------------------------------------------* - * Apply NB postfilter in case of 8kHz output - *--------------------------------------------------------*/ - test(); - IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) + IF( st->hBWE_TD != NULL ) + { + IF( EQ_16( st->L_frame, L_FRAME ) ) { - Copy( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k ); - IF( EQ_16( st->bwidth, NB ) ) - { - st->hPFstat->on = 1; - move16(); - nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); - } - ELSE - { - st->hPFstat->on = 0; - move16(); - nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); - } + Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } ELSE { - st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); + Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } + } - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( psyn_fx + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) ); - unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame ); - Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); - IF( st->hTcxDec != NULL ) + /*--------------------------------------------------------* + * Apply NB postfilter in case of 8kHz output + *--------------------------------------------------------*/ + test(); + IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) + { + Copy( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k ); + IF( EQ_16( st->bwidth, NB ) ) { - Copy_Scale_sig( psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/ + st->hPFstat->on = 1; + move16(); + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); } - Copy_Scale_sig( psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ - - /*------------------------------------------------------------------* - * Formant post-filter - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || GT_16( st->element_mode, EVS_MONO ) ) && LE_32( st->core_brate, ACELP_32k ) ) + ELSE { - st->hPFstat->on = 1; + st->hPFstat->on = 0; move16(); - /*----ftf conversions---*/ - Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); + } + } + ELSE + { + st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); + move16(); + } - set16_fx( st->hPFstat->mem_zero, 0, M ); + /*------------------------------------------------------------------* + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ - formant_post_filt_ivas_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); - } - ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) - { - IF( st->hPFstat->on ) - { + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + Copy( psyn_fx + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) ); + unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame ); + Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); + IF( st->hTcxDec != NULL ) + { + Copy_Scale_sig( psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/ + } + Copy_Scale_sig( psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ - Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); - Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); + /*------------------------------------------------------------------* + * Formant post-filter + *-----------------------------------------------------------------*/ - Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); - Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) ); - blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); - } - st->hPFstat->on = 0; - move16(); + test(); + test(); + test(); + test(); + IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || st->element_mode > EVS_MONO ) && LE_32( st->core_brate, ACELP_32k ) ) + { + st->hPFstat->on = 1; + move16(); + /*----ftf conversions---*/ + Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); + + set16_fx( st->hPFstat->mem_zero, 0, M ); + + formant_post_filt_ivas_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); + } + ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) + { + IF( st->hPFstat->on ) + { + Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); + Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); + + Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); + E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); + Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) ); + blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); } + st->hPFstat->on = 0; + move16(); + } - /*----------------------------------------------------------------* - * Comfort noise addition - *----------------------------------------------------------------*/ + /*----------------------------------------------------------------* + * Comfort noise addition + *----------------------------------------------------------------*/ + test(); + test(); + IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { test(); test(); - IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) { + /*VAD only for non inactive frame*/ + st->VAD = st->VAD && st->coder_type != INACTIVE; + test(); test(); test(); test(); test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( EQ_16( st->cng_type, LP_CNG ) && LE_32( st->core_brate, SID_2k40 ) ) ) + IF( st->idchan == 0 && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) ) { - /*VAD only for non inactive frame*/ - st->VAD = st->VAD && NE_16( st->coder_type, INACTIVE ); - test(); - test(); - test(); - test(); - IF( EQ_16( st->idchan, 0 ) && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( EQ_16( st->cng_type, LP_CNG ) && LE_32( st->core_brate, SID_2k40 ) ) ) ) - { - /*Noisy speech detector*/ - noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); + /*Noisy speech detector*/ + noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - IF( NE_16( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 ) ) - { - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); - move16(); - } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + move16(); + IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + { + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); + move16(); } + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ); + move32(); + } + + if ( st->idchan == 0 ) + { + st->lp_noise = st->hFdCngDec->lp_noise; + move32(); + } + test(); + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) + { + /*Noise estimate*/ + + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, Q27 ) ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 + move16(); - if ( st->idchan == 0 ) + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, Q27 ) ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, Q27 ) ); + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 + move16(); + /*==========================================================*/ + ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + /*==========================================================*/ + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) { - st->lp_noise = st->hFdCngDec->lp_noise; - move32(); + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + move16(); } - test(); - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { - /*Noise estimate*/ - - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - Q27 ); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27 ); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27 ); - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 - /*==========================================================*/ - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - /*==========================================================*/ - IF( st->hFdCngDec->partNoiseShape_exp < 0 ) - { - Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); - st->hFdCngDec->partNoiseShape_exp = 0; - } - IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) - { - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - } + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + move16(); } + } - IF( !st->cna_dirac_flag ) + IF( !st->cna_dirac_flag ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { test(); - test(); - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->GSC_noisy_speech ) ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) + IF( hStereoCng->flag_cna_fade ) { - IF( hStereoCng->flag_cna_fade ) - { - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); - hStereoCng->flag_cna_fade = 0; - } - ELSE - { - IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) - { - /* Clear memory for secondary channel CNA */ - set_s( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); - } - - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); - } + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 0; + move16(); } - ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + ELSE { - IF( st->idchan == 0 ) + IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) { - IF( NE_16( st->element_mode, last_element_mode ) ) - { - set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); - } - generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 /*, 0, 0, st->element_mode, hStereoCng, nchan_out*/ ); + /* Clear memory for secondary channel CNA */ + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); } + + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); } } - ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) + IF( st->idchan == 0 ) { - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); - hStereoCng->flag_cna_fade = 1; - move16(); - } - ELSE - { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + IF( NE_16( st->element_mode, last_element_mode ) ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); - move16(); + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } + generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 /*, 0, 0, st->element_mode, hStereoCng, nchan_out*/ ); } } - ELSE + } + ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) + { + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { - if ( hStereoCng != NULL ) - { - hStereoCng->flag_cna_fade = 1; - hStereoCng->enableSecCNA = 0; - move16(); - move16(); - } + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 1; + move16(); } - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + ELSE { - /*Noise estimate*/ - IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) ) ) + FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) { - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - IF( st->hFdCngDec->partNoiseShape_exp < 0 ) - { - Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp ); - st->hFdCngDec->partNoiseShape_exp = 0; - } - IF( st->hFdCngDec->partNoiseShape_exp < 0 ) - { - Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); - st->hFdCngDec->partNoiseShape_exp = 0; - } - IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) - { - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - } + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); move16(); } } } - } - - IF( !st->cna_dirac_flag ) - { - IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) + ELSE { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + if ( hStereoCng != NULL ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + hStereoCng->flag_cna_fade = 1; + move16(); + hStereoCng->enableSecCNA = 0; move16(); } } - IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->GSC_noisy_speech ) ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - IF( st->idchan == 0 ) - { - set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); - } - IF( hStereoCng != NULL && ( st->idchan == 0 ) ) + test(); + test(); + test(); + /*Noise estimate*/ + IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) ) { - set_s( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); + ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) + { + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + move16(); + } + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) + { + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + move16(); + } + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + { + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + move16(); + } } } } } - /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ - - /* check if the CLDFB works on the right sample rate */ - IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) + IF( !st->cna_dirac_flag ) { - resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - - IF( st->ini_frame > 0 ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + { + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + move16(); + } } - } - - /* analyze pitch coherence for bass post-filter */ - Word32 pitch_buf_fx_q20[12]; - - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); - Word16 lim = shr( st->L_frame, 6 ); - FOR( Word16 lp = 0; lp < lim; lp++ ) - { - pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); - move32(); - } - bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); - - - IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) - { test(); - IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) + test(); + test(); + IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) + IF( st->idchan == 0 ) { - retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } - ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) + IF( hStereoCng != NULL && ( st->idchan == 0 ) ) { - retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); } } + } + } + + /*----------------------------------------------------------------* + * Resample to the output sampling rate (8/16/32/48 kHz) + * Bass post-filter + *----------------------------------------------------------------*/ + + /* check if the CLDFB works on the right sample rate */ + IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) + { + resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, - st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); + IF( st->ini_frame > 0 ) + { + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + move16(); } + } + + /* analyze pitch coherence for bass post-filter */ - Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; - set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); - syn_32_fx = syn_tmp_32_fx + L_SUBFR; + Word32 pitch_buf_fx_q20[12]; + + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); + Word16 lim = shr( st->L_frame, 6 ); + FOR( Word16 lp = 0; lp < lim; lp++ ) + { + pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); + move32(); + } + bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); + + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) + { test(); - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) + IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) { - /* analysis of the synthesis at internal sampling rate */ - Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); + } + ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - pRealSave_fx[i] = realBufferSave_fx[i]; - pImagSave_fx[i] = imagBufferSave_fx[i]; + retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); } + } + + bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, + st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); + } + + Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; + set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); + syn_32_fx = syn_tmp_32_fx + L_SUBFR; + test(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) + { + /* analysis of the synthesis at internal sampling rate */ + Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + pRealSave_fx[i] = realBufferSave_fx[i]; + pImagSave_fx[i] = imagBufferSave_fx[i]; + } #ifndef MSAN_FIX - Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif - IF( st->p_bpf_noise_buf_32 ) - { + IF( st->p_bpf_noise_buf_32 ) + { #ifdef MSAN_FIX - Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif - Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); - } + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + } #ifdef MSAN_FIX - FOR( i = 0; i < st->L_frame; i++ ) + FOR( i = 0; i < st->L_frame; i++ ) #else for ( i = 0; i < L_FRAME16k; i++ ) #endif - { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12 - move32(); - } + { + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12 + move32(); + } - Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 - st->cldfbAna->Q_cldfb_state = Q12; - move16(); - cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - /* analysis and add the BPF error signal */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; + move16(); + cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + /* analysis and add the BPF error signal */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - q_bpf_error_signal = Q6; - move16(); + q_bpf_error_signal = Q6; + move16(); #ifdef MSAN_FIX - Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, q_bpf_error_signal - st->Q_syn ); // Q6 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, q_bpf_error_signal - st->Q_syn ); // Q6 #else Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn ); // Q6 #endif - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - } - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - move16(); - tmp = -1; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + move16(); + tmp = -1; + move16(); + if ( st->bpf_off ) + { + tmp = 0; move16(); - IF( st->bpf_off ) - { - tmp = 0; - move16(); - } + } - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 - st->cldfbBPF->Q_cldfb_state = Q10; + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; + move16(); + /* set output mask for upsampling */ + IF( EQ_16( st->bwidth, NB ) ) + { + /* set NB mask for upsampling */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); move16(); - /* set output mask for upsampling */ - IF( EQ_16( st->bwidth, NB ) ) - { - /* set NB mask for upsampling */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); - } - ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) - { - /* in case of BW switching, re-init to default */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); - } - test(); - IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); - test(); - /*WB/SWB-FD_CNG*/ - IF( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LE_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) - { - Word16 tmpBufferScale = 0; - move16(); - generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); - - /* Fixed to float */ - FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) - { - Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 - Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 - } - - IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) - { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); - } - ELSE - { - st->cldfbSyn->bandsToZero = 0; - move16(); - } - } - } - - IF( save_hb_synth_fx16 != NULL ) - { - /* save and then zero-out lowband */ - Word16 Q_real = 0, Q_imag = 0; - Word32 max_real = 0, max_imag = 0; - move16(); - move16(); - move32(); - move32(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); - } - } - Word32 max_val = max( max_real, max_imag ); - Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; - Q_real = Q_imag; - move16(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); - } - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) - st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); - - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - realBufferSave_fx[i][j] = realBuffer_fx[i][j]; - imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; - move32(); - move32(); - IF( j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots ) - { - realBuffer_fx[i][j] = 0; - imagBuffer_fx[i][j] = 0; - move32(); - move32(); - } - } - } - - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - - Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( sub( Q_real, 1 ) ) ); // Q0 - Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); - /* restore lowband */ - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - realBuffer_fx[i][j] = realBufferSave_fx[i][j]; - imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; - move32(); - move32(); - } - } - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 - st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); - cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); - Scale_sig32( synth_fx, L_FRAME48k, -sub( Q_real, 1 ) ); - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); - } - ELSE + } + ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) + { + /* in case of BW switching, re-init to default */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + move16(); + } + test(); + IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + test(); + test(); + test(); + /*WB/SWB-FD_CNG*/ + IF( ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) { - /* synthesis of the combined signal */ - Word16 Q_real = 0, Q_imag = 0; - Word32 max_real = 0, max_imag = 0; + Word16 tmpBufferScale = 0; move16(); - move16(); - move32(); - move32(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); + + /* Fixed to float */ + FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); - } + Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 + Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 } - Word32 max_val = max( max_real, max_imag ); - Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; - Q_real = Q_imag; - move16(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + + IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); + move16(); + } + ELSE + { + st->cldfbSyn->bandsToZero = 0; + move16(); } - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) - st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); -#ifndef MSAN_FIX - Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); -#endif - - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); -#ifdef MSAN_FIX - scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); -#else - Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); -#endif - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSyn->Q_cldfb_state = Q10; - move16(); } - - /* save synthesis - needed in case of core switching */ - Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 } - ELSE - { - Word16 nSamples = NS2SA( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ - - /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ -#ifndef MSAN_FIX - for ( i = 0; i < L_FRAME16k; i++ ) -#else - FOR( i = 0; i < st->L_frame; i++ ) -#endif - { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); - move32(); - } - Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 - st->cldfbAna->Q_cldfb_state = Q12; + IF( save_hb_synth_fx16 != NULL ) + { + /* save and then zero-out lowband */ + Word16 Q_real = 0, Q_imag = 0; + Word32 max_real = 0, max_imag = 0; move16(); - cldfbAnalysis_ivas_fx( syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); - - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 - st->cldfbAna->Q_cldfb_state = Q11; - move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - - // Get Q-factor - q_bpf_error_signal = Q6; move16(); - Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 + move32(); + move32(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } } - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + Word32 max_val = L_max( max_real, max_imag ); + Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; + Q_real = Q_imag; move16(); - tmp = 0; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); + } + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); move16(); - if ( !st->bpf_off ) + Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); + + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - tmp = nSamples; - move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + realBufferSave_fx[i][j] = realBuffer_fx[i][j]; + imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; + move32(); + move32(); + IF( LT_16( j, st->hFdCngDec->hFdCngCom->numCoreBands ) && LT_16( i, st->hFdCngDec->hFdCngCom->numSlots ) ) + { + realBuffer_fx[i][j] = 0; + imagBuffer_fx[i][j] = 0; + move32(); + move32(); + } + } } - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -sub( q_bpf_error_signal, Q10 ) ); // Q10 - st->cldfbBPF->Q_cldfb_state = Q10; - /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ + Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( sub( Q_real, 1 ) ) ); // Q0 + Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); + /* restore lowband */ + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + realBuffer_fx[i][j] = realBufferSave_fx[i][j]; + imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; + move32(); + move32(); + } + } + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); + move16(); + cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); + Scale_sig32( synth_fx, L_FRAME48k, -sub( Q_real, 1 ) ); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); + } + ELSE + { + /* synthesis of the combined signal */ Word16 Q_real = 0, Q_imag = 0; Word32 max_real = 0, max_imag = 0; move16(); @@ -1995,11 +1954,11 @@ ivas_error acelp_core_dec_ivas_fx( { FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); } } - Word32 max_val = max( max_real, max_imag ); + Word32 max_val = L_max( max_real, max_imag ); Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; Q_real = Q_imag; move16(); @@ -2009,192 +1968,293 @@ ivas_error acelp_core_dec_ivas_fx( scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); } scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) + st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); + move16(); #ifndef MSAN_FIX Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); #endif - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); - + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); #ifdef MSAN_FIX - Scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); + scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); #else - Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); + Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSyn->Q_cldfb_state = Q10; move16(); - IF( st->p_bpf_noise_buf_32 ) - { - Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 - Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); - } - - set_l( synth_fx, 0, output_frame ); } - /* Copy output signal */ + /* save synthesis - needed in case of core switching */ + Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 + } + ELSE + { + Word16 nSamples = NS2SA( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ + + /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ #ifndef MSAN_FIX - Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); + for ( i = 0; i < L_FRAME16k; i++ ) #else - Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), -st->Q_syn ); + FOR( i = 0; i < st->L_frame; i++ ) #endif - IF( GT_16( st->element_mode, EVS_MONO ) ) { - Copy( psyn_fx, output_fx, st->L_frame ); + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); + move32(); + } + + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; + move16(); + cldfbAnalysis_ivas_fx( syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); + + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; + move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); + + // Get Q-factor + q_bpf_error_signal = Q6; + move16(); + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + move16(); + tmp = 0; + move16(); + if ( !st->bpf_off ) + { + tmp = nSamples; + move16(); } + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + - st->Q_syn2 = 0; + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -sub( q_bpf_error_signal, Q10 ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; move16(); - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz - *-----------------------------------------------------------------*/ - IF( st->hBWE_zero != NULL ) + /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ + Word16 Q_real = 0, Q_imag = 0; + Word32 max_real = 0, max_imag = 0; + move16(); + move16(); + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && - ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } + } + Word32 max_val = L_max( max_real, max_imag ); + Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; + Q_real = Q_imag; + move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + } + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) +#ifndef MSAN_FIX + Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); +#endif + + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); + +#ifdef MSAN_FIX + Scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); +#else + Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); +#endif + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); + st->cldfbSyn->Q_cldfb_state = Q10; + move16(); + IF( st->p_bpf_noise_buf_32 ) + { + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); + + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + } + + set32_fx( synth_fx, 0, output_frame ); + } + + /* Copy output signal */ +#ifndef MSAN_FIX + Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); +#else + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), -st->Q_syn ); +#endif + IF( st->element_mode > EVS_MONO ) + { + Copy( psyn_fx, output_fx, st->L_frame ); + } + + st->Q_syn2 = 0; + move16(); + /*-----------------------------------------------------------------* + * Bandwidth extension 6kHz-7kHz + *-----------------------------------------------------------------*/ + IF( st->hBWE_zero != NULL ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && + ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) + { #ifndef FIX_774_ENERGY_BURST - Word16 tmp_exp = 0; - move16(); + Word16 tmp_exp = 0; + move16(); #endif #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif #ifdef FIX_774_ENERGY_BURST - hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, - psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &st->hBWE_zero->memExp1, - st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode ); + hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, + psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &st->hBWE_zero->memExp1, + st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode ); #else hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); #endif #ifdef MSAN_FIX - Copy_Scale_sig_16_32( synth_fx16, synth_fx, output_frame, 0 ); + Copy_Scale_sig_16_32( synth_fx16, synth_fx, output_frame, 0 ); #else Copy_Scale_sig_16_32( synth_fx16, synth_fx, L_FRAME48k, 0 ); #endif #ifndef FIX_774_ENERGY_BURST - IF( st->hBWE_FD != NULL ) - { - st->hBWE_FD->memExp1 = tmp_exp; - move16(); - } - ELSE - { - Scale_sig( st->hBWE_zero->mem_hf_fx, sub( L_FIR, 1 ), -tmp_exp ); - } -#endif + IF( st->hBWE_FD != NULL ) + { + st->hBWE_FD->memExp1 = tmp_exp; + move16(); } ELSE { - hf_synth_reset_fx( st->hBWE_zero ); + Scale_sig( st->hBWE_zero->mem_hf_fx, sub( L_FIR, 1 ), -tmp_exp ); + } +#endif + } + ELSE + { + hf_synth_reset_fx( st->hBWE_zero ); #ifdef MSAN_FIX - set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); + set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); #endif - } } + } - /*-----------------------------------------------------------------* - * Populate parameters for SWB TBE - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Populate parameters for SWB TBE + *-----------------------------------------------------------------*/ - IF( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) - { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - set_s( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - test(); - test(); - test(); - test(); - test(); - IF( !st->ppp_mode_dec && ( EQ_16( st->idchan, 0 ) || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) - { - Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); - 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 ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); - } - test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) - { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - } + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + } + test(); + test(); + test(); + test(); + test(); + IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) + { + Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + 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 ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); } - /*----------------------------------------------------------------------* - * Updates - *----------------------------------------------------------------------*/ - - updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); test(); - IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) + if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { - /* update CNG parameters in active frames */ - cng_params_upd_ivas_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 ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + } + } + /*----------------------------------------------------------------------* + * Updates + *----------------------------------------------------------------------*/ + + updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); + test(); + test(); + IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) + { + /* update CNG parameters in active frames */ + cng_params_upd_ivas_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 ); - /* Set 16k LSP flag for CNG buffer */ - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; + /* Set 16k LSP flag for CNG buffer */ + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; + move16(); + if ( NE_16( st->L_frame, L_FRAME ) ) + { + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; move16(); - if ( NE_16( st->L_frame, L_FRAME ) ) - { - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; - move16(); - } } + } + { + IF( save_hb_synth_fx16 ) { - IF( save_hb_synth_fx16 ) - { - Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); - } + Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); + } #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif - if ( st->hFdCngDec ) - { - st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; - move16(); - } + if ( st->hFdCngDec ) + { + st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; + move16(); } - - pop_wmops(); - return error; } + pop_wmops(); + return error; +} - static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff ) - { - Scale_sig32( hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, Exp_diff ); - } + +static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff ) +{ + Scale_sig32( hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, Exp_diff ); +} #endif diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 0984c7698..4a13837b1 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1904,7 +1904,7 @@ Word16 ApplyFdCng_ivas_fx( IF( EQ_16( st->codec_mode, MODE2 ) ) { /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); + generate_comfort_noise_dec_ivas_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); } BREAK; diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index a246eb92f..59969dba2 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -45,8 +45,6 @@ #include "wmc_auto.h" #include -/* NOTE: Temporary macro for computation happening in floating point. This macro and code active under this is to be removed once the intermediate conversions to float are not required */ -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*--------------------------------------------------------------------------* * Local function prototypes @@ -1321,14 +1319,12 @@ void destroy_cpe_dec( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { -#ifdef IVAS_FLOAT_FIXED free( hCPE->input_mem_LB_fx[n] ); hCPE->input_mem_LB_fx[n] = NULL; free( hCPE->input_mem_fx[n] ); hCPE->input_mem_fx[n] = NULL; free( hCPE->output_mem_fx[n] ); hCPE->output_mem_fx[n] = NULL; -#endif IF( hCPE->prev_synth_chs_fx[n] != NULL ) { @@ -1336,10 +1332,8 @@ void destroy_cpe_dec( hCPE->prev_synth_chs_fx[n] = NULL; } } -#ifdef IVAS_FLOAT_FIXED free( hCPE->input_mem_BPF_fx[0] ); hCPE->input_mem_BPF_fx[0] = NULL; -#endif } IF( hCPE->hStereoCng != NULL ) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 57210b2cb..c57261bbf 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -3304,93 +3304,7 @@ void ivas_param_mc_dec_digest_tc( } if ( slot_idx >= 2 * hParamMC->hMetadataPMC->attackIndex ) { -#ifdef IVAS_FLOAT_FIXED - Word32( *cx_fx )[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word16 cx_e; - Word32( *cx_imag_fx )[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word16 cx_imag_e; - Word16 cldfb_slots; - - cx_fx = malloc( sizeof( Word32[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS] ) ); - cx_imag_fx = malloc( sizeof( Word32[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS] ) ); - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - set32_fx( cx_fx[lp], 0, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - set32_fx( cx_imag_fx[lp], 0, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - } - - cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; - if ( st_ivas->hDecoderConfig->Opt_tsm ) - { - cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; - } - - f2me_buf( hParamMC->Cldfb_RealBuffer_tc, hParamMC->Cldfb_RealBuffer_tc_fx, &hParamMC->Cldfb_RealBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * hParamMC->num_freq_bands ); - f2me_buf( hParamMC->Cldfb_ImagBuffer_tc, hParamMC->Cldfb_ImagBuffer_tc_fx, &hParamMC->Cldfb_ImagBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * hParamMC->num_freq_bands ); - - Word16 max_e = 0; - cx_e; - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx[lp][lp2], &cx_fx[lp][lp2], &cx_e ); - max_e = s_max( cx_e, max_e ); - } - } - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx[lp][lp2], &cx_fx[lp][lp2], &cx_e ); - cx_fx[lp][lp2] = L_shr( cx_fx[lp][lp2], max_e - cx_e ); - } - } - cx_e = max_e; - - max_e = 0; - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx_imag[lp][lp2], &cx_imag_fx[lp][lp2], &cx_imag_e ); - max_e = s_max( cx_imag_e, max_e ); - } - } - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx_imag[lp][lp2], &cx_imag_fx[lp][lp2], &cx_imag_e ); - cx_imag_fx[lp][lp2] = L_shr( cx_imag_fx[lp][lp2], max_e - cx_imag_e ); - } - } - cx_imag_e = max_e; - - ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], - hParamMC->Cldfb_RealBuffer_tc_e, - &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], - hParamMC->Cldfb_ImagBuffer_tc_e, - cx_fx, - &cx_e, - cx_imag_fx, - &cx_imag_e, - hParamMC, - nchan_transport ); - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - me2f_buf( cx_fx[lp], cx_e, cx[lp], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - me2f_buf( cx_imag_fx[lp], cx_imag_e, cx_imag[lp], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - } - free( cx_fx ); - free( cx_imag_fx ); -#else ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( &hParamMC->Cldfb_RealBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], &hParamMC->Cldfb_ImagBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], cx, cx_imag, hParamMC, nchan_transport ); -#endif } } diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 505b6797f..2764b640b 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -1690,11 +1690,13 @@ void ivas_ls_setup_conversion_process_mdct( } #endif + /*------------------------------------------------------------------------- * ivas_ls_setup_conversion_process_mdct_param_mc() * * Equalization in MDCT Domain *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_ls_setup_conversion_process_mdct_param_mc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -2075,7 +2077,6 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( return; } #else - void ivas_ls_setup_conversion_process_mdct_param_mc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *x[][NB_DIV] /* i/o: output synthesis signal */ @@ -2237,49 +2238,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( } } -#ifdef IVAS_FLOAT_FIXED - Word32 real_in_buffer_fx[PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * PARAM_MC_BAND_TO_MDCT_BAND_RATIO * MAX_TRANSPORT_CHANNELS]; - Word32 imag_in_buffer_fx[PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * PARAM_MC_BAND_TO_MDCT_BAND_RATIO * MAX_TRANSPORT_CHANNELS]; - Word32 real_buffer_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 imag_buffer_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word16 real_exp, imag_exp, input_exp, output_exp; - Word16 shift = find_guarded_bits_fx( num_bands + 1 ); - - f2me_buf( real_in_buffer, real_in_buffer_fx, &real_exp, num_bands * nchan_transport ); - f2me_buf( imag_in_buffer, imag_in_buffer_fx, &imag_exp, num_bands * nchan_transport ); - - IF( real_exp > imag_exp ) - { - FOR( i = 0; i < num_bands * nchan_transport; ++i ) - { - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], real_exp - imag_exp ); - } - input_exp = real_exp; - } - ELSE - { - FOR( i = 0; i < num_bands * nchan_transport; ++i ) - { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], imag_exp - real_exp ); - } - input_exp = imag_exp; - } - - FOR( i = 0; i < num_bands * nchan_transport; ++i ) - { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], shift ); - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], shift ); - } - - input_exp += shift; - - cmplx_matrix_square_fx( real_in_buffer_fx, imag_in_buffer_fx, num_bands, nchan_transport, real_buffer_fx, imag_buffer_fx, input_exp, &output_exp ); - - me2f_buf( real_buffer_fx, output_exp, real_buffer, nchan_transport * nchan_transport ); - me2f_buf( imag_buffer_fx, output_exp, imag_buffer, nchan_transport * nchan_transport ); -#else cmplx_matrix_square( real_in_buffer, imag_in_buffer, num_bands, nchan_transport, real_buffer, imag_buffer ); -#endif v_add( cx[bandIdx], real_buffer, cx[bandIdx], nchan_transport * nchan_transport ); @@ -2445,6 +2404,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( } #endif + /*------------------------------------------------------------------------- * ivas_ls_setup_conversion_process_param_mc() * diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 50603a381..f4464f79c 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -42,8 +42,6 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #include "prot_fx.h" -#endif -#ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index 6a3638bfc..273a4c097 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -40,23 +40,17 @@ #include "ivas_prot.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx.h" -#include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -#endif -#ifndef IVAS_FLOAT_FIXED static void run_min_stats( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] ); -#endif + /*-------------------------------------------------------------------* * convert_coeffs_to_higher_res() @@ -65,55 +59,6 @@ static void run_min_stats( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] ) * by applying high- and lowpass filters to subdivide bins *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -#define POINT_5_Q31 ONE_IN_Q30 - -void convert_coeffs_to_higher_res_fx( - const Word32 *in1, /* i : first subframe input */ - const Word32 *in2, /* i : second subframe input */ - Word32 *out, /* o : converted output */ - const Word16 len /* i : length of subframes */ -) -{ - Word16 i; - Word32 tmp1, tmp2; - - IF( in1 == out ) - { - FOR( i = 0; i < len; i += 2 ) - { - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - out[2 * i] = tmp1; - move32(); - out[2 * i + 1] = tmp2; - move32(); - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - out[2 * i + 2] = tmp1; - move32(); - out[2 * i + 3] = tmp2; - move32(); - } - } - ELSE - { - FOR( i = 0; i < len; i += 2 ) - { - out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - move32(); - out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - move32(); - out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); - move32(); - out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); - move32(); - } - } - - return; -} -#endif void convert_coeffs_to_higher_res( const float *in1, /* i : first subframe input */ const float *in2, /* i : second subframe input */ @@ -159,7 +104,6 @@ void convert_coeffs_to_higher_res( * decode core and MDCT stereo information *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void stereo_mdct_dec_stereo( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t ms_mask[2][MAX_SFB] /* o : bandwise MS mask */ @@ -184,9 +128,8 @@ static void stereo_mdct_dec_stereo( return; } -#endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------* * stereo_mdct_core_dec() * @@ -208,11 +151,6 @@ void stereo_mdct_core_dec( int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW]; float Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; -#ifdef IVAS_FLOAT_FIXED - /* NOTE: temporary fix to avoid garbage values while calculating its - q-factor when not initialised. */ - set_zero( (float *) Aq, CPE_CHANNELS * ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); -#endif float *x[CPE_CHANNELS][NB_DIV]; /*needed to allocate N_MAX to prevent stereo switching crash */ @@ -240,11 +178,6 @@ void stereo_mdct_core_dec( int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV]; float signal_outFB_tmp[CPE_CHANNELS][L_FRAME_PLUS]; float signal_out_tmp[CPE_CHANNELS][L_FRAME_PLUS]; -#ifdef IVAS_FLOAT_FIXED - Word32 signal_out_tmp_fx[CPE_CHANNELS][L_FRAME_PLUS]; - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; -#endif - push_wmops( "stereo_mdct_core_dec" ); /*--------------------------------------------------------------------------------* @@ -260,26 +193,12 @@ void stereo_mdct_core_dec( for ( ch = 0; ch < nChannels; ch++ ) { /* Initialization or re-configuration of Stereo TCX */ -#ifdef IVAS_FLOAT_FIXED - /* stereo_tcx_dec_mode_switch_reconf_To_fixed is for intermediatery conversions which is needed to be removed */ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); - /*============*/ - stereo_tcx_init_dec_fx( sts[ch], 0, hCPE->last_element_mode ); - /*============*/ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); -#else stereo_tcx_init_dec( sts[ch], 0, hCPE->last_element_mode ); -#endif // IVAS_FLOAT_FIXED sts[ch]->hTcxDec->tnsActive[0] = sts[ch]->hTcxDec->tnsActive[1] = 0; sts[ch]->enablePlcWaveadjust = 0; set_zero( signal_out_tmp[ch], L_FRAME_PLUS ); x[ch][0] = &signal_out_tmp[ch][0]; x[ch][1] = &signal_out_tmp[ch][0] + L_FRAME_PLUS / 2; -#ifdef IVAS_FLOAT_FIXED - set32_fx( signal_out_tmp_fx[ch], 0, L_FRAME_PLUS ); - x_fx[ch][0] = &signal_out_tmp_fx[ch][0]; - x_fx[ch][1] = &signal_out_tmp_fx[ch][0] + L_FRAME_PLUS / 2; -#endif set_zero( x_0_buf[ch], N_MAX ); x_0[ch][0] = &x_0_buf[ch][0]; @@ -397,38 +316,11 @@ void stereo_mdct_core_dec( { float sns_int_scf[FDNS_NPTS]; -#ifdef IVAS_FLOAT_FIXED - Word32 sns_int_scf_fx[FDNS_NPTS], Aq_fx[SNS_NPTS]; - FOR( int c = 0; c < SNS_NPTS; c++ ) - { - Aq_fx[c] = (Word32) ( Aq[ch][k * M + c] * ONE_IN_Q16 ); - } - - sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx, DEC ); - - FOR( int c = 0; c < FDNS_NPTS; c++ ) - { - sns_int_scf[c] = ( (float) sns_int_scf_fx[c] / ONE_IN_Q16 ); - } -#else sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC ); -#endif // IVAS_FLOAT_FIXED if ( st->hTonalMDCTConc != NULL && ( ( k + 1 ) == nSubframes[ch] ) ) { -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx_[N_MAX]; - Word16 x_e, scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; - f2me_buf( x[ch][k], x_fx_, &x_e, L_frameTCX[ch] ); - for ( int j = 0; j < st->hTonalMDCTConc->nScaleFactors; j++ ) - { - f2me_16( sns_int_scf[j], &scf_fx[j], &scf_e[j] ); - } - TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx_, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - // st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); -#else TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); -#endif } } @@ -444,41 +336,7 @@ void stereo_mdct_core_dec( stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 ); } -#ifdef IVAS_FLOAT_FIXED1 - Word32 Aq_fx[2][102]; - Word16 x_e[2][2]; - FOR( Word16 ind = 0; ind < 2; ind++ ) - { - FOR( Word16 ind2 = 0; ind2 < 102; ind2++ ) - { - Aq_fx[ind][ind2] = (Word32) ( Aq[ind][ind2] * ( ONE_IN_Q16 ) ); - } - FOR( Word16 ind2 = 0; ind2 < 2; ind2++ ) - { - f2me_buf( x[ind][ind2], x_fx[ind][ind2], &x_e[ind][ind2], L_frameTCX[ind] ); - } - } - st->hTcxDec->cummulative_damping_tcx = (Word16) ( st->hTcxDec->cummulative_damping_tcx * ( ONE_IN_Q15 ) ); - FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) - { - f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); - } - FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) - { - f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); - } - FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) - { - st->hTonalMDCTConc->scaleFactorsBackground[i] = float_to_fix16( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); - } - st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); - st->old_fpitch = float_to_fix( st->old_fpitch_float, 16 ); - st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); - - ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx, 0, x_e ); -#else ivas_mdct_core_tns_ns( hCPE, fUseTns, tnsData, x, Aq, 0 ); -#endif if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { @@ -771,10 +629,7 @@ static void run_min_stats( noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; -#ifdef IVAS_FLOAT_FIXED - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01 ); -#endif + st->lp_noise_float = st->hFdCngDec->lp_noise_float; } diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 078c8957d..48850cf1b 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -44,19 +44,79 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define POINT_5_Q31 ONE_IN_Q30 + + /*------------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------------*/ static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -#ifndef IVAS_FLOAT_FIXED -static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -#endif static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[CPE_CHANNELS][NB_DIV] ); + /*-------------------------------------------------------------------* - * stereo_mdct_dec_stereo() + * convert_coeffs_to_higher_res_fx() + * + * convert MDCT coefficients to higher frequency resolution + * by applying high- and lowpass filters to subdivide bins + *-------------------------------------------------------------------*/ + +void convert_coeffs_to_higher_res_fx( + const Word32 *in1, /* i : first subframe input */ + const Word32 *in2, /* i : second subframe input */ + Word32 *out, /* o : converted output */ + const Word16 len /* i : length of subframes */ +) +{ + Word16 i; + Word32 tmp1, tmp2; + + IF( in1 == out ) + { + FOR( i = 0; i < len; i += 2 ) + { + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + out[2 * i] = tmp1; + move32(); + out[2 * i + 1] = tmp2; + move32(); + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + out[2 * i + 2] = tmp1; + move32(); + out[2 * i + 3] = tmp2; + move32(); + } + } + ELSE + { + FOR( i = 0; i < len; i += 2 ) + { + out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + move32(); + out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + move32(); + out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); + move32(); + out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); + move32(); + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * stereo_mdct_dec_stereo_fx() * * decode core and MDCT stereo information *-------------------------------------------------------------------*/ @@ -79,7 +139,9 @@ static void stereo_mdct_dec_stereo_fx( splitAvailableBits_fx( availableBits, hCPE->hStereoMdct->split_ratio, hCPE->hStereoMdct->isSBAStereoMode, &sts[0]->bits_frame_channel, &sts[1]->bits_frame_channel ); sts[0]->bits_frame_channel = add( sts[0]->bits_frame_channel, i_mult( sts[0]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + move16(); sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i_mult( sts[1]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + move16(); sts[1]->bit_stream = &sts[0]->bit_stream[add( add( sts[0]->next_bit_pos, sts[0]->bits_frame_channel ), i_mult( sts[0]->core, NF_GAIN_BITS ) )]; @@ -88,7 +150,7 @@ static void stereo_mdct_dec_stereo_fx( /*-------------------------------------------------------------------* - * stereo_mdct_core_dec() + * stereo_mdct_core_dec_fx() * * MDCT stereo core/stereo decoder *--------------------------------------------------------------------*/ @@ -501,204 +563,9 @@ void stereo_mdct_core_dec_fx( return; } -#ifndef IVAS_FLOAT_FIXED -static void apply_dmx_weights( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - float *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ - int16_t transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch */ - int16_t transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch */ -) -{ - int16_t b, k, l, i, ch; - int16_t nsub, nsub2[2], nChannels; - int16_t transform_type[2][2]; - int16_t numCoeffs[2], frameSize; - int16_t tcx_10_only, w_idx; - int16_t start, stop, start_tcx5, stop_tcx5; - STEREO_MDCT_BAND_PARAMETERS *sfbConf = NULL; - float mdst[CPE_CHANNELS][NB_DIV][L_FRAME48k]; - float convertRes[CPE_CHANNELS][L_FRAME48k]; - float *sig[CPE_CHANNELS][NB_DIV], *pTmp[CPE_CHANNELS][NB_DIV]; - - nChannels = CPE_CHANNELS; - frameSize = hCPE->hStereoMdct->stbParamsTCX20.sfbOffset[hCPE->hStereoMdct->stbParamsTCX20.sfbCnt]; - - transform_type[0][0] = transform_type_left[0]; - transform_type[0][1] = transform_type_left[1]; - transform_type[1][0] = transform_type_right[0]; - transform_type[1][1] = transform_type_right[1]; - - /* set overall frequency resolution of (sub)frame to maximum of (sub)frame, requires conversion if both channels are not the same */ - if ( transform_type[0][0] == TCX_20 || transform_type[1][0] == TCX_20 ) - { - /* use TCX20 band config for TCX20 in both channels and mixed frames */ - sfbConf = &hCPE->hStereoMdct->stbParamsTCX20; - nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 */ - tcx_10_only = 0; - } - else - { - /* use TCX10 band config only if none of the channels is TCX20 */ - sfbConf = &hCPE->hStereoMdct->stbParamsTCX10; - nsub = 2; - /* set resolution per subframe, subdivide again if subframe is TCX5 in both channels */ - nsub2[0] = ( transform_type[0][0] == TCX_5 && transform_type[1][0] == TCX_5 ) ? 2 : 1; - nsub2[1] = ( transform_type[0][1] == TCX_5 && transform_type[1][1] == TCX_5 ) ? 2 : 1; - tcx_10_only = 1; - } - - /* for subframes with only TCX5 in both channels number of coefficients is only half (in 2 quarterframes) */ - numCoeffs[0] = ( nsub2[0] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; - numCoeffs[1] = ( nsub2[1] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; - - /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[0][0] = pTmp[0][0] = x[0][0]; - sig[0][1] = pTmp[0][1] = x[0][1]; - sig[1][0] = pTmp[1][0] = x[1][0]; - sig[1][1] = pTmp[1][1] = x[1][1]; - - /* convert (sub)frames to higher frequency resolution */ - for ( ch = 0; ch < nChannels; ch++ ) - { - for ( k = 0; k < NB_DIV; k++ ) - { - if ( transform_type[ch][k] == TCX_5 && nsub2[k] == 1 ) - { - /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp[ch][k] = sig[ch][k] = convertRes[ch] + k * frameSize / 2; - convert_coeffs_to_higher_res( x[ch][k], x[ch][k] + frameSize / 4, pTmp[ch][k], frameSize / 4 ); - } - } - - if ( transform_type[ch][0] != TCX_20 && nsub == 1 ) - { - /* TCX20 and TCX10 in same frame -> convert channel with TCX10 to TCX20 resolution */ - sig[ch][0] = convertRes[ch]; - convert_coeffs_to_higher_res( pTmp[ch][0], pTmp[ch][1], sig[ch][0], frameSize / 2 ); - } - } - - /* MDST estimate */ - for ( ch = 0; ch < nChannels; ch++ ) - { - for ( k = 0; k < nsub; k++ ) - { - for ( l = 0; l < nsub2[k]; l++ ) - { - mdst[ch][k][l * numCoeffs[k]] = mdst[ch][k][( l + 1 ) * numCoeffs[k] - 1] = 0.f; - for ( i = l * numCoeffs[k] + 1; i < ( l + 1 ) * numCoeffs[k] - 1; i++ ) - { - mdst[ch][k][i] = sig[ch][k][i + 1] - sig[ch][k][i - 1]; - } - } - } - } - - /* compute and apply bandwise weigths for active downmix (similar to DFT Stereo) */ - stop_tcx5 = 0; - for ( b = 0; b < sfbConf->sfbCnt; b++ ) - { - float w[CPE_CHANNELS][4]; - - for ( k = 0; k < nsub; k++ ) - { - for ( l = 0; l < nsub2[k]; l++ ) - { - float sum_nrg_L = EPSILON, sum_nrg_R = EPSILON; - float dot_prod_real = EPSILON, dot_prod_imag = EPSILON; - float sum_nrg_Mid, sum_abs, dot_prod_abs; - - start = l * numCoeffs[k] + sfbConf->sfbOffset[b] / nsub2[k]; - stop = l * numCoeffs[k] + sfbConf->sfbOffset[b + 1] / nsub2[k]; - - /* compute band energies and cross correlation */ - for ( i = start; i < stop; i++ ) - { - sum_nrg_L += sig[0][k][i] * sig[0][k][i] + mdst[0][k][i] * mdst[0][k][i]; - sum_nrg_R += sig[1][k][i] * sig[1][k][i] + mdst[1][k][i] * mdst[1][k][i]; - dot_prod_real += sig[0][k][i] * sig[1][k][i] + mdst[0][k][i] * mdst[1][k][i]; - dot_prod_imag += mdst[0][k][i] * sig[1][k][i] - sig[0][k][i] * mdst[1][k][i]; - } - sum_nrg_Mid = max( 0.f, sum_nrg_L + sum_nrg_R + 2.f * dot_prod_real ); - sum_abs = sqrtf( sum_nrg_L ) + sqrtf( sum_nrg_R ) + EPSILON; - dot_prod_abs = sqrtf( dot_prod_real * dot_prod_real + dot_prod_imag * dot_prod_imag ); - - /* calculate weights */ - if ( hCPE->hStereoMdct->reverse_dmx == 0 ) - { - w[1][2 * k + l] = sqrtf( 0.5f * ( sum_nrg_L + sum_nrg_R ) + dot_prod_abs ) / sum_abs; - w[0][2 * k + l] = w[1][2 * k + l] + sqrtf( 2.f ) * ( 1.f - sqrtf( sum_nrg_Mid ) / sum_abs ); - } - else - { - w[0][2 * k + l] = sqrtf( 0.5f * ( sum_nrg_L + sum_nrg_R ) + dot_prod_abs ) / sum_abs; - w[1][2 * k + l] = w[0][2 * k + l] + sqrtf( 2.f ) * ( 1.f - sqrtf( sum_nrg_Mid ) / sum_abs ); - } - } - } - - /* apply weights to channels with their original frequency resolutions */ - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - if ( transform_type[ch][0] == TCX_20 ) - { - for ( i = sfbConf->sfbOffset[b]; i < sfbConf->sfbOffset[b + 1]; i++ ) - { - x[ch][0][i] *= w[ch][0]; - } - } - else - { - start = sfbConf->sfbOffset[b]; - stop = sfbConf->sfbOffset[b + 1]; - if ( !tcx_10_only ) /* TCX20 band config is used */ - { - start /= 2; - stop /= 2; - } - - for ( k = 0; k < NB_DIV; k++ ) - { - w_idx = ( nsub == 1 ) ? 0 : 2 * k; - if ( transform_type[ch][k] == TCX_10 ) - { - for ( i = start; i < stop; i++ ) - { - x[ch][k][i] *= w[ch][w_idx]; - } - } - else /* TCX_5 */ - { - start_tcx5 = stop_tcx5; - stop_tcx5 = ( stop + 1 ) / 2; - - for ( i = start_tcx5; i < stop_tcx5; i++ ) - { - x[ch][k][i] *= w[ch][w_idx]; - } - - if ( nsub2[k] == 2 ) - { - w_idx++; - } - - for ( i = start_tcx5; i < stop_tcx5; i++ ) - { - x[ch][k][i + ( frameSize >> 2 )] *= w[ch][w_idx]; - } - } - } - } - } - } - - return; -} -#endif - /*-------------------------------------------------------------------* - * apply_dmx_weights() + * apply_dmx_weights_fx() * * apply bandwise weighting for later dmx in case of mono output *--------------------------------------------------------------------*/ @@ -1090,7 +957,7 @@ static void apply_dmx_weights_fx( /*-------------------------------------------------------------------* - * run_min_stats() + * run_min_stats_fx() * * run the minimum statistics noise estimation algorithm * directly on the MDCT spectrum -- GitLab