From 3a062f0123da7dfffc1a55e689e789736ede6066 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 6 Mar 2026 08:55:27 +0200 Subject: [PATCH 1/3] Add macro statements in clang format to format reasonably when macro is not resolved. --- .clang-format | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.clang-format b/.clang-format index 0e8b84b3a..f6155a6cb 100644 --- a/.clang-format +++ b/.clang-format @@ -84,5 +84,14 @@ SpacesInCStyleCastParentheses: false SpacesInParentheses: true SpacesInSquareBrackets: false Standard: Cpp11 +StatementMacros: + - IF + - ELSEIF + - ELSE + - SWITCH + - CASE + - FOR + - WHILE + - DO TabWidth: 8 UseTab: Never -- GitLab From c5345f3d6675742c8cd189da7e7b433a0d118d08 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 6 Mar 2026 09:37:13 +0200 Subject: [PATCH 2/3] Fine tune a bit. --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index f6155a6cb..643f8053e 100644 --- a/.clang-format +++ b/.clang-format @@ -86,8 +86,8 @@ SpacesInSquareBrackets: false Standard: Cpp11 StatementMacros: - IF - - ELSEIF - - ELSE +# - ELSE IF +# - ELSE # Note that ELSE cannot be used here as it would break ELSE IF into two lines. - SWITCH - CASE - FOR -- GitLab From ebfa0ad794eac6f095f949a4b4ffd759523e9674 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 6 Mar 2026 09:43:02 +0200 Subject: [PATCH 3/3] Apply new clang format --- lib_com/bitstream_fx.c | 12 +- lib_com/cng_exc_fx.c | 716 ++++++++++++------------ lib_com/hq2_core_com_fx.c | 154 ++--- lib_com/ivas_qspherical_com_fx.c | 101 ++-- lib_com/ivas_stereo_td_bit_alloc_fx.c | 50 +- lib_com/lsf_dec_bfi_fx.c | 117 ++-- lib_com/swb_bwe_com_fx.c | 398 ++++++------- lib_com/swb_bwe_com_lr_fx.c | 187 ++++--- lib_com/tools_fx.c | 36 +- lib_dec/dec4t64_fx.c | 106 ++-- lib_dec/dec_tcx_fx.c | 73 +-- lib_dec/hdecnrm_fx.c | 108 ++-- lib_dec/igf_dec_fx.c | 32 +- lib_dec/ivas_qmetadata_dec_fx.c | 18 +- lib_dec/ivas_spar_md_dec_fx.c | 42 +- lib_dec/lib_dec_fx.c | 52 +- lib_dec/tonalMDCTconcealment_fx.c | 568 +++++++++---------- lib_dec/transition_dec_fx.c | 24 +- lib_enc/ACcontextMapping_enc_fx.c | 49 +- lib_enc/cod4t64_fx.c | 38 +- lib_enc/igf_enc_fx.c | 40 +- lib_enc/ivas_enc_cov_handler_fx.c | 30 +- lib_enc/ivas_mc_param_enc_fx.c | 28 +- lib_enc/ivas_qspherical_enc_fx.c | 191 ++++--- lib_enc/ivas_stereo_dft_enc_fx.c | 304 +++++----- lib_enc/lib_enc_fx.c | 25 +- lib_enc/mslvq_enc_fx.c | 32 +- lib_enc/ppp_enc_fx.c | 2 +- lib_enc/swb_tbe_enc_fx.c | 64 ++- lib_isar/lib_isar_post_rend.c | 42 +- lib_rend/ivas_binRenderer_internal_fx.c | 26 +- lib_rend/ivas_efap_fx.c | 18 +- 32 files changed, 1882 insertions(+), 1801 deletions(-) mode change 100755 => 100644 lib_enc/igf_enc_fx.c diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 634659c7f..0180ee363 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -5281,10 +5281,14 @@ void evs_dec_previewFrame( { /* read the fec offset at which the partial copy is received */ ind = get_indice_preview( bitstream, bitstreamSize, sub( bitstreamSize, 5 ), 2 ); - IF( ind == 0 ) *partialCopyOffset = 2; - ELSE IF( EQ_32( ind, 1 ) ) *partialCopyOffset = 3; - ELSE IF( EQ_32( ind, 2 ) ) *partialCopyOffset = 5; - ELSE IF( EQ_32( ind, 3 ) ) *partialCopyOffset = 7; + IF( ind == 0 ) + *partialCopyOffset = 2; + ELSE IF( EQ_32( ind, 1 ) ) + *partialCopyOffset = 3; + ELSE IF( EQ_32( ind, 2 ) ) + *partialCopyOffset = 5; + ELSE IF( EQ_32( ind, 3 ) ) + *partialCopyOffset = 7; move16(); /* the last three bits in a packet is the RF frame type */ *partialCopyFrameType = get_indice_preview( bitstream, bitstreamSize, bitstreamSize - 3, 3 ); diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 084f28796..69089dedf 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -147,451 +147,453 @@ void CNG_exc_fx( move16(); } } - ELSE{ + ELSE + { /* normal CNG update */ - IF( *last_allow_cn_step == 0 ){ + IF( *last_allow_cn_step == 0 ) + { /**lp_ener = (float)(A2 * *Enew + (1-A2) * *lp_ener);*/ L_tmp_ener = Mult_32_16( *Enew, A2 ); - L_tmp_ener = Madd_32_16( L_tmp_ener, *lp_ener, OmA2 ); -} -ELSE -{ - test(); - if ( EQ_32( core_brate, SID_1k75 ) || EQ_32( core_brate, SID_2k40 ) ) + L_tmp_ener = Madd_32_16( L_tmp_ener, *lp_ener, OmA2 ); + } + ELSE + { + test(); + if ( EQ_32( core_brate, SID_1k75 ) || EQ_32( core_brate, SID_2k40 ) ) + { + *last_allow_cn_step = 0; + move16(); + } + + L_tmp_ener = *Enew; + move32(); + } + } + *lp_ener = L_max( L_tmp_ener, 1 ); + move32(); /*To avoid / per 0*/ + + if ( EQ_16( allow_cn_step, 1 ) ) { - *last_allow_cn_step = 0; + *last_allow_cn_step = 1; move16(); } + /* If not mono, skip CNG here */ + IF( GT_16( element_mode, IVAS_SCE ) ) + { + return; + } - L_tmp_ener = *Enew; - move32(); -} -} -*lp_ener = L_max( L_tmp_ener, 1 ); -move32(); /*To avoid / per 0*/ - -if ( EQ_16( allow_cn_step, 1 ) ) -{ - *last_allow_cn_step = 1; - move16(); -} -/* If not mono, skip CNG here */ -IF( GT_16( element_mode, IVAS_SCE ) ) -{ - return; -} - -/*---------------------------------------------------------------------* - * Generate white noise vector - *---------------------------------------------------------------------*/ - -/*for ( i=0; i Q_exc +16 */ - exc2[i_subfr + i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); - move16(); + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* exc2[i] *= enr */ + L_tmp = L_mult( exc2[i_subfr + i], tmp ); /* Q-4 * Q_exc+19 -> Q_exc +16 */ + exc2[i_subfr + i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); + move16(); + } } -} -IF( NE_16( Opt_AMR_WB, 1 ) ) -{ - Copy( exc2, exc3, L_FRAME16k ); - - /* enr1 = (float)log10( *Enew*L_frame + 0.1f ) / (float)log10( 2.0f ); */ - exp = norm_l( *Enew ); - L_tmp = L_shl( *Enew, exp ); /* Q(exp+6) */ - L_tmp = Mult_32_16( L_tmp, shl( L_frame, 5 ) ); /* Q(exp+6+5-15=exp-4) */ - L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /* Q6 */ - exp = norm_l( L_tmp ); - fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 6 ); - L_tmp = L_Comp( exp, fra ); - /* enr1 = round_fx(L_shl(L_tmp,8)); */ /*Q8 */ - enr1 = L_shr( L_tmp, 10 ); /* Q6 */ - - - IF( EQ_32( core_brate, SID_2k40 ) ) + IF( NE_16( Opt_AMR_WB, 1 ) ) { - IF( *sid_bw == 0 ) + Copy( exc2, exc3, L_FRAME16k ); + + /* enr1 = (float)log10( *Enew*L_frame + 0.1f ) / (float)log10( 2.0f ); */ + exp = norm_l( *Enew ); + L_tmp = L_shl( *Enew, exp ); /* Q(exp+6) */ + L_tmp = Mult_32_16( L_tmp, shl( L_frame, 5 ) ); /* Q(exp+6+5-15=exp-4) */ + L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /* Q6 */ + exp = norm_l( L_tmp ); + fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 6 ); + L_tmp = L_Comp( exp, fra ); + /* enr1 = round_fx(L_shl(L_tmp,8)); */ /*Q8 */ + enr1 = L_shr( L_tmp, 10 ); /* Q6 */ + + + IF( EQ_32( core_brate, SID_2k40 ) ) { - FOR( i = 0; i < NUM_ENV_CNG; i++ ) + IF( *sid_bw == 0 ) + { + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* get quantized envelope */ + /* env[i] = pow(2.0f,(enr1 - q_env[i])); */ + L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ + L_tmp = L_shl( L_tmp, 10 ); /* 16 */ + temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); + + exp_pow = sub( 14, temp_hi_fx ); + L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ + env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); + move32(); /* Q6 */ + } + } + + /* initialize CNG envelope */ + test(); + IF( *first_CNG == 0 && *sid_bw == 0 ) { - /* get quantized envelope */ - /* env[i] = pow(2.0f,(enr1 - q_env[i])); */ - L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ - L_tmp = L_shl( L_tmp, 10 ); /* 16 */ - temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); - - exp_pow = sub( 14, temp_hi_fx ); - L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ - env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); - move32(); /* Q6 */ + Copy32( env, lp_env, NUM_ENV_CNG ); + } + + IF( *sid_bw == 0 ) + { + Copy32( env, old_env, NUM_ENV_CNG ); } } - /* initialize CNG envelope */ - test(); - IF( *first_CNG == 0 && *sid_bw == 0 ) + FOR( i = 0; i < NUM_ENV_CNG; i++ ) { - Copy32( env, lp_env, NUM_ENV_CNG ); + /* get AR low-passed envelope */ + /* lp_env[i] = 0.9f*lp_env[i] + (1-0.9f)*old_env[i]; */ + L_tmp = Mult_32_16( lp_env[i], 29491 /*.9f in Q15*/ ); + lp_env[i] = L_add( L_tmp, Mult_32_16( old_env[i], 3277 /*.1f in Q15*/ ) ); + move32(); /* Q6 */ } - IF( *sid_bw == 0 ) + /* calculate the spectrum of random excitation signal */ + Copy( exc2, fft_io, L_frame ); + + IF( EQ_16( L_frame, L_FRAME16k ) ) { - Copy32( env, old_env, NUM_ENV_CNG ); + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem1, 0, NULL, NULL ); } - } - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* get AR low-passed envelope */ - /* lp_env[i] = 0.9f*lp_env[i] + (1-0.9f)*old_env[i]; */ - L_tmp = Mult_32_16( lp_env[i], 29491 /*.9f in Q15*/ ); - lp_env[i] = L_add( L_tmp, Mult_32_16( old_env[i], 3277 /*.1f in Q15*/ ) ); - move32(); /* Q6 */ - } + /* fft_rel(fft_io, L_FFT, LOG2_L_FFT); */ + fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); /* ??????? */ + ptR = &fft_io[1]; + ptI = &fft_io[L_FFT - 1]; + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ + L_tmp = L_mult0( *ptR, *ptR ); /* 2*Q_exc */ + L_tmp = L_mac0_sat( L_tmp, *ptI, *ptI ); /* 2*Q_exc */ + L_tmp = L_shr( L_tmp, 1 ); /* 2*Q_exc+6 */ + tmp = add( Q_exc, Q_exc ); + env[i] = L_shr_sat( L_tmp, tmp ); + move32(); /* Q6 */ + ptR++; + ptI--; + } - /* calculate the spectrum of random excitation signal */ - Copy( exc2, fft_io, L_frame ); + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* denv[i] = lp_env[i] + 2*(*lp_ener) - env[i]; */ + L_tmp = L_add_sat( *lp_ener, *lp_ener ); + denv[i] = L_sub_sat( L_add_sat( lp_env[i], L_tmp ), env[i] ); + move32(); /* Q6 */ - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem1, 0, NULL, NULL ); - } + if ( denv[i] < 0 ) + { + denv[i] = 0; + move32(); + } + } + set32_fx( itmp, 0, NUM_ENV_CNG ); - /* fft_rel(fft_io, L_FFT, LOG2_L_FFT); */ - fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); /* ??????? */ - ptR = &fft_io[1]; - ptI = &fft_io[L_FFT - 1]; - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ - L_tmp = L_mult0( *ptR, *ptR ); /* 2*Q_exc */ - L_tmp = L_mac0_sat( L_tmp, *ptI, *ptI ); /* 2*Q_exc */ - L_tmp = L_shr( L_tmp, 1 ); /* 2*Q_exc+6 */ - tmp = add( Q_exc, Q_exc ); - env[i] = L_shr_sat( L_tmp, tmp ); - move32(); /* Q6 */ - ptR++; - ptI--; - } + set16_fx( fft_io, 0, L_FFT ); + ptR = &fft_io[1]; + ptI = &fft_io[L_FFT - 1]; + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* *ptR = own_random( cng_ener_seed1 ); */ + /* *ptI = own_random( cng_ener_seed1 ); */ + *ptR = Random( cng_ener_seed1 ); + move16(); + *ptI = Random( cng_ener_seed1 ); + move16(); - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* denv[i] = lp_env[i] + 2*(*lp_ener) - env[i]; */ - L_tmp = L_add_sat( *lp_ener, *lp_ener ); - denv[i] = L_sub_sat( L_add_sat( lp_env[i], L_tmp ), env[i] ); - move32(); /* Q6 */ + /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ + L_tmp = L_mult0( *ptR, *ptR ); /* Q0 */ + L_tmp = L_mac0( L_tmp, *ptI, *ptI ); /* Q0 */ + env[i] = L_shr( L_tmp, 1 ); + move32(); /* Q6 */ + ptR++; + ptI--; + } - if ( denv[i] < 0 ) + FOR( i = 0; i < NUM_ENV_CNG; i++ ) { - denv[i] = 0; - move32(); + /* itmp[i] += own_random( cng_ener_seed1 )*denv[i]*0.000011f + denv[i]; */ + L_tmp = Mult_32_16( denv[i], Random( cng_ener_seed1 ) ); // Q6 + L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); // Q6 + L_tmp = L_add_sat( L_tmp, denv[i] ); + itmp[i] = L_add_sat( L_tmp, itmp[i] ); + move32(); /* Q6 */ + + if ( itmp[i] < 0 ) + { + itmp[i] = 0; + move32(); + } } - } - set32_fx( itmp, 0, NUM_ENV_CNG ); + ptR = &fft_io[1]; + ptI = &fft_io[L_FFT - 1]; + FOR( i = 0; i < NUM_ENV_CNG; i++ ) + { + /* *ptR *= sqrt(itmp[i]/env[i]); */ + /* *ptI *= sqrt(itmp[i]/env[i]); */ + L_tmp = L_max( 1, itmp[i] ); /*Q6*/ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( 31 - 6, exp ); /* in Q15 (L_tmp in Q6)*/ - set16_fx( fft_io, 0, L_FFT ); - ptR = &fft_io[1]; - ptI = &fft_io[L_FFT - 1]; - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* *ptR = own_random( cng_ener_seed1 ); */ - /* *ptI = own_random( cng_ener_seed1 ); */ - *ptR = Random( cng_ener_seed1 ); - move16(); - *ptI = Random( cng_ener_seed1 ); - move16(); + exp2 = norm_l( env[i] ); + tmp2 = extract_h( L_shl( env[i], exp2 ) ); + exp2 = sub( 31 - 6, exp2 ); /* in Q15 (L_tmp in Q6)*/ - /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ - L_tmp = L_mult0( *ptR, *ptR ); /* Q0 */ - L_tmp = L_mac0( L_tmp, *ptI, *ptI ); /* Q0 */ - env[i] = L_shr( L_tmp, 1 ); - move32(); /* Q6 */ - ptR++; - ptI--; - } + exp = sub( exp2, exp ); /* Denormalize and substract */ + IF( GT_16( tmp2, tmp ) ) + { + exp = add( exp, 1 ); + } + IF( GT_16( tmp2, tmp ) ) + { + tmp2 = shr( tmp2, 1 ); + } + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* itmp[i] += own_random( cng_ener_seed1 )*denv[i]*0.000011f + denv[i]; */ - L_tmp = Mult_32_16( denv[i], Random( cng_ener_seed1 ) ); // Q6 - L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); // Q6 - L_tmp = L_add_sat( L_tmp, denv[i] ); - itmp[i] = L_add_sat( L_tmp, itmp[i] ); - move32(); /* Q6 */ + L_tmp2 = Mult_32_16( L_tmp, *ptR ); /*Q(16-exp)*/ + *ptR = extract_h( L_shl_sat( L_tmp2, add( exp, Q_exc ) ) ); /*Q_exc*/ + move16(); + L_tmp2 = Mult_32_16( L_tmp, *ptI ); /*Q(16-exp)*/ + *ptI = extract_h( L_shl_sat( L_tmp2, add( exp, Q_exc ) ) ); /*Q_exc*/ + move16(); + ptR++; + ptI--; + } + + ifft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); - if ( itmp[i] < 0 ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { - itmp[i] = 0; - move32(); + modify_Fs_fx( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0, NULL, NULL ); } - } - ptR = &fft_io[1]; - ptI = &fft_io[L_FFT - 1]; - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* *ptR *= sqrt(itmp[i]/env[i]); */ - /* *ptI *= sqrt(itmp[i]/env[i]); */ - L_tmp = L_max( 1, itmp[i] ); /*Q6*/ - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( 31 - 6, exp ); /* in Q15 (L_tmp in Q6)*/ - exp2 = norm_l( env[i] ); - tmp2 = extract_h( L_shl( env[i], exp2 ) ); - exp2 = sub( 31 - 6, exp2 ); /* in Q15 (L_tmp in Q6)*/ + /* enr1 = dotp( fft_io, fft_io, L_frame ) / L_frame; */ - exp = sub( exp2, exp ); /* Denormalize and substract */ - IF( GT_16( tmp2, tmp ) ) + enr1 = 1; + move32(); + pt_fft_io = fft_io; + IF( EQ_16( L_frame, L_FRAME ) ) { - exp = add( exp, 1 ); + FOR( j = 0; j < 128; j++ ) + { + L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); + pt_fft_io++; + L_tmp = L_mac0( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ + pt_fft_io++; + enr1 = L_add( enr1, L_shr( L_tmp, 7 ) ); /* 2*(Q_exc)+1, divide by L_frame done here */ + } } - IF( GT_16( tmp2, tmp ) ) + ELSE /* L_FRAME16k */ { - tmp2 = shr( tmp2, 1 ); + FOR( j = 0; j < 160; j++ ) + { + L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); + pt_fft_io++; + L_tmp = L_mac0( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ + pt_fft_io++; + enr1 = L_add( enr1, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_exc)+15+1-16+1, divide by L_frame done here */ + } } - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ + enr1 = L_shr( enr1, sub( add( Q_exc, Q_exc ), 5 ) ); /*Q6*/ - L_tmp2 = Mult_32_16( L_tmp, *ptR ); /*Q(16-exp)*/ - *ptR = extract_h( L_shl_sat( L_tmp2, add( exp, Q_exc ) ) ); /*Q_exc*/ - move16(); - L_tmp2 = Mult_32_16( L_tmp, *ptI ); /*Q(16-exp)*/ - *ptI = extract_h( L_shl_sat( L_tmp2, add( exp, Q_exc ) ) ); /*Q_exc*/ - move16(); - ptR++; - ptI--; - } + /* add time domain randomization */ + FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) + { - ifft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); + L_tmp = Mult_32_16( enr1, Random( cng_ener_seed1 ) ); + L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); + L_tmp = L_add( L_tmp, enr1 ); + L_tmp = L_max( L_tmp, 1 ); - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - modify_Fs_fx( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0, NULL, NULL ); - } + /* enr = dot_product( fft_io, fft_io, L_SUBFR ) + 0.01f */ + tmp = extract_h( Dot_product12( &fft_io[i_subfr], &fft_io[i_subfr], L_SUBFR, &exp ) ); + exp = add( exp, sub( -6, add( Q_exc, Q_exc ) ) ); /* -2*Q_exc from fft_io, -6 from L_SUBFR */ - /* enr1 = dotp( fft_io, fft_io, L_frame ) / L_frame; */ + /* enr = (float)sqrt( ener_lp*L_SUBFR / enr ) */ + exp2 = norm_l( L_tmp ); + tmp2 = extract_h( L_shl( L_tmp, exp2 ) ); + exp2 = sub( 31 - 6, exp2 ); /* in Q15 (L_tmp in Q6)*/ - enr1 = 1; - move32(); - pt_fft_io = fft_io; - IF( EQ_16( L_frame, L_FRAME ) ) - { - FOR( j = 0; j < 128; j++ ) - { - L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); - pt_fft_io++; - L_tmp = L_mac0( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ - pt_fft_io++; - enr1 = L_add( enr1, L_shr( L_tmp, 7 ) ); /* 2*(Q_exc)+1, divide by L_frame done here */ + exp = sub( exp, exp2 ); + + IF( GT_16( tmp, tmp2 ) ) + { + exp = add( exp, 1 ); + } + IF( GT_16( tmp, tmp2 ) ) + { + tmp = shr( tmp, 1 ); + } + tmp = div_s( tmp, tmp2 ); + + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ + test(); + test(); + test(); + IF( NE_32( last_core_brate, SID_2k40 ) && NE_32( last_core_brate, SID_1k75 ) && ( last_core_brate != FRAME_NO_DATA ) && EQ_32( core_brate, SID_2k40 ) ) + { + IF( GT_32( L_tmp, L_shl_sat( 1, sub( 31, exp ) ) ) ) + { + L_tmp = L_shl( 1, sub( 31, exp ) ); + } + } + + tmp = extract_h( L_tmp ); + FOR( i = 0; i < L_SUBFR; i++ ) + { + /* fft_io[i] *= enr */ + L_tmp = L_mult( fft_io[i_subfr + i], tmp ); /* Q_exc + 16 - exp */ + fft_io[i_subfr + i] = round_fx( L_shl( L_tmp, exp ) ); /*Q_exc*/ + move16(); + } } - } - ELSE /* L_FRAME16k */ - { - FOR( j = 0; j < 160; j++ ) + + FOR( i = 0; i < L_frame; i++ ) { - L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); - pt_fft_io++; - L_tmp = L_mac0( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ - pt_fft_io++; - enr1 = L_add( enr1, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_exc)+15+1-16+1, divide by L_frame done here */ + /* fft_io[i] = 0.75f*fft_io[i] + exc2[i];*/ + tmp = mult( fft_io[i], 24576 /*.75f in Q15*/ ); + fft_io[i] = add_sat( tmp, exc2[i] ); + move16(); /*Q_exc*/ } - } - enr1 = L_shr( enr1, sub( add( Q_exc, Q_exc ), 5 ) ); /*Q6*/ - /* add time domain randomization */ - FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) - { + /* enr = (dotp( fft_io, fft_io, L_frame ) / L_frame) + 0.01f */ - L_tmp = Mult_32_16( enr1, Random( cng_ener_seed1 ) ); - L_tmp = Mult_32_16( L_tmp, GAIN_VAR ); - L_tmp = L_add( L_tmp, enr1 ); - L_tmp = L_max( L_tmp, 1 ); + L_tmp2 = 1; + move32(); + pt_fft_io = fft_io; + IF( EQ_16( L_frame, L_FRAME ) ) + { + FOR( j = 0; j < 128; j++ ) + { + L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); + pt_fft_io++; + L_tmp = L_mac0_sat( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ + pt_fft_io++; + L_tmp2 = L_add_sat( L_tmp2, L_shr( L_tmp, 7 ) ); /* 2*(Q_exc)+1, divide by L_frame done here */ + } + } + ELSE /* L_FRAME16k */ + { + FOR( j = 0; j < 160; j++ ) + { + L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); + pt_fft_io++; + L_tmp = L_mac0_sat( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ + pt_fft_io++; + L_tmp2 = L_add( L_tmp2, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_exc)+15+1-16+1, divide by L_frame done here */ + } + } + L_tmp2 = L_shr( L_tmp2, sub( add( Q_exc, Q_exc ), 5 ) ); /*Q6*/ - /* enr = dot_product( fft_io, fft_io, L_SUBFR ) + 0.01f */ - tmp = extract_h( Dot_product12( &fft_io[i_subfr], &fft_io[i_subfr], L_SUBFR, &exp ) ); - exp = add( exp, sub( -6, add( Q_exc, Q_exc ) ) ); /* -2*Q_exc from fft_io, -6 from L_SUBFR */ + /* enr = (*lp_ener)/enr; */ + /* ftmp = sqrt(enr); */ + L_tmp = L_max( 1, *lp_ener ); /*Q6*/ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( 31 - 6, exp ); /* in Q15 (L_tmp in Q6)*/ - /* enr = (float)sqrt( ener_lp*L_SUBFR / enr ) */ - exp2 = norm_l( L_tmp ); - tmp2 = extract_h( L_shl( L_tmp, exp2 ) ); + exp2 = norm_l( L_tmp2 ); + tmp2 = extract_h( L_shl( L_tmp2, exp2 ) ); exp2 = sub( 31 - 6, exp2 ); /* in Q15 (L_tmp in Q6)*/ - exp = sub( exp, exp2 ); - - IF( GT_16( tmp, tmp2 ) ) + exp = sub( exp2, exp ); /* Denormalize and substract */ + IF( GT_16( tmp2, tmp ) ) { exp = add( exp, 1 ); } - IF( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp2, tmp ) ) { - tmp = shr( tmp, 1 ); + tmp2 = shr( tmp2, 1 ); } - tmp = div_s( tmp, tmp2 ); - + tmp = div_s( tmp2, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ - test(); - test(); - test(); - IF( NE_32( last_core_brate, SID_2k40 ) && NE_32( last_core_brate, SID_1k75 ) && ( last_core_brate != FRAME_NO_DATA ) && EQ_32( core_brate, SID_2k40 ) ) - { - IF( GT_32( L_tmp, L_shl_sat( 1, sub( 31, exp ) ) ) ) - { - L_tmp = L_shl( 1, sub( 31, exp ) ); - } - } - tmp = extract_h( L_tmp ); - FOR( i = 0; i < L_SUBFR; i++ ) + ftmp = extract_h( L_shl_sat( L_tmp, exp ) ); /* Q15 */ + FOR( i = 0; i < L_frame; i++ ) { - /* fft_io[i] *= enr */ - L_tmp = L_mult( fft_io[i_subfr + i], tmp ); /* Q_exc + 16 - exp */ - fft_io[i_subfr + i] = round_fx( L_shl( L_tmp, exp ) ); /*Q_exc*/ - move16(); + /* fft_io[i] *= ftmp;*/ + fft_io[i] = mult( fft_io[i], ftmp ); + move16(); /* Q_exc */ } + Copy( fft_io, exc2, L_frame ); } - - FOR( i = 0; i < L_frame; i++ ) + IF( NE_16( Opt_AMR_WB, 1 ) ) { - /* fft_io[i] = 0.75f*fft_io[i] + exc2[i];*/ - tmp = mult( fft_io[i], 24576 /*.75f in Q15*/ ); - fft_io[i] = add_sat( tmp, exc2[i] ); - move16(); /*Q_exc*/ + Copy( exc3, exc, L_frame ); } - - /* enr = (dotp( fft_io, fft_io, L_frame ) / L_frame) + 0.01f */ - - L_tmp2 = 1; - move32(); - pt_fft_io = fft_io; - IF( EQ_16( L_frame, L_FRAME ) ) - { - FOR( j = 0; j < 128; j++ ) - { - L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); - pt_fft_io++; - L_tmp = L_mac0_sat( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ - pt_fft_io++; - L_tmp2 = L_add_sat( L_tmp2, L_shr( L_tmp, 7 ) ); /* 2*(Q_exc)+1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ + ELSE { - FOR( j = 0; j < 160; j++ ) - { - L_tmp = L_mult0( *pt_fft_io, *pt_fft_io ); - pt_fft_io++; - L_tmp = L_mac0_sat( L_tmp, *pt_fft_io, *pt_fft_io ); /* 2*(Q_exc) */ - pt_fft_io++; - L_tmp2 = L_add( L_tmp2, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_exc)+15+1-16+1, divide by L_frame done here */ - } + Copy( exc2, exc, L_frame ); } - L_tmp2 = L_shr( L_tmp2, sub( add( Q_exc, Q_exc ), 5 ) ); /*Q6*/ - - /* enr = (*lp_ener)/enr; */ - /* ftmp = sqrt(enr); */ - L_tmp = L_max( 1, *lp_ener ); /*Q6*/ - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( 31 - 6, exp ); /* in Q15 (L_tmp in Q6)*/ - exp2 = norm_l( L_tmp2 ); - tmp2 = extract_h( L_shl( L_tmp2, exp2 ) ); - exp2 = sub( 31 - 6, exp2 ); /* in Q15 (L_tmp in Q6)*/ - - exp = sub( exp2, exp ); /* Denormalize and substract */ - IF( GT_16( tmp2, tmp ) ) - { - exp = add( exp, 1 ); - } - IF( GT_16( tmp2, tmp ) ) + IF( EQ_16( L_frame, L_FRAME ) ) { - tmp2 = shr( tmp2, 1 ); + interp_code_5over2_fx( exc2, bwe_exc, L_FRAME ); } - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ - - ftmp = extract_h( L_shl_sat( L_tmp, exp ) ); /* Q15 */ - FOR( i = 0; i < L_frame; i++ ) + ELSE { - /* fft_io[i] *= ftmp;*/ - fft_io[i] = mult( fft_io[i], ftmp ); - move16(); /* Q_exc */ + interp_code_4over2_fx( exc2, bwe_exc, L_frame ); } - Copy( fft_io, exc2, L_frame ); -} -IF( NE_16( Opt_AMR_WB, 1 ) ) -{ - Copy( exc3, exc, L_frame ); -} -ELSE -{ - Copy( exc2, exc, L_frame ); -} - -IF( EQ_16( L_frame, L_FRAME ) ) -{ - interp_code_5over2_fx( exc2, bwe_exc, L_FRAME ); -} -ELSE -{ - interp_code_4over2_fx( exc2, bwe_exc, L_frame ); -} -return; + return; } diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index b8ae7880d..2c24410f2 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -333,99 +333,101 @@ void hq2_core_configure_fx( } } ELSE /* (frame_length == SWB) */ + { + IF( is_transient ) { - IF( is_transient ){ - IF( LE_32( L_bwe_br, ACELP_13k20 ) ){ - xcore_config_fx = &xcore_config_32kHz_013200bps_short; + IF( LE_32( L_bwe_br, ACELP_13k20 ) ) + { + xcore_config_fx = &xcore_config_32kHz_013200bps_short; + move16(); + } + ELSE IF( LE_32( L_bwe_br, ACELP_16k40 ) ) + { + xcore_config_fx = &xcore_config_32kHz_016400bps_short; + move16(); + } + } + ELSE + { + IF( LE_32( L_bwe_br, ACELP_13k20 ) ) + { + xcore_config_fx = &xcore_config_32kHz_013200bps_long; + move16(); + } + ELSE IF( LE_32( L_bwe_br, ACELP_16k40 ) ) + { + xcore_config_fx = &xcore_config_32kHz_016400bps_long; + move16(); + } + } + } + + *bands = xcore_config_fx->bands; /* Q0 */ move16(); -} -ELSE IF( LE_32( L_bwe_br, ACELP_16k40 ) ) -{ - xcore_config_fx = &xcore_config_32kHz_016400bps_short; + *length = xcore_config_fx->bw; /* Q0 */ move16(); -} -} -ELSE -{ - IF( LE_32( L_bwe_br, ACELP_13k20 ) ) - { - xcore_config_fx = &xcore_config_32kHz_013200bps_long; - move16(); - } - ELSE IF( LE_32( L_bwe_br, ACELP_16k40 ) ) - { - xcore_config_fx = &xcore_config_32kHz_016400bps_long; - move16(); - } -} -} + *L_qint = xcore_config_fx->L_qint; /* Q13 */ + move32(); -*bands = xcore_config_fx->bands; /* Q0 */ -move16(); -*length = xcore_config_fx->bw; /* Q0 */ -move16(); -*L_qint = xcore_config_fx->L_qint; /* Q13 */ -move32(); - -*eref = xcore_config_fx->eref; /* Q10 */ -move16(); -*bit_alloc_weight = xcore_config_fx->bit_alloc_weight; /* Q13 */ -move16(); -*gqlevs = xcore_config_fx->gqlevs; /* Q0 */ -move16(); -*Ngq = xcore_config_fx->Ngq; /* Q0 */ -move16(); - -*p2a_bands = xcore_config_fx->p2a_bands; /* Q0 */ -move16(); -*p2a_th = xcore_config_fx->p2a_th; /* Q11 */ -move16(); - -*pd_thresh = xcore_config_fx->pd_thresh; /* Q15 */ -move16(); -*ld_slope = xcore_config_fx->ld_slope; /* Q14 */ -move16(); -*ni_coef = xcore_config_fx->ni_coef; /* Q14 */ -move16(); - -/*mvs2s_fx (xcore_config_fx->band_width, band_width, *bands); */ -Copy( xcore_config_fx->band_width, band_width, *bands ); /* Q0 */ - -/* Expand band_width[] table for short windows */ -IF( is_transient ) -{ - bands_sh = *bands; /* Q0 */ + *eref = xcore_config_fx->eref; /* Q10 */ move16(); - *bands = shl( bands_sh, 2 ); /* Q0 */ + *bit_alloc_weight = xcore_config_fx->bit_alloc_weight; /* Q13 */ + move16(); + *gqlevs = xcore_config_fx->gqlevs; /* Q0 */ + move16(); + *Ngq = xcore_config_fx->Ngq; /* Q0 */ + move16(); + + *p2a_bands = xcore_config_fx->p2a_bands; /* Q0 */ move16(); - *length = shl( *length, 2 ); /* Q0 */ + *p2a_th = xcore_config_fx->p2a_th; /* Q11 */ move16(); - FOR( i = 1; i <= 3; i++ ) + *pd_thresh = xcore_config_fx->pd_thresh; /* Q15 */ + move16(); + *ld_slope = xcore_config_fx->ld_slope; /* Q14 */ + move16(); + *ni_coef = xcore_config_fx->ni_coef; /* Q14 */ + move16(); + + /*mvs2s_fx (xcore_config_fx->band_width, band_width, *bands); */ + Copy( xcore_config_fx->band_width, band_width, *bands ); /* Q0 */ + + /* Expand band_width[] table for short windows */ + IF( is_transient ) { - FOR( k = 0; k < bands_sh; k++ ) + bands_sh = *bands; /* Q0 */ + move16(); + *bands = shl( bands_sh, 2 ); /* Q0 */ + move16(); + *length = shl( *length, 2 ); /* Q0 */ + move16(); + + FOR( i = 1; i <= 3; i++ ) { - band_width[i * bands_sh + k] = band_width[k]; /* Q0 */ - move16(); + FOR( k = 0; k < bands_sh; k++ ) + { + band_width[i * bands_sh + k] = band_width[k]; /* Q0 */ + move16(); + } } } -} -/* Formulate band_start and band_end tables from band_width table */ -band_start[0] = 0; /* Q0 */ -move16(); -band_end[0] = sub( band_width[0], 1 ); /* Q0 */ -move16(); -FOR( k = 1; k < *bands; k++ ) -{ - band_start[k] = add( band_start[k - 1], band_width[k - 1] ); /* Q0 */ + /* Formulate band_start and band_end tables from band_width table */ + band_start[0] = 0; /* Q0 */ move16(); - band_end[k] = sub( add( band_start[k], band_width[k] ), 1 ); /* Q0 */ + band_end[0] = sub( band_width[0], 1 ); /* Q0 */ move16(); -} + FOR( k = 1; k < *bands; k++ ) + { + band_start[k] = add( band_start[k - 1], band_width[k - 1] ); /* Q0 */ + move16(); + band_end[k] = sub( add( band_start[k], band_width[k] ), 1 ); /* Q0 */ + move16(); + } -return; + return; } /*--------------------------------------------------------------------------* diff --git a/lib_com/ivas_qspherical_com_fx.c b/lib_com/ivas_qspherical_com_fx.c index 2a0e7797c..2f50c3a6c 100644 --- a/lib_com/ivas_qspherical_com_fx.c +++ b/lib_com/ivas_qspherical_com_fx.c @@ -278,23 +278,26 @@ Word16 quantize_phi_fx( { id_phi = add( id_phi, ( n % 2 ) ); } - ELSE{ - IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ){ - IF( n % 2 ){ + ELSE + { + IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ) + { + IF( n % 2 ) + { id_phi = sub( id_phi, 1 ); -} -ELSE -{ - id_phi = negate( id_phi ); -} -} -} + } + ELSE + { + id_phi = negate( id_phi ); + } + } + } -*phi_hat = L_add_sat( L_add_sat( imult3216( delta_phi_fx, id_phi ), dd_fx ), DEGREE_180_Q_22 ); // Q22 -move32(); -id_phi = add( id_phi, shr( n, 1 ) ); + *phi_hat = L_add_sat( L_add_sat( imult3216( delta_phi_fx, id_phi ), dd_fx ), DEGREE_180_Q_22 ); // Q22 + move32(); + id_phi = add( id_phi, shr( n, 1 ) ); -return id_phi; + return id_phi; } Word16 quantize_phi_enc_fx( @@ -356,23 +359,26 @@ Word16 quantize_phi_enc_fx( { id_phi = add( id_phi, ( n % 2 ) ); } - ELSE{ - IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ){ - IF( n % 2 ){ + ELSE + { + IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ) + { + IF( n % 2 ) + { id_phi = sub( id_phi, 1 ); -} -ELSE -{ - id_phi = negate( id_phi ); -} -} -} + } + ELSE + { + id_phi = negate( id_phi ); + } + } + } -*phi_hat = L_add_sat( L_add_sat( ( imult3216( delta_phi_fx, id_phi ) ), dd_fx ), DEGREE_180_Q_22 ); -move32(); -id_phi = add( id_phi, shr( n, 1 ) ); + *phi_hat = L_add_sat( L_add_sat( ( imult3216( delta_phi_fx, id_phi ) ), dd_fx ), DEGREE_180_Q_22 ); + move32(); + id_phi = add( id_phi, shr( n, 1 ) ); -return id_phi; + return id_phi; } /*-----------------------------------------------------------------------* * companding_azimuth() @@ -677,27 +683,30 @@ Word16 quantize_phi_chan_compand_fx( { id_phi = add( id_phi, ( n % 2 ) ); } - ELSE{ - IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ){ - IF( n % 2 ){ + ELSE + { + IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ) + { + IF( n % 2 ) + { id_phi = sub( id_phi, 1 ); -} -ELSE -{ - id_phi = negate( id_phi ); -} -} -} -//*phi_hat = id_phi * delta_phi; -*phi_hat = imult3216( delta_phi, id_phi ); // Q22 -move32(); + } + ELSE + { + id_phi = negate( id_phi ); + } + } + } + //*phi_hat = id_phi * delta_phi; + *phi_hat = imult3216( delta_phi, id_phi ); // Q22 + move32(); -// id_phi += ( n >> 1 ); -id_phi = add( id_phi, shr( n, 1 ) ); + // id_phi += ( n >> 1 ); + id_phi = add( id_phi, shr( n, 1 ) ); -*phi_hat = L_add( companding_azimuth_fx( *phi_hat, mc_format, theta_flag, -1 ), DEGREE_180_Q_22 ); // Q22 -move32(); + *phi_hat = L_add( companding_azimuth_fx( *phi_hat, mc_format, theta_flag, -1 ), DEGREE_180_Q_22 ); // Q22 + move32(); -return id_phi; + return id_phi; } diff --git a/lib_com/ivas_stereo_td_bit_alloc_fx.c b/lib_com/ivas_stereo_td_bit_alloc_fx.c index 45dfb3110..fe5790a2f 100644 --- a/lib_com/ivas_stereo_td_bit_alloc_fx.c +++ b/lib_com/ivas_stereo_td_bit_alloc_fx.c @@ -513,37 +513,39 @@ void tdm_bit_alloc( move16(); idx = sub( NB_RATE_POSS, 2 ); - FOR( i = 0; i < NB_RATE_POSS; i++ ){ - IF( LE_16( tmp_rate, fast_FCB_rates_2sfr[i] ) ){ + FOR( i = 0; i < NB_RATE_POSS; i++ ) + { + IF( LE_16( tmp_rate, fast_FCB_rates_2sfr[i] ) ) + { idx = i; - move16(); - BREAK; + move16(); + BREAK; + } + } + *total_brate_sec = L_add( *total_brate_sec, sub( fast_FCB_rates_2sfr[idx], tmp_rate ) ); /*Q0*/ + move32(); + } + + /* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ + IF( EQ_32( L_sub( element_brate_wo_meta, *total_brate_sec ), ACELP_13k20 ) ) + { + *total_brate_sec = L_add( *total_brate_sec, 100 ); /*Q0*/ + move32(); } } - *total_brate_sec = L_add( *total_brate_sec, sub( fast_FCB_rates_2sfr[idx], tmp_rate ) ); /*Q0*/ - move32(); -} -/* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ -IF( EQ_32( L_sub( element_brate_wo_meta, *total_brate_sec ), ACELP_13k20 ) ) -{ - *total_brate_sec = L_add( *total_brate_sec, 100 ); /*Q0*/ - move32(); -} -} + /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ + test(); + IF( EQ_32( *total_brate_sec, PPP_NELP_2k80 ) || EQ_32( *total_brate_sec, SID_2k40 ) ) + { + *total_brate_sec = L_sub( *total_brate_sec, 100 ); /*Q0*/ + move32(); + } -/* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ -test(); -IF( EQ_32( *total_brate_sec, PPP_NELP_2k80 ) || EQ_32( *total_brate_sec, SID_2k40 ) ) -{ - *total_brate_sec = L_sub( *total_brate_sec, 100 ); /*Q0*/ + *total_brate_pri = L_sub( element_brate_wo_meta, *total_brate_sec ); /*Q0*/ move32(); -} - -*total_brate_pri = L_sub( element_brate_wo_meta, *total_brate_sec ); /*Q0*/ -move32(); -return; + return; } /*-------------------------------------------------------------------* diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index 41db2c647..f4329d64e 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -186,72 +186,75 @@ void lsf_dec_bfi( { reorder_isf_fx( lsf, ISF_GAP_FX, M, Fs_2 ); } - ELSE{ - IF( EQ_16( L_frame, L_FRAME ) ){ - IF( EQ_16( codec_mode, MODE1 ) ){ + ELSE + { + IF( EQ_16( L_frame, L_FRAME ) ) + { + IF( EQ_16( codec_mode, MODE1 ) ) + { reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M, INT_FS_FX ); /*arg1&2: 14Q1*1.18*/ -} -ELSE -{ - reorder_lsf_fx( lsf, LSF_GAP_FX, M, INT_FS_FX ); /*arg1&2: 14Q1*1.18*/ -} + } + ELSE + { + reorder_lsf_fx( lsf, LSF_GAP_FX, M, INT_FS_FX ); /*arg1&2: 14Q1*1.18*/ + } -IF( lsf_q_cng != NULL ) -{ - reorder_lsf_fx( lsf_q_cng, LSF_GAP_FX, M, INT_FS_FX ); -} -} -ELSE IF( tcxonly != 0 ) -{ - IF( EQ_16( L_frame, 320 ) ) - { - gap = 143; - move16(); - } - ELSE IF( EQ_16( L_frame, 512 ) ) - { - gap = 90; - move16(); + IF( lsf_q_cng != NULL ) + { + reorder_lsf_fx( lsf_q_cng, LSF_GAP_FX, M, INT_FS_FX ); + } + } + ELSE IF( tcxonly != 0 ) + { + IF( EQ_16( L_frame, 320 ) ) + { + gap = 143; + move16(); + } + ELSE IF( EQ_16( L_frame, 512 ) ) + { + gap = 90; + move16(); + } + ELSE IF( EQ_16( L_frame, 640 ) ) + { + gap = 72; + move16(); + } + ELSE + { + gap = 48; + move16(); + } + reorder_lsf_fx( lsf, gap, M, INT_FS_FX ); + } + ELSE + { + reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M, i_mult( L_frame, 50 ) ); /*arg1&2: 14Q1*1.18*/ + IF( lsf_q_cng != NULL ) + { + reorder_lsf_fx( lsf_q_cng, LSF_GAP_FX, M, INT_FS_16k_FX ); + } + } } - ELSE IF( EQ_16( L_frame, 640 ) ) + + /* update the AR memory to be used in the next frame */ { - gap = 72; - move16(); + Copy( lsf, mem_AR, M ); } - ELSE + + /* update the MA memory to be used in the next frame */ + FOR( i = 0; i < M; i++ ) { - gap = 48; + /*factor 0x4000 means 0.5. Together with /2 in mem_MA-assignment, + this results in an attenuation of the MA Q memory */ + tmp = L_msu( L_mult( lsf[i], 0x4000 ), pt_meansForMemUpdate[i], 0x4000 ); + /* Update with quantized prediction error for MA model */ + mem_MA[i] = msu_r( tmp, MU_MA_FX / 2, mem_MA[i] ); move16(); } - reorder_lsf_fx( lsf, gap, M, INT_FS_FX ); -} -ELSE -{ - reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M, i_mult( L_frame, 50 ) ); /*arg1&2: 14Q1*1.18*/ - IF( lsf_q_cng != NULL ) - { - reorder_lsf_fx( lsf_q_cng, LSF_GAP_FX, M, INT_FS_16k_FX ); - } -} -} - -/* update the AR memory to be used in the next frame */ -{ - Copy( lsf, mem_AR, M ); -} - -/* update the MA memory to be used in the next frame */ -FOR( i = 0; i < M; i++ ) -{ - /*factor 0x4000 means 0.5. Together with /2 in mem_MA-assignment, - this results in an attenuation of the MA Q memory */ - tmp = L_msu( L_mult( lsf[i], 0x4000 ), pt_meansForMemUpdate[i], 0x4000 ); - /* Update with quantized prediction error for MA model */ - mem_MA[i] = msu_r( tmp, MU_MA_FX / 2, mem_MA[i] ); - move16(); -} -return; + return; } Word16 const *PlcGetLsfBase( diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 9b7c2424f..ca7596606 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -1694,234 +1694,236 @@ void SWB_BWE_decoding_fx( } tmp_exp = sub( 15, Q_syn ); - FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ){ - IF( envelope[n_freq] != 0 ){ + FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ) + { + IF( envelope[n_freq] != 0 ) + { exp = norm_l( envelope[n_freq] ); - tmp = extract_h( L_shl( envelope[n_freq], exp ) ); - exp = sub( sub( 30, exp ), Q_syn ); - tmp = div_s( 16384 /* 0.5 in Q15*/, tmp ); /* Q(15+exp) */ - L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /* Q15 */ - SWB_signal[n_freq] = extract_l( L_tmp ); - move16(); /* Q15 */ + tmp = extract_h( L_shl( envelope[n_freq], exp ) ); + exp = sub( sub( 30, exp ), Q_syn ); + tmp = div_s( 16384 /* 0.5 in Q15*/, tmp ); /* Q(15+exp) */ + L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /* Q15 */ + SWB_signal[n_freq] = extract_l( L_tmp ); + move16(); /* Q15 */ + } + ELSE + { + SWB_signal[n_freq] = shl( SWB_signal[n_freq], tmp_exp ); + move16(); /* Q15 */ + } + } + *prev_weight = weight; + move16(); } ELSE { - SWB_signal[n_freq] = shl( SWB_signal[n_freq], tmp_exp ); - move16(); /* Q15 */ + exp = norm_s( L_swb_norm ); + tmp = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */ + tmp = add( shl( tmp, 1 ), tmp ); + *prev_weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ ); /* Q15 */ + move16(); } - } - *prev_weight = weight; - move16(); -} -ELSE -{ - exp = norm_s( L_swb_norm ); - tmp = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */ - tmp = add( shl( tmp, 1 ), tmp ); - *prev_weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ ); /* Q15 */ - move16(); -} -IF( EQ_16( mode, HARMONIC ) ) -{ - pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset]; - move16(); - FOR( n_band = 0; n_band < 19; n_band++ ) - { - L_mean = L_deposit_l( 0 ); - FOR( n_freq = 0; n_freq < 16; n_freq++ ) - { - L_mean = L_add( L_mean, abs_s( *pit1 ) ); /*Q15 */ - pit1++; - } - mean = extract_l( Mult_32_16( L_mean, 2048 /* 1/16 in Q15 */ ) ); /*Q15 */ - pit1 -= 16; - FOR( n_freq = 0; n_freq < 16; n_freq++ ) + IF( EQ_16( mode, HARMONIC ) ) { - IF( LT_16( abs_s( *pit1 ), mean ) ) + pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset]; + move16(); + FOR( n_band = 0; n_band < 19; n_band++ ) { - *pit1 = mult_r( *pit1, 6554 /* 0.2 in Q15 */ ); /*Q15*/ - move16(); + L_mean = L_deposit_l( 0 ); + FOR( n_freq = 0; n_freq < 16; n_freq++ ) + { + L_mean = L_add( L_mean, abs_s( *pit1 ) ); /*Q15 */ + pit1++; + } + mean = extract_l( Mult_32_16( L_mean, 2048 /* 1/16 in Q15 */ ) ); /*Q15 */ + pit1 -= 16; + FOR( n_freq = 0; n_freq < 16; n_freq++ ) + { + IF( LT_16( abs_s( *pit1 ), mean ) ) + { + *pit1 = mult_r( *pit1, 6554 /* 0.2 in Q15 */ ); /*Q15*/ + move16(); + } + pit1++; + } } - pit1++; } - } -} - -L = 1; -move16(); -if ( EQ_16( mode, HARMONIC ) ) -{ - L = 2; - move16(); -} -FOR( n_band = 0; n_band < SWB_FENV; n_band += L ) -{ - energy = L_deposit_l( 0 ); - tmp = add( swb_bwe_subband[n_band + L], st_offset ); - FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) - { - L_tmp = L_mult( SWB_signal[n_freq], SWB_signal[n_freq] ); /*Q31 */ - energy = L_add( energy, L_shr( L_tmp, 6 ) ); /*Q25 */ - } - - IF( energy == 0 ) - { - tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band]; /*Q12 */ + L = 1; move16(); - if ( NE_16( L, 1 ) ) + if ( EQ_16( mode, HARMONIC ) ) { - tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr( n_band, 1 )]; /*Q12 */ + L = 2; move16(); } - tmp = add( swb_bwe_subband[n_band + L], st_offset ); - tmp_exp = sub( Q_syn, 12 ); - FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + FOR( n_band = 0; n_band < SWB_FENV; n_band += L ) { - SWB_signal_32[n_freq] = L_shl( L_mult( tmp_ener, SWB_signal[n_freq] ), tmp_exp ); /*Qsyn */ - move32(); - } - } - ELSE - { - tmp = sub( swb_bwe_subband[n_band + L], swb_bwe_subband[n_band] ); - exp1 = norm_s( tmp ); - tmp = div_s( shl( 1, sub( 14, exp1 ) ), tmp ); /*Q(29-exp1) */ - energy = Mult_32_16( energy, tmp ); /*Q(29-exp1+25-15)->Q(-exp1+39) */ + energy = L_deposit_l( 0 ); + tmp = add( swb_bwe_subband[n_band + L], st_offset ); + FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + L_tmp = L_mult( SWB_signal[n_freq], SWB_signal[n_freq] ); /*Q31 */ + energy = L_add( energy, L_shr( L_tmp, 6 ) ); /*Q25 */ + } - exp = norm_l( energy ); - L_tmp = L_shl( energy, exp ); - /*exp = 31-exp-(-exp1+39);move16(); */ - exp = sub( sub( exp1, exp ), 8 ); - Ltmp_ener = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + IF( energy == 0 ) + { + tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band]; /*Q12 */ + move16(); + if ( NE_16( L, 1 ) ) + { + tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr( n_band, 1 )]; /*Q12 */ + move16(); + } + + tmp = add( swb_bwe_subband[n_band + L], st_offset ); + tmp_exp = sub( Q_syn, 12 ); + FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + SWB_signal_32[n_freq] = L_shl( L_mult( tmp_ener, SWB_signal[n_freq] ), tmp_exp ); /*Qsyn */ + move32(); + } + } + ELSE + { + tmp = sub( swb_bwe_subband[n_band + L], swb_bwe_subband[n_band] ); + exp1 = norm_s( tmp ); + tmp = div_s( shl( 1, sub( 14, exp1 ) ), tmp ); /*Q(29-exp1) */ + energy = Mult_32_16( energy, tmp ); /*Q(29-exp1+25-15)->Q(-exp1+39) */ - tmp = add( swb_bwe_subband[n_band + L], st_offset ); - tmp_exp = add( Q_syn, sub( exp, 15 ) ); - FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + exp = norm_l( energy ); + L_tmp = L_shl( energy, exp ); + /*exp = 31-exp-(-exp1+39);move16(); */ + exp = sub( sub( exp1, exp ), 8 ); + Ltmp_ener = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ + + tmp = add( swb_bwe_subband[n_band + L], st_offset ); + tmp_exp = add( Q_syn, sub( exp, 15 ) ); + FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) + { + SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), tmp_exp ); + move32(); /*Qsyn+16 */ + } + } + } + + IF( GT_16( *prev_Energy, add_sat( Energy_16, shr( Energy_16, 2 ) ) ) && Energy_16 > 0 ) { - SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), tmp_exp ); - move32(); /*Qsyn+16 */ + weight = shr( div_s( Energy_16, *prev_Energy ), 1 ); /*Q15 */ } - } -} + ELSE + { + weight = 16384; + move16(); /*Q15 */ + } + L_tmp = L_mult( weight, prev_SWB_fenv[0] ); /*Q17 */ + L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[0] ); /*Q17 */ + wfenv = round_fx( L_tmp ); /*Q1 */ -IF( GT_16( *prev_Energy, add_sat( Energy_16, shr( Energy_16, 2 ) ) ) && Energy_16 > 0 ) -{ - weight = shr( div_s( Energy_16, *prev_Energy ), 1 ); /*Q15 */ -} -ELSE -{ - weight = 16384; - move16(); /*Q15 */ -} -L_tmp = L_mult( weight, prev_SWB_fenv[0] ); /*Q17 */ -L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[0] ); /*Q17 */ -wfenv = round_fx( L_tmp ); /*Q1 */ + tmp = norm_s( wfenv ); + IF( GT_16( tmp, 4 ) ) + { + tmp = 12; + move16(); + factor = fenvL_16; + move16(); /*Q3 */ + factor1 = mult_r( sub( shl( wfenv, 2 ), fenvL_16 ), 4096 /* 0.125 in Q15 */ ); /*Q3 */ + } + ELSE + { + tmp = 14; + move16(); + factor = shr( fenvL_16, 2 ); /*Q1 */ + factor1 = mult_r( sub( wfenv, factor ), 4096 /* 0.125 in Q15 */ ); /*Q1 */ + } -tmp = norm_s( wfenv ); -IF( GT_16( tmp, 4 ) ) -{ - tmp = 12; - move16(); - factor = fenvL_16; - move16(); /*Q3 */ - factor1 = mult_r( sub( shl( wfenv, 2 ), fenvL_16 ), 4096 /* 0.125 in Q15 */ ); /*Q3 */ -} -ELSE -{ - tmp = 14; - move16(); - factor = shr( fenvL_16, 2 ); /*Q1 */ - factor1 = mult_r( sub( wfenv, factor ), 4096 /* 0.125 in Q15 */ ); /*Q1 */ -} + tmp2 = add( add( swb_bwe_subband[0], 8 ), st_offset ); + FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp2; n_freq++ ) + { + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); + move32(); /*15+Qsyn */ + factor = add( factor, factor1 ); /*Q3 */ + } -tmp2 = add( add( swb_bwe_subband[0], 8 ), st_offset ); -FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp2; n_freq++ ) -{ - L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); - move32(); /*15+Qsyn */ - factor = add( factor, factor1 ); /*Q3 */ -} + FOR( n_band = 0; n_band < 12; n_band++ ) + { + L_tmp = L_mult( weight, prev_SWB_fenv[n_band + 1] ); /*Q17 */ + L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band + 1] ); /*Q17 */ + wfenv = round_fx( L_tmp ); /*Q1 */ + factor = SWB_fenv[n_band]; + move16(); /*Q1 */ + factor1 = mult_r( sub( wfenv, SWB_fenv[n_band] ), smooth_factor_fx[n_band] ); /*Q1 */ + tmp = norm_s( factor ); + IF( GT_16( tmp, 4 ) ) + { + tmp = 12; + move16(); + factor = shl( factor, 2 ); + factor1 = shl( factor1, 2 ); + } + ELSE + { + tmp = 14; + move16(); + } -FOR( n_band = 0; n_band < 12; n_band++ ) -{ - L_tmp = L_mult( weight, prev_SWB_fenv[n_band + 1] ); /*Q17 */ - L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band + 1] ); /*Q17 */ - wfenv = round_fx( L_tmp ); /*Q1 */ - factor = SWB_fenv[n_band]; - move16(); /*Q1 */ - factor1 = mult_r( sub( wfenv, SWB_fenv[n_band] ), smooth_factor_fx[n_band] ); /*Q1 */ - tmp = norm_s( factor ); - IF( GT_16( tmp, 4 ) ) - { - tmp = 12; - move16(); - factor = shl( factor, 2 ); - factor1 = shl( factor1, 2 ); - } - ELSE - { - tmp = 14; - move16(); - } + tmp2 = add( swb_bwe_sm_subband[n_band + 1], st_offset ); + FOR( ; n_freq < tmp2; n_freq++ ) + { + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); + move32(); /*15+Qsyn */ + factor = add_sat( factor, factor1 ); /*Q1 */ + } + } + L_tmp = L_mult( weight, prev_SWB_fenv[13] ); /*Q17 */ + L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[13] ); /*Q17 */ + wfenv = round_fx( L_tmp ); /*Q1 */ + factor = SWB_fenv[12]; + move16(); /*Q1 */ + factor1 = mult_r( sub( wfenv, SWB_fenv[12] ), smooth_factor_fx[12] ); /*Q1 */ + tmp2 = add( swb_bwe_sm_subband[13], st_offset ); + FOR( ; n_freq < tmp2; n_freq++ ) + { + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); + move32(); /*15+Qsyn */ + factor = add( factor, factor1 ); /*Q1 */ + } - tmp2 = add( swb_bwe_sm_subband[n_band + 1], st_offset ); - FOR( ; n_freq < tmp2; n_freq++ ) - { - L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 ); - move32(); /*15+Qsyn */ - factor = add_sat( factor, factor1 ); /*Q1 */ + FOR( n_band = 13; n_band < SWB_FENV; n_band++ ) + { + L_tmp = L_mult( weight, prev_SWB_fenv[n_band] ); /*Q17 */ + L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band] ); /*Q17 */ + wfenv = round_fx( L_tmp ); /*Q1 */ + tmp2 = add( swb_bwe_subband[n_band + 1], st_offset ); + FOR( ; n_freq < tmp2; n_freq++ ) + { + L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); + SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); + move32(); /*15+Qsyn */ + } + } + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) + { + prev_SWB_fenv[n_band] = SWB_fenv[n_band]; + move16(); /*Q1 */ + } } -} -L_tmp = L_mult( weight, prev_SWB_fenv[13] ); /*Q17 */ -L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[13] ); /*Q17 */ -wfenv = round_fx( L_tmp ); /*Q1 */ -factor = SWB_fenv[12]; -move16(); /*Q1 */ -factor1 = mult_r( sub( wfenv, SWB_fenv[12] ), smooth_factor_fx[12] ); /*Q1 */ -tmp2 = add( swb_bwe_sm_subband[13], st_offset ); -FOR( ; n_freq < tmp2; n_freq++ ) -{ - L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); - move32(); /*15+Qsyn */ - factor = add( factor, factor1 ); /*Q1 */ -} - -FOR( n_band = 13; n_band < SWB_FENV; n_band++ ) -{ - L_tmp = L_mult( weight, prev_SWB_fenv[n_band] ); /*Q17 */ - L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band] ); /*Q17 */ - wfenv = round_fx( L_tmp ); /*Q1 */ - tmp2 = add( swb_bwe_subband[n_band + 1], st_offset ); - FOR( ; n_freq < tmp2; n_freq++ ) + pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */ + FOR( n_freq = 0; n_freq < 4; n_freq++ ) { - L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor ); - SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 ); - move32(); /*15+Qsyn */ + L_tmp1 = Mult_32_16( *pit1_32, 16384 /* 0.5 in Q15 */ ); /*15+Qsyn */ + *( pit1_32++ ) = L_tmp1; + move32(); } -} -FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) -{ - prev_SWB_fenv[n_band] = SWB_fenv[n_band]; - move16(); /*Q1 */ -} -} -pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */ -FOR( n_freq = 0; n_freq < 4; n_freq++ ) -{ - L_tmp1 = Mult_32_16( *pit1_32, 16384 /* 0.5 in Q15 */ ); /*15+Qsyn */ - *( pit1_32++ ) = L_tmp1; - move32(); -} -*prev_Energy = Energy_16; -move16(); + *prev_Energy = Energy_16; + move16(); -return; + return; } /*==========================================================================*/ diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 9b6c6cd8e..be4437a1b 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -3241,114 +3241,119 @@ void noiseinj_hf_fx( move32(); IF( p2a_flags_fx[k] == 0 ) { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ){ - IF( LE_32( L_abs( L_xSynth_har[i - fLenLow_fx] ), L_th_g[k - ( BANDS_fx - NB_SWB_SUBBANDS )] ) ){ - *p_L_En = L_mac( *p_L_En, xSynth_har_fx[i - fLenLow_fx], xSynth_har_fx[i - fLenLow_fx] ); + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) + { + IF( LE_32( L_abs( L_xSynth_har[i - fLenLow_fx] ), L_th_g[k - ( BANDS_fx - NB_SWB_SUBBANDS )] ) ) + { + *p_L_En = L_mac( *p_L_En, xSynth_har_fx[i - fLenLow_fx], xSynth_har_fx[i - fLenLow_fx] ); + move32(); + } + ELSE + { + map_pulse_t_fx[i] = 1; + move16(); + } + } + *p_L_En = L_shl_sat( *p_L_En, sub( QbeL, QE ) ); move32(); - } - ELSE - { - map_pulse_t_fx[i] = 1; + /**p_L_En = (float)sqrt(*p_En);*/ + sqrt_32n_16_fx( *p_L_En, QbeL, p_sqrt_En_fx, &Qtemp ); + *p_sqrt_En_fx = shl_sat( *p_sqrt_En_fx, sub( QsEn, Qtemp ) ); /* -> Q2 */ move16(); } + p_L_En++; + p_sqrt_En_fx++; } - *p_L_En = L_shl_sat( *p_L_En, sub( QbeL, QE ) ); - move32(); - /**p_L_En = (float)sqrt(*p_En);*/ - sqrt_32n_16_fx( *p_L_En, QbeL, p_sqrt_En_fx, &Qtemp ); - *p_sqrt_En_fx = shl_sat( *p_sqrt_En_fx, sub( QsEn, Qtemp ) ); /* -> Q2 */ - move16(); -} -p_L_En++; -p_sqrt_En_fx++; -} -p_sqrt_En_fx = sqrt_En_fx; -p_Enn_sm_sb_fx = Enn_sm_sb_fx; -p_prev_En_sb_fx = prev_En_sb_fx; -FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) -{ - *p_Enn_sm_sb_fx = prev_En_sb_fx[k - ( BANDS_fx - NB_SWB_SUBBANDS )]; - move16(); /* QsEn */ - IF( p2a_flags_fx[k] == 0 ) + p_sqrt_En_fx = sqrt_En_fx; + p_Enn_sm_sb_fx = Enn_sm_sb_fx; + p_prev_En_sb_fx = prev_En_sb_fx; + FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) { - L_temp = Mult_32_16( L_band_energy[k], 26214 ); /* 0.8: 26214(Q15) */ - temp_fx = round_fx( L_shl( L_temp, sub( QsEn, sub( Qbe, 16 ) ) ) ); - IF( LT_16( *p_prev_En_sb_fx, temp_fx ) ) - { - /**p_Enn_sm_sb = (0.15f*(*p_En)) + (0.85f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ - /* 0.15: 4915.2(Q15) 0.85: 27852.80(Q15) */ - *p_Enn_sm_sb_fx = round_fx( L_mac( L_mult( *p_sqrt_En_fx, 4915 ), *p_prev_En_sb_fx, 27853 ) ); - } - ELSE + *p_Enn_sm_sb_fx = prev_En_sb_fx[k - ( BANDS_fx - NB_SWB_SUBBANDS )]; + move16(); /* QsEn */ + IF( p2a_flags_fx[k] == 0 ) { - /**p_Enn_sm_sb = (0.8f*(*p_En)) + (0.2f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ - /* 0.8: 26214.4(Q15) 0.2:6553.6(Q15) */ - *p_Enn_sm_sb_fx = round_fx( L_mac( L_mult( *p_sqrt_En_fx, 26214 ), *p_prev_En_sb_fx, 6554 ) ); + L_temp = Mult_32_16( L_band_energy[k], 26214 ); /* 0.8: 26214(Q15) */ + temp_fx = round_fx( L_shl( L_temp, sub( QsEn, sub( Qbe, 16 ) ) ) ); + IF( LT_16( *p_prev_En_sb_fx, temp_fx ) ) + { + /**p_Enn_sm_sb = (0.15f*(*p_En)) + (0.85f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ + /* 0.15: 4915.2(Q15) 0.85: 27852.80(Q15) */ + *p_Enn_sm_sb_fx = round_fx( L_mac( L_mult( *p_sqrt_En_fx, 4915 ), *p_prev_En_sb_fx, 27853 ) ); + } + ELSE + { + /**p_Enn_sm_sb = (0.8f*(*p_En)) + (0.2f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/ + /* 0.8: 26214.4(Q15) 0.2:6553.6(Q15) */ + *p_Enn_sm_sb_fx = round_fx( L_mac( L_mult( *p_sqrt_En_fx, 26214 ), *p_prev_En_sb_fx, 6554 ) ); + } + move16(); } - move16(); - } - p_Enn_sm_sb_fx++; - p_sqrt_En_fx++; - p_prev_En_sb_fx++; -} + p_Enn_sm_sb_fx++; + p_sqrt_En_fx++; + p_prev_En_sb_fx++; + } -p_sqrt_En_fx = sqrt_En_fx; -p_Enn_sm_sb_fx = Enn_sm_sb_fx; -p_prev_En_sb_fx = prev_En_sb_fx; -map_pulse_fx[fLenLow_fx] = ( map_pulse_t_fx[fLenLow_fx] | map_pulse_t_fx[fLenLow_fx + 1] ); -logic16(); -move16(); -FOR( i = fLenLow_fx + 1; i < band_end_fx[BANDS_fx - 1]; i++ ) -{ - map_pulse_fx[i] = ( map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] | map_pulse_t_fx[i + 1] ); + p_sqrt_En_fx = sqrt_En_fx; + p_Enn_sm_sb_fx = Enn_sm_sb_fx; + p_prev_En_sb_fx = prev_En_sb_fx; + map_pulse_fx[fLenLow_fx] = ( map_pulse_t_fx[fLenLow_fx] | map_pulse_t_fx[fLenLow_fx + 1] ); logic16(); + move16(); + FOR( i = fLenLow_fx + 1; i < band_end_fx[BANDS_fx - 1]; i++ ) + { + map_pulse_fx[i] = ( map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] | map_pulse_t_fx[i + 1] ); + logic16(); + logic16(); + move16(); + } + map_pulse_fx[i] = ( map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] ); logic16(); move16(); -} -map_pulse_fx[i] = ( map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] ); -logic16(); -move16(); -FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) -{ - test(); - IF( p2a_flags_fx[k] == 0 && *p_sqrt_En_fx != 0x0 ) + FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) { - /*ni_scale = sqrt((*p_Enn_sm_sb)/(*p_En));*/ - /* Div Part */ - exp_normn = norm_s( *p_Enn_sm_sb_fx ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_s( *p_sqrt_En_fx ); - div_fx = div_s( shl( *p_Enn_sm_sb_fx, exp_normn ), shl( *p_sqrt_En_fx, exp_normd ) ); - Qdiv = add( sub( exp_normn, exp_normd ), 15 ); - - /* SQRT Part */ - sqrt_32n_16_fx( L_deposit_h( div_fx ), add( Qdiv, 16 ), &ni_scale_fx, &Qtemp ); - ni_scale_fx = shl_sat( ni_scale_fx, sub( 14, Qtemp ) ); - ni_scale_fx = s_min( 20408, ni_scale_fx ); /* 1.25=20408.0(Q14) */ - - ni_scale_fx = s_max( 12288, ni_scale_fx ); /* 0.75=12288.0(Q14) */ - - ni_scale_fx = mult_r( ni_scale_fx, 26214 ); /* 0.8=26214.4(Q15) -> Q14 */ - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ){ - IF( LE_32( L_abs( L_xSynth_har[i - fLenLow_fx] ), L_th_g[k - ( BANDS_fx - NB_SWB_SUBBANDS )] ) ){ - IF( map_pulse_fx[i] == 0 ){ - L_xSynth_har[i - fLenLow_fx] = L_shl( Mult_32_16( L_xSynth_har[i - fLenLow_fx], ni_scale_fx ), 1 ); /* Q12+Q14-15-1 = Q12 */ - move32(); + test(); + IF( p2a_flags_fx[k] == 0 && *p_sqrt_En_fx != 0x0 ) + { + /*ni_scale = sqrt((*p_Enn_sm_sb)/(*p_En));*/ + /* Div Part */ + exp_normn = norm_s( *p_Enn_sm_sb_fx ); + exp_normn = sub( exp_normn, 1 ); + exp_normd = norm_s( *p_sqrt_En_fx ); + div_fx = div_s( shl( *p_Enn_sm_sb_fx, exp_normn ), shl( *p_sqrt_En_fx, exp_normd ) ); + Qdiv = add( sub( exp_normn, exp_normd ), 15 ); + + /* SQRT Part */ + sqrt_32n_16_fx( L_deposit_h( div_fx ), add( Qdiv, 16 ), &ni_scale_fx, &Qtemp ); + ni_scale_fx = shl_sat( ni_scale_fx, sub( 14, Qtemp ) ); + ni_scale_fx = s_min( 20408, ni_scale_fx ); /* 1.25=20408.0(Q14) */ + + ni_scale_fx = s_max( 12288, ni_scale_fx ); /* 0.75=12288.0(Q14) */ + + ni_scale_fx = mult_r( ni_scale_fx, 26214 ); /* 0.8=26214.4(Q15) -> Q14 */ + FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) + { + IF( LE_32( L_abs( L_xSynth_har[i - fLenLow_fx] ), L_th_g[k - ( BANDS_fx - NB_SWB_SUBBANDS )] ) ) + { + IF( map_pulse_fx[i] == 0 ) + { + L_xSynth_har[i - fLenLow_fx] = L_shl( Mult_32_16( L_xSynth_har[i - fLenLow_fx], ni_scale_fx ), 1 ); /* Q12+Q14-15-1 = Q12 */ + move32(); + } + } + } + *p_prev_En_sb_fx = *p_Enn_sm_sb_fx; + move16(); + } + p_Enn_sm_sb_fx++; + p_sqrt_En_fx++; + p_prev_En_sb_fx++; } -} -} -*p_prev_En_sb_fx = *p_Enn_sm_sb_fx; -move16(); -} -p_Enn_sm_sb_fx++; -p_sqrt_En_fx++; -p_prev_En_sb_fx++; -} -return; + return; } /*--------------------------------------------------------------------------* diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 47111db3e..0e092280a 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -2918,25 +2918,27 @@ void iDiv_and_mod_32( TEMP = L_shl( TEMP, 1 ); } } - ELSE{ - WHILE( L_msu0( L_sub( Numer, TEMP ), 1, Denom ) >= 0 ){ + ELSE + { + WHILE( L_msu0( L_sub( Numer, TEMP ), 1, Denom ) >= 0 ) + { Quotient = L_add( Quotient, 1 ); - TEMP = L_shl( L_mult0( extract_h( L_shl( Quotient, 1 ) ), Denom ), 16 - 1 ); - TEMP = L_mac0( TEMP, extract_l( L_and( 0x7FFF, Quotient ) ), Denom ); -} -} -*Int_quotient = Quotient; -move32(); -IF( L_msu0( L_sub( Numer, TEMP ), 1, Denom ) == 0 ) -{ - *Int_mod = 0L; - move32(); -} -ELSE -{ - *Int_mod = L_sub( Numer, TEMP ); + TEMP = L_shl( L_mult0( extract_h( L_shl( Quotient, 1 ) ), Denom ), 16 - 1 ); + TEMP = L_mac0( TEMP, extract_l( L_and( 0x7FFF, Quotient ) ), Denom ); + } + } + *Int_quotient = Quotient; move32(); -} + IF( L_msu0( L_sub( Numer, TEMP ), 1, Denom ) == 0 ) + { + *Int_mod = 0L; + move32(); + } + ELSE + { + *Int_mod = L_sub( Numer, TEMP ); + move32(); + } } /*===================================================================*/ diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 062157dca..bef7b1905 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -630,71 +630,75 @@ static Word32 fcb_decode_class_all_p_fx( Word32 mn9, j, k; Word16 pulse_pos_num; Word32 L_tmp, L_tmp1; - FOR( i = 1; i <= pulse_num; i++ ){ - IF( LT_32( ( *code_index ), PI_offset[pulse_num][i] ) ){ + FOR( i = 1; i <= pulse_num; i++ ) + { + IF( LT_32( ( *code_index ), PI_offset[pulse_num][i] ) ) + { BREAK; -} -} + } + } -/* (*code_index) -= PI_offset[pulse_num][i-1];*/ -( *code_index ) = L_sub( ( *code_index ), PI_offset[pulse_num][i - 1] ); -move32(); + /* (*code_index) -= PI_offset[pulse_num][i-1];*/ + ( *code_index ) = L_sub( ( *code_index ), PI_offset[pulse_num][i - 1] ); + move32(); -/*pulse_pos_num = pulse_num - i + 2;*/ -pulse_pos_num = add( sub( pulse_num, i ), 2 ); + /*pulse_pos_num = pulse_num - i + 2;*/ + pulse_pos_num = add( sub( pulse_num, i ), 2 ); -/* j = (*code_index)>>pulse_pos_num;*/ -j = L_shr( ( *code_index ), pulse_pos_num ); -IF( LT_32( j, PI_select_table[16][pulse_pos_num] ) ) -{ - k = L_deposit_l( 0 ); - mn9 = L_add( j, 0 ); -} -ELSE -{ - L_tmp = L_deposit_l( 0 ); - L_tmp1 = L_add( j, 0 ); - WHILE( GE_32( L_tmp1, PI_select_table[16][pulse_pos_num] ) ) + /* j = (*code_index)>>pulse_pos_num;*/ + j = L_shr( ( *code_index ), pulse_pos_num ); + IF( LT_32( j, PI_select_table[16][pulse_pos_num] ) ) { - L_tmp = L_add( L_tmp, 1 ); - L_tmp1 = L_sub( L_tmp1, PI_select_table[16][pulse_pos_num] ); + k = L_deposit_l( 0 ); + mn9 = L_add( j, 0 ); } - k = L_add( L_tmp, 0 ); - mn9 = L_add( L_tmp1, 0 ); -} -/* mn9 = Mult_32_32(sub(j , k) , PI_select_table[16][pulse_pos_num]);*/ - -test(); -IF( ( LT_16( pulse_pos_num, pulse_num ) ) && ( GT_16( pulse_pos_num, 1 ) ) ) -{ - FOR( i = 0; i < pulse_pos_num; i++ ) + ELSE { - sector_6p_num[i] = 1; - move16(); + L_tmp = L_deposit_l( 0 ); + L_tmp1 = L_add( j, 0 ); + WHILE( GE_32( L_tmp1, PI_select_table[16][pulse_pos_num] ) ) + { + L_tmp = L_add( L_tmp, 1 ); + L_tmp1 = L_sub( L_tmp1, PI_select_table[16][pulse_pos_num] ); + } + k = L_add( L_tmp, 0 ); + mn9 = L_add( L_tmp1, 0 ); } - sector_6p_num[k] = add( sector_6p_num[k], 1 ); - move16(); -} -ELSE{ + /* mn9 = Mult_32_32(sub(j , k) , PI_select_table[16][pulse_pos_num]);*/ - IF( EQ_16( pulse_pos_num, 1 ) ){ - sector_6p_num[0] = pulse_num; -move16(); -} -ELSE -{ - FOR( i = 0; i < pulse_num; i++ ) + test(); + IF( ( LT_16( pulse_pos_num, pulse_num ) ) && ( GT_16( pulse_pos_num, 1 ) ) ) { - sector_6p_num[i] = 1; + FOR( i = 0; i < pulse_pos_num; i++ ) + { + sector_6p_num[i] = 1; + move16(); + } + sector_6p_num[k] = add( sector_6p_num[k], 1 ); move16(); } -} -} + ELSE + { + + IF( EQ_16( pulse_pos_num, 1 ) ) + { + sector_6p_num[0] = pulse_num; + move16(); + } + ELSE + { + FOR( i = 0; i < pulse_num; i++ ) + { + sector_6p_num[i] = 1; + move16(); + } + } + } -*pos_num = pulse_pos_num; -move16(); + *pos_num = pulse_pos_num; + move16(); -return mn9; + return mn9; } static void fcb_decode_position_fx( diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0f5f1ec57..0544631ff 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3587,44 +3587,47 @@ void IMDCT_ivas_fx( test(); test(); test(); - IF( ( left_rect != 0 ) && ( frame_cnt == 0 ) && st->last_core_bfi == ACELP_CORE && ( st->prev_bfi != 0 ) ){ - IF( FB_flag != 0 ){ - FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ){ - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); // Q(-2) - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) - move16(); - move16(); -} -FOR( ; i < tcx_mdct_window_half_length; i++ ) -{ - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); // Q(-2) - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) - move16(); - move16(); -} -} -ELSE -{ - FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) + IF( ( left_rect != 0 ) && ( frame_cnt == 0 ) && st->last_core_bfi == ACELP_CORE && ( st->prev_bfi != 0 ) ) { - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) - move16(); - move16(); - } - FOR( ; i < tcx_mdct_window_half_length; i++ ) - { - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) - move16(); - move16(); + IF( FB_flag != 0 ) + { + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) + { + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) + move16(); + move16(); + } + FOR( ; i < tcx_mdct_window_half_length; i++ ) + { + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) + move16(); + move16(); + } + } + ELSE + { + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) + { + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) + move16(); + move16(); + } + FOR( ; i < tcx_mdct_window_half_length; i++ ) + { + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) + move16(); + move16(); + } + } } -} -} -*pq_win = q_win; -move16(); + *pq_win = q_win; + move16(); -return; + return; } void init_tcx_info_fx( diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index 2efea77b0..88083de93 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -216,22 +216,24 @@ void hdecnrm_resize_fx( temp = 6; /* Q0 */ move16(); } - ELSE{ - IF( get_next_indice_1_fx( st_fx ) != 0 ){ + ELSE + { + IF( get_next_indice_1_fx( st_fx ) != 0 ) + { temp = add( 16, k ); /* Q0 */ - } - ELSE - { - temp = sub( 15, k ); /* Q0 */ + } + ELSE + { + temp = sub( 15, k ); /* Q0 */ + move16(); + } + } + + *pidx++ = temp; /* Q0 */ move16(); } -} - -*pidx++ = temp; /* Q0 */ -move16(); -} -return; + return; } /*-------------------------------------------------------------------------- @@ -338,59 +340,61 @@ void hdecnrm_tran_fx( { temp = sub( add( 15, l ), n ); /* Q0 */ } - ELSE{ - IF( get_next_indice_1_fx( st_fx ) != 0 ){ - temp = sub( add( 15, n ), l ); /* Q0 */ - } - ELSE - { - temp = sub( add( 15, l ), n ); /* Q0 */ - IF( get_next_indice_1_fx( st_fx ) != 0 ) + ELSE { - FOR( k = 0; k < 3; ) - { - IF( get_next_indice_1_fx( st_fx ) != 0 ) - { - k++; /* Q0 */ - } - ELSE - { - BREAK; - } - } - - test(); - IF( k == 0 || EQ_16( k, 3 ) ) - { - temp = sub( temp, 5 ); - if ( EQ_16( k, 3 ) ) - { - temp = sub( temp, 1 ); /* Q0 */ - } - } - ELSE IF( EQ_16( k, 1 ) ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( temp, 1 ); /* Q0 */ + temp = sub( add( 15, n ), l ); /* Q0 */ } ELSE { - temp = add( temp, 2 ); /* Q0 */ + temp = sub( add( 15, l ), n ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( temp, 1 ); - if ( get_next_indice_1_fx( st_fx ) != 0 ) + FOR( k = 0; k < 3; ) + { + IF( get_next_indice_1_fx( st_fx ) != 0 ) + { + k++; /* Q0 */ + } + ELSE + { + BREAK; + } + } + + test(); + IF( k == 0 || EQ_16( k, 3 ) ) + { + temp = sub( temp, 5 ); + if ( EQ_16( k, 3 ) ) + { + temp = sub( temp, 1 ); /* Q0 */ + } + } + ELSE IF( EQ_16( k, 1 ) ) { temp = add( temp, 1 ); /* Q0 */ } + ELSE + { + temp = add( temp, 2 ); /* Q0 */ + IF( get_next_indice_1_fx( st_fx ) != 0 ) + { + temp = add( temp, 1 ); + if ( get_next_indice_1_fx( st_fx ) != 0 ) + { + temp = add( temp, 1 ); /* Q0 */ + } + } + } } } } - } -} -*pidx++ = temp; /* Q0 */ -move16(); -} + *pidx++ = temp; /* Q0 */ + move16(); + } -return; + return; } diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index fba40748c..038cfcdf2 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -102,24 +102,26 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou nE = 0; move32(); - FOR( sb = start; sb < stop; sb++ ){ - IF( TCXNoise[sb] ){ + FOR( sb = start; sb < stop; sb++ ) + { + IF( TCXNoise[sb] ) + { tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l -} -IF( TCXNoise[sb] ) -{ - nE = L_mac( nE, tmp16, tmp16 ); // Q31 + s_l -} -IF( TCXNoise[sb] ) -{ - noise = add( noise, 1 ); // Q0 -} -} + } + IF( TCXNoise[sb] ) + { + nE = L_mac( nE, tmp16, tmp16 ); // Q31 + s_l + } + IF( TCXNoise[sb] ) + { + noise = add( noise, 1 ); // Q0 + } + } -*totalNoiseNrg = nE; // Q31 + s_l -move32(); + *totalNoiseNrg = nE; // Q31 + s_l + move32(); -return noise; + return noise; } static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q0 | number of noise bands */ diff --git a/lib_dec/ivas_qmetadata_dec_fx.c b/lib_dec/ivas_qmetadata_dec_fx.c index 7974350ce..5f7dd103c 100644 --- a/lib_dec/ivas_qmetadata_dec_fx.c +++ b/lib_dec/ivas_qmetadata_dec_fx.c @@ -3675,17 +3675,19 @@ static Word16 read_GR_min_removed_data( } } - FOR( j = 0; j < no_data; j++ ){ - IF( GT_16( no_cv_vec[j], 1 ) ){ + FOR( j = 0; j < no_data; j++ ) + { + IF( GT_16( no_cv_vec[j], 1 ) ) + { decoded_idx[j] = add( decoded_idx[j], min_index ); - move16(); -} -} + move16(); + } + } -*p_bit_pos = bit_pos; -move16(); + *p_bit_pos = bit_pos; + move16(); -return nbits; + return nbits; } diff --git a/lib_dec/ivas_spar_md_dec_fx.c b/lib_dec/ivas_spar_md_dec_fx.c index 9bce073cd..b490c66ed 100644 --- a/lib_dec/ivas_spar_md_dec_fx.c +++ b/lib_dec/ivas_spar_md_dec_fx.c @@ -2243,31 +2243,33 @@ static void ivas_spar_plc_get_band_age( *all_valid = 1; move16(); move16(); - FOR( b = 0; b < num_bands; b++ ){ - IF( valid_bands[b] != 0 ){ + FOR( b = 0; b < num_bands; b++ ) + { + IF( valid_bands[b] != 0 ) + { base_band_age[b] = 0; /* reset band age */ - idx = add( idx, 1 ); - valid_band_idx[idx] = b; - move16(); - move16(); -} -ELSE -{ - base_band_age[b] = add( base_band_age[b], 1 ); /* increment the age of invalid bands */ /*Q0*/ + idx = add( idx, 1 ); + valid_band_idx[idx] = b; + move16(); + move16(); + } + ELSE + { + base_band_age[b] = add( base_band_age[b], 1 ); /* increment the age of invalid bands */ /*Q0*/ - IF( GT_16( base_band_age[b], 3 ) ) - { - last_valid_band_idx[b] = idx; - move16(); + IF( GT_16( base_band_age[b], 3 ) ) + { + last_valid_band_idx[b] = idx; + move16(); + } + *all_valid = 0; + move16(); + } } - *all_valid = 0; + *b_idx = idx; move16(); -} -} -*b_idx = idx; -move16(); -return; + return; } diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 0dd016b9d..55348ddff 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -4886,46 +4886,48 @@ static ivas_error ivas_dec_voip_get_samples_common return error; } } - ELSE{ + ELSE + { /* render IVAS frames directly to the output buffer */ - IF( NE_32( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ){ + IF( NE_32( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ) + { return error; + } + } + + *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); + update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); } } - *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); - update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); -} -} - -IF( hIvasDec->hasDecodedFirstGoodFrame &&splitRendBits != NULL ) -{ - Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; - Word16 i; - - /* Analyse head poses over entire frame, generate ISAR metadata and maybe encode if split coded */ - IF( NE_32( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesRendered, splitRendBits, Q_out ) ), IVAS_ERR_OK ) ) + IF( hIvasDec->hasDecodedFirstGoodFrame && splitRendBits != NULL ) { - return error; - } + Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; + Word16 i; - /* Synthesise PCM output if split PCM */ - IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) + /* Analyse head poses over entire frame, generate ISAR metadata and maybe encode if split coded */ + IF( NE_32( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesRendered, splitRendBits, Q_out ) ), IVAS_ERR_OK ) ) { - scale_sig32( p_head_pose_buf[i], *nSamplesRendered, sub( Q11, Q_out[i] ) ); // Q11 + return error; } + /* Synthesise PCM output if split PCM */ + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) + { + scale_sig32( p_head_pose_buf[i], *nSamplesRendered, sub( Q11, Q_out[i] ) ); // Q11 + } + #ifndef DISABLE_LIMITER - ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, Q11 ); + ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, Q11 ); #endif - ivas_syn_output_fx( p_head_pose_buf, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); + ivas_syn_output_fx( p_head_pose_buf, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); + } } -} -return IVAS_ERR_OK; + return IVAS_ERR_OK; } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 0a8892dba..f009e714b 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1759,349 +1759,351 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( *mdctSpectrum_exp = add( *mdctSpectrum_exp, exp ); } } - ELSE{ - IF( tonalConcealmentActive == 0 ){ - sum1 = 0; - sum2 = 0; - move64(); - move64(); - FOR( i = 0; i < crossOverFreq; i++ ) + ELSE { - Word16 x; - /*x = hTonalMDCTConc->lastBlockData.spectralData[i]; - nrgNoiseInLastFrame += x * x;*/ - sum1 = W_mac0_16_16( sum1, hTonalMDCTConc->lastBlockData.spectralData[i], hTonalMDCTConc->lastBlockData.spectralData[i] ); // Q: 2*(15-hTonalMDCTConc->lastBlockData.spectralData_exp) - - /* rnd = own_random(&rnd); */ - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); /* Q0 */ + IF( tonalConcealmentActive == 0 ) + { + sum1 = 0; + sum2 = 0; + move64(); + move64(); + FOR( i = 0; i < crossOverFreq; i++ ) + { + Word16 x; + /*x = hTonalMDCTConc->lastBlockData.spectralData[i]; + nrgNoiseInLastFrame += x * x;*/ + sum1 = W_mac0_16_16( sum1, hTonalMDCTConc->lastBlockData.spectralData[i], hTonalMDCTConc->lastBlockData.spectralData[i] ); // Q: 2*(15-hTonalMDCTConc->lastBlockData.spectralData_exp) - /* mdctSpectrum[i] = tilt * rnd; */ - mdctSpectrum[i] = L_mult( tilt, rnd ); // Q16 - move32(); + /* rnd = own_random(&rnd); */ + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); /* Q0 */ - /* tilt *= tiltFactor; */ - tilt = mult_r( tilt, tiltFactor ); /* Q15 */ + /* mdctSpectrum[i] = tilt * rnd; */ + mdctSpectrum[i] = L_mult( tilt, rnd ); // Q16 + move32(); - /* nrgWhiteNoise += mdctSpectrum[i] * mdctSpectrum[i]; */ - x = round_fx( mdctSpectrum[i] ); // Q0 - sum2 = W_mac0_16_16( sum2, x, x ); // Q0 - } - *mdctSpectrum_exp = 15; - move16(); + /* tilt *= tiltFactor; */ + tilt = mult_r( tilt, tiltFactor ); /* Q15 */ - IF( sum1 /* nrgNoiseInLastFrame */ == 0 ) - { - set32_fx( mdctSpectrum, 0, crossOverFreq ); - *mdctSpectrum_exp = SPEC_EXP_DEC; - move16(); - } - ELSE - { - IF( g == 0 ) - { - *mdctSpectrum_exp = add( add( hTonalMDCTConc->lastBlockData.spectralData_exp, e_crossfadeGain ), 31 - SPEC_EXP_DEC ); + /* nrgWhiteNoise += mdctSpectrum[i] * mdctSpectrum[i]; */ + x = round_fx( mdctSpectrum[i] ); // Q0 + sum2 = W_mac0_16_16( sum2, x, x ); // Q0 + } + *mdctSpectrum_exp = 15; move16(); - FOR( i = 0; i < crossOverFreq; i++ ) + + IF( sum1 /* nrgNoiseInLastFrame */ == 0 ) + { + set32_fx( mdctSpectrum, 0, crossOverFreq ); + *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); + } + ELSE { - /* mdctSpectrum[i] = g * mdctSpectrum[i] + crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ - L_tmp = L_mult( crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData[i] ); // exp: hTonalMDCTConc->lastBlockData.spectralData_exp+e_crossfadeGain - if ( mdctSpectrum[i] <= 0 ) + IF( g == 0 ) { - /* mdctSpectrum[i] = g * mdctSpectrum[i] - crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ - L_tmp = L_negate( L_tmp ); // exp: hTonalMDCTConc->lastBlockData.spectralData_exp+e_crossfadeGain + *mdctSpectrum_exp = add( add( hTonalMDCTConc->lastBlockData.spectralData_exp, e_crossfadeGain ), 31 - SPEC_EXP_DEC ); + move16(); + FOR( i = 0; i < crossOverFreq; i++ ) + { + /* mdctSpectrum[i] = g * mdctSpectrum[i] + crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ + L_tmp = L_mult( crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData[i] ); // exp: hTonalMDCTConc->lastBlockData.spectralData_exp+e_crossfadeGain + if ( mdctSpectrum[i] <= 0 ) + { + /* mdctSpectrum[i] = g * mdctSpectrum[i] - crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ + L_tmp = L_negate( L_tmp ); // exp: hTonalMDCTConc->lastBlockData.spectralData_exp+e_crossfadeGain + } + /* headroom for mdct_shaping */ + mdctSpectrum[i] = L_shr( L_tmp, 31 - SPEC_EXP_DEC ); // *mdctSpectrum_exp + move32(); + } } - /* headroom for mdct_shaping */ - mdctSpectrum[i] = L_shr( L_tmp, 31 - SPEC_EXP_DEC ); // *mdctSpectrum_exp + ELSE + { + IF( sum2 /* nrgWhiteNoise */ > 0 ) + { + exp1 = sub( W_norm( sum1 ), 1 ); + num16 = extract_h( W_extract_h( W_shl( sum1, exp1 ) ) ); // nrgNoiseInLastFrame -> Q: 2*(15-hTonalMDCTConc->lastBlockData.spectralData_exp)+exp1-48 + exp2 = W_norm( sum2 ); + den16 = extract_h( W_extract_h( W_shl( sum2, exp2 ) ) ); // nrgWhiteNoise -> Q: exp2-48 + + /* sqrt( nrgNoiseInLastFrame / nrgWhiteNoise ) */ + tmp = div_s( num16, den16 ); // Q: 15+(2*(15-hTonalMDCTConc->lastBlockData.spectralData_exp)+exp1-48)-(exp2-48) + exp = sub( sub( shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ), 30 ), sub( exp1, exp2 ) ); // exp of tmp + tmp = Sqrt16( tmp, &exp ); + g = mult_r( g, tmp ); // exponent of g = exp + } + + exp1 = add( *mdctSpectrum_exp, exp ); + exp2 = add( hTonalMDCTConc->lastBlockData.spectralData_exp, e_crossfadeGain ); + exp = add( s_max( exp1, exp2 ), 1 ); + shift1 = sub( exp1, exp ); + shift2 = sub( exp2, exp ); + + FOR( i = 0; i < crossOverFreq; i++ ) + { + L_tmp1 = L_shl( Mpy_32_16_1( mdctSpectrum[i], g ), shift1 ); // g * mdctSpectrum[i] + L_tmp2 = L_shl( L_mult( crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData[i] ), shift2 ); // exp + + /* mdctSpectrum[i] = g * mdctSpectrum[i] - crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ + L_tmp = L_sub( L_tmp1, L_tmp2 ); // exp + if ( mdctSpectrum[i] > 0 ) + { + /* mdctSpectrum[i] = g * mdctSpectrum[i] + crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ + L_tmp = L_add( L_tmp1, L_tmp2 ); // exp + } + mdctSpectrum[i] = L_shr( L_tmp, 31 - SPEC_EXP_DEC ); // exp+31-SPEC_EXP_DEC + move32(); + } + /* headroom for mdct_shaping */ + *mdctSpectrum_exp = add( exp, 31 - SPEC_EXP_DEC ); + move16(); + } + } + exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, *mdctSpectrum_exp ); + FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) + { + mdctSpectrum[i] = L_shl( L_deposit_h( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // mdctSpectrum_exp move32(); } } ELSE { - IF( sum2 /* nrgWhiteNoise */ > 0 ) + assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++ ) { - exp1 = sub( W_norm( sum1 ), 1 ); - num16 = extract_h( W_extract_h( W_shl( sum1, exp1 ) ) ); // nrgNoiseInLastFrame -> Q: 2*(15-hTonalMDCTConc->lastBlockData.spectralData_exp)+exp1-48 - exp2 = W_norm( sum2 ); - den16 = extract_h( W_extract_h( W_shl( sum2, exp2 ) ) ); // nrgWhiteNoise -> Q: exp2-48 - - /* sqrt( nrgNoiseInLastFrame / nrgWhiteNoise ) */ - tmp = div_s( num16, den16 ); // Q: 15+(2*(15-hTonalMDCTConc->lastBlockData.spectralData_exp)+exp1-48)-(exp2-48) - exp = sub( sub( shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ), 30 ), sub( exp1, exp2 ) ); // exp of tmp - tmp = Sqrt16( tmp, &exp ); - g = mult_r( g, tmp ); // exponent of g = exp + mdctSpectrum[l] = L_deposit_l( 0 ); } - exp1 = add( *mdctSpectrum_exp, exp ); - exp2 = add( hTonalMDCTConc->lastBlockData.spectralData_exp, e_crossfadeGain ); - exp = add( s_max( exp1, exp2 ), 1 ); - shift1 = sub( exp1, exp ); - shift2 = sub( exp2, exp ); - - FOR( i = 0; i < crossOverFreq; i++ ) + ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); + fac = shr( -32768, ld ); + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - L_tmp1 = L_shl( Mpy_32_16_1( mdctSpectrum[i], g ), shift1 ); // g * mdctSpectrum[i] - L_tmp2 = L_shl( L_mult( crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData[i] ), shift2 ); // exp + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp + move16(); + Word32 y; - /* mdctSpectrum[i] = g * mdctSpectrum[i] - crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ - L_tmp = L_sub( L_tmp1, L_tmp2 ); // exp - if ( mdctSpectrum[i] > 0 ) - { - /* mdctSpectrum[i] = g * mdctSpectrum[i] + crossfadeGain * hTonalMDCTConc->lastBlockData.spectralData[i]; */ - L_tmp = L_add( L_tmp1, L_tmp2 ); // exp - } - mdctSpectrum[i] = L_shr( L_tmp, 31 - SPEC_EXP_DEC ); // exp+31-SPEC_EXP_DEC - move32(); - } - /* headroom for mdct_shaping */ - *mdctSpectrum_exp = add( exp, 31 - SPEC_EXP_DEC ); - move16(); - } - } - exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, *mdctSpectrum_exp ); - FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) - { - mdctSpectrum[i] = L_shl( L_deposit_h( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // mdctSpectrum_exp - move32(); - } -} -ELSE -{ - assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); - FOR( l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++ ) - { - mdctSpectrum[l] = L_deposit_l( 0 ); - } + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); - fac = shr( -32768, ld ); - FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) - { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp - move16(); - Word32 y; + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - x_exp - ld) + Q(15 - x_exp) - 15 = Q(31 - x_exp * 2 - ld) + x = round_fx( y ); // 15Q16 -> Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - (15 - 0) - ld) + Q(0) - 15 = Q(1 - ld) - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 - y = L_mult( tilt, rnd ); // 15Q16 + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - x_exp - ld) + Q(15 - x_exp) - 15 = Q(31 - x_exp * 2 - ld) - x = round_fx( y ); // 15Q16 -> Q15 - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - (15 - 0) - ld) + Q(0) - 15 = Q(1 - ld) + tilt = mult_r( tilt, tiltFactor ); /* Q15 */ + } - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ - move32(); + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[i - 1], hTonalMDCTConc->pTCI->lowerIndex[i - 1] ), 1 ) ), 15, &exp ) ); + tmp = shl_sat( tmp, exp ); + tilt = mult_r( tilt, tmp ); // Q15 - tilt = mult_r( tilt, tiltFactor ); /* Q15 */ - } + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) + { + mdctSpectrum[l] = L_deposit_l( 0 ); + move32(); + } + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) + { + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp + move16(); + Word32 y; - FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) - { - tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[i - 1], hTonalMDCTConc->pTCI->lowerIndex[i - 1] ), 1 ) ), 15, &exp ) ); - tmp = shl_sat( tmp, exp ); - tilt = mult_r( tilt, tmp ); // Q15 + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) - { - mdctSpectrum[l] = L_deposit_l( 0 ); - move32(); - } - FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) - { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp - move16(); - Word32 y; + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 - y = L_mult( tilt, rnd ); // 15Q16 + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) - x = round_fx( y ); // Q15 - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) + tilt = mult_r( tilt, tiltFactor ); // Q15 + } + } - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ - move32(); + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, + L_deposit_h( extract_l( L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ), 1 ) ) ), 15, &exp ) ); + BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ + tmp = shl_sat( tmp, exp ); + BASOP_SATURATE_WARNING_ON_EVS + tilt = mult_r( tilt, tmp ); - tilt = mult_r( tilt, tiltFactor ); // Q15 - } - } + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) + { + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp + move16(); + Word32 y; + rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 + y = L_mult( tilt, rnd ); // 15Q16 - tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, - L_deposit_h( extract_l( L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ), 1 ) ) ), 15, &exp ) ); - BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ - tmp = shl_sat( tmp, exp ); - BASOP_SATURATE_WARNING_ON_EVS - tilt = mult_r( tilt, tmp ); + nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) + x = round_fx( y ); // Q15 + nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) - FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) - { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp - move16(); - Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); // Q0 - y = L_mult( tilt, rnd ); // 15Q16 + mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ + move32(); - nrgNoiseInLastFrame = L_add( nrgNoiseInLastFrame, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(31 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) - x = round_fx( y ); // Q15 - nrgWhiteNoise = L_add( nrgWhiteNoise, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // Q(1 - ld) + tilt = mult_r( tilt, tiltFactor ); // Q15 + } - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ - move32(); + IF( EQ_32( nrgNoiseInLastFrame, 0 ) ) + { + set32_fx( mdctSpectrum, 0, crossOverFreq ); + *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); + } + ELSE + { + exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); + exp_noise = add( ld, shl( 15, 1 ) ); - tilt = mult_r( tilt, tiltFactor ); // Q15 - } + ld = norm_l( nrgNoiseInLastFrame ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last+ld + exp_last = sub( exp_last, ld ); + ld = norm_l( nrgWhiteNoise ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld + exp_noise = sub( exp_noise, ld ); - IF( EQ_32( nrgNoiseInLastFrame, 0 ) ) - { - set32_fx( mdctSpectrum, 0, crossOverFreq ); - *mdctSpectrum_exp = SPEC_EXP_DEC; - move16(); - } - ELSE - { - exp_last = add( ld, shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ) ); - exp_noise = add( ld, shl( 15, 1 ) ); + exp = sub( exp_last, exp_noise ); - ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last+ld - exp_last = sub( exp_last, ld ); - ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld - exp_noise = sub( exp_noise, ld ); + IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) + { + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - Qexp -1 + exp = add( exp, 1 ); + } + tmp = div_l( nrgNoiseInLastFrame, extract_h( nrgWhiteNoise ) ); + tmp = Sqrt16( tmp, &exp ); + g = mult_r( g, tmp ); - exp = sub( exp_last, exp_noise ); + L_tmp = L_deposit_h( 0 ); + ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); + exp = sub( ld, exp ); + IF( exp > 0 ) + { + g = shr( g, exp ); // Q15 - exp + *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); + } + ELSE + { + crossfadeGain = shl( crossfadeGain, exp ); + e_crossfadeGain = sub( e_crossfadeGain, exp ); + *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); + move16(); + } + /*make a headroom for mdct_shaping*/ + exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); - IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) - { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - Qexp -1 - exp = add( exp, 1 ); - } - tmp = div_l( nrgNoiseInLastFrame, extract_h( nrgWhiteNoise ) ); - tmp = Sqrt16( tmp, &exp ); - g = mult_r( g, tmp ); - - L_tmp = L_deposit_h( 0 ); - ld = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, 15 ); - exp = sub( ld, exp ); - IF( exp > 0 ) - { - g = shr( g, exp ); // Q15 - exp - *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; - move16(); - } - ELSE - { - crossfadeGain = shl( crossfadeGain, exp ); - e_crossfadeGain = sub( e_crossfadeGain, exp ); - *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); - move16(); - } - /*make a headroom for mdct_shaping*/ - exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); + IF( exp < 0 ) + { + *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); + } + ELSE + { + exp = 0; + move16(); + } - IF( exp < 0 ) - { - *mdctSpectrum_exp = SPEC_EXP_DEC; - move16(); - } - ELSE - { - exp = 0; - move16(); - } + FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) + { + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp + move16(); + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp + move32(); - FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) - { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp - move16(); - Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp - move32(); + IF( g > 0 ) + { + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp + } - IF( g > 0 ) - { - L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp - } + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + IF( y > 0 ) + { + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + } + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp + move32(); + } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp - IF( y > 0 ) - { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp - } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp - move32(); - } + FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) + { + FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) + { + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp + move16(); + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp + move32(); - FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) - { - FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) - { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp - move16(); - Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp - move32(); + IF( g > 0 ) + { + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp + } - IF( g > 0 ) - { - L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + IF( y > 0 ) + { + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + } + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp + move32(); + } } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp - IF( y > 0 ) + /* initialize bins of tonal components with zero: basically not + necessary, but currently the whole spectrum is rescaled in + mdct_noiseShaping() and then there would be a processing of + uninitialized values */ + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) + { + mdctSpectrum[l] = L_deposit_l( 0 ); + move32(); + } } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp - move32(); - } - } - /* initialize bins of tonal components with zero: basically not - necessary, but currently the whole spectrum is rescaled in - mdct_noiseShaping() and then there would be a processing of - uninitialized values */ - FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) - { - FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) - { - mdctSpectrum[l] = L_deposit_l( 0 ); - move32(); - } - } + FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) + { + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp + move16(); + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp + move32(); - FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) - { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp - move16(); - Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp - move32(); + IF( GT_16( g, 0 ) ) + { + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp + } - IF( GT_16( g, 0 ) ) - { - L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + IF( GT_32( y, 0 ) ) + { + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + } + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp + move32(); + } } - - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp - IF( GT_32( y, 0 ) ) + exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); + FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp + move32(); } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp - move32(); } } - exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, sub( *mdctSpectrum_exp, 16 ) ); - FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) - { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp - move32(); - } -} -} -*pSeed = rnd; -move16(); + *pSeed = rnd; + move16(); -pop_wmops(); + pop_wmops(); -return; + return; } diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 8fb036d2a..c903b8705 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -836,18 +836,20 @@ static void tc_dec_fx( *--------------------------------------------------------------*/ pred_lt4_tc_fx( exc, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); - IF( st_fx->hBWE_TD != NULL ){ - IF( EQ_16( L_frame, L_FRAME ) ){ + IF( st_fx->hBWE_TD != NULL ) + { + IF( EQ_16( L_frame, L_FRAME ) ) + { interp_code_5over2_fx( &exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); -} -ELSE -{ - interp_code_4over2_fx( &exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR ); -} -} -*position = add( imp_pos, i_subfr ); -move16(); -return; + } + ELSE + { + interp_code_4over2_fx( &exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR ); + } + } + *position = add( imp_pos, i_subfr ); + move16(); + return; } /*-------------------------------------------------------------------* diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index eca622dd0..6f68e5fff 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1587,36 +1587,37 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( } IF( overflow_flag != 0 ) /* Overflow */ { - IF( *stop ){ - *stop = tot_bits2; /* Q0 */ + IF( *stop ) + { + *stop = tot_bits2; /* Q0 */ + move16(); + } + ELSE + { + *stop = round_bit_estimate_fx; + move16(); + } + } + + *lastnz_out = lastnz; /* Q0 */ move16(); - } - ELSE - { - *stop = round_bit_estimate_fx; + *nEncoded = lastnz2; /* Q0 */ move16(); - } -} + /* Safety mechanism to avoid overflow */ + test(); + IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) ) + { + FOR( k = 0; k < lastnz2; k++ ) + { + x[k] = 0; + move16(); + } + } -*lastnz_out = lastnz; /* Q0 */ -move16(); -*nEncoded = lastnz2; /* Q0 */ -move16(); -/* Safety mechanism to avoid overflow */ -test(); -IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) ) -{ - FOR( k = 0; k < lastnz2; k++ ) - { - x[k] = 0; - move16(); + return tot_bits2; } } -return tot_bits2; -} -} - /*-------------------------------------------------------------------* * RCcontextMapping_encode2_estimate_bandWise_start_fx() diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c index f485463a4..4ccadc49d 100644 --- a/lib_enc/cod4t64_fx.c +++ b/lib_enc/cod4t64_fx.c @@ -1091,27 +1091,29 @@ static Word32 pre_process_fx( sign = L_deposit_l( 0 ); j = 0; move16(); - FOR( k = 0; k < 64; k += 4 ){ - IF( v[k] ){ - pos_vector[j] = shr( k, 2 ); - move16(); - pos_vector_num[j] = L_shr( abs_s( v[k] ), 9 ); /* Q9: 512 -> 1, Q0 */ - move32(); - IF( v[k] > 0 ) + FOR( k = 0; k < 64; k += 4 ) { - sign = L_shl( sign, 1 ); - } - ELSE - { - sign = L_add( L_shl( sign, 1 ), 1 ); + IF( v[k] ) + { + pos_vector[j] = shr( k, 2 ); + move16(); + pos_vector_num[j] = L_shr( abs_s( v[k] ), 9 ); /* Q9: 512 -> 1, Q0 */ + move32(); + IF( v[k] > 0 ) + { + sign = L_shl( sign, 1 ); + } + ELSE + { + sign = L_add( L_shl( sign, 1 ), 1 ); + } + j = add( j, 1 ); + } } - j = add( j, 1 ); -} -} -*pulse_pos_num = L_deposit_l( j ); -move32(); + *pulse_pos_num = L_deposit_l( j ); + move32(); -return sign; + return sign; } diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c old mode 100755 new mode 100644 index ac7cabe02..860795944 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1585,33 +1585,35 @@ void IGFEncConcatenateBitstream_ivas_fx( pFrame += *pFrame_size >> 3; /* bitstream packing (conversion of individual indices into a serial stream) */ - FOR( i = 0; i < bsBits; i++ ){ - IF( ind_list[i].nb_bits > 0 ){ + FOR( i = 0; i < bsBits; i++ ) + { + IF( ind_list[i].nb_bits > 0 ) + { /* mask from MSB to LSB */ imask = L_shl( 1, sub( ind_list[i].nb_bits, 1 ) ); - /* write bit by bit */ - FOR( k = 0; k < ind_list[i].nb_bits; k++ ) - { - pack_bit_fx( extract_l( L_and( ind_list[i].value, imask ) ), &pFrame, &omask ); - imask = L_shr( imask, 1 ); + /* write bit by bit */ + FOR( k = 0; k < ind_list[i].nb_bits; k++ ) + { + pack_bit_fx( extract_l( L_and( ind_list[i].value, imask ) ), &pFrame, &omask ); + imask = L_shr( imask, 1 ); + } + nb_bits_written = add( nb_bits_written, ind_list[i].nb_bits ); + + /* delete the indice */ + ind_list[i].nb_bits = -1; + move16(); + } } - nb_bits_written = add( nb_bits_written, ind_list[i].nb_bits ); - /* delete the indice */ - ind_list[i].nb_bits = -1; + *pFrame_size = add( *pFrame_size, nb_bits_written ); move16(); -} -} - -*pFrame_size = add( *pFrame_size, nb_bits_written ); -move16(); -/* update list of indices */ -hBstr->nb_ind_tot = sub( hBstr->nb_ind_tot, bsBits ); -hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, nb_bits_written ); + /* update list of indices */ + hBstr->nb_ind_tot = sub( hBstr->nb_ind_tot, bsBits ); + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, nb_bits_written ); -return; + return; } diff --git a/lib_enc/ivas_enc_cov_handler_fx.c b/lib_enc/ivas_enc_cov_handler_fx.c index 2d652a683..96420fc10 100644 --- a/lib_enc/ivas_enc_cov_handler_fx.c +++ b/lib_enc/ivas_enc_cov_handler_fx.c @@ -297,25 +297,27 @@ static Word16 ivas_spar_get_activeW_flag_fx( move16(); max_val = hCovEnc->bb_var_lt_fx[max_idx]; // q_bb_var[max_idx] move32(); - FOR( ch = nchan_transport; ch < num_chs; ch++ ){ - IF( GT_32( hCovEnc->bb_var_lt_fx[ch], max_val ) ){ + FOR( ch = nchan_transport; ch < num_chs; ch++ ) + { + IF( GT_32( hCovEnc->bb_var_lt_fx[ch], max_val ) ) + { max_idx = ch; + move16(); + max_val = hCovEnc->bb_var_lt_fx[ch]; + move32(); + } + } + *res_ind = max_idx; /* Q0 */ + move16(); + } + ELSE IF( EQ_16( nchan_transport, 3 ) ) + { + *res_ind = dmx_order[nchan_transport]; /* Q0 */ move16(); - max_val = hCovEnc->bb_var_lt_fx[ch]; - move32(); } } - *res_ind = max_idx; /* Q0 */ - move16(); -} -ELSE IF( EQ_16( nchan_transport, 3 ) ) -{ - *res_ind = dmx_order[nchan_transport]; /* Q0 */ - move16(); -} -} -return activeW_flag; + return activeW_flag; } diff --git a/lib_enc/ivas_mc_param_enc_fx.c b/lib_enc/ivas_mc_param_enc_fx.c index f17bee69a..2e1a71c72 100644 --- a/lib_enc/ivas_mc_param_enc_fx.c +++ b/lib_enc/ivas_mc_param_enc_fx.c @@ -1662,24 +1662,26 @@ static void ivas_param_mc_transient_detection_fx( move16(); } - FOR( i = 0; i < NSUBBLOCKS; i++ ){ - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( pSubblockNrg_fx[i], 32, Mpy_32_16_1( pAccSubblockNrg_fx[i], attackRatioThreshold_fx ), ( 32 + ATTACKTHRESHOLD_E ) ), 1 ) ){ + FOR( i = 0; i < NSUBBLOCKS; i++ ) + { + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( pSubblockNrg_fx[i], 32, Mpy_32_16_1( pAccSubblockNrg_fx[i], attackRatioThreshold_fx ), ( 32 + ATTACKTHRESHOLD_E ) ), 1 ) ) + { bIsAttackPresent = TRUE; + move16(); + attackIndex = i; + move16(); + } + } + + /* avoid post-echos on click sounds (very short transients) due to TNS aliasing */ + *pAttackIndex = attackIndex; move16(); - attackIndex = i; + *pbIsAttackPresent = bIsAttackPresent; move16(); -} -} -/* avoid post-echos on click sounds (very short transients) due to TNS aliasing */ -*pAttackIndex = attackIndex; -move16(); -*pbIsAttackPresent = bIsAttackPresent; -move16(); - -pop_wmops(); + pop_wmops(); -return; + return; } /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_qspherical_enc_fx.c b/lib_enc/ivas_qspherical_enc_fx.c index 5a9c3bb4f..02047191d 100644 --- a/lib_enc/ivas_qspherical_enc_fx.c +++ b/lib_enc/ivas_qspherical_enc_fx.c @@ -453,117 +453,122 @@ UWord16 quantize_direction_fx( idx_sph = add( cum_n[id_th - 1], id_phi ); } } - ELSE{ - IF( id_th == 0 ){ + ELSE + { + IF( id_th == 0 ) + { idx_sph = 0; + move16(); + } + ELSE + { + idx_sph = cum_n[id_th - 1]; + move16(); + } + } + *theta_q = theta_hat; + move32(); + IF( EQ_32( theta_hat, DEGREE_90_Q_22 ) ) + { + *phi_q = 0; + id_phi = MASA_NO_INDEX; + move32(); + move16(); + } + ELSE + { + *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); + move32(); + } + *index_theta = id_th; + *index_phi = id_phi_remap; move16(); - } - ELSE - { - idx_sph = cum_n[id_th - 1]; move16(); } -} -*theta_q = theta_hat; -move32(); -IF( EQ_32( theta_hat, DEGREE_90_Q_22 ) ) -{ - *phi_q = 0; - id_phi = MASA_NO_INDEX; - move32(); - move16(); -} -ELSE -{ - *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); - move32(); -} -*index_theta = id_th; -*index_phi = id_phi_remap; -move16(); -move16(); -} -ELSE -{ - /* Starting from Equator, alternating positive and negative */ - cum_n[0] = no_phi_masa[no_bits - 1][0]; - move16(); - FOR( i = 1; i < no_th; i++ ) + ELSE { - cum_n[2 * i - 1] = add( cum_n[2 * i - 2], no_phi_masa[no_bits - 1][i] ); - cum_n[2 * i] = add( cum_n[2 * i - 1], no_phi_masa[no_bits - 1][i] ); - move16(); + /* Starting from Equator, alternating positive and negative */ + cum_n[0] = no_phi_masa[no_bits - 1][0]; move16(); - } + FOR( i = 1; i < no_th; i++ ) + { + cum_n[2 * i - 1] = add( cum_n[2 * i - 2], no_phi_masa[no_bits - 1][i] ); + cum_n[2 * i] = add( cum_n[2 * i - 1], no_phi_masa[no_bits - 1][i] ); + move16(); + move16(); + } - if ( no_th > 0 ) - { - assert( abs( cum_n[2 * ( no_th - 1 )] ) < 32768 ); - } + if ( no_th > 0 ) + { + assert( abs( cum_n[2 * ( no_th - 1 )] ) < 32768 ); + } - IF( id_th == 0 ) - { - IF( LT_16( id_phi, MASA_NO_INDEX ) ) + IF( id_th == 0 ) { - idx_sph = id_phi; - move16(); + IF( LT_16( id_phi, MASA_NO_INDEX ) ) + { + idx_sph = id_phi; + move16(); + } + ELSE + { + idx_sph = 0; + move16(); + } } ELSE { - idx_sph = 0; + IF( sign_th > 0 ) + { + IF( LT_16( id_phi, MASA_NO_INDEX ) ) + { + idx_sph = add( cum_n[2 * id_th - 2], id_phi ); + } + ELSE + { + idx_sph = cum_n[2 * id_th - 2]; + move16(); + } + + id_th = sub( shl( id_th, 1 ), 1 ); + } + ELSE + { + IF( LT_16( id_phi, MASA_NO_INDEX ) ) + { + idx_sph = add( cum_n[2 * id_th - 1], id_phi ); + } + ELSE + { + idx_sph = cum_n[2 * id_th - 1]; + move16(); + } + id_th = shl( id_th, 1 ); + } + } + + *theta_q = imult3216( theta_hat, sign_th ); + move32(); + IF( EQ_32( theta_hat, DEGREE_90_Q_22 ) ) + { + *phi_q = 0; + id_phi = MASA_NO_INDEX; + move32(); move16(); } - } - ELSE{ - IF( sign_th > 0 ){ - IF( LT_16( id_phi, MASA_NO_INDEX ) ){ - idx_sph = add( cum_n[2 * id_th - 2], id_phi ); -} -ELSE -{ - idx_sph = cum_n[2 * id_th - 2]; - move16(); -} + ELSE + { + *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); + move32(); + } -id_th = sub( shl( id_th, 1 ), 1 ); -} -ELSE -{ - IF( LT_16( id_phi, MASA_NO_INDEX ) ) - { - idx_sph = add( cum_n[2 * id_th - 1], id_phi ); - } - ELSE - { - idx_sph = cum_n[2 * id_th - 1]; + *index_theta = id_th; + *index_phi = id_phi_remap; + move16(); move16(); } - id_th = shl( id_th, 1 ); -} -} - -*theta_q = imult3216( theta_hat, sign_th ); -move32(); -IF( EQ_32( theta_hat, DEGREE_90_Q_22 ) ) -{ - *phi_q = 0; - id_phi = MASA_NO_INDEX; - move32(); - move16(); -} -ELSE -{ - *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); - move32(); -} - -*index_theta = id_th; -*index_phi = id_phi_remap; -move16(); -move16(); -} -return idx_sph; + return idx_sph; } /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_dft_enc_fx.c b/lib_enc/ivas_stereo_dft_enc_fx.c index 6aa9673f4..9c34a92c9 100644 --- a/lib_enc/ivas_stereo_dft_enc_fx.c +++ b/lib_enc/ivas_stereo_dft_enc_fx.c @@ -3026,220 +3026,222 @@ void stereo_dft_enc_write_BS_fx( { nb = add( nb, write_bitstream_adapt_GR_fx( hBstr, IND_STEREO_DFT_SIDEGAINS, encoded_ind_GR, hStereoDft->nbands, hStereoDft->side_gain_flag_2, no_GR_ord ) ); } - ELSE{ - IF( EQ_16( hStereoDft->side_gain_flag_1, 2 ) ){ - nb = add( nb, write_bitstream_GR_fx( hBstr, IND_STEREO_DFT_SIDEGAINS, hStereoDft->side_gain_index_ECDiff, hStereoDft->nbands, hStereoDft->side_gain_flag_2 - no_GR_ord ) ); -} -ELSE -{ - FOR( b = 0; b < hStereoDft->nbands; b++ ) - { - /*ILD*/ - push_indice( hBstr, IND_STEREO_DFT_SIDEGAINS, hStereoDft->side_gain_index_EC[b], STEREO_DFT_SIDEGAIN_NBITS ); - nb = add( nb, STEREO_DFT_SIDEGAIN_NBITS ); - } -} -} - -/* nb bits are used for side gain*/ -( *nb_bits ) = add( *nb_bits, nb ); -move16(); -#ifdef DEBUG_MODE_DFT_BITS -fprintf( SG_bits, "%d ", nb ); -#endif -nb = 0; -move16(); - -IF( EQ_32( core_brate, SID_2k40 ) ) -{ - stereo_dft_enc_sid_calc_coh_fx( hStereoDft, hCPE->hStereoCng->prev_cohBand_fx, &hCPE->hStereoCng->td_active, &hCPE->hStereoCng->first_SID, cohBand ); - - IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 ) ) ) + ELSE { - IF( NE_32( hStereoDft->hItd->itd_fx[k_offset], 0 ) ) + IF( EQ_16( hStereoDft->side_gain_flag_1, 2 ) ) { - /* Re-quantize ITD with lower resolution for Stereo CNG */ - itd = hStereoDft->hItd->itd_index[k_offset]; - move16(); - if ( GT_16( itd, 255 ) ) - { - itd = sub( itd, 256 ); - } - itd = shr( itd, STEREO_DFT_SID_ITD_FAC ); - - sid_itd = itd && 1; - move16(); + nb = add( nb, write_bitstream_GR_fx( hBstr, IND_STEREO_DFT_SIDEGAINS, hStereoDft->side_gain_index_ECDiff, hStereoDft->nbands, hStereoDft->side_gain_flag_2 - no_GR_ord ) ); } ELSE { - sid_itd = 0; - move16(); + FOR( b = 0; b < hStereoDft->nbands; b++ ) + { + /*ILD*/ + push_indice( hBstr, IND_STEREO_DFT_SIDEGAINS, hStereoDft->side_gain_index_EC[b], STEREO_DFT_SIDEGAIN_NBITS ); + nb = add( nb, STEREO_DFT_SIDEGAIN_NBITS ); + } } + } - push_indice( hBstr, IND_STEREO_DFT_ITD_MODE, sid_itd, STEREO_DFT_ITD_MODE_NBITS ); - ( *nb_bits ) = add( *nb_bits, STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ - move16(); + /* nb bits are used for side gain*/ + ( *nb_bits ) = add( *nb_bits, nb ); + move16(); +#ifdef DEBUG_MODE_DFT_BITS + fprintf( SG_bits, "%d ", nb ); +#endif + nb = 0; + move16(); - IF( sid_itd ) + IF( EQ_32( core_brate, SID_2k40 ) ) + { + stereo_dft_enc_sid_calc_coh_fx( hStereoDft, hCPE->hStereoCng->prev_cohBand_fx, &hCPE->hStereoCng->td_active, &hCPE->hStereoCng->first_SID, cohBand ); + + IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 ) ) ) { - itd = hStereoDft->hItd->itd_index[k_offset]; - move16(); - IF( GT_16( itd, 255 ) ) + IF( NE_32( hStereoDft->hItd->itd_fx[k_offset], 0 ) ) { - itd = sub( itd, 256 ); - itd = shr( itd, STEREO_DFT_SID_ITD_FAC ); - - if ( GT_16( itd, ( ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1 ) ) ) + /* Re-quantize ITD with lower resolution for Stereo CNG */ + itd = hStereoDft->hItd->itd_index[k_offset]; + move16(); + if ( GT_16( itd, 255 ) ) { - itd = ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1; - move16(); + itd = sub( itd, 256 ); } + itd = shr( itd, STEREO_DFT_SID_ITD_FAC ); - push_indice( hBstr, IND_STEREO_DFT_ITD_NEG, 1, 1 ); /* negative */ - push_indice( hBstr, IND_STEREO_DFT_ITD_COD, itd, STEREO_DFT_SID_ITD_NBITS ); - ( *nb_bits ) = add( *nb_bits, STEREO_DFT_SID_ITD_NBITS + 1 ); + sid_itd = itd && 1; move16(); } ELSE { - itd = shr( itd, STEREO_DFT_SID_ITD_FAC ); + sid_itd = 0; + move16(); + } + + push_indice( hBstr, IND_STEREO_DFT_ITD_MODE, sid_itd, STEREO_DFT_ITD_MODE_NBITS ); + ( *nb_bits ) = add( *nb_bits, STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ + move16(); - if ( GT_16( itd, ( ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1 ) ) ) + IF( sid_itd ) + { + itd = hStereoDft->hItd->itd_index[k_offset]; + move16(); + IF( GT_16( itd, 255 ) ) { - itd = ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1; + itd = sub( itd, 256 ); + itd = shr( itd, STEREO_DFT_SID_ITD_FAC ); + + if ( GT_16( itd, ( ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1 ) ) ) + { + itd = ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1; + move16(); + } + + push_indice( hBstr, IND_STEREO_DFT_ITD_NEG, 1, 1 ); /* negative */ + push_indice( hBstr, IND_STEREO_DFT_ITD_COD, itd, STEREO_DFT_SID_ITD_NBITS ); + ( *nb_bits ) = add( *nb_bits, STEREO_DFT_SID_ITD_NBITS + 1 ); move16(); } + ELSE + { + itd = shr( itd, STEREO_DFT_SID_ITD_FAC ); - push_indice( hBstr, IND_STEREO_DFT_ITD_NEG, 0, 1 ); /* Positive */ - push_indice( hBstr, IND_STEREO_DFT_ITD_COD, itd, STEREO_DFT_SID_ITD_NBITS ); - ( *nb_bits ) = add( *nb_bits, STEREO_DFT_SID_ITD_NBITS + 1 ); - move16(); + if ( GT_16( itd, ( ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1 ) ) ) + { + itd = ( 1 << STEREO_DFT_SID_ITD_NBITS ) - 1; + move16(); + } + + push_indice( hBstr, IND_STEREO_DFT_ITD_NEG, 0, 1 ); /* Positive */ + push_indice( hBstr, IND_STEREO_DFT_ITD_COD, itd, STEREO_DFT_SID_ITD_NBITS ); + ( *nb_bits ) = add( *nb_bits, STEREO_DFT_SID_ITD_NBITS + 1 ); + move16(); + } } } } -} - -/*------------------------------------------------------------------* - * write IPD indices - *-----------------------------------------------------------------*/ -IF( NE_32( core_brate, SID_2k40 ) ) -{ - push_indice( hBstr, IND_STEREO_DFT_NO_IPD_FLAG, hStereoDft->no_ipd_flag, STEREO_DFT_FLAG_BITS ); - nb = add( nb, STEREO_DFT_FLAG_BITS ); /*IPD mode flag: 1bit*/ + /*------------------------------------------------------------------* + * write IPD indices + *-----------------------------------------------------------------*/ - IF( hStereoDft->no_ipd_flag == 0 ) + IF( NE_32( core_brate, SID_2k40 ) ) { - push_indice( hBstr, IND_STEREO_DFT_GIPD, hStereoDft->gipd_index, STEREO_DFT_GIPD_NBITS ); - nb = add( nb, STEREO_DFT_GIPD_NBITS ); - } -} -ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS ) ) ) -{ - push_indice( hBstr, IND_STEREO_DFT_NO_IPD_FLAG, hStereoDft->no_ipd_flag, STEREO_DFT_FLAG_BITS ); - nb = add( nb, STEREO_DFT_FLAG_BITS ); /*IPD mode flag: 1bit*/ + push_indice( hBstr, IND_STEREO_DFT_NO_IPD_FLAG, hStereoDft->no_ipd_flag, STEREO_DFT_FLAG_BITS ); + nb = add( nb, STEREO_DFT_FLAG_BITS ); /*IPD mode flag: 1bit*/ - IF( hStereoDft->no_ipd_flag == 0 ) + IF( hStereoDft->no_ipd_flag == 0 ) + { + push_indice( hBstr, IND_STEREO_DFT_GIPD, hStereoDft->gipd_index, STEREO_DFT_GIPD_NBITS ); + nb = add( nb, STEREO_DFT_GIPD_NBITS ); + } + } + ELSE IF( LE_16( *nb_bits, ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS ) ) ) { - stereo_dft_quantize_ipd_fx( &hStereoDft->sid_gipd_fx, &hStereoDft->sid_gipd_fx, &sid_gIpd_index, STEREO_DFT_SID_GIPD_NBITS ); - push_indice( hBstr, IND_STEREO_DFT_GIPD, sid_gIpd_index, STEREO_DFT_SID_GIPD_NBITS ); - nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); + push_indice( hBstr, IND_STEREO_DFT_NO_IPD_FLAG, hStereoDft->no_ipd_flag, STEREO_DFT_FLAG_BITS ); + nb = add( nb, STEREO_DFT_FLAG_BITS ); /*IPD mode flag: 1bit*/ + + IF( hStereoDft->no_ipd_flag == 0 ) + { + stereo_dft_quantize_ipd_fx( &hStereoDft->sid_gipd_fx, &hStereoDft->sid_gipd_fx, &sid_gIpd_index, STEREO_DFT_SID_GIPD_NBITS ); + push_indice( hBstr, IND_STEREO_DFT_GIPD, sid_gIpd_index, STEREO_DFT_SID_GIPD_NBITS ); + nb = add( nb, STEREO_DFT_SID_GIPD_NBITS ); + } } -} #ifdef DEBUG_MODE_DFT_BITS -fprintf( IPD_bits, "%d ", nb ); + fprintf( IPD_bits, "%d ", nb ); #endif -( *nb_bits ) = add( *nb_bits, nb ); + ( *nb_bits ) = add( *nb_bits, nb ); -/*----------------------------------------------------------------* - * Residual prediction - *----------------------------------------------------------------*/ + /*----------------------------------------------------------------* + * Residual prediction + *----------------------------------------------------------------*/ -nb = 0; /* bits for residual pred gains */ -move16(); -IF( hStereoDft->res_pred_mode[k_offset] ) -{ - IF( hStereoDft->attackPresent == 0 ) + nb = 0; /* bits for residual pred gains */ + move16(); + IF( hStereoDft->res_pred_mode[k_offset] ) { - nbands = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); - b = hStereoDft->res_pred_band_min; - move16(); - - /*Adaptive SF*/ - IF( hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + IF( hStereoDft->attackPresent == 0 ) { - /*read flag*/ - push_indice( hBstr, IND_STEREO_DFT_REVERB_MODE, hStereoDft->reverb_flag, STEREO_DFT_REVERB_MODE_NBITS ); - nb = add( nb, STEREO_DFT_REVERB_MODE_NBITS ); - IF( hStereoDft->reverb_flag ) + nbands = s_min( hStereoDft->nbands, STEREO_DFT_RES_PRED_BAND_MAX ); + b = hStereoDft->res_pred_band_min; + move16(); + + /*Adaptive SF*/ + IF( hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) { - nbands = sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); + /*read flag*/ + push_indice( hBstr, IND_STEREO_DFT_REVERB_MODE, hStereoDft->reverb_flag, STEREO_DFT_REVERB_MODE_NBITS ); + nb = add( nb, STEREO_DFT_REVERB_MODE_NBITS ); + IF( hStereoDft->reverb_flag ) + { + nbands = sub( nbands, STEREO_DFT_RES_PRED_BAND_MIN_CONST ); + } } - } - /* Res Pred Gain flag 0 */ - IF( hStereoDft->res_pred_flag_1 > 0 ) - { - push_indice( hBstr, IND_STEREO_DFT_RES_PRED_FLAG, hStereoDft->res_pred_flag_1, 2 ); - nb = add( nb, 2 ); /*pred gain mode flag: 2 bits*/ - } - ELSE - { - push_indice( hBstr, IND_STEREO_DFT_RES_PRED_FLAG, hStereoDft->res_pred_flag_1, STEREO_DFT_FLAG_BITS ); - nb = add( nb, STEREO_DFT_FLAG_BITS ); /*pred gain mode flag: 1bit*/ - } - - no_GR_ord = 2; - move16(); - IF( hStereoDft->res_pred_flag_1 == 0 ) - { - IF( EQ_16( encoded_ind_pred_GR[0], dft_maps_rpg[8 * NO_SYMB_GR_PRED_G] ) ) + /* Res Pred Gain flag 0 */ + IF( hStereoDft->res_pred_flag_1 > 0 ) { - nb = add( nb, write_GR1_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, 1 ) ); + push_indice( hBstr, IND_STEREO_DFT_RES_PRED_FLAG, hStereoDft->res_pred_flag_1, 2 ); + nb = add( nb, 2 ); /*pred gain mode flag: 2 bits*/ } ELSE { - nb = add( nb, write_bitstream_adapt_GR_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2, 2 ) ); + push_indice( hBstr, IND_STEREO_DFT_RES_PRED_FLAG, hStereoDft->res_pred_flag_1, STEREO_DFT_FLAG_BITS ); + nb = add( nb, STEREO_DFT_FLAG_BITS ); /*pred gain mode flag: 1bit*/ } - } - ELSE - { - IF( EQ_16( hStereoDft->res_pred_flag_1, 2 ) ) + + no_GR_ord = 2; + move16(); + IF( hStereoDft->res_pred_flag_1 == 0 ) { - nb = add( nb, write_bitstream_GR_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, &hStereoDft->res_pred_index_ECDiff[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2 - no_GR_ord ) ); + IF( EQ_16( encoded_ind_pred_GR[0], dft_maps_rpg[8 * NO_SYMB_GR_PRED_G] ) ) + { + nb = add( nb, write_GR1_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, 1 ) ); + } + ELSE + { + nb = add( nb, write_bitstream_adapt_GR_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2, 2 ) ); + } } ELSE { - FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) + IF( EQ_16( hStereoDft->res_pred_flag_1, 2 ) ) { - push_indice( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, hStereoDft->res_pred_index_EC[b], STEREO_DFT_RES_GAINS_BITS ); - nb = add( nb, STEREO_DFT_RES_GAINS_BITS ); + nb = add( nb, write_bitstream_GR_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, &hStereoDft->res_pred_index_ECDiff[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2 - no_GR_ord ) ); + } + ELSE + { + FOR( b = hStereoDft->res_pred_band_min; b < nbands; b++ ) + { + push_indice( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, hStereoDft->res_pred_index_EC[b], STEREO_DFT_RES_GAINS_BITS ); + nb = add( nb, STEREO_DFT_RES_GAINS_BITS ); + } } } } + ELSE + { + set16_fx( hStereoDft->res_pred_index_ECprevious, 0, sub( hStereoDft->nbands, hStereoDft->res_pred_band_min ) ); + } } ELSE { - set16_fx( hStereoDft->res_pred_index_ECprevious, 0, sub( hStereoDft->nbands, hStereoDft->res_pred_band_min ) ); + set16_fx( hStereoDft->res_pred_index_ECprevious, 0, hStereoDft->nbands - hStereoDft->res_pred_band_min ); } -} -ELSE -{ - set16_fx( hStereoDft->res_pred_index_ECprevious, 0, hStereoDft->nbands - hStereoDft->res_pred_band_min ); -} -( *nb_bits ) = add( *nb_bits, nb ); -move16(); + ( *nb_bits ) = add( *nb_bits, nb ); + move16(); -IF( EQ_32( core_brate, SID_2k40 ) ) -{ - stereo_dft_enc_sid_coh_fx( hBstr, hCPE->hStereoCng->mem_cohBand_fx, hStereoDft->nbands, nb_bits, cohBand ); -} + IF( EQ_32( core_brate, SID_2k40 ) ) + { + stereo_dft_enc_sid_coh_fx( hBstr, hCPE->hStereoCng->mem_cohBand_fx, hStereoDft->nbands, nb_bits, cohBand ); + } -return; + return; } /*------------------------------------------------------------------------- diff --git a/lib_enc/lib_enc_fx.c b/lib_enc/lib_enc_fx.c index 3832ce22e..057bde7d9 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -1529,21 +1529,22 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } } ELSE /* IVAS */ + { + IF( NE_32( ( error = ivas_enc_fx( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) { - IF( NE_32( ( error = ivas_enc_fx( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ){ - return error; -} -} + return error; + } + } -/* write indices into bitstream buffer */ -{ - write_indices_ivas_fx( st_ivas, outputBitStream, numOutBits ); -} -/* Reset switching flag before next call - can be set to "true" by some setters */ -hIvasEnc->switchingActive = false; -move16(); + /* write indices into bitstream buffer */ + { + write_indices_ivas_fx( st_ivas, outputBitStream, numOutBits ); + } + /* Reset switching flag before next call - can be set to "true" by some setters */ + hIvasEnc->switchingActive = false; + move16(); -return error; + return error; } diff --git a/lib_enc/mslvq_enc_fx.c b/lib_enc/mslvq_enc_fx.c index ab7122ad2..f23447da1 100644 --- a/lib_enc/mslvq_enc_fx.c +++ b/lib_enc/mslvq_enc_fx.c @@ -342,24 +342,26 @@ static void prepare_data_fx( sig = 1; move16(); - FOR( j = 0; j < LATTICE_DIM; j++ ){ - IF( xsort[j] < 0 ){ + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + IF( xsort[j] < 0 ) + { sign[j] = -1; + move16(); + sig = negate( sig ); + move16(); + xsort[j] = negate( xsort[j] ); /*Q10 */ + } + ELSE + { + sign[j] = 1; + move16(); + } + } + *p_sig = sig; move16(); - sig = negate( sig ); - move16(); - xsort[j] = negate( xsort[j] ); /*Q10 */ -} -ELSE -{ - sign[j] = 1; - move16(); -} -} -*p_sig = sig; -move16(); -return; + return; } diff --git a/lib_enc/ppp_enc_fx.c b/lib_enc/ppp_enc_fx.c index 15b013a4b..b60008758 100644 --- a/lib_enc/ppp_enc_fx.c +++ b/lib_enc/ppp_enc_fx.c @@ -554,7 +554,7 @@ static Word16 DTFS_quant_cw_fx( IF( n < 0 ) rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); ELSE IF( n > 0 ) - rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); + rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); tmp = shl( *POWER_IDX, 1 ); /* tmp=2*POWER_IDX */ *lastLgainE_fx = add( *lastLgainE_fx, PowerCB_fx[tmp] ); /* Q11 */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 03e7adade..396466cdc 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -5239,41 +5239,43 @@ static void QuantizeSHBframegain_fx( } } - IF( EQ_16( st_fx->rf_mode, 1 ) ){ - /*Currently intended for SWB only. Modify for WB is needed later!*/ - IF( EQ_16( hRF->rf_frame_type, RF_NELP ) ){ - *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ - move16(); -} -ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ -{ - IF( LE_32( *GainFrame, 327680 /*1.25 in Q18*/ ) ) /* [0 to 1.25] range --> 0.5*/ - { - *rf_gainFrame_ind = 0; - move16(); - } - ELSE IF( LE_32( *GainFrame, 786432 /*3 in Q18*/ ) ) /* (1.25 to 3] --> 2 */ - { - *rf_gainFrame_ind = 1; - move16(); - } - ELSE IF( LE_32( *GainFrame, 1572864 /*6 in Q18*/ ) ) /* (3 to 6] --> 4 */ + IF( EQ_16( st_fx->rf_mode, 1 ) ) { - *rf_gainFrame_ind = 2; - move16(); - } - ELSE /* (6 to Inf) --> 8 */ - { - *rf_gainFrame_ind = 3; - move16(); + /*Currently intended for SWB only. Modify for WB is needed later!*/ + IF( EQ_16( hRF->rf_frame_type, RF_NELP ) ) + { + *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ + move16(); + } + ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ + { + IF( LE_32( *GainFrame, 327680 /*1.25 in Q18*/ ) ) /* [0 to 1.25] range --> 0.5*/ + { + *rf_gainFrame_ind = 0; + move16(); + } + ELSE IF( LE_32( *GainFrame, 786432 /*3 in Q18*/ ) ) /* (1.25 to 3] --> 2 */ + { + *rf_gainFrame_ind = 1; + move16(); + } + ELSE IF( LE_32( *GainFrame, 1572864 /*6 in Q18*/ ) ) /* (3 to 6] --> 4 */ + { + *rf_gainFrame_ind = 2; + move16(); + } + ELSE /* (6 to Inf) --> 8 */ + { + *rf_gainFrame_ind = 3; + move16(); + } + } } -} -} -*GainFrame = Q_GainFrame; -move32(); /* Q18 */ + *GainFrame = Q_GainFrame; + move32(); /* Q18 */ -return; + return; } diff --git a/lib_isar/lib_isar_post_rend.c b/lib_isar/lib_isar_post_rend.c index 04e80dc61..58394fb6c 100644 --- a/lib_isar/lib_isar_post_rend.c +++ b/lib_isar/lib_isar_post_rend.c @@ -984,30 +984,32 @@ ivas_error ISAR_POST_REND_GetDelay( max_latency_ns = 0; /* Compute the maximum delay across all inputs */ - FOR( i = 0; i < RENDERER_MAX_BIN_INPUTS; i++ ){ - IF( hIvasRend->inputsSplitPost[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ){ - latency_ns = 0; - IF( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.hLc3plusDec != NULL ) - { - Word32 lc3plusDelaySamples; - ISAR_LC3PLUS_DEC_GetDelay( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.hLc3plusDec, &lc3plusDelaySamples ); - latency_ns = (Word32) ( ( ( (Word64) lc3plusDelaySamples * 1000000000 ) + ( *timeScale / 2 ) ) / *timeScale ); - } - IF( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) - { - latency_ns += IVAS_FB_DEC_DELAY_NS; - } - ELSE IF( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.hSplitBinLCLDDec != NULL ) + FOR( i = 0; i < RENDERER_MAX_BIN_INPUTS; i++ ) { - latency_ns += IVAS_FB_DEC_DELAY_NS; + IF( hIvasRend->inputsSplitPost[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) + { + latency_ns = 0; + IF( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.hLc3plusDec != NULL ) + { + Word32 lc3plusDelaySamples; + ISAR_LC3PLUS_DEC_GetDelay( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.hLc3plusDec, &lc3plusDelaySamples ); + latency_ns = (Word32) ( ( ( (Word64) lc3plusDelaySamples * 1000000000 ) + ( *timeScale / 2 ) ) / *timeScale ); + } + IF( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) + { + latency_ns += IVAS_FB_DEC_DELAY_NS; + } + ELSE IF( hIvasRend->inputsSplitPost[i].splitPostRendWrapper.hSplitBinLCLDDec != NULL ) + { + latency_ns += IVAS_FB_DEC_DELAY_NS; + } + max_latency_ns = L_max( max_latency_ns, latency_ns ); + } } - max_latency_ns = L_max( max_latency_ns, latency_ns ); -} -} -*nSamples = (Word16) ( ( ( (Word64) max_latency_ns * *timeScale ) + 500000000 ) / 1000000000 ); + *nSamples = (Word16) ( ( ( (Word64) max_latency_ns * *timeScale ) + 500000000 ) / 1000000000 ); -return IVAS_ERR_OK; + return IVAS_ERR_OK; } diff --git a/lib_rend/ivas_binRenderer_internal_fx.c b/lib_rend/ivas_binRenderer_internal_fx.c index 3d7241a97..a9802477b 100644 --- a/lib_rend/ivas_binRenderer_internal_fx.c +++ b/lib_rend/ivas_binRenderer_internal_fx.c @@ -512,25 +512,27 @@ static ivas_error ivas_alloc_pppMem_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); } - FOR( i = 0; i < dim1; i++ ){ - IF( ( localMem[i] = (Word32 **) malloc( dim2 * sizeof( Word32 * ) ) ) == NULL ){ - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); -} -IF( allocate_init_flag == 0 ) -{ - FOR( j = 0; j < dim2; j++ ) + FOR( i = 0; i < dim1; i++ ) { - IF( ( localMem[i][j] = (Word32 *) malloc( dim3 * sizeof( Word32 ) ) ) == NULL ) + IF( ( localMem[i] = (Word32 **) malloc( dim2 * sizeof( Word32 * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); } + IF( allocate_init_flag == 0 ) + { + FOR( j = 0; j < dim2; j++ ) + { + IF( ( localMem[i][j] = (Word32 *) malloc( dim3 * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); + } + } + } } -} -} -*pppMem = localMem; + *pppMem = localMem; -return IVAS_ERR_OK; + return IVAS_ERR_OK; } diff --git a/lib_rend/ivas_efap_fx.c b/lib_rend/ivas_efap_fx.c index c5bbfb2ea..03f79f87e 100644 --- a/lib_rend/ivas_efap_fx.c +++ b/lib_rend/ivas_efap_fx.c @@ -564,17 +564,19 @@ static ivas_error sphere_triangulation_fx( *numTot = vtxData->numVtx; move16(); - FOR( i = 0; i < vtxData->numVtx; i++ ){ - IF( ( p_dmTranspose[i] = malloc( numSpk * sizeof( Word32 ) ) ) == NULL ){ + FOR( i = 0; i < vtxData->numVtx; i++ ) + { + IF( ( p_dmTranspose[i] = malloc( numSpk * sizeof( Word32 ) ) ) == NULL ) + { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "EFAP: can not allocate memory for dmTranspose\n" ) ); -} -} -*dmTranspose_fx = (Word32 **) p_dmTranspose; + } + } + *dmTranspose_fx = (Word32 **) p_dmTranspose; -/* Remap Ghosts */ -remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); // dmTranspose_fx q31 + /* Remap Ghosts */ + remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); // dmTranspose_fx q31 -return IVAS_ERR_OK; + return IVAS_ERR_OK; } -- GitLab